CTT/Server/Hotfix/Game/System/Battle/New/BossBattleSystem.cs

282 lines
10 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Cal.DataTable;
using System;
using System.Collections.Generic;
namespace ET
{
public class BossBattleAwakeSystem : AwakeSystem<BossBattle, Team>
{
public override void Awake(BossBattle self, Team team)
{
self.Awake(team);
}
}
public class BossBattleLoadSystem : LoadSystem<BossBattle>
{
public override void Load(BossBattle self)
{
self.Load();
}
}
public class BossBattleUpdateSystem : UpdateSystem<BossBattle>
{
public override void Update(BossBattle self)
{
self.Update();
}
}
public class BossBattleDestroySystem : DestroySystem<BossBattle>
{
public override void Destroy(BossBattle self)
{
self.team.ChangeState(TeamState.None);
self.targetTeam.ChangeState(TeamState.None);
self.team = null;
foreach (var item in self.targetTeam.GetUnits())
{
item.GetMap().Leave(item);
item.Dispose();
}
self.targetTeam.Dispose();
self.targetTeam = null;
self.mapId = 0;
self.mineKillInfo.Dispose();
self.targetKillInfo.Dispose();
}
}
public static class BossBattleSystem
{
//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 BossBattle self, Team team)
{
self.team = team;
self.mineKillInfo = new MonsterKillInfo(self, team);
self.isRunning = false;
self.quitBattleAction = OnQuitBattle;
}
public static void Load(this BossBattle self)
{
self.quitBattleAction = OnQuitBattle;
}
public static void Init(this BossBattle self, int mapId)
{
self.mapId = mapId;
self.ReadyBeforeBattle();
self.startTime = TimeHelper.ClientNow();
}
public static void Update(this BossBattle self)
{
if (!self.isRunning) return;
var now = TimeHelper.ClientNow();
if (now - self.startTime < ConstDefine.StartTime)
return;
if (now - self.startTime > ConstDefine.BossBattleTime)
{
var anotherTeam = self.GetAnotherTeam(self.team);
OnTargetVictory(self, anotherTeam);
return;
}
CheckCanStartSkill(self, now);
}
private static void CheckCanStartSkill(BossBattle self, long now)
{
foreach (var unit in self.team.GetUnits())
{
if (!unit.IsAlive) continue;
if (unit.GetComponent<SkillAI>().CheckCD(now))
{
BattleHelper.PlayerSkill(unit, now);
}
}
foreach (var unit in self.targetTeam.GetUnits())
{
if (!unit.IsAlive) continue;
if (unit.GetComponent<SkillAI>().CheckCD(now))
{
BattleHelper.MonsterSkill(unit);
}
}
}
public static void ReadyBeforeBattle(this BossBattle self)
{
try
{
var team = self.team;
if (self.mapId == 0)
{
BattleMgrCompnent.Instance.RemoveBattle(self);
return;
}
team.ChangeState(TeamState.Fight);
var teamList = team.GetUnits();
int mapLayer = self.mapId % 100;
var bossBase = MonsterFactoryHelper.BossGenerate(self, self.mapId);
self.targetKillInfo = new MonsterKillInfo(self, self.targetTeam);
//!+设置每个人的状态
foreach (var u in teamList)
{
u.GetComponent<BattleComponent>().BattleType = BattleType.Boss;
}
//!+设置目标/技能信息
var monsterTeamList = self.targetTeam.GetUnits();
Game.EventSystem.Publish(new EventType.BattleStart { teamList = teamList, targetTeamList = monsterTeamList }).Coroutine();
foreach (var item in monsterTeamList)
{
CharacterHelper.SyncNumeric(item);
CharacterHelper.RecoverUnit(item);
}
BattleHelper.SetTargets(self, teamList, monsterTeamList);
//!+保存主怪Id
MainStoryMap.Instance.GetBattleInteractiveInfo(team.LeaderId).LeaderMonsterId = (int)bossBase.Id;
//!+创建怪物击破信息
self.mineKillInfo.Init(self.targetTeam.MemberCount, OnVictory);
self.targetKillInfo.Init(self.team.MemberCount, OnTargetVictory);
Log.Info($"\n{team.GetMemberName()}开始Boss战斗,[{self.mapId / 100}][{self.mapId % 100}]*************");
self.SendMonsterInfo();
self.isRunning = true;
}
catch (Exception e)
{
BattleMgrCompnent.Instance.RemoveBattle(self);
Log.Error(e);
}
}
private static void SendMonsterInfo(this BossBattle self)
{
M2C_SendBossInfo m2C_MainStoryMonsterInfo = new M2C_SendBossInfo();
foreach (var unitMonster in self.targetTeam.GetUnits())
{
//!给玩家返回怪物信息
m2C_MainStoryMonsterInfo.BossId = unitMonster.GetComponent<MonsterInfo>().monsterId;
m2C_MainStoryMonsterInfo.UnitId = unitMonster.Id;
}
foreach (var u in self.team.GetUnits())
{
MessageHelper.SendActor(u, m2C_MainStoryMonsterInfo);
}
}
public static void ReSendMonsterInfo(this BossBattle self, Unit unit)
{
M2C_ReSendBossInfo m2C_MainStoryMonsterInfo = new M2C_ReSendBossInfo();
foreach (var unitMonster in self.targetTeam.GetUnits())
{
//!给玩家返回怪物信息
m2C_MainStoryMonsterInfo.BossId = unitMonster.GetComponent<MonsterInfo>().monsterId;
m2C_MainStoryMonsterInfo.UnitId = unitMonster.Id;
m2C_MainStoryMonsterInfo.Hp = unitMonster.GetComponent<NumericComponent>().GetAsInt(NumericType.Hp);
}
MessageHelper.SendActor(unit, m2C_MainStoryMonsterInfo);
}
private static void OnVictory(BattleBase self, Team team)
{
try
{
if (self == null)
{
Log.Error($"battle == null");
return;
}
if (!self.isRunning) return;
Execute(self.As<BossBattle>(), team).Coroutine();
static async ETVoid Execute(BossBattle self, Team team)
{
self.isRunning = false;
var teamList = team.GetUnits();
Unit unit = MapUnitComponent.Instance.Get(team.LeaderId);
var unitScene = unit.GetComponent<UnitScene>();
Log.Info($"{team.GetMemberName()}Boss战斗胜利了{unitScene.MapId}");
//!触发通关任务事件
//BattleHelper.UpdateChangeMapTaskStateEvent(unitScene, teamList).Coroutine();
await TimerComponent.Instance.WaitAsync(5500);
foreach (var item in teamList)
{
MessageHelper.SendActor(item, new M2C_BattleVictory() { BattleType = (int)self.battleType });
}
//!更新Boss状态
BossComponent.Instance.BossDead(team.GetMemberName(), unitScene.MapId % 100);
await BattleHelper.VictoryOption(self, team);
var anotherTeam = self.GetAnotherTeam(team);
BattleHelper.EnermyClearOption(self, anotherTeam);
BattleMgrCompnent.Instance.RemoveBattle(self);
}
}
catch (Exception e)
{
Log.Error(e);
BattleMgrCompnent.Instance.RemoveBattle(self);
}
}
public static void OnTargetVictory(this BattleBase self, Team team)
{
try
{
if (self == null)
{
Log.Error($"battle == null");
return;
}
if (!self.isRunning) return;
Execute(self.As<BossBattle>(), team).Coroutine();
static async ETVoid Execute(BossBattle self, Team team)
{
self.isRunning = false;
var teamList = team.GetUnits();
await TimerComponent.Instance.WaitAsync(5500);
BattleHelper.EnermyClearOption(self, team);
var anotherTeam = self.GetAnotherTeam(team);
await self.OnDefeat(anotherTeam);
//!重新刷新Boss
int mapLayer = self.As<BossBattle>().mapId % 100;
BossComponent.Instance.ChangeState(mapLayer, BossComponent.BossState.Idle, true);
BattleMgrCompnent.Instance.RemoveBattle(self);
}
}
catch (Exception e)
{
Log.Error(e);
BattleMgrCompnent.Instance.RemoveBattle(self);
}
}
private static void OnQuitBattle(BattleBase self, Team team,long Id)
{
try
{
if (team.AddVote(Id))
{
var anotherTeam = self.GetAnotherTeam(team);
OnTargetVictory(self, anotherTeam);
}
}
catch (Exception e)
{
Log.Error(e);
BattleMgrCompnent.Instance.RemoveBattle(self);
}
}
}
}