public IEnumerable <SpecialAbility> EnumerateSpecialAbilities() { if (SpecialAbilities == null) { yield break; } for (var index = 0; index < SpecialAbilities.Length; index++) { SpecialAbility ability = SpecialAbilities[index]; yield return(ability); } }
public static bool IsRuleBreaker(SpecialAbility ability) { for (var index = 0; index < PetTrainingHelper.RuleBreakers.Length; index++) { var abil = PetTrainingHelper.RuleBreakers[index]; if (abil == ability) { return(true); } } return(false); }
public void RemoveAbility(SpecialAbility ability) { if (SpecialAbilities == null || !SpecialAbilities.Any(a => a == ability)) { return; } var list = SpecialAbilities.ToList(); list.Remove(ability); RemovePetAdvancement(ability); SpecialAbilities = list.ToArray(); ColUtility.Free(list); }
public bool HasSpecialAbility(SpecialAbility ability) { bool any = false; for (var index = 0; index < SpecialAbilities.Length; index++) { var a = SpecialAbilities[index]; if (a == ability) { any = true; break; } } return(SpecialAbilities != null && any); }
public static bool CheckThinkTrigger(BaseCreature bc) { var combatant = bc.Combatant; var profile = PetTrainingHelper.GetAbilityProfile(bc); if (combatant is Mobile) { if (profile != null) { SpecialAbility ability = null; var abilties = profile.EnumerateSpecialAbilities().Where(m => m.TriggerOnThink && !m.IsInCooldown(bc)).ToArray(); if (abilties != null && abilties.Length > 0) { ability = abilties[Utility.Random(abilties.Length)]; } if (ability != null) { int d = 0; ability.Trigger(bc, (Mobile)combatant, ref d); } } } else { SpecialAbility ability = null; var abilties = profile.EnumerateSpecialAbilities().Where(m => m.TriggerOnThink && !m.IsInCooldown(bc) && !m.RequiresCombatant).ToArray(); if (abilties != null && abilties.Length > 0) { ability = abilties[Utility.Random(abilties.Length)]; } if (ability != null) { int d = 0; return(ability.Trigger(bc, bc, ref d)); } } return(false); }
public IEnumerable <object> EnumerateAllAbilities() { if (MagicalAbility != MagicalAbility.None) { for (var index = 0; index < PetTrainingHelper.MagicalAbilities.Length; index++) { MagicalAbility abil = PetTrainingHelper.MagicalAbilities[index]; if ((MagicalAbility & abil) != 0) { yield return(abil); } } } if (SpecialAbilities != null) { for (var index = 0; index < SpecialAbilities.Length; index++) { SpecialAbility abil = SpecialAbilities[index]; yield return(abil); } } if (AreaEffects != null) { for (var index = 0; index < AreaEffects.Length; index++) { AreaEffect effect = AreaEffects[index]; yield return(effect); } } if (WeaponAbilities != null) { for (var index = 0; index < WeaponAbilities.Length; index++) { WeaponAbility abil = WeaponAbilities[index]; yield return(abil); } } }
public bool AddAbility(SpecialAbility ability, bool advancement = true) { if (SpecialAbilities == null) { SpecialAbilities = new[] { ability }; } else { bool any = false; for (var index = 0; index < SpecialAbilities.Length; index++) { var a = SpecialAbilities[index]; if (a == ability) { any = true; break; } } if (!any) { SpecialAbility[] temp = SpecialAbilities; SpecialAbilities = new SpecialAbility[temp.Length + 1]; for (int i = 0; i < temp.Length; i++) { SpecialAbilities[i] = temp[i]; } SpecialAbilities[temp.Length] = ability; } } OnAddAbility(ability, advancement); return(true); }
public bool AddAbility(SpecialAbility ability, bool advancement = true) { if (SpecialAbilities == null) { SpecialAbilities = new SpecialAbility[] { ability }; } else if (!SpecialAbilities.Any(a => a == ability)) { var temp = SpecialAbilities; SpecialAbilities = new SpecialAbility[temp.Length + 1]; for (int i = 0; i < temp.Length; i++) { SpecialAbilities[i] = temp[i]; } SpecialAbilities[temp.Length] = ability; } OnAddAbility(ability, advancement); return(true); }
public void RemoveAbility(SpecialAbility ability) { bool any = false; for (var index = 0; index < SpecialAbilities.Length; index++) { var a = SpecialAbilities[index]; if (a == ability) { any = true; break; } } if (SpecialAbilities == null || !any) { return; } List <SpecialAbility> list = new List <SpecialAbility>(); for (var index = 0; index < SpecialAbilities.Length; index++) { var specialAbility = SpecialAbilities[index]; list.Add(specialAbility); } list.Remove(ability); RemovePetAdvancement(ability); SpecialAbilities = list.ToArray(); ColUtility.Free(list); }
public bool HasSpecialAbility(SpecialAbility ability) { return(SpecialAbilities != null && SpecialAbilities.Any(a => a == ability)); }
public static bool CheckCombatTrigger(Mobile attacker, Mobile defender, ref int damage, DamageType type) { if (defender == null) { return(false); } if (attacker is BaseCreature && !((BaseCreature)attacker).Summoned) { var bc = attacker as BaseCreature; var profile = PetTrainingHelper.GetAbilityProfile(bc); if (profile != null) { SpecialAbility ability = null; var abilties = profile.EnumerateSpecialAbilities().Where(m => (type == DamageType.Melee && m.TriggerOnDoMeleeDamage) || (type >= DamageType.Spell && m.TriggerOnDoSpellDamage) && !m.IsInCooldown(attacker)).ToArray(); if (abilties != null && abilties.Length > 0) { ability = abilties[Utility.Random(abilties.Length)]; } if (ability != null) { return(ability.Trigger(bc, defender, ref damage)); } } return(false); } if (defender is BaseCreature && !((BaseCreature)defender).Summoned) { var bc = defender as BaseCreature; var profile = PetTrainingHelper.GetAbilityProfile(bc); if (profile != null) { SpecialAbility ability = null; var abilties = profile.EnumerateSpecialAbilities().Where(m => (type == DamageType.Melee && m.TriggerOnGotMeleeDamage) || (type >= DamageType.Spell && m.TriggerOnGotSpellDamage) && !m.IsInCooldown(attacker)).ToArray(); if (abilties != null && abilties.Length > 0) { ability = abilties[Utility.Random(abilties.Length)]; } if (ability != null) { int d = 0; return(ability.Trigger(bc, attacker, ref d)); } } } return(false); }
public AbilityProfile(BaseCreature bc, GenericReader reader) { int version = reader.ReadInt(); Creature = bc; switch (version) { case 0: DamageIndex = -1; break; case 1: DamageIndex = reader.ReadInt(); break; } MagicalAbility = (MagicalAbility)reader.ReadInt(); TokunoTame = reader.ReadBool(); RegenHits = reader.ReadInt(); RegenStam = reader.ReadInt(); RegenMana = reader.ReadInt(); int count = reader.ReadInt(); SpecialAbilities = new SpecialAbility[count]; for (int i = 0; i < count; i++) { SpecialAbilities[i] = SpecialAbility.Abilities[reader.ReadInt()]; } count = reader.ReadInt(); AreaEffects = new AreaEffect[count]; for (int i = 0; i < count; i++) { AreaEffects[i] = AreaEffect.Effects[reader.ReadInt()]; } count = reader.ReadInt(); WeaponAbilities = new WeaponAbility[count]; for (int i = 0; i < count; i++) { WeaponAbilities[i] = WeaponAbility.Abilities[reader.ReadInt()]; } count = reader.ReadInt(); for (int i = 0; i < count; i++) { if (Advancements == null) { Advancements = new List <object>(); } switch (reader.ReadInt()) { case 1: Advancements.Add((MagicalAbility)reader.ReadInt()); break; case 2: Advancements.Add(SpecialAbility.Abilities[reader.ReadInt()]); break; case 3: Advancements.Add(AreaEffect.Effects[reader.ReadInt()]); break; case 4: Advancements.Add(WeaponAbility.Abilities[reader.ReadInt()]); break; case 5: Advancements.Add((SkillName)reader.ReadInt()); break; } } }
public bool IsRuleBreaker(SpecialAbility ability) { return(PetTrainingHelper.RuleBreakers.Any(abil => abil == ability)); }
public virtual void Serialize(GenericWriter writer) { writer.Write(1); writer.Write(DamageIndex); writer.Write((int)MagicalAbility); writer.Write(TokunoTame); writer.Write(RegenHits); writer.Write(RegenStam); writer.Write(RegenMana); writer.Write(SpecialAbilities != null ? SpecialAbilities.Length : 0); if (SpecialAbilities != null) { for (var index = 0; index < SpecialAbilities.Length; index++) { SpecialAbility abil = SpecialAbilities[index]; writer.Write(Array.IndexOf(SpecialAbility.Abilities, abil)); } } writer.Write(AreaEffects != null ? AreaEffects.Length : 0); if (AreaEffects != null) { for (var index = 0; index < AreaEffects.Length; index++) { AreaEffect abil = AreaEffects[index]; writer.Write(Array.IndexOf(AreaEffect.Effects, abil)); } } writer.Write(WeaponAbilities != null ? WeaponAbilities.Length : 0); if (WeaponAbilities != null) { for (var index = 0; index < WeaponAbilities.Length; index++) { WeaponAbility abil = WeaponAbilities[index]; writer.Write(Array.IndexOf(WeaponAbility.Abilities, abil)); } } writer.Write(Advancements != null ? Advancements.Count : 0); if (Advancements != null) { for (var index = 0; index < Advancements.Count; index++) { object o = Advancements[index]; if (o is MagicalAbility ability) { writer.Write(1); writer.Write((int)ability); } else if (o is SpecialAbility specialAbility) { writer.Write(2); writer.Write(Array.IndexOf(SpecialAbility.Abilities, specialAbility)); } else if (o is AreaEffect effect) { writer.Write(3); writer.Write(Array.IndexOf(AreaEffect.Effects, effect)); } else if (o is WeaponAbility weaponAbility) { writer.Write(4); writer.Write(Array.IndexOf(WeaponAbility.Abilities, weaponAbility)); } else if (o is SkillName skillName) { writer.Write(5); writer.Write((int)skillName); } else { writer.Write(0); } } } }