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

373 lines
14 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using Cal.DataTable;
using System;
using System.Collections.Generic;
namespace ET
{
public class FamilyBossBattleAwakeSystem : AwakeSystem<FamilyBossBattle, Team>
{
public override void Awake(FamilyBossBattle self, Team team)
{
self.Awake(team);
}
}
public class FamilyBossBattleUpdateSystem : UpdateSystem<FamilyBossBattle>
{
public override void Update(FamilyBossBattle self)
{
self.Update();
}
}
public class FamilyBossBattleDestroySystem : DestroySystem<FamilyBossBattle>
{
public override void Destroy(FamilyBossBattle self)
{
self.team.ChangeState(TeamState.None);
self.targetTeam.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.bossId = 0;
self.mineKillInfo.Dispose();
self.targetKillInfo.Dispose();
self.family = null;
self.bossDamageMap = null;
self.hasSettle = false;
}
}
public static class FamilyBossBattleSystem
{
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 FamilyBossBattle self, Team team)
{
self.team = team;
self.mineKillInfo = new MonsterKillInfo(self, team);
self.isRunning = false;
self.bossDamageMap = new BossDamageMap();
2021-04-11 19:50:39 +08:00
foreach (Unit unit in team.GetUnits())
2021-04-08 20:09:59 +08:00
{
self.bossDamageMap.DamageList.Add(new BossDamagePerMemberMap
{
Id = unit.Id,
Name = UserComponent.Instance.Get(unit.Id)?.NickName,
});
}
self.quitBattleAction = OnQuitBattle;
}
public static void Init(this FamilyBossBattle self, int bossId, FamilyBoss family)
{
self.bossId = bossId;
self.family = family;
self.ReadyBeforeBattle();
self.startTime = TimeHelper.ClientNow();
}
public static void Update(this FamilyBossBattle 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.FamilyBossBattleTime)
{
2021-04-11 19:50:39 +08:00
Team anotherTeam = self.GetAnotherTeam(self.team);
2021-04-08 20:09:59 +08:00
OnTargetVictory(self, anotherTeam);
return;
}
CheckCanStartSkill(self, now);
}
private static void CheckCanStartSkill(FamilyBossBattle 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);
AddProperty(self, unit);
}
}
}
private static void AddProperty(FamilyBossBattle self, Unit unit)
{
FamilyBossConfig familyBossConfig = DataTableHelper.Get<FamilyBossConfig>(self.bossId);
float additional = familyBossConfig.CharacterAdd;
2021-04-11 19:50:39 +08:00
NumericComponent num = unit.GetComponent<NumericComponent>();
2021-04-08 20:09:59 +08:00
int atk = MathHelper.RoundToInt(num.GetAsInt(NumericType.PhyAtkBase) * additional);
num.AddSet(NumericType.PhyAtk, atk);
atk = MathHelper.RoundToInt(num.GetAsInt(NumericType.SpiAtkBase) * additional);
num.AddSet(NumericType.SpiAtk, atk);
int def = MathHelper.RoundToInt(num.GetAsInt(NumericType.PhyDefBase) * additional);
num.AddSet(NumericType.PhyDef, def);
def = MathHelper.RoundToInt(num.GetAsInt(NumericType.SpiDefBase) * additional);
num.AddSet(NumericType.SpiDef, def);
}
public static void ReadyBeforeBattle(this FamilyBossBattle self)
{
try
{
2021-04-11 19:50:39 +08:00
Team team = self.team;
2021-04-08 20:09:59 +08:00
if (self.bossId == 0)
{
BattleMgrCompnent.Instance.RemoveBattle(self);
return;
}
team.ChangeState(TeamState.Fight);
2021-04-11 19:50:39 +08:00
LinkedList<Unit> teamList = team.GetUnits();
2021-04-08 20:09:59 +08:00
2021-04-11 19:50:39 +08:00
FamilyBossConfig bossBase = MonsterFactoryHelper.FamilyBossGenerate(self, self.bossId, self.family);
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.FamilyBoss;
}
//!+设置目标/技能信息
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 = (int)bossBase.Id;
//!+创建怪物击破信息
self.mineKillInfo.Init(self.targetTeam.MemberCount, OnVictory);
self.targetKillInfo.Init(self.team.MemberCount, OnTargetVictory);
Log.Info($"\n{team.GetMemberName()}开始家族Boss战斗,[{self.bossId}阶Boss]*************");
self.SendMonsterInfo();
self.isRunning = true;
}
catch (Exception e)
{
BattleMgrCompnent.Instance.RemoveBattle(self);
Log.Error(e);
}
}
private static void SendMonsterInfo(this FamilyBossBattle self)
{
M2C_SendFamilyBossInfo m2C_MainStoryMonsterInfo = new M2C_SendFamilyBossInfo();
2021-04-11 19:50:39 +08:00
foreach (Unit unitMonster in self.targetTeam.GetUnits())
2021-04-08 20:09:59 +08:00
{
//!给玩家返回怪物信息
m2C_MainStoryMonsterInfo.BossId = unitMonster.GetComponent<MonsterInfo>().monsterId;
m2C_MainStoryMonsterInfo.UnitId = unitMonster.Id;
m2C_MainStoryMonsterInfo.Hp = unitMonster.GetComponent<NumericComponent>().GetAsInt(NumericType.Hp);
}
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 FamilyBossBattle self)
{
M2C_ReSendFamilyBossInfo m2C_MainStoryMonsterInfo = new M2C_ReSendFamilyBossInfo();
2021-04-11 19:50:39 +08:00
foreach (Unit unitMonster in self.targetTeam.GetUnits())
2021-04-08 20:09:59 +08:00
{
//!给玩家返回怪物信息
m2C_MainStoryMonsterInfo.BossId = unitMonster.GetComponent<MonsterInfo>().monsterId;
m2C_MainStoryMonsterInfo.UnitId = unitMonster.Id;
m2C_MainStoryMonsterInfo.Hp = unitMonster.GetComponent<NumericComponent>().GetAsInt(NumericType.Hp);
}
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 ChangeBossHp(this FamilyBossBattle self, Unit unit, int hp)
{
2021-04-11 19:50:39 +08:00
MonsterInfo monsterInfo = unit.GetComponent<MonsterInfo>();
2021-04-08 20:09:59 +08:00
self.family.SetBossHp(monsterInfo.monsterId, hp);
}
public static void ChangeDamageData(this FamilyBossBattle self, Unit unit, int damage)
{
2021-04-11 19:50:39 +08:00
BossDamageMap map = self.bossDamageMap;
2021-04-08 20:09:59 +08:00
map.TotalDamage += damage;
for (int i = map.DamageList.Count - 1; i >= 0; i--)
{
2021-04-11 19:50:39 +08:00
BossDamagePerMemberMap info = map.DamageList[i];
2021-04-08 20:09:59 +08:00
if (info.Id == unit.Id)
{
info.Damage += damage;
return;
}
}
}
public static void ChangeTreatData(this FamilyBossBattle self, Unit unit, int treat)
{
2021-04-11 19:50:39 +08:00
BossDamageMap map = self.bossDamageMap;
2021-04-08 20:09:59 +08:00
for (int i = map.DamageList.Count - 1; i >= 0; i--)
{
2021-04-11 19:50:39 +08:00
BossDamagePerMemberMap info = map.DamageList[i];
2021-04-08 20:09:59 +08:00
if (info.Id == unit.Id)
{
info.Treat += treat;
return;
}
}
}
/// <summary>
/// 结算Boss伤害数据
/// </summary>
/// <param name="self"></param>
private static void SettleBossDamageData(FamilyBossBattle self)
{
self.family.InsertDamageInfo(self.bossId, self.bossDamageMap);
}
private static void OnVictory(BattleBase self, Team team)
{
try
{
if (self == null)
{
Log.Error($"battle == null");
return;
}
if (!self.isRunning) return;
Execute(self.As<FamilyBossBattle>(), team).Coroutine();
static async ETVoid Execute(FamilyBossBattle self, Team team)
{
self.isRunning = false;
if (!self.hasSettle)
{
self.hasSettle = true;
SettleBossDamageData(self);
}
2021-04-11 19:50:39 +08:00
LinkedList<Unit> teamList = team.GetUnits();
2021-04-08 20:09:59 +08:00
Unit unit = MapUnitComponent.Instance.Get(team.LeaderId);
Log.Info($"{team.GetMemberName()}家族{self.bossId}阶Boss战斗胜利了");
//!触发通关任务事件
//BattleHelper.UpdateChangeMapTaskStateEvent(unitScene, teamList).Coroutine();
await TimerComponent.Instance.WaitAsync(5500);
2021-04-11 19:50:39 +08:00
foreach (Unit item in teamList)
2021-04-08 20:09:59 +08:00
{
MessageHelper.SendActor(item, new M2C_BattleVictory() { BattleType = (int)self.battleType });
}
await VictoryOption(self, team);
2021-04-08 20:09:59 +08:00
2021-04-11 19:50:39 +08:00
Team anotherTeam = self.GetAnotherTeam(team);
2021-04-08 20:09:59 +08:00
BattleHelper.EnermyClearOption(self, anotherTeam);
BattleMgrCompnent.Instance.RemoveBattle(self);
}
}
catch (Exception e)
{
Log.Error(e);
BattleMgrCompnent.Instance.RemoveBattle(self);
}
}
private static async ETTask VictoryOption(BattleBase self, Team team)
{
try
{
LinkedList<Unit> teamList = team.GetUnits();
team.ChangeState(TeamState.None);
//!战斗结束事件(回血,奖励)
UnOrderMultiMapComponent<long, (int, int)> rewordMapComponent = UnOrderMultiMapComponent<long, (int, int)>.Create();
foreach (Unit u in teamList)
{
Game.EventSystem.Publish(new EventType.BattleEnd { unit = u, team = team }).Coroutine();
Game.EventSystem.Publish(new EventType.BattleEnd_AddHp { unit = u }).Coroutine();
u.Live();
}
MainStoryInteractive battleInteractiveInfo = MainStoryMap.Instance.GetBattleInteractiveInfo(team.LeaderId);
battleInteractiveInfo.LeaderMonsterId = 0;
//!移除不在线玩家
await TeamComponent.Instance.RemoveAllOffLineId(team);
}
catch (Exception e)
{
Log.Error(e);
}
}
private static void OnTargetVictory(this BattleBase self, Team team)
2021-04-08 20:09:59 +08:00
{
try
{
if (self == null)
{
Log.Error($"battle == null");
return;
}
if (!self.isRunning) return;
Execute(self.As<FamilyBossBattle>(), team).Coroutine();
static async ETVoid Execute(FamilyBossBattle self, Team team)
{
self.isRunning = false;
if (!self.hasSettle)
{
self.hasSettle = true;
SettleBossDamageData(self);
}
2021-04-11 19:50:39 +08:00
LinkedList<Unit> teamList = team.GetUnits();
2021-04-08 20:09:59 +08:00
await TimerComponent.Instance.WaitAsync(5500);
BattleHelper.EnermyClearOption(self, team);
2021-04-11 19:50:39 +08:00
Team anotherTeam = self.GetAnotherTeam(team);
2021-04-08 20:09:59 +08:00
await self.OnDefeat(anotherTeam);
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))
{
2021-04-11 19:50:39 +08:00
Team anotherTeam = self.GetAnotherTeam(team);
2021-04-08 20:09:59 +08:00
OnTargetVictory(self, anotherTeam);
}
}
catch (Exception e)
{
Log.Error(e);
BattleMgrCompnent.Instance.RemoveBattle(self);
}
}
}
}