yyl
19 小时以前 30ba2ef747ced774bef177d5273cb5a3429cff49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System.Collections.Generic;
using UnityEngine;
 
public class BattleField
{
    public BattleObjMgr battleObjMgr;
 
    public RecordPlayer recordPlayer;
 
    public IOperationAgent operationAgent;
 
    public int round = 0;
 
    public bool IsActive
    {
        get;
        protected set;
    }
 
    public bool IsBattleFinish
    {
        get;
        protected set;
    }
 
    public virtual bool IsPvp
    {
        get
        {
            return false;
        }
    }
 
    private bool m_IsPause = false;
 
    public bool IsPause
    {
        get
        {
            return m_IsPause;
        }
        protected set
        {
            m_IsPause = value;
 
            if (m_IsPause)
            {
                PauseGame();
            }
            else
            {
                ResumeGame();
            }
        }
    }
 
    public BattleRootNode battleRootNode;
 
    private BattleMode battleMode;
 
    public virtual void Init(TeamBase _redTeam, TeamBase _blueTeam)
    {
        GameObject go = ResManager.Instance.LoadAsset<GameObject>("Battle/Prefabs", "BattleRootNode");
        GameObject battleRootNodeGO = GameObject.Instantiate(go);
        battleRootNode = battleRootNodeGO.GetComponent<BattleRootNode>();
        battleRootNodeGO.name = this.GetType().Name;
 
        battleObjMgr = new BattleObjMgr();
        battleObjMgr.Init(this, _redTeam, _blueTeam);
 
        recordPlayer = new RecordPlayer();
        recordPlayer.Init(this);
    }
 
    //  在Run之前要设置完毕 要创建Agent
    public void SetBattleMode(BattleMode _battleMode)
    {
        battleMode = _battleMode;
        CreateAgent();
    }
 
    public virtual void Release()
    {
        battleObjMgr.Release();
    }
 
    public virtual void Run()
    {
        if (IsPause)
            return;
 
        if (IsRoundReachLimit())
        {
            return;
        }
 
        recordPlayer.Run();
        battleObjMgr.Run();
 
        if (operationAgent == null)
        {
            Debug.LogError("you should SetBattleMode before Run");
            return;
        }
 
        operationAgent.Run();
    }
 
 
    protected virtual void CreateAgent()
    {
        // Hand,//手动战斗
        // Auto,//自动战斗
        // Record,//战报
        switch (battleMode)
        {
            case BattleMode.Hand:
                operationAgent = new HandModeOperationAgent(this);
                break;
            case BattleMode.Auto:
                operationAgent = new AutoModeOperationAgent(this);
                break;
            case BattleMode.Record:
                operationAgent = new RecordModeOperationAgent(this);
                break;
            default:
                operationAgent = new HandModeOperationAgent(this);
                break;
        }
    }
 
    public virtual void PlayRecord(RecordAction recordAction)
    {
        recordPlayer.PlayRecord(recordAction);
    }
 
    public virtual void PlayRecord(List<RecordAction> recordList)
    {
        recordPlayer.PlayRecord(recordList);
    }
 
    protected virtual void ResumeGame()
    {
        battleObjMgr.ResumeGame();
        recordPlayer.ResumeGame();
    }
 
    protected virtual void PauseGame()
    {
        battleObjMgr.PauseGame();
        recordPlayer.PauseGame();
    }
 
    public bool IsRoundReachLimit()
    {
        // return round > xxx;
        return false;
    }
}