备份CatanBuilding瘦身独立工程
This commit is contained in:
424
Assets/Scripts/DataCenter/FishingBoxData.cs
Normal file
424
Assets/Scripts/DataCenter/FishingBoxData.cs
Normal file
@@ -0,0 +1,424 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using LitJson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
[Serializable]
|
||||
public class FishingBoxData
|
||||
{
|
||||
public Dictionary<int, int> FishingBoxs = new();
|
||||
public Dictionary<int, int> FishingNewBoxs = new();
|
||||
public Dictionary<int, int> FishingBoxOpenNum = new();
|
||||
public int FishingBoxScore;
|
||||
public int CurFishingBoxLevel;
|
||||
|
||||
public FishingBoxData()
|
||||
{
|
||||
var firstItemID = FishingBoxDataProvier.firstFishingBoxID;
|
||||
for (int i = 0; i < FishingBoxDataProvier.QualityCount; i++)
|
||||
{
|
||||
FishingBoxs.Add(firstItemID + i, 0);
|
||||
FishingNewBoxs.Add(firstItemID + i, 0);
|
||||
}
|
||||
}
|
||||
public void InitData(string data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(data) == false)
|
||||
{
|
||||
var boxData = Newtonsoft.Json.JsonConvert.DeserializeObject<FishingBoxData>(data);
|
||||
FishingBoxs = boxData.FishingBoxs;
|
||||
FishingNewBoxs = boxData.FishingNewBoxs;
|
||||
FishingBoxOpenNum = boxData.FishingBoxOpenNum;
|
||||
FishingBoxScore = boxData.FishingBoxScore;
|
||||
CurFishingBoxLevel = boxData.CurFishingBoxLevel;
|
||||
|
||||
var firstItemID = FishingBoxDataProvier.firstFishingBoxID;
|
||||
for (int i = 0; i < FishingBoxDataProvier.QualityCount; i++)
|
||||
{
|
||||
if (!FishingBoxs.ContainsKey(firstItemID + i))
|
||||
{
|
||||
FishingBoxs.Add(firstItemID + i, 0);
|
||||
}
|
||||
if (!FishingNewBoxs.ContainsKey(firstItemID + i))
|
||||
{
|
||||
FishingNewBoxs.Add(firstItemID + i, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFishingBoxCount(int itemID, int value)
|
||||
{
|
||||
if (value < 0)
|
||||
GContext.Publish(new ConditionTypeEvent { type = ConditionType.OpenFishBoxCount, count = -value });
|
||||
if (FishingNewBoxs.ContainsKey(itemID))
|
||||
{
|
||||
FishingNewBoxs[itemID] += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
FishingNewBoxs.Add(itemID, value);
|
||||
}
|
||||
Save();
|
||||
}
|
||||
public void Save()
|
||||
{
|
||||
PlayFabMgr.Instance.UpdateUserDataValue("FishingBoxData", JsonMapper.ToJson(this));
|
||||
}
|
||||
|
||||
public int GetFishingBoxCount(int itemID)
|
||||
{
|
||||
if (FishingNewBoxs.ContainsKey(itemID))
|
||||
{
|
||||
return FishingNewBoxs[itemID];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int GetNextValidFishingBoxSelectedID()
|
||||
{
|
||||
foreach (var box in FishingBoxs)
|
||||
{
|
||||
var id = box.Key;
|
||||
if (box.Value > 0)
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void AddBoxOpenCount(int itemID, int count)
|
||||
{
|
||||
if (FishingBoxOpenNum.ContainsKey(itemID))
|
||||
{
|
||||
FishingBoxOpenNum[itemID] += count;
|
||||
}
|
||||
else
|
||||
FishingBoxOpenNum.Add(itemID, count);
|
||||
Save();
|
||||
|
||||
}
|
||||
public int GetFishingBoxOpenCount(int itemID)
|
||||
{
|
||||
if (FishingBoxOpenNum.ContainsKey(itemID))
|
||||
{
|
||||
return FishingBoxOpenNum[itemID];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public class FishingBoxDataProvier
|
||||
{
|
||||
public static int QualityCount;
|
||||
public static int firstFishingBoxID;
|
||||
|
||||
public int EventTipID;
|
||||
|
||||
public bool IsUnclocked;
|
||||
|
||||
public bool CanSwitchBox;
|
||||
|
||||
private int _curSelectedID;
|
||||
/// <summary>
|
||||
/// 0-4
|
||||
/// </summary>
|
||||
private int _curSelectedQuality;
|
||||
private int maxOpenCount;
|
||||
public int CurSelectedID
|
||||
{
|
||||
get
|
||||
{
|
||||
return _curSelectedID;
|
||||
}
|
||||
set
|
||||
{
|
||||
_curSelectedID = value;
|
||||
_curSelectedQuality = GetQualityByID(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//public int CurSelectedQuality
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return _curSelectedQuality;
|
||||
// }
|
||||
|
||||
// set
|
||||
// {
|
||||
// _curSelectedQuality = value;
|
||||
// if (_curSelectedQuality < 0 || _curSelectedQuality > QualityCount - 1)
|
||||
// {
|
||||
// _curSelectedQuality += QualityCount;
|
||||
// _curSelectedQuality %= QualityCount;
|
||||
// }
|
||||
// _curSelectedID = GetIDByQuality(_curSelectedQuality);
|
||||
// }
|
||||
//}
|
||||
//public int CurBoxLevel
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// var level = Data.CurFishingBoxLevel;
|
||||
// if (level == 0)
|
||||
// {
|
||||
// Data.CurFishingBoxLevel = 1;
|
||||
// Data.Save();
|
||||
// }
|
||||
// var len = _boxLevels.Count;
|
||||
// if (level > len)
|
||||
// {
|
||||
// Data.CurFishingBoxLevel = 1;
|
||||
// Data.Save();
|
||||
// }
|
||||
|
||||
// return Data.CurFishingBoxLevel;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
|
||||
// var count = value;
|
||||
// if (value == 0)
|
||||
// {
|
||||
// count = 1;
|
||||
// }
|
||||
// var len = _boxLevels.Count;
|
||||
// if (value > len)
|
||||
// {
|
||||
// count = 1;
|
||||
// }
|
||||
|
||||
// Data.CurFishingBoxLevel = count;
|
||||
// Data.Save();
|
||||
// }
|
||||
//}
|
||||
|
||||
public FishingBoxData Data;
|
||||
|
||||
public FishingBoxDataProvier(Tables table)
|
||||
{
|
||||
firstFishingBoxID = table.TbBox.DataList[0].ID;
|
||||
QualityCount = table.TbBox.DataList.Count;
|
||||
|
||||
_items = table.TbItem.DataMap;
|
||||
_itemDropPackages = table.TbItemDropPackage.DataMap;
|
||||
_boxLevels = table.TbBoxLevel.DataMap;
|
||||
_boxInits = table.TbBoxInit.DataMap;
|
||||
_boxes = table.TbBox.DataMap;
|
||||
maxOpenCount = table.TbGlobalConfig.BoxMaxOpenCount;
|
||||
|
||||
Data = GContext.container.Resolve<FishingBoxData>();
|
||||
}
|
||||
|
||||
#region TablesData
|
||||
private Dictionary<int, Item> _items;
|
||||
private Dictionary<int, ItemDropPackage> _itemDropPackages;
|
||||
private Dictionary<int, BoxLevel> _boxLevels;
|
||||
private Dictionary<int, Box> _boxes;
|
||||
private Dictionary<int, BoxInit> _boxInits;
|
||||
#endregion
|
||||
|
||||
|
||||
public void Init()
|
||||
{
|
||||
CanSwitchBox = true;
|
||||
CurSelectedID = Data.GetNextValidFishingBoxSelectedID() == -1 ? firstFishingBoxID : Data.GetNextValidFishingBoxSelectedID();
|
||||
}
|
||||
|
||||
#region Get Function
|
||||
public List<int> GetFishingBoxDropID(int itemID = -1)
|
||||
{
|
||||
if (itemID == -1)
|
||||
{
|
||||
itemID = CurSelectedID;
|
||||
}
|
||||
Data.AddBoxOpenCount(itemID, 1);
|
||||
if (_boxInits.ContainsKey(itemID))
|
||||
{
|
||||
var boxInit = _boxInits[itemID];
|
||||
var openCout = Data.GetFishingBoxOpenCount(itemID);
|
||||
if (openCout <= boxInit.DropChange.Count && openCout != 0)
|
||||
{
|
||||
return _itemDropPackages[boxInit.DropChange[openCout - 1]].DropList;
|
||||
}
|
||||
}
|
||||
|
||||
return _itemDropPackages[itemID].DropList;
|
||||
|
||||
}
|
||||
//public string GetFishingBoxName(int itemID = -1)
|
||||
//{
|
||||
// if (itemID == -1)
|
||||
// {
|
||||
// return LocalizationMgr.GetFormatTextValue(_items[CurSelectedID].Name_l10n_key);
|
||||
// }
|
||||
// return LocalizationMgr.GetFormatTextValue(_items[itemID].Name_l10n_key);
|
||||
//}
|
||||
//public string GetFishingBoxRewardTitle(int itemID = -1)
|
||||
//{
|
||||
// if (itemID == -1)
|
||||
// {
|
||||
// return LocalizationMgr.GetFormatTextValue(_itemDropPackages[CurSelectedID].Desc_l10n_key);
|
||||
// }
|
||||
// return LocalizationMgr.GetFormatTextValue(_itemDropPackages[itemID].Desc_l10n_key);
|
||||
|
||||
//}
|
||||
//public string GetFishingBoxDesc(int itemID = -1)
|
||||
//{
|
||||
// if (itemID == -1)
|
||||
// {
|
||||
// return LocalizationMgr.GetFormatTextValue(_items[CurSelectedID].Desc_l10n_key);
|
||||
// }
|
||||
// return LocalizationMgr.GetFormatTextValue(_items[itemID].Desc_l10n_key);
|
||||
|
||||
|
||||
//}
|
||||
|
||||
//public string GetFishingBoxTitleImg(int itemID = -1)
|
||||
//{
|
||||
// var name = "bg_fishingbox_title_";
|
||||
// if (itemID == -1)
|
||||
// {
|
||||
// return name + (CurSelectedQuality + 1);
|
||||
// }
|
||||
// return name + (GetQualityByID(itemID) + 1);
|
||||
//}
|
||||
//public string GetFishingBoxTipImg(int itemID = -1)
|
||||
//{
|
||||
// var name = "bg_fishingbox_tips_";
|
||||
// if (itemID == -1)
|
||||
// {
|
||||
// return name + (CurSelectedQuality + 1);
|
||||
// }
|
||||
// return name + (GetQualityByID(itemID) + 1);
|
||||
//}
|
||||
|
||||
|
||||
//public string GetFishingBoxIcon(int itemID = -1)
|
||||
//{
|
||||
// if (itemID == -1)
|
||||
// {
|
||||
// return _items[CurSelectedID].Icon;
|
||||
// }
|
||||
// return _items[itemID].Icon;
|
||||
//}
|
||||
|
||||
public int GetQualityByID(int itemID)
|
||||
{
|
||||
return _items[itemID].Quality;
|
||||
}
|
||||
public int GetIDByQuality(int quality)
|
||||
{
|
||||
return firstFishingBoxID + quality;
|
||||
}
|
||||
//public void SetBoxRewardScore(int itemID, int count)
|
||||
//{
|
||||
// ChangeCurScore(_boxes[itemID].PointsGain * count);
|
||||
//}
|
||||
|
||||
//InfoBar
|
||||
//public void GetRewardsInfo(List<FishingBoxInfoBar.RewardItemInfo> infos, int itemID = -1)
|
||||
//{
|
||||
// foreach (var info in infos)
|
||||
// {
|
||||
// info.Tran.gameObject.SetActive(false);
|
||||
// }
|
||||
|
||||
// ItemDropPackage fishingBox;
|
||||
// if (itemID == -1)
|
||||
// {
|
||||
// fishingBox = _itemDropPackages[CurSelectedID];
|
||||
// }
|
||||
// else
|
||||
// fishingBox = _itemDropPackages[CurSelectedID];
|
||||
|
||||
|
||||
// var uiService = GContext.container.Resolve<IUIService>();
|
||||
// for (int i = 0; i < fishingBox.ItemDisplay.Count; i++)
|
||||
// {
|
||||
// var item = _items[fishingBox.ItemDisplay[i]];
|
||||
// var name = LocalizationMgr.GetFormatTextValue(item.Name_l10n_key);
|
||||
// var desc = "";
|
||||
// var prob = fishingBox.ProbDisplay[i] * 100;
|
||||
// if (item.Type == 1 && item.SubType == 2)
|
||||
// {
|
||||
// var bate = GContext.container.Resolve<PlayerItemData>().GetExtraCoinMag(1);
|
||||
// var nums = fishingBox.CountDisplay[i].Split('-').ToList();
|
||||
// var descs = nums.Select(x => int.Parse(x) * bate).ToList();
|
||||
// for (int j = 0; j < descs.Count - 1; j++)
|
||||
// {
|
||||
// desc += Mathf.Round(descs[j] / 10) * 10 + "-";
|
||||
// }
|
||||
// desc += Mathf.Round(descs[descs.Count - 1] / 10) * 10 + " " + prob + "%";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// desc = fishingBox.CountDisplay[i] + " " + prob + "%";
|
||||
// }
|
||||
// infos[i].Reset(name, desc);
|
||||
// uiService.SetImageSprite(infos[i].Img, item.Icon);
|
||||
|
||||
// infos[i].Tran.gameObject.SetActive(true);
|
||||
// }
|
||||
//}
|
||||
|
||||
//ProgressBar
|
||||
//public int GetCurScore()
|
||||
//{
|
||||
// return Data.FishingBoxScore;
|
||||
//}
|
||||
//public int GetRequriedScore()
|
||||
//{
|
||||
// return _boxLevels[CurBoxLevel].PointsRequired;
|
||||
//}
|
||||
public void ChangeCurScore(int value)
|
||||
{
|
||||
Data.FishingBoxScore += value;
|
||||
Data.Save();
|
||||
}
|
||||
//public string GetBoxRewardIcon()
|
||||
//{
|
||||
// var id = _boxLevels[CurBoxLevel].BoxID;
|
||||
// return _items[id].Icon;
|
||||
//}
|
||||
//public int GetBoxRewardID()
|
||||
//{
|
||||
// return _boxLevels[CurBoxLevel].BoxID;
|
||||
//}
|
||||
|
||||
//public void OnGetBoxReward()
|
||||
//{
|
||||
// Data.FishingBoxScore -= _boxLevels[CurBoxLevel].PointsRequired;
|
||||
// Data.SetFishingBoxCount(_boxLevels[CurBoxLevel].BoxID, 1);
|
||||
// CurBoxLevel = CurBoxLevel + 1;
|
||||
//}
|
||||
|
||||
|
||||
//SelectedBar
|
||||
public int GetBoxCount(int itemID = -1)
|
||||
{
|
||||
if (itemID == -1)
|
||||
{
|
||||
return Data.GetFishingBoxCount(CurSelectedID);
|
||||
}
|
||||
return Data.GetFishingBoxCount(itemID);
|
||||
}
|
||||
//public int GetBoxToOpenCount(int itemID = -1)
|
||||
//{
|
||||
// var count = GetBoxCount(itemID);
|
||||
|
||||
// return count > maxOpenCount ? maxOpenCount : count;
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user