Skip to content

Commit

Permalink
修复入侵Api变动导致的报错
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealKamisama committed Apr 1, 2024
1 parent c6b6756 commit e6d38bd
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 34 deletions.
8 changes: 4 additions & 4 deletions WFBot/Features/Common/WFNotificationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ private void CheckInvasions()

private static IEnumerable<string> 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;
}
}

Expand Down
22 changes: 12 additions & 10 deletions WFBot/Features/ImageRendering/ImageRenderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ public static Image<Rgba32> 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

Check warning on line 109 in WFBot/Features/ImageRendering/ImageRenderHelper.cs

View workflow job for this annotation

GitHub Actions / build

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '""' is not covered.

Check warning on line 109 in WFBot/Features/ImageRendering/ImageRenderHelper.cs

View workflow job for this annotation

GitHub Actions / publish

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '""' is not covered.
{
"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

Check warning on line 117 in WFBot/Features/ImageRendering/ImageRenderHelper.cs

View workflow job for this annotation

GitHub Actions / build

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '""' is not covered.

Check warning on line 117 in WFBot/Features/ImageRendering/ImageRenderHelper.cs

View workflow job for this annotation

GitHub Actions / publish

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '""' is not covered.
{
"Corpus" => corpusColor,
"Infested" => infestedColor,
Expand All @@ -124,19 +126,19 @@ public static Image<Rgba32> 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<Rgba32>(560, 40);
var rewardImage = new Image<Rgba32>(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<Rgba32>(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()));
Expand Down
10 changes: 5 additions & 5 deletions WFBot/Features/Utils/WFFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 27 additions & 11 deletions WFBot/Features/Utils/WFObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -1775,24 +1780,35 @@ 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<CountedItem>();
set => countedItems1 = value;
}

public int credits { get; set; }
public string asString { get; set; }
public string itemString { get; set; }
public string thumbnail { get; set; }
public int color { get; set; }
}

public class Counteditem
{
public int count { get; set; }
public string type { get; set; }
}


public class ArchonHunt
{
Expand Down
11 changes: 7 additions & 4 deletions WFBot/Features/Utils/WFTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
}

Expand Down

0 comments on commit e6d38bd

Please sign in to comment.