using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class AlchemyModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, uint> m_AlchemyTimes = new Dictionary<int, uint>();
|
Dictionary<int, AlchemyCount> m_AlchemyCounts = new Dictionary<int, AlchemyCount>();
|
Dictionary<int, int> m_AlchemyQualityLucks = new Dictionary<int, int>();
|
Dictionary<int, List<Item>> m_AlchemyMaterials = new Dictionary<int, List<Item>>();
|
|
int m_SelectQuality = 0;
|
public int selectQuality
|
{
|
get { return m_SelectQuality; }
|
set
|
{
|
if (m_SelectQuality != value)
|
{
|
m_SelectQuality = value;
|
if (selectQualityRefresh != null)
|
{
|
selectQualityRefresh();
|
}
|
}
|
}
|
}
|
|
int m_SelectAlchemy = 0;
|
public int selectAlchemy
|
{
|
get { return m_SelectAlchemy; }
|
set
|
{
|
if (m_SelectAlchemy != value)
|
{
|
m_SelectAlchemy = value;
|
if (selectAlchemyRefresh != null)
|
{
|
selectAlchemyRefresh();
|
}
|
}
|
}
|
}
|
|
public int stoveLevel { get; private set; }
|
public int stoveExp { get; private set; }
|
public string alchemySuccRate { get; private set; }
|
|
public event Action selectQualityRefresh;
|
public event Action selectAlchemyRefresh;
|
public event Action alchemyStateRefresh;
|
|
public override void Init()
|
{
|
ParseConfig();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
m_AlchemyTimes.Clear();
|
stoveLevel = 0;
|
stoveExp = 0;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
void ParseConfig()
|
{
|
{
|
var configs = AlchemyCountConfig.GetValues();
|
foreach (var config in configs)
|
{
|
var intArray = LitJson.JsonMapper.ToObject<int[][]>(config.CntRateList);
|
var min = intArray[0][1];
|
var max = intArray[intArray.Length - 1][1];
|
if (m_AlchemyCounts.ContainsKey(config.AlchemyQuality))
|
{
|
var alchemyCount = m_AlchemyCounts[config.AlchemyQuality];
|
if (min < alchemyCount.min)
|
{
|
alchemyCount.min = min;
|
m_AlchemyCounts[config.AlchemyQuality] = alchemyCount;
|
}
|
if (max > alchemyCount.max)
|
{
|
alchemyCount.max = max;
|
m_AlchemyCounts[config.AlchemyQuality] = alchemyCount;
|
}
|
}
|
else
|
{
|
m_AlchemyCounts[config.AlchemyQuality] = new AlchemyCount()
|
{
|
min = min,
|
max = max,
|
};
|
}
|
}
|
}
|
|
{
|
var funcConfig = FuncConfigConfig.Get("alchemySuccess");
|
alchemySuccRate = funcConfig.Numerical3;
|
|
var json = LitJson.JsonMapper.ToObject(funcConfig.Numerical2);
|
foreach (var key in json.Keys)
|
{
|
var quality = int.Parse(key);
|
m_AlchemyQualityLucks.Add(quality, int.Parse(json[key].ToString()));
|
}
|
}
|
|
{
|
var configs = AlchemyConfig.GetValues();
|
foreach (var config in configs)
|
{
|
m_AlchemyMaterials.Add(config.ID, new List<Item>());
|
var dict = ConfigParse.GetDic<int, int>(config.Material);
|
foreach (var key in dict.Keys)
|
{
|
m_AlchemyMaterials[config.ID].Add(new Item()
|
{
|
id = key,
|
count = dict[key],
|
});
|
}
|
}
|
}
|
}
|
|
public bool TryGetAlchemyStartTime(int alchemyId, out uint tick)
|
{
|
return m_AlchemyTimes.TryGetValue(alchemyId, out tick);
|
}
|
|
public bool TryGetAlchemyCount(int alchemyId, out AlchemyCount alchemyCount)
|
{
|
var config = AlchemyConfig.Get(alchemyId);
|
if (config == null)
|
{
|
alchemyCount = default(AlchemyCount);
|
return false;
|
}
|
if (config.AlchemType == (int)AlchemyType.Fairy)
|
{
|
alchemyCount = AlchemyCount.one;
|
return true;
|
}
|
return m_AlchemyCounts.TryGetValue(config.AlchemyQuality, out alchemyCount);
|
}
|
|
public bool TryGetAlchemyMaterials(int alchemyId, out List<Item> items)
|
{
|
return m_AlchemyMaterials.TryGetValue(alchemyId, out items);
|
}
|
|
public float GetAlchemySuccRate(int alchemyId)
|
{
|
var config = AlchemyConfig.Get(alchemyId);
|
if (config == null)
|
{
|
return 0f;
|
}
|
if (config.AlchemType == (int)AlchemyType.Fairy)
|
{
|
return 10000f;
|
}
|
var itemConfig = ItemConfig.Get(config.AlchemItemID);
|
var luckValue = PlayerDatas.Instance.extersion.luckValue;
|
return GetAlchemySuccRate(stoveLevel, itemConfig.LV, luckValue);
|
}
|
|
public float GetAlchemySuccRate(int stoveLevel, int itemLevel, int luck)
|
{
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("alchemyLV", stoveLevel);
|
Equation.Instance.AddKeyValue("alchemyQuality", itemLevel);
|
Equation.Instance.AddKeyValue("curLuckValue", luck);
|
var qualityNeedLuck = m_AlchemyQualityLucks.ContainsKey(itemLevel) ? m_AlchemyQualityLucks[itemLevel] : 0;
|
Equation.Instance.AddKeyValue("qualityNeedLuck", qualityNeedLuck);
|
return Equation.Instance.Eval<float>(alchemySuccRate);
|
}
|
|
public bool IsGraspRecipe(int alchemyId)
|
{
|
return m_AlchemyTimes.ContainsKey(alchemyId);
|
}
|
|
public void ReceivePackage(HA3BF_tagMCPlayerStoveMsg package)
|
{
|
for (int i = 0; i < package.StoveCnt; i++)
|
{
|
var data = package.InfoList[i];
|
m_AlchemyTimes[(int)data.AlchemyID] = data.StartTime;
|
}
|
|
stoveLevel = package.StoveLV;
|
stoveExp = (int)package.StoveExp;
|
|
if (package.ItemID != 0)
|
{
|
if (package.ItemCnt > 0)//炼丹成功
|
{
|
|
}
|
else//炼丹失败
|
{
|
|
}
|
}
|
|
if (alchemyStateRefresh != null)
|
{
|
alchemyStateRefresh();
|
}
|
}
|
|
public override void UnInit()
|
{
|
}
|
}
|
|
public enum AlchemyType
|
{
|
Normal = 1,
|
Fairy = 2,
|
}
|
|
public struct AlchemyCount
|
{
|
public int min;
|
public int max;
|
|
public static readonly AlchemyCount one = new AlchemyCount()
|
{
|
min = 1,
|
max = 1,
|
};
|
}
|
}
|