123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- 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;
- [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<int, CockActionComp> cockActionComps;
- [RdReset] public Dictionary<int, CockHpComp> cockHpComps;
- [RdReset] public Dictionary<int, MasterActionComp> masterDict;
- [RdReset] public GameObject parent;
- [RdReset] public BattleMainComp battleMainComp;
- [RdReset] public GameObject camera;
- [RdReset] public GameObject resultPanel;
- [RdReset] public LinkedList<BattleDetailObj> 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<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();
- }
- 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);
- }
- 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;
- }
- if (masterBack.Item1 && masterBack.Item2)
- {
- if (currentState != liftState) return;
- masterBack = (false, false);
- TransitionToState(battleState);
- }
- }
- }
- }
|