Refactor player managers

This commit is contained in:
Melledy 2022-07-18 20:42:22 -07:00
parent 3957616b6c
commit d20e9d1f72
30 changed files with 231 additions and 485 deletions

View File

@ -21,6 +21,7 @@ import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.entity.gadget.GadgetGatherObject; import emu.grasscutter.game.entity.gadget.GadgetGatherObject;
import emu.grasscutter.game.entity.gadget.GadgetGatherPoint; import emu.grasscutter.game.entity.gadget.GadgetGatherPoint;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ElementType; import emu.grasscutter.game.props.ElementType;
import emu.grasscutter.net.proto.AbilityActionGenerateElemBallOuterClass.AbilityActionGenerateElemBall; import emu.grasscutter.net.proto.AbilityActionGenerateElemBallOuterClass.AbilityActionGenerateElemBall;
@ -35,18 +36,14 @@ import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
public class AbilityManager { public class AbilityManager extends BasePlayerManager {
private Player player; private Player player;
HealAbilityManager healAbilityManager; HealAbilityManager healAbilityManager;
public AbilityManager(Player player) { public AbilityManager(Player player) {
this.player = player; super(player);
this.healAbilityManager = new HealAbilityManager(player); this.healAbilityManager = new HealAbilityManager(player);
} }
public Player getPlayer() {
return this.player;
}
public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception { public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception {
healAbilityManager.healHandler(invoke); healAbilityManager.healHandler(invoke);

View File

@ -5,6 +5,7 @@ import com.google.gson.reflect.TypeToken;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader; import emu.grasscutter.data.DataLoader;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActivityType; import emu.grasscutter.game.props.ActivityType;
import emu.grasscutter.game.props.WatcherTriggerType; import emu.grasscutter.game.props.WatcherTriggerType;
@ -19,9 +20,8 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@Getter @Getter
public class ActivityManager { public class ActivityManager extends BasePlayerManager {
private static final Map<Integer, ActivityConfigItem> activityConfigItemMap; private static final Map<Integer, ActivityConfigItem> activityConfigItemMap;
private final Player player;
private final Map<Integer, PlayerActivityData> playerActivityDataMap; private final Map<Integer, PlayerActivityData> playerActivityDataMap;
static { static {
@ -79,7 +79,7 @@ public class ActivityManager {
} }
public ActivityManager(Player player){ public ActivityManager(Player player){
this.player = player; super(player);
playerActivityDataMap = new ConcurrentHashMap<>(); playerActivityDataMap = new ConcurrentHashMap<>();
// load data for player // load data for player

View File

@ -1,26 +0,0 @@
package emu.grasscutter.game.avatar;
import dev.morphia.annotations.Entity;
@Entity
public class AvatarProfileData {
private int avatarId;
private int level;
public AvatarProfileData(Avatar avatar) {
this.update(avatar);
}
public int getAvatarId() {
return avatarId;
}
public int getLevel() {
return level;
}
public void update(Avatar avatar) {
this.avatarId = avatar.getAvatarId();
this.level = avatar.getLevel();
}
}

View File

@ -9,6 +9,7 @@ import emu.grasscutter.data.excels.AvatarSkillDepotData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.PacketAvatarChangeCostumeNotify; import emu.grasscutter.server.packet.send.PacketAvatarChangeCostumeNotify;
import emu.grasscutter.server.packet.send.PacketAvatarFlycloakChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarFlycloakChangeNotify;
@ -17,20 +18,15 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
public class AvatarStorage implements Iterable<Avatar> { public class AvatarStorage extends BasePlayerManager implements Iterable<Avatar> {
private final Player player;
private final Int2ObjectMap<Avatar> avatars; private final Int2ObjectMap<Avatar> avatars;
private final Long2ObjectMap<Avatar> avatarsGuid; private final Long2ObjectMap<Avatar> avatarsGuid;
public AvatarStorage(Player player) { public AvatarStorage(Player player) {
this.player = player; super(player);
this.avatars = new Int2ObjectOpenHashMap<>(); this.avatars = new Int2ObjectOpenHashMap<>();
this.avatarsGuid = new Long2ObjectOpenHashMap<>(); this.avatarsGuid = new Long2ObjectOpenHashMap<>();
} }
public Player getPlayer() {
return player;
}
public Int2ObjectMap<Avatar> getAvatars() { public Int2ObjectMap<Avatar> getAvatars() {
return avatars; return avatars;

View File

@ -15,7 +15,6 @@ import org.bson.types.ObjectId;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id; import dev.morphia.annotations.Id;
import dev.morphia.annotations.Indexed; import dev.morphia.annotations.Indexed;
import dev.morphia.annotations.Transient;
import emu.grasscutter.GameConstants; import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
@ -26,6 +25,7 @@ import emu.grasscutter.data.excels.RewardData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.MaterialType; import emu.grasscutter.game.inventory.MaterialType;
import emu.grasscutter.game.player.BasePlayerDataManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.BattlePassMissionRefreshType; import emu.grasscutter.game.props.BattlePassMissionRefreshType;
import emu.grasscutter.game.props.BattlePassMissionStatus; import emu.grasscutter.game.props.BattlePassMissionStatus;
@ -41,9 +41,8 @@ import emu.grasscutter.server.packet.send.PacketTakeBattlePassRewardRsp;
import lombok.Getter; import lombok.Getter;
@Entity(value = "battlepass", useDiscriminator = false) @Entity(value = "battlepass", useDiscriminator = false)
public class BattlePassManager { public class BattlePassManager extends BasePlayerDataManager {
@Id @Getter private ObjectId id; @Id @Getter private ObjectId id;
@Transient @Getter private Player player;
@Indexed private int ownerUid; @Indexed private int ownerUid;
@Getter private int point; @Getter private int point;
@ -60,7 +59,7 @@ public class BattlePassManager {
public BattlePassManager() {} public BattlePassManager() {}
public BattlePassManager(Player player) { public BattlePassManager(Player player) {
this.setPlayer(player); super(player);
} }
public void setPlayer(Player player) { public void setPlayer(Player player) {

View File

@ -3,6 +3,7 @@ package emu.grasscutter.game.friends;
import java.util.List; import java.util.List;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.DealAddFriendResultTypeOuterClass.DealAddFriendResultType; import emu.grasscutter.net.proto.DealAddFriendResultTypeOuterClass.DealAddFriendResultType;
import emu.grasscutter.server.packet.send.PacketAskAddFriendNotify; import emu.grasscutter.server.packet.send.PacketAskAddFriendNotify;
@ -13,24 +14,18 @@ import emu.grasscutter.server.packet.send.PacketDeleteFriendRsp;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class FriendsList { public class FriendsList extends BasePlayerManager {
private final Player player;
private final Int2ObjectMap<Friendship> friends; private final Int2ObjectMap<Friendship> friends;
private final Int2ObjectMap<Friendship> pendingFriends; private final Int2ObjectMap<Friendship> pendingFriends;
private boolean loaded = false; private boolean loaded = false;
public FriendsList(Player player) { public FriendsList(Player player) {
this.player = player; super(player);
this.friends = new Int2ObjectOpenHashMap<Friendship>(); this.friends = new Int2ObjectOpenHashMap<Friendship>();
this.pendingFriends = new Int2ObjectOpenHashMap<Friendship>(); this.pendingFriends = new Int2ObjectOpenHashMap<Friendship>();
} }
public Player getPlayer() {
return player;
}
public boolean hasLoaded() { public boolean hasLoaded() {
return loaded; return loaded;
} }

View File

@ -15,6 +15,7 @@ import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.avatar.AvatarStorage; import emu.grasscutter.game.avatar.AvatarStorage;
import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
@ -31,14 +32,13 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import static emu.grasscutter.Configuration.*; import static emu.grasscutter.Configuration.*;
public class Inventory implements Iterable<GameItem> { public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
private final Player player;
private final Long2ObjectMap<GameItem> store; private final Long2ObjectMap<GameItem> store;
private final Int2ObjectMap<InventoryTab> inventoryTypes; private final Int2ObjectMap<InventoryTab> inventoryTypes;
public Inventory(Player player) { public Inventory(Player player) {
this.player = player; super(player);
this.store = new Long2ObjectOpenHashMap<>(); this.store = new Long2ObjectOpenHashMap<>();
this.inventoryTypes = new Int2ObjectOpenHashMap<>(); this.inventoryTypes = new Int2ObjectOpenHashMap<>();
@ -48,10 +48,6 @@ public class Inventory implements Iterable<GameItem> {
this.createInventoryTab(ItemType.ITEM_FURNITURE, new MaterialInventoryTab(INVENTORY_LIMITS.furniture)); this.createInventoryTab(ItemType.ITEM_FURNITURE, new MaterialInventoryTab(INVENTORY_LIMITS.furniture));
} }
public Player getPlayer() {
return player;
}
public AvatarStorage getAvatarStorage() { public AvatarStorage getAvatarStorage() {
return this.getPlayer().getAvatars(); return this.getPlayer().getAvatars();
} }

View File

@ -1,30 +1,26 @@
package emu.grasscutter.game.mail; package emu.grasscutter.game.mail;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.event.player.PlayerReceiveMailEvent; import emu.grasscutter.server.event.player.PlayerReceiveMailEvent;
import emu.grasscutter.server.packet.send.PacketDelMailRsp; import emu.grasscutter.server.packet.send.PacketDelMailRsp;
import emu.grasscutter.server.packet.send.PacketMailChangeNotify; import emu.grasscutter.server.packet.send.PacketMailChangeNotify;
public class MailHandler { public class MailHandler extends BasePlayerManager {
private final Player player;
private final List<Mail> mail; private final List<Mail> mail;
public MailHandler(Player player) { public MailHandler(Player player) {
this.player = player; super(player);
this.mail = new ArrayList<>(); this.mail = new ArrayList<>();
} }
public Player getPlayer() {
return player;
}
public List<Mail> getMail() { public List<Mail> getMail() {
return mail; return mail;
} }

View File

@ -10,6 +10,7 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.proto.CookRecipeDataOuterClass; import emu.grasscutter.net.proto.CookRecipeDataOuterClass;
@ -22,14 +23,12 @@ import emu.grasscutter.server.packet.send.PacketPlayerCookArgsRsp;
import emu.grasscutter.server.packet.send.PacketPlayerCookRsp; import emu.grasscutter.server.packet.send.PacketPlayerCookRsp;
import io.netty.util.internal.ThreadLocalRandom; import io.netty.util.internal.ThreadLocalRandom;
public class CookingManager { public class CookingManager extends BasePlayerManager {
private static final int MANUAL_PERFECT_COOK_QUALITY = 3; private static final int MANUAL_PERFECT_COOK_QUALITY = 3;
private static Set<Integer> defaultUnlockedRecipies; private static Set<Integer> defaultUnlockedRecipies;
private final Player player;
public CookingManager(Player player) { public CookingManager(Player player) {
this.player = player; super(player);
} }
public static void initialize() { public static void initialize() {

View File

@ -4,6 +4,7 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.game.home.FurnitureMakeSlotItem; import emu.grasscutter.game.home.FurnitureMakeSlotItem;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.ItemParamOuterClass; import emu.grasscutter.net.proto.ItemParamOuterClass;
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
@ -13,11 +14,10 @@ import emu.grasscutter.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FurnitureManager { public class FurnitureManager extends BasePlayerManager {
private final Player player;
public FurnitureManager(Player player) { public FurnitureManager(Player player) {
this.player = player; super(player);
} }
public void onLogin(){ public void onLogin(){

View File

@ -8,11 +8,17 @@ import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.EntityVehicle; import emu.grasscutter.game.entity.EntityVehicle;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.proto.VisionTypeOuterClass; import emu.grasscutter.net.proto.VisionTypeOuterClass;
public record InsectCaptureManager(Player player) { public class InsectCaptureManager extends BasePlayerManager {
public InsectCaptureManager(Player player) {
super(player);
}
public void arrestSmallCreature(GameEntity entity) { public void arrestSmallCreature(GameEntity entity) {
//System.out.println("arrestSmallCreature!"); //System.out.println("arrestSmallCreature!");
EnvAnimalGatherConfigData gather; EnvAnimalGatherConfigData gather;

View File

@ -1,5 +1,6 @@
package emu.grasscutter.game.managers; package emu.grasscutter.game.managers;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.game.props.WatcherTriggerType; import emu.grasscutter.game.props.WatcherTriggerType;
@ -9,11 +10,10 @@ import emu.grasscutter.utils.Utils;
import static emu.grasscutter.Configuration.GAME_OPTIONS; import static emu.grasscutter.Configuration.GAME_OPTIONS;
public class ResinManager { public class ResinManager extends BasePlayerManager {
private final Player player;
public ResinManager(Player player) { public ResinManager(Player player) {
this.player = player; super(player);
} }
/******************** /********************

View File

@ -3,6 +3,7 @@ package emu.grasscutter.game.managers;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
@ -16,11 +17,10 @@ import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
// Statue of the Seven Manager // Statue of the Seven Manager
public class SotSManager { public class SotSManager extends BasePlayerManager {
// NOTE: Spring volume balance *1 = fight prop HP *100 // NOTE: Spring volume balance *1 = fight prop HP *100
private final Player player;
private final Logger logger = Grasscutter.getLogger(); private final Logger logger = Grasscutter.getLogger();
private Timer autoRecoverTimer; private Timer autoRecoverTimer;
private final boolean enablePriorityHealing = false; private final boolean enablePriorityHealing = false;
@ -28,7 +28,7 @@ public class SotSManager {
public final static int GlobalMaximumSpringVolume = PlayerProperty.PROP_MAX_SPRING_VOLUME.getMax(); public final static int GlobalMaximumSpringVolume = PlayerProperty.PROP_MAX_SPRING_VOLUME.getMax();
public SotSManager(Player player) { public SotSManager(Player player) {
this.player = player; super(player);
} }
public boolean getIsAutoRecoveryEnabled() { public boolean getIsAutoRecoveryEnabled() {

View File

@ -1,74 +0,0 @@
package emu.grasscutter.game.managers.collection;
import java.util.HashMap;
import java.util.List;
import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.player.Player;
public class CollectionManager {
private static final long SECOND = 1000; //1 Second
private static final long MINUTE = SECOND*60; //1 Minute
private static final long HOUR = MINUTE*60; //1 Hour
private static final long DAY = HOUR*24; //1 Day
private static final HashMap<Integer,Long> DEFINE_REFRESH_TIME = new HashMap<>();// <GadgetId,Waiting Millisecond>
private static final long DEFAULT_REFRESH_TIME = HOUR*6; // default 6 Hours
static {
DEFINE_REFRESH_TIME.put(70590027,3*DAY);//星银矿石 3 Days
DEFINE_REFRESH_TIME.put(70590036,3*DAY);//紫晶块 3 Days
DEFINE_REFRESH_TIME.put(70520003,3*DAY);//水晶 3 Days
DEFINE_REFRESH_TIME.put(70590013,2*DAY);//嘟嘟莲 2 Days
DEFINE_REFRESH_TIME.put(70540029,2*DAY);//清心 2 Days
DEFINE_REFRESH_TIME.put(70540028,2*DAY);//星螺 2 Days
DEFINE_REFRESH_TIME.put(70540027,2*DAY);//马尾 2 Days
DEFINE_REFRESH_TIME.put(70540026,2*DAY);//琉璃袋 2 Days
DEFINE_REFRESH_TIME.put(70540022,2*DAY);//落落莓 2 Days
DEFINE_REFRESH_TIME.put(70540020,2*DAY);//慕风蘑菇 2 Days
DEFINE_REFRESH_TIME.put(70540019,2*DAY);//风车菊 2 Days
DEFINE_REFRESH_TIME.put(70540018,2*DAY);//塞西莉亚花 2 Days
DEFINE_REFRESH_TIME.put(70540015,2*DAY);//霓裳花 2 Days
DEFINE_REFRESH_TIME.put(70540014,2*DAY);//莲蓬 2 Days
DEFINE_REFRESH_TIME.put(70540013,2*DAY);//钩钩果 2 Days
DEFINE_REFRESH_TIME.put(70540012,2*DAY);//琉璃百合 2 Days
DEFINE_REFRESH_TIME.put(70540008,2*DAY);//绝云椒椒 2 Days
DEFINE_REFRESH_TIME.put(70520018,2*DAY);//夜泊石 2 Days
DEFINE_REFRESH_TIME.put(70520002,2*DAY);//白铁矿 2 Days
DEFINE_REFRESH_TIME.put(70510012,2*DAY);//石珀 2 Days
DEFINE_REFRESH_TIME.put(70510009,2*DAY);//蒲公英 2 Days
DEFINE_REFRESH_TIME.put(70510007,2*DAY);//冰雾花 2 Days
DEFINE_REFRESH_TIME.put(70510006,2*DAY);//烈焰花 2 Days
DEFINE_REFRESH_TIME.put(70510005,2*DAY);//电气水晶 2 Days
DEFINE_REFRESH_TIME.put(70510004,2*DAY);//小灯草 2 Days
DEFINE_REFRESH_TIME.put(70540021,DAY);//日落果 1 Day
DEFINE_REFRESH_TIME.put(70540005,DAY);//松果 1 Day
DEFINE_REFRESH_TIME.put(70540003,DAY);//苹果 1 Day
DEFINE_REFRESH_TIME.put(70540001,DAY);//树莓 1 Day
DEFINE_REFRESH_TIME.put(70520019,DAY);//魔晶块 1 Days
DEFINE_REFRESH_TIME.put(70520008,DAY);//金鱼草 1 Days
DEFINE_REFRESH_TIME.put(70520007,DAY);//白萝卜 1 Days
DEFINE_REFRESH_TIME.put(70520006,DAY);//胡萝卜 1 Days
DEFINE_REFRESH_TIME.put(70520004,DAY);//蘑菇 1 Day
DEFINE_REFRESH_TIME.put(70520001,DAY);//铁矿 1 Day
DEFINE_REFRESH_TIME.put(70520009,12*HOUR);//薄荷 12 Hours
DEFINE_REFRESH_TIME.put(70520005,12*HOUR);//甜甜花 12 Hours
}
private final static HashMap<Integer, List<CollectionData>> CollectionResourcesData = new HashMap<>();
private final HashMap<CollectionData,EntityGadget> spawnedEntities = new HashMap<>();
private CollectionRecordStore collectionRecordStore;
Player player;
private static long getGadgetRefreshTime(int gadgetId){
return DEFINE_REFRESH_TIME.getOrDefault(gadgetId,DEFAULT_REFRESH_TIME);
}
public synchronized void setPlayer(Player player) {
this.player = player;
this.collectionRecordStore = player.getCollectionRecordStore();
}
}

View File

@ -7,20 +7,21 @@ import dev.morphia.annotations.Transient;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.game.entity.EntityItem; import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.Scene; import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.proto.HitTreeNotifyOuterClass; import emu.grasscutter.net.proto.HitTreeNotifyOuterClass;
import emu.grasscutter.net.proto.VectorOuterClass; import emu.grasscutter.net.proto.VectorOuterClass;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
public class DeforestationManager { public class DeforestationManager extends BasePlayerManager {
final static int RECORD_EXPIRED_SECONDS = 60*5; // 5 min final static int RECORD_EXPIRED_SECONDS = 60*5; // 5 min
final static int RECORD_MAX_TIMES = 3; // max number of wood final static int RECORD_MAX_TIMES = 3; // max number of wood
final static int RECORD_MAX_TIMES_OTHER_HIT_TREE = 10; // if hit 10 times other trees, reset wood final static int RECORD_MAX_TIMES_OTHER_HIT_TREE = 10; // if hit 10 times other trees, reset wood
@Transient private final Player player; private final ArrayList<HitTreeRecord> currentRecord;
@Transient private final ArrayList<HitTreeRecord> currentRecord; private final static HashMap<Integer, Integer> ColliderTypeToWoodItemID = new HashMap<>();
@Transient private final static HashMap<Integer, Integer> ColliderTypeToWoodItemID = new HashMap<>();
static { static {
/* define wood types which reflected to item id*/ /* define wood types which reflected to item id*/
ColliderTypeToWoodItemID.put(1,101301); ColliderTypeToWoodItemID.put(1,101301);
@ -36,8 +37,9 @@ public class DeforestationManager {
ColliderTypeToWoodItemID.put(11,101311); ColliderTypeToWoodItemID.put(11,101311);
ColliderTypeToWoodItemID.put(12,101312); ColliderTypeToWoodItemID.put(12,101312);
} }
public DeforestationManager(Player player){ public DeforestationManager(Player player){
this.player = player; super(player);
this.currentRecord = new ArrayList<>(); this.currentRecord = new ArrayList<>();
} }
public void resetWood(){ public void resetWood(){

View File

@ -13,6 +13,7 @@ import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ElementType; import emu.grasscutter.game.props.ElementType;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
@ -46,8 +47,7 @@ import static java.util.Map.entry;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
public class EnergyManager { public class EnergyManager extends BasePlayerManager {
private final Player player;
private final Map<EntityAvatar, Integer> avatarNormalProbabilities; private final Map<EntityAvatar, Integer> avatarNormalProbabilities;
// energyUsage for each player // energyUsage for each player
private Boolean energyUsage; private Boolean energyUsage;
@ -55,15 +55,11 @@ public class EnergyManager {
private final static Int2ObjectMap<List<SkillParticleGenerationInfo>> skillParticleGenerationData = new Int2ObjectOpenHashMap<>(); private final static Int2ObjectMap<List<SkillParticleGenerationInfo>> skillParticleGenerationData = new Int2ObjectOpenHashMap<>();
public EnergyManager(Player player) { public EnergyManager(Player player) {
this.player = player; super(player);
this.avatarNormalProbabilities = new HashMap<>(); this.avatarNormalProbabilities = new HashMap<>();
this.energyUsage=GAME_OPTIONS.energyUsage; this.energyUsage=GAME_OPTIONS.energyUsage;
} }
public Player getPlayer() {
return this.player;
}
public static void initialize() { public static void initialize() {
// Read the data we need for monster energy drops. // Read the data we need for monster energy drops.
try (Reader fileReader = new InputStreamReader(DataLoader.load("EnergyDrop.json"))) { try (Reader fileReader = new InputStreamReader(DataLoader.load("EnergyDrop.json"))) {

View File

@ -11,6 +11,7 @@ import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.excels.ForgeData; import emu.grasscutter.data.excels.ForgeData;
import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.WatcherTriggerType; import emu.grasscutter.game.props.WatcherTriggerType;
@ -27,11 +28,10 @@ import emu.grasscutter.server.packet.send.PacketForgeQueueManipulateRsp;
import emu.grasscutter.server.packet.send.PacketForgeStartRsp; import emu.grasscutter.server.packet.send.PacketForgeStartRsp;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
public class ForgingManager { public class ForgingManager extends BasePlayerManager {
private final Player player;
public ForgingManager(Player player) { public ForgingManager(Player player) {
this.player = player; super(player);
} }
/********** /**********

View File

@ -1,5 +1,6 @@
package emu.grasscutter.game.managers.mapmark; package emu.grasscutter.game.managers.mapmark;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType; import emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType;
import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq; import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq;
@ -9,16 +10,17 @@ import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
public class MapMarksManager { public class MapMarksManager extends BasePlayerManager {
public static final int mapMarkMaxCount = 150; public static final int mapMarkMaxCount = 150;
private HashMap<String, MapMark> mapMarks;
private final Player player;
public MapMarksManager(Player player) { public MapMarksManager(Player player) {
this.player = player; super(player);
this.mapMarks = player.getMapMarks(); }
if (this.mapMarks == null) { this.mapMarks = new HashMap<>(); }
public Map<String, MapMark> getMapMarks() {
return getPlayer().getMapMarks();
} }
public void handleMapMarkReq(MarkMapReq req) { public void handleMapMarkReq(MarkMapReq req) {
@ -45,31 +47,26 @@ public class MapMarksManager {
} }
} }
if (op != Operation.OPERATION_GET) { if (op != Operation.OPERATION_GET) {
saveMapMarks(); save();
} }
player.getSession().send(new PacketMarkMapRsp(getMapMarks())); player.getSession().send(new PacketMarkMapRsp(getMapMarks()));
} }
public HashMap<String, MapMark> getMapMarks() {
return mapMarks;
}
public String getMapMarkKey(Position position) { public String getMapMarkKey(Position position) {
return "x" + (int)position.getX()+ "z" + (int)position.getZ(); return "x" + (int)position.getX()+ "z" + (int)position.getZ();
} }
public void removeMapMark(Position position) { public void removeMapMark(Position position) {
mapMarks.remove(getMapMarkKey(position)); getMapMarks().remove(getMapMarkKey(position));
} }
public void addMapMark(MapMark mapMark) { public void addMapMark(MapMark mapMark) {
if (mapMarks.size() < mapMarkMaxCount) { if (getMapMarks().size() < mapMarkMaxCount) {
mapMarks.put(getMapMarkKey(mapMark.getPosition()), mapMark); getMapMarks().put(getMapMarkKey(mapMark.getPosition()), mapMark);
} }
} }
private void saveMapMarks() { private void save() {
player.setMapMarks(mapMarks);
player.save(); player.save();
} }

View File

@ -5,6 +5,7 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState; import emu.grasscutter.game.props.LifeState;
@ -25,10 +26,9 @@ import java.util.*;
import static emu.grasscutter.Configuration.GAME_OPTIONS; import static emu.grasscutter.Configuration.GAME_OPTIONS;
public class StaminaManager { public class StaminaManager extends BasePlayerManager {
// TODO: Skiff state detection? // TODO: Skiff state detection?
private final Player player;
private static final HashMap<String, HashSet<MotionState>> MotionStatesCategorized = new HashMap<>() {{ private static final HashMap<String, HashSet<MotionState>> MotionStatesCategorized = new HashMap<>() {{
put("CLIMB", new HashSet<>(List.of( put("CLIMB", new HashSet<>(List.of(
MotionState.MOTION_STATE_CLIMB, // sustained, when not moving no cost no recover MotionState.MOTION_STATE_CLIMB, // sustained, when not moving no cost no recover
@ -163,7 +163,7 @@ public class StaminaManager {
} }
public StaminaManager(Player player) { public StaminaManager(Player player) {
this.player = player; super(player);
} }
// Accessors // Accessors

View File

@ -0,0 +1,23 @@
package emu.grasscutter.game.player;
import lombok.NonNull;
public abstract class BasePlayerDataManager {
protected transient Player player;
public BasePlayerDataManager() {}
public BasePlayerDataManager(@NonNull Player player) {
this.player = player;
}
public Player getPlayer() {
return this.player;
}
public void setPlayer(Player player) {
if (this.player == null) {
this.player = player;
}
}
}

View File

@ -0,0 +1,15 @@
package emu.grasscutter.game.player;
import lombok.NonNull;
public abstract class BasePlayerManager {
protected transient final Player player;
public BasePlayerManager(@NonNull Player player) {
this.player = player;
}
public Player getPlayer() {
return this.player;
}
}

View File

@ -4,7 +4,6 @@ import dev.morphia.annotations.*;
import emu.grasscutter.GameConstants; import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.PersonalLineData;
import emu.grasscutter.data.excels.PlayerLevelData; import emu.grasscutter.data.excels.PlayerLevelData;
import emu.grasscutter.data.excels.WeatherData; import emu.grasscutter.data.excels.WeatherData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
@ -13,7 +12,6 @@ import emu.grasscutter.game.CoopRequest;
import emu.grasscutter.game.ability.AbilityManager; import emu.grasscutter.game.ability.AbilityManager;
import emu.grasscutter.game.activity.ActivityManager; import emu.grasscutter.game.activity.ActivityManager;
import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.avatar.AvatarProfileData;
import emu.grasscutter.game.avatar.AvatarStorage; import emu.grasscutter.game.avatar.AvatarStorage;
import emu.grasscutter.game.battlepass.BattlePassManager; import emu.grasscutter.game.battlepass.BattlePassManager;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
@ -34,7 +32,6 @@ 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.InsectCaptureManager;
import emu.grasscutter.game.managers.ResinManager; import emu.grasscutter.game.managers.ResinManager;
import emu.grasscutter.game.managers.collection.CollectionManager;
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;
import emu.grasscutter.game.managers.energy.EnergyManager; import emu.grasscutter.game.managers.energy.EnergyManager;
@ -91,11 +88,11 @@ import static emu.grasscutter.Configuration.*;
@Entity(value = "players", useDiscriminator = false) @Entity(value = "players", useDiscriminator = false)
public class Player { public class Player {
@Id private int id; @Id private int id;
@Indexed(options = @IndexOptions(unique = true)) private String accountId; @Indexed(options = @IndexOptions(unique = true)) private String accountId;
private transient Account account;
@Transient private Account account; private transient GameSession session;
private String nickname; private String nickname;
private String signature; private String signature;
private int headImage; private int headImage;
@ -104,22 +101,29 @@ public class Player {
private Position rotation; private Position rotation;
private PlayerBirthday birthday; private PlayerBirthday birthday;
private PlayerCodex codex; private PlayerCodex codex;
@Getter private PlayerOpenStateManager openStateManager; private boolean showAvatars;
private List<Integer> showAvatarList;
private Map<Integer, Integer> properties; private Map<Integer, Integer> properties;
private Set<Integer> nameCardList; private int currentRealmId;
private Set<Integer> flyCloakList; private int widgetId;
private Set<Integer> costumeList; private int sceneId;
private Set<Integer> unlockedForgingBlueprints; private int regionId;
private Set<Integer> unlockedCombines; private int mainCharacterId;
private Set<Integer> unlockedFurniture; private boolean godmode;
private Set<Integer> unlockedFurnitureSuite; private boolean stamina;
private List<ActiveForgeData> activeForges;
private Map<Integer, Integer> unlockedRecipies; @Getter private Set<Integer> nameCardList;
@Getter private Set<Integer> flyCloakList;
private Integer widgetId; @Getter private Set<Integer> costumeList;
@Getter private Set<Integer> rewardedLevels;
private Set<Integer> realmList; @Getter private Set<Integer> realmList;
private Integer currentRealmId; @Getter private Set<Integer> unlockedForgingBlueprints;
@Getter private Set<Integer> unlockedCombines;
@Getter private Set<Integer> unlockedFurniture;
@Getter private Set<Integer> unlockedFurnitureSuite;
@Getter private Map<Long, ExpeditionInfo> expeditionInfo;
@Getter private Map<Integer, Integer> unlockedRecipies;
@Getter private List<ActiveForgeData> activeForges;
@Transient private long nextGuid = 0; @Transient private long nextGuid = 0;
@Transient private int peerId; @Transient private int peerId;
@ -127,71 +131,56 @@ public class Player {
@Transient private Scene scene; @Transient private Scene scene;
@Transient @Getter private int weatherId = 0; @Transient @Getter private int weatherId = 0;
@Transient @Getter private ClimateType climate = ClimateType.CLIMATE_SUNNY; @Transient @Getter private ClimateType climate = ClimateType.CLIMATE_SUNNY;
@Transient private GameSession session;
@Transient private AvatarStorage avatars; // Player managers go here
@Transient private Inventory inventory; @Getter private transient AvatarStorage avatars;
@Transient private FriendsList friendsList; @Getter private transient Inventory inventory;
@Transient private MailHandler mailHandler; @Getter private transient FriendsList friendsList;
@Transient private MessageHandler messageHandler; @Getter private transient MailHandler mailHandler;
@Transient private AbilityManager abilityManager; @Getter private transient MessageHandler messageHandler;
@Transient private QuestManager questManager; @Getter private transient AbilityManager abilityManager;
@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;
@Getter private transient ResinManager resinManager;
@Getter private transient ForgingManager forgingManager;
@Getter private transient DeforestationManager deforestationManager;
@Getter private transient FurnitureManager furnitureManager;
@Getter private transient BattlePassManager battlePassManager;
@Getter private transient CookingManager cookingManager;
@Getter private transient ActivityManager activityManager;
@Transient private SotSManager sotsManager; // Manager data (Save-able to the database)
@Transient private InsectCaptureManager insectCaptureManager; private PlayerProfile playerProfile;
private TeamManager teamManager;
private TeamManager teamManager;
@Transient private TowerManager towerManager;
private TowerData towerData; private TowerData towerData;
private PlayerGachaInfo gachaInfo; private PlayerGachaInfo gachaInfo;
private PlayerProfile playerProfile; private PlayerOpenStateManager openStateManager;
private boolean showAvatar; private CollectionRecordStore collectionRecordStore;
private ArrayList<AvatarProfileData> shownAvatars;
private Set<Integer> rewardedLevels;
private ArrayList<ShopLimit> shopLimit; private ArrayList<ShopLimit> shopLimit;
private Map<Long, ExpeditionInfo> expeditionInfo;
@Getter private transient GameHome home;
private int sceneId;
private int regionId;
private int mainCharacterId;
private boolean godmode;
private boolean stamina;
private boolean moonCard; private boolean moonCard;
private Date moonCardStartTime; private Date moonCardStartTime;
private int moonCardDuration; private int moonCardDuration;
private Set<Date> moonCardGetTimes; private Set<Date> moonCardGetTimes;
private List<Integer> showAvatarList;
private boolean showAvatars;
@Transient private boolean paused; @Transient private boolean paused;
@Transient private int enterSceneToken; @Transient private int enterSceneToken;
@Transient private SceneLoadState sceneState; @Transient private SceneLoadState sceneState;
@Transient private boolean hasSentAvatarDataNotify; @Transient private boolean hasSentAvatarDataNotify;
@Transient private long nextSendPlayerLocTime = 0; @Transient private long nextSendPlayerLocTime = 0;
@Transient private final Int2ObjectMap<CoopRequest> coopRequests; private transient final Int2ObjectMap<CoopRequest> coopRequests;
@Transient private final Queue<AttackResult> attackResults; private transient final Queue<AttackResult> attackResults;
@Transient private final InvokeHandler<CombatInvokeEntry> combatInvokeHandler; @Getter private transient final InvokeHandler<CombatInvokeEntry> combatInvokeHandler;
@Transient private final InvokeHandler<AbilityInvokeEntry> abilityInvokeHandler; @Getter private transient final InvokeHandler<AbilityInvokeEntry> abilityInvokeHandler;
@Transient private final InvokeHandler<AbilityInvokeEntry> clientAbilityInitFinishHandler; @Getter private transient final InvokeHandler<AbilityInvokeEntry> clientAbilityInitFinishHandler;
@Transient private MapMarksManager mapMarksManager;
@Transient private StaminaManager staminaManager;
@Transient private EnergyManager energyManager;
@Transient private ResinManager resinManager;
@Transient private ForgingManager forgingManager;
@Transient private DeforestationManager deforestationManager;
@Transient private GameHome home;
@Transient private FurnitureManager furnitureManager;
@Transient private BattlePassManager battlePassManager;
@Transient private CookingManager cookingManager;
// @Transient private
@Getter @Transient private ActivityManager activityManager;
@Transient private CollectionManager collectionManager;
private CollectionRecordStore collectionRecordStore;
private long springLastUsed; private long springLastUsed;
private HashMap<String, MapMark> mapMarks; private HashMap<String, MapMark> mapMarks;
@ -209,8 +198,8 @@ public class Player {
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.insectCaptureManager = new InsectCaptureManager(this);
this.questManager = new QuestManager(this);
this.setQuestManager(new QuestManager(this));
this.pos = new Position(); this.pos = new Position();
this.rotation = new Position(); this.rotation = new Position();
this.properties = new HashMap<>(); this.properties = new HashMap<>();
@ -374,10 +363,6 @@ public class Player {
this.session.send(new PacketSceneAreaWeatherNotify(this)); this.session.send(new PacketSceneAreaWeatherNotify(this));
} }
public int getGmLevel() {
return 1;
}
public String getNickname() { public String getNickname() {
return nickname; return nickname;
} }
@ -413,10 +398,6 @@ public class Player {
this.widgetId = widgetId; this.widgetId = widgetId;
} }
public Set<Integer> getRealmList() {
return realmList;
}
public void setRealmList(Set<Integer> realmList) { public void setRealmList(Set<Integer> realmList) {
this.realmList = realmList; this.realmList = realmList;
} }
@ -430,16 +411,14 @@ public class Player {
this.realmList.add(realmId); this.realmList.add(realmId);
} }
public Integer getCurrentRealmId() { public int getCurrentRealmId() {
return currentRealmId; return currentRealmId;
} }
public void setCurrentRealmId(Integer currentRealmId) { public void setCurrentRealmId(int currentRealmId) {
this.currentRealmId = currentRealmId; this.currentRealmId = currentRealmId;
} }
public GameHome getHome(){
return home;
}
public Position getPos() { public Position getPos() {
return pos; return pos;
} }
@ -598,10 +577,6 @@ public class Player {
return this.teamManager; return this.teamManager;
} }
public TowerManager getTowerManager() {
return towerManager;
}
public TowerData getTowerData() { public TowerData getTowerData() {
if (towerData == null) { if (towerData == null) {
// because of mistake, null may be saved as storage at some machine, this if can be removed in future // because of mistake, null may be saved as storage at some machine, this if can be removed in future
@ -610,14 +585,6 @@ public class Player {
return towerData; return towerData;
} }
public QuestManager getQuestManager() {
return questManager;
}
public void setQuestManager(QuestManager questManager) {
this.questManager = questManager;
}
public PlayerGachaInfo getGachaInfo() { public PlayerGachaInfo getGachaInfo() {
return gachaInfo; return gachaInfo;
} }
@ -647,42 +614,6 @@ public class Player {
return getProperties().get(prop.getId()); return getProperties().get(prop.getId());
} }
public Set<Integer> getFlyCloakList() {
return flyCloakList;
}
public Set<Integer> getCostumeList() {
return costumeList;
}
public Set<Integer> getNameCardList() {
return this.nameCardList;
}
public Set<Integer> getUnlockedForgingBlueprints() {
return this.unlockedForgingBlueprints;
}
public Set<Integer> getUnlockedCombines() {
return this.unlockedCombines;
}
public Set<Integer> getUnlockedFurniture() {
return unlockedFurniture;
}
public Set<Integer> getUnlockedFurnitureSuite() {
return unlockedFurnitureSuite;
}
public List<ActiveForgeData> getActiveForges() {
return this.activeForges;
}
public Map<Integer, Integer> getUnlockedRecipies() {
return this.unlockedRecipies;
}
public MpSettingType getMpSetting() { public MpSettingType getMpSetting() {
return MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; // TEMP return MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; // TEMP
} }
@ -695,34 +626,6 @@ public class Player {
return coopRequests; return coopRequests;
} }
public InvokeHandler<CombatInvokeEntry> getCombatInvokeHandler() {
return this.combatInvokeHandler;
}
public InvokeHandler<AbilityInvokeEntry> getAbilityInvokeHandler() {
return this.abilityInvokeHandler;
}
public InvokeHandler<AbilityInvokeEntry> getClientAbilityInitFinishHandler() {
return clientAbilityInitFinishHandler;
}
public AvatarStorage getAvatars() {
return avatars;
}
public Inventory getInventory() {
return inventory;
}
public FriendsList getFriendsList() {
return this.friendsList;
}
public MailHandler getMailHandler() {
return mailHandler;
}
public int getEnterSceneToken() { public int getEnterSceneToken() {
return enterSceneToken; return enterSceneToken;
} }
@ -931,10 +834,6 @@ public class Player {
session.send(new PacketCardProductRewardNotify(getMoonCardRemainDays())); session.send(new PacketCardProductRewardNotify(getMoonCardRemainDays()));
} }
public Map<Long, ExpeditionInfo> getExpeditionInfo() {
return expeditionInfo;
}
public void addExpeditionInfo(long avaterGuid, int expId, int hourTime, int startTime){ public void addExpeditionInfo(long avaterGuid, int expId, int hourTime, int startTime){
ExpeditionInfo exp = new ExpeditionInfo(); ExpeditionInfo exp = new ExpeditionInfo();
exp.setExpId(expId); exp.setExpId(expId);
@ -1188,10 +1087,8 @@ public class Player {
return this.birthday.getDay() > 0; return this.birthday.getDay() > 0;
} }
public PlayerCodex getCodex(){ return this.codex; } public PlayerCodex getCodex() {
return this.codex;
public Set<Integer> getRewardedLevels() {
return rewardedLevels;
} }
public void setRewardedLevels(Set<Integer> rewardedLevels) { public void setRewardedLevels(Set<Integer> rewardedLevels) {
@ -1290,59 +1187,12 @@ public class Player {
.build(); .build();
} }
public MapMarksManager getMapMarksManager() {
return mapMarksManager;
}
public StaminaManager getStaminaManager() { return staminaManager; }
public SotSManager getSotSManager() { return sotsManager; }
public EnergyManager getEnergyManager() {
return this.energyManager;
}
public ResinManager getResinManager() {
return this.resinManager;
}
public ForgingManager getForgingManager() {
return this.forgingManager;
}
public FurnitureManager getFurnitureManager() {
return furnitureManager;
}
public BattlePassManager getBattlePassManager(){
return battlePassManager;
}
public CookingManager getCookingManager() {
return cookingManager;
}
public void loadBattlePassManager() { public void loadBattlePassManager() {
if (this.battlePassManager != null) return; if (this.battlePassManager != null) return;
this.battlePassManager = DatabaseHelper.loadBattlePass(this); this.battlePassManager = DatabaseHelper.loadBattlePass(this);
this.battlePassManager.getMissions().values().removeIf(mission -> mission.getData() == null); this.battlePassManager.getMissions().values().removeIf(mission -> mission.getData() == null);
} }
public AbilityManager getAbilityManager() {
return abilityManager;
}
public DeforestationManager getDeforestationManager() {
return deforestationManager;
}
public CollectionManager getCollectionManager() {
if(this.collectionManager==null){
this.collectionManager = new CollectionManager();
}
return this.collectionManager;
}
public CollectionRecordStore getCollectionRecordStore() { public CollectionRecordStore getCollectionRecordStore() {
if(this.collectionRecordStore==null){ if(this.collectionRecordStore==null){
this.collectionRecordStore = new CollectionRecordStore(); this.collectionRecordStore = new CollectionRecordStore();
@ -1350,11 +1200,21 @@ public class Player {
return collectionRecordStore; return collectionRecordStore;
} }
public HashMap<String, MapMark> getMapMarks() { return mapMarks; } public Map<String, MapMark> getMapMarks() {
if (this.mapMarks == null) {
this.mapMarks = new HashMap<String, MapMark>();
}
return mapMarks;
}
public void setMapMarks(HashMap<String, MapMark> newMarks) { mapMarks = newMarks; } public PlayerOpenStateManager getOpenStateManager() {
if (this.openStateManager == null) {
this.openStateManager = new PlayerOpenStateManager(this);
}
return openStateManager;
}
public synchronized void onTick() { public synchronized void onTick() {
// Check ping // Check ping
if (this.getLastPingTime() > System.currentTimeMillis() + 60000) { if (this.getLastPingTime() > System.currentTimeMillis() + 60000) {
this.getSession().close(); this.getSession().close();
@ -1453,7 +1313,6 @@ public class Player {
this.getCodex().setPlayer(this); this.getCodex().setPlayer(this);
this.getOpenStateManager().setPlayer(this); this.getOpenStateManager().setPlayer(this);
this.getTeamManager().setPlayer(this); this.getTeamManager().setPlayer(this);
this.getTowerManager().setPlayer(this);
} }
public void save() { public void save() {
@ -1463,24 +1322,15 @@ public class Player {
// Called from tokenrsp // Called from tokenrsp
public void loadFromDatabase() { public void loadFromDatabase() {
// Make sure these exist // Make sure these exist
if (this.getTowerManager() == null) {
this.towerManager = new TowerManager(this);
}
if (this.getTeamManager() == null) { if (this.getTeamManager() == null) {
this.teamManager = new TeamManager(this); this.teamManager = new TeamManager(this);
} }
if (this.getCodex() == null) { if (this.getCodex() == null) {
this.codex = new PlayerCodex(this); this.codex = new PlayerCodex(this);
} }
if (this.getOpenStateManager() == null) {
this.openStateManager = new PlayerOpenStateManager(this);
}
if (this.getProfile().getUid() == 0) { if (this.getProfile().getUid() == 0) {
this.getProfile().syncWithCharacter(this); this.getProfile().syncWithCharacter(this);
} }
//Make sure towerManager's player is online player
this.getTowerManager().setPlayer(this);
this.getCollectionManager().setPlayer(this);
// Load from db // Load from db
this.getAvatars().loadFromDatabase(); this.getAvatars().loadFromDatabase();
@ -1537,8 +1387,8 @@ public class Player {
this.cookingManager.sendCookDataNofity(); this.cookingManager.sendCookDataNofity();
// Unlock in case this is an existing user that reached a level before we implemented unlocking. // Unlock in case this is an existing user that reached a level before we implemented unlocking.
this.openStateManager.unlockLevelDependentStates(); this.getOpenStateManager().unlockLevelDependentStates();
this.openStateManager.onPlayerLogin(); this.getOpenStateManager().onPlayerLogin();
getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward. getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward.

View File

@ -16,9 +16,7 @@ import java.util.stream.Stream;
import static emu.grasscutter.game.props.OpenState.*; import static emu.grasscutter.game.props.OpenState.*;
@Entity @Entity
public class PlayerOpenStateManager { public class PlayerOpenStateManager extends BasePlayerDataManager {
@Transient private Player player;
// Map of all open states that this player has. Do not put default values here. // Map of all open states that this player has. Do not put default values here.
private Map<Integer, Integer> map; private Map<Integer, Integer> map;
@ -37,11 +35,7 @@ public class PlayerOpenStateManager {
.collect(Collectors.toSet()); .collect(Collectors.toSet());
public PlayerOpenStateManager(Player player) { public PlayerOpenStateManager(Player player) {
this.player = player; super(player);
}
public void setPlayer(Player player) {
this.player = player;
} }
public Map<Integer, Integer> getOpenStateMap() { public Map<Integer, Integer> getOpenStateMap() {

View File

@ -41,7 +41,7 @@ import it.unimi.dsi.fastutil.ints.IntSet;
import static emu.grasscutter.Configuration.*; import static emu.grasscutter.Configuration.*;
@Entity @Entity
public class TeamManager { public class TeamManager extends BasePlayerDataManager {
@Transient private Player player; @Transient private Player player;
private Map<Integer, TeamInfo> teams; private Map<Integer, TeamInfo> teams;
@ -56,10 +56,7 @@ public class TeamManager {
@Transient private final IntSet teamResonancesConfig; @Transient private final IntSet teamResonancesConfig;
@Transient private int useTemporarilyTeamIndex = -1; @Transient private int useTemporarilyTeamIndex = -1;
/** @Transient private List<TeamInfo> temporaryTeam; // Temporary Team for tower
* Temporary Team for tower
*/
@Transient private List<TeamInfo> temporaryTeam;
public TeamManager() { public TeamManager() {
this.mpTeam = new TeamInfo(); this.mpTeam = new TeamInfo();
@ -71,7 +68,7 @@ public class TeamManager {
public TeamManager(Player player) { public TeamManager(Player player) {
this(); this();
this.player = player; this.setPlayer(player);
this.teams = new HashMap<>(); this.teams = new HashMap<>();
this.currentTeamIndex = 1; this.currentTeamIndex = 1;
@ -80,17 +77,9 @@ public class TeamManager {
} }
} }
public Player getPlayer() {
return player;
}
public World getWorld() { public World getWorld() {
return player.getWorld(); return player.getWorld();
} }
public void setPlayer(Player player) {
this.player = player;
}
public Map<Integer, TeamInfo> getTeams() { public Map<Integer, TeamInfo> getTeams() {
return this.teams; return this.teams;

View File

@ -10,6 +10,7 @@ import emu.grasscutter.data.binout.MainQuestData;
import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.data.excels.QuestData;
import emu.grasscutter.data.excels.QuestData.QuestCondition; import emu.grasscutter.data.excels.QuestData.QuestCondition;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.quest.enums.ParentQuestState; import emu.grasscutter.game.quest.enums.ParentQuestState;
import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.game.quest.enums.QuestTrigger;
@ -19,19 +20,14 @@ import emu.grasscutter.server.packet.send.*;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class QuestManager { public class QuestManager extends BasePlayerManager {
private final Player player;
private final Int2ObjectMap<GameMainQuest> quests; private final Int2ObjectMap<GameMainQuest> quests;
public QuestManager(Player player) { public QuestManager(Player player) {
this.player = player; super(player);
this.quests = new Int2ObjectOpenHashMap<>(); this.quests = new Int2ObjectOpenHashMap<>();
} }
public Player getPlayer() {
return player;
}
public Int2ObjectMap<GameMainQuest> getQuests() { public Int2ObjectMap<GameMainQuest> getQuests() {
return quests; return quests;
} }

View File

@ -4,6 +4,7 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.TowerLevelData; import emu.grasscutter.data.excels.TowerLevelData;
import emu.grasscutter.game.dungeons.DungeonSettleListener; import emu.grasscutter.game.dungeons.DungeonSettleListener;
import emu.grasscutter.game.dungeons.TowerDungeonSettleListener; import emu.grasscutter.game.dungeons.TowerDungeonSettleListener;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
@ -11,55 +12,54 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class TowerManager { public class TowerManager extends BasePlayerManager {
private Player player;
private TowerData towerData;
public TowerManager(Player player) { public TowerManager(Player player) {
setPlayer(player); super(player);
} }
public void setPlayer(Player player) {
this.player = player; public TowerData getTowerData() {
this.towerData = player.getTowerData(); return getPlayer().getTowerData();
} }
public int getCurrentFloorId() { public int getCurrentFloorId() {
return towerData.currentFloorId; return getTowerData().currentFloorId;
} }
public int getCurrentLevelId(){ public int getCurrentLevelId(){
return towerData.currentLevelId + towerData.currentLevel; return getTowerData().currentLevelId + getTowerData().currentLevel;
} }
/** /**
* form 1-3 * form 1-3
*/ */
public int getCurrentLevel(){ public int getCurrentLevel(){
return towerData.currentLevel + 1; return getTowerData().currentLevel + 1;
} }
private static final List<DungeonSettleListener> towerDungeonSettleListener = List.of(new TowerDungeonSettleListener()); private static final List<DungeonSettleListener> towerDungeonSettleListener = List.of(new TowerDungeonSettleListener());
public Map<Integer, TowerLevelRecord> getRecordMap() { public Map<Integer, TowerLevelRecord> getRecordMap() {
Map<Integer, TowerLevelRecord> recordMap = towerData.recordMap; Map<Integer, TowerLevelRecord> recordMap = getTowerData().recordMap;
if(recordMap == null || recordMap.size()==0){ if(recordMap == null || recordMap.size()==0){
recordMap = new HashMap<>(); recordMap = new HashMap<>();
recordMap.put(1001, new TowerLevelRecord(1001)); recordMap.put(1001, new TowerLevelRecord(1001));
towerData.recordMap = recordMap; getTowerData().recordMap = recordMap;
} }
return recordMap; return recordMap;
} }
public void teamSelect(int floor, List<List<Long>> towerTeams) { public void teamSelect(int floor, List<List<Long>> towerTeams) {
var floorData = GameData.getTowerFloorDataMap().get(floor); var floorData = GameData.getTowerFloorDataMap().get(floor);
towerData.currentFloorId = floorData.getFloorId(); getTowerData().currentFloorId = floorData.getFloorId();
towerData.currentLevel = 0; getTowerData().currentLevel = 0;
towerData.currentLevelId = GameData.getTowerLevelDataMap().values().stream() getTowerData().currentLevelId = GameData.getTowerLevelDataMap().values().stream()
.filter(x -> x.getLevelGroupId() == floorData.getLevelGroupId() && x.getLevelIndex() == 1) .filter(x -> x.getLevelGroupId() == floorData.getLevelGroupId() && x.getLevelIndex() == 1)
.findFirst() .findFirst()
.map(TowerLevelData::getId) .map(TowerLevelData::getId)
.orElse(0); .orElse(0);
if (towerData.entryScene == 0){ if (getTowerData().entryScene == 0){
towerData.entryScene = player.getSceneId(); getTowerData().entryScene = player.getSceneId();
} }
player.getTeamManager().setupTemporaryTeam(towerTeams); player.getTeamManager().setupTemporaryTeam(towerTeams);
@ -78,22 +78,22 @@ public class TowerManager {
towerDungeonSettleListener); towerDungeonSettleListener);
// make sure user can exit dungeon correctly // make sure user can exit dungeon correctly
player.getScene().setPrevScene(towerData.entryScene); player.getScene().setPrevScene(getTowerData().entryScene);
player.getScene().setPrevScenePoint(enterPointId); player.getScene().setPrevScenePoint(enterPointId);
player.getSession().send(new PacketTowerEnterLevelRsp(towerData.currentFloorId, getCurrentLevel())); player.getSession().send(new PacketTowerEnterLevelRsp(getTowerData().currentFloorId, getCurrentLevel()));
// stop using skill // stop using skill
player.getSession().send(new PacketCanUseSkillNotify(false)); player.getSession().send(new PacketCanUseSkillNotify(false));
// notify the cond of stars // notify the cond of stars
player.getSession().send(new PacketTowerLevelStarCondNotify(towerData.currentFloorId, getCurrentLevel())); player.getSession().send(new PacketTowerLevelStarCondNotify(getTowerData().currentFloorId, getCurrentLevel()));
} }
public void notifyCurLevelRecordChange(){ public void notifyCurLevelRecordChange(){
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(towerData.currentFloorId, getCurrentLevel())); player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(getTowerData().currentFloorId, getCurrentLevel()));
} }
public void notifyCurLevelRecordChangeWhenDone(int stars){ public void notifyCurLevelRecordChangeWhenDone(int stars){
Map<Integer, TowerLevelRecord> recordMap = getRecordMap(); Map<Integer, TowerLevelRecord> recordMap = getRecordMap();
int currentFloorId = towerData.currentFloorId; int currentFloorId = getTowerData().currentFloorId;
if(!recordMap.containsKey(currentFloorId)){ if(!recordMap.containsKey(currentFloorId)){
recordMap.put(currentFloorId, recordMap.put(currentFloorId,
new TowerLevelRecord(currentFloorId).setLevelStars(getCurrentLevelId(),stars)); new TowerLevelRecord(currentFloorId).setLevelStars(getCurrentLevelId(),stars));
@ -102,7 +102,7 @@ public class TowerManager {
recordMap.get(currentFloorId).setLevelStars(getCurrentLevelId(),stars)); recordMap.get(currentFloorId).setLevelStars(getCurrentLevelId(),stars));
} }
towerData.currentLevel++; getTowerData().currentLevel++;
if(!hasNextLevel()){ if(!hasNextLevel()){
// set up the next floor // set up the next floor
@ -113,17 +113,17 @@ public class TowerManager {
} }
} }
public boolean hasNextLevel(){ public boolean hasNextLevel(){
return towerData.currentLevel < 3; return getTowerData().currentLevel < 3;
} }
public int getNextFloorId() { public int getNextFloorId() {
return player.getServer().getTowerScheduleManager().getNextFloorId(towerData.currentFloorId); return player.getServer().getTowerScheduleManager().getNextFloorId(getTowerData().currentFloorId);
} }
public boolean hasNextFloor(){ public boolean hasNextFloor(){
return player.getServer().getTowerScheduleManager().getNextFloorId(towerData.currentFloorId) > 0; return player.getServer().getTowerScheduleManager().getNextFloorId(getTowerData().currentFloorId) > 0;
} }
public void clearEntry() { public void clearEntry() {
towerData.entryScene = 0; getTowerData().entryScene = 0;
} }
public boolean canEnterScheduleFloor(){ public boolean canEnterScheduleFloor(){

View File

@ -11,6 +11,6 @@ import emu.grasscutter.server.game.GameSession;
public class HandlerEnterTransPointRegionNotify extends PacketHandler { public class HandlerEnterTransPointRegionNotify extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception{ public void handle(GameSession session, byte[] header, byte[] payload) throws Exception{
session.getPlayer().getSotSManager().handleEnterTransPointRegionNotify(); session.getPlayer().getSotsManager().handleEnterTransPointRegionNotify();
} }
} }

View File

@ -12,6 +12,6 @@ import emu.grasscutter.server.game.GameSession;
public class HandlerExitTransPointRegionNotify extends PacketHandler { public class HandlerExitTransPointRegionNotify extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception{ public void handle(GameSession session, byte[] header, byte[] payload) throws Exception{
session.getPlayer().getSotSManager().handleExitTransPointRegionNotify(); session.getPlayer().getSotsManager().handleExitTransPointRegionNotify();
} }
} }

View File

@ -13,7 +13,7 @@ public class PacketHomeBasicInfoNotify extends BasePacket {
public PacketHomeBasicInfoNotify(Player player, boolean editMode) { public PacketHomeBasicInfoNotify(Player player, boolean editMode) {
super(PacketOpcodes.HomeBasicInfoNotify); super(PacketOpcodes.HomeBasicInfoNotify);
if(player.getCurrentRealmId() == null){ if (player.getCurrentRealmId() <= 0) {
return; return;
} }

View File

@ -10,7 +10,7 @@ import java.util.*;
public class PacketMarkMapRsp extends BasePacket { public class PacketMarkMapRsp extends BasePacket {
public PacketMarkMapRsp(HashMap<String, MapMark> mapMarks) { public PacketMarkMapRsp(Map<String, MapMark> mapMarks) {
super(PacketOpcodes.MarkMapRsp); super(PacketOpcodes.MarkMapRsp);
MarkMapRspOuterClass.MarkMapRsp.Builder proto = MarkMapRspOuterClass.MarkMapRsp.newBuilder(); MarkMapRspOuterClass.MarkMapRsp.Builder proto = MarkMapRspOuterClass.MarkMapRsp.newBuilder();