少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-14 fa456af06ddef00145aff72bdee795390c78586e
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ClientCrossServerOneVsOneStage : Stage
{
    static FightInfo fightInfo;
    static PKStageType pkStageType;
    PKStage currentStage;
 
    public override void Initialize()
    {
        base.Initialize();
        fightInfo = default(FightInfo);
        currentStage = null;
    }
 
    protected override void OnStageLoadFinish()
    {
        base.OnStageLoadFinish();
        currentStage = new WaitStartStage();
        currentStage.Begin();
    }
 
    protected override void OnUpdate()
    {
        base.OnUpdate();
 
        if (currentStage != null)
        {
            currentStage.Update();
            if (currentStage.completed)
            {
                currentStage.End();
                currentStage = null;
                switch (pkStageType)
                {
                    case PKStageType.WaitStart:
                        currentStage = new FightStage();
                        break;
                    case PKStageType.Fight:
                        if (fightInfo.isOver)
                        {
                            currentStage = new FightOverStage();
                        }
                        else
                        {
                            currentStage = new RoundPauseStage();
                        }
                        break;
                    case PKStageType.RoundPause:
                        currentStage = new FightStage();
                        break;
                    case PKStageType.FightOver:
                        break;
                    default:
                        break;
                }
 
                if (currentStage != null)
                {
                    currentStage.Begin();
                }
            }
        }
    }
 
    public abstract class PKStage
    {
        public float timer { get; protected set; }
        public float duration { get; protected set; }
        public bool completed { get; protected set; }
 
        public abstract void Begin();
        public abstract void Update();
        public abstract void End();
    }
 
    public class WaitStartStage : PKStage
    {
        public override void Begin()
        {
            pkStageType = PKStageType.WaitStart;
            duration = 10f;
            //模拟开始倒计时
        }
 
        public override void End()
        {
            //模拟战斗开始包
 
        }
 
        public override void Update()
        {
            timer += duration;
            completed = timer >= duration;
        }
    }
 
    public class FightStage : PKStage
    {
        public override void Begin()
        {
            pkStageType = PKStageType.Fight;
            duration = 60f;
            fightInfo.roundCount++;
        }
 
        public override void End()
        {
            fightInfo.roundWinnerIds[fightInfo.roundCount - 1] = 1000;//记录获胜者的id
            if (fightInfo.roundCount >= 2)
            {
                if (fightInfo.roundCount == 2)
                {
                    if (fightInfo.roundWinnerIds[0] == fightInfo.roundWinnerIds[1])
                    {
                        fightInfo.isOver = true;
                    }
                }
                else
                {
                    fightInfo.isOver = true;
                }
            }
        }
 
        public override void Update()
        {
            timer += Time.deltaTime;
            if (timer >= duration)//时间到或者有一方死亡,就算结束
            {
                completed = true;
            }
            else
            {
                completed = false;
            }
        }
 
    }
 
    public class RoundPauseStage : PKStage
    {
        public override void Begin()
        {
            pkStageType = PKStageType.RoundPause;
            duration = 3f;
        }
 
        public override void End()
        {
            //模拟发战斗开始包
        }
 
        public override void Update()
        {
            timer += Time.deltaTime;
            completed = timer >= duration;
        }
    }
 
    public class FightOverStage : PKStage
    {
        public override void Begin()
        {
            pkStageType = PKStageType.FightOver;
            duration = 10f;
        }
 
        public override void End()
        {
            if (ClientCrossServerOneVsOne.isClientCrossServerOneVsOne)
            {
                ClientCrossServerOneVsOne.StopClientCrossServerOneVsOne();
            }
        }
 
        public override void Update()
        {
            timer += Time.deltaTime;
            completed = timer >= duration;
        }
 
    }
 
    public enum PKStageType
    {
        WaitStart,
        Fight,
        RoundPause,
        FightOver,
    }
 
    public struct FightInfo
    {
        public bool isOver;
        public int roundCount;
        public int[] roundWinnerIds;
    }
 
}