using System;
|
using LitJson;
|
using UnityEngine;
|
using System.Collections.Generic;
|
|
// 【主线战斗流程】
|
// 发送 B413 (ReqType 为 2 或 3)
|
// 后端回复 B425标记0开始 (中间N个战斗片段封包) B425标记1结束
|
// 前端解析 N个战斗片段封包 ,拆解成前端支持的action指令,然后进行战斗表现
|
// 表现完毕后继续发送 B413 (ReqType 为 4)
|
// 后端回复 B425标记0开始 (中间N个战斗片段封包) B425标记1结束
|
// 前端解析表现,然后一直循环即可
|
|
public enum StoryBattleState
|
{
|
Break,
|
Battle,
|
}
|
|
public class StoryBattleField : BattleField
|
{
|
protected int chapter;// 章节
|
protected int wave;// 波数
|
protected int level;// 关卡
|
protected JsonData extendData;
|
|
protected MainChapterConfig chapterConfig;
|
|
protected MainLevelConfig levelConfig;
|
|
public StoryBattleState battleState;
|
|
public StoryBattleField() : base(string.Empty)
|
{
|
|
}
|
|
public override void Init(int MapID, int FuncLineID, JsonData _extendData,
|
List<TeamBase> _redTeamList, List<TeamBase> _blueTeamList)
|
{
|
base.Init(MapID, FuncLineID, extendData, _redTeamList, _blueTeamList);
|
|
if (null == _blueTeamList || _blueTeamList.Count == 0)
|
{
|
battleState = StoryBattleState.Break;
|
}
|
else
|
{
|
battleState = StoryBattleState.Battle;
|
}
|
|
// LoadBattleMode();
|
|
chapter = FuncLineID / 10000;
|
wave = MapID == 1 ? FuncLineID % 100 : 1;//第几波怪
|
level = (FuncLineID % 10000) / 100;
|
|
extendData = _extendData;
|
chapterConfig = MainChapterConfig.Get(chapter);
|
levelConfig = MainLevelConfig.Get(level);
|
|
TeamManager.Instance.OnTeamChange += OnTeamChange;
|
}
|
|
public override void Release()
|
{
|
base.Release();
|
TeamManager.Instance.OnTeamChange -= OnTeamChange;
|
}
|
|
protected void LoadBattleMode()
|
{
|
//主线模式:stop休息 无怪;Hand/Auto 有怪 等待指令
|
BattleMode mode = BattleMode.Hand;
|
if (AutoFightModel.Instance.isAutoAttackSet)
|
{
|
mode = BattleMode.Auto;
|
}
|
if (GetBattleMode() == mode)
|
return;
|
|
SetBattleMode(mode);
|
}
|
|
public override void AutoSetBattleMode()
|
{
|
LoadBattleMode();
|
}
|
|
|
public override void TurnFightState(int TurnNum, int State,
|
uint FuncLineID, JsonData extendData)
|
{
|
base.TurnFightState(TurnNum, State, FuncLineID, extendData);
|
|
switch (State)
|
{
|
// 起始状态标记
|
case 0:
|
break;
|
case 1://准备完毕
|
break;
|
case 2://战斗中
|
break;
|
case 3://战斗结束
|
break;
|
case 4://结算奖励
|
break;
|
case 5://结束状态标记
|
break;
|
default:
|
BattleDebug.LogError("recieve a unknown State");
|
break;
|
}
|
}
|
|
public override void OnTurnFightObjAction(int turnNum, int ObjID)
|
{
|
base.OnTurnFightObjAction(turnNum, ObjID);
|
}
|
|
public override void OnTurnFightState(int turnNum, int State, int FuncLineID, JsonData extendData)
|
{
|
base.OnTurnFightState(turnNum, State, FuncLineID, extendData);
|
|
// 0-起始状态标记;1-准备完毕;2-战斗中;3-战斗结束;4-结算奖励;5-结束状态标记 6-休息并结束
|
if (State == 4)
|
{
|
//上一波小怪死亡,默认帮玩家请求一下刷新新怪,玩家点击锤子时候就可以直接攻击
|
RequestFight();
|
}
|
}
|
|
protected void OnTeamChange(TeamType teamType)
|
{
|
if (teamType == TeamType.Story)
|
{
|
if (battleState == StoryBattleState.Break)
|
{
|
ReloadTeam();
|
}
|
}
|
}
|
|
public override void HaveRest()
|
{
|
base.HaveRest();
|
battleState = StoryBattleState.Break;
|
BattleManager.Instance.MainFightRequest(0);
|
}
|
|
protected void ReloadTeam()
|
{
|
battleObjMgr.ReloadTeam(TeamManager.Instance.GetTeam(TeamType.Story), BattleCamp.Red);
|
}
|
|
// public override void OnBattleEnd(JsonData turnFightStateData)
|
// {
|
// base.OnBattleEnd(turnFightStateData);
|
|
// // HaveRest();
|
// }
|
|
public override void Run()
|
{
|
if (operationAgent == null)
|
{
|
//防范异常
|
HaveRest();
|
return;
|
}
|
base.Run();
|
}
|
|
public override void DistributeNextPackage()
|
{
|
// 不要调用base的函数
|
BattleManager.Instance.DistributeNextPackage();
|
}
|
|
|
//请求单次战斗
|
public void RequestFight()
|
{
|
if (IsPause)
|
{
|
//外部控制 IsPause
|
//还需考虑其他不可战斗状况,主线的BOSS战斗也是另外一个场景且不能切出来 等跳过或者结束
|
return;
|
}
|
if (BattleManager.Instance.isWaitServerStory)
|
return;
|
|
// 当前没有在播放战斗录像
|
if (!recordPlayer.IsPlaying())
|
{
|
BattleDebug.LogError("HandModeOperationAgent DoNext 1");
|
// 没有下一个包可以发了
|
if (!BattleManager.Instance.DistributeNextPackage())
|
{
|
|
BattleDebug.LogError("HandModeOperationAgent DoNext 2");
|
|
//再检查一次有没装备未处理
|
if (PackManager.Instance.GetSinglePack(PackType.DropItem).GetItems().Count > 0)
|
{
|
//构建所有物品
|
List<int> dropList = new List<int>();
|
foreach (var item in PackManager.Instance.GetSinglePack(PackType.DropItem).GetItems())
|
{
|
dropList.Add(item.gridIndex);
|
}
|
EquipModel.Instance.NotifyItemDrop(dropList, null);
|
return;
|
}
|
|
// 检查一下锤子的消耗
|
if (!ItemLogicUtility.CheckCurrencyCount(41, PlayerDatas.Instance.baseData.UseHarmerCount, 2))
|
{
|
//多次防范
|
if (GetBattleMode() != BattleMode.Stop)
|
HaveRest();
|
return;
|
}
|
|
// 请求下一个战斗包 或者检查战斗是否结束
|
// ReqType; // 0-停止战斗回城;1-设置消耗倍值;2-挑战关卡小怪;3-挑战关卡boss;4-继续战斗;
|
// 需要发2的情况:休息转变为战斗
|
// 进入休息的逻辑:1.主动点击 2.没有战锤 3.断线重连太久(约定1分钟)仍停留在游戏内 4.回到登录界面(含断线超时)
|
// 需要发4的情况:战场进行中都发4
|
// 1.武将战斗有消耗锤子
|
// 2.战斗结束,开始下一(小)波,此时发4 不扣锤子只有初始化战场
|
// 3.挑战BOSS结束后
|
// BOSS挑战说明:休息中挑战BOSS恢复到休息状态 不发包;
|
// 战斗中挑战BOSS恢复到战斗状态 发4包;服务端挑战boss已经清小怪场
|
|
BattleDebug.LogError("HandModeOperationAgent DoNext 3");
|
byte reqType;
|
|
if (battleState == StoryBattleState.Break)
|
{
|
reqType = 2;
|
}
|
else if (battleState == StoryBattleState.Battle)
|
{
|
reqType = 4; // 继续战斗
|
}
|
else
|
{
|
BattleDebug.LogError("unknown battle state");
|
return;
|
}
|
|
BattleDebug.LogError("HandModeOperationAgent DoNext 4 reqType is " + reqType);
|
|
|
// 如果请求的是2 说明要初始化一下战场
|
BattleManager.Instance.MainFightRequest(reqType);
|
|
// 初始化战场后本来不会自动打 那么就需要再请求一次4继续战斗 来开始战斗
|
if (reqType == 2)
|
{
|
BattleManager.Instance.MainFightRequest(4);
|
}
|
}
|
}
|
else
|
{
|
if (!AutoFightModel.Instance.isAutoAttack)
|
BattleDebug.LogError("action doesnt finish, wait a moment please");
|
}
|
}
|
}
|