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

168 lines
7.1 KiB
C#

using asap.core;
using cfg;
using game;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace GameCore
{
public partial class PlayerItemData
{
List<ItemData> fishCardData = new List<ItemData>();
void AddFishCardData(ItemData itemData)
{
fishCardData.Add(itemData);
}
public List<DropFishCardData> OpenFishCard()
{
if (fishCardData.Count == 0)
{
return new List<DropFishCardData>();
}
List<DropFishCardData> itemDataGifts = new List<DropFishCardData>();
List<ItemData> fishCardOpenData = new List<ItemData>(fishCardData);
fishCardData.Clear();
for (int i = 0; i < fishCardOpenData.Count; i++)
{
try
{
var itemData = fishCardOpenData[i];
Item item = _tables.TbItem.GetOrDefault(itemData.id);
var dropFishCardData = OnDropFishCard(item.SubType, item.RedirectID, itemData.id, itemData.count);
if (dropFishCardData != null && dropFishCardData.Count > 0)
{
itemDataGifts.AddRange(dropFishCardData);
}
}
catch (Exception e)
{
GameDebug.LogError($"[PlayerItemData]OpenFishCard: Exception occurred while opening fish card. Details: {e.Message}\n{e.StackTrace}");
}
}
return itemDataGifts;
}
List<DropFishCardData> OnDropFishCard(int subType, int id, int itemId, int count)
{
List<DropFishCardData> itemDataGifts = new List<DropFishCardData>();
List<int> countByQuality;
List<List<int>> fishCardQuality;
MapData mapData;
PlayerFishData playerFishData = GContext.container.Resolve<PlayerFishData>();
for (int j = 0; j < count; j++)
{
List<ItemData> itemDataGift = new List<ItemData>();
if (subType != 1)
{
GeneralCardWeight generalCardWeight = _tables.TbGeneralCardWeight.GetOrDefault(id);
if (generalCardWeight == null)
{
GameDebug.LogError($"[PlayerItemData]OnDropFishCard: Not found id({itemId}) in TbGeneralCardWeight");
return itemDataGifts;
}
countByQuality = generalCardWeight.CountByQuality;
fishCardQuality = new List<List<int>>();
int currentMapId = GContext.container.Resolve<PlayerData>().currentMapId;
//当前地图
var currentMap = _tables.TbMapData.GetOrDefault(currentMapId);
int lv = GContext.container.Resolve<PlayerData>().lv;
var lastMapData = _tables.TbMapData.GetOrDefault(GContext.container.Resolve<PlayerData>().lastMapId);
//非当前地图
var dataList = new List<MapData>();
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 = UnityEngine.Random.Range(0, allWeight);
if (random < generalCardWeight.Weight[0] || dataList.Count == 0)
{
//当前地图
mapData = currentMap;
}
else
{
//非当前地图
mapData = dataList[UnityEngine.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 itemDataGifts;
}
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][UnityEngine.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, null);
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 AGG
using (var e = GEvent.GameEvent("item_change", gaSend: true))
{
e.AddContent("item_id", id)
.AddContent("state_info", "cost")
.AddContent("change_num", count);
}
#endif
return itemDataGifts;
}
}
}