using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class DungeonTargetBehaviour : MonoBehaviour { [SerializeField] Text descText; [SerializeField] List m_TargetDescs; [SerializeField] List m_TargetNums; private Dungeon dungeonInfo; DungeonModel m_Model; DungeonModel model { get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel()); } } public void Init(Dungeon dungeon) { dungeonInfo = dungeon; UpdateMissionEvent(); } public void Init(int mapId, int lineId = 0) { Init(new Dungeon() { mapId = mapId, lineId = lineId, }); } private void OnEnable() { model.updateMissionEvent += UpdateMissionEvent; model.onCollectNpcInfoRefresh += UpdateMissionEvent; model.onAttackNpcInfoRefresh += UpdateMissionEvent; } private void UpdateMissionEvent() { if (dungeonInfo.mapId == 0) return; var dateMapId = model.GetDataMapIdByMapId(dungeonInfo.mapId); var hintId = model.GetDungeonHintId(dateMapId, dungeonInfo.lineId); var config = DungeonHintConfig.Get(hintId); m_TargetDescs[0].SetActive(config.targetNum >= 1); m_TargetDescs[1].SetActive(config.targetNum >= 2); m_TargetDescs[2].SetActive(config.targetNum >= 3); var step = Mathf.Clamp(model.mission.step, 1, int.MaxValue) - 1; if (config.targetNum >= 1) { var desc = config.targetDescription1[step < config.targetDescription1.Length ? step : 0]; var npcId = config.NPC1ID.Length == 0 ? 0 : config.NPC1ID[step < config.NPC1ID.Length ? step : 0]; var targetValue = config.targetValue1.Length == 0 ? 0 : config.targetValue1[step < config.targetValue1.Length ? step : 0]; GetTargetInfo(0, desc, targetValue, step, config.targetType1, npcId, config.NPC1ID); } if (config.targetNum >= 2) { var desc = config.targetDescription2[step < config.targetDescription2.Length ? step : 0]; var npcId = config.NPC2ID.Length == 0 ? 0 : config.NPC2ID[step < config.NPC2ID.Length ? step : 0]; var targetValue = config.targetValue2.Length == 0 ? 0 : config.targetValue2[step < config.targetValue2.Length ? step : 0]; GetTargetInfo(1, desc, targetValue, step, config.targetType2, npcId, config.NPC2ID); } if (config.targetNum >= 3) { var desc = config.targetDescription3[step < config.targetDescription2.Length ? step : 0]; var npcId = config.NPC3ID.Length == 0 ? 0 : config.NPC3ID[step < config.NPC3ID.Length ? step : 0]; var targetValue = config.targetValue3.Length == 0 ? 0 : config.targetValue3[step < config.targetValue3.Length ? step : 0]; GetTargetInfo(2, desc, targetValue, step, config.targetType3, npcId, config.NPC3ID); } switch (dateMapId) { case HazyGrassModel.FAIRY_DATAMAP: case HazyGrassModel.REIKI_DATAMAP: break; default: descText.text = config.Info.Length > step ? config.Info[step] : config.Info[0]; break; } } private void GetTargetInfo(int _index, string desc, int _targetValue, int _targetStep, int _targetType, int npcId, int[] npcIds) { m_TargetDescs[_index].text = desc; m_TargetNums[_index].text = string.Empty; switch ((DungeonTargetType)_targetType) { case DungeonTargetType.NPC: int killCnt = 0; if (npcId != 0) { var npcConfig = NPCConfig.Get(npcId); desc = desc.Replace("@NPCName@", npcConfig.charName); if (model.mission.npc != null) { for (int i = 0; i < model.mission.npc.Length; i++) { var npcInfo = model.mission.npc[i]; if (npcInfo.NPCID == npcId) { killCnt = npcInfo.killCnt; break; } } } } if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(killCnt, "/", _targetValue); break; } m_TargetNums[_index].text = killCnt.ToString(); break; case DungeonTargetType.Exp: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(UIHelper.ReplaceLargeNum((ulong)model.mission.totalExp), "/", UIHelper.ReplaceLargeNum((ulong)_targetValue)); break; } m_TargetNums[_index].text = StringUtility.Contact(UIHelper.ReplaceLargeNum((ulong)model.mission.totalExp), model.mission.isFullExp == 1 ? StringUtility.Contact(" ", Language.Get("FullExp")) : string.Empty); break; case DungeonTargetType.Score: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.score, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.score.ToString(); break; case DungeonTargetType.Money: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.money, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.money.ToString(); break; case DungeonTargetType.Wave: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.wheel, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.wheel.ToString(); break; case DungeonTargetType.NpcTotal: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.npcTotal, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.npcTotal.ToString(); break; case DungeonTargetType.Stage: if (_targetValue > 0) { m_TargetNums[_index].text = StringUtility.Contact(model.mission.step, "/", _targetValue); break; } m_TargetNums[_index].text = model.mission.step.ToString(); break; case DungeonTargetType.Collect: var collectCount = 0; for (int i = 0; i < npcIds.Length; i++) { collectCount += model.GetDugneonNpcCollectCount(npcIds[i]); } if (_targetValue > 0) { var label = UIHelper.AppendColor(collectCount >= _targetValue ? TextColType.LightYellow : TextColType.Green , collectCount.ToString()); m_TargetNums[_index].text = StringUtility.Contact(label, "/", _targetValue); break; } m_TargetNums[_index].text = collectCount.ToString(); break; case DungeonTargetType.AttackCount: var attackCount = model.GetDungeonNpcAttackCount(npcId); if (_targetValue > 0) { var label = UIHelper.AppendColor(attackCount >= _targetValue ? TextColType.LightYellow : TextColType.Green , attackCount.ToString()); m_TargetNums[_index].text = StringUtility.Contact(label, "/", _targetValue); break; } m_TargetNums[_index].text = attackCount.ToString(); break; } } private void OnDisable() { model.updateMissionEvent -= UpdateMissionEvent; model.onCollectNpcInfoRefresh -= UpdateMissionEvent; model.onAttackNpcInfoRefresh -= UpdateMissionEvent; } } }