Commit 30c7bb94 authored by Melledy's avatar Melledy
Browse files

Merge branch 'dev-world-scripts' of https://github.com/Grasscutters/Grasscutter into development

parents 8e6aa50c 5a3e9bc3
......@@ -37,7 +37,7 @@ public class ScriptMonsterTideService {
this.sceneScriptManager.getScriptMonsterSpawnService().addMonsterDeadListener(onMonsterDead);
// spawn the first turn
for (int i = 0; i < this.monsterSceneLimit; i++) {
this.sceneScriptManager.getScriptMonsterSpawnService().spawnMonster(group.id, getNextMonster());
sceneScriptManager.addEntity(this.sceneScriptManager.createMonster(group.id, group.block_id, getNextMonster()));
}
}
......@@ -73,7 +73,7 @@ public class ScriptMonsterTideService {
monsterKillCount.incrementAndGet();
if (monsterTideCount.get() > 0) {
// add more
sceneScriptManager.getScriptMonsterSpawnService().spawnMonster(currentGroup.id, getNextMonster());
sceneScriptManager.addEntity(sceneScriptManager.createMonster(currentGroup.id, currentGroup.block_id, getNextMonster()));
}
// spawn the last turn of monsters
// fix the 5-2
......
......@@ -19,6 +19,7 @@ import emu.grasscutter.game.quest.ServerQuestHandler;
import emu.grasscutter.game.shop.ShopManager;
import emu.grasscutter.game.tower.TowerScheduleManager;
import emu.grasscutter.game.world.World;
import emu.grasscutter.game.world.WorldDataManager;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.server.event.types.ServerEvent;
......@@ -55,25 +56,15 @@ public final class GameServer extends KcpServer {
private final CommandMap commandMap;
private final TaskMap taskMap;
private final DropManager dropManager;
private final WorldDataManager worldDataManager;
private final CombineManger combineManger;
private final TowerScheduleManager towerScheduleManager;
private static InetSocketAddress getAdapterInetSocketAddress(){
InetSocketAddress inetSocketAddress;
if(GAME_INFO.bindAddress.equals("")){
inetSocketAddress=new InetSocketAddress(GAME_INFO.bindPort);
}else{
inetSocketAddress=new InetSocketAddress(
GAME_INFO.bindAddress,
GAME_INFO.bindPort
);
}
return inetSocketAddress;
}
public GameServer() {
this(getAdapterInetSocketAddress());
}
public GameServer(InetSocketAddress address) {
ChannelConfig channelConfig = new ChannelConfig();
channelConfig.nodelay(true,40,2,true);
......@@ -104,7 +95,7 @@ public final class GameServer extends KcpServer {
this.expeditionManager = new ExpeditionManager(this);
this.combineManger = new CombineManger(this);
this.towerScheduleManager = new TowerScheduleManager(this);
this.worldDataManager = new WorldDataManager(this);
// Hook into shutdown event.
Runtime.getRuntime().addShutdownHook(new Thread(this::onServerShutdown));
}
......@@ -173,11 +164,27 @@ public final class GameServer extends KcpServer {
return towerScheduleManager;
}
public WorldDataManager getWorldDataManager() {
return worldDataManager;
}
public TaskMap getTaskMap() {
return this.taskMap;
}
private static InetSocketAddress getAdapterInetSocketAddress(){
InetSocketAddress inetSocketAddress;
if(GAME_INFO.bindAddress.equals("")){
inetSocketAddress=new InetSocketAddress(GAME_INFO.bindPort);
}else{
inetSocketAddress=new InetSocketAddress(
GAME_INFO.bindAddress,
GAME_INFO.bindPort
);
}
return inetSocketAddress;
}
public void registerPlayer(Player player) {
getPlayers().put(player.getUid(), player);
}
......
......@@ -3,7 +3,6 @@ package emu.grasscutter.server.game;
import java.io.File;
import java.net.InetSocketAddress;
import java.util.Set;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.Grasscutter.ServerDebugMode;
import emu.grasscutter.game.Account;
......@@ -17,8 +16,9 @@ import emu.grasscutter.utils.FileUtils;
import emu.grasscutter.utils.Utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import static emu.grasscutter.Configuration.*;
import static emu.grasscutter.utils.Language.translate;
import static emu.grasscutter.Configuration.*;
public class GameSession implements GameSessionManager.KcpChannel {
private final GameServer server;
......
......@@ -13,7 +13,7 @@ public class HandlerGadgetInteractReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
GadgetInteractReq req = GadgetInteractReq.parseFrom(payload);
session.getPlayer().interactWith(req.getGadgetEntityId(), req);
session.getPlayer().interactWith(req.getGadgetEntityId(), req.getOpType());
}
}
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetInvestigationMonsterReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketGetInvestigationMonsterRsp;
@Opcodes(PacketOpcodes.GetInvestigationMonsterReq)
public class HandlerGetInvestigationMonsterReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = GetInvestigationMonsterReqOuterClass.GetInvestigationMonsterReq.parseFrom(payload);
session.send(new PacketGetInvestigationMonsterRsp(req.getCityIdListList()));
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge;
import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ChallengeDataNotifyOuterClass.ChallengeDataNotify;
public class PacketChallengeDataNotify extends BasePacket {
public PacketChallengeDataNotify(DungeonChallenge challenge, int index, int value) {
public PacketChallengeDataNotify(WorldChallenge challenge, int index, int value) {
super(PacketOpcodes.ChallengeDataNotify);
ChallengeDataNotify proto = ChallengeDataNotify.newBuilder()
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge;
import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DungeonChallengeBeginNotifyOuterClass.DungeonChallengeBeginNotify;
public class PacketDungeonChallengeBeginNotify extends BasePacket {
public PacketDungeonChallengeBeginNotify(DungeonChallenge challenge) {
public PacketDungeonChallengeBeginNotify(WorldChallenge challenge) {
super(PacketOpcodes.DungeonChallengeBeginNotify, true);
DungeonChallengeBeginNotify proto = DungeonChallengeBeginNotify.newBuilder()
.setChallengeId(challenge.getChallengeId())
.setChallengeIndex(challenge.getChallengeIndex())
.setGroupId(challenge.getGroup().id)
.addParamList(challenge.getObjective())
.addParamList(challenge.getTimeLimit())
.addAllParamList(challenge.getParamList())
.build();
this.setData(proto);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge;
import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DungeonChallengeFinishNotifyOuterClass.DungeonChallengeFinishNotify;
public class PacketDungeonChallengeFinishNotify extends BasePacket {
public PacketDungeonChallengeFinishNotify(DungeonChallenge challenge) {
public PacketDungeonChallengeFinishNotify(WorldChallenge challenge) {
super(PacketOpcodes.DungeonChallengeFinishNotify, true);
DungeonChallengeFinishNotify proto = DungeonChallengeFinishNotify.newBuilder()
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge;
import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass.DungeonSettleNotify;
......@@ -9,7 +9,7 @@ import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNoti
public class PacketDungeonSettleNotify extends BasePacket {
public PacketDungeonSettleNotify(DungeonChallenge challenge) {
public PacketDungeonSettleNotify(WorldChallenge challenge) {
super(PacketOpcodes.DungeonSettleNotify);
DungeonSettleNotify proto = DungeonSettleNotify.newBuilder()
......@@ -22,7 +22,7 @@ public class PacketDungeonSettleNotify extends BasePacket {
this.setData(proto);
}
public PacketDungeonSettleNotify(DungeonChallenge challenge,
public PacketDungeonSettleNotify(WorldChallenge challenge,
boolean canJump,
boolean hasNextLevel,
int nextFloorId
......
......@@ -4,20 +4,27 @@ import emu.grasscutter.game.entity.EntityBaseGadget;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GadgetInteractRspOuterClass.GadgetInteractRsp;
import emu.grasscutter.net.proto.InterOpTypeOuterClass;
import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType;
import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketGadgetInteractRsp extends BasePacket {
public PacketGadgetInteractRsp(EntityBaseGadget gadget, InteractType interact) {
this(gadget, interact, null);
}
public PacketGadgetInteractRsp(EntityBaseGadget gadget, InteractType interact, InterOpTypeOuterClass.InterOpType opType) {
super(PacketOpcodes.GadgetInteractRsp);
GadgetInteractRsp proto = GadgetInteractRsp.newBuilder()
var proto = GadgetInteractRsp.newBuilder()
.setGadgetEntityId(gadget.getId())
.setInteractType(interact)
.setGadgetId(gadget.getGadgetId())
.build();
.setGadgetId(gadget.getGadgetId());
this.setData(proto);
if(opType != null){
proto.setOpType(opType);
}
this.setData(proto.build());
}
public PacketGadgetInteractRsp() {
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetActivityInfoRspOuterClass;
import java.util.List;
public class PacketGetInvestigationMonsterRsp extends BasePacket {
public PacketGetInvestigationMonsterRsp(List<Integer> cityIdListList) {
super(PacketOpcodes.GetInvestigationMonsterRsp);
var resp = GetActivityInfoRspOuterClass.GetActivityInfoRsp.newBuilder();
this.setData(resp.build());
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.entity.EntityNPC;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GroupSuiteNotifyOuterClass;
import java.util.List;
public class PacketGroupSuiteNotify extends BasePacket {
/**
* control which npc suite is loaded
*/
public PacketGroupSuiteNotify(List<EntityNPC> list) {
super(PacketOpcodes.GroupSuiteNotify);
var proto = GroupSuiteNotifyOuterClass.GroupSuiteNotify.newBuilder();
list.forEach(item -> proto.putGroupMap(item.getGroupId(), item.getSuiteId()));
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.props.LifeState;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.LifeStateChangeNotifyOuterClass.LifeStateChangeNotify;
import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType;
import emu.grasscutter.net.proto.ServerBuffOuterClass.ServerBuff;
import java.util.ArrayList;
public class PacketLifeStateChangeNotify extends BasePacket {
public PacketLifeStateChangeNotify(GameEntity target, LifeState lifeState) {
super(PacketOpcodes.LifeStateChangeNotify);
LifeStateChangeNotify proto = LifeStateChangeNotify.newBuilder()
.setEntityId(target.getId())
.setLifeState(lifeState.getValue())
.build();
this.setData(proto);
}
public PacketLifeStateChangeNotify(GameEntity attacker, GameEntity target, LifeState lifeState) {
super(PacketOpcodes.LifeStateChangeNotify);
......
......@@ -36,7 +36,7 @@ public class PacketSceneEntityAppearNotify extends BasePacket {
this(player.getTeamManager().getCurrentAvatarEntity());
}
public PacketSceneEntityAppearNotify(Collection<GameEntity> entities, VisionType visionType) {
public PacketSceneEntityAppearNotify(Collection<? extends GameEntity> entities, VisionType visionType) {
super(PacketOpcodes.SceneEntityAppearNotify, true);
SceneEntityAppearNotify.Builder proto = SceneEntityAppearNotify.newBuilder()
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.entity.gadget.GadgetWorktop;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WorktopOptionNotifyOuterClass.WorktopOptionNotify;
......@@ -13,8 +14,8 @@ public class PacketWorktopOptionNotify extends BasePacket {
WorktopOptionNotify.Builder proto = WorktopOptionNotify.newBuilder()
.setGadgetEntityId(gadget.getId());
if (gadget.getWorktopOptions() != null) {
proto.addAllOptionList(gadget.getWorktopOptions());
if (gadget.getContent() instanceof GadgetWorktop worktop) {
proto.addAllOptionList(worktop.getWorktopOptions());
}
this.setData(proto);
......
......@@ -137,6 +137,9 @@ public class ConfigContainer {
public int bindPort = 22102;
/* This is the port used in the default region. */
public int accessPort = 0;
/* Entities within a certain range will be loaded for the player */
public int loadEntitiesForPlayerRange = 100;
public boolean enableScriptInBigWorld = false;
public boolean enableConsole = true;
public GameOptions gameOptions = new GameOptions();
public JoinOptions joinOptions = new JoinOptions();
......
......@@ -9,6 +9,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
......
......@@ -3,7 +3,7 @@ package emu.grasscutter.utils;
import java.io.Serializable;
import com.google.gson.annotations.SerializedName;
import com.github.davidmoten.rtreemulti.geometry.Point;
import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
......@@ -162,4 +162,20 @@ public class Position implements Serializable {
.setZ(this.getZ())
.build();
}
public Point toPoint(){
return Point.create(x,y,z);
}
/**
* To XYZ array for Spatial Index
*/
public double[] toDoubleArray(){
return new double[]{ x, y, z};
}
/**
* To XZ array for Spatial Index (Blocks)
*/
public double[] toXZDoubleArray(){
return new double[]{x, z};
}
}
[
{
"objNames" : [
"SceneObj_Chest_Default_Lv1",
"SceneObj_Chest_Locked_Lv1",
"SceneObj_Chest_Bramble_Lv1",
"SceneObj_Chest_Frozen_Lv1",
"SceneObj_Chest_Rock_Lv1",
"SceneObj_EssenceChest_Default_Lv1",
"SceneObj_EssenceChest_Locked_Lv1"
],
"advExp" : 10,
"resin" : 0,
"mora" : 257,
"sigil" : 1,
"content" : [
{
"itemId" : 104011,
"count": 3
},
{
"itemId" : 104001,
"count": 1
}
],
"randomCount": 4,
"randomContent": [
{
"itemId" : 11101,
"count": 1
},
{
"itemId" : 11201,
"count": 1
},
{
"itemId" : 12101,
"count": 1
},
{
"itemId" : 12201,
"count": 1
},
{
"itemId" : 13101,
"count": 1
},
{
"itemId" : 13201,
"count": 1
},
{
"itemId" : 14101,
"count": 1
},
{
"itemId" : 14201,
"count": 1
},
{
"itemId" : 15101,
"count": 1
},
{
"itemId" : 15201,
"count": 1
}
]
},
{
"objNames" : [
"SceneObj_Chest_Default_Lv2",
"SceneObj_Chest_Locked_Lv2",
"SceneObj_Chest_Bramble_Lv2",
"SceneObj_Chest_Frozen_Lv2"
],
"advExp" : 20,
"resin" : 2,
"mora" : 756,
"sigil" : 2,
"content" : [
{
"itemId" : 104012,
"count": 3
},
{
"itemId" : 104002,
"count": 1
}
],
"randomCount": 4,
"randomContent": [
{
"itemId" : 11201,
"count": 1
},
{
"itemId" : 11301,
"count": 1
},
{
"itemId" : 12201,
"count": 1
},
{
"itemId" : 12301,
"count": 1
},
{
"itemId" : 13201,
"count": 1
},
{
"itemId" : 13301,
"count": 1
},
{
"itemId" : 14201,
"count": 1
},
{
"itemId" : 14301,
"count": 1
},
{
"itemId" : 15201,
"count": 1
},
{
"itemId" : 15301,
"count": 1
}
]
}
]
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment