mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-25 22:06:29 +00:00
Refactor out InsectCaptureManager
This commit is contained in:
parent
f020cefd80
commit
fc16f9d694
@ -2,6 +2,7 @@ package emu.grasscutter.data.common;
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
// Used in excels
|
||||||
public class ItemParamData {
|
public class ItemParamData {
|
||||||
@SerializedName(value="id", alternate={"itemId"})
|
@SerializedName(value="id", alternate={"itemId"})
|
||||||
private int id;
|
private int id;
|
||||||
@ -10,6 +11,7 @@ public class ItemParamData {
|
|||||||
private int count;
|
private int count;
|
||||||
|
|
||||||
public ItemParamData() {}
|
public ItemParamData() {}
|
||||||
|
|
||||||
public ItemParamData(int id, int count) {
|
public ItemParamData(int id, int count) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.count = count;
|
this.count = count;
|
||||||
|
@ -4,37 +4,32 @@ import java.util.List;
|
|||||||
|
|
||||||
import emu.grasscutter.data.GameResource;
|
import emu.grasscutter.data.GameResource;
|
||||||
import emu.grasscutter.data.ResourceType;
|
import emu.grasscutter.data.ResourceType;
|
||||||
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
|
|
||||||
@ResourceType(name = "EnvAnimalGatherExcelConfigData.json", loadPriority = ResourceType.LoadPriority.LOW)
|
@ResourceType(name = "EnvAnimalGatherExcelConfigData.json", loadPriority = ResourceType.LoadPriority.LOW)
|
||||||
public class EnvAnimalGatherConfigData extends GameResource {
|
public class EnvAnimalGatherConfigData extends GameResource {
|
||||||
private int animalId;
|
private int animalId;
|
||||||
private String entityType;
|
private String entityType;
|
||||||
private List<GatherItem> gatherItemId;
|
private List<ItemParamData> gatherItemId;
|
||||||
private String excludeWeathers;
|
private String excludeWeathers;
|
||||||
private int aliveTime;
|
private int aliveTime;
|
||||||
private int escapeTime;
|
private int escapeTime;
|
||||||
private int escapeRadius;
|
private int escapeRadius;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return animalId;
|
return animalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAnimalId(){
|
public int getAnimalId(){
|
||||||
return animalId;
|
return animalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEntityType(){
|
public String getEntityType(){
|
||||||
return entityType;
|
return entityType;
|
||||||
}
|
}
|
||||||
public GatherItem gatherItem(){
|
|
||||||
return gatherItemId.get(0);
|
public ItemParamData getGatherItem() {
|
||||||
}
|
return gatherItemId.size() > 0 ? gatherItemId.get(0) : null;
|
||||||
public static class GatherItem{
|
|
||||||
private int id;
|
|
||||||
private int count;
|
|
||||||
public int getId(){
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
public int getCount(){
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
package emu.grasscutter.game.entity;
|
package emu.grasscutter.game.entity;
|
||||||
|
|
||||||
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
import emu.grasscutter.data.common.PropGrowCurve;
|
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.MonsterCurveData;
|
||||||
import emu.grasscutter.data.excels.MonsterData;
|
import emu.grasscutter.data.excels.MonsterData;
|
||||||
|
import emu.grasscutter.game.inventory.GameItem;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
import emu.grasscutter.game.props.EntityIdType;
|
import emu.grasscutter.game.props.EntityIdType;
|
||||||
import emu.grasscutter.game.props.FightProperty;
|
import emu.grasscutter.game.props.FightProperty;
|
||||||
import emu.grasscutter.game.props.PlayerProperty;
|
import emu.grasscutter.game.props.PlayerProperty;
|
||||||
import emu.grasscutter.game.props.WatcherTriggerType;
|
import emu.grasscutter.game.props.WatcherTriggerType;
|
||||||
import emu.grasscutter.game.world.Scene;
|
import emu.grasscutter.game.world.Scene;
|
||||||
|
import emu.grasscutter.net.proto.VisionTypeOuterClass;
|
||||||
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
|
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
|
||||||
import emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair;
|
import emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair;
|
||||||
import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo;
|
import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo;
|
||||||
@ -115,7 +122,15 @@ public class EntityMonster extends GameEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInteract(Player player, GadgetInteractReq interactReq) {
|
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
|
@Override
|
||||||
|
@ -84,11 +84,6 @@ public class EntityVehicle extends EntityBaseGadget {
|
|||||||
return this.rot;
|
return this.rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInteract(Player player, GadgetInteractReq interactReq) {
|
|
||||||
player.getInsectCaptureManager().arrestSmallCreature(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SceneEntityInfo toProto() {
|
public SceneEntityInfo toProto() {
|
||||||
|
|
||||||
|
@ -77,6 +77,10 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean addItem(int itemId, int count) {
|
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);
|
ItemData itemData = GameData.getItemDataMap().get(itemId);
|
||||||
|
|
||||||
if (itemData == null) {
|
if (itemData == null) {
|
||||||
@ -85,7 +89,7 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
|
|||||||
|
|
||||||
GameItem item = new GameItem(itemData, count);
|
GameItem item = new GameItem(itemData, count);
|
||||||
|
|
||||||
return addItem(item);
|
return addItem(item, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addItem(GameItem item) {
|
public boolean addItem(GameItem item) {
|
||||||
@ -120,6 +124,15 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
|
|||||||
return result;
|
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) {
|
public void addItems(Collection<GameItem> items) {
|
||||||
this.addItems(items, null);
|
this.addItems(items, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -30,7 +30,6 @@ import emu.grasscutter.game.mail.Mail;
|
|||||||
import emu.grasscutter.game.mail.MailHandler;
|
import emu.grasscutter.game.mail.MailHandler;
|
||||||
import emu.grasscutter.game.managers.CookingManager;
|
import emu.grasscutter.game.managers.CookingManager;
|
||||||
import emu.grasscutter.game.managers.FurnitureManager;
|
import emu.grasscutter.game.managers.FurnitureManager;
|
||||||
import emu.grasscutter.game.managers.InsectCaptureManager;
|
|
||||||
import emu.grasscutter.game.managers.ResinManager;
|
import emu.grasscutter.game.managers.ResinManager;
|
||||||
import emu.grasscutter.game.managers.collection.CollectionRecordStore;
|
import emu.grasscutter.game.managers.collection.CollectionRecordStore;
|
||||||
import emu.grasscutter.game.managers.deforestation.DeforestationManager;
|
import emu.grasscutter.game.managers.deforestation.DeforestationManager;
|
||||||
@ -142,7 +141,6 @@ public class Player {
|
|||||||
@Getter private transient QuestManager questManager;
|
@Getter private transient QuestManager questManager;
|
||||||
@Getter private transient TowerManager towerManager;
|
@Getter private transient TowerManager towerManager;
|
||||||
@Getter private transient SotSManager sotsManager;
|
@Getter private transient SotSManager sotsManager;
|
||||||
@Getter private transient InsectCaptureManager insectCaptureManager;
|
|
||||||
@Getter private transient MapMarksManager mapMarksManager;
|
@Getter private transient MapMarksManager mapMarksManager;
|
||||||
@Getter private transient StaminaManager staminaManager;
|
@Getter private transient StaminaManager staminaManager;
|
||||||
@Getter private transient EnergyManager energyManager;
|
@Getter private transient EnergyManager energyManager;
|
||||||
@ -197,7 +195,6 @@ public class Player {
|
|||||||
this.towerManager = new TowerManager(this);
|
this.towerManager = new TowerManager(this);
|
||||||
this.abilityManager = new AbilityManager(this);
|
this.abilityManager = new AbilityManager(this);
|
||||||
this.deforestationManager = new DeforestationManager(this);
|
this.deforestationManager = new DeforestationManager(this);
|
||||||
this.insectCaptureManager = new InsectCaptureManager(this);
|
|
||||||
this.questManager = new QuestManager(this);
|
this.questManager = new QuestManager(this);
|
||||||
this.position = new Position(GameConstants.START_POSITION);
|
this.position = new Position(GameConstants.START_POSITION);
|
||||||
this.rotation = new Position(0, 307, 0);
|
this.rotation = new Position(0, 307, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user