Implements freeze, poisoned, badly poisoned
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user