using System; using System.Collections.Generic; using Comp; using HttpApi; using Ragdoll; using UnityEngine; namespace Game { public class GameCore : RdSingletonStateMachine { [RdReset] public GameState pendingState; [RdReset] public GameState battleState; [RdReset] public GameState liftState; [RdReset] public GameState endState; [RdReset] public GamePlayer localPlayer; [RdReset] public GamePlayer antiPlayer; [RdReset] public int winPlayerId; [RdReset] public int diamond; [RdReset] public Dictionary cockDict; [RdReset] public Dictionary masterDict; [RdReset] public GameObject parent; [RdReset] public BattleMainComp battleMainComp; [RdReset] public GameObject camera; [RdReset] public GameObject resultPanel; [RdReset] public LinkedList battleDetailObjs; [RdReset] public (bool, bool) masterBack; // 主人复位 [RdReset] public string curBattleSession; [RdReset(2)] public int liftTimes; [RdReset] public bool inBattleState = false; 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(); this.camera = camera; this.resultPanel = resultPanel; cockDict = new Dictionary(); masterDict = new Dictionary(); winPlayerId = jsonLogs.winPlayer; diamond = jsonLogs.diamond; Array.Sort(jsonLogs.logArray, (obj1, obj2) => obj1.index.CompareTo(obj2.index)); battleDetailObjs = new LinkedList(); foreach (var log in jsonLogs.logArray) { battleDetailObjs.AddFirst(log); } Start(); } public override void TransitionToState(GameState nextState) { inBattleState = nextState == battleState; base.TransitionToState(nextState); } protected override void Start() { TransitionToState(pendingState); currentState.PlayBattle(); } public ICockController GetController(GamePlayer gamePlayer) { return GetControllerByPlayerId(gamePlayer.playerId); } public ICockController GetControllerByPlayerId(int playerId) { cockDict.TryGetValue(playerId, out var cockActionComp); return cockActionComp != null ? cockActionComp.CockController : null; } public IMasterController GetMasterControllerByPlayerId(int playerId) { masterDict.TryGetValue(playerId, out var masterActionComp); return masterActionComp != null ? masterActionComp.MasterController : null; } public CockActionComp GetCockActionCompByPlayerId(int playerId) { cockDict.TryGetValue(playerId, out var cockActionComp); return cockActionComp != null ? cockActionComp : null; } public void ReportMasterBack(bool leftSide) { if (leftSide) { masterBack.Item1 = true; } else { masterBack.Item2 = true; } if (masterBack.Item1 && masterBack.Item2) { if (currentState != liftState) return; masterBack = (false, false); TransitionToState(battleState); } } } }