mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-29 23:18:23 +00:00
Arresting small creature support (#1150)
* Arresting small creature support * add InsectCaptureManager * use EnvAnimalGatherExcelConfigData.json * Update InsectCaptureManager.java
This commit is contained in:
parent
27b7ce7cc1
commit
01481fd524
@ -52,6 +52,7 @@ public class GameData {
|
|||||||
private static final Int2ObjectMap<WeaponCurveData> weaponCurveDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<WeaponCurveData> weaponCurveDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<EquipAffixData> equipAffixDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<EquipAffixData> equipAffixDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
private static final Int2ObjectMap<EnvAnimalGatherConfigData> envAnimalGatherConfigDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<MonsterData> monsterDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<MonsterData> monsterDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<NpcData> npcDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<NpcData> npcDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<GadgetData> gadgetDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<GadgetData> gadgetDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
@ -240,6 +241,9 @@ public class GameData {
|
|||||||
public static Int2ObjectMap<MonsterData> getMonsterDataMap() {
|
public static Int2ObjectMap<MonsterData> getMonsterDataMap() {
|
||||||
return monsterDataMap;
|
return monsterDataMap;
|
||||||
}
|
}
|
||||||
|
public static Int2ObjectMap<EnvAnimalGatherConfigData> getEnvAnimalGatherConfigDataMap() {
|
||||||
|
return envAnimalGatherConfigDataMap;
|
||||||
|
}
|
||||||
|
|
||||||
public static Int2ObjectMap<NpcData> getNpcDataMap() {
|
public static Int2ObjectMap<NpcData> getNpcDataMap() {
|
||||||
return npcDataMap;
|
return npcDataMap;
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package emu.grasscutter.data.excels;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import emu.grasscutter.data.GameResource;
|
||||||
|
import emu.grasscutter.data.ResourceType;
|
||||||
|
|
||||||
|
@ResourceType(name = "EnvAnimalGatherExcelConfigData.json", loadPriority = ResourceType.LoadPriority.LOW)
|
||||||
|
public class EnvAnimalGatherConfigData extends GameResource {
|
||||||
|
private int animalId;
|
||||||
|
private String entityType;
|
||||||
|
private List<GatherItem> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
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.Player;
|
||||||
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
|
import emu.grasscutter.net.proto.VisionTypeOuterClass;
|
||||||
|
|
||||||
|
public record InsectCaptureManager(Player 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,8 @@ import emu.grasscutter.game.ability.AbilityManager;
|
|||||||
import emu.grasscutter.game.avatar.Avatar;
|
import emu.grasscutter.game.avatar.Avatar;
|
||||||
import emu.grasscutter.game.avatar.AvatarProfileData;
|
import emu.grasscutter.game.avatar.AvatarProfileData;
|
||||||
import emu.grasscutter.game.avatar.AvatarStorage;
|
import emu.grasscutter.game.avatar.AvatarStorage;
|
||||||
|
import emu.grasscutter.game.entity.EntityMonster;
|
||||||
|
import emu.grasscutter.game.entity.EntityVehicle;
|
||||||
import emu.grasscutter.game.managers.DeforestationManager.DeforestationManager;
|
import emu.grasscutter.game.managers.DeforestationManager.DeforestationManager;
|
||||||
import emu.grasscutter.game.entity.EntityGadget;
|
import emu.grasscutter.game.entity.EntityGadget;
|
||||||
import emu.grasscutter.game.entity.EntityItem;
|
import emu.grasscutter.game.entity.EntityItem;
|
||||||
@ -23,6 +25,7 @@ import emu.grasscutter.game.inventory.GameItem;
|
|||||||
import emu.grasscutter.game.inventory.Inventory;
|
import emu.grasscutter.game.inventory.Inventory;
|
||||||
import emu.grasscutter.game.mail.Mail;
|
import emu.grasscutter.game.mail.Mail;
|
||||||
import emu.grasscutter.game.mail.MailHandler;
|
import emu.grasscutter.game.mail.MailHandler;
|
||||||
|
import emu.grasscutter.game.managers.InsectCaptureManager;
|
||||||
import emu.grasscutter.game.managers.StaminaManager.StaminaManager;
|
import emu.grasscutter.game.managers.StaminaManager.StaminaManager;
|
||||||
import emu.grasscutter.game.managers.SotSManager;
|
import emu.grasscutter.game.managers.SotSManager;
|
||||||
import emu.grasscutter.game.managers.EnergyManager.EnergyManager;
|
import emu.grasscutter.game.managers.EnergyManager.EnergyManager;
|
||||||
@ -47,6 +50,7 @@ import emu.grasscutter.net.proto.OnlinePlayerInfoOuterClass.OnlinePlayerInfo;
|
|||||||
import emu.grasscutter.net.proto.PlayerLocationInfoOuterClass.PlayerLocationInfo;
|
import emu.grasscutter.net.proto.PlayerLocationInfoOuterClass.PlayerLocationInfo;
|
||||||
import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture;
|
import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture;
|
||||||
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
|
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
|
||||||
|
|
||||||
import emu.grasscutter.server.event.player.PlayerJoinEvent;
|
import emu.grasscutter.server.event.player.PlayerJoinEvent;
|
||||||
import emu.grasscutter.server.event.player.PlayerQuitEvent;
|
import emu.grasscutter.server.event.player.PlayerQuitEvent;
|
||||||
import emu.grasscutter.server.game.GameServer;
|
import emu.grasscutter.server.game.GameServer;
|
||||||
@ -105,6 +109,7 @@ public class Player {
|
|||||||
@Transient private QuestManager questManager;
|
@Transient private QuestManager questManager;
|
||||||
|
|
||||||
@Transient private SotSManager sotsManager;
|
@Transient private SotSManager sotsManager;
|
||||||
|
@Transient private InsectCaptureManager insectCaptureManager;
|
||||||
|
|
||||||
private TeamManager teamManager;
|
private TeamManager teamManager;
|
||||||
|
|
||||||
@ -161,6 +166,7 @@ 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.setQuestManager(new QuestManager(this));
|
this.setQuestManager(new QuestManager(this));
|
||||||
this.pos = new Position();
|
this.pos = new Position();
|
||||||
@ -907,47 +913,46 @@ public class Player {
|
|||||||
|
|
||||||
public void interactWith(int gadgetEntityId) {
|
public void interactWith(int gadgetEntityId) {
|
||||||
GameEntity entity = getScene().getEntityById(gadgetEntityId);
|
GameEntity entity = getScene().getEntityById(gadgetEntityId);
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle
|
// Handle
|
||||||
if (entity instanceof EntityItem) {
|
if (entity instanceof EntityItem drop) {
|
||||||
// Pick item
|
// Pick item
|
||||||
EntityItem drop = (EntityItem) entity;
|
|
||||||
if (!drop.isShare()) // check drop owner to avoid someone picked up item in others' world
|
if (!drop.isShare()) // check drop owner to avoid someone picked up item in others' world
|
||||||
{
|
{
|
||||||
int dropOwner = (int)(drop.getGuid() >> 32);
|
int dropOwner = (int)(drop.getGuid() >> 32);
|
||||||
if (dropOwner != getUid())
|
if (dropOwner != getUid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
entity.getScene().removeEntity(entity);
|
entity.getScene().removeEntity(entity);
|
||||||
GameItem item = new GameItem(drop.getItemData(), drop.getCount());
|
GameItem item = new GameItem(drop.getItemData(), drop.getCount());
|
||||||
// Add to inventory
|
// Add to inventory
|
||||||
boolean success = getInventory().addItem(item, ActionReason.SubfieldDrop);
|
boolean success = getInventory().addItem(item, ActionReason.SubfieldDrop);
|
||||||
if (success) {
|
if (success) {
|
||||||
if (!drop.isShare()) // not shared drop
|
if (!drop.isShare()) { // not shared drop
|
||||||
this.sendPacket(new PacketGadgetInteractRsp(drop, InteractType.INTERACT_TYPE_PICK_ITEM));
|
this.sendPacket(new PacketGadgetInteractRsp(drop, InteractType.INTERACT_TYPE_PICK_ITEM));
|
||||||
else
|
}else{
|
||||||
this.getScene().broadcastPacket(new PacketGadgetInteractRsp(drop, InteractType.INTERACT_TYPE_PICK_ITEM));
|
this.getScene().broadcastPacket(new PacketGadgetInteractRsp(drop, InteractType.INTERACT_TYPE_PICK_ITEM));
|
||||||
}
|
}
|
||||||
} else if (entity instanceof EntityGadget) {
|
}
|
||||||
EntityGadget gadget = (EntityGadget) entity;
|
} else if (entity instanceof EntityGadget gadget) {
|
||||||
|
|
||||||
if (gadget.getGadgetData().getType() == EntityType.RewardStatue) {
|
if (gadget.getGadgetData().getType() == EntityType.RewardStatue) {
|
||||||
if (scene.getChallenge() != null) {
|
if (scene.getChallenge() != null) {
|
||||||
scene.getChallenge().getStatueDrops(this);
|
scene.getChallenge().getStatueDrops(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendPacket(new PacketGadgetInteractRsp(gadget, InteractType.INTERACT_TYPE_OPEN_STATUE));
|
this.sendPacket(new PacketGadgetInteractRsp(gadget, InteractType.INTERACT_TYPE_OPEN_STATUE));
|
||||||
}
|
}
|
||||||
|
} else if (entity instanceof EntityMonster monster) {
|
||||||
|
insectCaptureManager.arrestSmallCreature(monster);
|
||||||
|
} else if (entity instanceof EntityVehicle vehicle) {// try to arrest it, example: glowworm
|
||||||
|
insectCaptureManager.arrestSmallCreature(vehicle);
|
||||||
} else {
|
} else {
|
||||||
// Delete directly
|
// Delete directly
|
||||||
entity.getScene().removeEntity(entity);
|
entity.getScene().removeEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
|
Loading…
Reference in New Issue
Block a user