2021-04-08 20:09:59 +08:00
|
|
|
|
using Cal.DataTable;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class TrialCopyBattleAwakeSystem : AwakeSystem<TrialCopyBattle, Team>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(TrialCopyBattle self, Team team)
|
|
|
|
|
{
|
|
|
|
|
self.Awake(team);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class TrialCopyBattleUpdateSystem : UpdateSystem<TrialCopyBattle>
|
|
|
|
|
{
|
|
|
|
|
public override void Update(TrialCopyBattle self)
|
|
|
|
|
{
|
|
|
|
|
self.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class TrialCopyBattleDestroySystem : DestroySystem<TrialCopyBattle>
|
|
|
|
|
{
|
|
|
|
|
public override void Destroy(TrialCopyBattle self)
|
|
|
|
|
{
|
|
|
|
|
self.team.ChangeState( TeamState.None);
|
|
|
|
|
self.team = null;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit item in self.targetTeam.GetUnits())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
item.GetMap().Leave(item);
|
|
|
|
|
item.Dispose();
|
|
|
|
|
}
|
|
|
|
|
self.targetTeam.Dispose();
|
|
|
|
|
self.targetTeam = null;
|
|
|
|
|
self.trialCopy = null;
|
|
|
|
|
self.mineKillInfo.Dispose();
|
|
|
|
|
self.targetKillInfo.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static class TrialCopyBattleSystem
|
|
|
|
|
{
|
|
|
|
|
private const int StartTime = 5 * 1000;
|
|
|
|
|
//0.50f, 0.46f, 0.41f, 0.35f
|
|
|
|
|
public readonly static float[] HpDifficultyArr = { 0, 0.50f, 0.96f, 1.37f, 1.72f };
|
|
|
|
|
// 0.18f, 0.16f, 0.12f, 0.08f
|
|
|
|
|
public readonly static float[] AtkDefDifficultyArr = { 0, 0.18f, 0.34f, 0.46f, 0.53f };
|
|
|
|
|
public static void Awake(this TrialCopyBattle self, Team team)
|
|
|
|
|
{
|
|
|
|
|
self.team = team;
|
|
|
|
|
self.mineKillInfo = new MonsterKillInfo(self, team);
|
|
|
|
|
self.isRunning = false;
|
|
|
|
|
self.quitBattleAction = OnQuitBattle;
|
|
|
|
|
}
|
|
|
|
|
public static void Init(this TrialCopyBattle self, TrialCopy trialCopy)
|
|
|
|
|
{
|
|
|
|
|
self.trialCopy = trialCopy;
|
|
|
|
|
self.ReadyBeforeBattle();
|
|
|
|
|
self.startTime = TimeHelper.ClientNow();
|
|
|
|
|
}
|
|
|
|
|
public static void Update(this TrialCopyBattle self)
|
|
|
|
|
{
|
|
|
|
|
if (!self.isRunning) return;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
long now = TimeHelper.ClientNow();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (now - self.startTime < StartTime)
|
|
|
|
|
return;
|
|
|
|
|
if (now - self.startTime > ConstDefine.TrialCopyBattleTime)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Team anotherTeam = self.GetAnotherTeam(self.team);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
BattleHelper.OnTargetVictory(self, anotherTeam);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CheckCanStartSkill(self, now);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void CheckCanStartSkill(TrialCopyBattle self, long now)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unit in self.team.GetUnits())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (!unit.IsAlive) continue;
|
|
|
|
|
if (unit.GetComponent<SkillAI>().CheckCD(now))
|
|
|
|
|
{
|
|
|
|
|
BattleHelper.PlayerSkill(unit, now);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unit in self.targetTeam.GetUnits())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (!unit.IsAlive) continue;
|
|
|
|
|
if (unit.GetComponent<SkillAI>().CheckCD(now))
|
|
|
|
|
{
|
|
|
|
|
BattleHelper.MonsterSkill(unit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ReadyBeforeBattle(this TrialCopyBattle self)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Team team = self.team;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
TrialCopy trialCopy = self.trialCopy;
|
|
|
|
|
if (trialCopy == null)
|
|
|
|
|
{
|
|
|
|
|
BattleMgrCompnent.Instance.RemoveBattle(self);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
team.ChangeState(TeamState.Fight);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
LinkedList<Unit> teamList = team.GetUnits();
|
|
|
|
|
MonsterBase monsterBase = MonsterFactoryHelper.TrialCopyGenerate(self, trialCopy);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
self.targetKillInfo = new MonsterKillInfo(self, self.targetTeam);
|
|
|
|
|
//!+设置每个人的状态
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit u in teamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
u.GetComponent<BattleComponent>().BattleType = BattleType.TrialCopy;
|
|
|
|
|
}
|
|
|
|
|
//!+设置目标/技能信息
|
2021-04-11 19:50:39 +08:00
|
|
|
|
LinkedList<Unit> monsterTeamList = self.targetTeam.GetUnits();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Game.EventSystem.Publish(new EventType.BattleStart { teamList = teamList, targetTeamList = monsterTeamList }).Coroutine();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit item in monsterTeamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
CharacterHelper.SyncNumeric(item);
|
|
|
|
|
CharacterHelper.RecoverUnit(item);
|
|
|
|
|
}
|
|
|
|
|
BattleHelper.SetTargets(self, teamList, monsterTeamList);
|
|
|
|
|
//!+保存主怪Id
|
|
|
|
|
MainStoryMap.Instance.GetBattleInteractiveInfo(team.LeaderId).LeaderMonsterId = trialCopy.MonsterId;
|
|
|
|
|
//!+创建怪物击破信息
|
|
|
|
|
self.mineKillInfo.Init(self.targetTeam.MemberCount, OnVictory);
|
|
|
|
|
self.targetKillInfo.Init(self.team.MemberCount, BattleHelper.OnTargetVictory);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.Info($"\n{team.GetMemberName()}开始试炼之地战斗,[{trialCopy.MapId / 100}][{trialCopy.MapId % 100}]*************");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.SendMonsterInfo();
|
|
|
|
|
self.isRunning = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
BattleMgrCompnent.Instance.RemoveBattle(self);
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static void SendMonsterInfo(this TrialCopyBattle self)
|
|
|
|
|
{
|
|
|
|
|
M2C_MainStoryMonsterInfo m2C_MainStoryMonsterInfo = new M2C_MainStoryMonsterInfo();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unitMonster in self.targetTeam.GetUnits())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
//!给玩家返回怪物信息
|
|
|
|
|
MonsterUnitInfo retUnitInfo = new MonsterUnitInfo()
|
|
|
|
|
{
|
|
|
|
|
Id = unitMonster.Id,
|
|
|
|
|
MonsterId = unitMonster.GetComponent<MonsterInfo>().monsterId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
m2C_MainStoryMonsterInfo.MonsterUnitInfoList.Add(retUnitInfo);
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit u in self.team.GetUnits())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
MessageHelper.SendActor(u, m2C_MainStoryMonsterInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static void ReSendMonsterInfo(this TrialCopyBattle self, Unit unit)
|
|
|
|
|
{
|
|
|
|
|
M2C_ReMainStoryMonsterInfo m2C_MainStoryMonsterInfo = new M2C_ReMainStoryMonsterInfo();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unitMonster in self.targetTeam.GetUnits())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
//!给玩家返回怪物信息
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericComponent num = unitMonster.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
ReMonsterUnitInfo retUnitInfo = new ReMonsterUnitInfo()
|
|
|
|
|
{
|
|
|
|
|
Id = unitMonster.Id,
|
|
|
|
|
MonsterId = unitMonster.GetComponent<MonsterInfo>().monsterId,
|
|
|
|
|
Hp = num.GetAsInt(NumericType.Hp),
|
|
|
|
|
MaxHp = num.GetAsInt(NumericType.MaxHp),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
m2C_MainStoryMonsterInfo.MonsterUnitInfoList.Add(retUnitInfo);
|
|
|
|
|
}
|
|
|
|
|
MessageHelper.SendActor(unit, m2C_MainStoryMonsterInfo);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void OnVictory(BattleBase self, Team team)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (self == null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("battle == null");
|
|
|
|
|
}
|
|
|
|
|
else if (self.isRunning)
|
|
|
|
|
{
|
|
|
|
|
Execute(self.As<TrialCopyBattle>(), team).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
BattleMgrCompnent.Instance.RemoveBattle(self);
|
|
|
|
|
}
|
|
|
|
|
static async ETVoid Execute(TrialCopyBattle self, Team team)
|
|
|
|
|
{
|
|
|
|
|
self.isRunning = false;
|
|
|
|
|
LinkedList<Unit> teamList = team.GetUnits();
|
|
|
|
|
Unit unit = MapUnitComponent.Instance.Get(team.LeaderId);
|
|
|
|
|
Log.Info(team.GetMemberName() + "试炼之地胜利了!");
|
|
|
|
|
UnitScene unitScene = unit.GetComponent<UnitScene>();
|
|
|
|
|
BattleHelper.UpdateChangeMapTaskStateEvent(unitScene, teamList).Coroutine();
|
|
|
|
|
await TimerComponent.Instance.WaitAsync(5000L);
|
|
|
|
|
MessageHelper.SendActor(unit, new M2C_BattleVictory
|
|
|
|
|
{
|
|
|
|
|
BattleType = (int)self.battleType
|
|
|
|
|
});
|
|
|
|
|
await TimerComponent.Instance.WaitAsync(500L);
|
|
|
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
|
|
|
|
await data.UpdateTrialCopy(self.trialCopy.MapId/100);
|
|
|
|
|
await TimerComponent.Instance.WaitAsync(500L);
|
|
|
|
|
await BattleHelper.VictoryOption(self, team, 0L);
|
|
|
|
|
Team anotherTeam = self.GetAnotherTeam(team);
|
|
|
|
|
BattleHelper.EnermyClearOption(self, anotherTeam);
|
|
|
|
|
BattleMgrCompnent.Instance.RemoveBattle(self);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static void OnQuitBattle(BattleBase self, Team team,long Id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (team.AddVote(Id))
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Team anotherTeam = self.GetAnotherTeam(team);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
BattleHelper.OnTargetVictory(self, anotherTeam);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
BattleMgrCompnent.Instance.RemoveBattle(self);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|