123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System;
- using System.Collections.Generic;
- using Comp;
- using HttpApi;
- using Ragdoll;
- using UnityEngine;
- namespace Game
- {
- public class GameCore : RdSingletonStateMachine<GameState, GameCore>
- {
- [RdReset] public GameState pendingState, battleState, liftState, endState;
- [RdReset] public GamePlayer localPlayer, antiPlayer;
- [RdReset] public int winPlayerId, diamond;
- // 存储组件的容器
- [RdReset] public Dictionary<int, CockActionComp> cockActionComps;
- [RdReset] public Dictionary<int, CockHpComp> cockHpComps;
- [RdReset] public Dictionary<int, MasterActionComp> masterDict;
- // 需要用到的GameObject
- [RdReset] public GameObject parent, camera, resultPanel;
- [RdReset] public BattleMainComp battleMainComp;
- // 游戏运行数据
- [RdReset] public LinkedList<BattleDetailObj> battleDetailObjs;
- [RdReset] public (bool, bool) masterBack; // 主人复位
- [RdReset] public string curBattleSession;
- [RdReset(2)] public int liftTimes;
- [RdReset(true)] public bool showResultPanel = true;
-
- public GameCore()
- {
- }
- public void Exit()
- {
- currentState = null;
- RdResetTool.ResetAttribute(this);
- }
- public void Init(GamePlayer localPlayer, GamePlayer antiPlayer, GameObject parent, GameObject camera,
- BattleDetailListObj jsonLogs, GameObject resultPanel)
- {
- if (currentState != null) // 防止多重初始化
- return;
- pendingState = new GamePendingState(this);
- battleState = new GameBattleState(this);
- liftState = new GameLiftState(this);
- endState = new GameEndState(this);
- // 举J次数限制
- liftTimes = 2;
- this.localPlayer = localPlayer;
- this.antiPlayer = antiPlayer;
- this.parent = parent;
- this.battleMainComp = parent.GetComponent<BattleMainComp>();
- this.camera = camera;
- this.resultPanel = resultPanel;
- cockActionComps = new Dictionary<int, CockActionComp>();
- cockHpComps = new Dictionary<int, CockHpComp>();
- masterDict = new Dictionary<int, MasterActionComp>();
- winPlayerId = jsonLogs.winPlayer;
- diamond = jsonLogs.diamond;
- Array.Sort(jsonLogs.logArray, (obj1, obj2) => obj1.index.CompareTo(obj2.index));
- battleDetailObjs = new LinkedList<BattleDetailObj>();
- foreach (var log in jsonLogs.logArray)
- {
- battleDetailObjs.AddFirst(log);
- }
- Start();
- }
- protected override void Start()
- {
- TransitionToState(pendingState);
- currentState.PlayBattle();
- }
- public ICockController GetController(GamePlayer gamePlayer)
- {
- return GetControllerByPlayerId(gamePlayer.playerId);
- }
- private ICockController GetControllerByPlayerId(int playerId)
- {
- cockActionComps.TryGetValue(playerId, out var cockActionComp);
- return cockActionComp != null ? cockActionComp.CockController : null;
- }
- public CockActionComp GetCockActionCompByPlayerId(int playerId)
- {
- cockActionComps.TryGetValue(playerId, out var cockActionComp);
- return cockActionComp != null ? cockActionComp : null;
- }
- public CockHpComp GetCockHpCompByPlayerId(int playerId)
- {
- cockHpComps.TryGetValue(playerId, out var cockHpComp);
- return cockHpComp != null ? cockHpComp : null;
- }
- public void ReportMasterBack(bool leftSide)
- {
- if (leftSide)
- {
- masterBack.Item1 = true;
- }
- else
- {
- masterBack.Item2 = true;
- }
- Debug.Log("report master back " + masterBack.Item1 + " " + masterBack.Item2);
- if (masterBack.Item1 && masterBack.Item2)
- {
- if (currentState != liftState) return;
- TransitionToState(battleState);
- }
- }
- }
- }
|