452 lines
16 KiB
C#
452 lines
16 KiB
C#
|
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
public class BackpackManager : ManagerBase
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 背包信息
|
|||
|
/// </summary>
|
|||
|
public Dictionary<long, BackpackItem> backpackDatas = new Dictionary<long, BackpackItem>();
|
|||
|
|
|||
|
public BackpackItem GetItem(long uuid)
|
|||
|
{
|
|||
|
if (backpackDatas.ContainsKey(uuid))
|
|||
|
return backpackDatas[uuid];
|
|||
|
else return null;
|
|||
|
}
|
|||
|
|
|||
|
public BackpackItem GetItem(int propId)
|
|||
|
{
|
|||
|
foreach (var item in backpackDatas)
|
|||
|
if (item.Value.itemId == propId)
|
|||
|
return item.Value;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
public int GetCount(int propId)
|
|||
|
{
|
|||
|
var bag = GetItem(propId);
|
|||
|
if (bag == null) return 0;
|
|||
|
return bag.count;
|
|||
|
}
|
|||
|
|
|||
|
// public ItemType GetType(int itemId)
|
|||
|
// {
|
|||
|
// // var cfg = ConfigBase_Item.GetItem(itemId);
|
|||
|
// // if (cfg == null)
|
|||
|
// // {
|
|||
|
// // LogError($"Items表找不到 {itemId}");
|
|||
|
// // return ItemType.Material;
|
|||
|
// // }
|
|||
|
// // return (ItemType)cfg.categoryI;
|
|||
|
// }
|
|||
|
|
|||
|
public void Reset()
|
|||
|
{
|
|||
|
backpackDatas.Clear();
|
|||
|
}
|
|||
|
|
|||
|
// public string GetIcon(int itemId)
|
|||
|
// {
|
|||
|
// // var cfg = ConfigBase_Item.GetItem(itemId);
|
|||
|
// // if (cfg == null) return "";
|
|||
|
// // return cfg.img;
|
|||
|
// }
|
|||
|
// /// <summary>
|
|||
|
// /// 获取一级类型
|
|||
|
// /// </summary>
|
|||
|
// public int GetCategoryI(int itemId)
|
|||
|
// {
|
|||
|
// var cfg = ConfigBase_Item.GetItem(itemId);
|
|||
|
// if (cfg == null) return -1;
|
|||
|
// return cfg.categoryI;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public int GetCategoryII(int itemId)
|
|||
|
// {
|
|||
|
// var cfg = ConfigBase_Item.GetItem(itemId);
|
|||
|
// if (cfg == null) return 0;
|
|||
|
// return cfg.categoryII;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public string GetName(int itemId)
|
|||
|
// {
|
|||
|
// var cfg = ConfigBase_Item.GetItem(itemId);
|
|||
|
// if (cfg == null) return "";
|
|||
|
// return cfg.name_i18;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public string GetPashIds(int itemId)
|
|||
|
// {
|
|||
|
// var cfg = ConfigBase_Item.GetItem(itemId);
|
|||
|
// if (cfg == null) return "";
|
|||
|
// return cfg.getPathID;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public string GetDescribe(int itemId)
|
|||
|
// {
|
|||
|
// var cfg = ConfigBase_Item.GetItem(itemId);
|
|||
|
// if (cfg == null) return "";
|
|||
|
// return cfg.useRemark_i18;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public PropQuality GetQuality(int id)
|
|||
|
// {
|
|||
|
// return (PropQuality)GetQualityByInt(id);
|
|||
|
// }
|
|||
|
//
|
|||
|
// public int GetQualityByInt(int itemId)
|
|||
|
// {
|
|||
|
// var cfg = ConfigBase_Item.GetItem(itemId);
|
|||
|
// if (cfg == null) return 0;
|
|||
|
// return cfg.colour;
|
|||
|
// }
|
|||
|
|
|||
|
// public int GetStarByInt(int id)
|
|||
|
// {
|
|||
|
// // return Config_FakeItem.GetItem(id)?.star ?? 0;
|
|||
|
// }
|
|||
|
|
|||
|
public static int GetFirstDigit(int number)
|
|||
|
{
|
|||
|
// 处理特殊情况:负数和0
|
|||
|
if (number == 0)
|
|||
|
return 0;
|
|||
|
|
|||
|
number = Math.Abs(number);
|
|||
|
|
|||
|
// 确定数字的位数
|
|||
|
int bitLength = (int)Math.Log10(number);
|
|||
|
|
|||
|
// 通过除以 10 的相应次幂来获取最左边的数字
|
|||
|
int firstDigit = number / (int)Math.Pow(10, bitLength);
|
|||
|
|
|||
|
return firstDigit;
|
|||
|
}
|
|||
|
//
|
|||
|
// public List<BackpackItem_Equip> GetEquipsByHeroUuid(long uuid)
|
|||
|
// {
|
|||
|
// var list = new List<BackpackItem_Equip>();
|
|||
|
// foreach (var item in backpackDatas)
|
|||
|
// {
|
|||
|
// var t = GetCategoryI(item.Value.itemId);
|
|||
|
// if ((ItemType)t == ItemType.Equipment)
|
|||
|
// {
|
|||
|
// var equipItem = item.Value as BackpackItem_Equip;
|
|||
|
// if (equipItem.heroId == uuid)
|
|||
|
// list.Add(equipItem);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
|
|||
|
// public List<BackpackItem> GetItemsByHeroUuid(long heroUuid, ItemType eType, ItemTypeII eType2 = ItemTypeII.None)
|
|||
|
// {
|
|||
|
// List<BackpackItem> list = new List<BackpackItem>();
|
|||
|
// if (eType2 != ItemTypeII.None)
|
|||
|
// {
|
|||
|
// foreach (var item in backpackDatas)
|
|||
|
// {
|
|||
|
// var t = GetCategoryI(item.Value.itemId);
|
|||
|
// var t2 = GetCategoryII(item.Value.itemId);
|
|||
|
// if ((ItemType)t == eType && (ItemTypeII)t2 == eType2)
|
|||
|
// {
|
|||
|
// if (eType == ItemType.Equipment)
|
|||
|
// {
|
|||
|
// var equipItem = item.Value as BackpackItem_Equip;
|
|||
|
// if (equipItem.heroId == heroUuid)
|
|||
|
// {
|
|||
|
// list.Add(equipItem);
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// if (eType == ItemType.Rune)
|
|||
|
// {
|
|||
|
// var runeItem = item.Value as BackpackItem_Rune;
|
|||
|
// if (runeItem.heroId == heroUuid)
|
|||
|
// {
|
|||
|
// list.Add(runeItem);
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// foreach (var item in backpackDatas)
|
|||
|
// {
|
|||
|
// var t = GetCategoryI(item.Value.itemId);
|
|||
|
// if ((ItemType)t == eType)
|
|||
|
// {
|
|||
|
// if (eType == ItemType.Equipment)
|
|||
|
// {
|
|||
|
// var equipItem = item.Value as BackpackItem_Equip;
|
|||
|
// if (equipItem.heroId == heroUuid)
|
|||
|
// list.Add(equipItem);
|
|||
|
// }
|
|||
|
// if (eType == ItemType.Rune)
|
|||
|
// {
|
|||
|
// var runeItem = item.Value as BackpackItem_Rune;
|
|||
|
// if (runeItem.heroId == heroUuid)
|
|||
|
// list.Add(runeItem);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public List<BackpackItem> GetItemsByHeroUuid(ItemType eType, ItemTypeII eType2 = ItemTypeII.None)
|
|||
|
// {
|
|||
|
// List<BackpackItem> list = new List<BackpackItem>();
|
|||
|
// if (eType2 != ItemTypeII.None)
|
|||
|
// {
|
|||
|
// foreach (var item in backpackDatas)
|
|||
|
// {
|
|||
|
// var t = GetCategoryI(item.Value.itemId);
|
|||
|
// var t2 = GetCategoryII(item.Value.itemId);
|
|||
|
// if ((ItemType)t == eType && (ItemTypeII)t2 == eType2)
|
|||
|
// {
|
|||
|
// if (eType == ItemType.Equipment)
|
|||
|
// {
|
|||
|
// var equipItem = item.Value as BackpackItem_Equip;
|
|||
|
// if (equipItem.heroId != -1)
|
|||
|
// {
|
|||
|
// list.Add(equipItem);
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// if (eType == ItemType.Rune)
|
|||
|
// {
|
|||
|
// var runeItem = item.Value as BackpackItem_Rune;
|
|||
|
// if (runeItem.heroId != -1)
|
|||
|
// {
|
|||
|
// list.Add(runeItem);
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// foreach (var item in backpackDatas)
|
|||
|
// {
|
|||
|
// var t = GetCategoryI(item.Value.itemId);
|
|||
|
// if ((ItemType)t == eType)
|
|||
|
// {
|
|||
|
// if (eType == ItemType.Equipment)
|
|||
|
// {
|
|||
|
// var equipItem = item.Value as BackpackItem_Equip;
|
|||
|
// if (equipItem.heroId != -1)
|
|||
|
// list.Add(equipItem);
|
|||
|
// }
|
|||
|
// if (eType == ItemType.Rune)
|
|||
|
// {
|
|||
|
// var runeItem = item.Value as BackpackItem_Rune;
|
|||
|
// if (runeItem.heroId != -1)
|
|||
|
// list.Add(runeItem);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
//
|
|||
|
// /// <summary>
|
|||
|
// /// 一键装备
|
|||
|
// /// </summary>
|
|||
|
// public List<BackpackItem_Equip> GetOneKeyEquipsByHeroUuid(long heroUuid)
|
|||
|
// {
|
|||
|
// var list = new List<BackpackItem_Equip>();
|
|||
|
// var equipTypeStr = Config_ClientAtt.GetItem("WEAPON_ITEMTYPEII").value;
|
|||
|
// var equipTypes = equipTypeStr.Split(",").Select(i => (ItemTypeII)int.Parse(i));
|
|||
|
// foreach (var eType in equipTypes)
|
|||
|
// {
|
|||
|
// if (OpenLvUtils.IsOpen(BackpackConst.EquipOpenLv[eType]))
|
|||
|
// {
|
|||
|
// BackpackItem_Equip equipItem = null;
|
|||
|
// var equips = GetItemsByType(ItemType.Equipment, eType).Select((i) => i as BackpackItem_Equip)
|
|||
|
// .Where((equip) => (equip.heroId == heroUuid || equip.heroId <= 0)).ToList<BackpackItem_Equip>();
|
|||
|
// equips.Sort((a, b) => { return b.power - a.power; });
|
|||
|
// equipItem = equips.Count > 0 ? equips[0] : null;
|
|||
|
// if (equipItem != null)
|
|||
|
// list.Add(equipItem);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public List<BackpackItem> GetItemsByType(ItemType t, ItemTypeII tII = ItemTypeII.None)
|
|||
|
// {
|
|||
|
// var list = new List<BackpackItem>();
|
|||
|
// foreach (var data in backpackDatas)
|
|||
|
// {
|
|||
|
// var itemType = GetCategoryI(data.Value.itemId);
|
|||
|
// if ((ItemType)itemType == t)
|
|||
|
// {
|
|||
|
// if (tII == ItemTypeII.None)
|
|||
|
// list.Add(data.Value);
|
|||
|
// else
|
|||
|
// {
|
|||
|
// var itemTypeII = GetCategoryII(data.Value.itemId);
|
|||
|
// if ((ItemTypeII)itemTypeII == tII)
|
|||
|
// {
|
|||
|
// list.Add(data.Value);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public int GetRuneSuitCount(int itemId, long heroUuid)
|
|||
|
// {
|
|||
|
// var cfg = Config_RuneItem.GetItem(itemId);
|
|||
|
// var runeItems = this.GetItemsByHeroUuid(heroUuid, ItemType.Rune);
|
|||
|
// var haveCount = 1;
|
|||
|
// foreach (var item in runeItems)
|
|||
|
// {
|
|||
|
// var runeCfg = Config_RuneItem.GetItem(item.itemId);
|
|||
|
// if (cfg.groupId == runeCfg.groupId && cfg.categoryII != runeCfg.categoryII)
|
|||
|
// haveCount++;
|
|||
|
// }
|
|||
|
// return haveCount;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public List<BackpackItem_Rune> GetOneKeyRuneByHeroUuid(long heroUuid)
|
|||
|
// {
|
|||
|
// var runeTypeIIStr = Config_ClientAtt.GetItem("RUNE_ITEMTYPEII").value;
|
|||
|
// var runeTypes = runeTypeIIStr.Split(',');
|
|||
|
// var list = new List<BackpackItem_Rune>();
|
|||
|
// for (int i = 0; i < runeTypes.Length; i++)
|
|||
|
// {
|
|||
|
// BackpackItem_Rune runeItem = null;
|
|||
|
// var eType = int.Parse(runeTypes[i]);
|
|||
|
// foreach (var data in backpackDatas)
|
|||
|
// {
|
|||
|
// var item = data.Value as BackpackItem_Rune;
|
|||
|
// var t = GetCategoryI(data.Value.itemId);
|
|||
|
// if ((ItemType)t == ItemType.Rune)
|
|||
|
// {
|
|||
|
// var cfg = Config_RuneItem.GetItem(data.Value.itemId);
|
|||
|
// if (cfg.categoryII == eType)
|
|||
|
// {
|
|||
|
// if (item.heroId == heroUuid || item.heroId <= 0)
|
|||
|
// {
|
|||
|
// if (runeItem == null || item.power > runeItem.power)
|
|||
|
// runeItem = item;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// if (runeItem != null)
|
|||
|
// list.Add(runeItem);
|
|||
|
// }
|
|||
|
// return list;
|
|||
|
// }
|
|||
|
|
|||
|
// public bool IsRuneSuitActive(int itemId, int needCount, long heroUuid)
|
|||
|
// {
|
|||
|
// var haveCount = GetRuneSuitCount(itemId, heroUuid);
|
|||
|
// return haveCount >= needCount;
|
|||
|
// }
|
|||
|
//
|
|||
|
// public List<BackpackItem> GetEquipStrengthMats()
|
|||
|
// {
|
|||
|
// List<BackpackItem> mats = new List<BackpackItem>();
|
|||
|
// mats = Game.backpack.GetItemsByType(ItemType.Consumable, ItemTypeII.EquipStrength);
|
|||
|
// var equips = Game.backpack.GetItemsByType(ItemType.Equipment);
|
|||
|
// foreach (var item in equips)
|
|||
|
// {
|
|||
|
// var equip = item as BackpackItem_Equip;
|
|||
|
// if (equip.heroId <= 0)
|
|||
|
// mats.Add(equip);
|
|||
|
// }
|
|||
|
// return mats;
|
|||
|
// }
|
|||
|
//
|
|||
|
//
|
|||
|
// public void CalNextLvExp(Dev_Sys sys, long uuid, List<long> mats, ref int lv, ref int exp, ref int addExp)
|
|||
|
// {
|
|||
|
// if (sys == Dev_Sys.Equip_Strength)
|
|||
|
// {
|
|||
|
// var item = GetItem(uuid) as BackpackItem_Equip;
|
|||
|
// var cfg = Config_EquipmentItem.GetItem(item.itemId);
|
|||
|
//
|
|||
|
// //材料经验
|
|||
|
// addExp = 0;
|
|||
|
// foreach (var mat in mats)
|
|||
|
// {
|
|||
|
// var backPackItem = Game.backpack.GetItem(mat);
|
|||
|
// ItemType type = Game.backpack.GetType(backPackItem.itemId);
|
|||
|
// var useLogic = "";
|
|||
|
// switch (type)
|
|||
|
// {
|
|||
|
// case ItemType.Equipment:
|
|||
|
// useLogic = Config_EquipmentItem.GetItem(backPackItem.itemId).useLogic;
|
|||
|
// addExp += Config_ItemEquipStrengthen.GetTotalExp(mat);
|
|||
|
// break;
|
|||
|
// case ItemType.Consumable:
|
|||
|
// useLogic = Config_PropItem.GetItem(backPackItem.itemId).useLogic;
|
|||
|
// break;
|
|||
|
// }
|
|||
|
// addExp += int.Parse(useLogic.Split(",")[1]);
|
|||
|
// }
|
|||
|
//
|
|||
|
// //计算等级+剩余经验
|
|||
|
// var leftExp = addExp;
|
|||
|
// var items = Config_ItemEquipStrengthen.GetAllItemsByColor(cfg.colour);
|
|||
|
// for (int i = lv - 1; i < items.Count; i++) //1级index:0
|
|||
|
// {
|
|||
|
// var strengthItem = items[i];
|
|||
|
// if (strengthItem.exp > 0 && leftExp + exp - strengthItem.exp >= 0)
|
|||
|
// {
|
|||
|
// leftExp = leftExp + exp - strengthItem.exp;
|
|||
|
// exp = 0;
|
|||
|
// lv++;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// exp = leftExp + exp;
|
|||
|
// break;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// else if (sys == Dev_Sys.Rune_Strength)
|
|||
|
// {
|
|||
|
// var item = Game.backpack.GetItem(uuid) as BackpackItem_Rune;
|
|||
|
// var cfg = Config_RuneItem.GetItem(item.itemId);
|
|||
|
//
|
|||
|
// addExp = 0;
|
|||
|
// foreach (var mat in mats)
|
|||
|
// {
|
|||
|
// var strs = cfg.useLogic.Split(';').Where(s => s.Contains("runeStrengthExp")).Select(s => s.Split(',')).ToList();
|
|||
|
// addExp += strs.Count > 0 ? int.Parse(strs[0][1]) : 0;
|
|||
|
// addExp += Config_RuneStrength.GetTotalExp(mat);
|
|||
|
// }
|
|||
|
//
|
|||
|
// //计算等级+剩余经验
|
|||
|
// var leftExp = addExp;
|
|||
|
// var items = Config_RuneStrength.GetAllItemsByColor(cfg.colour);
|
|||
|
// for (int i = lv; i < items.Count; i++) //0级index:0
|
|||
|
// {
|
|||
|
// var strengthItem = items[i];
|
|||
|
// if (strengthItem.exp > 0 && leftExp + exp - strengthItem.exp >= 0)
|
|||
|
// {
|
|||
|
// leftExp = leftExp + exp - strengthItem.exp;
|
|||
|
// exp = 0;
|
|||
|
// lv++;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// exp = leftExp + exp;
|
|||
|
// break;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
}
|