public IEnumerator UpdateView() { while (true) { AbilityWrapper wrapper = m_entity.m_abilities.Find(a => a.HotkeySlot == m_hotkey); if (wrapper != null && (m_wrapper == null || wrapper.AbilityName != m_wrapper.AbilityName)) { m_wrapper = wrapper; m_icon.enabled = true; m_backgroundIcon.enabled = true; m_icon.sprite = wrapper.GetAbility().m_icon; m_backgroundIcon.sprite = wrapper.GetAbility().m_icon; } else if (wrapper == null) { m_wrapper = null; m_icon.enabled = false; m_backgroundIcon.enabled = false; } string hotkeyText = ""; if (m_entity is Player) { Rewired.Player player = ((Player)m_entity).m_rewiredPlayer; Rewired.Controller lastActive = player.controllers.GetLastActiveController(); if (lastActive != null && lastActive.type == Rewired.ControllerType.Mouse) { lastActive = player.controllers.Keyboard; } Rewired.ActionElementMap elementMap = player.controllers.maps.GetFirstElementMapWithAction( lastActive, "Hotkey " + m_hotkey, false); if (elementMap != null) { hotkeyText = elementMap.elementIdentifierName; } else { elementMap = player.controllers.maps.GetFirstElementMapWithAction("Hotkey " + m_hotkey, false); if (elementMap != null) { hotkeyText = elementMap.elementIdentifierName; } } } m_hotkeyText.text = hotkeyText; yield return(new WaitForSeconds(Constants.ABILITY_VIEW_REFRESH)); } }
public IEnumerator UpdateCooldown() { while (true) { if (m_wrapper != null) { float lastUse = m_wrapper.GetLastUseTime(); if (lastUse > 0) { float cooldown = m_wrapper.GetAbility().m_cooldowns.Find(c => c.TrainingLevel == m_wrapper.TrainingLevel).Value * 1000; float time = Time.time * 1000; if (time >= lastUse + cooldown && m_icon.fillAmount != 1) { m_icon.fillAmount = 1; } else if (time < lastUse + cooldown) { m_icon.fillAmount = 1 - (lastUse + cooldown - time) / cooldown; } } else { m_icon.fillAmount = 1; } } yield return(new WaitForSeconds(Constants.ABILITY_COOLDOWN_REFRESH)); } }
public void UseAbility(string p_ability) { AbilityWrapper wrapper = m_abilities.Find(a => a.AbilityName == p_ability); if (wrapper == null && wrapper.Learned) { return; } Ability ability = wrapper.GetAbility(); int cost = ability.m_manaCosts.Find(m => m.TrainingLevel == wrapper.TrainingLevel).Value; int leftoverMana = m_stats.GetStat(Stats.MP) - cost; if (leftoverMana >= 0 && wrapper.Use()) { m_stats.AddModifier(Stats.MP, -cost, 0); ability.Use(this, wrapper.TrainingLevel); if (wrapper.ChainedAbilities != null && wrapper.ChainedAbilities.Count > 0) { foreach (string chain in wrapper.ChainedAbilities) { AbilityWrapper chainWrapper = m_abilities.Find(a => a.AbilityName == chain); if (chainWrapper == null && chainWrapper.Learned) { continue; } Ability chainAbility = Ability.Get(chain); cost = chainAbility.m_manaCosts.Find(m => m.TrainingLevel == chainWrapper.TrainingLevel).Value; leftoverMana = m_stats.GetStat(Stats.MP) - cost; if (leftoverMana >= 0 && chainWrapper.Use()) { m_stats.AddModifier(Stats.MP, -cost, 0); chainAbility.Use(this, chainWrapper.TrainingLevel); } } } } }
public string GetDisplayName() { return(IsEmpty() ? "" : (AbilityWrapper != null ? AbilityWrapper.GetAbility().GetDisplayName() : SkillWrapper.GetSkill().GetDisplayName())); }