You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

110 lines
3.1 KiB

using System.Collections.Generic;
using CoreGame.Render;
using Entitas;
using Entitas.CodeGeneration.Attributes;
public partial class CombatEntity
{
public void AddFaction(Faction newFaction, SelectUseType newSelectUseType)
{
var index = CombatComponentsLookup.Faction;
var component =
(FactionComponent)CreateComponent(index, typeof(FactionComponent));
component.faction = newFaction;
component.selectUseType = newSelectUseType;
component.commonBeQueryParam = new QueryParam(newFaction, newSelectUseType);
if (newFaction == Faction.Player)
component.opposite = Faction.Enemy;
else if (newFaction == Faction.Enemy)
component.opposite = Faction.Player;
AddComponent(index, component);
}
public void AddFaction(Faction newFaction, SelectUseType newSelectUseType, Faction newOpposite)
{
var index = CombatComponentsLookup.Faction;
var component =
(FactionComponent)CreateComponent(index, typeof(FactionComponent));
component.faction = newFaction;
component.selectUseType = newSelectUseType;
component.commonBeQueryParam = new QueryParam(newFaction, newSelectUseType);
component.opposite = newOpposite;
AddComponent(index, component);
}
}
namespace CoreGame.Render
{
// 暂时不考虑多阵营
public enum Faction
{
None = 0,
Player = 1,
Enemy = 2,
Npc = 3,
}
public enum SelectUseType
{
None = 0,
Actor = 1, // 角色
Summon = 2, // 召唤物
Zone = 3, // 暴风雪,火墙等区域技能
Bullet = 4,
Obstacle = 5,
Suppressor = 6,
Max,
}
public class QueryParamEqualityComparer : IEqualityComparer<QueryParam>
{
public bool Equals(QueryParam x, QueryParam y)
{
return x == y;
}
public int GetHashCode(QueryParam obj)
{
return obj.GetHashCode();
}
}
public struct QueryParam
{
public Faction faction;
public SelectUseType selectUseType;
public QueryParam(Faction faction, SelectUseType selectUseType)
{
this.faction = faction;
this.selectUseType = selectUseType;
}
public static bool operator ==(QueryParam a, QueryParam b)
{
return a.faction == b.faction && a.selectUseType == b.selectUseType;
}
public static bool operator !=(QueryParam a, QueryParam b)
{
return !(a == b);
}
public override int GetHashCode()
{
return (int)faction * 100 + (int)selectUseType;
}
}
[Combat]
public class FactionComponent : IComponent
{
[EntityIndex] // 阵营
public Faction faction;
[EntityIndex] // 筛选类型
public SelectUseType selectUseType;
// [EntityIndex] // 目标筛选用的
public QueryParam commonBeQueryParam;
public Faction opposite;
}
}