Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -7,21 +7,21 @@ public class Conversion2 : Script, IScriptOnSecondaryEffect
|
||||
private static readonly StringKey NoneTypeName = "none";
|
||||
|
||||
/// <inheritdoc />
|
||||
public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
|
||||
public void OnSecondaryEffect(IExecutingMove move, IBattlePokemon target, byte hit)
|
||||
{
|
||||
var lastMoveByTarget = target.BattleData?.LastMoveChoice;
|
||||
var lastMoveByTarget = target.LastMoveChoice;
|
||||
if (lastMoveByTarget == null || lastMoveByTarget.ChosenMove.MoveData.MoveType.Name == NoneTypeName)
|
||||
{
|
||||
move.GetHitData(target, hit).Fail();
|
||||
return;
|
||||
}
|
||||
|
||||
var typeLibrary = move.User.BattleData!.Battle.Library.StaticLibrary.Types;
|
||||
var typeLibrary = move.User.Battle.Library.StaticLibrary.Types;
|
||||
// Get all types against which the last move would be not very effective
|
||||
var type = typeLibrary.GetAllEffectivenessFromAttacking(lastMoveByTarget.ChosenMove.MoveData.MoveType)
|
||||
.Where(x => x.effectiveness < 1 && !move.User.Types.Contains(x.type))
|
||||
// Shuffle them randomly, but deterministically
|
||||
.OrderBy(_ => move.User.BattleData.Battle.Random.GetInt()).ThenBy(x => x.type.Value)
|
||||
.OrderBy(_ => move.User.Battle.Random.GetInt()).ThenBy(x => x.type.Value)
|
||||
// And grab the first one
|
||||
.Select(x => x.type).FirstOrDefault();
|
||||
if (type == null)
|
||||
|
||||
Reference in New Issue
Block a user