More warning fixes

This commit is contained in:
Deukhoofd 2025-05-02 16:04:54 +02:00
parent dabb26e4f2
commit b69ba6eaff
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
56 changed files with 56 additions and 80 deletions

View File

@ -4,6 +4,7 @@ using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text.Json;
using JetBrains.Annotations;
using PkmnLib.Dataloader.Models;
using PkmnLib.Static;
using PkmnLib.Static.Libraries;
@ -26,11 +27,13 @@ public static class MoveDataLoader
return library;
}
[PublicAPI]
public static
Func<SerializedMove, StringKey, TypeIdentifier, MoveCategory, byte, byte, byte, MoveTarget, sbyte,
ISecondaryEffect?, IEnumerable<StringKey>, MoveDataImpl> MoveConstructor =
(serialized, name, moveType, category, basePower, accuracy, baseUsages, target, priority, secondaryEffect,
flags) => new MoveDataImpl(name, moveType, category, basePower, accuracy, baseUsages, target, priority,
ISecondaryEffect?
, IEnumerable<StringKey>, MoveDataImpl> MoveConstructor =
(_, name, moveType, category, basePower, accuracy, baseUsages, target, priority, secondaryEffect, flags) =>
new MoveDataImpl(name, moveType, category, basePower, accuracy, baseUsages, target, priority,
secondaryEffect, flags);
private static MoveDataImpl DeserializeMove(SerializedMove serialized, TypeLibrary typeLibrary)

View File

@ -21,7 +21,7 @@ public static class SpeciesDataLoader
if (obj == null)
throw new InvalidDataException("Species data is empty.");
return obj.Where(x => x.Key != "$schema").ToDictionary(x => x.Key,
x => x.Value.Deserialize<SerializedSpecies>(JsonOptions.DefaultOptions));
x => x.Value.Deserialize<SerializedSpecies>(JsonOptions.DefaultOptions))!;
}
public static SpeciesLibrary LoadSpecies(Stream[] streams, IReadOnlyTypeLibrary typeLibrary)
@ -159,17 +159,17 @@ public static class SpeciesDataLoader
Happiness = evolution.Data.GetValue<byte>(),
ToSpecies = evolution.Species,
},
"happinessday" => new HappinessDayEvolution()
"happinessday" => new HappinessDayEvolution
{
Happiness = evolution.Data.GetValue<byte>(),
ToSpecies = evolution.Species,
},
"happinessnight" => new HappinessNightEvolution()
"happinessnight" => new HappinessNightEvolution
{
Happiness = evolution.Data.GetValue<byte>(),
ToSpecies = evolution.Species,
},
"item" => new ItemUseEvolution()
"item" => new ItemUseEvolution
{
Item = evolution.Data.GetValue<string>() ?? throw new InvalidDataException("Item is null."),
ToSpecies = evolution.Species,
@ -184,17 +184,17 @@ public static class SpeciesDataLoader
Item = evolution.Data.GetValue<string>() ?? throw new InvalidDataException("Item is null."),
ToSpecies = evolution.Species,
},
"holditem" => new HoldItemEvolution()
"holditem" => new HoldItemEvolution
{
Item = evolution.Data.GetValue<string>() ?? throw new InvalidDataException("Item is null."),
ToSpecies = evolution.Species,
},
"dayholditem" => new DayHoldItemEvolution()
"dayholditem" => new DayHoldItemEvolution
{
Item = evolution.Data.GetValue<string>() ?? throw new InvalidDataException("Item is null."),
ToSpecies = evolution.Species,
},
"nightholditem" => new NightHoldItemEvolution()
"nightholditem" => new NightHoldItemEvolution
{
Item = evolution.Data.GetValue<string>() ?? throw new InvalidDataException("Item is null."),
ToSpecies = evolution.Species,

View File

@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Static.Libraries;
namespace PkmnLib.Dataloader;

View File

@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.AI;

View File

@ -36,7 +36,7 @@ public class RandomAI : PokemonAI
continue;
}
var target = targets[_random.GetInt(targets.Length)];
var moveTurnChoice = new MoveChoice(pokemon, move!, target.side, target.position);
var moveTurnChoice = new MoveChoice(pokemon, move, target.side, target.position);
if (battle.CanUse(moveTurnChoice))
{
return moveTurnChoice;

View File

@ -1,3 +1,4 @@
using JetBrains.Annotations;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Static.Utils;
@ -33,12 +34,19 @@ public interface IMoveChoice : ITurnChoice
/// </summary>
ScriptContainer Script { get; set; }
/// <summary>
/// Additional data that can be used by scripts to store information about the choice.
/// </summary>
Dictionary<StringKey, object?>? AdditionalData { get; }
/// <summary>
/// Volatile effects that are applied to the move choice.
/// </summary>
IScriptSet Volatile { get; }
}
/// <inheritdoc cref="IMoveChoice"/>
[PublicAPI]
public class MoveChoice : TurnChoice, IMoveChoice
{
/// <inheritdoc cref="MoveChoice"/>

View File

@ -525,7 +525,7 @@ public class PokemonImpl : ScriptSource, IPokemon
return null;
if (!library.StaticLibrary.Moves.TryGet(move.MoveName, out var moveData))
throw new KeyNotFoundException($"Move {move.MoveName} not found");
return new LearnedMoveImpl(moveData, move.LearnMethod, move.CurrentPp);
return (ILearnedMove)new LearnedMoveImpl(moveData, move.LearnMethod, move.CurrentPp);
}).ToArray();
AllowedExperience = serializedPokemon.AllowedExperience;
IsEgg = serializedPokemon.IsEgg;

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events_005Chandling/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EV/@EntryIndexedValue">EV</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PP/@EntryIndexedValue">PP</s:String></wpf:ResourceDictionary>

