Lots more work on implementing battling
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Static;
|
||||
using PkmnLib.Static.Moves;
|
||||
using PkmnLib.Static.Utils.Errors;
|
||||
|
||||
namespace PkmnLib.Dynamic.Models;
|
||||
|
||||
@@ -110,7 +111,7 @@ public interface IExecutingMove : IScriptSource
|
||||
/// <summary>
|
||||
/// Gets a hit data for a target, with a specific index.
|
||||
/// </summary>
|
||||
HitData GetHitData(IPokemon target, byte hit);
|
||||
IHitData GetHitData(IPokemon target, byte hit);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a Pokémon is a target for this move.
|
||||
@@ -125,5 +126,99 @@ public interface IExecutingMove : IScriptSource
|
||||
/// <summary>
|
||||
/// Gets a hit based on its raw index.
|
||||
/// </summary>
|
||||
HitData GetDataFromRawIndex(int index);
|
||||
IHitData GetDataFromRawIndex(int index);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IExecutingMove"/>
|
||||
public class ExecutingMoveImpl : ScriptSource, IExecutingMove
|
||||
{
|
||||
private readonly List<IPokemon?> _targets;
|
||||
private readonly IHitData[] _hits;
|
||||
|
||||
/// <inheritdoc cref="ExecutingMoveImpl"/>
|
||||
public ExecutingMoveImpl(List<IPokemon?> targets, byte numberOfHits, IPokemon user, ILearnedMove chosenMove,
|
||||
IMoveData useMove, ScriptContainer script)
|
||||
{
|
||||
_targets = targets;
|
||||
NumberOfHits = numberOfHits;
|
||||
User = user;
|
||||
ChosenMove = chosenMove;
|
||||
UseMove = useMove;
|
||||
Script = script;
|
||||
|
||||
var totalHits = targets.Count * numberOfHits;
|
||||
_hits = new IHitData[totalHits];
|
||||
for (var i = 0; i < totalHits; i++)
|
||||
{
|
||||
_hits[i] = new HitData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int TargetCount => _targets.Count;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte NumberOfHits { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IPokemon User { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ILearnedMove ChosenMove { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IMoveData UseMove { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ScriptContainer Script { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IHitData GetHitData(IPokemon target, byte hit)
|
||||
{
|
||||
var targetIndex = _targets.IndexOf(target);
|
||||
if (targetIndex == -1)
|
||||
{
|
||||
throw new ArgumentException("The target is not a target of this move.");
|
||||
}
|
||||
|
||||
var index = targetIndex * NumberOfHits + hit;
|
||||
return _hits[index];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsPokemonTarget(IPokemon target) => _targets.Contains(target);
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetTargetIndex(IPokemon target)
|
||||
{
|
||||
var targetIndex = _targets.IndexOf(target);
|
||||
if (targetIndex == -1)
|
||||
throw new ArgumentException("The target is not a target of this move.");
|
||||
|
||||
return targetIndex * NumberOfHits;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IHitData GetDataFromRawIndex(int index)
|
||||
{
|
||||
if (index < 0 || index >= _hits.Length)
|
||||
throw new OutOfRangeException("Hit", index, _hits.Length - 1);
|
||||
return _hits[index];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int ScriptCount => 1 + User.ScriptCount;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void GetOwnScripts(List<IEnumerable<ScriptContainer>> scripts)
|
||||
{
|
||||
scripts.Add(Script);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void CollectScripts(List<IEnumerable<ScriptContainer>> scripts)
|
||||
{
|
||||
scripts.Add(Script);
|
||||
User.CollectScripts(scripts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user