From b92cc6a88287a3b4dd7070104b87d89879d78c96 Mon Sep 17 00:00:00 2001 From: Akka <104902222+Akka0@users.noreply.github.com> Date: Sun, 3 Jul 2022 15:56:18 +0800 Subject: [PATCH] fix some region errors --- .../grasscutter/game/entity/EntityRegion.java | 4 ++ .../scripts/SceneScriptManager.java | 19 +++++--- .../emu/grasscutter/scripts/ScriptLib.java | 47 +++++++++++++++++++ .../emu/grasscutter/scripts/ScriptLoader.java | 5 ++ .../grasscutter/scripts/data/ScriptArgs.java | 13 ++++- .../send/PacketDungeonShowReminderNotify.java | 18 +++++++ .../packet/send/PacketGroupSuiteNotify.java | 5 +- 7 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketDungeonShowReminderNotify.java diff --git a/src/main/java/emu/grasscutter/game/entity/EntityRegion.java b/src/main/java/emu/grasscutter/game/entity/EntityRegion.java index 5a09b7442..20c135fba 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityRegion.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityRegion.java @@ -71,4 +71,8 @@ public class EntityRegion extends GameEntity{ */ return null; } + + public int getFirstEntityId() { + return entities.stream().findFirst().orElse(0); + } } diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index da2323e5c..fa05a21a7 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -7,6 +7,7 @@ import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.MonsterData; import emu.grasscutter.data.excels.WorldLevelData; import emu.grasscutter.game.entity.*; +import emu.grasscutter.game.props.EntityType; import emu.grasscutter.game.world.Scene; import emu.grasscutter.net.proto.VisionTypeOuterClass; import emu.grasscutter.scripts.constants.EventType; @@ -167,11 +168,11 @@ public class SceneScriptManager { public boolean isInit() { return isInit; } - + public void loadBlockFromScript(SceneBlock block) { block.load(scene.getId(), meta.context); } - + public void loadGroupFromScript(SceneGroup group) { group.load(getScene().getId()); @@ -188,13 +189,17 @@ public class SceneScriptManager { } for (var region : this.regions.values()) { + // currently all condition_ENTER_REGION Events check for avatar, so we have no necessary to add other types of entity getScene().getEntities().values() .stream() - .filter(e -> e.getEntityType() <= 2 && region.getMetaRegion().contains(e.getPosition())) + .filter(e -> e.getEntityType() == EntityType.Avatar.getValue() && region.getMetaRegion().contains(e.getPosition())) .forEach(region::addEntity); if (region.hasNewEntities()) { - callEvent(EventType.EVENT_ENTER_REGION, new ScriptArgs(region.getConfigId()).setSourceEntityId(region.getId())); + callEvent(EventType.EVENT_ENTER_REGION, new ScriptArgs(region.getConfigId()) + .setSourceEntityId(region.getId()) + .setTargetEntityId(region.getFirstEntityId()) + ); region.resetNewEntities(); } @@ -409,18 +414,18 @@ public class SceneScriptManager { this.getScriptMonsterSpawnService() .onMonsterCreatedListener.forEach(action -> action.onNotify(entity)); - + return entity; } public void addEntity(GameEntity gameEntity){ getScene().addEntity(gameEntity); } - + public void meetEntities(List gameEntity){ getScene().addEntities(gameEntity, VisionTypeOuterClass.VisionType.VISION_TYPE_MEET); } - + public void addEntities(List gameEntity){ getScene().addEntities(gameEntity); } diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index 494282299..39ee908b5 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -6,9 +6,13 @@ import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.gadget.GadgetWorktop; import emu.grasscutter.game.dungeons.challenge.factory.ChallengeFactory; +import emu.grasscutter.game.props.EntityType; +import emu.grasscutter.game.quest.enums.QuestState; +import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.scripts.data.SceneGroup; import emu.grasscutter.scripts.data.SceneRegion; import emu.grasscutter.server.packet.send.PacketCanUseSkillNotify; +import emu.grasscutter.server.packet.send.PacketDungeonShowReminderNotify; import emu.grasscutter.server.packet.send.PacketWorktopOptionNotify; import io.netty.util.concurrent.FastThreadLocal; import org.luaj.vm2.LuaTable; @@ -502,4 +506,47 @@ public class ScriptLib { return 1; } + + public int GetEntityType(int entityId){ + var entity = getSceneScriptManager().getScene().getEntityById(entityId); + if(entity == null){ + return EntityType.None.getValue(); + } + + return entity.getEntityType(); + } + + public int GetQuestState(int entityId, int questId){ + var player = getSceneScriptManager().getScene().getWorld().getHost(); + + var quest = player.getQuestManager().getQuestById(questId); + if(quest == null){ + return QuestState.QUEST_STATE_NONE.getValue(); + } + + return quest.getState().getValue(); + } + + public int ShowReminder(int reminderId){ + getSceneScriptManager().getScene().broadcastPacket(new PacketDungeonShowReminderNotify(reminderId)); + return 0; + } + + public int RemoveEntityByConfigId(int groupId, int entityType, int configId){ + logger.debug("[LUA] Call RemoveEntityByConfigId"); + + var entity = getSceneScriptManager().getScene().getEntities().values().stream() + .filter(e -> e.getGroupId() == groupId) + .filter(e -> e.getEntityType() == entityType) + .filter(e -> e.getConfigId() == configId) + .findFirst(); + + if(entity.isEmpty()){ + return 1; + } + + getSceneScriptManager().getScene().removeEntity(entity.get()); + + return 0; + } } diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLoader.java b/src/main/java/emu/grasscutter/scripts/ScriptLoader.java index 9ee97fd4d..3cb0031cf 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLoader.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLoader.java @@ -2,6 +2,7 @@ package emu.grasscutter.scripts; import emu.grasscutter.Grasscutter; import emu.grasscutter.game.props.EntityType; +import emu.grasscutter.game.quest.enums.QuestState; import emu.grasscutter.scripts.constants.EventType; import emu.grasscutter.scripts.constants.ScriptGadgetState; import emu.grasscutter.scripts.constants.ScriptRegionShape; @@ -67,6 +68,10 @@ public class ScriptLoader { Arrays.stream(EntityType.values()).forEach(e -> table.set(e.name().toUpperCase(), e.getValue())); ctx.globals.set("EntityType", table); + LuaTable table1 = new LuaTable(); + Arrays.stream(QuestState.values()).forEach(e -> table1.set(e.name().toUpperCase(), e.getValue())); + ctx.globals.set("QuestState", table1); + ctx.globals.set("EventType", CoerceJavaToLua.coerce(new EventType())); // TODO - make static class to avoid instantiating a new class every scene ctx.globals.set("GadgetState", CoerceJavaToLua.coerce(new ScriptGadgetState())); ctx.globals.set("RegionShape", CoerceJavaToLua.coerce(new ScriptRegionShape())); diff --git a/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java b/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java index a1f183b63..daa5e0342 100644 --- a/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java +++ b/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java @@ -5,9 +5,9 @@ public class ScriptArgs { public int param2; public int param3; public int source_eid; // Source entity - + public int target_eid; public ScriptArgs() { - + } public ScriptArgs(int param1) { @@ -54,4 +54,13 @@ public class ScriptArgs { this.source_eid = source_eid; return this; } + + public int getTargetEntityId() { + return target_eid; + } + + public ScriptArgs setTargetEntityId(int target_eid) { + this.target_eid = target_eid; + return this; + } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonShowReminderNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonShowReminderNotify.java new file mode 100644 index 000000000..daf1606f3 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonShowReminderNotify.java @@ -0,0 +1,18 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonShowReminderNotifyOuterClass; + +public class PacketDungeonShowReminderNotify extends BasePacket { + + public PacketDungeonShowReminderNotify(int reminderId) { + super(PacketOpcodes.DungeonShowReminderNotify); + + var proto = DungeonShowReminderNotifyOuterClass.DungeonShowReminderNotify.newBuilder(); + + proto.setReminderId(reminderId); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGroupSuiteNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGroupSuiteNotify.java index 59c5a83a3..5a79b2ef1 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGroupSuiteNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGroupSuiteNotify.java @@ -18,8 +18,9 @@ public class PacketGroupSuiteNotify extends BasePacket { var proto = GroupSuiteNotifyOuterClass.GroupSuiteNotify.newBuilder(); - npcBornEntries.forEach(x -> - x.getSuiteIdList().forEach(y -> + npcBornEntries.stream() + .filter(x -> x.getGroupId() > 0 && x.getSuiteIdList() != null) + .forEach(x -> x.getSuiteIdList().forEach(y -> proto.putGroupMap(x.getGroupId(), y) ));