View File

@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using PkmnLib.Static.Utils;
namespace PkmnLib.Static.Libraries;
@ -16,7 +15,7 @@ public interface IReadOnlyTypeLibrary
/// <summary>
/// Gets the type identifier for a type with an index.
/// </summary>
bool TryGetTypeIdentifierFromIndex(byte index, [MaybeNullWhen(false)] out TypeIdentifier typeIdentifier);
bool TryGetTypeIdentifierFromIndex(byte index, out TypeIdentifier typeIdentifier);
/// <summary>
/// Gets the effectiveness for a single attacking type against a single defending type.

View File

@ -35,7 +35,7 @@ public class MoveDataTests
try
{
await Assert.That(test.Library.ScriptResolver.TryResolve(ScriptCategory.Move, scriptName,
test.Move.SecondaryEffect.Parameters, out var script)).IsTrue();
test.Move.SecondaryEffect.Parameters, out _)).IsTrue();
}
catch (Exception e)
{

View File

@ -1,4 +1,3 @@
using System.Collections;
using PkmnLib.Static.Utils;
namespace PkmnLib.Tests.Static;

View File

@ -1,5 +1,5 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Plugin.Gen7.Moves;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;

View File

@ -11,7 +11,7 @@ public class Gen7Plugin : Dynamic.ScriptHandling.Registry.Plugin
{
private readonly Gen7PluginConfiguration _configuration;
public Gen7Plugin() : base()
public Gen7Plugin()
{
_configuration = new Gen7PluginConfiguration();
}

View File

@ -57,6 +57,7 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
executingMove.RunScriptHook(
x => x.ChangeAccuracyModifier(executingMove, target, hitIndex, ref accuracyModifier));
var modifiedAccuracy = (int)(moveAccuracy * accuracyModifier);
// ReSharper disable once AccessToModifiedClosure
executingMove.RunScriptHook(x => x.ChangeAccuracy(executingMove, target, hitIndex, ref modifiedAccuracy));
if (modifiedAccuracy == 255)
return 255;

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Static.Utils;

View File

@ -1,6 +1,6 @@
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
/// <summary>
/// The user nimbly strikes the target. If the user is not holding an item, this attack inflicts massive damage.

View File

@ -1,7 +1,7 @@
using System.Linq;
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
/// <summary>
/// The user applies pressure to stress points, sharply boosting one of its or its allies' stats.

View File

@ -1,4 +1,4 @@
namespace PkmnLib.Plugin.Gen7.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
/// <summary>
/// The user helps the target and makes it use its move right after the user.

View File

@ -4,7 +4,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
/// <summary>
/// The user hurriedly and randomly uses a move among those known by ally Pokémon.

View File

@ -1,7 +1,7 @@
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Static.Species;
namespace PkmnLib.Plugin.Gen7.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
/// <summary>
/// If it is the opposite gender of the user, the target becomes infatuated and less likely to attack.

View File

@ -1,10 +1,9 @@
using System.Collections.Generic;
using PkmnLib.Plugin.Gen7.Scripts;
using PkmnLib.Plugin.Gen7.Scripts.Side;
using PkmnLib.Plugin.Gen7.Scripts.Weather;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
/// <summary>
/// This move reduces damage from physical and special moves for five turns. This can be used only in a hailstorm.
@ -43,7 +42,7 @@ public class AuroraVeil : Script
var side = battle.Sides[move.User.BattleData!.SideIndex];
var numberOfTurns = 5;
var dict = new Dictionary<StringKey, object?>()
var dict = new Dictionary<StringKey, object?>
{
{ "duration", numberOfTurns },
};

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
/// <summary>
/// The user sheds part of its body to make itself lighter and sharply raise its Speed stat.
@ -27,7 +27,7 @@ public class Autotomize : Script
if (user.ChangeStatBoost(Statistic.Speed, 2, true) && user.ChangeWeightInKgBy(-100.0f))
{
var battle = user.BattleData?.Battle;
battle?.EventHook.Invoke(new DialogEvent("pokemon_became_nimble", new Dictionary<string, object>()
battle?.EventHook.Invoke(new DialogEvent("pokemon_became_nimble", new Dictionary<string, object>
{
{ "pokemon", user },
}));

View File

@ -1,4 +1,3 @@
using System;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Events;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "change_all_target_stats")]
public class ChangeAllTargetStats : Script

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
@ -34,7 +33,7 @@ public class ChangeMultipleTargetStatBoosts : Script
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
EventBatchId batchId = new();
foreach (var stat in _statBoosts!)
foreach (var stat in _statBoosts)
{
target.ChangeStatBoost(stat.Key, stat.Value, true, batchId);
}

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
@ -34,7 +33,7 @@ public class ChangeMultipleUserStatBoosts : Script
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
EventBatchId batchId = new();
foreach (var stat in _statBoosts!)
foreach (var stat in _statBoosts)
{
move.User.ChangeStatBoost(stat.Key, stat.Value, true, batchId);
}

View File

@ -1,4 +1,3 @@
using System.Linq;
using PkmnLib.Plugin.Gen7.Scripts.Side;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -30,7 +30,7 @@ public class DoublePowerIfTargetDamagedInTurn : Script
var data = side.VolatileScripts.Get<DoublePowerIfTargetDamagedInTurnData>();
if (data == null)
return;
if (data._hitPokemon.Contains(target))
if (data.HitPokemon.Contains(target))
basePower *= 2;
}
}

View File

@ -25,6 +25,6 @@ public class Drain : Script
var healed = (uint)(damage * DrainModifier);
if (move.User.HasHeldItem("big_root"))
healed = (uint)(healed * 1.3f);
user.Heal(healed, false);
user.Heal(healed);
}
}

