More abilities
This commit is contained in:
		| @@ -235,7 +235,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable | ||||
|     /// Changes the held item of the Pokemon. Returns the previously held item. | ||||
|     /// </summary> | ||||
|     [MustUseReturnValue] | ||||
|     IItem? SetHeldItem(IItem? item); | ||||
|     IItem? ForceSetHeldItem(IItem? item); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Removes the held item from the Pokemon. Returns the previously held item. | ||||
| @@ -243,6 +243,8 @@ public interface IPokemon : IScriptSource, IDeepCloneable | ||||
|     [MustUseReturnValue] | ||||
|     IItem? RemoveHeldItem(); | ||||
|  | ||||
|     bool HasItemBeenRemovedForBattle { get; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Removes the held item from the Pokemon for the duration of the battle. Returns the previously held item. | ||||
|     /// </summary> | ||||
| @@ -261,7 +263,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable | ||||
|     /// <summary> | ||||
|     /// Restores the held item of a Pokémon if it was temporarily removed. | ||||
|     /// </summary> | ||||
|     void RestoreStolenHeldItem(); | ||||
|     void RestoreRemovedHeldItem(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Makes the Pokemon uses its held item. Returns whether the item was consumed. | ||||
| @@ -788,7 +790,7 @@ public class PokemonImpl : ScriptSource, IPokemon | ||||
|     public bool HasHeldItem(StringKey itemName) => HeldItem?.Name == itemName; | ||||
|  | ||||
|     /// <inheritdoc /> | ||||
|     public IItem? SetHeldItem(IItem? item) | ||||
|     public IItem? ForceSetHeldItem(IItem? item) | ||||
|     { | ||||
|         var previous = HeldItem; | ||||
|         HeldItem = item; | ||||
| @@ -812,12 +814,15 @@ public class PokemonImpl : ScriptSource, IPokemon | ||||
|         return previous; | ||||
|     } | ||||
|  | ||||
|     private IItem? _stolenHeldItem; | ||||
|     /// <inheritdoc /> | ||||
|     public bool HasItemBeenRemovedForBattle => _removedHeldItem is not null; | ||||
|  | ||||
|     private IItem? _removedHeldItem; | ||||
|  | ||||
|     /// <inheritdoc /> | ||||
|     public IItem? RemoveHeldItemForBattle() | ||||
|     { | ||||
|         return _stolenHeldItem = RemoveHeldItem(); | ||||
|         return _removedHeldItem = RemoveHeldItem(); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc /> | ||||
| @@ -840,10 +845,10 @@ public class PokemonImpl : ScriptSource, IPokemon | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc /> | ||||
|     public void RestoreStolenHeldItem() | ||||
|     public void RestoreRemovedHeldItem() | ||||
|     { | ||||
|         _ = SetHeldItem(_stolenHeldItem); | ||||
|         _stolenHeldItem = null; | ||||
|         _ = ForceSetHeldItem(_removedHeldItem); | ||||
|         _removedHeldItem = null; | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc /> | ||||
| @@ -863,7 +868,7 @@ public class PokemonImpl : ScriptSource, IPokemon | ||||
|             BattleData.MarkItemAsConsumed(HeldItem); | ||||
|         } | ||||
|  | ||||
|         UseItem(SetHeldItem(null)!); | ||||
|         UseItem(ForceSetHeldItem(null)!); | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -82,4 +82,22 @@ public static class NumericHelpers | ||||
|         var result = value * multiplier; | ||||
|         return result > uint.MaxValue ? uint.MaxValue : (uint)result; | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Multiplies two values. If this overflows, returns <see cref="uint.MaxValue"/>. | ||||
|     /// </summary> | ||||
|     public static int MultiplyOrMax(this int value, int multiplier) | ||||
|     { | ||||
|         var result = (long)value * multiplier; | ||||
|         return result > int.MaxValue ? int.MaxValue : (int)result; | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Multiplies two values. If this overflows, returns <see cref="uint.MaxValue"/>. | ||||
|     /// </summary> | ||||
|     public static int MultiplyOrMax(this int value, float multiplier) | ||||
|     { | ||||
|         var result = value * multiplier; | ||||
|         return result > int.MaxValue ? int.MaxValue : (int)result; | ||||
|     } | ||||
| } | ||||
| @@ -695,18 +695,37 @@ | ||||
|       "cant_be_copied" | ||||
|     ] | ||||
|   }, | ||||
|   "triage": {}, | ||||
|   "truant": { | ||||
|     "canBeChanged": false | ||||
|   "triage": { | ||||
|     "effect": "triage" | ||||
|   }, | ||||
|   "truant": { | ||||
|     "canBeChanged": false, | ||||
|     "effect": "truant" | ||||
|   }, | ||||
|   "turboblaze": { | ||||
|     "effect": "teravolt" | ||||
|   }, | ||||
|   "unaware": { | ||||
|     "effect": "unaware" | ||||
|   }, | ||||
|   "unburden": { | ||||
|     "effect": "unburden" | ||||
|   }, | ||||
|   "unnerve": { | ||||
|     "effect": "unnerve" | ||||
|   }, | ||||
|   "victory_star": { | ||||
|     "effect": "victory_star" | ||||
|   }, | ||||
|   "vital_spirit": { | ||||
|     "effect": "vital_spirit" | ||||
|   }, | ||||
|   "volt_absorb": { | ||||
|     "effect": "volt_absorb" | ||||
|   }, | ||||
|   "water_absorb": { | ||||
|     "effect": "water_absorb" | ||||
|   }, | ||||
|   "turboblaze": {}, | ||||
|   "unaware": {}, | ||||
|   "unburden": {}, | ||||
|   "unnerve": {}, | ||||
|   "victory_star": {}, | ||||
|   "vital_spirit": {}, | ||||
|   "volt_absorb": {}, | ||||
|   "water_absorb": {}, | ||||
|   "water_bubble": {}, | ||||
|   "water_compaction": {}, | ||||
|   "water_veil": {}, | ||||
|   | ||||
| @@ -33,7 +33,7 @@ public class Harvest : Script | ||||
|             if (battle.WeatherName != ScriptUtils.ResolveName<Weather.HarshSunlight>() && rng.GetInt(1) != 0) | ||||
|                 return; | ||||
|             battle.EventHook.Invoke(new AbilityTriggerEvent(_pokemon)); | ||||
|             _ = _pokemon.SetHeldItem(consumedBerry); | ||||
|             _ = _pokemon.ForceSetHeldItem(consumedBerry); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -23,6 +23,6 @@ public class Magician : Script | ||||
|             return; | ||||
|  | ||||
|         move.Battle.EventHook.Invoke(new AbilityTriggerEvent(move.User)); | ||||
|         _ = move.User.SetHeldItem(item); | ||||
|         _ = move.User.ForceSetHeldItem(item); | ||||
|     } | ||||
| } | ||||
| @@ -15,6 +15,6 @@ public class Pickpocket : Script | ||||
|             !move.User.TryStealHeldItem(out var item)) | ||||
|             return; | ||||
|         move.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); | ||||
|         _ = target.SetHeldItem(item); | ||||
|         _ = target.ForceSetHeldItem(item); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										20
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Triage.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Triage.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Triage is an ability that gives priority to healing moves. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Triage_(Ability)">Bulbapedia - Triage</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "triage")] | ||||
| public class Triage : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void ChangePriority(IMoveChoice choice, ref sbyte priority) | ||||
|     { | ||||
|         if (!choice.ChosenMove.MoveData.HasFlag("heal")) | ||||
|             return; | ||||
|         if (priority == sbyte.MaxValue) | ||||
|             return; | ||||
|         priority++; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										18
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Truant.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Truant.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| using PkmnLib.Plugin.Gen7.Scripts.Pokemon; | ||||
|  | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Truant is an ability that causes the Pokémon to only be able to move every other turn. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Truant_(Ability)">Bulbapedia - Truant</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "truant")] | ||||
| public class Truant : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void OnAfterMove(IExecutingMove move) | ||||
|     { | ||||
|         move.User.Volatile.Add(new TruantEffect(move.User)); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										24
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Unaware.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Unaware.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Unaware is an ability that ignores the opposing Pokémon's stat changes when attacking or defending. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Unaware_(Ability)">Bulbapedia - Unaware</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "unaware")] | ||||
| public class Unaware : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void ChangeIncomingMoveOffensiveStatValue(IExecutingMove executingMove, IPokemon target, | ||||
|         byte hitNumber, uint defensiveStat, StatisticSet<uint> targetStats, Statistic offensive, ref uint offensiveStat) | ||||
|     { | ||||
|         offensiveStat = executingMove.User.FlatStats.GetStatistic(offensive); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc /> | ||||
|     public override void ChangeDefensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint offensiveStat, | ||||
|         ImmutableStatisticSet<uint> targetStats, Statistic stat, ref uint value) | ||||
|     { | ||||
|         value = target.FlatStats.GetStatistic(stat); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Unburden.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Unburden.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Unburden is an ability that doubles the Pokémon's Speed if it loses its held item. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Unburden_(Ability)">Bulbapedia - Unburden</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "unburden")] | ||||
| public class Unburden : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void ChangeSpeed(ITurnChoice choice, ref uint speed) | ||||
|     { | ||||
|         if (choice.User.HasItemBeenRemovedForBattle) | ||||
|         { | ||||
|             speed = speed.MultiplyOrMax(2); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										12
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Unnerve.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Unnerve.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Unnerve is an ability that prevents opposing Pokémon from using their held Berries. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Unnerve_(Ability)">Bulbapedia - Unnerve</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "unnerve")] | ||||
| public class Unnerve : Script | ||||
| { | ||||
|     // TODO: Implement Unnerve ability logic | ||||
| } | ||||
							
								
								
									
										17
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VictoryStar.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VictoryStar.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Victory Star is an ability that boosts the accuracy of the Pokémon and its allies. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Victory_Star_(Ability)">Bulbapedia - Victory Star</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "victory_star")] | ||||
| public class VictoryStar : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, | ||||
|         ref int modifiedAccuracy) | ||||
|     { | ||||
|         modifiedAccuracy = modifiedAccuracy.MultiplyOrMax(1.1f); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										20
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VitalSpirit.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VitalSpirit.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Vital Spirit is an ability that prevents the Pokémon from falling asleep. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Vital_Spirit_(Ability)">Bulbapedia - Vital Spirit</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "vital_spirit")] | ||||
| public class VitalSpirit : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, | ||||
|         ref bool preventStatus) | ||||
|     { | ||||
|         if (status == ScriptUtils.ResolveName<Status.Sleep>() && !selfInflicted) | ||||
|         { | ||||
|             preventStatus = true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										20
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VoltAbsorb.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/VoltAbsorb.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Volt Absorb is an ability that heals the Pokémon when hit by an Electric-type move. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Volt_Absorb_(Ability)">Bulbapedia - Volt Absorb</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "volt_absorb")] | ||||
| public class VoltAbsorb : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable) | ||||
|     { | ||||
|         if (move.GetHitData(target, 0).Type?.Name != "electric") | ||||
|             return; | ||||
|         invulnerable = true; | ||||
|         target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); | ||||
|         target.Heal(target.MaxHealth / 4); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										20
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterAbsorb.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/WaterAbsorb.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; | ||||
|  | ||||
| /// <summary> | ||||
| /// Water Absorb is an ability that heals the Pokémon when hit by a Water-type move. | ||||
| /// | ||||
| /// <see href="https://bulbapedia.bulbagarden.net/wiki/Water_Absorb_(Ability)">Bulbapedia - Water Absorb</see> | ||||
| /// </summary> | ||||
| [Script(ScriptCategory.Ability, "water_absorb")] | ||||
| public class WaterAbsorb : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable) | ||||
|     { | ||||
|         if (move.GetHitData(target, 0).Type?.Name != "water") | ||||
|             return; | ||||
|         invulnerable = true; | ||||
|         target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)); | ||||
|         target.Heal(target.MaxHealth / 4); | ||||
|     } | ||||
| } | ||||
| @@ -16,6 +16,6 @@ public class Bestow : Script | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         _ = target.SetHeldItem(userHeldItem); | ||||
|         _ = target.ForceSetHeldItem(userHeldItem); | ||||
|     } | ||||
| } | ||||
| @@ -19,7 +19,7 @@ public class BugBite : Script | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         _ = target.SetHeldItem(null); | ||||
|         _ = target.ForceSetHeldItem(null); | ||||
|         targetHeldItem.RunItemScript(battleData.Battle.Library.ScriptResolver, user, move.Battle.EventHook); | ||||
|     } | ||||
| } | ||||
| @@ -10,6 +10,6 @@ public class Covet : Script | ||||
|             return; | ||||
|         if (!move.User.TryStealHeldItem(out var item)) | ||||
|             return; | ||||
|         _ = move.User.SetHeldItem(item); | ||||
|         _ = move.User.ForceSetHeldItem(item); | ||||
|     } | ||||
| } | ||||
| @@ -20,6 +20,6 @@ public class Recycle : Script | ||||
|             move.GetHitData(target, hit).Fail(); | ||||
|             return; | ||||
|         } | ||||
|         _ = move.User.SetHeldItem(lastItem); | ||||
|         _ = move.User.ForceSetHeldItem(lastItem); | ||||
|     } | ||||
| } | ||||
| @@ -18,7 +18,7 @@ public class Switcheroo : Script | ||||
|         targetHeldItem = target.RemoveHeldItem(); | ||||
|         userHeldItem = move.User.RemoveHeldItem(); | ||||
|  | ||||
|         _ = target.SetHeldItem(userHeldItem); | ||||
|         _ = move.User.SetHeldItem(targetHeldItem); | ||||
|         _ = target.ForceSetHeldItem(userHeldItem); | ||||
|         _ = move.User.ForceSetHeldItem(targetHeldItem); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										10
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/TruantEffect.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/TruantEffect.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon; | ||||
|  | ||||
| public class TruantEffect(IPokemon owner) : Script | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) | ||||
|     { | ||||
|         choice = new PassChoice(owner); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user