2021-04-08 20:09:59 +08:00
|
|
|
|
using Cal;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public enum NumTargetType
|
|
|
|
|
{
|
|
|
|
|
Self,
|
|
|
|
|
Target
|
|
|
|
|
}
|
|
|
|
|
public static class BattleHelper
|
|
|
|
|
{
|
|
|
|
|
public static void GetNumType(ValueCalculate valueCalculate, NumTargetType numTargetType, NumericComponent _num, NumericComponent _numTarget, out NumericComponent num, out NumericType numericType)
|
|
|
|
|
{
|
|
|
|
|
num = numTargetType switch
|
|
|
|
|
{
|
|
|
|
|
NumTargetType.Self => _num,
|
|
|
|
|
NumTargetType.Target => _numTarget ?? throw new Exception("numTarget is null ,baseOriType 类型错误!"),
|
|
|
|
|
_ => throw new Exception("baseOriType 类型错误!"),
|
|
|
|
|
};
|
|
|
|
|
numericType = valueCalculate.calculateType switch
|
|
|
|
|
{
|
|
|
|
|
ValueCalculateType.物理攻击力x系数 => NumericType.PhyAtk,
|
|
|
|
|
ValueCalculateType.精神攻击力x系数 => NumericType.SpiAtk,
|
|
|
|
|
ValueCalculateType.生命值上限x系数 => NumericType.MaxHp,
|
|
|
|
|
ValueCalculateType.当前生命值x系数 => NumericType.Hp,
|
|
|
|
|
_ => throw new Exception("basePercEffectType 类型错误!")
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计算伤害
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="damageType"></param>
|
|
|
|
|
/// <param name="owner"></param>
|
|
|
|
|
/// <param name="target"></param>
|
|
|
|
|
/// <param name="damageCalculate_Self"></param>
|
|
|
|
|
/// <param name="damageCalculate_Target"></param>
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
internal static void Calculate(SkillDamageType damageType, ISkillSender skillSender, Unit target, ValueCalculate damageCalculate_Self, ValueCalculate damageCalculate_Target, out BallisticData data)
|
|
|
|
|
{
|
|
|
|
|
if (damageCalculate_Self == null && damageCalculate_Target == null)
|
|
|
|
|
{
|
|
|
|
|
data = default;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericComponent num = skillSender.caster.GetComponent<NumericComponent>();
|
|
|
|
|
NumericComponent numTarget = target.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
switch (damageType)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case SkillDamageType.None:
|
|
|
|
|
data = default;
|
|
|
|
|
break;
|
|
|
|
|
case SkillDamageType.物理伤害:
|
|
|
|
|
PhyBuffDamageCalculate.Calculate(num, numTarget, damageCalculate_Self, damageCalculate_Target, skillSender.skillLogic.skillConfigId, out data);
|
|
|
|
|
break;
|
|
|
|
|
case SkillDamageType.精神伤害:
|
|
|
|
|
SpiBuffDamageCalculate.Calculate(num, numTarget, damageCalculate_Self, damageCalculate_Target, skillSender.skillLogic.skillConfigId, out data);
|
|
|
|
|
break;
|
|
|
|
|
case SkillDamageType.真实伤害:
|
|
|
|
|
RealBuffDamageCalculate.Calculate(num, numTarget, damageCalculate_Self, damageCalculate_Target, skillSender.skillLogic.skillConfigId, out data);
|
|
|
|
|
break;
|
|
|
|
|
case SkillDamageType.护盾治疗:
|
|
|
|
|
TreatBuffDamageCalculate.Calculate(num, numTarget, damageCalculate_Self, damageCalculate_Target, skillSender.skillLogic.skillConfigId, out data);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void SetTargets( BattleBase battle, IEnumerable<Unit> teamList, IEnumerable<Unit> targetTeamList)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unit in teamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
unit.BattleId = battle.Id;
|
|
|
|
|
//!增加目标
|
|
|
|
|
unit.AddComponent<AttackComponent>();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
TargetableUnitComponent targetUnits = unit.AddComponent<TargetableUnitComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
targetUnits.AddEnermy(targetTeamList);
|
|
|
|
|
targetUnits.AddTeam(teamList);
|
|
|
|
|
targetUnits.selectedEnermy = null;
|
|
|
|
|
|
|
|
|
|
//!战斗开始添加技能,现在添加合适吗
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillMgrComponent skillMgr = unit.GetComponent<SkillMgrComponent>();
|
|
|
|
|
UnitSkillComponent skillComponent = unit.GetComponent<UnitSkillComponent>();
|
|
|
|
|
foreach (UnitSkill unitSkill in skillComponent.GetLearnedSkills())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
//if (unitSkill.IsPassive)
|
|
|
|
|
// continue;
|
|
|
|
|
skillMgr.AddSkill(unit, unitSkill);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unit in targetTeamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
unit.BattleId = battle.Id;
|
|
|
|
|
//!增加目标
|
|
|
|
|
unit.AddComponent<AttackComponent>();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
TargetableUnitComponent targetUnits = unit.AddComponent<TargetableUnitComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
targetUnits.AddEnermy(teamList);
|
|
|
|
|
targetUnits.AddTeam(targetTeamList);
|
|
|
|
|
targetUnits.selectedEnermy = null;
|
|
|
|
|
|
|
|
|
|
//!战斗开始添加技能,现在添加合适吗
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillMgrComponent skillMgr = unit.GetComponent<SkillMgrComponent>();
|
|
|
|
|
UnitSkillComponent skillComponent = unit.GetComponent<UnitSkillComponent>();
|
|
|
|
|
foreach (UnitSkill unitSkill in skillComponent.GetLearnedSkills())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
//if (unitSkill.IsPassive)
|
|
|
|
|
// continue;
|
|
|
|
|
skillMgr.AddSkill(unit, unitSkill);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//!玩家释放技能
|
|
|
|
|
public static void PlayerSkill(Unit unit, long now)
|
|
|
|
|
{
|
|
|
|
|
if (!unit.IsAlive) return;
|
|
|
|
|
if (unit.GetComponent<UserSetting>().IsAutoSkill)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillAI ai = unit.GetComponent<SkillAI>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
ai.canSkill = true;
|
|
|
|
|
ai.PlayAutoSkill(now);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//!怪物释放技能
|
|
|
|
|
public static void MonsterSkill(Unit unit)
|
|
|
|
|
{
|
|
|
|
|
if (!unit.IsAlive) return;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillAI ai = unit.GetComponent<SkillAI>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
ai.PlaySkill();
|
|
|
|
|
}
|
|
|
|
|
public static async ETVoid UpdateChangeMapTaskStateEvent(UnitScene unitScene, IEnumerable<Unit> teamList)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit u in teamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
await Game.EventSystem.Publish(new EventType.UpdateTaskState
|
|
|
|
|
{
|
|
|
|
|
unit = u,
|
|
|
|
|
type = TaskTargetType.ChangeMapTask,
|
|
|
|
|
value = unitScene.MapId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static async ETVoid BrocastReword(IEnumerable<Unit> teamList, UnOrderMultiMapComponent<long, (int, int)> rewordMap)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
using ListComponent<string> listComponent = ListComponent<string>.Create();
|
|
|
|
|
foreach (KeyValuePair<long, List<(int, int)>> kp in rewordMap.MultiMap.GetDictionary())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
long unitId = kp.Key;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
User user = await UserHelper.Query(unitId);
|
|
|
|
|
foreach ((int id, int count) in kp.Value)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
listComponent.List.Add($"[color=#ffff00]【{user?.NickName}】[/color]获得了[color=#226655]{BagHelper.GetName(id)}x{count}[/color]");
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unit in teamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
Chat.Instance.SendSystemToTeamCaht(unit, listComponent.List);
|
|
|
|
|
}
|
|
|
|
|
rewordMap.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async ETVoid UnitDead(BattleBase self, Unit unit)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!unit)
|
|
|
|
|
Log.Error($"unit is invalid which Id = {unit?.Id}");
|
|
|
|
|
//!触发死亡事件
|
|
|
|
|
if (unit.UnitType != UnitType.Player)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
UnitEnermy unitInfo = unit.GetComponent<UnitEnermy>();
|
|
|
|
|
Unit attackerUnit = unitInfo.unit;
|
2021-04-10 19:49:32 +08:00
|
|
|
|
int monsterId = unitInfo.MonsterId;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
await Game.EventSystem.Publish(new EventType.UpdateTaskState
|
|
|
|
|
{
|
|
|
|
|
type = TaskTargetType.KillSpecialTask,
|
2021-04-10 19:49:32 +08:00
|
|
|
|
unit = attackerUnit,
|
|
|
|
|
value = monsterId
|
2021-04-08 20:09:59 +08:00
|
|
|
|
});
|
|
|
|
|
await Game.EventSystem.Publish(new EventType.UpdateTaskState
|
|
|
|
|
{
|
|
|
|
|
type = TaskTargetType.KillAnyTask,
|
2021-04-10 19:49:32 +08:00
|
|
|
|
unit = attackerUnit,
|
|
|
|
|
value = monsterId
|
2021-04-08 20:09:59 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
LinkedList<Unit> teamList = self.team.GetUnits();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
if (self.team.Contains(unit.Id))
|
|
|
|
|
{
|
|
|
|
|
self.targetKillInfo.UpdateAmount(1);
|
|
|
|
|
Log.Info($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】战斗死亡了!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.mineKillInfo.UpdateAmount(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//!给客户端广播怪物死亡消息
|
|
|
|
|
IActorMessage deadMessage = new M2C_UnitDead()
|
|
|
|
|
{
|
|
|
|
|
UnitId = unit.Id
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MessageHelper.Broadcast(teamList, self.targetTeam.GetUnits(), deadMessage);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OnTargetVictory(this BattleBase self, Team team)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (self == null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"battle == null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!self.isRunning) return;
|
|
|
|
|
Execute(self, team).Coroutine();
|
|
|
|
|
static async ETVoid Execute(BattleBase self, Team team)
|
|
|
|
|
{
|
|
|
|
|
self.isRunning = false;
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal static async ETTask VictoryOption(BattleBase self, Team team,long configid = 0)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
LinkedList<Unit> teamList = team.GetUnits();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
team.ChangeState(TeamState.None);
|
|
|
|
|
|
|
|
|
|
//!战斗结束事件(回血,奖励)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
UnOrderMultiMapComponent<long, (int, int)> rewordMapComponent = EntityFactory.Create<UnOrderMultiMapComponent<long, (int, int)>>(Game.Scene);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
rewordMapComponent.Dispose();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit u in teamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
u.RemoveComponent<AttackComponent>();
|
|
|
|
|
u.RemoveComponent<TargetableUnitComponent>();
|
|
|
|
|
|
|
|
|
|
Game.EventSystem.Publish(new EventType.BattleEnd { unit = u ,team = team}).Coroutine();
|
|
|
|
|
Game.EventSystem.Publish(new EventType.BattleEnd_AddHp { unit = u }).Coroutine();
|
|
|
|
|
u.Live();
|
|
|
|
|
await Game.EventSystem.Publish(new EventType.BattleEnd_Reword { unit = u, rewordMap = rewordMapComponent.MultiMap, battleType = self.battleType,configid=configid });
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
MainStoryInteractive battleInteractiveInfo = MainStoryMap.Instance.GetBattleInteractiveInfo(team.LeaderId);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
battleInteractiveInfo.LeaderMonsterId = 0;
|
|
|
|
|
//!存档
|
|
|
|
|
//UnitHelper.Save(team).Coroutine();
|
|
|
|
|
BattleHelper.BrocastReword(teamList, rewordMapComponent).Coroutine();
|
|
|
|
|
//!移除不在线玩家
|
|
|
|
|
await TeamComponent.Instance.RemoveAllOffLineId(team);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
internal static async ETTask DefeatOption(BattleBase self, Team team)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
LinkedList<Unit> teamList = team.GetUnits();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
team.ChangeState(TeamState.None);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit u in teamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
MessageHelper.SendActor(u, new M2C_BattleDefeat
|
|
|
|
|
{
|
|
|
|
|
BattleType = (int)self.battleType
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit u in teamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
u.RemoveComponent<AttackComponent>();
|
|
|
|
|
u.RemoveComponent<TargetableUnitComponent>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (u.IsTeamLeader)
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new EventType.BackMainCity { unit = u,isForce =true }).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
u.Live();
|
|
|
|
|
//!战斗结束事件(回血)
|
|
|
|
|
Game.EventSystem.Publish(new EventType.BattleEnd { unit = u,team = team }).Coroutine();
|
|
|
|
|
Game.EventSystem.Publish(new EventType.BattleEnd_AddHp { unit = u }).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//!移除不在线玩家
|
|
|
|
|
await TeamComponent.Instance.RemoveAllOffLineId(team);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal static void EnermyClearOption(BattleBase self, Team team)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
LinkedList<Unit> teamList = team.GetUnits();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
team.ChangeState(TeamState.None);
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit u in teamList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
u.RemoveComponent<AttackComponent>();
|
|
|
|
|
u.RemoveComponent<TargetableUnitComponent>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static string SelectFixedTarget(this BattleBase self, Unit unit, long unitId, Team targetTeam, TeamType teamType)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
AttackComponent attacker = unit.GetComponent<AttackComponent>();
|
|
|
|
|
TargetableUnitComponent targetComponent = unit.GetComponent<TargetableUnitComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
switch (teamType)
|
|
|
|
|
{
|
|
|
|
|
case TeamType.Self:
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Team team = self.team;
|
|
|
|
|
Unit targetUnit = team.Get(unitId);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (targetUnit == null)
|
|
|
|
|
{
|
|
|
|
|
return "系统错误";
|
|
|
|
|
}
|
|
|
|
|
targetComponent.selectedTeamMember = targetUnit;
|
|
|
|
|
break;
|
|
|
|
|
case TeamType.Target:
|
|
|
|
|
team = targetTeam;
|
|
|
|
|
targetUnit = team.Get(unitId);
|
|
|
|
|
if (targetUnit == null)
|
|
|
|
|
{
|
|
|
|
|
return "系统错误";
|
|
|
|
|
}
|
|
|
|
|
targetComponent.selectedEnermy = targetUnit;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|