149 lines
5.5 KiB
C#
149 lines
5.5 KiB
C#
using Cal;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace ET
|
|
{
|
|
public class TargetableUnitComponentDstroySystem : DestroySystem<TargetableUnitComponent>
|
|
{
|
|
public override void Destroy(TargetableUnitComponent self)
|
|
{
|
|
self.selectedEnermy = null;
|
|
self.selectedTeamMember = null;
|
|
self.allEnermy.Clear();
|
|
self.allTeam.Clear();
|
|
self.allTarget.Clear();
|
|
self.currTarget = null;
|
|
self.targetList.Clear();
|
|
self.currEnermyList.Clear();
|
|
self.currFriendlyList.Clear();
|
|
self.currAllList.Clear();
|
|
self.hasCurrList = false;
|
|
}
|
|
}
|
|
|
|
public static class TargetableUnitComponentSystem
|
|
{
|
|
public static void Clear(this TargetableUnitComponent self)
|
|
{
|
|
self.allEnermy.Clear();
|
|
self.allTeam.Clear();
|
|
self.allTarget.Clear();
|
|
self.currTarget = null;
|
|
self.targetList.Clear();
|
|
self.currEnermyList.Clear();
|
|
self.currFriendlyList.Clear();
|
|
self.currAllList.Clear();
|
|
self.hasCurrList = false;
|
|
self.selectedEnermy = null;
|
|
self.selectedTeamMember = null;
|
|
}
|
|
public static void AddEnermy(this TargetableUnitComponent self, IEnumerable<Unit> list)
|
|
{
|
|
foreach (Unit item in list)
|
|
{
|
|
self.allEnermy.Add(item);
|
|
self.allTarget.Add(item);
|
|
}
|
|
}
|
|
public static void AddTeam(this TargetableUnitComponent self, IEnumerable<Unit> list)
|
|
{
|
|
foreach (Unit item in list)
|
|
{
|
|
self.allTeam.Add(item);
|
|
self.allTarget.Add(item);
|
|
}
|
|
}
|
|
public static List<Unit> GetAllTarget(this TargetableUnitComponent self)
|
|
{
|
|
return self.allTarget;
|
|
}
|
|
public static int GetTagetAliveCount(this TargetableUnitComponent self)
|
|
{
|
|
int count = 0;
|
|
foreach (Unit item in self.allEnermy)
|
|
{
|
|
if (item.IsAlive)
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
public static void SelectTarget(this TargetableUnitComponent targetComponent, SkillLogicConfig skillLogic)
|
|
{
|
|
if (skillLogic == null)
|
|
{
|
|
Log.Error($"skilllogic == null when unitId = {targetComponent.Parent.Id}");
|
|
return;
|
|
}
|
|
targetComponent.hasCurrList = false;
|
|
targetComponent.currFriendlyList.Clear();
|
|
targetComponent.currEnermyList.Clear();
|
|
targetComponent.currAllList.Clear();
|
|
SelectTargetHelper.SelectUnitByFlags(targetComponent.allEnermy, targetComponent.targetList, skillLogic.flagType);
|
|
targetComponent.currEnermyList.AddRange(targetComponent.targetList);
|
|
SelectTargetHelper.SelectUnitByFlags(targetComponent.allTeam, targetComponent.targetList, skillLogic.flagType);
|
|
targetComponent.currFriendlyList.AddRange(targetComponent.targetList);
|
|
SelectTargetHelper.SelectUnitByFlags(targetComponent.allTarget, targetComponent.targetList, skillLogic.flagType);
|
|
targetComponent.currAllList.AddRange(targetComponent.targetList);
|
|
switch (skillLogic.teamType)
|
|
{
|
|
case Cal.TeamType.无:
|
|
break;
|
|
case Cal.TeamType.敌方队伍:
|
|
SelectEnermy(targetComponent, skillLogic.flagType);
|
|
break;
|
|
case Cal.TeamType.友方队伍:
|
|
SelectFriendly(targetComponent, skillLogic.flagType);
|
|
break;
|
|
case Cal.TeamType.全体队伍:
|
|
SelectAllTeam(targetComponent, skillLogic.flagType);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
public static void SelectEnermy(this TargetableUnitComponent targetComponent, TargetFlagType flagType)
|
|
{
|
|
if (targetComponent.selectedEnermy != null)
|
|
{
|
|
targetComponent.currTarget = targetComponent.selectedEnermy;
|
|
}
|
|
else
|
|
{
|
|
int count = targetComponent.currEnermyList.Count;
|
|
if (count > 0)
|
|
{
|
|
int rand = RandomHelper.RandomNumber(0, count);
|
|
targetComponent.currTarget = targetComponent.currEnermyList?[rand];
|
|
}
|
|
}
|
|
}
|
|
private static void SelectFriendly(this TargetableUnitComponent targetComponent, TargetFlagType flagType)
|
|
{
|
|
if (targetComponent.selectedTeamMember != null)
|
|
{
|
|
targetComponent.currTarget = targetComponent.selectedTeamMember;
|
|
}
|
|
else
|
|
{
|
|
int count = targetComponent.currFriendlyList.Count;
|
|
if (count > 0)
|
|
{
|
|
int rand = RandomHelper.RandomNumber(0, count);
|
|
targetComponent.currTarget = targetComponent.currFriendlyList?[rand];
|
|
}
|
|
}
|
|
}
|
|
public static void SelectAllTeam(this TargetableUnitComponent targetComponent, TargetFlagType flagType)
|
|
{
|
|
int count = targetComponent.currAllList.Count;
|
|
if (count > 0)
|
|
{
|
|
int rand = RandomHelper.RandomNumber(0, count);
|
|
targetComponent.currTarget = targetComponent.currAllList?[rand];
|
|
}
|
|
}
|
|
}
|
|
}
|