Fixes for some things that can be null, adds functions for LearnedMove uses
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2022-04-22 11:54:50 +02:00
parent 0486c9cdfb
commit 61e48a705a
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
12 changed files with 34 additions and 16 deletions

View File

@ -155,9 +155,9 @@ namespace PkmnLibSharp.Battling
Creaturelib.Generated.Battle.ForceRecall(Ptr, side, index).Assert();
}
public void SwitchPokemon(byte side, byte index, Pokemon newPokemon)
public void SwitchPokemon(byte side, byte index, Pokemon? newPokemon)
{
Creaturelib.Generated.Battle.SwitchCreature(Ptr, side, index, newPokemon.Ptr).Assert();
Creaturelib.Generated.Battle.SwitchCreature(Ptr, side, index, newPokemon?.Ptr ?? IntPtr.Zero).Assert();
}
public bool CanSlotBeFilled(byte side, byte index)

View File

@ -44,10 +44,12 @@ namespace PkmnLibSharp.Battling
Creaturelib.Generated.BattleSide.SetCreature(Ptr, pokemon.Ptr, index);
}
public Pokemon GetPokemon(byte index)
public Pokemon? GetPokemon(byte index)
{
var ptr = IntPtr.Zero;
Creaturelib.Generated.BattleSide.GetCreature(ref ptr, Ptr, index);
if (ptr == IntPtr.Zero)
return null;
if (TryResolvePointer(ptr, out Pokemon? pokemon))
return pokemon!;
return Constructor.Active.ConstructPokemon(ptr)!;

View File

@ -42,6 +42,22 @@ namespace PkmnLibSharp.Battling
private MoveData? _move;
public void DecreaseUses(byte amount)
{
LearnedAttack.DecreaseUses(Ptr, amount);
}
public void RestoreUses(byte amount)
{
LearnedAttack.RestoreUses(Ptr, amount);
}
public void RestoreAllUses()
{
LearnedAttack.RestoreAllUses(Ptr);
}
public override string ToString()
{
return base.ToString() + $": {Move.Name} PP: {RemainingUses}/{MaxUses}";

View File

@ -31,7 +31,7 @@ namespace PkmnLibSharp.Battling
protected static IntPtr CreatePtr(BattleLibrary library, Species species, Forme forme, byte level,
uint experience, uint uid, Gender gender, byte coloring, Item? heldItem, string? nickname,
bool hiddenAbility, byte abilityIndex, IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs,
bool hiddenAbility, byte abilityIndex, IReadOnlyCollection<LearnedMove?> moves, StatisticSet<byte> ivs,
StatisticSet<byte> evs, Nature nature, bool allowedExperienceGain, bool isEgg)
{
var movesArr = moves.Select(x => x?.Ptr ?? IntPtr.Zero).ToArray();

BIN
PkmnLibSharp/Native/Linux/libArbutils.so (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
PkmnLibSharp/Native/Linux/libpkmnLib.so (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
PkmnLibSharp/Native/Windows/libpkmnLib.dll (Stored with Git LFS)

Binary file not shown.

Binary file not shown.