From 68978dc0f23b0126af02d5635c19c849b3e8fb38 Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Sun, 15 Oct 2023 07:04:44 -0700 Subject: [PATCH] Fix battle start logic with assisting monsters --- .../proto/SceneCastSkillCsReqOuterClass.java | 168 +++++++++--------- .../lunarcore/game/battle/BattleService.java | 32 ++-- .../recv/HandlerSceneCastSkillCsReq.java | 14 +- 3 files changed, 117 insertions(+), 97 deletions(-) diff --git a/src/generated/main/emu/lunarcore/proto/SceneCastSkillCsReqOuterClass.java b/src/generated/main/emu/lunarcore/proto/SceneCastSkillCsReqOuterClass.java index 43a9c66..947f2af 100644 --- a/src/generated/main/emu/lunarcore/proto/SceneCastSkillCsReqOuterClass.java +++ b/src/generated/main/emu/lunarcore/proto/SceneCastSkillCsReqOuterClass.java @@ -40,14 +40,14 @@ public final class SceneCastSkillCsReqOuterClass { private final MotionInfoOuterClass.MotionInfo targetMotion = MotionInfoOuterClass.MotionInfo.newInstance(); /** - * repeated uint32 cast_entity_id_list = 12; + * repeated uint32 assist_monster_id_list = 12; */ - private final RepeatedInt castEntityIdList = RepeatedInt.newEmptyInstance(); + private final RepeatedInt assistMonsterIdList = RepeatedInt.newEmptyInstance(); /** - * repeated uint32 attacked_entity_id_list = 15; + * repeated uint32 hit_target_id_list = 15; */ - private final RepeatedInt attackedEntityIdList = RepeatedInt.newEmptyInstance(); + private final RepeatedInt hitTargetIdList = RepeatedInt.newEmptyInstance(); private SceneCastSkillCsReq() { } @@ -228,39 +228,39 @@ public final class SceneCastSkillCsReqOuterClass { } /** - * repeated uint32 cast_entity_id_list = 12; - * @return whether the castEntityIdList field is set + * repeated uint32 assist_monster_id_list = 12; + * @return whether the assistMonsterIdList field is set */ - public boolean hasCastEntityIdList() { + public boolean hasAssistMonsterIdList() { return (bitField0_ & 0x00000010) != 0; } /** - * repeated uint32 cast_entity_id_list = 12; + * repeated uint32 assist_monster_id_list = 12; * @return this */ - public SceneCastSkillCsReq clearCastEntityIdList() { + public SceneCastSkillCsReq clearAssistMonsterIdList() { bitField0_ &= ~0x00000010; - castEntityIdList.clear(); + assistMonsterIdList.clear(); return this; } /** - * repeated uint32 cast_entity_id_list = 12; + * repeated uint32 assist_monster_id_list = 12; * * This method returns the internal storage object without modifying any has state. * The returned object should not be modified and be treated as read-only. * - * Use {@link #getMutableCastEntityIdList()} if you want to modify it. + * Use {@link #getMutableAssistMonsterIdList()} if you want to modify it. * * @return internal storage object for reading */ - public RepeatedInt getCastEntityIdList() { - return castEntityIdList; + public RepeatedInt getAssistMonsterIdList() { + return assistMonsterIdList; } /** - * repeated uint32 cast_entity_id_list = 12; + * repeated uint32 assist_monster_id_list = 12; * * This method returns the internal storage object and sets the corresponding * has state. The returned object will become part of this message and its @@ -268,67 +268,67 @@ public final class SceneCastSkillCsReqOuterClass { * * @return internal storage object for modifications */ - public RepeatedInt getMutableCastEntityIdList() { + public RepeatedInt getMutableAssistMonsterIdList() { bitField0_ |= 0x00000010; - return castEntityIdList; + return assistMonsterIdList; } /** - * repeated uint32 cast_entity_id_list = 12; - * @param value the castEntityIdList to add + * repeated uint32 assist_monster_id_list = 12; + * @param value the assistMonsterIdList to add * @return this */ - public SceneCastSkillCsReq addCastEntityIdList(final int value) { + public SceneCastSkillCsReq addAssistMonsterIdList(final int value) { bitField0_ |= 0x00000010; - castEntityIdList.add(value); + assistMonsterIdList.add(value); return this; } /** - * repeated uint32 cast_entity_id_list = 12; - * @param values the castEntityIdList to add + * repeated uint32 assist_monster_id_list = 12; + * @param values the assistMonsterIdList to add * @return this */ - public SceneCastSkillCsReq addAllCastEntityIdList(final int... values) { + public SceneCastSkillCsReq addAllAssistMonsterIdList(final int... values) { bitField0_ |= 0x00000010; - castEntityIdList.addAll(values); + assistMonsterIdList.addAll(values); return this; } /** - * repeated uint32 attacked_entity_id_list = 15; - * @return whether the attackedEntityIdList field is set + * repeated uint32 hit_target_id_list = 15; + * @return whether the hitTargetIdList field is set */ - public boolean hasAttackedEntityIdList() { + public boolean hasHitTargetIdList() { return (bitField0_ & 0x00000020) != 0; } /** - * repeated uint32 attacked_entity_id_list = 15; + * repeated uint32 hit_target_id_list = 15; * @return this */ - public SceneCastSkillCsReq clearAttackedEntityIdList() { + public SceneCastSkillCsReq clearHitTargetIdList() { bitField0_ &= ~0x00000020; - attackedEntityIdList.clear(); + hitTargetIdList.clear(); return this; } /** - * repeated uint32 attacked_entity_id_list = 15; + * repeated uint32 hit_target_id_list = 15; * * This method returns the internal storage object without modifying any has state. * The returned object should not be modified and be treated as read-only. * - * Use {@link #getMutableAttackedEntityIdList()} if you want to modify it. + * Use {@link #getMutableHitTargetIdList()} if you want to modify it. * * @return internal storage object for reading */ - public RepeatedInt getAttackedEntityIdList() { - return attackedEntityIdList; + public RepeatedInt getHitTargetIdList() { + return hitTargetIdList; } /** - * repeated uint32 attacked_entity_id_list = 15; + * repeated uint32 hit_target_id_list = 15; * * This method returns the internal storage object and sets the corresponding * has state. The returned object will become part of this message and its @@ -336,30 +336,30 @@ public final class SceneCastSkillCsReqOuterClass { * * @return internal storage object for modifications */ - public RepeatedInt getMutableAttackedEntityIdList() { + public RepeatedInt getMutableHitTargetIdList() { bitField0_ |= 0x00000020; - return attackedEntityIdList; + return hitTargetIdList; } /** - * repeated uint32 attacked_entity_id_list = 15; - * @param value the attackedEntityIdList to add + * repeated uint32 hit_target_id_list = 15; + * @param value the hitTargetIdList to add * @return this */ - public SceneCastSkillCsReq addAttackedEntityIdList(final int value) { + public SceneCastSkillCsReq addHitTargetIdList(final int value) { bitField0_ |= 0x00000020; - attackedEntityIdList.add(value); + hitTargetIdList.add(value); return this; } /** - * repeated uint32 attacked_entity_id_list = 15; - * @param values the attackedEntityIdList to add + * repeated uint32 hit_target_id_list = 15; + * @param values the hitTargetIdList to add * @return this */ - public SceneCastSkillCsReq addAllAttackedEntityIdList(final int... values) { + public SceneCastSkillCsReq addAllHitTargetIdList(final int... values) { bitField0_ |= 0x00000020; - attackedEntityIdList.addAll(values); + hitTargetIdList.addAll(values); return this; } @@ -372,8 +372,8 @@ public final class SceneCastSkillCsReqOuterClass { casterId = other.casterId; attackedGroupId = other.attackedGroupId; targetMotion.copyFrom(other.targetMotion); - castEntityIdList.copyFrom(other.castEntityIdList); - attackedEntityIdList.copyFrom(other.attackedEntityIdList); + assistMonsterIdList.copyFrom(other.assistMonsterIdList); + hitTargetIdList.copyFrom(other.hitTargetIdList); } return this; } @@ -396,11 +396,11 @@ public final class SceneCastSkillCsReqOuterClass { if (other.hasTargetMotion()) { getMutableTargetMotion().mergeFrom(other.targetMotion); } - if (other.hasCastEntityIdList()) { - getMutableCastEntityIdList().addAll(other.castEntityIdList); + if (other.hasAssistMonsterIdList()) { + getMutableAssistMonsterIdList().addAll(other.assistMonsterIdList); } - if (other.hasAttackedEntityIdList()) { - getMutableAttackedEntityIdList().addAll(other.attackedEntityIdList); + if (other.hasHitTargetIdList()) { + getMutableHitTargetIdList().addAll(other.hitTargetIdList); } return this; } @@ -416,8 +416,8 @@ public final class SceneCastSkillCsReqOuterClass { casterId = 0; attackedGroupId = 0; targetMotion.clear(); - castEntityIdList.clear(); - attackedEntityIdList.clear(); + assistMonsterIdList.clear(); + hitTargetIdList.clear(); return this; } @@ -429,8 +429,8 @@ public final class SceneCastSkillCsReqOuterClass { cachedSize = -1; bitField0_ = 0; targetMotion.clearQuick(); - castEntityIdList.clear(); - attackedEntityIdList.clear(); + assistMonsterIdList.clear(); + hitTargetIdList.clear(); return this; } @@ -448,8 +448,8 @@ public final class SceneCastSkillCsReqOuterClass { && (!hasCasterId() || casterId == other.casterId) && (!hasAttackedGroupId() || attackedGroupId == other.attackedGroupId) && (!hasTargetMotion() || targetMotion.equals(other.targetMotion)) - && (!hasCastEntityIdList() || castEntityIdList.equals(other.castEntityIdList)) - && (!hasAttackedEntityIdList() || attackedEntityIdList.equals(other.attackedEntityIdList)); + && (!hasAssistMonsterIdList() || assistMonsterIdList.equals(other.assistMonsterIdList)) + && (!hasHitTargetIdList() || hitTargetIdList.equals(other.hitTargetIdList)); } @Override @@ -471,15 +471,15 @@ public final class SceneCastSkillCsReqOuterClass { output.writeMessageNoTag(targetMotion); } if ((bitField0_ & 0x00000010) != 0) { - for (int i = 0; i < castEntityIdList.length(); i++) { + for (int i = 0; i < assistMonsterIdList.length(); i++) { output.writeRawByte((byte) 96); - output.writeUInt32NoTag(castEntityIdList.array()[i]); + output.writeUInt32NoTag(assistMonsterIdList.array()[i]); } } if ((bitField0_ & 0x00000020) != 0) { - for (int i = 0; i < attackedEntityIdList.length(); i++) { + for (int i = 0; i < hitTargetIdList.length(); i++) { output.writeRawByte((byte) 120); - output.writeUInt32NoTag(attackedEntityIdList.array()[i]); + output.writeUInt32NoTag(hitTargetIdList.array()[i]); } } } @@ -500,10 +500,10 @@ public final class SceneCastSkillCsReqOuterClass { size += 1 + ProtoSink.computeMessageSizeNoTag(targetMotion); } if ((bitField0_ & 0x00000010) != 0) { - size += (1 * castEntityIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(castEntityIdList); + size += (1 * assistMonsterIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(assistMonsterIdList); } if ((bitField0_ & 0x00000020) != 0) { - size += (1 * attackedEntityIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(attackedEntityIdList); + size += (1 * hitTargetIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(hitTargetIdList); } return size; } @@ -552,8 +552,8 @@ public final class SceneCastSkillCsReqOuterClass { } } case 98: { - // castEntityIdList [packed=true] - input.readPackedUInt32(castEntityIdList, tag); + // assistMonsterIdList [packed=true] + input.readPackedUInt32(assistMonsterIdList, tag); bitField0_ |= 0x00000010; tag = input.readTag(); if (tag != 122) { @@ -561,8 +561,8 @@ public final class SceneCastSkillCsReqOuterClass { } } case 122: { - // attackedEntityIdList [packed=true] - input.readPackedUInt32(attackedEntityIdList, tag); + // hitTargetIdList [packed=true] + input.readPackedUInt32(hitTargetIdList, tag); bitField0_ |= 0x00000020; tag = input.readTag(); if (tag != 0) { @@ -580,14 +580,14 @@ public final class SceneCastSkillCsReqOuterClass { break; } case 96: { - // castEntityIdList [packed=false] - tag = input.readRepeatedUInt32(castEntityIdList, tag); + // assistMonsterIdList [packed=false] + tag = input.readRepeatedUInt32(assistMonsterIdList, tag); bitField0_ |= 0x00000010; break; } case 120: { - // attackedEntityIdList [packed=false] - tag = input.readRepeatedUInt32(attackedEntityIdList, tag); + // hitTargetIdList [packed=false] + tag = input.readRepeatedUInt32(hitTargetIdList, tag); bitField0_ |= 0x00000020; break; } @@ -611,10 +611,10 @@ public final class SceneCastSkillCsReqOuterClass { output.writeMessage(FieldNames.targetMotion, targetMotion); } if ((bitField0_ & 0x00000010) != 0) { - output.writeRepeatedUInt32(FieldNames.castEntityIdList, castEntityIdList); + output.writeRepeatedUInt32(FieldNames.assistMonsterIdList, assistMonsterIdList); } if ((bitField0_ & 0x00000020) != 0) { - output.writeRepeatedUInt32(FieldNames.attackedEntityIdList, attackedEntityIdList); + output.writeRepeatedUInt32(FieldNames.hitTargetIdList, hitTargetIdList); } output.endObject(); } @@ -674,11 +674,11 @@ public final class SceneCastSkillCsReqOuterClass { } break; } - case -182636805: - case -1429767706: { - if (input.isAtField(FieldNames.castEntityIdList)) { + case -1198312214: + case -1972457465: { + if (input.isAtField(FieldNames.assistMonsterIdList)) { if (!input.trySkipNullValue()) { - input.readRepeatedUInt32(castEntityIdList); + input.readRepeatedUInt32(assistMonsterIdList); bitField0_ |= 0x00000010; } } else { @@ -686,11 +686,11 @@ public final class SceneCastSkillCsReqOuterClass { } break; } - case -849608541: - case 1628923710: { - if (input.isAtField(FieldNames.attackedEntityIdList)) { + case 269057149: + case 197471936: { + if (input.isAtField(FieldNames.hitTargetIdList)) { if (!input.trySkipNullValue()) { - input.readRepeatedUInt32(attackedEntityIdList); + input.readRepeatedUInt32(hitTargetIdList); bitField0_ |= 0x00000020; } } else { @@ -759,9 +759,9 @@ public final class SceneCastSkillCsReqOuterClass { static final FieldName targetMotion = FieldName.forField("targetMotion", "target_motion"); - static final FieldName castEntityIdList = FieldName.forField("castEntityIdList", "cast_entity_id_list"); + static final FieldName assistMonsterIdList = FieldName.forField("assistMonsterIdList", "assist_monster_id_list"); - static final FieldName attackedEntityIdList = FieldName.forField("attackedEntityIdList", "attacked_entity_id_list"); + static final FieldName hitTargetIdList = FieldName.forField("hitTargetIdList", "hit_target_id_list"); } } } diff --git a/src/main/java/emu/lunarcore/game/battle/BattleService.java b/src/main/java/emu/lunarcore/game/battle/BattleService.java index 9737bad..412e8fe 100644 --- a/src/main/java/emu/lunarcore/game/battle/BattleService.java +++ b/src/main/java/emu/lunarcore/game/battle/BattleService.java @@ -22,7 +22,7 @@ import emu.lunarcore.server.packet.send.PacketSceneCastSkillScRsp; import emu.lunarcore.server.packet.send.PacketStartCocoonStageScRsp; import emu.lunarcore.server.packet.send.PacketSyncLineupNotify; -import us.hebi.quickbuf.RepeatedInt; +import it.unimi.dsi.fastutil.ints.IntSet; public class BattleService extends BaseGameService { @@ -30,7 +30,7 @@ public class BattleService extends BaseGameService { super(server); } - public void startBattle(Player player, int casterId, int attackedGroupId, boolean castedSkill, RepeatedInt attackedList) { + public void startBattle(Player player, int casterId, int attackedGroupId, boolean castedSkill, IntSet targetList) { // Sanity check to make sure player isnt in a battle if (player.isInBattle()) { player.sendPacket(new PacketSceneCastSkillScRsp()); @@ -38,19 +38,17 @@ public class BattleService extends BaseGameService { } // Setup variables - List entities = new ArrayList<>(); - List monsters = new ArrayList<>(); - + List targetEntities = new ArrayList<>(); boolean isPlayerCaster = false; // Set true if the player is the one casting // Check if attacker is the player or not if (player.getScene().getAvatarEntityIds().contains(casterId)) { - // Attacker is the player - for (int entityId : attackedList) { + // Player is the attacker + for (int entityId : targetList) { GameEntity entity = player.getScene().getEntities().get(entityId); if (entity != null) { - entities.add(entity); + targetEntities.add(entity); } } @@ -60,18 +58,30 @@ public class BattleService extends BaseGameService { GameEntity entity = player.getScene().getEntities().get(casterId); if (entity != null) { - entities.add(entity); + targetEntities.add(entity); + } + + // Add any assisting monsters from target list + for (int entityId : targetList) { + entity = player.getScene().getEntities().get(entityId); + + if (entity != null) { + targetEntities.add(entity); + } } } // Give the client an error if no attacked entities detected - if (entities.size() == 0) { + if (targetEntities.size() == 0) { player.sendPacket(new PacketSceneCastSkillScRsp()); return; } + // Monster list + List monsters = new ArrayList<>(); + // Destroy props - var it = entities.iterator(); + var it = targetEntities.iterator(); while (it.hasNext()) { GameEntity entity = it.next(); diff --git a/src/main/java/emu/lunarcore/server/packet/recv/HandlerSceneCastSkillCsReq.java b/src/main/java/emu/lunarcore/server/packet/recv/HandlerSceneCastSkillCsReq.java index 9155e6a..d9b0075 100644 --- a/src/main/java/emu/lunarcore/server/packet/recv/HandlerSceneCastSkillCsReq.java +++ b/src/main/java/emu/lunarcore/server/packet/recv/HandlerSceneCastSkillCsReq.java @@ -10,9 +10,13 @@ import emu.lunarcore.server.packet.PacketHandler; import emu.lunarcore.server.packet.send.PacketSceneCastSkillMpUpdateScNotify; import emu.lunarcore.server.packet.send.PacketSceneCastSkillScRsp; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; + @Opcodes(CmdId.SceneCastSkillCsReq) public class HandlerSceneCastSkillCsReq extends PacketHandler { + @SuppressWarnings("deprecation") @Override public void handle(GameSession session, byte[] header, byte[] data) throws Exception { var req = SceneCastSkillCsReq.parseFrom(data); @@ -34,8 +38,14 @@ public class HandlerSceneCastSkillCsReq extends PacketHandler { } } - if (req.hasAttackedEntityIdList()) { - session.getServer().getBattleService().startBattle(session.getPlayer(), req.getCasterId(), req.getAttackedGroupId(), castedSkill, req.getAttackedEntityIdList()); + if (req.hasHitTargetIdList()) { + // Create target list + IntSet targetList = new IntOpenHashSet(); + req.getHitTargetIdList().forEach(targetList::add); + req.getAssistMonsterIdList().forEach(targetList::add); + + // Start battle + session.getServer().getBattleService().startBattle(session.getPlayer(), req.getCasterId(), req.getAttackedGroupId(), castedSkill, targetList); } else { session.send(new PacketSceneCastSkillScRsp(req.getAttackedGroupId())); }