|
@@ -2,39 +2,68 @@ package com.incubator.game.player;
|
|
|
|
|
|
import com.incubator.game.GGame;
|
|
|
import com.incubator.game.data.entity.PlayerInfoPO;
|
|
|
+import com.incubator.game.util.Const.PlayerEventType;
|
|
|
+import com.incubator.game.util.Const.ManagerType;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 玩家实体
|
|
|
*/
|
|
|
public class Player extends GPlayer {
|
|
|
|
|
|
+ /** 玩家绑定的所有功能管理类 **/
|
|
|
+ public Map<ManagerType, ModuleManager> allManagers = new HashMap<>();
|
|
|
+
|
|
|
/** 玩家数据 **/
|
|
|
public PlayerInfoPO data;
|
|
|
|
|
|
- public Player(PlayerInfoPO playerInfoPO) {
|
|
|
+ public Player(PlayerInfoPO playerData) {
|
|
|
try {
|
|
|
- this.data = playerInfoPO;
|
|
|
+ this.init(playerData);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("玩家初始化数据出错...{}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 注册玩家管理类
|
|
|
+ *
|
|
|
+ * @param manager
|
|
|
+ */
|
|
|
+ private void registerManager(ModuleManager manager) {
|
|
|
+ if (manager.getManagerType() == null) {
|
|
|
+ logger.error("{}, manager.getManagerType 为空", manager.getClass());
|
|
|
+ }
|
|
|
+ this.allManagers.put(manager.getManagerType(), manager);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化玩家数据,注册绑定玩家各功能管理类
|
|
|
+ *
|
|
|
+ * @param data
|
|
|
+ */
|
|
|
+ private void init(PlayerInfoPO data) {
|
|
|
+ this.data = data;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 角色登录成功, 服务器内部处理逻辑在此
|
|
|
*/
|
|
|
public void onLogin() {
|
|
|
- this.logger.info("玩家登录成功...");
|
|
|
- //0点重置数据
|
|
|
-// Date now = new Date();
|
|
|
-// if (DateUtils.isSameDay(now, this.memePunksData.refreshTime)) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
+ logger.info("玩家登录成功...");
|
|
|
+
|
|
|
this.refreshNewDay();
|
|
|
|
|
|
- // 加入在线玩家集合
|
|
|
- GGame.onlinePlayers.put(this.getId(), this);
|
|
|
+ for (ModuleManager manager : allManagers.values()) {
|
|
|
+ try {
|
|
|
+ manager.onPlayerEvent(PlayerEventType.AFTER_LOGIN);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(manager.getClass().getName(), " AFTER_LOGIN 登录出错: ", this.getId(), ", ", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -55,7 +84,17 @@ public class Player extends GPlayer {
|
|
|
* 每日刷新
|
|
|
*/
|
|
|
public void refreshNewDay() {
|
|
|
- this.logger.info("每日刷新玩家数据...");
|
|
|
+ //0点重置数据
|
|
|
+// Date now = new Date();
|
|
|
+// if (DateUtils.isSameDay(now, this.memePunksData.refreshTime)) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+ for (ModuleManager manager : this.allManagers.values()) {
|
|
|
+ manager.onPlayerEvent(PlayerEventType.REFRESH_NEWDAY);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.info("refreshNewDay playerId : {}, name : {}", this.getId(), this.data.name);
|
|
|
}
|
|
|
|
|
|
@Override
|