using System;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
///
/// 对所有技能数据进行处理和缓存的类
///
public class SkillHelper : Singleton
{
private Dictionary m_SkillInfoDict;
private Dictionary> m_SkillToSpSkill;
public void Init()
{
if (m_SkillInfoDict == null)
{
m_SkillInfoDict = new Dictionary();
}
if (m_SkillToSpSkill == null)
{
m_SkillToSpSkill = new Dictionary>();
}
Snxxz.UI.TreasureModel _model = Snxxz.UI.ModelCenter.Instance.GetModel();
_model.potentialLevelUpdate += OnSpSkillChange;
}
public void OnSpSkillChange(int skillTypeID, int level)
{
//Debug.LogFormat("# sp技能[{0}]发生了改变: {1} #", skillTypeID, level);
int _skillID = skillTypeID + level - 1;
SkillConfig _skill = Config.Instance.Get(_skillID);
//Debug.LogFormat("# -- 关联的技能id: {0}", _skill.ExAttr1);
// 关联的技能
if (!m_SkillToSpSkill.ContainsKey(_skill.ExAttr1))
{
List _spSkillList = new List();
m_SkillToSpSkill.Add(_skill.ExAttr1, _spSkillList);
}
bool _needCreate = true;
for (int i = m_SkillToSpSkill[_skill.ExAttr1].Count - 1; i >= 0; --i)
{
if (m_SkillToSpSkill[_skill.ExAttr1][i].config.SkillTypeID == skillTypeID)
{
_needCreate = false;
//Debug.LogFormat("# -- 此技能已经存在: {0} 的sp技能列表中", _skill.ExAttr1);
if (m_SkillToSpSkill[_skill.ExAttr1][i].config.SkillLV < level)
{
//Debug.LogFormat("# -- 但是等级发生了改变, 这里删除旧的", _skill.ExAttr1);
m_SkillToSpSkill[_skill.ExAttr1].RemoveAt(i);
_needCreate = true;
}
}
}
if (_needCreate)
{
SkillInfo _skillInfo = Get(_skillID);
m_SkillToSpSkill[_skill.ExAttr1].Add(_skillInfo);
#if UNITY_EDITOR
Debug.LogFormat("# -- 为技能: {0} 创建sp技能: {1}", _skill.ExAttr1, _skillID);
#endif
}
}
public List GetSpSkill(int skillID)
{
if (m_SkillToSpSkill.ContainsKey(skillID))
{
return m_SkillToSpSkill[skillID];
}
return null;
}
public SkillInfo Get(int skillID)
{
SkillInfo _info = null;
if (!m_SkillInfoDict.TryGetValue(skillID, out _info))
{
_info = new SkillInfo(skillID);
m_SkillInfoDict.Add(skillID, _info);
}
return _info;
}
public class SkillInfo
{
///
/// 技能配置
///
public SkillConfig config;
///
/// 插帧文件
///
public SoSkill soFile;
///
/// 效果值, 从SkillConfig抽出的配置
///
public Dictionary effectValue;
public bool HasHitEvent { get; private set; }
///
/// 构造
///
/// 技能id
public SkillInfo(int skillID)
{
effectValue = new Dictionary();
soFile = ScriptableObjectLoader.LoadSoSkill(skillID);
if (soFile)
{
HasHitEvent = soFile.animationEventList.Count > 0;
if (HasHitEvent)
{
HasHitEvent = false;
SoConfigBase _soConfig = null;
int _param;
int _id;
SoSkill.E_AttackType _type;
for (int i = 0; i < soFile.animationEventList.Count; ++i)
{
if (soFile.animationEventList[i].frameEventType != E_FrameEventType.OnSkillEvent)
{
continue;
}
_soConfig = null;
_param = soFile.animationEventList[i].intParam;
_id = SoSkill.GetFrameEventId(_param);
_type = SoSkill.GetAttactType(_param);
if (_type == SoSkill.E_AttackType.Sweep)
{
_soConfig = ScriptableObjectLoader.LoadSoSweepHit(_id);
}
else if (_type == SoSkill.E_AttackType.FlyObject)
{
_soConfig = ScriptableObjectLoader.LoadSoFlyObject(_id);
}
if (_soConfig != null && _soConfig.floodPercent != 0)
{
HasHitEvent = true;
break;
}
}
}
}
config = Config.Instance.Get(skillID);
if (config != null)
{
if (config.Effect1 > 0)
{
EffectValue _effectValue = new EffectValue()
{
value1 = config.EffectValue11,
value2 = config.EffectValue12,
value3 = config.EffectValue13
};
effectValue[config.Effect1] = _effectValue;
}
if (config.Effect2 > 0)
{
EffectValue _effectValue = new EffectValue()
{
value1 = config.EffectValue21,
value2 = config.EffectValue22,
value3 = config.EffectValue23
};
effectValue[config.Effect2] = _effectValue;
}
if (config.Effect3 > 0)
{
EffectValue _effectValue = new EffectValue()
{
value1 = config.EffectValue31,
value2 = config.EffectValue32,
value3 = config.EffectValue33
};
effectValue[config.Effect3] = _effectValue;
}
if (config.Effect4 > 0)
{
EffectValue _effectValue = new EffectValue()
{
value1 = config.EffectValue41,
value2 = config.EffectValue42,
value3 = config.EffectValue43
};
effectValue[config.Effect4] = _effectValue;
}
if (config.Effect5 > 0)
{
EffectValue _effectValue = new EffectValue()
{
value1 = config.EffectValue51,
value2 = config.EffectValue52,
value3 = config.EffectValue53
};
effectValue[config.Effect5] = _effectValue;
}
if (config.Effect6 > 0)
{
EffectValue _effectValue = new EffectValue()
{
value1 = config.EffectValue61,
value2 = config.EffectValue62,
value3 = config.EffectValue63
};
effectValue[config.Effect5] = _effectValue;
}
}
}
}
///
/// 效果值类
///
public struct EffectValue
{
public int value1;
public int value2;
public int value3;
}
}