Adds battle history, fixes code style

This commit is contained in:
2024-08-23 09:24:00 +02:00
parent d48889e21a
commit e7dc885afd
21 changed files with 80 additions and 70 deletions

View File

@@ -110,6 +110,12 @@ public interface IBattle : IScriptSource
/// Gets the current weather of the battle. If no weather is present, this returns null.
/// </summary>
StringKey? WeatherName { get; }
/// <summary>
/// Gets the turn choices of the previous turn. This is a list of lists, where each list represents the choices
/// for a single turn. The outer list is ordered from oldest to newest turn.
/// </summary>
IReadOnlyList<IReadOnlyList<ITurnChoice>> PreviousTurnChoices { get; }
}
/// <inheritdoc cref="IBattle"/>
@@ -172,7 +178,8 @@ public class BattleImpl : ScriptSource, IBattle
public IPokemon? GetPokemon(byte side, byte position) => Sides[side].Pokemon[position];
/// <inheritdoc />
public bool CanSlotBeFilled(byte side, byte position) => Parties.Any(x => x.IsResponsibleForIndex(new ResponsibleIndex(side, position)) && x.HasPokemonNotInField());
public bool CanSlotBeFilled(byte side, byte position) => Parties.Any(x =>
x.IsResponsibleForIndex(new ResponsibleIndex(side, position)) && x.HasPokemonNotInField());
/// <inheritdoc />
public void ValidateBattleState()
@@ -207,7 +214,7 @@ public class BattleImpl : ScriptSource, IBattle
HasEnded = true;
return;
}
// If only one side is left, that side has won
Result = BattleResult.Conclusive(survivingSide!.Index);
HasEnded = true;
@@ -267,17 +274,22 @@ public class BattleImpl : ScriptSource, IBattle
choice.RunScriptHook(script => script.ChangePriority(moveChoice, ref priority));
moveChoice.Priority = priority;
}
var speed = choice.User.BoostedStats.Speed;
choice.RunScriptHook(script => script.ChangeSpeed(choice, ref speed));
choice.Speed = speed;
choice.RandomValue = (uint)Random.GetInt();
choices[index * PositionsPerSide + i] = choice;
choices[index * PositionsPerSide + i] = choice;
}
side.ResetChoices();
}
_previousTurnChoices.Add(choices.ToList());
CurrentTurnNumber += 1;
ChoiceQueue = new BattleChoiceQueue(choices);
@@ -288,6 +300,7 @@ public class BattleImpl : ScriptSource, IBattle
}
private readonly ScriptContainer _weatherScript = new();
/// <inheritdoc />
public void SetWeather(StringKey? weatherName)
{
@@ -303,19 +316,25 @@ public class BattleImpl : ScriptSource, IBattle
_weatherScript.Clear();
}
}
private IScriptSet Volatile { get; } = new ScriptSet();
/// <inheritdoc />
public StringKey? WeatherName => _weatherScript.Script?.Name;
private readonly List<IReadOnlyList<ITurnChoice>> _previousTurnChoices = new();
/// <inheritdoc />
public IReadOnlyList<IReadOnlyList<ITurnChoice>> PreviousTurnChoices => _previousTurnChoices;
/// <inheritdoc />
public override int ScriptCount => 2;
/// <inheritdoc />
public override void GetOwnScripts(List<IEnumerable<ScriptContainer>> scripts)
{
scripts.Add(_weatherScript );
scripts.Add(_weatherScript);
scripts.Add(Volatile);
}