Fix battle start logic with assisting monsters

This commit is contained in:
Melledy
2023-10-15 07:04:44 -07:00
parent 4f45e54e12
commit 68978dc0f2
3 changed files with 117 additions and 97 deletions

View File

@@ -40,14 +40,14 @@ public final class SceneCastSkillCsReqOuterClass {
private final MotionInfoOuterClass.MotionInfo targetMotion = MotionInfoOuterClass.MotionInfo.newInstance(); private final MotionInfoOuterClass.MotionInfo targetMotion = MotionInfoOuterClass.MotionInfo.newInstance();
/** /**
* <code>repeated uint32 cast_entity_id_list = 12;</code> * <code>repeated uint32 assist_monster_id_list = 12;</code>
*/ */
private final RepeatedInt castEntityIdList = RepeatedInt.newEmptyInstance(); private final RepeatedInt assistMonsterIdList = RepeatedInt.newEmptyInstance();
/** /**
* <code>repeated uint32 attacked_entity_id_list = 15;</code> * <code>repeated uint32 hit_target_id_list = 15;</code>
*/ */
private final RepeatedInt attackedEntityIdList = RepeatedInt.newEmptyInstance(); private final RepeatedInt hitTargetIdList = RepeatedInt.newEmptyInstance();
private SceneCastSkillCsReq() { private SceneCastSkillCsReq() {
} }
@@ -228,39 +228,39 @@ public final class SceneCastSkillCsReqOuterClass {
} }
/** /**
* <code>repeated uint32 cast_entity_id_list = 12;</code> * <code>repeated uint32 assist_monster_id_list = 12;</code>
* @return whether the castEntityIdList field is set * @return whether the assistMonsterIdList field is set
*/ */
public boolean hasCastEntityIdList() { public boolean hasAssistMonsterIdList() {
return (bitField0_ & 0x00000010) != 0; return (bitField0_ & 0x00000010) != 0;
} }
/** /**
* <code>repeated uint32 cast_entity_id_list = 12;</code> * <code>repeated uint32 assist_monster_id_list = 12;</code>
* @return this * @return this
*/ */
public SceneCastSkillCsReq clearCastEntityIdList() { public SceneCastSkillCsReq clearAssistMonsterIdList() {
bitField0_ &= ~0x00000010; bitField0_ &= ~0x00000010;
castEntityIdList.clear(); assistMonsterIdList.clear();
return this; return this;
} }
/** /**
* <code>repeated uint32 cast_entity_id_list = 12;</code> * <code>repeated uint32 assist_monster_id_list = 12;</code>
* *
* This method returns the internal storage object without modifying any has state. * 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. * 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 * @return internal storage object for reading
*/ */
public RepeatedInt getCastEntityIdList() { public RepeatedInt getAssistMonsterIdList() {
return castEntityIdList; return assistMonsterIdList;
} }
/** /**
* <code>repeated uint32 cast_entity_id_list = 12;</code> * <code>repeated uint32 assist_monster_id_list = 12;</code>
* *
* This method returns the internal storage object and sets the corresponding * This method returns the internal storage object and sets the corresponding
* has state. The returned object will become part of this message and its * 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 * @return internal storage object for modifications
*/ */
public RepeatedInt getMutableCastEntityIdList() { public RepeatedInt getMutableAssistMonsterIdList() {
bitField0_ |= 0x00000010; bitField0_ |= 0x00000010;
return castEntityIdList; return assistMonsterIdList;
} }
/** /**
* <code>repeated uint32 cast_entity_id_list = 12;</code> * <code>repeated uint32 assist_monster_id_list = 12;</code>
* @param value the castEntityIdList to add * @param value the assistMonsterIdList to add
* @return this * @return this
*/ */
public SceneCastSkillCsReq addCastEntityIdList(final int value) { public SceneCastSkillCsReq addAssistMonsterIdList(final int value) {
bitField0_ |= 0x00000010; bitField0_ |= 0x00000010;
castEntityIdList.add(value); assistMonsterIdList.add(value);
return this; return this;
} }
/** /**
* <code>repeated uint32 cast_entity_id_list = 12;</code> * <code>repeated uint32 assist_monster_id_list = 12;</code>
* @param values the castEntityIdList to add * @param values the assistMonsterIdList to add
* @return this * @return this
*/ */
public SceneCastSkillCsReq addAllCastEntityIdList(final int... values) { public SceneCastSkillCsReq addAllAssistMonsterIdList(final int... values) {
bitField0_ |= 0x00000010; bitField0_ |= 0x00000010;
castEntityIdList.addAll(values); assistMonsterIdList.addAll(values);
return this; return this;
} }
/** /**
* <code>repeated uint32 attacked_entity_id_list = 15;</code> * <code>repeated uint32 hit_target_id_list = 15;</code>
* @return whether the attackedEntityIdList field is set * @return whether the hitTargetIdList field is set
*/ */
public boolean hasAttackedEntityIdList() { public boolean hasHitTargetIdList() {
return (bitField0_ & 0x00000020) != 0; return (bitField0_ & 0x00000020) != 0;
} }
/** /**
* <code>repeated uint32 attacked_entity_id_list = 15;</code> * <code>repeated uint32 hit_target_id_list = 15;</code>
* @return this * @return this
*/ */
public SceneCastSkillCsReq clearAttackedEntityIdList() { public SceneCastSkillCsReq clearHitTargetIdList() {
bitField0_ &= ~0x00000020; bitField0_ &= ~0x00000020;
attackedEntityIdList.clear(); hitTargetIdList.clear();
return this; return this;
} }
/** /**
* <code>repeated uint32 attacked_entity_id_list = 15;</code> * <code>repeated uint32 hit_target_id_list = 15;</code>
* *
* This method returns the internal storage object without modifying any has state. * 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. * 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 * @return internal storage object for reading
*/ */
public RepeatedInt getAttackedEntityIdList() { public RepeatedInt getHitTargetIdList() {
return attackedEntityIdList; return hitTargetIdList;
} }
/** /**
* <code>repeated uint32 attacked_entity_id_list = 15;</code> * <code>repeated uint32 hit_target_id_list = 15;</code>
* *
* This method returns the internal storage object and sets the corresponding * This method returns the internal storage object and sets the corresponding
* has state. The returned object will become part of this message and its * 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 * @return internal storage object for modifications
*/ */
public RepeatedInt getMutableAttackedEntityIdList() { public RepeatedInt getMutableHitTargetIdList() {
bitField0_ |= 0x00000020; bitField0_ |= 0x00000020;
return attackedEntityIdList; return hitTargetIdList;
} }
/** /**
* <code>repeated uint32 attacked_entity_id_list = 15;</code> * <code>repeated uint32 hit_target_id_list = 15;</code>
* @param value the attackedEntityIdList to add * @param value the hitTargetIdList to add
* @return this * @return this
*/ */
public SceneCastSkillCsReq addAttackedEntityIdList(final int value) { public SceneCastSkillCsReq addHitTargetIdList(final int value) {
bitField0_ |= 0x00000020; bitField0_ |= 0x00000020;
attackedEntityIdList.add(value); hitTargetIdList.add(value);
return this; return this;
} }
/** /**
* <code>repeated uint32 attacked_entity_id_list = 15;</code> * <code>repeated uint32 hit_target_id_list = 15;</code>
* @param values the attackedEntityIdList to add * @param values the hitTargetIdList to add
* @return this * @return this
*/ */
public SceneCastSkillCsReq addAllAttackedEntityIdList(final int... values) { public SceneCastSkillCsReq addAllHitTargetIdList(final int... values) {
bitField0_ |= 0x00000020; bitField0_ |= 0x00000020;
attackedEntityIdList.addAll(values); hitTargetIdList.addAll(values);
return this; return this;
} }
@@ -372,8 +372,8 @@ public final class SceneCastSkillCsReqOuterClass {
casterId = other.casterId; casterId = other.casterId;
attackedGroupId = other.attackedGroupId; attackedGroupId = other.attackedGroupId;
targetMotion.copyFrom(other.targetMotion); targetMotion.copyFrom(other.targetMotion);
castEntityIdList.copyFrom(other.castEntityIdList); assistMonsterIdList.copyFrom(other.assistMonsterIdList);
attackedEntityIdList.copyFrom(other.attackedEntityIdList); hitTargetIdList.copyFrom(other.hitTargetIdList);
} }
return this; return this;
} }
@@ -396,11 +396,11 @@ public final class SceneCastSkillCsReqOuterClass {
if (other.hasTargetMotion()) { if (other.hasTargetMotion()) {
getMutableTargetMotion().mergeFrom(other.targetMotion); getMutableTargetMotion().mergeFrom(other.targetMotion);
} }
if (other.hasCastEntityIdList()) { if (other.hasAssistMonsterIdList()) {
getMutableCastEntityIdList().addAll(other.castEntityIdList); getMutableAssistMonsterIdList().addAll(other.assistMonsterIdList);
} }
if (other.hasAttackedEntityIdList()) { if (other.hasHitTargetIdList()) {
getMutableAttackedEntityIdList().addAll(other.attackedEntityIdList); getMutableHitTargetIdList().addAll(other.hitTargetIdList);
} }
return this; return this;
} }
@@ -416,8 +416,8 @@ public final class SceneCastSkillCsReqOuterClass {
casterId = 0; casterId = 0;
attackedGroupId = 0; attackedGroupId = 0;
targetMotion.clear(); targetMotion.clear();
castEntityIdList.clear(); assistMonsterIdList.clear();
attackedEntityIdList.clear(); hitTargetIdList.clear();
return this; return this;
} }
@@ -429,8 +429,8 @@ public final class SceneCastSkillCsReqOuterClass {
cachedSize = -1; cachedSize = -1;
bitField0_ = 0; bitField0_ = 0;
targetMotion.clearQuick(); targetMotion.clearQuick();
castEntityIdList.clear(); assistMonsterIdList.clear();
attackedEntityIdList.clear(); hitTargetIdList.clear();
return this; return this;
} }
@@ -448,8 +448,8 @@ public final class SceneCastSkillCsReqOuterClass {
&& (!hasCasterId() || casterId == other.casterId) && (!hasCasterId() || casterId == other.casterId)
&& (!hasAttackedGroupId() || attackedGroupId == other.attackedGroupId) && (!hasAttackedGroupId() || attackedGroupId == other.attackedGroupId)
&& (!hasTargetMotion() || targetMotion.equals(other.targetMotion)) && (!hasTargetMotion() || targetMotion.equals(other.targetMotion))
&& (!hasCastEntityIdList() || castEntityIdList.equals(other.castEntityIdList)) && (!hasAssistMonsterIdList() || assistMonsterIdList.equals(other.assistMonsterIdList))
&& (!hasAttackedEntityIdList() || attackedEntityIdList.equals(other.attackedEntityIdList)); && (!hasHitTargetIdList() || hitTargetIdList.equals(other.hitTargetIdList));
} }
@Override @Override
@@ -471,15 +471,15 @@ public final class SceneCastSkillCsReqOuterClass {
output.writeMessageNoTag(targetMotion); output.writeMessageNoTag(targetMotion);
} }
if ((bitField0_ & 0x00000010) != 0) { 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.writeRawByte((byte) 96);
output.writeUInt32NoTag(castEntityIdList.array()[i]); output.writeUInt32NoTag(assistMonsterIdList.array()[i]);
} }
} }
if ((bitField0_ & 0x00000020) != 0) { 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.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); size += 1 + ProtoSink.computeMessageSizeNoTag(targetMotion);
} }
if ((bitField0_ & 0x00000010) != 0) { if ((bitField0_ & 0x00000010) != 0) {
size += (1 * castEntityIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(castEntityIdList); size += (1 * assistMonsterIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(assistMonsterIdList);
} }
if ((bitField0_ & 0x00000020) != 0) { if ((bitField0_ & 0x00000020) != 0) {
size += (1 * attackedEntityIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(attackedEntityIdList); size += (1 * hitTargetIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(hitTargetIdList);
} }
return size; return size;
} }
@@ -552,8 +552,8 @@ public final class SceneCastSkillCsReqOuterClass {
} }
} }
case 98: { case 98: {
// castEntityIdList [packed=true] // assistMonsterIdList [packed=true]
input.readPackedUInt32(castEntityIdList, tag); input.readPackedUInt32(assistMonsterIdList, tag);
bitField0_ |= 0x00000010; bitField0_ |= 0x00000010;
tag = input.readTag(); tag = input.readTag();
if (tag != 122) { if (tag != 122) {
@@ -561,8 +561,8 @@ public final class SceneCastSkillCsReqOuterClass {
} }
} }
case 122: { case 122: {
// attackedEntityIdList [packed=true] // hitTargetIdList [packed=true]
input.readPackedUInt32(attackedEntityIdList, tag); input.readPackedUInt32(hitTargetIdList, tag);
bitField0_ |= 0x00000020; bitField0_ |= 0x00000020;
tag = input.readTag(); tag = input.readTag();
if (tag != 0) { if (tag != 0) {
@@ -580,14 +580,14 @@ public final class SceneCastSkillCsReqOuterClass {
break; break;
} }
case 96: { case 96: {
// castEntityIdList [packed=false] // assistMonsterIdList [packed=false]
tag = input.readRepeatedUInt32(castEntityIdList, tag); tag = input.readRepeatedUInt32(assistMonsterIdList, tag);
bitField0_ |= 0x00000010; bitField0_ |= 0x00000010;
break; break;
} }
case 120: { case 120: {
// attackedEntityIdList [packed=false] // hitTargetIdList [packed=false]
tag = input.readRepeatedUInt32(attackedEntityIdList, tag); tag = input.readRepeatedUInt32(hitTargetIdList, tag);
bitField0_ |= 0x00000020; bitField0_ |= 0x00000020;
break; break;
} }
@@ -611,10 +611,10 @@ public final class SceneCastSkillCsReqOuterClass {
output.writeMessage(FieldNames.targetMotion, targetMotion); output.writeMessage(FieldNames.targetMotion, targetMotion);
} }
if ((bitField0_ & 0x00000010) != 0) { if ((bitField0_ & 0x00000010) != 0) {
output.writeRepeatedUInt32(FieldNames.castEntityIdList, castEntityIdList); output.writeRepeatedUInt32(FieldNames.assistMonsterIdList, assistMonsterIdList);
} }
if ((bitField0_ & 0x00000020) != 0) { if ((bitField0_ & 0x00000020) != 0) {
output.writeRepeatedUInt32(FieldNames.attackedEntityIdList, attackedEntityIdList); output.writeRepeatedUInt32(FieldNames.hitTargetIdList, hitTargetIdList);
} }
output.endObject(); output.endObject();
} }
@@ -674,11 +674,11 @@ public final class SceneCastSkillCsReqOuterClass {
} }
break; break;
} }
case -182636805: case -1198312214:
case -1429767706: { case -1972457465: {
if (input.isAtField(FieldNames.castEntityIdList)) { if (input.isAtField(FieldNames.assistMonsterIdList)) {
if (!input.trySkipNullValue()) { if (!input.trySkipNullValue()) {
input.readRepeatedUInt32(castEntityIdList); input.readRepeatedUInt32(assistMonsterIdList);
bitField0_ |= 0x00000010; bitField0_ |= 0x00000010;
} }
} else { } else {
@@ -686,11 +686,11 @@ public final class SceneCastSkillCsReqOuterClass {
} }
break; break;
} }
case -849608541: case 269057149:
case 1628923710: { case 197471936: {
if (input.isAtField(FieldNames.attackedEntityIdList)) { if (input.isAtField(FieldNames.hitTargetIdList)) {
if (!input.trySkipNullValue()) { if (!input.trySkipNullValue()) {
input.readRepeatedUInt32(attackedEntityIdList); input.readRepeatedUInt32(hitTargetIdList);
bitField0_ |= 0x00000020; bitField0_ |= 0x00000020;
} }
} else { } else {
@@ -759,9 +759,9 @@ public final class SceneCastSkillCsReqOuterClass {
static final FieldName targetMotion = FieldName.forField("targetMotion", "target_motion"); 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");
} }
} }
} }

