public void SelectAbility(Ability aAbility) { if(aAbility != null) { string abilityName = "Ability_" + aAbility.abilityName + "_Image"; for(int i = 0; i < m_Abilities.Count; i++) { if(m_Abilities[i].name == abilityName) { m_SelectedAbilityIndex = i; break; } } } }
private void Attack() { ///Get current ability if(m_Unit == null) { return; } Ability currentAbility = m_Unit.selectedAbility; if(currentAbility == null) { DebugUtils.LogWarning("Unit is missing an ability to attack with."); return; } ///Check the last ability with the current ability if(currentAbility != m_TriggeredAbility) { ///Cancelled attack? if(m_TriggeredAbility != null) { GameEventManager.InvokeEvent(new GameEventData(Time.time, GameEventID.UNIT_ATTACK_CANCELLED, GameEventType.UNIT, this, m_TriggeredAbility)); } m_CurrentTime = 0.0f; } ///Update time and ability. m_TriggeredAbility = currentAbility; ///Ability first started if(m_CurrentTime == 0.0f) { if (m_TriggeredAbility != null) { GameEventManager.InvokeEvent(new GameEventData(Time.time, GameEventID.UNIT_ATTACK_BEGIN, GameEventType.UNIT, this, m_TriggeredAbility)); } } m_CurrentTime += Time.deltaTime; ///Start executing ability if(m_CurrentTime > m_AttackWindup) { ///Execute ability event if (m_TriggeredAbility != null) { GameEventManager.InvokeEvent(new GameEventData(Time.time, GameEventID.UNIT_ATTACK_EXECUTE, GameEventType.UNIT, this, m_TriggeredAbility)); } DebugUtils.Log("Unit is executing an ability"); m_Unit.ExecuteAbility(); if(m_TriggeredAbility.abilityType != AbilityType.CHANNELED) { m_Motor.attackMotion = 0.0f; m_Motor.attackType = AttackType.NONE; if (m_TriggeredAbility != null) { GameEventManager.InvokeEvent(new GameEventData(Time.time, GameEventID.UNIT_ATTACK_FINISHED, GameEventType.UNIT, this, m_TriggeredAbility)); } } } else { m_Motor.attackMotion = 1.0f; m_Motor.attackType = m_Unit.selectedAbility.attackType; } }
protected virtual void Start() { UnitManager.Register(this); List<Ability> abilities = new List<Ability>(); IEnumerator<Ability> iter = m_Abilities.GetEnumerator(); while(iter.MoveNext()) { if(iter.Current == null) { continue; } abilities.Add(Instantiate(iter.Current) as Ability); } m_Abilities = abilities; UpdateAbilityReferences(); if (m_Abilities.Count > 0) { m_SelectedAbility = m_Abilities[0]; } m_Inventory = GetComponent<UnitInventory>(); }
public void SelectAbility(AbilityType aType) { IEnumerator<Ability> iter = m_Abilities.GetEnumerator(); while (iter.MoveNext()) { if (iter.Current == null) { continue; } if(iter.Current.abilityType == aType) { m_SelectedAbility = iter.Current; if(m_AbilityHud != null) { m_AbilityHud.SelectAbility(m_SelectedAbility); } return; } } }
public void SelectAbility(int aIndex) { if(aIndex >= 0 && aIndex < m_Abilities.Count) { m_SelectedAbility = m_Abilities[aIndex]; if (m_AbilityHud != null) { m_AbilityHud.SelectAbility(m_SelectedAbility); } } }
public void RemoveAbility(AbilityType aType) { IEnumerator<Ability> iter = m_Abilities.GetEnumerator(); while(iter.MoveNext()) { if(iter.Current == null) { continue; } if(aType == iter.Current.abilityType) { if(iter.Current == m_SelectedAbility) { if(m_Abilities.Count == 1) { m_SelectedAbility = null; } else { NextAbility(false); } } m_Abilities.Remove(iter.Current); break; } } UpdateAbilityReferences(); }
public void PreviousAbility(bool aCheckCooldown) { int count = m_Abilities.Count; if (count == 0 || count == 1) { return; } int index = 0; Ability ability = m_SelectedAbility; if (m_SelectedAbility != null) { while (index < count && ability != null) { ability = ability.previous; index++; if (ability.isOnCooldown == true && aCheckCooldown == true) { continue; } m_SelectedAbility = ability; if (m_AbilityHud != null) { m_AbilityHud.SelectAbility(m_SelectedAbility); } return; } } else if (m_Abilities.Count > 0) { m_SelectedAbility = m_Abilities[0]; } }
public void AddAbility(Ability aAbility) { if(aAbility == null) { return; } if ( m_Abilities.Any(Elemenet => Elemenet.abilityName == aAbility.abilityName)) { DebugUtils.LogWarning("Unit " + unitName + " already knows " + aAbility.abilityName); return; } aAbility = Instantiate(aAbility) as Ability; m_Abilities.Add(aAbility); UpdateAbilityReferences(); if(m_Abilities.Count > 0 && m_SelectedAbility == null) { m_SelectedAbility = m_Abilities[0]; if(m_AbilityHud != null) { m_AbilityHud.SelectAbility(m_SelectedAbility); } } }