183 lines
6.1 KiB
C#
183 lines
6.1 KiB
C#
using cfg.ActorCfg;
|
||
using cfg.CharacterCfg;
|
||
using cfg.LevelCfg;
|
||
using Framework;
|
||
using Gameplay.Common;
|
||
using Gameplay.Net;
|
||
using NLDPB;
|
||
using System.Collections.Generic;
|
||
|
||
namespace Gameplay
|
||
{
|
||
public partial class CommonUtils
|
||
{
|
||
public static uint GetItemCount(int id)
|
||
{
|
||
return Actor.Instance.Item.GetItemCount(id);
|
||
}
|
||
|
||
public static string GetItemName(int id)
|
||
{
|
||
return GetLocalizeText(TableManager.Instance.Tables.Item.Get(id).NameLocal);
|
||
}
|
||
public static string GetItemPath(int id)
|
||
{
|
||
return TableManager.Instance.Tables.Item.Get(id).IconPath;
|
||
}
|
||
|
||
public static readonly List<ItemSource> ItemSourceNotShowInItemWindow = new List<ItemSource>
|
||
{ ItemSource.LevelPassNormal, ItemSource.LevelPassFirst, ItemSource.LevelPassStar1,
|
||
ItemSource.LevelPassStar2, ItemSource.LevelPassStar2, ItemSource.LevelPassStar3,
|
||
ItemSource.ChapterStar,ItemSource.MailItem,ItemSource.Raffle, ItemSource.LevelUp,
|
||
};
|
||
|
||
public static int GetItemCharacterCfgId(int id)
|
||
{
|
||
DataItem item = TableManager.Instance.Tables.Item.Get(id);
|
||
if(item==null)
|
||
{
|
||
DebugUtil.Log("item表格id为{0}的物品不存在",id);
|
||
return 0;
|
||
}
|
||
if(item.Type!=ItemType.Character)
|
||
{
|
||
DebugUtil.Log("item表格id为{0}的物品不是角色物品", id);
|
||
return 0;
|
||
}
|
||
DataCharacterAttri dataCharacterAttri=TableManager.Instance.Tables.CharacterAttri.Get(item.Param1);
|
||
if(dataCharacterAttri==null)
|
||
{
|
||
DebugUtil.Log("item表格id为{0}的物品角色id没有配");
|
||
return 0;
|
||
}
|
||
return item.Param1;
|
||
|
||
}
|
||
public static ItemType GetItemType(int id)
|
||
{
|
||
DataItem item = TableManager.Instance.Tables.Item.Get(id);
|
||
return item.Type;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 道具是否溢出
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="count"></param>
|
||
/// <returns></returns>
|
||
public static bool IsItemOverflow(int id, int count)
|
||
{
|
||
DataItem item = TableManager.Instance.Tables.Item.Get(id);
|
||
if (item == null)
|
||
{
|
||
DebugUtil.LogError($"获取道具配置失败,道具id:{id}");
|
||
return true;
|
||
}
|
||
|
||
if (item.MaxCount == 0)
|
||
return count > TableManager.Instance.Tables.GlobalConfig.ItemMaxDefault;
|
||
|
||
return count > item.MaxCount;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 角色皮肤本地化名称
|
||
/// </summary>
|
||
/// <param name="skinCfg"></param>
|
||
/// <returns></returns>
|
||
public static string GetSkinName(DataCharacterSkin skinCfg)
|
||
{
|
||
string skinNameKey = $"SkinInfo_SkinName_{skinCfg.RoleID}_{skinCfg.SkinID:D2}";
|
||
return GetLocalizeText(skinNameKey);
|
||
}
|
||
/// <summary>
|
||
/// 角色皮肤本地化描述
|
||
/// </summary>
|
||
/// <param name="skinCfg"></param>
|
||
/// <returns></returns>
|
||
public static string GetSkinDesc(DataCharacterSkin skinCfg)
|
||
{
|
||
string skinDescKey = $"SkinInfo_SkinDesc_{skinCfg.RoleID}_{skinCfg.SkinID:D2}";
|
||
return GetLocalizeText(skinDescKey);
|
||
}
|
||
/// <summary>
|
||
/// 皮肤获取条件
|
||
/// </summary>
|
||
/// <param name="skinCfg"></param>
|
||
/// <returns></returns>
|
||
public static string GetSkinAcquireCondition(DataCharacterSkin skinCfg)
|
||
{
|
||
string skinAcquireConditionKey = $"SkinInfo_AcquireCondition_{skinCfg.RoleID}_{skinCfg.SkinID:D2}";
|
||
return GetLocalizeText(skinAcquireConditionKey);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 从道具列表中获取指定来源的道具
|
||
/// </summary>
|
||
/// <param name="sourceType"></param>
|
||
/// <param name="itemList"></param>
|
||
/// <returns></returns>
|
||
public static List<Item> GetItemBySource(ItemSource sourceType, ItemCounts[] itemList)
|
||
{
|
||
var itemCount = itemList[(int)sourceType];
|
||
if (itemCount.Ids.Count > 0)
|
||
{
|
||
ListItem items = new ListItem(itemCount);
|
||
return items.List;
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将一个道具列表的内容加入到另一个道具列表中
|
||
/// </summary>
|
||
/// <param name="Sourcelist"></param>
|
||
/// <param name="addList"></param>
|
||
public static void CombineListItem(List<Item> Sourcelist, List<Item> addList)
|
||
{
|
||
for (int i = 0; i < addList.Count; i++)
|
||
{
|
||
var item = addList[i];
|
||
if (Sourcelist.Find(it => item.ID == it.ID) != null)
|
||
{
|
||
Sourcelist[i].AddCount(item.Count);
|
||
continue;
|
||
}
|
||
Sourcelist.Add(item);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查体力是否足够
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static bool CheckEnergy(DataLevel dataLevel, int fightCount)
|
||
{
|
||
if (dataLevel.CostItems.Count <= 0)
|
||
{
|
||
DebugUtil.LogError($"关卡消耗配置错误,关卡id:{dataLevel.Id}");
|
||
return true;
|
||
}
|
||
|
||
int costEnergy = dataLevel.CostItems[0].Count * fightCount;
|
||
|
||
return EnergyManager.Instance.EnergyCheck(costEnergy);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取体力最大战斗次数
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static int GetEnergyFightCount(DataLevel dataLevel)
|
||
{
|
||
if (dataLevel.CostItems.Count <= 0)
|
||
{
|
||
DebugUtil.LogError($"关卡消耗配置错误,关卡id:{dataLevel.Id}");
|
||
return 0;
|
||
}
|
||
|
||
return EnergyManager.Instance.GetMaxFightCount(dataLevel.CostItems[0].Count);
|
||
}
|
||
}
|
||
} |