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> talentSkills = new Dictionary<int, TalentSkill>();
|
Dictionary<int, TalentTree> talentTreeDict = new Dictionary<int, TalentTree>();
|
|
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 talentSkills.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;
|
talentSkills.Add(skillConfig.SkillTypeID, talent);
|
|
TalentTree talentTree;
|
if (!talentTreeDict.TryGetValue(skillConfig.UseType, out talentTree))
|
{
|
talentTree = new TalentTree();
|
talentTreeDict.Add(skillConfig.UseType, talentTree);
|
}
|
talentTree.Add(configs[i], skillConfig.SkillTypeID);
|
}
|
}
|
}
|
|
public bool TryGetTalents(int job, int talentType, int talentSeries, out List<int> talents)
|
{
|
talents = null;
|
TalentTree talentTree = null;
|
var _job = (int)Math.Pow(2, job);
|
talentTreeDict.TryGetValue(_job, out talentTree);
|
if (null != talentTree)
|
{
|
return talentTree.TryGetTalents(talentType, talentSeries, out talents);
|
}
|
return false;
|
}
|
|
public bool TryGetTalent(int talentId, out TalentSkill talent)
|
{
|
return talentSkills.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.maxLevel)
|
{
|
error = 1;
|
return false;
|
}
|
if (talentPoint <= 0)
|
{
|
error = 2;
|
return false;
|
}
|
var talentConfig = Config.Instance.Get<TalentConfig>(talent.skillId + talent.level);
|
if (talentConfig.requireSeriesPoint != 0)
|
{
|
if (GetTalentTypeTotalPoint(talentConfig.requireSeries, talentConfig.type) < talentConfig.requireSeriesPoint)
|
{
|
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 maxLevel { get; private set; }
|
|
public TalentSkill(int skillId, int maxLevel)
|
{
|
this.skillId = skillId;
|
this.maxLevel = maxLevel;
|
}
|
}
|
|
public class TalentSeries
|
{
|
public int series { get; private set; }
|
public List<int> talentSkills { get; private set; }
|
|
public TalentSeries(int series)
|
{
|
this.series = series;
|
talentSkills = new List<int>();
|
}
|
|
public void Add(int skillId)
|
{
|
if (talentSkills.Contains(skillId))
|
{
|
return;
|
}
|
talentSkills.Add(skillId);
|
}
|
}
|
|
public class TalentTree
|
{
|
Dictionary<int, List<TalentSeries>> talentSeriesDict = new Dictionary<int, List<TalentSeries>>();
|
|
public void Add(TalentConfig config, int skillId)
|
{
|
List<TalentSeries> list = null;
|
if (!talentSeriesDict.TryGetValue(config.type, out list))
|
{
|
list = new List<TalentSeries>();
|
talentSeriesDict.Add(config.type, list);
|
}
|
TalentSeries talentSeries = list.Find((x) =>
|
{
|
return x.series == config.series;
|
});
|
if (talentSeries == null)
|
{
|
talentSeries = new TalentSeries(config.series);
|
list.Add(talentSeries);
|
}
|
talentSeries.Add(skillId);
|
}
|
|
public bool TryGetTalents(int type, int series, out List<int> list)
|
{
|
list = null;
|
if (talentSeriesDict.ContainsKey(type))
|
{
|
var talentSeries = talentSeriesDict[type].Find((x) =>
|
{
|
return x.series == series;
|
});
|
if (talentSeries != null)
|
{
|
list = talentSeries.talentSkills;
|
return true;
|
}
|
}
|
return false;
|
}
|
}
|
}
|