diff --git a/src/main/java/emu/grasscutter/data/common/ItemParamData.java b/src/main/java/emu/grasscutter/data/common/ItemParamData.java index cc96240bb..229cbf7b9 100644 --- a/src/main/java/emu/grasscutter/data/common/ItemParamData.java +++ b/src/main/java/emu/grasscutter/data/common/ItemParamData.java @@ -2,6 +2,7 @@ package emu.grasscutter.data.common; import com.google.gson.annotations.SerializedName; +// Used in excels public class ItemParamData { @SerializedName(value="id", alternate={"itemId"}) private int id; @@ -10,6 +11,7 @@ public class ItemParamData { private int count; public ItemParamData() {} + public ItemParamData(int id, int count) { this.id = id; this.count = count; diff --git a/src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java b/src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java index e99d681e0..d169b3ef7 100644 --- a/src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java @@ -4,37 +4,32 @@ import java.util.List; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.common.ItemParamData; @ResourceType(name = "EnvAnimalGatherExcelConfigData.json", loadPriority = ResourceType.LoadPriority.LOW) public class EnvAnimalGatherConfigData extends GameResource { private int animalId; private String entityType; - private List gatherItemId; + private List gatherItemId; private String excludeWeathers; private int aliveTime; private int escapeTime; private int escapeRadius; + @Override public int getId() { return animalId; } + public int getAnimalId(){ return animalId; } + public String getEntityType(){ return entityType; } - public GatherItem gatherItem(){ - return gatherItemId.get(0); - } - public static class GatherItem{ - private int id; - private int count; - public int getId(){ - return id; - } - public int getCount(){ - return count; - } + + public ItemParamData getGatherItem() { + return gatherItemId.size() > 0 ? gatherItemId.get(0) : null; } } diff --git a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java index eacc0ca60..2ff99bef4 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java @@ -1,15 +1,22 @@ package emu.grasscutter.game.entity; +import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; +import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.common.PropGrowCurve; +import emu.grasscutter.data.excels.EnvAnimalGatherConfigData; +import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.data.excels.MonsterCurveData; import emu.grasscutter.data.excels.MonsterData; +import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.EntityIdType; import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.WatcherTriggerType; import emu.grasscutter.game.world.Scene; +import emu.grasscutter.net.proto.VisionTypeOuterClass; import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo; import emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair; import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo; @@ -115,7 +122,15 @@ public class EntityMonster extends GameEntity { @Override public void onInteract(Player player, GadgetInteractReq interactReq) { - player.getInsectCaptureManager().arrestSmallCreature(this); + EnvAnimalGatherConfigData gatherData = GameData.getEnvAnimalGatherConfigDataMap().get(this.getMonsterData().getId()); + + if (gatherData == null) { + return; + } + + player.getInventory().addItem(gatherData.getGatherItem(), ActionReason.SubfieldDrop); + + this.getScene().killEntity(this); } @Override diff --git a/src/main/java/emu/grasscutter/game/entity/EntityVehicle.java b/src/main/java/emu/grasscutter/game/entity/EntityVehicle.java index a8381b8d8..16d8b1f6f 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityVehicle.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityVehicle.java @@ -84,11 +84,6 @@ public class EntityVehicle extends EntityBaseGadget { return this.rot; } - @Override - public void onInteract(Player player, GadgetInteractReq interactReq) { - player.getInsectCaptureManager().arrestSmallCreature(this); - } - @Override public SceneEntityInfo toProto() { diff --git a/src/main/java/emu/grasscutter/game/inventory/Inventory.java b/src/main/java/emu/grasscutter/game/inventory/Inventory.java index 15eb9710d..bdda8ac9f 100644 --- a/src/main/java/emu/grasscutter/game/inventory/Inventory.java +++ b/src/main/java/emu/grasscutter/game/inventory/Inventory.java @@ -77,6 +77,10 @@ public class Inventory extends BasePlayerManager implements Iterable { } public boolean addItem(int itemId, int count) { + return addItem(itemId, count, null); + } + + public boolean addItem(int itemId, int count, ActionReason reason) { ItemData itemData = GameData.getItemDataMap().get(itemId); if (itemData == null) { @@ -85,9 +89,9 @@ public class Inventory extends BasePlayerManager implements Iterable { GameItem item = new GameItem(itemData, count); - return addItem(item); + return addItem(item, reason); } - + public boolean addItem(GameItem item) { GameItem result = putItem(item); @@ -120,6 +124,15 @@ public class Inventory extends BasePlayerManager implements Iterable { return result; } + public boolean addItem(ItemParamData itemParam) { + return addItem(itemParam, null); + } + + public boolean addItem(ItemParamData itemParam, ActionReason reason) { + if (itemParam == null) return false; + return addItem(itemParam.getId(), itemParam.getCount(), reason); + } + public void addItems(Collection items) { this.addItems(items, null); } diff --git a/src/main/java/emu/grasscutter/game/managers/InsectCaptureManager.java b/src/main/java/emu/grasscutter/game/managers/InsectCaptureManager.java deleted file mode 100644 index 42a21bbb3..000000000 --- a/src/main/java/emu/grasscutter/game/managers/InsectCaptureManager.java +++ /dev/null @@ -1,50 +0,0 @@ -package emu.grasscutter.game.managers; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.EnvAnimalGatherConfigData; -import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.game.entity.EntityMonster; -import emu.grasscutter.game.entity.EntityVehicle; -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.player.BasePlayerManager; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.net.proto.VisionTypeOuterClass; - -public class InsectCaptureManager extends BasePlayerManager { - - public InsectCaptureManager(Player player) { - super(player); - } - - public void arrestSmallCreature(GameEntity entity) { - //System.out.println("arrestSmallCreature!"); - EnvAnimalGatherConfigData gather; - int thingId; - if (entity instanceof EntityMonster monster) { - thingId = monster.getMonsterData().getId(); - gather = GameData.getEnvAnimalGatherConfigDataMap().get(thingId); - } else if (entity instanceof EntityVehicle gadget) { - thingId = gadget.getGadgetId(); - gather = GameData.getEnvAnimalGatherConfigDataMap().get(thingId); - } else { - return; - } - if (gather == null) { - Grasscutter.getLogger().warn("monster/gather(id={}) couldn't be caught.", thingId); - return; - } - String type = gather.getEntityType(); - if ((type.equals("Monster") && entity instanceof EntityMonster) || (type.equals("Gadget") && entity instanceof EntityVehicle)) { - EnvAnimalGatherConfigData.GatherItem gatherItem = gather.gatherItem(); - ItemData data = GameData.getItemDataMap().get(gatherItem.getId()); - GameItem item = new GameItem(data, gatherItem.getCount()); - player.getInventory().addItem(item, ActionReason.SubfieldDrop); - entity.getScene().removeEntity(entity, VisionTypeOuterClass.VisionType.VISION_TYPE_REMOVE); - } else { - Grasscutter.getLogger().warn("monster/gather(id={}) has a wrong type.", thingId); - } - } -} diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index c415cf7c7..c718b0460 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -30,7 +30,6 @@ import emu.grasscutter.game.mail.Mail; import emu.grasscutter.game.mail.MailHandler; import emu.grasscutter.game.managers.CookingManager; import emu.grasscutter.game.managers.FurnitureManager; -import emu.grasscutter.game.managers.InsectCaptureManager; import emu.grasscutter.game.managers.ResinManager; import emu.grasscutter.game.managers.collection.CollectionRecordStore; import emu.grasscutter.game.managers.deforestation.DeforestationManager; @@ -142,7 +141,6 @@ public class Player { @Getter private transient QuestManager questManager; @Getter private transient TowerManager towerManager; @Getter private transient SotSManager sotsManager; - @Getter private transient InsectCaptureManager insectCaptureManager; @Getter private transient MapMarksManager mapMarksManager; @Getter private transient StaminaManager staminaManager; @Getter private transient EnergyManager energyManager; @@ -197,7 +195,6 @@ public class Player { this.towerManager = new TowerManager(this); this.abilityManager = new AbilityManager(this); this.deforestationManager = new DeforestationManager(this); - this.insectCaptureManager = new InsectCaptureManager(this); this.questManager = new QuestManager(this); this.position = new Position(GameConstants.START_POSITION); this.rotation = new Position(0, 307, 0);