Refactor out InsectCaptureManager

This commit is contained in:
Melledy 2022-07-19 03:05:36 -07:00
parent f020cefd80
commit fc16f9d694
7 changed files with 41 additions and 74 deletions

View File

@ -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;

View File

@ -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<GatherItem> gatherItemId;
private List<ItemParamData> 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;
}
}

View File

@ -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

View File

@ -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() {

View File

@ -77,6 +77,10 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
}
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,7 +89,7 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
GameItem item = new GameItem(itemData, count);
return addItem(item);
return addItem(item, reason);
}
public boolean addItem(GameItem item) {
@ -120,6 +124,15 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
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<GameItem> items) {
this.addItems(items, null);
}

View File

@ -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);
}
}
}

View File

@ -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);