Implements freeze, poisoned, badly poisoned

This commit is contained in:
2025-05-19 15:56:27 +02:00
parent 9d2c2de17a
commit 405a21e887
5 changed files with 107 additions and 10 deletions

View File

@@ -3,5 +3,40 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status;
[Script(ScriptCategory.Status, "poisoned")]
public class Poisoned : Script
{
// TODO: Implement the Poisoned status effect.
private IPokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Poisoned script can only be added to a Pokemon.");
_pokemon = pokemon;
}
public virtual float GetPoisonMultiplier() => 1f / 8f;
/// <inheritdoc />
public override void OnEndTurn(IBattle battle)
{
if (_pokemon == null)
return;
if (_pokemon.IsFainted)
return;
var damage = (uint)(_pokemon.MaxHealth * GetPoisonMultiplier());
if (damage == 0)
damage = 1;
var battleData = _pokemon.BattleData;
var eventBatchId = new EventBatchId();
battleData?.Battle.EventHook.Invoke(new DialogEvent("poisoned_damage", new Dictionary<string, object>
{
{ "pokemon", _pokemon },
{ "damage", damage },
})
{
BatchId = eventBatchId,
});
_pokemon.Damage(damage, DamageSource.Status, eventBatchId);
}
}