// *********************************************************************** // Company : // Author : Kimch // Created : // // Last Modified By : Kimch // Last Modified On : // *********************************************************************** namespace G { using CodeStage.AntiCheat.ObscuredTypes; using F; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 物品基类 /// public class Item : F.Item.IItem { #region CONST #endregion #region ENUM public static class Id { public const int kCoin = 1; public const int kGem = 2; public const int kAds = 3; public const int kRmb = 4; public const int kChip = 5; public const int kChip2 = 36; public const int kEnergy = 6; public const int kGrade = 7; public const int kExp = 8; public const int kBeautyLevel = 10; public const int kBeautyExp = 9; public const int kStone = 11; public const int kBattlePassExp = 12; public const int kBattlePassToken = 13; public const int kMotility = 17; /// /// 好友值 /// public const int kFriend = 21; public const int kLuckyBag = 27; public const int kAdTicket = 33; } public static class Type { public const int Money = 1; public const int Prop = 2; public const int Weapon = 3; public const int Equipment = 4; public const int Gem = 6; public const int BeautyProp = 8; } public static class Quality { public const int kMin = 1; public const int kWhite = 1; public const int kGreen = 2; public const int kBlue = 3; public const int kPurple = 4; public const int kYellow = 5; public const int kRed = 6; public const int kMax = 6; } public enum EquipmentType { Weapon, kMax = 6, } #endregion #region Field public int id { get; protected set; } public ItemProp propItem { get { return ItemProxy.Instance.GetStaticItem(id); } } #endregion #region MODEL /// /// 物品信息 /// public struct ItemInfo { public int id; private ObscuredInt _obscuredCount; public int count { get { return _obscuredCount; } set { _obscuredCount = value; } } public ItemProp propItem { get { return ItemProxy.Instance.GetStaticItem(id); } } public override int GetHashCode() { return id; } public void Set(int id, int count) { this.id = id; _obscuredCount = count; } /// /// /// /// public void Apply(float multiple) { _obscuredCount = (int)(count * multiple); } /// /// /// /// /// public ItemInfo(int id, int count) { this.id = id; _obscuredCount = count; } /// /// /// /// /// /// public static ItemInfo Create(int id, int count) { return new ItemInfo { id = id, _obscuredCount = count }; } public static void FromArray(List results, int[] source, int offset = 0) { if (source != null && source.Length > offset) { int length = (source.Length - offset) / 2; for (int i = 0, j = offset; i < length; i++) { results.Add(new ItemInfo { id = source[j++], count = source[j++], }); } } } /// /// /// /// /// /// public static ItemInfo[] FromArray(IList data, int start = 0) { if (data != null) { int length = data.Count - start; var ret = new ItemInfo[length / 2]; for (int i = 0, j = start; i < ret.Length; i++) { ret[i] = new ItemInfo { id = data[j++], count = data[j++], }; } return ret; } else { return new ItemInfo[0]; } } /// /// /// /// /// public static ItemInfo[] FormJsonList(IList list) { if (list != null) { var result = new ItemInfo[list.Count]; for (int i = 0; i < list.Count; i++) { var info = list.GetDictionary(i); result[i] = new ItemInfo { id = info.GetInt("id"), count = info.GetInt("count"), }; } return result; } return null; } /// /// /// /// /// /// public static ItemInfo Convert(IList data, int start = 0) { if (data != null && data.Count > start + 1) { var ret = new ItemInfo() { id = data[start], count = data[start + 1], }; return ret; } else { return new ItemInfo(); } } static readonly Dictionary _Caches = new Dictionary(); /// /// 合并 堆叠 /// /// /// public static void Combine(IList sources, List results) { _Caches.Clear(); for (int i = 0; i < sources.Count; i++) { var itemInfo = sources[i]; if (itemInfo.id < 100) { if (_Caches.TryGetValue(itemInfo.id, out var result)) { result.count += itemInfo.count; _Caches[itemInfo.id] = result; } else { _Caches.Add(itemInfo.id, itemInfo); } } } if (_Caches.Count > 0) { results.AddRange(_Caches.Values); foreach (var itemInfo in sources) { if (itemInfo.id >= 100) { results.Add(itemInfo); } } _Caches.Clear(); } else { results.AddRange(sources); } } } #endregion #region Method public virtual void Init() { } public virtual void Reset() { } #endregion #region Static Helper private static readonly string[] _QualityTexts = new string[] { "普通", "精良", "卓越", "稀世", "传说", "神话" }; public static string GetQualityText(int quality) { if (quality > 0 && quality < 7) { return _QualityTexts[quality - 1]; } return ""; } private static readonly Color[] _QualityColors = new Color[] { new Color32(0x7c, 0x82, 0x88, 255), new Color32(0x52, 0xb8, 0x7b, 255), new Color32(0x12, 0x8d, 0xff, 255), new Color32(0xa0, 0x44, 0xff, 255), new Color32(0xff, 0x67, 0x0b, 255), new Color32(0xff, 0x00, 0x00, 255) }; public static Color GetQualityColor(int quality) { if (quality > 0 && quality < 7) { return _QualityColors[quality - 1]; } return Color.gray; } public static string GetQualityColorString(int quality) { if (quality > 0 && quality < 7) { return ColorUtility.ToHtmlStringRGB(_QualityColors[quality - 1]); } return ColorUtility.ToHtmlStringRGB(Color.gray); } #endregion } }