using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
namespace vnxbqy.UI
|
{
|
public class MainWinSkillController : Singleton<MainWinSkillController>
|
{
|
const int SKILL_COUNT_MAX = 8;
|
|
public bool enable { get; set; }
|
|
public readonly LogicStruct<SkillCD> skillcd0 = new LogicStruct<SkillCD>();
|
public readonly LogicStruct<SkillCD> skillcd1 = new LogicStruct<SkillCD>();
|
public readonly LogicStruct<SkillCD> skillcd2 = new LogicStruct<SkillCD>();
|
public readonly LogicStruct<SkillCD> skillcd3 = new LogicStruct<SkillCD>();
|
public readonly LogicStruct<SkillCD> skillcd4 = new LogicStruct<SkillCD>();
|
public readonly LogicStruct<SkillCD> skillcd5 = new LogicStruct<SkillCD>();
|
public readonly LogicStruct<SkillCD> skillcd6 = new LogicStruct<SkillCD>();
|
public readonly LogicStruct<SkillCD> skillcd7 = new LogicStruct<SkillCD>();
|
public readonly LogicStruct<SkillCD> skillcd8 = new LogicStruct<SkillCD>();
|
|
public readonly LogicBool forbid0 = new LogicBool();
|
public readonly LogicBool forbid1 = new LogicBool();
|
public readonly LogicBool forbid2 = new LogicBool();
|
public readonly LogicBool forbid3 = new LogicBool();
|
public readonly LogicBool forbid4 = new LogicBool();
|
public readonly LogicBool forbid5 = new LogicBool();
|
public readonly LogicBool forbid6 = new LogicBool();
|
public readonly LogicBool forbid7 = new LogicBool();
|
public readonly LogicBool forbid8 = new LogicBool();
|
|
Dictionary<int, int> skillPlaceMap = new Dictionary<int, int>();
|
Dictionary<int, int> placeSkillMap = new Dictionary<int, int>();
|
|
SkillModel model { get { return ModelCenter.Instance.GetModel<SkillModel>(); } }
|
|
public MainWinSkillController()
|
{
|
PlayerSkillDatas.OnRefreshSkill += OnSkillRefresh;
|
Skill.RefreshCD += OnSkillCDRefresh;
|
|
GA_Hero.OnStateEnter += OnSkillStateEnter;
|
GA_Hero.OnStateEnd += OnSkillStateEnd;
|
|
StatusMgr.OnGainCantCastSkillStatus += OnGainCantCastSkillStatus;
|
StatusMgr.OnReleaseCantCastSkillStatus += OnReleaseCantCastSkillStatus;
|
}
|
|
public void InitSkill()
|
{
|
skillPlaceMap.Clear();
|
placeSkillMap.Clear();
|
if(PlayerDatas.Instance.skill == null) return;
|
for (int i = 0; i < SKILL_COUNT_MAX; i++)
|
{
|
var skillData = PlayerDatas.Instance.skill.GetQuickSkillByPos(i);
|
placeSkillMap[i + 1] = skillData != null ? skillData.id : 0;
|
if (skillData != null)
|
{
|
skillPlaceMap[skillData.id] = i + 1;
|
}
|
}
|
|
var blinkSkill = PlayerDatas.Instance.skill.GetSKillById(190);
|
placeSkillMap[0] = blinkSkill != null ? blinkSkill.id : 0;
|
if (blinkSkill != null)
|
{
|
skillPlaceMap[blinkSkill.id] = 0;
|
}
|
|
//var skillXpId = model.GetXpSkillID();
|
//var skillXpData = PlayerDatas.Instance.skill.GetSKillById(skillXpId);
|
//placeSkillMap[8] = skillXpData != null ? skillXpData.id : 0;
|
//if (skillXpData != null)
|
//{
|
// skillPlaceMap[skillXpId] = 8;
|
//}
|
|
if (PlayerDatas.Instance.hero != null)
|
{
|
foreach (var skillId in skillPlaceMap.Keys)
|
{
|
if (PlayerDatas.Instance.hero.SkillMgr == null) break;
|
var skill = PlayerDatas.Instance.hero.SkillMgr.Get(skillId);
|
if (skill != null)
|
{
|
UpdateSkillExclusiveCountDown(skillId, skill.cd, skill.skillInfo.config.CoolDownTime * Constants.F_GAMMA);
|
}
|
}
|
}
|
|
UpdateSkillForbidStates();
|
}
|
|
public void Reset()
|
{
|
skillcd0.value = default(SkillCD);
|
skillcd1.value = default(SkillCD);
|
skillcd2.value = default(SkillCD);
|
skillcd3.value = default(SkillCD);
|
skillcd4.value = default(SkillCD);
|
skillcd5.value = default(SkillCD);
|
skillcd6.value = default(SkillCD);
|
skillcd7.value = default(SkillCD);
|
skillcd8.value = default(SkillCD);
|
|
forbid0.value = false;
|
forbid1.value = false;
|
forbid2.value = false;
|
forbid3.value = false;
|
forbid4.value = false;
|
forbid5.value = false;
|
forbid6.value = false;
|
forbid7.value = false;
|
forbid8.value = false;
|
|
skillPlaceMap.Clear();
|
placeSkillMap.Clear();
|
}
|
|
public LogicStruct<SkillCD> GetSkillCD(int index)
|
{
|
switch (index)
|
{
|
case 0:
|
return skillcd0;
|
case 1:
|
return skillcd1;
|
case 2:
|
return skillcd2;
|
case 3:
|
return skillcd3;
|
case 4:
|
return skillcd4;
|
case 5:
|
return skillcd5;
|
case 6:
|
return skillcd6;
|
case 7:
|
return skillcd7;
|
case 8:
|
return skillcd8;
|
default:
|
return null;
|
}
|
}
|
|
public LogicBool GetSkillForbid(int index)
|
{
|
switch (index)
|
{
|
case 0:
|
return forbid0;
|
case 1:
|
return forbid1;
|
case 2:
|
return forbid2;
|
case 3:
|
return forbid3;
|
case 4:
|
return forbid4;
|
case 5:
|
return forbid5;
|
case 6:
|
return forbid6;
|
case 7:
|
return forbid7;
|
case 8:
|
return forbid8;
|
default:
|
return null;
|
}
|
}
|
|
private void OnSkillRefresh()
|
{
|
InitSkill();
|
}
|
|
private void OnSkillCDRefresh(int skillId, float cd, float total)
|
{
|
UpdateSkillExclusiveCountDown(skillId, cd, total);
|
}
|
|
private void OnSkillStateEnter(float time)
|
{
|
UpdateSkillCommonCountDown(time);
|
}
|
|
private void OnSkillStateEnd()
|
{
|
UpdateSkillCommonCountDown(0);
|
}
|
|
private void OnGainCantCastSkillStatus(float duration)
|
{
|
UpdateSkillForbidStates();
|
}
|
|
private void OnReleaseCantCastSkillStatus()
|
{
|
UpdateSkillForbidStates();
|
}
|
|
private void UpdateSkillExclusiveCountDown(int skillId, float cd, float total)
|
{
|
ILSkillManager.Instance.OnSkillCDRefresh(skillId, cd, total);
|
if (skillPlaceMap.ContainsKey(skillId))
|
{
|
var place = skillPlaceMap[skillId];
|
var skillcd = GetSkillCD(place);
|
skillcd.value = skillcd.value.SetExclusiveCountDown(cd, total);
|
}
|
}
|
|
private void UpdateSkillCommonCountDown(float time)
|
{
|
for (int i = 0; i <= 8; i++)
|
{
|
if (placeSkillMap.ContainsKey(i) && placeSkillMap[i] != 0)
|
{
|
var skillcd = GetSkillCD(i);
|
skillcd.value = skillcd.value.SetCommonCountDown(time);
|
}
|
}
|
}
|
|
private void UpdateSkillForbidStates()
|
{
|
var forbid = !StatusMgr.Instance.CanCastSkill(PlayerDatas.Instance.baseData.PlayerID);
|
for (int i = 0; i <= 8; i++)
|
{
|
if (placeSkillMap.ContainsKey(i))
|
{
|
int _skillId = placeSkillMap[i];
|
var _tsModel = ModelCenter.Instance.GetModel<TreasureSkillModel>();
|
if (_tsModel.TryGetExpertSkill(_skillId, out _skillId))
|
{
|
int _level = 0;
|
if (_tsModel.TryGetExpertActiveLevel(_skillId, out _level))
|
{
|
_skillId += (_level - 1);
|
}
|
var _skillInfo = SkillHelper.Instance.Get(_skillId);
|
SkillHelper.EffectValue _effectValue;
|
if (_skillInfo.effectValue.TryGetValue(4093, out _effectValue))
|
{
|
if (forbid)
|
{
|
continue;
|
}
|
}
|
}
|
}
|
var skillForbid = GetSkillForbid(i);
|
skillForbid.value = forbid;
|
}
|
}
|
|
public struct SkillCD
|
{
|
public float exclusiveTotal;
|
public float exclusiveOverTime;
|
public float commonTotal;
|
public float commonOverTime;
|
|
public SkillCD SetCommonCountDown(float time)
|
{
|
commonTotal = time;
|
commonOverTime = Time.realtimeSinceStartup + time;
|
|
return this;
|
}
|
|
public SkillCD SetExclusiveCountDown(float cd, float total)
|
{
|
exclusiveTotal = total;
|
exclusiveOverTime = Time.realtimeSinceStartup + cd;
|
|
return this;
|
}
|
|
public bool IsCountDown()
|
{
|
if (exclusiveOverTime > Time.realtimeSinceStartup)
|
{
|
return true;
|
}
|
|
if (commonOverTime > Time.realtimeSinceStartup)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
public bool IsExclusiveCountDown()
|
{
|
if (exclusiveOverTime > Time.realtimeSinceStartup)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
public float GetCountDownFillAmount()
|
{
|
if (exclusiveOverTime > Time.realtimeSinceStartup)
|
{
|
return (exclusiveOverTime - Time.realtimeSinceStartup) / exclusiveTotal;
|
}
|
|
if (commonOverTime > Time.realtimeSinceStartup)
|
{
|
return (commonOverTime - Time.realtimeSinceStartup) / commonTotal;
|
}
|
|
return 0f;
|
}
|
|
public float GetCountDown()
|
{
|
if (exclusiveOverTime > Time.realtimeSinceStartup)
|
{
|
return exclusiveOverTime - Time.realtimeSinceStartup;
|
}
|
|
return 0f;
|
}
|
|
}
|
|
|
}
|
}
|