View File

@ -18,6 +18,6 @@ public class DreamEater : Script
var healed = (uint)(damage * 0.5f);
if (move.User.HasHeldItem("big_root"))
healed = (uint)(healed * 1.3f);
user.Heal(healed, false);
user.Heal(healed);
}
}

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -16,7 +16,7 @@ public class FlareBlitz : Script
}
var hitData = move.GetHitData(target, hit);
var recoilDamage = (uint)(hitData.Damage * (1 / 3));
var recoilDamage = hitData.Damage * (1 / 3);
move.User.Damage(recoilDamage, DamageSource.Misc);
}
}

View File

@ -1,5 +1,3 @@
using PkmnLib.Plugin.Gen7.Scripts.Terrain;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "floral_healing")]

View File

@ -1,7 +1,4 @@
using System;
using PkmnLib.Plugin.Gen7.Scripts.Battle;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -1,5 +1,3 @@
using PkmnLib.Plugin.Gen7.Scripts.Terrain;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "genesis_supernova")]

View File

@ -1,5 +1,3 @@
using PkmnLib.Plugin.Gen7.Scripts.Terrain;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "grassy_terrain")]

View File

@ -20,7 +20,7 @@ public class HealEachEndOfTurn : Script
}
else
{
_healPercentage = healPercentage!;
_healPercentage = healPercentage;
}
}

