From b6c22a2d51f2f569ae5ba92a7c4c025616944744 Mon Sep 17 00:00:00 2001 From: Xian55 <367101+Xian55@users.noreply.github.com> Date: Wed, 22 Dec 2021 16:35:37 +0100 Subject: [PATCH] Core: replace Tuple with ValueTuple --- Core/Actionbar/ActionBarCooldownReader.cs | 11 ++++++----- Core/Actionbar/ActionBarCostReader.cs | 10 +++++----- Core/ClassConfig/KeyAction.cs | 10 +++++----- Core/Goals/CombatUtil.cs | 6 +++--- Core/Path/DirectionCalculator.cs | 4 ++-- Core/Requirement/RequirementFactory.cs | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Core/Actionbar/ActionBarCooldownReader.cs b/Core/Actionbar/ActionBarCooldownReader.cs index 6352479d9..cc25b8200 100644 --- a/Core/Actionbar/ActionBarCooldownReader.cs +++ b/Core/Actionbar/ActionBarCooldownReader.cs @@ -11,7 +11,7 @@ public class ActionBarCooldownReader private readonly float MAX_ACTION_IDX = 100000f; private readonly float MAX_VALUE_MUL = 100f; - private readonly Dictionary> dict = new Dictionary>(); + private readonly Dictionary dict = new Dictionary(); public ActionBarCooldownReader(ISquareReader reader, int cActionbarNum) { @@ -31,12 +31,12 @@ public void Read() newCooldown /= MAX_VALUE_MUL; - if (dict.TryGetValue(index, out var tuple) && tuple.Item1 != (int)newCooldown) + if (dict.TryGetValue(index, out var tuple) && tuple.duration != (int)newCooldown) { dict.Remove(index); } - dict.TryAdd(index, Tuple.Create((int)newCooldown, DateTime.Now)); + dict.TryAdd(index, ((int)newCooldown, DateTime.Now)); } public void Reset() @@ -55,8 +55,9 @@ public int GetRemainingCooldown(PlayerReader playerReader, KeyAction keyAction) if (dict.TryGetValue(slot, out var tuple)) { - if (tuple.Item1 == 0) return 0; - return Math.Clamp((int)(tuple.Item2.AddSeconds(tuple.Item1) - DateTime.Now).TotalMilliseconds, 0, int.MaxValue); + return tuple.duration == 0 + ? 0 + : Math.Clamp((int)(tuple.startTime.AddSeconds(tuple.duration) - DateTime.Now).TotalMilliseconds, 0, int.MaxValue); } } diff --git a/Core/Actionbar/ActionBarCostReader.cs b/Core/Actionbar/ActionBarCostReader.cs index dd79cd1d5..1678f0e56 100644 --- a/Core/Actionbar/ActionBarCostReader.cs +++ b/Core/Actionbar/ActionBarCostReader.cs @@ -26,9 +26,9 @@ public class ActionBarCostReader private readonly float MAX_ACTION_IDX = 1000f; //https://wowwiki-archive.fandom.com/wiki/ActionSlot - private readonly Dictionary> dict = new Dictionary>(); + private readonly Dictionary dict = new Dictionary(); - private readonly Tuple empty = new Tuple(PowerType.Mana,0); + private readonly (PowerType type, int cost) empty = (PowerType.Mana, 0); public int MaxCount { get; } = 108; // maximum amount of actionbar slot which tracked @@ -57,12 +57,12 @@ public void Read() int cost = data; - if (dict.TryGetValue(index, out var tuple) && tuple.Item2 != cost) + if (dict.TryGetValue(index, out var tuple) && tuple.cost != cost) { dict.Remove(index); } - if (dict.TryAdd(index, Tuple.Create((PowerType)type, cost))) + if (dict.TryAdd(index, ((PowerType)type, cost))) { OnActionCostChanged?.Invoke(this, new ActionBarCostEventArgs(index, (PowerType)type, cost)); } @@ -73,7 +73,7 @@ public void Reset() dict.Clear(); } - public Tuple GetCostByActionBarSlot(PlayerReader playerReader, KeyAction keyAction) + public (PowerType type, int cost) GetCostByActionBarSlot(PlayerReader playerReader, KeyAction keyAction) { if (KeyReader.ActionBarSlotMap.TryGetValue(keyAction.Key, out int slot)) { diff --git a/Core/ClassConfig/KeyAction.cs b/Core/ClassConfig/KeyAction.cs index 66466b845..8fdc2b2a0 100644 --- a/Core/ClassConfig/KeyAction.cs +++ b/Core/ClassConfig/KeyAction.cs @@ -237,22 +237,22 @@ public bool HasFormRequirement() private void UpdateMinResourceRequirement(PlayerReader playerReader, ActionBarCostReader actionBarCostReader) { var tuple = actionBarCostReader.GetCostByActionBarSlot(playerReader, this); - if (tuple.Item2 != 0) + if (tuple.cost != 0) { int oldValue = 0; - switch (tuple.Item1) + switch (tuple.type) { case PowerType.Mana: oldValue = MinMana; - MinMana = tuple.Item2; + MinMana = tuple.cost; break; case PowerType.Rage: oldValue = MinRage; - MinRage = tuple.Item2; + MinRage = tuple.cost; break; case PowerType.Energy: oldValue = MinEnergy; - MinEnergy = tuple.Item2; + MinEnergy = tuple.cost; break; } diff --git a/Core/Goals/CombatUtil.cs b/Core/Goals/CombatUtil.cs index 9f6032cc5..ee58d44bd 100644 --- a/Core/Goals/CombatUtil.cs +++ b/Core/Goals/CombatUtil.cs @@ -97,7 +97,7 @@ public bool IsPlayerMoving(Vector3 lastPos) return distance > 0.01f; } - public async ValueTask> FoundTargetWhileMoved() + public async ValueTask<(bool foundTarget, bool hadToMove)> FoundTargetWhileMoved() { bool hadToMove = false; var startedMoving = await wait.InterruptTask(200, () => lastPosition != playerReader.PlayerLocation); @@ -113,12 +113,12 @@ public async ValueTask> FoundTargetWhileMoved() if (!await Wait(100, EnteredCombat())) { if (await AquiredTarget()) - return Tuple.Create(true, hadToMove); + return (true, hadToMove); } } - return Tuple.Create(false, hadToMove); + return (false, hadToMove); } diff --git a/Core/Path/DirectionCalculator.cs b/Core/Path/DirectionCalculator.cs index 82a249809..98fd1e70c 100644 --- a/Core/Path/DirectionCalculator.cs +++ b/Core/Path/DirectionCalculator.cs @@ -13,10 +13,10 @@ public static float CalculateHeading(Vector3 from, Vector3 to) return MathF.PI + target; } - public static Tuple ToNormalRadian(float wowRadian) + public static (float, float) ToNormalRadian(float wowRadian) { // wow origo is north side - shifted 90 degree - return new Tuple( + return ( MathF.Cos(wowRadian + (MathF.PI / 2)), MathF.Sin(wowRadian - (MathF.PI / 2))); } diff --git a/Core/Requirement/RequirementFactory.cs b/Core/Requirement/RequirementFactory.cs index bc34c4344..34882f728 100644 --- a/Core/Requirement/RequirementFactory.cs +++ b/Core/Requirement/RequirementFactory.cs @@ -430,7 +430,7 @@ private void BindMinCost(KeyAction item) if (!valueDictionary.ContainsKey(key)) { valueDictionary.Add(key, - () => addonReader.ActionBarCostReader.GetCostByActionBarSlot(playerReader, item).Item2); + () => addonReader.ActionBarCostReader.GetCostByActionBarSlot(playerReader, item).cost); } }