122 lines
3.6 KiB
C#
122 lines
3.6 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Cal;
|
|||
|
using ET.EventType;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
public class StarSoulBagAwakeSystem: AwakeSystem<StarSoulBag>
|
|||
|
{
|
|||
|
public override void Awake(StarSoulBag self)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class StarSoulBagDeserializeSystem: DeserializeSystem<StarSoulBag>
|
|||
|
{
|
|||
|
public override void Deserialize(StarSoulBag self)
|
|||
|
{
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class StarSoulBagDestroySystem: DestroySystem<StarSoulBag>
|
|||
|
{
|
|||
|
public override void Destroy(StarSoulBag self)
|
|||
|
{
|
|||
|
self.ItemCount = 0;
|
|||
|
self.itemDic.Clear();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static class StarSoulBagSystem
|
|||
|
{
|
|||
|
public static void InitData(this StarSoulBag self)
|
|||
|
{
|
|||
|
#if UNITY
|
|||
|
GetDataFromServer(self).Coroutine();
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
private static async ETVoid GetDataFromServer(StarSoulBag self)
|
|||
|
{
|
|||
|
var ret = await self.ZoneScene().GetComponent<SessionComponent>().Call<M2C_GetStarSoulBag>(new C2M_GetStarSoulBag());
|
|||
|
if (!ret.Message.IsNullOrEmpty())
|
|||
|
{
|
|||
|
Game.EventSystem.Publish(new ShowTipUI() { tip = ret.Message, tipType = TipType.Single, isClearIpt = true, });
|
|||
|
return;
|
|||
|
}
|
|||
|
foreach (StarSoulNetItem starSoulNetItem in ret.itemList)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var item = new StarSoulItem()
|
|||
|
{
|
|||
|
Id = starSoulNetItem.Id,
|
|||
|
isUsed = starSoulNetItem.isUsed,
|
|||
|
posType = (EquipType) starSoulNetItem.posType,
|
|||
|
quality = (Quality) starSoulNetItem.quality,
|
|||
|
typeId = starSoulNetItem.typeId,
|
|||
|
level = (byte) starSoulNetItem.level,
|
|||
|
exp = starSoulNetItem.exp,
|
|||
|
};
|
|||
|
item.mainAttribute = starSoulNetItem.main;
|
|||
|
for (var i = 0; i < starSoulNetItem.vice.Count; i++)
|
|||
|
{
|
|||
|
item.viceAttribute[i] = starSoulNetItem.vice[i];
|
|||
|
} for (var i = 0; i < starSoulNetItem.viceAdd.Count; i++)
|
|||
|
{
|
|||
|
item.viceAdd[i] = starSoulNetItem.viceAdd[i];
|
|||
|
}
|
|||
|
self.Add(item);
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
Debug.Log(e);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static bool CanAdd(this StarSoulBag self)
|
|||
|
{
|
|||
|
return self.ItemCount < StarSoulBag.MaxCount;
|
|||
|
}
|
|||
|
|
|||
|
public static string Add(this StarSoulBag self, StarSoulItem item)
|
|||
|
{
|
|||
|
if (!self.CanAdd()) return "星魂背包已满";
|
|||
|
if (self.itemDic.ContainsKey(item.Id))
|
|||
|
{
|
|||
|
#if SERVER
|
|||
|
Log.Error($"{self.Id.GetPlayerFormatName()} serverId 重复 :{item.Id}");
|
|||
|
#endif
|
|||
|
return "系统错误";
|
|||
|
}
|
|||
|
|
|||
|
self.itemDic.Add(item.Id, item);
|
|||
|
self.ItemCount++;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
public static bool Remove(this StarSoulBag self, long Id)
|
|||
|
{
|
|||
|
if(! self.itemDic.Remove(Id))
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
self.ItemCount--;
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public static StarSoulItem Get(this StarSoulBag self, long Id)
|
|||
|
{
|
|||
|
if (!self.itemDic.TryGetValue(Id, out var itemBase))
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return itemBase;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|