using System;
using System.Collections.Generic;
using System.Linq;
public class BackpackManager : ManagerBase
{
///
/// 背包信息
///
public Dictionary backpackDatas = new Dictionary();
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;
// }
// ///
// /// 获取一级类型
// ///
// 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 GetEquipsByHeroUuid(long uuid)
// {
// var list = new List();
// 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 GetItemsByHeroUuid(long heroUuid, ItemType eType, ItemTypeII eType2 = ItemTypeII.None)
// {
// List list = new List();
// 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 GetItemsByHeroUuid(ItemType eType, ItemTypeII eType2 = ItemTypeII.None)
// {
// List list = new List();
// 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;
// }
//
// ///
// /// 一键装备
// ///
// public List GetOneKeyEquipsByHeroUuid(long heroUuid)
// {
// var list = new List();
// 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();
// 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 GetItemsByType(ItemType t, ItemTypeII tII = ItemTypeII.None)
// {
// var list = new List();
// 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 GetOneKeyRuneByHeroUuid(long heroUuid)
// {
// var runeTypeIIStr = Config_ClientAtt.GetItem("RUNE_ITEMTYPEII").value;
// var runeTypes = runeTypeIIStr.Split(',');
// var list = new List();
// 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 GetEquipStrengthMats()
// {
// List mats = new List();
// 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 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;
// }
// }
// }
// }
}