179 lines
5.4 KiB
C#
179 lines
5.4 KiB
C#
|
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
|
|||
|
public class TeamAwakeSystem : AwakeSystem<Team>
|
|||
|
{
|
|||
|
public override void Awake(Team self)
|
|||
|
{
|
|||
|
self.ChangeState(TeamState.None);
|
|||
|
}
|
|||
|
}
|
|||
|
public class TeamDestroy : DestroySystem<Team>
|
|||
|
{
|
|||
|
public override void Destroy(Team self)
|
|||
|
{
|
|||
|
self.teamMemberList.Clear();
|
|||
|
self.teamMemberIds.Clear();
|
|||
|
self.ChangeState(TeamState.None);
|
|||
|
//!不能在这儿修改
|
|||
|
//self.offLineUnits.Clear();
|
|||
|
self.voteList.Clear();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static class TeamSystem
|
|||
|
{
|
|||
|
|
|||
|
public static void ChangeState(this Team self, TeamState state)
|
|||
|
{
|
|||
|
self.TeamState = state;
|
|||
|
foreach (var kv in self.teamMemberList)
|
|||
|
{
|
|||
|
kv.teamState = state;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static Unit Get(this Team self, long id)
|
|||
|
{
|
|||
|
foreach (var item in self.teamMemberList)
|
|||
|
{
|
|||
|
if (item.Id == id)
|
|||
|
return item;
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
public static LinkedList<Unit> GetUnits(this Team self)
|
|||
|
{
|
|||
|
return self.teamMemberList;
|
|||
|
}
|
|||
|
public static List<long> GetUnitIds(this Team self)
|
|||
|
{
|
|||
|
return self.teamMemberIds;
|
|||
|
}
|
|||
|
public static string GetMemberName(this Team self)
|
|||
|
{
|
|||
|
string name = null;
|
|||
|
foreach (var u in self.GetUnits())
|
|||
|
{
|
|||
|
name += $"【{ UserComponent.Instance.Get(u.Id)?.NickName}({u.Id})】";
|
|||
|
}
|
|||
|
return name;
|
|||
|
}
|
|||
|
public static bool Contains(this Team self, long id)
|
|||
|
{
|
|||
|
return self.teamMemberIds.Contains(id);
|
|||
|
}
|
|||
|
public static bool CanAddMember(this Team self, int max)
|
|||
|
{
|
|||
|
return self.MemberCount < max;
|
|||
|
}
|
|||
|
public static void Add(this Team self, Unit unit)
|
|||
|
{
|
|||
|
unit.TeamLeaderId = self.LeaderId;
|
|||
|
self.teamMemberList.AddLast(unit);
|
|||
|
self.teamMemberIds.Add(unit.Id);
|
|||
|
var newBrocast = unit.GetComponent<BrocastComponent>();
|
|||
|
foreach (var item in self.teamMemberList)
|
|||
|
{
|
|||
|
if (item.Id != unit.Id)
|
|||
|
item.GetComponent<BrocastComponent>()?.AddInternal(unit);
|
|||
|
}
|
|||
|
newBrocast.AddInternal(self.teamMemberList);
|
|||
|
|
|||
|
}
|
|||
|
public static void Remove(this Team self, long id)
|
|||
|
{
|
|||
|
for (var item = self.teamMemberList.First; item != null; item = item.Next)
|
|||
|
{
|
|||
|
if (item.Value.Id == id)
|
|||
|
self.teamMemberList.Remove(item);
|
|||
|
}
|
|||
|
self.teamMemberIds.Remove(id);
|
|||
|
self.RemoveAIId(id);
|
|||
|
Unit unit = MapUnitComponent.Instance.Get(id);
|
|||
|
if (unit)
|
|||
|
{
|
|||
|
var newBrocast = unit.GetComponent<BrocastComponent>();
|
|||
|
foreach (var member in self.teamMemberList)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
newBrocast.RemoveInternal(member.Id);
|
|||
|
member.GetComponent<BrocastComponent>()?.RemoveInternal(id);
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
Log.Error(e);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if (self.MemberCount == 0)
|
|||
|
{
|
|||
|
self.GetParent<TeamComponent>().Remove(self.LeaderId);
|
|||
|
self.Dispose();
|
|||
|
}
|
|||
|
}
|
|||
|
public static void RemoveAIId(this Team self,long id)
|
|||
|
{
|
|||
|
if(self.LeaderId!=id)
|
|||
|
MainStoryAIComponent.instance.aiIdDic.Remove(id);
|
|||
|
}
|
|||
|
public static void AddOffLineId(this Team self, Unit unit)
|
|||
|
{
|
|||
|
self.offLineUnits.Add(unit);
|
|||
|
}
|
|||
|
public static bool HasOffLineUnit(this Team self)
|
|||
|
{
|
|||
|
return self.offLineUnits.Count > 0;
|
|||
|
}
|
|||
|
public static void ChangeLeader(this Team self, long leaderId)
|
|||
|
{
|
|||
|
Unit unit = MapUnitComponent.Instance.Get(leaderId);
|
|||
|
if (unit)
|
|||
|
{
|
|||
|
if (self.teamMemberList.Remove(unit))
|
|||
|
{
|
|||
|
self.teamMemberList.AddFirst(unit);
|
|||
|
}else
|
|||
|
Log.Error($"team not has the unit:{leaderId}");
|
|||
|
}else
|
|||
|
Log.Error($"cann't find unit:{leaderId}");
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 选票增加
|
|||
|
/// </summary>
|
|||
|
/// <param name="self"></param>
|
|||
|
/// <param name="count"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static bool AddVote(this Team self, long Id)
|
|||
|
{
|
|||
|
self.voteList.Add(Id);
|
|||
|
Log.Info($"{self.voteList.Count} {self.MemberCount / 2f}");
|
|||
|
if (self.voteList.Count >= self.MemberCount / 2f)
|
|||
|
{
|
|||
|
self.voteList.Clear();
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
public static Unit GetLeader(this Team self)
|
|||
|
{
|
|||
|
long leaderId = self.LeaderId;
|
|||
|
Unit unit = MapUnitComponent.Instance.Get(leaderId);
|
|||
|
if (!unit)
|
|||
|
{
|
|||
|
Log.Error($"unit is invalid :{unit?.Id}");
|
|||
|
return null;
|
|||
|
}
|
|||
|
return unit;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|