Files
back_cantanBuilding/Assets/Scripts/DataCenter/PlayerFishDataRod.cs
2026-05-26 16:15:54 +08:00

682 lines
27 KiB
C#

using asap.core;
using cfg;
using LitJson;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace GameCore
{
public class RodGSAData
{
public int GloveID;
public Dictionary<int, int> RodToSkin = new Dictionary<int, int>();
public List<int> GloveIds = new List<int>();
public List<int> SkinIds = new List<int>();
public List<int> GloveNewIds = new List<int>();
public List<int> SkinNewIds = new List<int>();
}
public partial class PlayerFishData
{
#region
public RodGSAData rodAccessoriesData;
string InitRodAccessoriesDataKey = "InitRodAccessoriesData";
public GloveData GetGloveData
{
get
{
return _tables.TbGloveData.GetOrDefault(rodAccessoriesData.GloveID);
}
}
public void InitRodAccessoriesData()
{
if (rodAccessoriesData == null || rodAccessoriesData.GloveID == 0)
{
rodAccessoriesData = new RodGSAData();
rodAccessoriesData.GloveID = _tables.TbGlobalConfig.InitGloveID;
rodAccessoriesData.GloveIds = new List<int>() { _tables.TbGlobalConfig.InitGloveID };
}
}
/// <summary>
/// 获取鱼杆对应的皮肤
/// </summary>
/// <param name="rodId"></param>
/// <returns></returns>
public int GetRodSkin(int rodId)
{
if (rodAccessoriesData.RodToSkin.ContainsKey(rodId))
{
return rodAccessoriesData.RodToSkin[rodId];
}
return rodId;
}
/// <summary>
/// 设置鱼杆对应的皮肤
/// </summary>
/// <param name="rodId"></param>
/// <param name="skinId"></param>
public void SetRodSkin(int rodId, int skinId)
{
if (skinId <= 0)
{
skinId = rodId;
}
rodAccessoriesData.RodToSkin[rodId] = skinId;
SaveInitRodAccessoriesData();
}
public void InitRodAccessoriesData(string value)
{
rodAccessoriesData = Newtonsoft.Json.JsonConvert.DeserializeObject<RodGSAData>(value);
}
public void SaveInitRodAccessoriesData()
{
string value = Newtonsoft.Json.JsonConvert.SerializeObject(rodAccessoriesData);
PlayFabMgr.Instance.UpdateUserDataValue(InitRodAccessoriesDataKey, value);
}
/// <summary>
/// 手是否解锁
/// </summary>
/// <param name="gloveId"></param>
/// <returns></returns>
public bool IsGloveUnlocked(int gloveId)
{
return rodAccessoriesData.GloveIds.Contains(gloveId);
}
/// <summary>
/// 皮肤是否解锁
/// </summary>
/// <param name="skinId"></param>
/// <returns></returns>
public bool IsSkinUnlocked(int skinId)
{
return rodAccessoriesData.SkinIds.Contains(skinId);
}
/// <summary>
/// 解锁手
/// </summary>
/// <param name="gloveId"></param>
public void UnlockGlove(int gloveId)
{
if (!IsGloveUnlocked(gloveId))
{
rodAccessoriesData.GloveIds.Add(gloveId);
rodAccessoriesData.GloveNewIds.Add(gloveId);
SaveInitRodAccessoriesData();
}
else
{
Debug.LogError("手投放重复:" + gloveId);
}
}
/// <summary>
/// 解锁皮肤
/// </summary>
/// <param name="skinId"></param>
public void UnlockSkin(int skinId)
{
if (!IsSkinUnlocked(skinId))
{
rodAccessoriesData.SkinIds.Add(skinId);
rodAccessoriesData.SkinNewIds.Add(skinId);
SaveInitRodAccessoriesData();
}
else
{
Debug.LogError("鱼杆皮肤投放重复:" + skinId);
}
}
/// <summary>
/// 获取是否是没查看过的手
/// </summary>
/// <param name="skinId"></param>
/// <returns></returns>
public bool IsNewGlove(int skinId)
{
return rodAccessoriesData.GloveNewIds.Contains(skinId);
}
/// <summary>
/// 是否是没查看过的皮肤
/// </summary>
/// <param name="skinId"></param>
/// <returns></returns>
public bool IsNewSkin(int skinId)
{
bool isNew = rodAccessoriesData.SkinNewIds.Contains(skinId);
if (isNew)
{
rodAccessoriesData.SkinNewIds.Remove(skinId);
}
return isNew;
}
/// <summary>
/// 取消new标记 手
/// </summary>
/// <param name="gloveId"></param>
public void RemoveGloveNewId()
{
if (rodAccessoriesData.GloveNewIds.Count > 0)
{
rodAccessoriesData.GloveNewIds.Clear();
SaveInitRodAccessoriesData();
}
}
#endregion
#region
//合成或强化鱼竿
bool EnhanceConsumed(int quality, int fragmentID, int rquiredFragments)
{
if (rodData.TryGetValue(fragmentID, out int rodCount) && rodCount >= rquiredFragments)
{
rodData[fragmentID] -= rquiredFragments;
#if AGG
using (var e = GEvent.GameEvent("item_change", gaSend: false))
{
e.AddContent("item_id", fragmentID)
.AddContent("state_info", "cost")
.AddContent("change_num", rquiredFragments);
}
#endif
return true;
}
else
{
rquiredFragments -= rodCount;
RodFragmentExchange rodFragmentExchange = _tables.TbRodFragmentExchange.GetOrDefault(quality);
int fragment = 0;
if (rodFragmentExchange != null)
{
rquiredFragments *= rodFragmentExchange.ExchangeRate;
fragment = GContext.container.Resolve<PlayerFishData>().GetRodPiece(rodFragmentExchange.GeneralFragmentID);
}
if (fragment >= rquiredFragments)
{
if (rodData.ContainsKey(fragmentID))
{
rodData[fragmentID] = 0;
}
rodData[rodFragmentExchange.GeneralFragmentID] -= rquiredFragments;
#if AGG
if (rodCount > 0)
{
using (var e = GEvent.GameEvent("item_change", gaSend: false))
{
e.AddContent("item_id", fragmentID)
.AddContent("state_info", "cost")
.AddContent("change_num", rodCount);
}
}
using (var e = GEvent.GameEvent("item_change", gaSend: false))
{
e.AddContent("item_id", rodFragmentExchange.GeneralFragmentID)
.AddContent("state_info", "cost")
.AddContent("change_num", rquiredFragments);
}
#endif
return true;
}
}
return false;
}
public void AscendRod(int id)
{
RodData _rodData = _tables.TbRodData.GetOrDefault(id);
if (_rodData != null)
{
bool isUp = false;
RodAscend rodAscend = _tables.TbRodAscend.GetOrDefault(_rodData.AscendID);
int rquiredFragments;
int fragmentID = rodAscend.FragmentID;
int quality = _rodData.Quality;
if (rodData.ContainsKey(id))
{
rquiredFragments = rodAscend.AscentTransformed[rodData[id] + 1];
if (rodData[id] < rodAscend.AscentTransformed.Count - 1 && EnhanceConsumed(quality, fragmentID, rquiredFragments))
{
isUp = true;
rodData[id] += 1;
}
}
else
{
rquiredFragments = rodAscend.AscentTransformed[0];
if (rodData.TryGetValue(fragmentID, out int rodCount) && rodCount >= rquiredFragments)
{
rodData[fragmentID] -= rquiredFragments;
#if AGG
using (var e = GEvent.GameEvent("item_change", gaSend: false))
{
e.AddContent("item_id", fragmentID)
.AddContent("state_info", "cost")
.AddContent("change_num", rquiredFragments);
}
#endif
isUp = true;
rodData.Add(id, 0);
}
}
if (isUp)
{
#if AGG
using (var e = GEvent.GameEvent("rod_upgrade"))
{
e.AddContent("rod_id", id)
.AddContent("rod_level", GetRodLevel(id))
.AddContent("resin_consume", 0)
.AddContent("rod_star", rodData[id])
.AddContent("rod_chips_consume", rquiredFragments);
}
#endif
PlayFabMgr.Instance.UpdateUserDataValue("RodData", JsonMapper.ToJson(rodData));
//鱼竿红点数据修改
CheckRodRedPointUp();
//合成鱼竿
CheckAllRodUpLevel();
}
}
}
#endregion
#region 耀
Dictionary<int, int> _honorlevel = new Dictionary<int, int>();
public int GetHonorLevel(int honorId)
{
if (_honorlevel.TryGetValue(honorId, out int level))
{
return level;
}
return 0;
}
public int GetHonorLevelAttribute(int quality, int starAdd = 0)
{
RodRodLevelPeak rodLevelPeak = _tables.TbRodRodLevelPeak.GetOrDefault(quality);
//星级对属性的加成 某几个属性加多少加到多少星
int level = GetHonorLevel(quality) + starAdd;
if (rodLevelPeak != null && level > 0)
{
List<int> peakBasicStats = rodLevelPeak.PeakBasicStats;
int value;
int count = peakBasicStats.Count;
if (level > count)
{
value = peakBasicStats[count - 1];
value += (level - count) * (peakBasicStats[count - 1] - peakBasicStats[count - 2]);
}
else
{
value = peakBasicStats[level - 1];
}
return value;
}
return 0;
}
public void HonorLevelUp(RodData rodData)
{
PlayerData playerData = GContext.container.Resolve<PlayerData>();
RodAscend rodAscend = _tables.TbRodAscend.GetOrDefault(rodData.AscendID);
int quality = rodData.Quality;
int fragmentID = rodAscend.FragmentID;
RodRodLevelPeak rodLevelPeak = _tables.TbRodRodLevelPeak.GetOrDefault(rodData.Quality);
if (rodLevelPeak == null)
{
Debug.LogError($"[FishingRodHonorlevelPanel]OnClickUpGray: No RodRodLevelPeak data found for Quality {quality}");
return;
}
int currentHonorLevel = GetHonorLevel(rodData.Quality);
if (currentHonorLevel >= rodLevelPeak.ItemConsume.Count)
{
currentHonorLevel = rodLevelPeak.ItemConsume.Count - 1;
}
int requiredItems = rodLevelPeak.ItemConsume[currentHonorLevel];
int fragmentItems = rodLevelPeak.FragmentConsume[currentHonorLevel];
if (playerData.pearl >= requiredItems && EnhanceConsumed(quality, fragmentID, fragmentItems))
{
playerData.SetPearl(playerData.pearl - requiredItems);
if (_honorlevel.ContainsKey(quality))
{
_honorlevel[quality]++;
}
else
{
_honorlevel[quality] = 1;
}
SaveHonorLevelData();
}
}
string HonorLevelDataKey = "HonorLevelData";
public void SaveHonorLevelData()
{
string value = Newtonsoft.Json.JsonConvert.SerializeObject(_honorlevel);
PlayFabMgr.Instance.UpdateUserDataValue(HonorLevelDataKey, value);
}
#endregion 耀
#region
//计算升级和强化后的属性
public List<int> GetRodAttribute(int id, bool isMax = false, int levelAdd = 0, int starAdd = 0)
{
RodData rodData = _tables.TbRodData.GetOrDefault(id);
RodAscend rodAscend = _tables.TbRodAscend.GetOrDefault(rodData.AscendID);
RodLevelup rodLevelup = _tables.TbRodLevelup.GetOrDefault(rodData.LevelupID);
int star = isMax ? rodAscend.MaxAscent : GetRodPiece(rodData.ID) + starAdd;
int level = isMax ? rodLevelup.MaxLevel - 1 : GetRodLevel(rodData.ID) + levelAdd;
List<int> list = new List<int>();
for (int i = 0; i < rodData.InitialBasicStats.Count; i++)
{
list.Add(0);
}
//星级对属性的加成 某几个属性加多少加到多少星
var AscentBasicStats = rodAscend.AscentBasicStat;
var AscentBasicStatList = rodAscend.AscentBasicStatList;
int index;
for (int i = 0; i < star; i++)
{
var AscentBasicStat = AscentBasicStats[i];
int count = AscentBasicStat.Count;
for (int j = 0; j < count; j++)
{
//InitialBasicStats 中第 AscentBasicStat[j] 个值加 i 星的值 累加
index = AscentBasicStat[j] - 1;
list[index] = AscentBasicStatList[i][j];
}
}
//等级对属性的加成 每个属性升到多少级
var levelupBasicStats = rodLevelup.LevelupBasicStats;
for (int j = 0; j < list.Count; j++)
{
list[j] += levelupBasicStats[j][level] + rodData.InitialBasicStats[j];
}
list[0] += GetHonorLevelAttribute(rodData.Quality);
return list;
}
#region
//获取鱼竿某一星级各个词条的等级
public int[] GetPerkLevel(int perkIDListCount, int star, List<int> DefaultPerk, List<int> PerkUnlockOrder)
{
int[] lv = new int[perkIDListCount];
for (int i = 0; i < DefaultPerk.Count; i++)
{
lv[DefaultPerk[i] - 1]++;
}
for (int i = 0; i < star; i++)
{
if (PerkUnlockOrder[i] <= perkIDListCount)
{
//每一星升级的是第几个特性
lv[PerkUnlockOrder[i] - 1]++;
}
}
return lv;
}
//获取鱼竿某一星级能解锁的词条ID及值
public Dictionary<int, string> GetRodDuelPerk(int id, int star)
{
RodData rodData = _tables.TbRodData.GetOrDefault(id);
RodAscend curRodAscend = _tables.TbRodAscend.GetOrDefault(rodData.AscendID);
int perkIDListCount = curRodAscend.PerkIDList.Count;
int[] lv = GetPerkLevel(perkIDListCount, star, curRodAscend.DefaultPerk, curRodAscend.PerkUnlockOrder);
Dictionary<int, string> RodPerkDic = new Dictionary<int, string>();
for (int i = 0; i < perkIDListCount; i++)
{
int level = lv[i];
if (level > 0)
{
var rodEngancePerk = _tables.TbRodAscendPerk.GetOrDefault(curRodAscend.PerkIDList[i]);
if (rodEngancePerk.DuelPerk)
{
List<string> PerkDataList = curRodAscend.PerkDataList[i];
if (level > PerkDataList.Count)
{
Debug.LogError($"GetRodPerk: rod {id} perkID {curRodAscend.PerkIDList[i]} level {level} is out of range (1 - {PerkDataList.Count})");
}
else
{
RodPerkDic[curRodAscend.PerkIDList[i]] = PerkDataList[level - 1];
}
}
}
}
return RodPerkDic;
}
//获取鱼竿某一星级能解锁的词条类型及值
public Dictionary<RodPerkType, string> GetRodPerk(int id, int star)
{
RodData rodData = _tables.TbRodData.GetOrDefault(id);
RodAscend curRodAscend = _tables.TbRodAscend.GetOrDefault(rodData.AscendID);
int perkIDListCount = curRodAscend.PerkIDList.Count;
int[] lv = GetPerkLevel(perkIDListCount, star, curRodAscend.DefaultPerk, curRodAscend.PerkUnlockOrder);
Dictionary<RodPerkType, string> RodPerkDic = new Dictionary<RodPerkType, string>();
for (int i = 0; i < curRodAscend.PerkDataList.Count; i++)
{
int level = lv[i];
if (level > 0)
{
var rodEngancePerk = _tables.TbRodAscendPerk.GetOrDefault(curRodAscend.PerkIDList[i]);
//第i条第lv[i]级 直接读数值
List<string> PerkDataList = curRodAscend.PerkDataList[i];
if (level > PerkDataList.Count)
{
Debug.LogError($"GetRodPerk: rod {id} perkID {curRodAscend.PerkIDList[i]} level {level} is out of range (1 - {PerkDataList.Count})");
}
else
{
RodPerkDic[rodEngancePerk.PerkType] = PerkDataList[level - 1];
}
}
}
return RodPerkDic;
}
//获取鱼竿某一星级能解锁的词条类型及等级
public Dictionary<RodPerkType, (int, int)> GetRodPerkLevel(int id, int star)
{
RodData rodData = _tables.TbRodData.GetOrDefault(id);
RodAscend curRodAscend = _tables.TbRodAscend.GetOrDefault(rodData.AscendID);
int perkIDListCount = curRodAscend.PerkIDList.Count;
int[] lv = GetPerkLevel(perkIDListCount, star, curRodAscend.DefaultPerk, curRodAscend.PerkUnlockOrder);
Dictionary<RodPerkType, (int, int)> RodPerkDic = new Dictionary<RodPerkType, (int, int)>();
for (int i = 0; i < perkIDListCount; i++)
{
int level = lv[i];
if (level > 0)
{
var rodEngancePerk = _tables.TbRodAscendPerk.GetOrDefault(curRodAscend.PerkIDList[i]);
RodPerkDic[rodEngancePerk.PerkType] = (curRodAscend.PerkIDList[i], level);
}
}
return RodPerkDic;
}
//解析词条的值
public float GetRodPerkValue(RodPerkType rodPerkType, Dictionary<RodPerkType, string> RodPerkDic)
{
if (RodPerkDic.TryGetValue(rodPerkType, out string perk))
{
if (perk.Contains('|'))
{
Debug.LogError($"GetRodPerkValue: rodPerkType {rodPerkType} perk {perk} cannot convert to float directly");
string[] values = perk.Split('|');
return float.Parse(values[0]);
}
return float.Parse(perk);
}
return 0;
}
public static string GetPerkDesc(RodPerkType rodPerkType, string des, string value)
{
var values = value.Split('|');
string str = LocalizationMgr.GetText(des);
try
{
switch (rodPerkType)
{
case RodPerkType.BattlePerk_AllToAtkSpeed:
str = LocalizationMgr.GetFormatTextValue(des, float.Parse(values[0]).ToPercentageString(), values[1], float.Parse(values[2]).ToPercentageString());
break;
case RodPerkType.BattlePerk_ComboToExDmg:
str = LocalizationMgr.GetFormatTextValue(des, float.Parse(values[0]).ToPercentageString(), values[1]);
break;
case RodPerkType.BattlePerk_FishSkillToAtkSpeed:
case RodPerkType.BattlePerk_FishEscapeToAtkSpeed:
str = LocalizationMgr.GetFormatTextValue(des, values[0], float.Parse(values[1]).ToPercentageString());
break;
case RodPerkType.BattlePerk_PiercingAddDamage:
str = LocalizationMgr.GetFormatTextValue(des, values[1], float.Parse(values[0]).ToPercentageString());
break;
case RodPerkType.BattlePerk_PiercingToCombo:
case RodPerkType.BattlePerk_TensionToCrit:
case RodPerkType.BattlePerk_PiercingCritDmg:
case RodPerkType.FactoryLabel_ScaleG:
case RodPerkType.FactoryLabel_Ilmarinen:
case RodPerkType.FactoryLabel_ChromaCast:
case RodPerkType.FactoryLabel_Victoria:
case RodPerkType.FactoryLabel_Sakura:
case RodPerkType.FactoryLabel_Titan:
str = LocalizationMgr.GetFormatTextValue(des, float.Parse(values[0]).ToPercentageString(), float.Parse(values[1]).ToPercentageString());
break;
case RodPerkType.BattlePerk_ComboToCombo:
str = LocalizationMgr.GetFormatTextValue(des, float.Parse(values[0]).ToPercentageString(), float.Parse(values[1]).ToPercentageString(), float.Parse(values[2]).ToPercentageString());
break;
case RodPerkType.NewPiercingZone:
break;
default:
if (!value.Contains('|'))
{
str = LocalizationMgr.GetFormatTextValue(des, float.Parse(value).ToPercentageString());
}
else
{
str = LocalizationMgr.GetFormatTextValue(des, float.Parse(values[0]).ToPercentageString(), float.Parse(values[1]).ToPercentageString());
Debug.LogError($"GetPerkDesc error: no case for rodPerkType: {rodPerkType}, des: {des}, value: {value}");
}
break;
}
}
catch (Exception e)
{
Debug.LogError($"GetPerkDesc error: {e.Message}, rodPerkType: {rodPerkType}, des: {des}, value: {value}");
}
return str;
}
/// <summary>
/// 设置星级展示
/// </summary>
/// <param name="star"></param>
/// <param name="MaxAscent"></param>
/// <param name="star_empty_list"></param>
/// <param name="star_empty_image"></param>
/// <param name="starList"></param>
/// <param name="isUp"></param>
/// <returns></returns>
public static int SetRodStar(int star,
int MaxAscent,
List<GameObject> star_empty_list,
List<Image> star_empty_image,
List<StarItem> starList, bool isUp = false)
{
if (star > MaxAscent || star < 0)
{
Debug.LogError($"SetRodStar: star {star} is out of range (0 - {MaxAscent})");
star = MaxAscent;
}
int Quality = MaxAscent / 3;
if (MaxAscent > 15)
{
Debug.LogError("MaxAscent >> show == 15");
Quality = MaxAscent / 4;
}
if (Quality > 5)
{
Debug.LogError("MaxAscent >> show == 20");
Quality = 5;
}
int show = star;
int startIndex = 0;
if (star > Quality * 3)
{
show = star - Quality * 3;
startIndex = 3;
}
else if (star > Quality * 2)
{
show = star - Quality * 2;
startIndex = 2;
}
else if (star > Quality)
{
show = star - Quality;
startIndex = 1;
}
int index = startIndex;
for (int i = 0; i < starList.Count; i++)
{
starList[i].gameObject.SetActive(i < Quality);
star_empty_list[i].SetActive(i < Quality);
if (i < show)
{
starList[i].SetStar(startIndex + 1);
}
else if (i < Quality)
{
starList[i].SetStar(startIndex);
}
if (star_empty_image != null)
{
if (index > 0)
{
if (index > 3)
{
Debug.LogError("SetRodStar index > 3, index = " + index);
index = 3;
}
star_empty_image[i].gameObject.SetActive(true);
star_empty_image[i].sprite = starList[i].Star[index - 1].sprite;
}
else
{
star_empty_image[i].gameObject.SetActive(false);
}
}
}
if (isUp)
{
if (show > 0)
{
starList[show - 1].PlayAni();
if (star_empty_image != null)
{
index = startIndex;
if (index > 0)
{
star_empty_image[show - 1].gameObject.SetActive(true);
star_empty_image[show - 1].sprite = starList[show - 1].Star[index - 1].sprite;
}
else
{
star_empty_image[show - 1].gameObject.SetActive(false);
}
}
}
}
return Quality;
}
#endregion
#endregion
}
}