From fef5c06a29077eb0990840393d1f7a20a2702e39 Mon Sep 17 00:00:00 2001 From: ShiroSaki <62388797+ShigemoriHakura@users.noreply.github.com> Date: Tue, 24 May 2022 00:11:29 +0800 Subject: [PATCH] Fix the bug that can't kill command-generated monsters Command-generated monsters do not have spawnentry so we have to get data from getMonsterData --- .../emu/grasscutter/game/entity/GameEntity.java | 2 +- .../emu/grasscutter/game/player/PlayerCodex.java | 12 ++++++------ .../java/emu/grasscutter/game/world/Scene.java | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/entity/GameEntity.java b/src/main/java/emu/grasscutter/game/entity/GameEntity.java index 0cdcc3ebd..5180dd0df 100644 --- a/src/main/java/emu/grasscutter/game/entity/GameEntity.java +++ b/src/main/java/emu/grasscutter/game/entity/GameEntity.java @@ -216,7 +216,7 @@ public abstract class GameEntity { // Check if dead if (isDead) { - getScene().killEntity(this, 0); + getScene().killEntity(this, killerId); } } } diff --git a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java index b054b2e95..909848150 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java @@ -5,6 +5,7 @@ import dev.morphia.annotations.Transient; import emu.grasscutter.data.GameData; import emu.grasscutter.data.def.CodexAnimalData; import emu.grasscutter.data.def.CodexReliquaryData; +import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.ItemType; @@ -79,22 +80,21 @@ public class PlayerCodex { } public void checkAnimal(GameEntity target, CodexAnimalData.CodexAnimalUnlockCondition condition){ - if(target.getEntityType() == 2){ - var monsterId = target.getSpawnEntry().getMonsterId(); + if(target instanceof EntityMonster){ + var monsterId = ((EntityMonster)target).getMonsterData().getId(); var codexAnimal = GameData.getCodexAnimalDataMap().get(monsterId); if(!getUnlockedAnimal().containsKey(monsterId)) { if (codexAnimal != null) { - if(codexAnimal.getUnlockCondition() == condition){ + if(codexAnimal.getUnlockCondition() == condition || codexAnimal.getUnlockCondition() == null){ getUnlockedAnimal().put(monsterId, 1); - player.save(); - this.player.sendPacket(new PacketCodexDataUpdateNotify(3, monsterId)); } } }else{ getUnlockedAnimal().put(monsterId, getUnlockedAnimal().get(monsterId) + 1); - player.save(); } + player.save(); + this.player.sendPacket(new PacketCodexDataUpdateNotify(3, monsterId)); } } diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 134b86fe7..e2ef958f7 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.danilopianini.util.SpatialIndex; +import org.quartz.Trigger; import java.util.*; @@ -386,9 +387,19 @@ public class Scene { } public void killEntity(GameEntity target, int attackerId) { - for (Player player : this.getPlayers()) { - player.getCodex().checkAnimal(target, CodexAnimalData.CodexAnimalUnlockCondition.CODEX_COUNT_TYPE_KILL); + GameEntity attacker = getEntityById(attackerId); + + //Check codex + if (attacker instanceof EntityClientGadget) { + var clientGadgetOwner = getEntityById(((EntityClientGadget) attacker).getOwnerEntityId()); + if(clientGadgetOwner instanceof EntityAvatar) { + ((EntityClientGadget) attacker).getOwner().getCodex().checkAnimal(target, CodexAnimalData.CodexAnimalUnlockCondition.CODEX_COUNT_TYPE_KILL); + } } + else if (attacker instanceof EntityAvatar) { + ((EntityAvatar) attacker).getPlayer().getCodex().checkAnimal(target, CodexAnimalData.CodexAnimalUnlockCondition.CODEX_COUNT_TYPE_KILL); + } + // Packet this.broadcastPacket(new PacketLifeStateChangeNotify(attackerId, target, LifeState.LIFE_DEAD));