diff --git a/WFBot/Features/Common/WFNotificationHandler.cs b/WFBot/Features/Common/WFNotificationHandler.cs index bb14c81..f05bcad 100644 --- a/WFBot/Features/Common/WFNotificationHandler.cs +++ b/WFBot/Features/Common/WFNotificationHandler.cs @@ -290,14 +290,14 @@ private void CheckInvasions() private static IEnumerable GetAllInvasionsCountedItems(WFInvasion inv) { - foreach (var reward in inv.attackerReward.countedItems) + foreach (var reward in inv.Attacker.Reward.countedItems) { - yield return reward.type; + yield return reward.Type; } - foreach (var reward in inv.defenderReward.countedItems) + foreach (var reward in inv.Defender.Reward.countedItems) { - yield return reward.type; + yield return reward.Type; } } diff --git a/WFBot/Features/ImageRendering/ImageRenderHelper.cs b/WFBot/Features/ImageRendering/ImageRenderHelper.cs index b254703..e6d0fcb 100644 --- a/WFBot/Features/ImageRendering/ImageRenderHelper.cs +++ b/WFBot/Features/ImageRendering/ImageRenderHelper.cs @@ -105,14 +105,16 @@ public static Image SingleInvasion(WFInvasion invasion) var grineerColor = ColorX.FromArgb(227, 49, 62); var infestedColor = ColorX.FromArgb(106, 220, 141); var corpusColor = ColorX.FromArgb(96, 182, 229); - var aColor = invasion.attackingFaction switch + var attacker = invasion.Attacker; + var aColor = attacker.Faction switch { "Corpus" => corpusColor, "Infested" => infestedColor, "Grineer" => grineerColor }; var aPercent = invasion.completion / 100.0; - var bColor = invasion.defendingFaction switch + var defender = invasion.Defender; + var bColor = defender.Faction switch { "Corpus" => corpusColor, "Infested" => infestedColor, @@ -124,19 +126,19 @@ public static Image SingleInvasion(WFInvasion invasion) var breakPoint = (int)(aPercent * percentageImage.Width); percentageImage.Mutate(x => x.Fill(new Rgba32(aColor.R, aColor.G, aColor.B), new RectangleF(0,0, breakPoint, percentageImage.Height))); percentageImage.Mutate(x => x.Fill(new Rgba32(bColor.R, bColor.G, bColor.B), new RectangleF(breakPoint, 0, percentageImage.Width - breakPoint, percentageImage.Height))); - var factionA = $"{invasion.attackingFaction.ToUpper()} {aPercent*100:F1}%"; - var factionB = $"{bPercent*100:F1}% {invasion.defendingFaction.ToUpper()}"; - var rewardA = $"{(!invasion.vsInfestation ? $"{WFFormatter.ToString(invasion.attackerReward)}" : "")}"; - var rewardB = $"{WFFormatter.ToString(invasion.defenderReward)}"; + var factionA = $"{attacker.Faction.ToUpper()} {aPercent*100:F1}%"; + var factionB = $"{bPercent*100:F1}% {defender.Faction.ToUpper()}"; + var rewardA = $"{(!invasion.vsInfestation ? $"{WFFormatter.ToString(attacker.Reward)}" : "")}"; + var rewardB = $"{WFFormatter.ToString(defender.Reward)}"; var textOptions = CreateTextOptions(18); var factionImage = new Image(560, 40); var rewardImage = new Image(560, 40); - using var attackerImage = GetResource($"Factions.{invasion.attackingFaction.ToLower()}").Clone().Resize(30, 30); - using var defenderImage = GetResource($"Factions.{invasion.defendingFaction.ToLower()}").Clone().Resize(30, 30); + using var attackerImage = GetResource($"Factions.{attacker.Faction.ToLower()}").Clone().Resize(30, 30); + using var defenderImage = GetResource($"Factions.{defender.Faction.ToLower()}").Clone().Resize(30, 30); using var attackerReward = invasion.vsInfestation ? new Image(35, 35) - : GetInvasionReward(invasion.attackerReward.countedItems.First().type).Clone().Resize(35, 35); - using var defenderReward = GetInvasionReward(invasion.defenderReward.countedItems.First().type).Clone().Resize(35, 35); + : GetInvasionReward(attacker.Reward.countedItems.First().Type).Clone().Resize(35, 35); + using var defenderReward = GetInvasionReward(defender.Reward.countedItems.First().Type).Clone().Resize(35, 35); var desc = RenderText($"{FlipNode(invasion.node)}", CreateTextOptions(23)); factionImage.Mutate(x => x.DrawImage(attackerImage, new Point(0,0), new GraphicsOptions())); rewardImage.Mutate(x => x.DrawImage(attackerReward, new Point(0,0), new GraphicsOptions())); diff --git a/WFBot/Features/Utils/WFFormatter.cs b/WFBot/Features/Utils/WFFormatter.cs index 7f6fe69..a772904 100644 --- a/WFBot/Features/Utils/WFFormatter.cs +++ b/WFBot/Features/Utils/WFFormatter.cs @@ -736,14 +736,14 @@ public static string ToString(WFInvasion inv, bool isNotification = false) } sb.AppendLine($"地点: [{inv.node}]"); - sb.AppendLine($"> 进攻方: {inv.attackingFaction}"); + sb.AppendLine($"> 进攻方: {inv.Attacker.Faction}"); if (!inv.vsInfestation) - sb.AppendLine($"奖励: {ToString(inv.attackerReward)}"); + sb.AppendLine($"奖励: {ToString(inv.Attacker.Reward)}"); sb.AppendLine($"进度: {completion}%"); // sb.AppendLine(); - sb.AppendLine($"> 防守方: {inv.defendingFaction}"); - sb.AppendLine($"奖励: {ToString(inv.defenderReward)}"); + sb.AppendLine($"> 防守方: {inv.Defender.Faction}"); + sb.AppendLine($"奖励: {ToString(inv.Defender.Reward)}"); sb.Append($"进度 {100 - completion}%"); return sb.ToString(); } @@ -908,7 +908,7 @@ public static string ToString(RewardInfo reward) foreach (var item in reward.countedItems) { - rewards.Add($"{item.count}x{item.type}"); + rewards.Add($"{item.Count}x{item.Type}"); } return string.Join(" + ", rewards); diff --git a/WFBot/Features/Utils/WFObjects.cs b/WFBot/Features/Utils/WFObjects.cs index 626600e..b90d2ea 100644 --- a/WFBot/Features/Utils/WFObjects.cs +++ b/WFBot/Features/Utils/WFObjects.cs @@ -1763,10 +1763,15 @@ public class WFInvasion public string startString { get; set; } public string node { get; set; } public string desc { get; set; } - public RewardInfo attackerReward { get; set; } - public string attackingFaction { get; set; } - public RewardInfo defenderReward { get; set; } - public string defendingFaction { get; set; } + + [JsonProperty("attackingFaction")] + public string AttackingFaction { get; set; } + + [JsonProperty("attacker")] + public Attacker Attacker { get; set; } + + [JsonProperty("defender")] + public Attacker Defender { get; set; } public bool vsInfestation { get; set; } public int count { get; set; } public int requiredRuns { get; set; } @@ -1775,11 +1780,28 @@ public class WFInvasion public string eta { get; set; } public string[] rewardTypes { get; set; } } + public class Attacker + { + [JsonProperty("reward", NullValueHandling = NullValueHandling.Include)] + public RewardInfo Reward { get; set; } + [JsonProperty("faction")] + public string Faction { get; set; } + + [JsonProperty("factionKey")] + public string FactionKey { get; set; } + } public class RewardInfo { + private CountedItem[] countedItems1; public object[] items { get; set; } - public Counteditem[] countedItems { get; set; } + + public CountedItem[] countedItems + { + get => countedItems1 ?? Array.Empty(); + set => countedItems1 = value; + } + public int credits { get; set; } public string asString { get; set; } public string itemString { get; set; } @@ -1787,12 +1809,6 @@ public class RewardInfo public int color { get; set; } } - public class Counteditem - { - public int count { get; set; } - public string type { get; set; } - } - public class ArchonHunt { diff --git a/WFBot/Features/Utils/WFTranslator.cs b/WFBot/Features/Utils/WFTranslator.cs index 641c845..01ca4d3 100644 --- a/WFBot/Features/Utils/WFTranslator.cs +++ b/WFBot/Features/Utils/WFTranslator.cs @@ -333,8 +333,11 @@ public TranslateResult TranslateSearchWord(string source) public void TranslateInvasion(WFInvasion invasion) { - TranslateReward(invasion.attackerReward); - TranslateReward(invasion.defenderReward); + if (!invasion.vsInfestation) + { + TranslateReward(invasion.Attacker.Reward); + } + TranslateReward(invasion.Defender.Reward); invasion.node = TranslateNode(invasion.node); @@ -345,12 +348,12 @@ private void TranslateReward(RewardInfo reward) { foreach (var item in reward.countedItems) { - item.type = invasionTranslator.Translate(item.type).Result; + item.Type = invasionTranslator.Translate(item.Type).Result; } foreach (var t in reward.countedItems) { - t.type = dictTranslator.Translate(t.type).Result; + t.Type = dictTranslator.Translate(t.Type).Result; } }