Files
MinFt/Client/Assets/Scripts/DataCenter/DataCenter.PlayerItemData.cs
2026-04-27 12:07:32 +08:00

1560 lines
60 KiB
C#

using cfg;
using asap.core;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using game;
using TMPro;
using System;
using GameCore.Events;
namespace GameCore
{
public class ItemData
{
public int id;
public ulong curCount;
public int count;
[System.NonSerialized]
public int origin;
[System.NonSerialized]
public float inflate;
[System.NonSerialized]
public ExchangeItemData exchangeItemData;
[System.NonSerialized]
public ChangeSource changeSource;
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 partial 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<PlayerData>().SetEnergy(GContext.container.Resolve<PlayerData>().Energy + (int)count);
break;
case 2:
if (count > 0)
{
GContext.container.Resolve<PlayerData>().AddGold((ulong)count);
}
break;
case 3:
GContext.container.Resolve<PlayerData>().SetPearl(GContext.container.Resolve<PlayerData>().pearl + (int)count);
break;
case 4:
GContext.container.Resolve<FishingEventData>().AddTurntableCoupon((int)count);
break;
case 5:
GContext.container.Resolve<PlayerData>().AddDiamond((int)count);
break;
case 6:
GContext.container.Resolve<PlayerShopData>().AddAdticket((int)count);
break;
case 9:
GContext.container.Resolve<PlayerShopData>().AddVoucher((int)count);
break;
}
}
void AddTokens(int subType, float count, int id)
{
switch (subType)
{
case 1:
GContext.container.Resolve<PlayerData>().SetLv(GContext.container.Resolve<PlayerData>().lv + (int)count);
break;
case 3:
//转盘积分
//GContext.container.Resolve<FishingEventData>().IncreaseScore((int)count);
break;
case 2:
GContext.container.Resolve<PlayerData>().AddVIPScore((int)count);
break;
case 7:
//GContext.container.Resolve<PokerScoreData>().AddPokerScore((int)count);
break;
case 5:
//小玩法代币
//GContext.container.Resolve<SmallGameData>().AddPokerToken((int)count);
break;
case 11:
//GContext.container.Resolve<SmallGameData>().AddPokerToken((int)count);
break;
case 12:
break;
// break;
// case 18:
// break;
// break;
// //1v1门票
// GContext.container.Resolve<FishingEventData>().AddDuelTickets((int)count);
// break;
// GContext.container.Resolve<FishingEventData>().AddPVPToken((int)count);
// break;
// break;
// // 魔药
// break;
// // 弹珠
// break;
// if (bingoModel == null)
// Debug.LogWarning("[EventBingo] Try to add bingo token, but bingo model not found.");
// else
// bingoModel.AddTicket((int)count);
// break;
// break;
// eventOfferJourneyData?.AddTicket((int)count);
// break;
// break;
// break;
}
}
void AddActivityTokens(int subType, float count, int id)
{
switch (subType)
{
case 1:
GContext.container.Resolve<FishingEventData>().AddCollectingTarget(id, (int)count);
break;
case 2:
GContext.container.Resolve<FishingEventData>().AddRankTarget(id, (int)count);
break;
case 11:
GContext.container.Resolve<FishingEventData>().AddCollectingTarget((int)count);
break;
case 12:
GContext.container.Resolve<FishingEventData>().AddRankTarget((int)count);
break;
// break;
}
}
ExchangeItemData AddRodItem(Item item, float count)
{
PlayerFishData playerFishData = GContext.container.Resolve<PlayerFishData>();
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, ChangeSource changeSource, 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 (changeSource != null)
//{
// Debug.Log($"item_change_source Group : {changeSource.Source_Group} Type : {changeSource.Source_Type} Module : {changeSource.Source_Module}");
//}
#if AGG
using (var e = GEvent.GameEvent("item_change", gaSend: true))
{
e.AddContent("item_id", id)
.AddContent("state_info", "get")
.AddContent("change_num", count);
if (id == 1001 && itemData != null)
{
e.AddContent("hook_origin", itemData.origin);
}
if (changeSource != null)
{
e.AddContent("Source_EventId", changeSource.Source_EventId)
.AddContent("Source_Group", changeSource.Source_Group)
.AddContent("Source_Type", changeSource.Source_Type)
.AddContent("Source_Module", changeSource.Source_Module);
}
}
#endif
// 发布物品添加事件,活动系统会通过配置表自动处理代币添加
GContext.Publish(new ItemAddedEvent
{
ItemId = item.ID,
ItemType = (int)item.Type,
ItemSubType = (int)item.SubType,
Count = (int)count
});
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<PlayerFishData>().AddTotalMastery(item.RedirectID, Mathf.RoundToInt(count));
//}
if (item.SubType == 3)
{
exchangeItemData = GContext.container.Resolve<PlayerFishData>().AddTotalCard(item.RedirectID, Mathf.RoundToInt(count));
}
// if (item.SubType == 8)
// {
// }
// if (item.SubType == 11)
// {
// }
break;
case 5:
if (item.SubType == 1 || item.SubType == 2)
{
AddFishCardData(new ItemData(id, (int)count));
GContext.Publish(new ShowData(RewardType.CardHolder));
//OnDropFishCard(item.SubType, item.RedirectID, id, (int)count);
}
break;
case 6:
if (item.SubType == 1)
{
//转盘积分
GContext.container.Resolve<FishingEventData>().IncreaseScore((int)count);
}
else if (item.SubType == 2)
{
//转盘免费次数
GContext.container.Resolve<FishingEventData>().AddFreecount((int)count);
}
// else
// {
// }
break;
case 7:
if (item.SubType == 1)
{
//GContext.container.Resolve<MonthCardDataConter>().AddMonthCardTime(item.RedirectID);
}
switch (item.SubType)
{
case 1:
break;
case 2:
GContext.container.Resolve<BattlePassDataProvider>().SetVipUnlock();
break;
case 3:
GContext.container.Resolve<BattlePassDataProvider>().SetBPExp((int)count);
break;
//case 4:
//case 5:
//case 6:
// break;
// break;
}
break;
case 8:
switch (item.SubType)
{
case 2:
GContext.container.Resolve<FishingEventData>().AddTurntableCoupon((int)count);
break;
// if (data == null)
// Debug.LogWarning("Event luck magic is likely not available.");
// else
// data.AddTicket((int)count);
// break;
// break;
}
break;
case 9:
switch (item.SubType)
{
case 1:
case 3:
case 4:
OnGetDropPackage(item.RedirectID, (int)count, itemData?.inflate ?? 0, changeSource);
break;
case 7:
OnGetDropPackage7(item.RedirectID, (int)count, itemData?.inflate ?? 0, changeSource);
break;
case 8:
OnGetDropPackage8(item.RedirectID, (int)count, itemData?.inflate ?? 0, changeSource);
break;
case 6:
OnGetDropPackage6(item.RedirectID, (int)count, changeSource);
break;
//case 5:
// OnGetPicturePackage(item.RedirectID, id, (int)count);
// break;
//TODO: 获取鱼箱
case 2:
OnGetFishingBox(item.RedirectID, (int)count);
break;
case 9:
OnGetDropPackage9(item, (int)count, itemData?.inflate ?? 0, changeSource);
break;
}
break;
case 10:
AddActivityTokens(item.SubType, count, item.RedirectID);
break;
case 11:
if (item.SubType == 1)
{
GContext.container.Resolve<BuffDataCenter>().AddGlobalBuff(item.RedirectID);
}
break;
//case 12:
// GContext.container.Resolve<PlayerData>().AddBenefitUpgrade((int)count, id);
//break;
// switch (item.SubType)
// {
// case 2:
// if (data != null)
// data.AddAmmo((int)count);
// else
// Debug.LogError("Trying to add ammo but event data is null. SUS");
// break;
// case 3:
// 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:
// // 刮刮乐
// break;
// case 12:
// 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:
// if (eventGatherCoreData == null)
// {
// Debug.Log($"[EventGatherCore] Trying to add token but event gather core data is null. SUS");
// break;
// }
// eventGatherCoreData.AddTicket((int)count);
// break;
// case 14:
// break;
// }
// break;
// switch (item.SubType)
// {
// case 3:
// break;
// case 2:
// break;
// case 5:
// socialRushArc?.AddProgress((int)count);
// break;
// }
// break;
}
if (itemData != null)
{
itemData.exchangeItemData = exchangeItemData;
}
}
void OnGetDropPackage6(int id, int count, ChangeSource changeSource)
{
List<ItemData> itemDataGift = GetItemDataByDropIdAndType(id);
for (int i = 0; i < itemDataGift.Count; i++)
{
itemDataGift[i].count *= count;
}
GContext.Publish(new ShowData(itemDataGift, RewardType.Normal));
AddItem(itemDataGift, changeSource);
}
/// <summary>
/// 直接打开
/// </summary>
/// <summary>
/// 随机鱼杆碎片、鱼杆
/// </summary>
void OnGetDropPackage(int id, int count, float inflate, ChangeSource changeSource)
{
List<ItemData> itemDataGift = GetItemDropPackageItemList(id, count);
LureInflation(itemDataGift, inflate);
GContext.Publish(new ShowData(itemDataGift, RewardType.Normal));
AddItem(itemDataGift, changeSource);
}
void OnGetDropPackage7(int redirectID, int count, float inflate, ChangeSource changeSource)
{
List<ItemData> itemDataGift = GetItemDropItemList(redirectID, count);
LureInflation(itemDataGift, inflate);
GContext.Publish(new ShowData(itemDataGift, RewardType.Normal));
AddItem(itemDataGift, changeSource);
}
void OnGetDropPackage8(int redirectID, int count, float inflate, ChangeSource changeSource)
{
List<ItemData> itemDataGift = GetItemDataByDropIdAndType(redirectID);
for (int i = 1; i < count; i++)
{
itemDataGift.AddRange(GetItemDataByDropIdAndType(redirectID));
}
LureInflation(itemDataGift, inflate);
GContext.Publish(new ShowData(itemDataGift, RewardType.Normal));
AddItem(itemDataGift, changeSource);
}
void OnGetDropPackage9(Item item, int count, float inflate, ChangeSource changeSource)
{
if (item == null) return;
var itemClick = _tables.TbItemClick.GetOrDefault(item.ID);
if (itemClick != null)
{
GContext.Publish<ItemClick>(itemClick);
}
List<ItemData> itemDataGift = GetItemDropItemList(item.RedirectID, count);
if (changeSource != null)
{
for (int i = 0; i < itemDataGift.Count; i++)
{
itemDataGift[i].changeSource = changeSource;
}
}
LureInflation(itemDataGift, inflate);
}
/// <summary>
/// 钓箱
/// </summary>
void OnGetFishingBox(int itemID, int count)
{
GContext.container.Resolve<FishingBoxData>().SetFishingBoxCount(itemID, count);
if (count > 0)
{
GContext.Publish(new ShowData(new List<ItemData>() { new ItemData(itemID, count) }, RewardType.FishBoxOpen, 1));
}
}
public List<ItemData> GetItemDropPackageItemList(int id, int count)
{
ItemDropPackage itemDropPackage = _tables.TbItemDropPackage[id];
List<int> dropIdList = itemDropPackage.DropList;
List<ItemData> itemDataList = new List<ItemData>();
foreach (var t in dropIdList)
{
itemDataList.AddRange(GetItemDataByDropIdAndType(t));
}
for (int i = 0; i < itemDataList.Count; i++)
{
itemDataList[i].count *= count;
}
return itemDataList;
}
public List<ItemData> GetItemDropItemList(int id, int count)
{
List<ItemData> itemDataList = GetItemDataByDropIdAndType(id);
for (int i = 0; i < itemDataList.Count; i++)
{
itemDataList[i].count *= count;
}
return itemDataList;
}
/// <summary>
///
/// </summary>
/// <param name="dropIDList"></param>
/// <param name="isShow"></param>
/// <returns></returns>
public List<ItemData> AddItemByDropList(List<int> dropIDList, ChangeSource changeSource, bool isShow = true, RewardType rewardType = RewardType.Normal)
{
if (dropIDList == null || dropIDList.Count == 0)
{
return null;
}
List<ItemData> itemDataList = new List<ItemData>();
foreach (var t in dropIDList)
{
List<ItemData> itemDatas = GetItemDataByDropIdAndType(t);
if (itemDatas != null && itemDatas.Count > 0)
{
itemDataList.AddRange(itemDatas);
}
}
if (itemDataList.Count == 0)
{
return null;
}
if (isShow)
{
GContext.Publish(new ShowData(itemDataList, rewardType));
}
AddItem(itemDataList, changeSource);
return itemDataList;
}
/// <summary>
/// Get ItemData by drop list, merging same items if necessary.
/// </summary>
/// <param name="dropIDList"></param>
/// <returns>List of items, merged.</returns>
public List<ItemData> GetMergedItemDataByDropList(List<int> dropIDList)
{
if (dropIDList == null || dropIDList.Count == 0)
{
return new List<ItemData>();
}
var itemDataList = new List<ItemData>();
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<int, int>();
//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<ItemData>();
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;
}
/// <summary>
/// Get ItemData list from a drop id list where all drop id points to only one item.
/// </summary>
/// <param name="singleDropIdList">drop id list</param>
/// <returns>ItemData list.</returns>
public List<ItemData> GetItemDataListFromListOfSingleDropId(List<int> singleDropIdList)
{
var res = new List<ItemData>();
if (singleDropIdList == null || singleDropIdList.Count <= 0)
{
return res;
}
var itemLists = singleDropIdList.Select(i => GetItemDataByDropIdAndType(i)).ToList();
for (int i = 0; i < itemLists.Count; i++)
{
if (itemLists[i].Count == 1)
continue;
else
{
Debug.LogError($"GetItemDataListFromListOfSingleDropId: drop id {singleDropIdList[i]} points to more than one item.");
break;
}
}
foreach (var itemDatas in itemLists.Where(itemDatas => itemDatas.Count == 1))
res.AddRange(itemDatas);
return res;
}
/// <summary>
///
/// </summary>
/// <param name="dropID"></param>
/// <param name="isShow"></param>
/// <param name="rewardType"></param>
/// <returns></returns>
public List<ItemData> AddItemByDrop(int dropID, ChangeSource changeSource, bool isShow = true, RewardType rewardType = RewardType.Normal)
{
List<ItemData> itemDataList = GetItemDataByDropIdAndType(dropID);
if (itemDataList != null)
{
if (isShow)
{
GContext.Publish(new ShowData(itemDataList, rewardType));
}
AddItem(itemDataList, changeSource);
}
return itemDataList;
}
/// <summary>
/// 分批获得的时候,卡包合并开启
/// </summary>
/// <param name="itemDataList"></param>
/// <param name="stash"></param>
public void AddItem(List<ItemData> itemDataList, ChangeSource changeSource)
{
Dictionary<int, int> cardItemDataList = new Dictionary<int, int>();
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, changeSource ?? itemData.changeSource, 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, changeSource ?? itemData.changeSource, itemData);
}
}
}
public void AddItem(ItemData itemData, ChangeSource changeSource)
{
AddItemCount(itemData.id, itemData.count, changeSource ?? itemData.changeSource, 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<PlayerData>().Energy;
case 2:
return GContext.container.Resolve<PlayerData>().gold;
case 3:
return GContext.container.Resolve<PlayerData>().pearl;
case 4:
return GContext.container.Resolve<FishingEventData>().TurntableCoupon;
case 5:
return GContext.container.Resolve<PlayerData>().diamond;
case 6:
return GContext.container.Resolve<PlayerShopData>().GetAdticketCount();
//case 9:
// return GContext.container.Resolve<PlayerShopData>().GetVoucher();
}
break;
case 2:
switch (item.SubType)
{
case 1:
return GContext.container.Resolve<PlayerData>().lv;
//case 2:
// return GContext.container.Resolve<PlayerData>().vipScore;
case 5:
case 11:
//猜玩法代币通用代币
//return GContext.container.Resolve<SmallGameData>().GetPokerToken();
case 12:
return 0;
// case 18:
// //1v1门票
// return GContext.container.Resolve<FishingEventData>().GetDuelTickets();
// return GContext.container.Resolve<FishingEventData>().PVPToken;
// // 魔药
// // 弹珠
// if (bingoModel == null || !bingoModel.IsActivated)
// {
// Debug.LogWarning("[EventBingo] Try to get bingo token, but bingo model not found or not activated.");
// return 0;
// }
// else
//
// if (pbManager == null)
// return 0;
// return pbManager.GetTicketCount();
}
break;
case 3:
switch (item.SubType)
{
case 1:
return GContext.container.Resolve<PlayerFishData>().GetRodPiece(item.RedirectID);
case 2:
return GContext.container.Resolve<PlayerFishData>().GetRodPiece(item.ID);
}
break;
case 4:
if (item.SubType == 2)
{
return GContext.container.Resolve<PlayerFishData>().GetCardDataProficiency(item.RedirectID);
}
break;
case 5:
return 0;//ntext.container.Resolve<AlbumData>().GetPictureProgress(id);
case 6:
var _fishingEventData = GContext.container.Resolve<FishingEventData>();
if (item.SubType == 1)
{
return _fishingEventData.GetWheelLevelCount(_fishingEventData.wheelLevel.Level);
}
// else if (item.SubType == 3)
// {
// }
break;
case 7:
var bpDataProvider = GContext.container.Resolve<BattlePassDataProvider>();
if (item.SubType == 3)
return bpDataProvider.Data.BattlePassRecord.Exp;
break;
case 9:
if (item.SubType == 2)
{
return GContext.container.Resolve<FishingBoxData>().GetFishingBoxCount(item.RedirectID);
}
else
{
return 0;
}
case 10:
switch (item.SubType)
{
case 1:
case 11:
return GContext.container.Resolve<FishingEventData>().GetAllCollectingTarget();
case 2:
case 12:
return GContext.container.Resolve<FishingEventData>().GetAllRankTarget();
case 14:
return 1;//小马皮纳塔棒 不需要计数
}
break;
// switch (item.SubType)
// {
// case 2:
// 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:
// // 刮刮乐
// }
// break;
// switch (item.SubType)
// {
// case 2:
// return 0;
// case 3:
// {
// if (arc == null || arc.Model == null)
// return 0;
// return arc.Model.TicketCount;
// }
// case 5:
// {
// if (socialRushArc == null || socialRushArc.Model == null)
// return 0;
// return socialRushArc.Model.ProgressActual;
// }
// }
// 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<FishingEventData>();
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);
}
else if (itemData.id == 15000000)
{
fishingEvent = fishingEventData.GetEventTable(15);
Item15ToEventItem(fishingEvent, itemData);
}
//可能其他转换成1002 然后吃加成
if (itemData.id == 1002)
{
itemData.count = GetExtraCoinMag(itemData.count);
}
if (itemData.id == 101000000)
{
//itemData.origin = itemData.count;
itemData.id = fishingEventData.collectingTargetInitTokenID;
//ItemInflation(itemData, fishingEventData.CollectingTargetInflation);
}
itemData.curCount = (ulong)GetItemCount(itemData.id);
}
void ItemTransition(ItemData itemData, int ExchangeRate, int ItemId)
{
itemData.count = (int)Math.Round(itemData.count / (float)ExchangeRate, MidpointRounding.AwayFromZero);
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.GetOrDefault(fishingEvent.RedirectID);
if (cycle != null)
{
ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId);
return;
}
}
}
//没有活动时默认转换
cycle = _tables.TbFishingEventCycleItem.GetOrDefault(40000);
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)
{
FishingEventCycleItem cycle;
if (fishingEvent != null)
{
if (fishingEvent.Type == 7)
{
cycle = _tables.TbFishingEventCycleItem.GetOrDefault(fishingEvent.RedirectID);
if (cycle != null)
{
ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId);
return;
}
}
}
//没有活动时默认转换
cycle = _tables.TbFishingEventCycleItem.GetOrDefault(70000);
if (cycle != null)
{
itemData.count *= 1000;
ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId);
return;
}
}
void Item8ToEventItem(FishingEvent fishingEvent, ItemData itemData)
{
FishingEventCycleItem cycle;
if (fishingEvent != null)
{
if (fishingEvent.Type == 8)
{
cycle = _tables.TbFishingEventCycleItem.GetOrDefault(fishingEvent.RedirectID);
if (cycle != null)
{
ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId);
return;
}
}
}
//没有活动时默认转换
cycle = _tables.TbFishingEventCycleItem.GetOrDefault(8000000);
if (cycle != null)
{
itemData.count *= 1000;
ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId);
return;
}
}
void Item15ToEventItem(FishingEvent fishingEvent, ItemData itemData)
{
FishingEventCycleItem cycle;
if (fishingEvent != null)
{
if (fishingEvent.Type == 15)
{
cycle = _tables.TbFishingEventCycleItem.GetOrDefault(fishingEvent.RedirectID);
if (cycle != null)
{
ItemTransition(itemData, cycle.ExchangeRate, cycle.ItemId);
return;
}
}
}
//没有活动时默认转换
cycle = _tables.TbFishingEventCycleItem.GetOrDefault(15000000);
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;
}
/// <summary>
/// 处理有选定地图鱼卡的情况
/// </summary>
/// <returns></returns>
public List<ItemData> GetItemDataByDropId(int dropId, int mapId = -1, bool afterAdding = false)
{
var drop = _tables.TbDrop.GetOrDefault(dropId);
DropPackageList dropPackageList = drop?.DropList;
if (dropPackageList == null)
{
GameDebug.LogError("null dropID" + dropId);
return null;
}
List<ItemData> itemDataList = new List<ItemData>();
if (drop.Type == DropType.Beta)
{
Debug.LogError($"[PlayerItemData] DropType == DropType.Beta user [GetItemDataByDropIdAndType]");
return null;
}
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<PlayerData>();
float mg = (1 + playerData.benefitsCashMag) * (1 + playerData.benefitsCashMagLimited);
number *= mg;
int targetCount = Mathf.RoundToInt(number);
if (targetCount < 0)
{
targetCount = int.MaxValue;
Debug.LogError($" ExtraCoinMag overflow {number} {mg} {targetCount}");
}
return targetCount;
}
public float ExtraCoinMag()
{
PlayerData playerData = GContext.container.Resolve<PlayerData>();
float mg = (1 + playerData.benefitsCashMag) * (1 + playerData.benefitsCashMagLimited);
return mg;
}
//获取地图的加成
//public float GetExtraCoinMag()
//{
// float ExtraCoinMag = 0;
// //地图加成
// MapData data = _tables.TbMapData.GetOrDefault(GContext.container.Resolve<PlayerData>().lastMapId);
// if (data != null)
// {
// ExtraCoinMag = data.CashMag;
// }
// //float mcCoinMag = GContext.container.Resolve<MonthCardDataConter>().GetPrivilege2();
// //ExtraCoinMag += mcCoinMag;
// return ExtraCoinMag;
//}
public List<ItemData> GetItemDataByDropIdAndType(int dropId, int mapId = -1)
{
List<ItemData> itemDataList = new List<ItemData>();
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 (drop.Type == DropType.Beta)
{
len2 /= 2;
len3 /= 2;
}
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<int, int> itemDataSubList = new Dictionary<int, int>();
for (int i = 0; i < len; i++)
{
if (Mathf.Ceil(dropList.DropProbList[i] * 100) >= UnityEngine.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 = UnityEngine.Random.Range(0, totalSum);
float sum = 0;
for (int i = 0; i < len; i++)
{
sum += dropList.DropProbList[i];
if (random <= sum - 0.00001f)
{
if (dropList.DropIDList[i] > 0)
{
itemDataList.Add(new ItemData()
{
id = dropList.DropIDList[i],
count = dropList.DropCountList[i]
});
}
break;
}
}
}
else if (drop.Type == DropType.Beta)
{
int minCount;
int maxCount;
float betaA;
float betaB;
double b;
int count;
int id;
for (int i = 0; i < len; i++)
{
minCount = dropList.DropCountList[i * 2];
maxCount = dropList.DropCountList[i * 2 + 1];
id = dropList.DropIDList[i];
if (minCount == maxCount)
{
count = minCount;
}
else
{
betaA = dropList.DropProbList[i * 2];
betaB = dropList.DropProbList[i * 2 + 1];
b = Beta.Sample(betaA, betaB);
count = minCount + (int)((maxCount - minCount) * b);
GameDebug.Log($"[DropType.Beta] dropID == {dropId} itemID == {id} DropType.Beta == {b}");
}
count = BetaRoundingStep(id, count);
ItemData itemData = new ItemData()
{
id = id,
count = count
};
itemDataList.Add(itemData);
}
}
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 int BetaRoundingStep(int id, int count)
{
List<int> roundingStep = null;
if (id == 1001)
{
roundingStep = _tables.TbGlobalConfig.BetaLureRoundingStep;
}
else if (id == 1002)
{
roundingStep = _tables.TbGlobalConfig.BetaCashRoundingStep;
}
if (roundingStep != null && roundingStep.Count > 2)
{
int stepCount = roundingStep.Count / 2;
int step = roundingStep[stepCount * 2];
for (int i = 0; i < stepCount; i++)
{
if (count <= roundingStep[i])
{
step = roundingStep[i + stepCount];
break;
}
}
int a = count / step;
int b = count % step;
count = a * step;
if (b > 0)
{
float r = b / (float)step;
if (UnityEngine.Random.value < r)
{
count += step;
}
}
}
return count;
}
public async void ShowItemTips(int id, Transform trans, float count = -1, float inflate = 0)
{ //物品详情弹窗
Item item = _tables.TbItem.GetOrDefault(id);
if (item.Type == 9 && (item.SubType == 7 || item.SubType == 8))
{
try
{
if (item.SubType == 7)
{
item_sanddig_tips.Show(trans.position, item.RedirectID, inflate);
}
else
{
item_sanddig_tips.ShowBeta(trans.position, item.RedirectID, inflate);
}
}
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<PlayerGradeBenefitInfoPopupPanel>();
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>();
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, inflate);
}
}
}
public List<string> ShowItemDropPackage(ItemDropPackage itemDropPackage)
{
var ItemDisplay = itemDropPackage.ItemDisplay;
List<string> CountDisplay = new List<string>(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);
}
/// <summary>
/// Get iap item list and text price string by iap id.
/// </summary>
/// <param name="iapId"></param>
/// <param name="iapItemList"></param>
/// <param name="price"></param>
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;
}
/// <summary>
/// Get iap item list and set text price by iap id.
/// </summary>
/// <param name="iapId"></param>
/// <param name="iapItemList"></param>
/// <param name="textPrice"></param>
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<ItemData> FishCardItemList;
}
/// <summary>
/// 一般情况下,添加物品的 AddItem…… 传入 changeSource 就行
/// 如果一次添加多个 Item 有不同的来源设置 changeSource 传入 null ,设置每一个ItemData.changeSource
/// </summary>
public class ChangeSource
{
public ChangeSource(int Source_EventId, string Source_Group, string Source_Type, string Source_Module)
{
this.Source_EventId = Source_EventId;
this.Source_Group = Source_Group;
this.Source_Type = Source_Type;
this.Source_Module = Source_Module;
}
public int Source_EventId;
public string Source_Group;
public string Source_Type;
public string Source_Module;
}
}