128 lines
4.6 KiB
C#
128 lines
4.6 KiB
C#
using ET;
|
|
using Cal.DataTable;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using ET.EventType;
|
|
|
|
namespace ET
|
|
{
|
|
|
|
public class ClientUnitCharacterComponentAwakeSystem : AwakeSystem<ClientUnitCharacterComponent>
|
|
{
|
|
public override void Awake(ClientUnitCharacterComponent self)
|
|
{
|
|
ClientUnitCharacterComponent.Instance = self;
|
|
}
|
|
}
|
|
public class ClientUnitCharacterComponentDestroySystem : DestroySystem<ClientUnitCharacterComponent>
|
|
{
|
|
public override void Destroy(ClientUnitCharacterComponent self)
|
|
{
|
|
self.Destroy();
|
|
}
|
|
}
|
|
public class ClientUnitCharacterComponent : Entity
|
|
{
|
|
public static ClientUnitCharacterComponent Instance { get; set; }
|
|
|
|
|
|
private readonly Dictionary<long, ClientUnitCharacter> _clientUnitCharacterDic = new Dictionary<long, ClientUnitCharacter>();
|
|
public void Add(long Id,string name,int level,int hp=0,int maxHp=0)
|
|
{
|
|
ClientUnitCharacter unitCharacter = EntityFactory.CreateWithParentAndId<ClientUnitCharacter>(this,Id);
|
|
unitCharacter.NickName = name;
|
|
|
|
Add(unitCharacter.Id, unitCharacter);
|
|
}
|
|
public void Add(UnitCharacter unitServerCharacter)
|
|
{
|
|
ClientUnitCharacter unitCharacter = EntityFactory.CreateWithParentAndId<ClientUnitCharacter>(this,unitServerCharacter.Id);
|
|
unitCharacter.NickName = unitServerCharacter.NickName;
|
|
unitCharacter.JobId = unitServerCharacter.JobId;
|
|
unitCharacter.CampType = unitServerCharacter.CampType;
|
|
unitCharacter.Family = unitServerCharacter.Family;
|
|
unitCharacter.Title = unitServerCharacter.Title;
|
|
|
|
Add(unitCharacter.Id, unitCharacter);
|
|
}
|
|
private void Add(long id,ClientUnitCharacter clientUnitCharacter)
|
|
{
|
|
if (_clientUnitCharacterDic.ContainsKey(id))
|
|
{
|
|
Log.Error($"_clientUnitCharacterDic already has the key = {id}");
|
|
}
|
|
_clientUnitCharacterDic[id] = clientUnitCharacter;
|
|
}
|
|
public ClientUnitCharacter Update(UnitCharacter unitServerCharacter)
|
|
{
|
|
long Id = unitServerCharacter.Id;
|
|
if (!_clientUnitCharacterDic.TryGetValue(Id, out var unitCharacter))
|
|
{
|
|
unitCharacter = EntityFactory.CreateWithParentAndId<ClientUnitCharacter>(this,Id);
|
|
Add(unitCharacter.Id, unitCharacter);
|
|
}
|
|
unitCharacter.Id = unitServerCharacter.Id;
|
|
unitCharacter.NickName = unitServerCharacter.NickName;
|
|
unitCharacter.JobId = unitServerCharacter.JobId;
|
|
unitCharacter.CampType = unitServerCharacter.CampType;
|
|
unitCharacter.Family = unitServerCharacter.Family;
|
|
unitCharacter.Title = unitServerCharacter.Title;
|
|
unitCharacter.SkinId = unitServerCharacter.SkinId;
|
|
unitCharacter.CharacterPoint = unitServerCharacter.CharacterPoint;
|
|
unitCharacter.SkillPoint = unitServerCharacter.SkillPoint;
|
|
return unitCharacter;
|
|
}
|
|
public ClientUnitCharacter Get(long id)
|
|
{
|
|
_clientUnitCharacterDic.TryGetValue(id, out var unitCharacter);
|
|
return unitCharacter;
|
|
}
|
|
public ClientUnitCharacter Get()
|
|
{
|
|
_clientUnitCharacterDic.TryGetValue(UnitComponent.MyUnit.Id, out var unitCharacter);
|
|
return unitCharacter;
|
|
}
|
|
public void Remove(long id)
|
|
{
|
|
var character = Get(id);
|
|
if (!_clientUnitCharacterDic.Remove(id))
|
|
{
|
|
Log.Error($"character == null where Id = {id}");
|
|
}
|
|
character?.Dispose();
|
|
}
|
|
public void Remove(Unit unit)
|
|
{
|
|
switch (unit.UnitType)
|
|
{
|
|
case UnitType.None:
|
|
break;
|
|
case UnitType.Player:
|
|
case UnitType.MainStoryMonster:
|
|
case UnitType.TrialCopyMonster:
|
|
case UnitType.BossMonster:
|
|
case UnitType.OtherPlayer:
|
|
case UnitType.Enermy:
|
|
case UnitType.TeamMember:
|
|
case UnitType.ManulEquipMonster:
|
|
Remove(unit.Id);
|
|
break;
|
|
case UnitType.NPC:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
foreach (var item in _clientUnitCharacterDic.Values)
|
|
{
|
|
item.Dispose();
|
|
}
|
|
_clientUnitCharacterDic.Clear();
|
|
}
|
|
}
|
|
}
|