using cfg; using asap.core; using System.Collections.Generic; using System.Linq; using UnityEngine; using game; using Script.RuntimeScript; using TMPro; namespace GameCore { public class ItemData { public int id; public ulong curCount; public int count; [System.NonSerialized] public ExchangeItemData exchangeItemData; public ItemData() { } public ItemData(int id, int count) { this.id = id; this.count = count; } } public class ExchangeItemData { public int exchangeId; public int exchangeCount; public ulong curCount; [System.NonSerialized] public ExchangeItemData nextExchangeItemData; } public class PlayerItemData { private cfg.Tables _tables; public PlayerItemData(cfg.Tables tables) { this._tables = tables; } void AddCurrency(int subType, float count) { switch (subType) { case 1: GContext.container.Resolve().SetEnergy(GContext.container.Resolve().Energy + (int)count); break; case 2: GContext.container.Resolve().AddGold((ulong)count); break; case 3: GContext.container.Resolve().SetPearl(GContext.container.Resolve().pearl + (int)count); break; case 4: GContext.container.Resolve().AddTurntableCoupon((int)count); break; case 5: GContext.container.Resolve().AddDiamond((int)count); break; case 6: GContext.container.Resolve().AddAdticket((int)count); break; case 9: GContext.container.Resolve().AddVoucher((int)count); break; } } void AddTokens(int subType, float count, int id) { switch (subType) { case 1: GContext.container.Resolve().SetLv(GContext.container.Resolve().lv + (int)count); break; case 3: //转盘积分 //GContext.container.Resolve().IncreaseScore((int)count); break; case 2: GContext.container.Resolve().AddVIPScore((int)count); break; case 7: //GContext.container.Resolve().AddPokerScore((int)count); break; case 5: //小玩法代币 //GContext.container.Resolve().AddPokerToken((int)count); break; case 11: //GContext.container.Resolve().AddPokerToken((int)count); break; case 12: GContext.container.Resolve().AddTicket((int)count); break; case 51: //1v1门票 GContext.container.Resolve().AddDuelTickets((int)count); break; case 52: GContext.container.Resolve().AddPVPToken((int)count); break; case 53: GContext.container.Resolve().ChainPackWithProgressMigrationData.AddToken((int)count); break; case 14: // 电池 GContext.container.Resolve().AddToken((int)count); break; case 15: // 魔药 GContext.container.Resolve().AddToken((int)count); break; case 16: // 弹珠 GContext.container.Resolve().AddToken((int)count); break; case 17: var bingoModel = GContext.container.Resolve(); if (bingoModel == null) Debug.LogWarning("[EventBingo] Try to add bingo token, but bingo model not found."); else bingoModel.AddTicket((int)count); break; } } void AddActivityTokens(int subType, float count, int id) { switch (subType) { case 1: GContext.container.Resolve().AddCollectingTarget(id, (int)count); break; case 2: GContext.container.Resolve().AddRankTarget(id, (int)count); break; case 11: GContext.container.Resolve().AddCollectingTarget((int)count); break; case 12: GContext.container.Resolve().AddRankTarget((int)count); break; case 13: GContext.container.Resolve().AddDigCount((int)count); break; } } ExchangeItemData AddRodItem(Item item, float count) { PlayerFishData playerFishData = GContext.container.Resolve(); ExchangeItemData exchangeItemData = null; switch (item.SubType) { case 1: exchangeItemData = playerFishData.AddNewRod(item.RedirectID, (int)count); break; case 2: playerFishData.AddRodPiece(item.ID, (int)count); break; case 3: playerFishData.UnlockSkin(item.RedirectID); break; case 4: break; case 11: playerFishData.UnlockGlove(item.RedirectID); break; } return exchangeItemData; } public void AddItemCount(int id, float count, ItemData itemData = null) { if (!_tables.TbItem.DataMap.ContainsKey(id)) { GameDebug.LogError($"[PlayerItemData]AddItemCount: Not found id({id}) in DataMap"); return; } Item item = _tables.TbItem.DataMap[id]; #if AGG using (var e = GEvent.GameEvent("item_change", gaSend: false)) { e.AddContent("item_id", id) .AddContent("state_info", "get") .AddContent("change_num", count); } #endif ExchangeItemData exchangeItemData = null; switch (item.Type) { case 1: AddCurrency(item.SubType, count); break; case 2: AddTokens(item.SubType, count, item.ID); break; case 3: exchangeItemData = AddRodItem(item, count); break; case 4: //if (item.SubType == 2) //{ // GContext.container.Resolve().AddTotalMastery(item.RedirectID, Mathf.RoundToInt(count)); //} if (item.SubType == 3) { exchangeItemData = GContext.container.Resolve().AddTotalCard(item.RedirectID, Mathf.RoundToInt(count)); } break; case 5: if (item.SubType == 1 || item.SubType == 2) { OnDropFishCard(item.SubType, item.RedirectID, id, (int)count); } break; case 6: if (item.SubType == 1) { //转盘积分 GContext.container.Resolve().IncreaseScore((int)count); } else if (item.SubType == 2) { //转盘免费次数 GContext.container.Resolve().AddFreecount((int)count); } break; case 7: if (item.SubType == 1) { //GContext.container.Resolve().AddMonthCardTime(item.RedirectID); } switch (item.SubType) { case 1: break; case 2: GContext.container.Resolve().SetVipUnlock(); break; case 3: GContext.container.Resolve().SetBPExp((int)count); break; case 4: case 5: case 6: GContext.container.Resolve().SetVipUnlock(item.SubType); break; default: break; } break; case 8: switch (item.SubType) { case 2: GContext.container.Resolve().AddTurntableCoupon((int)count); break; case 3: var data = GContext.container.Resolve(); if (data == null) Debug.LogWarning("Event luck magic is likely not available."); else data.AddTicket((int)count); break; default: EventLuckyGameModel.Get().AddTicket((int)count); break; } break; case 9: switch (item.SubType) { case 1: case 3: case 4: case 7: case 8: OnGetDropPackage(item.RedirectID, (int)count); break; case 6: OnGetDropPackage6(item.RedirectID, (int)count); break; //case 5: // OnGetPicturePackage(item.RedirectID, id, (int)count); // break; //TODO: 获取鱼箱 case 2: OnGetFishingBox(item.RedirectID, (int)count); break; } break; case 10: AddActivityTokens(item.SubType, count, item.RedirectID); break; case 11: if (item.SubType == 1) { GContext.container.Resolve().AddGlobalBuff(item.RedirectID); } break; //case 12: // GContext.container.Resolve().AddBenefitUpgrade((int)count, id); //break; case 13: switch (item.SubType) { case 2: var data = GContext.container.Resolve(); if (data != null) data.AddAmmo((int)count); else Debug.LogError("Trying to add ammo but event data is null. SUS"); break; case 3: var drillModel = GContext.container.Resolve(); if (drillModel == null) { Debug.Log($"[EventBreak] Trying to add gas but event break data is null. SUS"); break; } drillModel.AddTicket((int)count); break; case 11: // 刮刮乐 GContext.container.Resolve().AddToken((int)count); break; case 12: var canModel = GContext.container.Resolve(); if (canModel == null) { Debug.Log($"[EventCan] Trying to add gas but event can data is null. SUS"); break; } canModel.AddTicket((int)count); break; case 13: var eventGatherCoreData = GContext.container.Resolve(); if (eventGatherCoreData == null) { Debug.Log($"[EventGatherCore] Trying to add token but event gather core data is null. SUS"); break; } eventGatherCoreData.AddTicket((int)count); break; } break; } if (itemData != null) { itemData.exchangeItemData = exchangeItemData; } } void OnGetDropPackage6(int id, int count) { List itemDataGift = GetItemDataByDropIdAndType(id); for (int i = 0; i < itemDataGift.Count; i++) { itemDataGift[i].count *= count; } GContext.Publish(new ShowData(itemDataGift, RewardType.Normal)); AddItem(itemDataGift); } /// /// 直接打开虚拟背包 /// /// /// 随机鱼杆碎片、鱼杆 /// /// /// 直接打开虚拟背包,后续改为手提袋式钓箱 /// void OnGetDropPackage(int id, int count) { List itemDataGift = GetItemDropPackageItemList(id, count); GContext.Publish(new ShowData(itemDataGift, RewardType.Normal)); AddItem(itemDataGift); } /// /// 钓箱 /// void OnGetFishingBox(int itemID, int count) { GContext.container.Resolve().SetFishingBoxCount(itemID, count); if (count > 0) { GContext.Publish(new ShowData(new List() { new ItemData(itemID, count) }, RewardType.FishBoxOpen, 1)); } } // void OnGetPicturePackage(int id, int itemId, int count) // { //#if AGG // using (var e = GAEvent.GameEvent($"get_cardbox{id}")) // { // e.AddContent("itemId", itemId); // } //#endif // List itemDataGift = GetItemDropPackageItemList(id, count); // GContext.Publish(new ShowData(itemDataGift, RewardType.CardHolder, itemId)); // AddItem(itemDataGift); // } void OnDropFishCard(int subType, int id, int itemId, int count) { List itemDataGifts = new List(); List countByQuality; List> fishCardQuality; MapData mapData; PlayerFishData playerFishData = GContext.container.Resolve(); for (int j = 0; j < count; j++) { List itemDataGift = new List(); if (subType != 1) { GeneralCardWeight generalCardWeight = _tables.TbGeneralCardWeight.GetOrDefault(id); if (generalCardWeight == null) { GameDebug.LogError($"[PlayerItemData]OnDropFishCard: Not found id({itemId}) in TbGeneralCardWeight"); return; } countByQuality = generalCardWeight.CountByQuality; fishCardQuality = new List>(); int currentMapId = GContext.container.Resolve().currentMapId; //当前地图 var currentMap = _tables.TbMapData.GetOrDefault(currentMapId); int lv = GContext.container.Resolve().lv; var lastMapData = _tables.TbMapData.GetOrDefault(GContext.container.Resolve().lastMapId); //非当前地图 var dataList = new List(); var mapDataList = _tables.TbMapData.DataList; int allWeight = generalCardWeight.Weight.Sum(); for (int i = 0; i < mapDataList.Count; i++) { if (mapDataList[i].ID != currentMapId) { dataList.Add(mapDataList[i]); } if (mapDataList[i].ID == lastMapData.ID) { break; } } for (int f = 0; f < countByQuality.Count; f++) { int random = Random.Range(0, allWeight); if (random < generalCardWeight.Weight[0] || dataList.Count == 0) { //当前地图 mapData = currentMap; } else { //非当前地图 mapData = dataList[Random.Range(0, dataList.Count)]; } fishCardQuality.Add(mapData.FishCardList[f]); } } else { var fishCardData = _tables.TbFishCardDrop.GetOrDefault(id); if (fishCardData == null) { GameDebug.LogError($"[PlayerItemData]OnDropFishCard: Not found id({id}) in TbFishCardDrop"); return; } mapData = _tables.TbMapData.GetOrDefault(fishCardData.MapID); countByQuality = fishCardData.CountByQuality; fishCardQuality = mapData.FishCardList; } for (int i = 0; i < fishCardQuality.Count; i++) { if (countByQuality[i] > 0) { int fishCardId = fishCardQuality[i][Random.Range(0, fishCardQuality[i].Count)]; ulong curTotalCard = (ulong)playerFishData.GetCardDataProficiency(fishCardId); itemDataGift.Add(new ItemData() { id = fishCardId, curCount = curTotalCard, count = countByQuality[i], }); } } if (itemDataGift.Count > 0) { DropFishCardData dropFishCardData = new DropFishCardData(); dropFishCardData.FishCardItemList = itemDataGift; dropFishCardData.ItemID = itemId; itemDataGifts.Add(dropFishCardData); AddItem(itemDataGift); ItemData exchangeItemData = new ItemData(); for (int i = itemDataGift.Count - 1; i >= 0; i--) { if (itemDataGift[i].exchangeItemData != null) { exchangeItemData.id = itemDataGift[i].exchangeItemData.exchangeId; exchangeItemData.count += itemDataGift[i].exchangeItemData.exchangeCount; exchangeItemData.curCount = itemDataGift[i].exchangeItemData.curCount; } } if (exchangeItemData.id > 0) { dropFishCardData.exchangeItemData = exchangeItemData; } } } if (itemDataGifts.Count > 0) { GContext.Publish(new ShowData(itemDataGifts)); } #if AGG using (var e = GEvent.GameEvent("item_change", gaSend: false)) { e.AddContent("item_id", id) .AddContent("state_info", "cost") .AddContent("change_num", count); } #endif } public List GetItemDropPackageItemList(int id, int count) { ItemDropPackage itemDropPackage = _tables.TbItemDropPackage[id]; List dropIdList = itemDropPackage.DropList; List itemDataList = new List(); foreach (var t in dropIdList) { itemDataList.AddRange(GetItemDataByDropIdAndType(t)); } for (int i = 0; i < itemDataList.Count; i++) { itemDataList[i].count *= count; } return itemDataList; } /// /// /// /// /// /// 0:重复奖励合并1:重复奖励不合并 /// stash == true 卡包展示存到临时背包 /// isShow == true && stash == true 存到临时背包 /// public List AddItemByDropList(List dropIDList, bool isShow = true, int scope = 0, RewardType rewardType = RewardType.Normal) { if (dropIDList == null || dropIDList.Count == 0) { return null; } List itemDataList = new List(); foreach (var t in dropIDList) { List itemDatas = GetItemDataByDropIdAndType(t); if (itemDatas != null && itemDatas.Count > 0) { itemDataList.AddRange(itemDatas); } } //itemDataList不需要重复合并 if (itemDataList.Count == 0) { return null; } if (scope == 0) { List newData = new List(); Dictionary map = new Dictionary(); ItemData itemData; //itemDataList重复合并 for (int i = 0; i < itemDataList.Count; i++) { itemData = itemDataList[i]; if (map.ContainsKey(itemData.id)) { map[itemData.id] += itemData.count; } else { map[itemData.id] = itemData.count; } } foreach (var item in map) { ItemData itemData1 = new ItemData() { id = item.Key, count = item.Value }; itemData1.curCount = (ulong)GetItemCount(itemData1.id); newData.Add(itemData1); } itemDataList = newData; } if (isShow) { GContext.Publish(new ShowData(itemDataList, rewardType)); } AddItem(itemDataList); return itemDataList; } /// /// Get ItemData by drop list, merging same items if necessary. /// /// /// List of items, merged. public List GetItemDataByDropList(List dropIDList) { if (dropIDList == null || dropIDList.Count == 0) { return new List(); } var itemDataList = new List(); foreach (var itemDatas in dropIDList.Select(t => GetItemDataByDropIdAndType(t)).Where(itemDatas => itemDatas is { Count: > 0 })) { itemDataList.AddRange(itemDatas); } //itemDataList不需要重复合并 if (itemDataList.Count == 0) { return null; } var map = new Dictionary(); //itemDataList重复合并 foreach (var itemData in itemDataList) { if (map.ContainsKey(itemData.id)) { map[itemData.id] += itemData.count; } else { map[itemData.id] = itemData.count; } } var newData = new List(); foreach (var item in map) { ItemData itemData1 = new ItemData() { id = item.Key, count = item.Value }; itemData1.curCount = (ulong)GetItemCount(itemData1.id); newData.Add(itemData1); } // AddItem(newData); return newData; } /// /// /// /// /// /// /// stash == true 卡包展示存到临时背包 /// isShow == true && stash == true 存到临时背包 /// public List AddItemByDrop(int dropID, bool isShow = true, RewardType rewardType = RewardType.Normal) { List itemDataList = GetItemDataByDropIdAndType(dropID); if (itemDataList != null) { if (isShow) { GContext.Publish(new ShowData(itemDataList, rewardType)); } AddItem(itemDataList); } return itemDataList; } /// /// 分批获得的时候,卡包合并开启 /// /// /// public void AddItem(List itemDataList) { Dictionary cardItemDataList = new Dictionary(); foreach (var itemData in itemDataList) { if (!_tables.TbItem.DataMap.ContainsKey(itemData.id)) { GameDebug.LogError($"[PlayerItemData]AddItem: Not found id({itemData.id}) in DataMap"); continue; } Item item = _tables.TbItem.DataMap[itemData.id]; if (item.Type == 5) { if (cardItemDataList.ContainsKey(itemData.id)) { cardItemDataList[itemData.id] += itemData.count; } else { cardItemDataList.Add(itemData.id, itemData.count); } continue; } AddItemCount(itemData.id, itemData.count, itemData); } if (cardItemDataList.Count > 0) { foreach (var item in cardItemDataList) { ItemData itemData = new ItemData() { id = item.Key, count = item.Value }; itemData.curCount = (ulong)GetItemCount(item.Key); AddItemCount(itemData.id, itemData.count, itemData); } } } public void AddItem(ItemData itemData) { AddItemCount(itemData.id, itemData.count, itemData); } public double GetItemCount(int itemID) { Item item = _tables.TbItem.GetOrDefault(itemID); if (item == null) { GameDebug.LogError($"[PlayerItemData]GetItemCount: Not found item with ID({itemID})"); return 0; } return GetItemCount(item); } public double GetItemCount(Item item, float defaultCount = 0) { switch (item.Type) { case 1: switch (item.SubType) { case 1: return GContext.container.Resolve().Energy; case 2: return GContext.container.Resolve().gold; case 3: return GContext.container.Resolve().pearl; case 4: return GContext.container.Resolve().TurntableCoupon; case 5: return GContext.container.Resolve().diamond; case 6: return GContext.container.Resolve().GetAdticketCount(); //case 9: // return GContext.container.Resolve().GetVoucher(); } break; case 2: switch (item.SubType) { case 1: return GContext.container.Resolve().lv; case 2: return GContext.container.Resolve().vipScore; case 5: case 11: //猜玩法代币通用代币 //return GContext.container.Resolve().GetPokerToken(); case 12: return GContext.container.Resolve().TicketCount; case 51: //1v1门票 return GContext.container.Resolve().GetDuelTickets(); case 52: return GContext.container.Resolve().PVPToken; case 53: return GContext.container.Resolve().ChainPackWithProgressMigrationData.TokenProgress; case 14: // 电池 return GContext.container.Resolve().GetToken(); case 15: // 魔药 return GContext.container.Resolve().GetToken(); case 16: // 弹珠 return GContext.container.Resolve().GetToken(); case 17: var bingoModel = GContext.container.Resolve(); if (bingoModel == null || !bingoModel.IsActivated) { Debug.LogWarning("[EventBingo] Try to get bingo token, but bingo model not found or not activated."); return 0; } else return GContext.container.Resolve().TicketCount; } break; case 3: switch (item.SubType) { case 1: return GContext.container.Resolve().GetRodPiece(item.RedirectID); case 2: return GContext.container.Resolve().GetRodPiece(item.ID); } break; case 4: if (item.SubType == 2) { return GContext.container.Resolve().GetCardDataProficiency(item.RedirectID); } break; case 5: return 0;//ntext.container.Resolve().GetPictureProgress(id); case 6: var _fishingEventData = GContext.container.Resolve(); if (item.SubType == 1) { return _fishingEventData.GetWheelLevelCount(_fishingEventData.wheelLevel.Level); } break; case 7: var bpDataProvider = GContext.container.Resolve(); if (item.SubType == 3) return bpDataProvider.Data.BattlePassRecord.Exp; break; case 8: if (item.SubType == 2) return GContext.container.Resolve().TurntableCoupon; if (item.SubType == 3) { var data = GContext.container.Resolve(); if (data == null) { Debug.LogWarning("It is very likely that event luck magic is not available at this time."); return 0; } return data.TicketCount; } return EventLuckyGameModel.Get().TicketCount; case 9: if (item.SubType == 2) { return GContext.container.Resolve().GetFishingBoxCount(item.RedirectID); } else { return 0; } case 10: switch (item.SubType) { case 1: case 11: return GContext.container.Resolve().GetAllCollectingTarget(); case 2: case 12: return GContext.container.Resolve().GetAllRankTarget(); case 13: return GContext.container.Resolve().DataModel.GetDigCount(); } break; case 13: // var handler = EventBreakAct.DrillModel; var drillModel = GContext.container.Resolve(); switch (item.SubType) { case 2: return GContext.container.Resolve().AmmoCount; case 3: if (drillModel == null) return defaultCount; return drillModel.TicketCount; case 6: if (drillModel == null || drillModel.TaskInfoList == null || drillModel.TaskInfoList.Length <= 0) return defaultCount; return drillModel.TaskInfoList[0].CurrentGemProgress; case 5: if (drillModel == null || drillModel.TaskInfoList == null || drillModel.TaskInfoList.Length <= 1) return defaultCount; return drillModel.TaskInfoList[1].CurrentGemProgress; case 4: if (drillModel == null || drillModel.TaskInfoList == null || drillModel.TaskInfoList.Length <= 2) return defaultCount; return drillModel.TaskInfoList[2].CurrentGemProgress; case 11: // 刮刮乐 return GContext.container.Resolve().GetToken(); } break; default: GameDebug.LogWarning( $"[PlayerItemData]GetItemCount: Item ID({item.ID}) type({item.Type}) subType({item.SubType}) not handled"); break; } return defaultCount; } public void ItemTransition(ItemData itemData) { FishingEvent fishingEvent; FishingEventData fishingEventData = GContext.container.Resolve(); if (itemData.id == 2005) { fishingEvent = fishingEventData.GetEventTable(4); Item4ToEventItem(fishingEvent, itemData); } else if (itemData.id == 2050) { fishingEvent = fishingEventData.GetEventTable(5); Item5ToEventItem(fishingEvent, itemData); } else if (itemData.id == 70000) { fishingEvent = fishingEventData.GetEventTable(7); Item7ToEventItem(fishingEvent, itemData); } else if (itemData.id == 8000000) { fishingEvent = fishingEventData.GetEventTable(8); Item8ToEventItem(fishingEvent, itemData); } if (itemData.id == 101000000) { itemData.id = fishingEventData.collectingTargetInitTokenID; } //可能其他转换成1002 然后吃加成 if (itemData.id == 1002) { itemData.count = GetExtraCoinMag(itemData.count); } itemData.curCount = (ulong)GetItemCount(itemData.id); } void ItemTransition(ItemData itemData, int ExchangeRate, int ItemId) { itemData.count = Mathf.RoundToInt(itemData.count / (float)ExchangeRate); if (itemData.count < 1) { itemData.count = 1; } itemData.id = ItemId; } void Item4ToEventItem(FishingEvent fishingEvent, ItemData itemData) { FishingEventCycleItem cycle; if (fishingEvent != null) { if (fishingEvent.Type == 4) { cycle = _tables.TbFishingEventCycleItem.DataList .Find(x => x.Type == fishingEvent.Type && x.SubType == fishingEvent.SubType && x.RedirectID == fishingEvent.RedirectID); if (cycle != null) { ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId); return; } } } //没有活动时默认转换 cycle = _tables.TbFishingEventCycleItem.DataList[0]; if (cycle != null) { itemData.count *= 1000; ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId); return; } } void Item5ToEventItem(FishingEvent fishingEvent, ItemData itemData) { PvpEventCycleItem cycle; if (fishingEvent != null) { if (fishingEvent.Type == 5) { cycle = _tables.TbPvpEventCycleItem. DataList.Find(x => x.Type == fishingEvent.Type && x.SubType == fishingEvent.SubType); if (cycle != null) { ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId); return; } } } //没有活动时默认转换 cycle = _tables.TbPvpEventCycleItem.DataList[0]; if (cycle != null) { itemData.count *= 1000; ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId); return; } } void Item7ToEventItem(FishingEvent fishingEvent, ItemData itemData) { FishingEventCycleItem2 cycle; if (fishingEvent != null) { if (fishingEvent.Type == 7) { cycle = _tables.TbFishingEventCycleItem2.GetOrDefault(fishingEvent.RedirectID); if (cycle != null) { ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId); return; } } } //没有活动时默认转换 cycle = _tables.TbFishingEventCycleItem2.DataList[0]; if (cycle != null) { itemData.count *= 1000; ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId); return; } } void Item8ToEventItem(FishingEvent fishingEvent, ItemData itemData) { FishingEventCycleItem3 cycle; if (fishingEvent != null) { if (fishingEvent.Type == 8) { cycle = _tables.TbFishingEventCycleItem3.GetOrDefault(fishingEvent.RedirectID); if (cycle != null) { ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId); return; } } } //没有活动时默认转换 cycle = _tables.TbFishingEventCycleItem3.DataList[0]; if (cycle != null) { itemData.count *= 1000; ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId); return; } } public ItemData GetItemDataOne(int dropId, int index = 0) { DropPackageList dropPackageList = _tables.TbDrop.GetOrDefault(dropId)?.DropList; if (dropPackageList == null) { GameDebug.LogError("null dropID" + dropId); return null; } int len = dropPackageList.DropIDList.Count; int len2 = dropPackageList.DropCountList.Count; if (len != len2) { if (len > len2) { len = len2; } Debug.LogError($"[PlayerItemData]GetItemDataByDropIdAndType: DropPackageList count not equal [DropId]=={dropId}"); } if (index >= len) { return null; } ItemData itemData = new ItemData() { id = dropPackageList.DropIDList[index], count = dropPackageList.DropCountList[index] }; ItemTransition(itemData); return itemData; } /// /// 处理有选定地图鱼卡的情况 /// /// public List GetItemDataByDropId(int dropId, int mapId = -1, bool afterAdding = false) { DropPackageList dropPackageList = _tables.TbDrop.GetOrDefault(dropId)?.DropList; if (dropPackageList == null) { GameDebug.LogError("null dropID" + dropId); return null; } List itemDataList = new List(); int len = dropPackageList.DropIDList.Count; int len2 = dropPackageList.DropCountList.Count; if (len != len2) { if (len > len2) { len = len2; } Debug.LogError($"[PlayerItemData]GetItemDataByDropId: DropPackageList count not equal [DropId]=={dropId}"); } for (int i = 0; i < len; i++) { var itemID = dropPackageList.DropIDList[i]; if (mapId > 0) { var item = _tables.TbItem.GetOrDefault(itemID); if (item.Type == 5 && item.SubType == 4) { itemID = GetFishCardItemIdByRedirectIDAndMapId(item.RedirectID - 1, mapId); } } ItemData itemData = new ItemData() { id = itemID, count = dropPackageList.DropCountList[i] }; ItemTransition(itemData); if (afterAdding && itemData.curCount >= (ulong)itemData.count) { itemData.curCount -= (ulong)itemData.count; } itemDataList.Add(itemData); } return itemDataList; } public int GetExtraCoinMag(float number) { PlayerData playerData = GContext.container.Resolve(); float mg = (1 + playerData.benefitsCashMag) * (1 + playerData.benefitsCashMagLimited); return Mathf.RoundToInt(number * mg); } public float ExtraCoinMag() { PlayerData playerData = GContext.container.Resolve(); float mg = (1 + playerData.benefitsCashMag) * (1 + playerData.benefitsCashMagLimited); return mg; } //获取地图的加成 //public float GetExtraCoinMag() //{ // float ExtraCoinMag = 0; // //地图加成 // MapData data = _tables.TbMapData.GetOrDefault(GContext.container.Resolve().lastMapId); // if (data != null) // { // ExtraCoinMag = data.CashMag; // } // //float mcCoinMag = GContext.container.Resolve().GetPrivilege2(); // //ExtraCoinMag += mcCoinMag; // return ExtraCoinMag; //} public List GetItemDataByDropIdAndType(int dropId, int mapId = -1) { List itemDataList = new List(); Drop drop = _tables.TbDrop.GetOrDefault(dropId); if (drop == null) { GameDebug.LogError("null dropID" + dropId); return null; } DropPackageList dropList = drop.DropList; int len = dropList.DropIDList.Count; int len2 = dropList.DropCountList.Count; int len3 = dropList.DropProbList.Count; if (len != len2 || len2 != len3) { Debug.LogError($"[PlayerItemData] DropPackageList count not equal [DropId]=={dropId} DropIDList=={len} DropCountList=={len2} DropProbList=={len3}"); if (len2 < len) { len = len2; } if (len3 < len) { len = len3; } } if (drop.Type == DropType.Probability) { Dictionary itemDataSubList = new Dictionary(); for (int i = 0; i < len; i++) { if (Mathf.Ceil(dropList.DropProbList[i] * 100) >= Random.Range(0, 100) - 0.00001f) { if (itemDataSubList.ContainsKey(dropList.DropIDList[i])) { itemDataSubList[dropList.DropIDList[i]] += dropList.DropCountList[i]; } else { itemDataSubList.Add(dropList.DropIDList[i], dropList.DropCountList[i]); } } } foreach (var itemDataSub in itemDataSubList) { itemDataList.Add(new ItemData() { id = itemDataSub.Key, count = itemDataSub.Value }); } } else if (drop.Type == DropType.Weight) { float totalSum = dropList.DropProbList.Sum(); float random = Random.Range(0, totalSum); float sum = 0; for (int i = 0; i < len; i++) { sum += dropList.DropProbList[i]; if (random <= sum - 0.00001f) { itemDataList.Add(new ItemData() { id = dropList.DropIDList[i], count = dropList.DropCountList[i] }); break; } } } else { for (int i = 0; i < len; i++) { itemDataList.Add(new ItemData() { id = dropList.DropIDList[i], count = dropList.DropCountList[i] }); } } for (int i = 0; i < itemDataList.Count; i++) { if (mapId > 0) { var item = _tables.TbItem.GetOrDefault(itemDataList[i].id); if (item.Type == 5 && item.SubType == 4) { itemDataList[i].id = GetFishCardItemIdByRedirectIDAndMapId(item.RedirectID - 1, mapId); } } ItemTransition(itemDataList[i]); } return itemDataList; } public async void ShowItemTips(int id, Transform trans, float count = -1) { //物品详情弹窗 Item item = _tables.TbItem.GetOrDefault(id); if (item.Type == 9 && (item.SubType == 7 || item.SubType == 8)) { try { ItemDropPackage itemDropPackage = _tables.TbItemDropPackage[item.RedirectID]; List dropIdList = itemDropPackage.DropList; if (item.SubType == 7) { item_sanddig_tips.Show(trans.position, dropIdList[0]); } else if (item.SubType == 8) { item_sanddig_tips.Show(trans.position, dropIdList); } } catch (System.Exception e) { Debug.LogError($"[PlayerItemData]ShowItemTips: Error showing sand dig tips for item ID {id}: {e.Message}"); } } else if (item.Type == 12) { GameObject go = await UIManager.Instance.ShowUI(UITypes.PlayerGradeBenefitInfoPopupPanel); PlayerGradeBenefitInfoPopupPanel panel = go.GetComponent(); panel.Init(item, Mathf.RoundToInt(count)); } else if (item.Type == 11 && item.SubType == 1) { var buff = _tables.TbFishBuff.GetOrDefault(item.RedirectID); GameObject go = await UIManager.Instance.ShowUI(UITypes.FishingBuffInfoPopupPanel); FishingBuffInfoPopupPanel fishingBuffInfoPopupPanel = go.GetComponent(); fishingBuffInfoPopupPanel.InitPanel(buff); } else { var curCount = GetItemCount(item, -1); if (curCount > -0.5f) { item_tips _item_tips = await item_tips.Show(); if (_item_tips == null /*|| trans.gameObject.GetInstanceID() == _item_tips.clickInstanceID*/) { return; } _item_tips.Init(trans.gameObject.GetInstanceID(), trans.position, item, curCount); } } } public List ShowItemDropPackage(ItemDropPackage itemDropPackage) { var ItemDisplay = itemDropPackage.ItemDisplay; List CountDisplay = new List(itemDropPackage.CountDisplay); for (int i = 0; i < ItemDisplay.Count; i++) { if (ItemDisplay[i] == 1002) { string[] strings = CountDisplay[i].Split('-'); if (strings.Length != 2) { if (float.TryParse(strings[0], out float ab)) { ab = GetExtraCoinMag(ab); CountDisplay[i] = ConvertTools.GetNumberString((int)ab); } continue; } if (!float.TryParse(strings[0], out float a) || !float.TryParse(strings[1], out float b)) { continue; } a = GetExtraCoinMag(a); b = GetExtraCoinMag(b); CountDisplay[i] = $"{ConvertTools.GetNumberString((int)a)}-{ConvertTools.GetNumberString((int)b)}"; } } return CountDisplay; } public int GetFishCardItemIdByRedirectIDAndMapId(int index, int mapID) { var cardList = _tables.TbMapData.GetOrDefault(mapID).FishCardItemList; var fishCardId = cardList[index]; return fishCardId; } public int GetFishCardItemIdByItemIDAndMapId(int itemID, int mapID) { Item item = _tables.TbItem.GetOrDefault(itemID); return GetFishCardItemIdByRedirectIDAndMapId(item.RedirectID - 1, mapID); } /// /// Get iap item list and text price string by iap id. /// /// /// /// public void ResolveIapId(in int iapId, out IAPItemList iapItemList, out string price) { var doesIapExist = _tables.TbIAPItemList.DataMap.TryGetValue(iapId, out iapItemList); if (!doesIapExist) { Debug.LogError($"IapId {iapId} not found in iap list."); price = ""; return; } var sdde = new SKUDetailDataEvent(iapItemList); GContext.Publish(sdde); price = sdde.price; } /// /// Get iap item list and set text price by iap id. /// /// /// /// public void ResolveIapId(in int iapId, out IAPItemList iapItemList, TMP_Text textPrice) { var doesIapExist = _tables.TbIAPItemList.DataMap.TryGetValue(iapId, out iapItemList); if (!doesIapExist) { Debug.LogError($"IapId {iapId} not found in iap list."); textPrice.text = ""; return; } var sdde = new SKUDetailDataEvent(iapItemList); GContext.Publish(sdde); textPrice.text = sdde.price; } public ItemData GetRandomItemDataByDropId(System.Random rng, int dropId, int mapId = -1) { Drop drop = _tables.TbDrop.GetOrDefault(dropId); if (drop == null) { GameDebug.LogError("null dropID" + dropId); return null; } DropPackageList dropList = drop.DropList; var itemData = new ItemData() { id = dropList.DropIDList[0], count = dropList.DropCountList[0] };// Just in case. int len = dropList.DropIDList.Count; int len2 = dropList.DropCountList.Count; int len3 = dropList.DropProbList.Count; if (len != len2 || len2 != len3) { Debug.LogError($"[PlayerItemData] DropPackageList count not equal [DropId]=={dropId} DropIDList=={len} DropCountList=={len2} DropProbList=={len3}"); if (len2 < len) { len = len2; } if (len3 < len) { len = len3; } } if (drop.Type == DropType.Weight) { float totalSum = dropList.DropProbList.Sum(); // float random = Random.Range(0, totalSum); float random = (float)rng.NextDouble() * totalSum; float sum = 0; for (int i = 0; i < len; i++) { sum += dropList.DropProbList[i]; if (random <= sum - 0.00001f) { itemData = new ItemData() { id = dropList.DropIDList[i], count = dropList.DropCountList[i] }; break; } } } else { Debug.Log($"[PlayerItemData] Drop id {dropId} is not a drop with weight. This is likely a wrong call."); return null; } if (mapId > 0) { var item = _tables.TbItem.GetOrDefault(itemData.id); if (item.Type == 5 && item.SubType == 4) { itemData.id = GetFishCardItemIdByRedirectIDAndMapId(item.RedirectID - 1, mapId); } } ItemTransition(itemData); return itemData; } } public class DropFishCardData { public int ItemID; public ItemData exchangeItemData; public List FishCardItemList; } }