Additional functionality
This commit is contained in:
parent
4c34910a43
commit
b01a8fb704
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
|
@ -6,4 +8,22 @@ namespace PkmnLib.Dynamic.Models.Choices;
|
|||
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;
|
||||
|
||||
/// <summary>
|
||||
|
@ -6,4 +9,29 @@ namespace PkmnLib.Dynamic.Models.Choices;
|
|||
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;
|
||||
|
||||
/// <summary>
|
||||
|
@ -6,4 +8,29 @@ namespace PkmnLib.Dynamic.Models.Choices;
|
|||
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.
|
||||
/// </summary>
|
||||
IHitData GetDataFromRawIndex(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the targets of this move.
|
||||
/// </summary>
|
||||
IReadOnlyList<IPokemon?> Targets { get; }
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IExecutingMove"/>
|
||||
|
@ -207,6 +212,9 @@ public class ExecutingMoveImpl : ScriptSource, IExecutingMove
|
|||
return _hits[index];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IPokemon?> Targets => _targets.ToList();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int ScriptCount => 1 + User.ScriptCount;
|
||||
|
||||
|
|
|
@ -71,6 +71,11 @@ public interface IPokemon : IScriptSource
|
|||
/// currently not used, and can be used for other implementations.
|
||||
/// </summary>
|
||||
byte Coloring { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the Pokemon is shiny.
|
||||
/// </summary>
|
||||
bool IsShiny { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The held item of the Pokemon.
|
||||
|
@ -163,7 +168,12 @@ public interface IPokemon : IScriptSource
|
|||
/// <summary>
|
||||
/// Checks whether the Pokemon has a specific move in its current moveset.
|
||||
/// </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>
|
||||
/// Whether or not the Pokemon is allowed to gain experience.
|
||||
|
@ -487,12 +497,21 @@ public class PokemonImpl : ScriptSource, IPokemon
|
|||
var oldLevel = Level;
|
||||
var oldExperience = 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);
|
||||
if (newLevel > Level)
|
||||
{
|
||||
Level = newLevel;
|
||||
RecalculateFlatStats();
|
||||
BattleData?.Battle.EventHook.Invoke(new LevelUpEvent(this, oldLevel, Level));
|
||||
BattleData?.Battle.EventHook.Invoke(new LevelUpEvent(this, oldLevel, Level)
|
||||
{
|
||||
BatchId = batchId,
|
||||
});
|
||||
|
||||
if (newLevel >= maxLevel)
|
||||
{
|
||||
|
@ -511,6 +530,9 @@ public class PokemonImpl : ScriptSource, IPokemon
|
|||
|
||||
/// <inheritdoc />
|
||||
public byte Coloring { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsShiny => Coloring == 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IItem? HeldItem { get; private set; }
|
||||
|
@ -568,6 +590,17 @@ public class PokemonImpl : ScriptSource, IPokemon
|
|||
/// <inheritdoc />
|
||||
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 />
|
||||
public bool AllowedExperience { get; set; }
|
||||
|
||||
|
|
|
@ -7,10 +7,13 @@ namespace PkmnLib.Dynamic.Models;
|
|||
/// </summary>
|
||||
public interface IPokemonParty : IReadOnlyList<IPokemon?>
|
||||
{
|
||||
event EventHandler<(IPokemon?, int index)>? OnSwapInto;
|
||||
event EventHandler<(int index1, int index2)>? OnSwap;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.
|
||||
/// </summary>
|
||||
IPokemon? SwapInto(IPokemon pokemon, int index);
|
||||
IPokemon? SwapInto(IPokemon? pokemon, int index);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
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 />
|
||||
|
@ -37,6 +45,13 @@ public class PokemonParty : IPokemonParty
|
|||
_pokemon = new IPokemon[size];
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<(IPokemon?, int index)>? OnSwapInto;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<(int index1, int index2)>? OnSwap;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.
|
||||
/// </summary>
|
||||
|
@ -44,14 +59,18 @@ public class PokemonParty : IPokemonParty
|
|||
{
|
||||
var old = _pokemon[index];
|
||||
_pokemon[index] = pokemon;
|
||||
OnSwapInto?.Invoke(this, (pokemon, index));
|
||||
return old;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swaps two Pokemon in the party around.
|
||||
/// </summary>
|
||||
public void Swap(int index1, int index2) =>
|
||||
public void Swap(int index1, int index2)
|
||||
{
|
||||
(_pokemon[index1], _pokemon[index2]) = (_pokemon[index2], _pokemon[index1]);
|
||||
OnSwap?.Invoke(this, (index1, index2));
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -69,6 +88,7 @@ public class PokemonParty : IPokemonParty
|
|||
/// <inheritdoc />
|
||||
public IPokemon? this[int index] => _pokemon[index];
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Pack()
|
||||
{
|
||||
// Pack the party so that all Pokémon are at the front.
|
||||
|
|
|
@ -8,6 +8,10 @@ namespace PkmnLib.Dynamic.ScriptHandling.Registry;
|
|||
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
|
||||
public abstract class Plugin
|
||||
{
|
||||
protected Plugin()
|
||||
{
|
||||
}
|
||||
|
||||
protected Plugin(PluginConfiguration configuration)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -5,12 +5,17 @@ namespace PkmnLib.Plugin.Gen7;
|
|||
|
||||
public class Gen7PluginConfiguration : PluginConfiguration
|
||||
{
|
||||
public bool DamageCalculatorHasRandomness { get; set; }
|
||||
public bool DamageCalculatorHasRandomness { get; set; } = true;
|
||||
}
|
||||
|
||||
public class Gen7Plugin : Dynamic.ScriptHandling.Registry.Plugin
|
||||
{
|
||||
private readonly Gen7PluginConfiguration _configuration;
|
||||
|
||||
public Gen7Plugin() : base()
|
||||
{
|
||||
_configuration = new Gen7PluginConfiguration();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Gen7Plugin(PluginConfiguration configuration) : base(configuration)
|
||||
|
|
Loading…
Reference in New Issue