Forráskód Böngészése

优化玩家功能管理类管理

johnclot69 4 hónapja
szülő
commit
0d01796d6c

+ 2 - 0
incubator-game/src/main/java/com/incubator/game/player/GPlayer.java

@@ -41,6 +41,8 @@ public abstract class GPlayer extends GPlayerBase {
 			session.setUid(userid);
 			session.setPlayerId(playerId);
 			this.session = session;
+			// 加入在线玩家集合
+			GGame.onlinePlayers.put(this.getId(), this);
 		}
 	}
 

+ 11 - 0
incubator-game/src/main/java/com/incubator/game/player/ModuleManager.java

@@ -0,0 +1,11 @@
+package com.incubator.game.player;
+
+import com.incubator.game.util.Const.ManagerType;
+import com.incubator.game.util.Const.PlayerEventType;
+
+public abstract class ModuleManager {
+
+	public abstract void onPlayerEvent(PlayerEventType eventType);
+
+	public abstract ManagerType getManagerType();
+}

+ 50 - 11
incubator-game/src/main/java/com/incubator/game/player/Player.java

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

+ 28 - 1
incubator-game/src/main/java/com/incubator/game/util/Const.java

@@ -21,9 +21,36 @@ public final class Const {
 	}
 
 	/**
-	 * 管理类类型
+	 * 玩家管理类类型
 	 */
 	public static enum ManagerType {
+		BASE_DATA,
+		BTL_DATA,
+		SKILL,
+		SKILL_KEY,
+		VIP,
+		/** 邮件 **/
+		MAIL,
+		/** 充值 **/
+		PREPAID,
+		FIST_PAY,
+		AUCTION,
+		/** 活动 **/
+		ACTIVITY,
+		RICH,
+		SEVEN_GOAL,
+		/** 商城 **/
+		SHOP,
+		/** 成长 **/
+		GROWING,
+		/** 成就 **/
+		ACHIEVEMENT,
+		/** 称号 **/
+		TITLE,
+		/** 兑换商城 **/
+		INTERGAL_SHOP,
+		/** 设置 **/
+		HOOKSET,
 		;
 	}