using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using TableConfig;
|
using System;
|
|
namespace Snxxz.UI
|
{
|
public class TalentModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize
|
{
|
Dictionary<int, TalentSkill> talentSkillDict = new Dictionary<int, TalentSkill>();
|
Dictionary<int, Dictionary<int, List<int>>> talentSkills = new Dictionary<int, Dictionary<int, List<int>>>();
|
|
int m_SelectSeries;
|
public int selectSeries
|
{
|
get { return m_SelectSeries; }
|
set
|
{
|
if (m_SelectSeries != value && OnSelectSeriesEvent != null)
|
{
|
m_SelectSeries = value;
|
OnSelectSeriesEvent();
|
}
|
m_SelectSeries = value;
|
}
|
}
|
int m_SelectTalentType;
|
public int selectTalentType
|
{
|
get { return m_SelectTalentType; }
|
set
|
{
|
if (m_SelectTalentType != value && OnSelectTalentTypeEvnet != null)
|
{
|
m_SelectTalentType = value;
|
OnSelectTalentTypeEvnet();
|
}
|
m_SelectTalentType = value;
|
}
|
}
|
int m_SelectSkill;
|
public int selectSkill
|
{
|
get { return m_SelectSkill; }
|
set
|
{
|
if (m_SelectSkill != value && OnSelectSkillEvent != null)
|
{
|
m_SelectSkill = value;
|
OnSelectSkillEvent();
|
}
|
m_SelectSkill = value;
|
}
|
}
|
|
public event Action OnSelectTalentTypeEvnet;
|
public event Action OnSelectSeriesEvent;
|
public event Action OnSelectSkillEvent;
|
public event Action talentPointUpdate;
|
public event Action<int> talentSkillUpdate;
|
|
public override void Init()
|
{
|
//ParseConfig();
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
foreach (var talent in talentSkillDict.Values)
|
{
|
talent.level = 0;
|
}
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
public override void UnInit()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
}
|
|
private void OnFuncStateChangeEvent(int _id)
|
{
|
if (_id == (int)FuncOpenEnum.Talent)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
void ParseConfig()
|
{
|
var configs = Config.Instance.GetAllValues<TalentConfig>();
|
for (int i = 0; i < configs.Count; i++)
|
{
|
var skillId = configs[i].SkillId;
|
var skillConfig = Config.Instance.Get<SkillConfig>(skillId);
|
TalentSkill talent;
|
if (!TryGetTalent(skillConfig.SkillTypeID, out talent))
|
{
|
talent = new TalentSkill(skillConfig.SkillTypeID, skillConfig.SkillMaxLV);
|
talent.level = 0;
|
talentSkillDict.Add(skillConfig.SkillTypeID, talent);
|
|
Dictionary<int, List<int>> dict = null;
|
if (!talentSkills.TryGetValue(skillConfig.UseType, out dict))
|
{
|
dict = new Dictionary<int, List<int>>();
|
talentSkills.Add(skillConfig.UseType, dict);
|
}
|
List<int> list = null;
|
var type = configs[i].series * 10 + configs[i].talentType;
|
if (!dict.TryGetValue(type, out list))
|
{
|
list = new List<int>();
|
dict.Add(type, list);
|
}
|
list.Add(skillConfig.SkillTypeID);
|
}
|
}
|
}
|
|
public bool TryGetTalents(int job, int series, int talentType, out List<int> talents)
|
{
|
talents = null;
|
Dictionary<int, List<int>> dict = null;
|
var _job = (int)Math.Pow(2, job);
|
talentSkills.TryGetValue(_job, out dict);
|
if (null != dict)
|
{
|
return dict.TryGetValue(series * 10 + talentType, out talents);
|
}
|
return false;
|
}
|
|
public bool TryGetTalent(int talentId,out TalentSkill talent)
|
{
|
return talentSkillDict.TryGetValue(talentId, out talent);
|
}
|
|
public int GetTalentTypeTotalPoint(int series, int talentType)
|
{
|
var job = (int)Math.Pow(PlayerDatas.Instance.baseData.Job, 2);
|
List<int> list;
|
var point = 0;
|
if (TryGetTalents(job, series, talentType, out list))
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
TalentSkill talent;
|
if (TryGetTalent(list[i], out talent))
|
{
|
point += talent.level;
|
}
|
}
|
}
|
return point;
|
}
|
|
public bool SatisfyLevelUp(int talentId, out int error)
|
{
|
error = 0;
|
TalentSkill talent;
|
if (TryGetTalent(talentId, out talent))
|
{
|
if (talent.level >= talent.max)
|
{
|
error = 1;
|
return false;
|
}
|
if (talentPoint <= 0)
|
{
|
error = 2;
|
return false;
|
}
|
var talentConfig = Config.Instance.Get<TalentConfig>(talent.skillId + talent.level);
|
if (talentConfig.property != 0)
|
{
|
if (UIHelper.GetPropertyMapPlayerData((AttrEnum)talentConfig.property) < talentConfig.propertyValue)
|
{
|
error = 3;
|
return false;
|
}
|
}
|
if (talentConfig.seriesCondition != 0)
|
{
|
if (GetTalentTypeTotalPoint(talentConfig.series, talentConfig.seriesCondition) < talentConfig.point)
|
{
|
error = 4;
|
return false;
|
}
|
}
|
var skillConfig = Config.Instance.Get<SkillConfig>(talent.skillId + talent.level);
|
if (skillConfig.LearnSkillReq != 0)
|
{
|
TalentSkill learnTalent;
|
if (TryGetTalent(skillConfig.LearnSkillReq, out learnTalent))
|
{
|
if (learnTalent.level < skillConfig.LearnSkillLV)
|
{
|
error = 5;
|
return false;
|
}
|
}
|
}
|
}
|
return true;
|
}
|
|
public void ProcessLevelUpError(int error)
|
{
|
|
}
|
|
#region 服务端数据
|
public int talentPoint { get; private set; }
|
|
public void UpdateTalent()
|
{
|
|
UpdateRedpoint();
|
}
|
#endregion
|
|
#region 红点
|
Redpoint talentRedpoint = new Redpoint(103, 10303);
|
void UpdateRedpoint()
|
{
|
talentRedpoint.state = RedPointState.None;
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Talent))
|
{
|
return;
|
}
|
if (talentPoint > 0)
|
{
|
talentRedpoint.state = RedPointState.Simple;
|
}
|
}
|
#endregion
|
}
|
|
public class TalentSkill
|
{
|
public int skillId { get; private set; }
|
public int level { get; set; }
|
public int max { get; private set; }
|
|
public TalentSkill(int id, int maxLevel)
|
{
|
skillId = id;
|
max = maxLevel;
|
}
|
}
|
}
|