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;
|
}
|
|
}
|