View File

@@ -22,7 +22,7 @@ import emu.lunarcore.server.packet.send.PacketSceneCastSkillScRsp;
import emu.lunarcore.server.packet.send.PacketStartCocoonStageScRsp; import emu.lunarcore.server.packet.send.PacketStartCocoonStageScRsp;
import emu.lunarcore.server.packet.send.PacketSyncLineupNotify; import emu.lunarcore.server.packet.send.PacketSyncLineupNotify;
import us.hebi.quickbuf.RepeatedInt; import it.unimi.dsi.fastutil.ints.IntSet;
public class BattleService extends BaseGameService { public class BattleService extends BaseGameService {
@@ -30,7 +30,7 @@ public class BattleService extends BaseGameService {
super(server); 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 // Sanity check to make sure player isnt in a battle
if (player.isInBattle()) { if (player.isInBattle()) {
player.sendPacket(new PacketSceneCastSkillScRsp()); player.sendPacket(new PacketSceneCastSkillScRsp());
@@ -38,19 +38,17 @@ public class BattleService extends BaseGameService {
} }
// Setup variables // Setup variables
List<GameEntity> entities = new ArrayList<>(); List<GameEntity> targetEntities = new ArrayList<>();
List<EntityMonster> monsters = new ArrayList<>();
boolean isPlayerCaster = false; // Set true if the player is the one casting boolean isPlayerCaster = false; // Set true if the player is the one casting
// Check if attacker is the player or not // Check if attacker is the player or not
if (player.getScene().getAvatarEntityIds().contains(casterId)) { if (player.getScene().getAvatarEntityIds().contains(casterId)) {
// Attacker is the player // Player is the attacker
for (int entityId : attackedList) { for (int entityId : targetList) {
GameEntity entity = player.getScene().getEntities().get(entityId); GameEntity entity = player.getScene().getEntities().get(entityId);
if (entity != null) { 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); GameEntity entity = player.getScene().getEntities().get(casterId);
if (entity != null) { 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 // Give the client an error if no attacked entities detected
if (entities.size() == 0) { if (targetEntities.size() == 0) {
player.sendPacket(new PacketSceneCastSkillScRsp()); player.sendPacket(new PacketSceneCastSkillScRsp());
return; return;
} }
// Monster list
List<EntityMonster> monsters = new ArrayList<>();
// Destroy props // Destroy props
var it = entities.iterator(); var it = targetEntities.iterator();
while (it.hasNext()) { while (it.hasNext()) {
GameEntity entity = it.next(); GameEntity entity = it.next();

View File

@@ -10,9 +10,13 @@ import emu.lunarcore.server.packet.PacketHandler;
import emu.lunarcore.server.packet.send.PacketSceneCastSkillMpUpdateScNotify; import emu.lunarcore.server.packet.send.PacketSceneCastSkillMpUpdateScNotify;
import emu.lunarcore.server.packet.send.PacketSceneCastSkillScRsp; import emu.lunarcore.server.packet.send.PacketSceneCastSkillScRsp;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
@Opcodes(CmdId.SceneCastSkillCsReq) @Opcodes(CmdId.SceneCastSkillCsReq)
public class HandlerSceneCastSkillCsReq extends PacketHandler { public class HandlerSceneCastSkillCsReq extends PacketHandler {
@SuppressWarnings("deprecation")
@Override @Override
public void handle(GameSession session, byte[] header, byte[] data) throws Exception { public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
var req = SceneCastSkillCsReq.parseFrom(data); var req = SceneCastSkillCsReq.parseFrom(data);
@@ -34,8 +38,14 @@ public class HandlerSceneCastSkillCsReq extends PacketHandler {
} }
} }
if (req.hasAttackedEntityIdList()) { if (req.hasHitTargetIdList()) {
session.getServer().getBattleService().startBattle(session.getPlayer(), req.getCasterId(), req.getAttackedGroupId(), castedSkill, req.getAttackedEntityIdList()); // 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 { } else {
session.send(new PacketSceneCastSkillScRsp(req.getAttackedGroupId())); session.send(new PacketSceneCastSkillScRsp(req.getAttackedGroupId()));
} }