using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using DG.Tweening;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
namespace vnxbqy.UI
|
{
|
public class FairyLeagueResPointBehaviour : MonoBehaviour
|
{
|
|
[SerializeField] List<Button> m_ResPointBtns;
|
[SerializeField] List<Text> m_ResPointIds;
|
[SerializeField] List<Image> m_Crystals;
|
[SerializeField] List<Image> m_CrystalFlags;
|
[SerializeField] List<UIAlphaTween> m_AlphaTweens;
|
[SerializeField] Button m_FairyLeagueMapBtn;
|
[SerializeField] List<Button> m_BuffBtns;
|
[SerializeField] List<Image> m_BuffIcons;
|
[SerializeField] List<Text> m_CrystalRates;
|
|
[SerializeField] Sprite m_BlueCrystal;
|
[SerializeField] Sprite m_RedCrystal;
|
[SerializeField] Sprite m_GrayCrystal;
|
|
int NpcId = 0;
|
|
FairyLeagueModel m_Model;
|
FairyLeagueModel model
|
{
|
get
|
{
|
return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<FairyLeagueModel>());
|
}
|
}
|
|
private Dictionary<int, GActor> crystalActorDict = new Dictionary<int, GActor>();
|
|
private void Awake()
|
{
|
for (int i = 0; i < m_ResPointBtns.Count; i++)
|
{
|
int index = i;
|
m_ResPointBtns[i].onClick.AddListener(() =>
|
{
|
OnClickResPoint(index);
|
});
|
}
|
for (int i = 0; i < m_BuffBtns.Count; i++)
|
{
|
int index = i;
|
m_BuffBtns[i].onClick.AddListener(() =>
|
{
|
OnClickBuff(index);
|
});
|
}
|
|
m_FairyLeagueMapBtn.onClick.AddListener(OpenFairyLeagueMap);
|
}
|
|
private void OnEnable()
|
{
|
model.UpdateWarBuffEvent += UpdateBuffs;
|
model.UpdateWarCrystalEvent += UpdateWarCrystals;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
|
UpdateWarCrystals();
|
UpdateBuffs();
|
UpdateCrystalId();
|
}
|
|
|
|
private void OnDisable()
|
{
|
model.UpdateWarBuffEvent -= UpdateBuffs;
|
model.UpdateWarCrystalEvent -= UpdateWarCrystals;
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
|
crystalActorDict.Clear();
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType _type)
|
{
|
if (_type == PlayerDataType.Faction)
|
{
|
UpdateWarCrystals();
|
UpdateCrystalId();
|
}
|
}
|
|
private void UpdateCrystalId()
|
{
|
for (int i = 0; i < m_ResPointIds.Count; i++)
|
{
|
m_ResPointIds[i].text = (i + 1).ToString();
|
}
|
}
|
|
private void UpdateWarCrystals()
|
{
|
var _help = model.fairyLeagueHelp;
|
|
for (int i = 0; i < m_Crystals.Count; i++)
|
{
|
int _sortIndex = i;
|
if (model.crystalSortDict.ContainsKey((int)PlayerDatas.Instance.baseData.faction))
|
{
|
_sortIndex = model.crystalSortDict[(int)PlayerDatas.Instance.baseData.faction][i];
|
}
|
_sortIndex = Mathf.Max(1, _sortIndex);
|
var _npcId = model.fairyLeagueCrystals[_sortIndex - 1];
|
float _rate = 0;
|
if(model.TryGetCrystalRate(_npcId,out _rate))
|
{
|
m_CrystalRates[i].SetActive(true);
|
m_CrystalRates[i].text = Language.Get("FairyLeagueExtraCrystal", (_rate - 1) * 100);
|
}
|
else
|
{
|
m_CrystalRates[i].SetActive(false);
|
}
|
var _camp = _help.GetCrystalBelongCamp(_npcId);
|
m_Crystals[i].sprite = _camp == 0 ? m_GrayCrystal : _camp == (int)FairyCampType.Red ? m_RedCrystal : m_BlueCrystal;
|
m_CrystalFlags[i].SetSprite(_camp == 0 ? "GreyBottom" : _camp == (int)FairyCampType.Red ? "RedBottom" : "BlueBottom");
|
m_AlphaTweens[i].SetStartState();
|
m_AlphaTweens[i].enabled = false;
|
}
|
|
if (_help.FairyWarCrystalAtks == null)
|
{
|
return;
|
}
|
var _faction = PlayerDatas.Instance.baseData.faction;
|
int[] _selfCampCrystals = _help.fairyWarCrystalDict.ContainsKey((int)_faction) ? _help.fairyWarCrystalDict[(int)_faction] : null;
|
for (int i = 0; i < _help.FairyWarCrystalAtks.Length; i++)
|
{
|
var _crystalAtkNpc = _help.FairyWarCrystalAtks[i];
|
bool _atk = false;
|
if (_selfCampCrystals != null)
|
{
|
for (int j = 0; j < _selfCampCrystals.Length; j++)
|
{
|
if (_crystalAtkNpc == _selfCampCrystals[j])
|
{
|
_atk = true;
|
}
|
}
|
}
|
if (_atk)
|
{
|
CrystalAtk(model.GetCrystalIndex(_crystalAtkNpc), _faction == 1 ? 2 : 1);
|
}
|
}
|
}
|
|
private void UpdateBuffs()
|
{
|
var _help = model.fairyLeagueHelp;
|
for (int i = 0; i < m_BuffBtns.Count; i++)
|
{
|
if (_help.fairyWarBuffs == null || i >= _help.fairyWarBuffs.Length)
|
{
|
m_BuffBtns[i].SetActive(false);
|
continue;
|
}
|
m_BuffBtns[i].SetActive(true);
|
NPCConfig _npcCfg = NPCConfig.Get(_help.fairyWarBuffs[i].NPCID);
|
var _buffCfg = SkillConfig.Get(_npcCfg.Skill1);
|
if (_buffCfg != null)
|
{
|
m_BuffIcons[i].SetSprite(_buffCfg.IconName);
|
}
|
OnAtkBuff(i, _help.fairyWarBuffs[i].Atk == 1);
|
}
|
}
|
|
private void CrystalAtk(int _index, int _camp)
|
{
|
if (_index == -1)
|
{
|
return;
|
}
|
m_AlphaTweens[_index].enabled = true;
|
m_Crystals[_index].sprite = _camp == (int)FairyCampType.Red ? m_RedCrystal : m_BlueCrystal;
|
}
|
|
private void OnClickBuff(int _index)
|
{
|
var _help = model.fairyLeagueHelp;
|
if (_help.fairyWarBuffs == null || _index >= _help.fairyWarBuffs.Length)
|
{
|
return;
|
}
|
Vector2 _buffPos = model.crystalPosList[_help.fairyWarBuffs[_index].PosIndex];
|
var _hero = PlayerDatas.Instance.hero;
|
if (_hero != null)
|
{
|
_hero.Behaviour.StopHandupAI(true);
|
SnxxzGame.Instance.StartCoroutine(Co_HeroMoveToPos(new Vector3(_buffPos.x, 0, _buffPos.y),
|
_help.fairyWarBuffs[_index].NPCID));
|
}
|
}
|
|
private void OnAtkBuff(int _index, bool _onAtk)
|
{
|
|
}
|
|
private void OpenFairyLeagueMap()
|
{
|
WindowCenter.Instance.Open<FairyLeagueMapWin>();
|
}
|
|
private void OnClickResPoint(int index)
|
{
|
var _hero = PlayerDatas.Instance.hero;
|
if (_hero == null)
|
{
|
return;
|
}
|
int _sortIndex = index;
|
if (model.crystalSortDict.ContainsKey((int)PlayerDatas.Instance.baseData.faction))
|
{
|
_sortIndex = model.crystalSortDict[(int)PlayerDatas.Instance.baseData.faction][index];
|
}
|
_sortIndex = Mathf.Max(1, _sortIndex);
|
var _crystalNpc = model.fairyLeagueCrystals[_sortIndex - 1];
|
SnxxzGame.Instance.StartCoroutine(Co_HeroMoveToActor(_crystalNpc));
|
}
|
|
IEnumerator Co_HeroMoveToActor(int _npcId)
|
{
|
var _hero = PlayerDatas.Instance.hero;
|
while (_hero.SkillMgr.CurCastSkill != null &&
|
_hero.SkillMgr.CurCastSkill.SkillCompelete == false)
|
{
|
yield return null;
|
}
|
MapTransferUtility.Instance.MoveToNPC(_npcId);
|
}
|
|
IEnumerator Co_HeroMoveToPos(Vector3 _targetPos, int _npcId)
|
{
|
var _hero = PlayerDatas.Instance.hero;
|
while (_hero.SkillMgr.CurCastSkill != null &&
|
_hero.SkillMgr.CurCastSkill.SkillCompelete == false)
|
{
|
yield return null;
|
}
|
if (_hero != null)
|
{
|
NpcId = _npcId;
|
_targetPos.y = _hero.Pos.y;
|
_hero.OnPathFindStop -= OnHeroFindStop;
|
_hero.OnPathFindStop += OnHeroFindStop;
|
_hero.MoveToPosition(_targetPos);
|
}
|
}
|
|
private void OnHeroFindStop()
|
{
|
var _hero = PlayerDatas.Instance.hero;
|
if (_hero != null)
|
{
|
_hero.OnPathFindStop -= OnHeroFindStop;
|
}
|
|
NPCConfig _npcConfig = NPCConfig.Get(NpcId);
|
if (_npcConfig == null)
|
{
|
return;
|
}
|
|
GActor _npc = GAMgr.Instance.GetCloserNPC(_hero.Pos, NpcId);
|
if (_npc == null)
|
{
|
return;
|
}
|
|
float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, _npc.Pos);
|
float _chkDist = GeneralDefine.CloseNpcDist + _npcConfig.ModelRadius + 0.3f;
|
|
if (_chkDistSqrt <= Mathf.Pow(_chkDist, 2))
|
{
|
NPCInteractProcessor.InvokeEvent((E_NpcType)_npcConfig.NPCType, _npcConfig.NPCID, _npc.ServerInstID);
|
_hero.LockTarget = _npc;
|
_hero.SelectTarget = _npc;
|
Vector3 _npc2heroDir = MathUtility.ForwardXZ(_npc.Pos, _hero.Pos);
|
if (_npcConfig.AutomaticFace == 1)
|
{
|
_npc.Forward = -_npc2heroDir;
|
}
|
_hero.Forward = _npc2heroDir;
|
}
|
}
|
}
|
}
|