Implements freeze, poisoned, badly poisoned
This commit is contained in:
parent
9d2c2de17a
commit
405a21e887
@ -1,6 +1,17 @@
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Status;
|
||||
|
||||
[Script(ScriptCategory.Status, "badly_poisoned")]
|
||||
public class BadlyPoisoned : Script
|
||||
public class BadlyPoisoned : Poisoned
|
||||
{
|
||||
private int _turns = 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetPoisonMultiplier() => 1f / (16f * _turns);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle)
|
||||
{
|
||||
base.OnEndTurn(battle);
|
||||
_turns = Math.Min(_turns + 1, 15);
|
||||
}
|
||||
}
|
@ -3,5 +3,48 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status;
|
||||
[Script(ScriptCategory.Status, "frozen")]
|
||||
public class Frozen : Script
|
||||
{
|
||||
// TODO: Implement the Frozen status effect.
|
||||
private IPokemon? _pokemon;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnAddedToParent(IScriptSource source)
|
||||
{
|
||||
_pokemon = source as IPokemon;
|
||||
if (_pokemon == null)
|
||||
{
|
||||
throw new InvalidOperationException("Frozen script can only be added to a Pokemon.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void PreventMove(IExecutingMove move, ref bool prevent)
|
||||
{
|
||||
if (move.UseMove.MoveType.Name == "fire" || move.UseMove.HasFlag("defrost"))
|
||||
{
|
||||
_pokemon?.ClearStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
prevent = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle)
|
||||
{
|
||||
if (_pokemon == null)
|
||||
return;
|
||||
if (battle.Random.GetInt(0, 100) >= 20)
|
||||
return;
|
||||
|
||||
_pokemon.ClearStatus();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnRemove()
|
||||
{
|
||||
_pokemon?.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_thawed_out",
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "pokemon", _pokemon },
|
||||
}));
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status;
|
||||
[Script(ScriptCategory.Status, "sleep")]
|
||||
public class Sleep : Script
|
||||
{
|
||||
private IPokemon? _pokemon;
|
||||
public int Turns { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -15,6 +16,7 @@ public class Sleep : Script
|
||||
return;
|
||||
if (source is not IPokemon pokemon)
|
||||
throw new InvalidOperationException("Sleep script can only be added to a Pokemon.");
|
||||
_pokemon = pokemon;
|
||||
var battleData = pokemon.BattleData;
|
||||
if (battleData != null)
|
||||
{
|
||||
@ -29,12 +31,7 @@ public class Sleep : Script
|
||||
Turns--;
|
||||
if (Turns <= 0)
|
||||
{
|
||||
RemoveSelf();
|
||||
move.User.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_woke_up",
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "pokemon", move.User },
|
||||
}));
|
||||
move.User.ClearStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,4 +49,13 @@ public class Sleep : Script
|
||||
return;
|
||||
prevent = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnRemove()
|
||||
{
|
||||
_pokemon?.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_woke_up", new Dictionary<string, object>
|
||||
{
|
||||
{ "pokemon", _pokemon },
|
||||
}));
|
||||
}
|
||||
}
|
@ -44,6 +44,8 @@ public class Hail : Script, ILimitedTurnsScript
|
||||
|
||||
_duration--;
|
||||
if (_duration <= 0)
|
||||
RemoveSelf();
|
||||
{
|
||||
battle.SetWeather(null, 0);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user