Work on item use/evolutions
All checks were successful
Build / Build (push) Successful in 1m7s

This commit is contained in:
2025-08-18 11:57:03 +02:00
parent e5041ec5f0
commit f061ba2455
7 changed files with 157 additions and 12 deletions

View File

@@ -0,0 +1,54 @@
using PkmnLib.Static.Species;
namespace PkmnLib.Plugin.Gen7.Scripts.Items;
[ItemScript("evolution_use")]
public class EvolutionItem : ItemScript
{
/// <inheritdoc />
public EvolutionItem(IItem item) : base(item)
{
}
/// <inheritdoc />
public override bool IsItemUsable => true;
/// <inheritdoc />
public override bool RequiresTarget => true;
/// <inheritdoc />
public override bool IsTargetValid(IPokemon target)
{
foreach (var x in target.Species.EvolutionData)
{
switch (x)
{
case ItemUseEvolution itemUseEvolution when itemUseEvolution.Item == Item.Name:
return true;
case ItemGenderEvolution itemGenderEvolution when itemGenderEvolution.Item == Item.Name:
return itemGenderEvolution.Gender == target.Gender;
}
}
return false;
}
/// <inheritdoc />
public override void OnUseWithTarget(IPokemon target, EventHook eventHook)
{
var evolutionData = target.Species.EvolutionData.FirstOrDefault(x =>
{
switch (x)
{
case ItemUseEvolution itemUseEvolution when itemUseEvolution.Item == Item.Name:
case ItemGenderEvolution itemGenderEvolution when itemGenderEvolution.Item == Item.Name:
return true;
default:
return false;
}
});
if (evolutionData == null)
return;
target.EvolveTo(evolutionData, eventHook);
}
}

View File

@@ -29,7 +29,7 @@ public class HealingItem : ItemScript
}
/// <inheritdoc />
public override bool IsTargetValid(IPokemon target) => !target.IsFainted;
public override bool IsTargetValid(IPokemon target) => !target.IsFainted && target.CurrentHealth < target.MaxHealth;
/// <inheritdoc />
public override void OnUseWithTarget(IPokemon target, EventHook eventHook)