Additional functionality
This commit is contained in:
parent
4c34910a43
commit
b01a8fb704
21
PkmnLib.Dynamic/Events/ExperienceGainEvent.cs
Normal file
21
PkmnLib.Dynamic/Events/ExperienceGainEvent.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using PkmnLib.Dynamic.Models;
|
||||||
|
|
||||||
|
namespace PkmnLib.Dynamic.Events;
|
||||||
|
|
||||||
|
public class ExperienceGainEvent : IEventData
|
||||||
|
{
|
||||||
|
public ExperienceGainEvent(IPokemon pokemon, uint previousExperience, uint newExperience)
|
||||||
|
{
|
||||||
|
Pokemon = pokemon;
|
||||||
|
PreviousExperience = previousExperience;
|
||||||
|
NewExperience = newExperience;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPokemon Pokemon { get; set; }
|
||||||
|
public uint PreviousExperience { get; }
|
||||||
|
public uint NewExperience { get; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public EventBatchId BatchId { get; init; }
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
using PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
|
||||||
namespace PkmnLib.Dynamic.Models.Choices;
|
namespace PkmnLib.Dynamic.Models.Choices;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -7,3 +9,21 @@ public interface IFleeChoice : ITurnChoice
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IFleeChoice"/>
|
||||||
|
public class FleeTurnChoice : TurnChoice, IFleeChoice
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public FleeTurnChoice(IPokemon user) : base(user)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override int ScriptCount => User.ScriptCount;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void GetOwnScripts(List<IEnumerable<ScriptContainer>> scripts) { }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void CollectScripts(List<IEnumerable<ScriptContainer>> scripts) => User.CollectScripts(scripts);
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
using PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
using PkmnLib.Static;
|
||||||
|
|
||||||
namespace PkmnLib.Dynamic.Models.Choices;
|
namespace PkmnLib.Dynamic.Models.Choices;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -7,3 +10,28 @@ public interface IItemChoice : ITurnChoice
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IItemChoice"/>
|
||||||
|
public class ItemChoice : TurnChoice, IItemChoice
|
||||||
|
{
|
||||||
|
public ItemChoice(IPokemon user, IItem item) : base(user)
|
||||||
|
{
|
||||||
|
Item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IItem Item { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override int ScriptCount => User.ScriptCount;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void GetOwnScripts(List<IEnumerable<ScriptContainer>> scripts)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void CollectScripts(List<IEnumerable<ScriptContainer>> scripts)
|
||||||
|
{
|
||||||
|
User.CollectScripts(scripts);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
using PkmnLib.Dynamic.ScriptHandling;
|
||||||
|
|
||||||
namespace PkmnLib.Dynamic.Models.Choices;
|
namespace PkmnLib.Dynamic.Models.Choices;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -7,3 +9,28 @@ public interface ISwitchChoice : ITurnChoice
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ISwitchChoice"/>
|
||||||
|
public class SwitchChoice : TurnChoice, ISwitchChoice
|
||||||
|
{
|
||||||
|
public SwitchChoice(IPokemon user, IPokemon switchTo) : base(user)
|
||||||
|
{
|
||||||
|
SwitchTo = switchTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPokemon SwitchTo { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override int ScriptCount => User.ScriptCount;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void GetOwnScripts(List<IEnumerable<ScriptContainer>> scripts)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void CollectScripts(List<IEnumerable<ScriptContainer>> scripts)
|
||||||
|
{
|
||||||
|
User.CollectScripts(scripts);
|
||||||
|
}
|
||||||
|
}
|
@ -128,6 +128,11 @@ public interface IExecutingMove : IScriptSource
|
|||||||
/// Gets a hit based on its raw index.
|
/// Gets a hit based on its raw index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IHitData GetDataFromRawIndex(int index);
|
IHitData GetDataFromRawIndex(int index);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the targets of this move.
|
||||||
|
/// </summary>
|
||||||
|
IReadOnlyList<IPokemon?> Targets { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IExecutingMove"/>
|
/// <inheritdoc cref="IExecutingMove"/>
|
||||||
@ -207,6 +212,9 @@ public class ExecutingMoveImpl : ScriptSource, IExecutingMove
|
|||||||
return _hits[index];
|
return _hits[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyList<IPokemon?> Targets => _targets.ToList();
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override int ScriptCount => 1 + User.ScriptCount;
|
public override int ScriptCount => 1 + User.ScriptCount;
|
||||||
|
|
||||||
|
@ -72,6 +72,11 @@ public interface IPokemon : IScriptSource
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
byte Coloring { get; }
|
byte Coloring { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the Pokemon is shiny.
|
||||||
|
/// </summary>
|
||||||
|
bool IsShiny { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The held item of the Pokemon.
|
/// The held item of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -163,7 +168,12 @@ public interface IPokemon : IScriptSource
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether the Pokemon has a specific move in its current moveset.
|
/// Checks whether the Pokemon has a specific move in its current moveset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HasMove(StringKey moveName);
|
bool HasMove(StringKey moveName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Swaps two moves of the Pokemon.
|
||||||
|
/// </summary>
|
||||||
|
void SwapMoves(byte index1, byte index2);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not the Pokemon is allowed to gain experience.
|
/// Whether or not the Pokemon is allowed to gain experience.
|
||||||
@ -487,12 +497,21 @@ public class PokemonImpl : ScriptSource, IPokemon
|
|||||||
var oldLevel = Level;
|
var oldLevel = Level;
|
||||||
var oldExperience = Experience;
|
var oldExperience = Experience;
|
||||||
Experience += experience;
|
Experience += experience;
|
||||||
|
var batchId = new EventBatchId();
|
||||||
|
BattleData?.Battle.EventHook.Invoke(new ExperienceGainEvent(this, oldExperience, Experience)
|
||||||
|
{
|
||||||
|
BatchId = batchId,
|
||||||
|
});
|
||||||
|
|
||||||
var newLevel = Library.StaticLibrary.GrowthRates.CalculateLevel(Species.GrowthRate, Experience);
|
var newLevel = Library.StaticLibrary.GrowthRates.CalculateLevel(Species.GrowthRate, Experience);
|
||||||
if (newLevel > Level)
|
if (newLevel > Level)
|
||||||
{
|
{
|
||||||
Level = newLevel;
|
Level = newLevel;
|
||||||
RecalculateFlatStats();
|
RecalculateFlatStats();
|
||||||
BattleData?.Battle.EventHook.Invoke(new LevelUpEvent(this, oldLevel, Level));
|
BattleData?.Battle.EventHook.Invoke(new LevelUpEvent(this, oldLevel, Level)
|
||||||
|
{
|
||||||
|
BatchId = batchId,
|
||||||
|
});
|
||||||
|
|
||||||
if (newLevel >= maxLevel)
|
if (newLevel >= maxLevel)
|
||||||
{
|
{
|
||||||
@ -512,6 +531,9 @@ public class PokemonImpl : ScriptSource, IPokemon
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte Coloring { get; }
|
public byte Coloring { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool IsShiny => Coloring == 1;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IItem? HeldItem { get; private set; }
|
public IItem? HeldItem { get; private set; }
|
||||||
|
|
||||||
@ -568,6 +590,17 @@ public class PokemonImpl : ScriptSource, IPokemon
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool HasMove(StringKey moveName) => Moves.Any(move => move?.MoveData.Name == moveName);
|
public bool HasMove(StringKey moveName) => Moves.Any(move => move?.MoveData.Name == moveName);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void SwapMoves(byte index1, byte index2)
|
||||||
|
{
|
||||||
|
if (index1 >= Const.MovesCount || index2 >= Const.MovesCount)
|
||||||
|
return;
|
||||||
|
var move1 = _learnedMoves[index1];
|
||||||
|
var move2 = _learnedMoves[index2];
|
||||||
|
_learnedMoves[index1] = move2;
|
||||||
|
_learnedMoves[index2] = move1;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool AllowedExperience { get; set; }
|
public bool AllowedExperience { get; set; }
|
||||||
|
|
||||||
|
@ -7,10 +7,13 @@ namespace PkmnLib.Dynamic.Models;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPokemonParty : IReadOnlyList<IPokemon?>
|
public interface IPokemonParty : IReadOnlyList<IPokemon?>
|
||||||
{
|
{
|
||||||
|
event EventHandler<(IPokemon?, int index)>? OnSwapInto;
|
||||||
|
event EventHandler<(int index1, int index2)>? OnSwap;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.
|
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IPokemon? SwapInto(IPokemon pokemon, int index);
|
IPokemon? SwapInto(IPokemon? pokemon, int index);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Swaps two Pokemon in the party around.
|
/// Swaps two Pokemon in the party around.
|
||||||
@ -24,6 +27,11 @@ public interface IPokemonParty : IReadOnlyList<IPokemon?>
|
|||||||
/// This will return false if all Pokemon are fainted, or eggs, etc.
|
/// This will return false if all Pokemon are fainted, or eggs, etc.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
bool HasUsablePokemon();
|
bool HasUsablePokemon();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Packs the party so that all Pokémon are at the front, and the empty slots are at the back.
|
||||||
|
/// </summary>
|
||||||
|
void Pack();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -37,6 +45,13 @@ public class PokemonParty : IPokemonParty
|
|||||||
_pokemon = new IPokemon[size];
|
_pokemon = new IPokemon[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event EventHandler<(IPokemon?, int index)>? OnSwapInto;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event EventHandler<(int index1, int index2)>? OnSwap;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.
|
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -44,14 +59,18 @@ public class PokemonParty : IPokemonParty
|
|||||||
{
|
{
|
||||||
var old = _pokemon[index];
|
var old = _pokemon[index];
|
||||||
_pokemon[index] = pokemon;
|
_pokemon[index] = pokemon;
|
||||||
|
OnSwapInto?.Invoke(this, (pokemon, index));
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Swaps two Pokemon in the party around.
|
/// Swaps two Pokemon in the party around.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Swap(int index1, int index2) =>
|
public void Swap(int index1, int index2)
|
||||||
|
{
|
||||||
(_pokemon[index1], _pokemon[index2]) = (_pokemon[index2], _pokemon[index1]);
|
(_pokemon[index1], _pokemon[index2]) = (_pokemon[index2], _pokemon[index1]);
|
||||||
|
OnSwap?.Invoke(this, (index1, index2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -69,6 +88,7 @@ public class PokemonParty : IPokemonParty
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IPokemon? this[int index] => _pokemon[index];
|
public IPokemon? this[int index] => _pokemon[index];
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public void Pack()
|
public void Pack()
|
||||||
{
|
{
|
||||||
// Pack the party so that all Pokémon are at the front.
|
// Pack the party so that all Pokémon are at the front.
|
||||||
|
@ -8,6 +8,10 @@ namespace PkmnLib.Dynamic.ScriptHandling.Registry;
|
|||||||
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
|
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
|
||||||
public abstract class Plugin
|
public abstract class Plugin
|
||||||
{
|
{
|
||||||
|
protected Plugin()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected Plugin(PluginConfiguration configuration)
|
protected Plugin(PluginConfiguration configuration)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,18 @@ namespace PkmnLib.Plugin.Gen7;
|
|||||||
|
|
||||||
public class Gen7PluginConfiguration : PluginConfiguration
|
public class Gen7PluginConfiguration : PluginConfiguration
|
||||||
{
|
{
|
||||||
public bool DamageCalculatorHasRandomness { get; set; }
|
public bool DamageCalculatorHasRandomness { get; set; } = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Gen7Plugin : Dynamic.ScriptHandling.Registry.Plugin
|
public class Gen7Plugin : Dynamic.ScriptHandling.Registry.Plugin
|
||||||
{
|
{
|
||||||
private readonly Gen7PluginConfiguration _configuration;
|
private readonly Gen7PluginConfiguration _configuration;
|
||||||
|
|
||||||
|
public Gen7Plugin() : base()
|
||||||
|
{
|
||||||
|
_configuration = new Gen7PluginConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Gen7Plugin(PluginConfiguration configuration) : base(configuration)
|
public Gen7Plugin(PluginConfiguration configuration) : base(configuration)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user