View File

@ -1,4 +1,3 @@
using System;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -1,5 +1,3 @@
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "mimic")]

View File

@ -1,4 +1,3 @@
using PkmnLib.Static;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -1,5 +1,4 @@
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Static.Utils;

View File

@ -1,4 +1,3 @@
using System.Collections.Generic;
using PkmnLib.Plugin.Gen7.Scripts.Status;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -1,5 +1,4 @@
using System;
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Static.Utils;

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using PkmnLib.Dynamic.Models.BattleFlow;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -13,7 +13,7 @@ public class Rest : Script
move.GetHitData(target, hit).Fail();
return;
}
if (!move.User.Heal(move.User.MaxHealth, false, forceHeal: false))
if (!move.User.Heal(move.User.MaxHealth))
{
move.GetHitData(target, hit).Fail();
return;

View File

@ -1,4 +1,3 @@
using System.Linq;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -1,5 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@ -17,7 +17,7 @@ public class SetWeather : Script
{
throw new Exception("Weather not provided.");
}
_weather = weather!.ToString();
_weather = weather.ToString();
if (parameters.TryGetValue("turns", out var turns) && turns is int turn)
{
_defaultTurns = turn;

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
@ -52,6 +50,6 @@ public class BideEffect : Script
return;
}
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "bide", opposingSideIndex, position);
choice = _choice = TurnChoiceHelper.CreateMoveChoice(_owner, "bide", opposingSideIndex, position);
}
}

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Static.Libraries;
using PkmnLib.Static.Utils;
@ -9,14 +8,12 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "foresight")]
public class ForesightEffect : Script
{
private readonly IReadOnlyTypeLibrary _typeLibrary;
private readonly TypeIdentifier _normalType;
private readonly TypeIdentifier _fightingType;
private readonly TypeIdentifier _ghostType;
public ForesightEffect(IReadOnlyTypeLibrary typeLibrary)
{
_typeLibrary = typeLibrary;
typeLibrary.TryGetTypeIdentifier("normal", out _normalType);
typeLibrary.TryGetTypeIdentifier("fighting", out _fightingType);
typeLibrary.TryGetTypeIdentifier("ghost", out _ghostType);

View File

@ -15,7 +15,7 @@ public class Infatuated : Script
/// <inheritdoc />
public override void PreventMove(IExecutingMove move, ref bool prevent)
{
if (move.User.BattleData?.Battle?.Random.GetBool() == true)
if (move.User.BattleData?.Battle.Random.GetBool() == true)
prevent = true;
}
}

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Static.Utils;

View File

@ -23,7 +23,7 @@ public abstract class OutrageLikeEffect : Script
/// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice)
{
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "_move", _targetSide, _targetPosition);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, _move, _targetSide, _targetPosition);
}
/// <inheritdoc />

View File

@ -1,5 +1,3 @@
using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "perish_song")]

View File

@ -5,7 +5,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Side;
[Script(ScriptCategory.Side, "double_power_if_target_damaged_in_turn_data")]
public class DoublePowerIfTargetDamagedInTurnData : Script
{
public HashSet<IPokemon> _hitPokemon = new();
public readonly HashSet<IPokemon> HitPokemon = [];
/// <param name="battle"></param>
/// <inheritdoc />
@ -17,6 +17,6 @@ public class DoublePowerIfTargetDamagedInTurnData : Script
/// <inheritdoc />
public override void OnDamage(IPokemon pokemon, DamageSource source, uint oldHealth, uint newHealth)
{
_hitPokemon.Add(pokemon);
HitPokemon.Add(pokemon);
}
}