Skip to content

Commit

Permalink
add great success to expedition check
Browse files Browse the repository at this point in the history
  • Loading branch information
myangelkamikaze committed Oct 1, 2024
1 parent be8e1dd commit 5d8a609
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ExpeditionViewModel(Expedition expedition, FleetInfoViewModel fleetInfo,

private void UpdateGreatSuccessRate(object? sender, PropertyChangedEventArgs e)
{
GreatSuccessRate = Math.Clamp(GetGreatSuccessRate(Model, FleetInfo), 0, 1);
GreatSuccessRate = Math.Clamp(FleetInfo.GreatSuccessRate(Model), 0, 1);

UpdateScore(sender, e);
}
Expand Down Expand Up @@ -100,41 +100,4 @@ private static int ExpeditionRewardWeight(UseItemId type, ExpeditionScoreWeights
UseItemId.MoraleFoodIrako => weights.MoraleFoodIrako,
_ => 0,
};

private static double GetGreatSuccessRate(Expedition model, FleetInfoViewModel fleetInfo) => model.GreatSuccessType switch
{
GreatSuccessType.Regular => RegularGreatSuccessRate(fleetInfo),
GreatSuccessType.Drum => DrumGreatSuccessRate(model, fleetInfo),
GreatSuccessType.Level => LevelGreatSuccessRate(fleetInfo),

_ => 0,
};

private static double RegularGreatSuccessRate(FleetInfoViewModel fleetInfo) => fleetInfo.AllSparkled switch
{
false => 0,
_ => fleetInfo.SparkleCount * 0.15 + 0.21
};

private static double DrumGreatSuccessRate(Expedition model, FleetInfoViewModel fleetInfo)
=> fleetInfo.SparkleCount * 0.15 + GetDrumBonus(model, fleetInfo);

private static double GetDrumBonus(Expedition model, FleetInfoViewModel fleetInfo)
=> (model.Id, fleetInfo.DrumCount) switch
{
(21, >= 4) => 0.41,
(24, >= 2) => 0.41,
(37, >= 5) => 0.41,
(38, >= 10) => 0.41,
(40, >= 4) => 0.41,
(44, >= 8) => 0.41,
(142, >= 6) => 0.41,

_ => 0.06,
};

private static double LevelGreatSuccessRate(FleetInfoViewModel fleetInfo)
=> fleetInfo.SparkleCount * 0.15 + 0.16
+ Math.Sqrt(fleetInfo.FlagshipLevel) / 100
+ fleetInfo.FlagshipLevel / 1000.0;
}
41 changes: 41 additions & 0 deletions ElectronicObserver.Avalonia/ExpeditionCalculator/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace ElectronicObserver.Avalonia.ExpeditionCalculator;

public static class Extensions
{
public static double GreatSuccessRate(this FleetInfoViewModel fleetInfo, Expedition model) => model.GreatSuccessType switch
{
GreatSuccessType.Regular => RegularGreatSuccessRate(fleetInfo),
GreatSuccessType.Drum => DrumGreatSuccessRate(model, fleetInfo),
GreatSuccessType.Level => LevelGreatSuccessRate(fleetInfo),

_ => 0,
};

private static double RegularGreatSuccessRate(FleetInfoViewModel fleetInfo) => fleetInfo.AllSparkled switch
{
false => 0,
_ => fleetInfo.SparkleCount * 0.15 + 0.21
};

private static double DrumGreatSuccessRate(Expedition model, FleetInfoViewModel fleetInfo)
=> fleetInfo.SparkleCount * 0.15 + DrumBonus(model, fleetInfo);

private static double DrumBonus(Expedition model, FleetInfoViewModel fleetInfo)
=> (model.Id, fleetInfo.DrumCount) switch
{
(21, >= 4) => 0.41,
(24, >= 2) => 0.41,
(37, >= 5) => 0.41,
(38, >= 10) => 0.41,
(40, >= 4) => 0.41,
(44, >= 8) => 0.41,
(142, >= 6) => 0.41,

_ => 0.06,
};

private static double LevelGreatSuccessRate(FleetInfoViewModel fleetInfo)
=> fleetInfo.SparkleCount * 0.15 + 0.16
+ Math.Sqrt(fleetInfo.FlagshipLevel) / 100
+ fleetInfo.FlagshipLevel / 1000.0;
}
2 changes: 1 addition & 1 deletion ElectronicObserver/Data/MissionClearCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ public class MissionClearConditionResult
/// </summary>
public ReadOnlyCollection<string> FailureReason => failureReason.AsReadOnly();

private IFleetData? TargetFleet { get; }
public IFleetData? TargetFleet { get; }
private IEnumerable<IShipData> Members => (TargetFleet?.MembersInstance ?? Enumerable.Empty<IShipData?>())
.Where(s => s is not null)
.Cast<IShipData>();
Expand Down
92 changes: 59 additions & 33 deletions ElectronicObserver/Window/Wpf/ExpeditionCheck/ExpeditionCheckRow.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
using System.Linq;
using System.Windows.Media;
using ElectronicObserver.Window.Dialog;
using ElectronicObserver.Avalonia.ExpeditionCalculator;
using ElectronicObserver.Data;
using ElectronicObserverTypes;
using static ElectronicObserver.Data.MissionClearCondition;

namespace ElectronicObserver.Window.Wpf.ExpeditionCheck;

public class ExpeditionCheckRow
{
public int AreaId { get; set; }
public int ExpeditionId { get; set; }
public required int AreaId { get; init; }
public required int ExpeditionId { get; init; }

public string ExpeditionDisplayId { get; set; }
public string AreaName { get; set; }
public string ExpeditionName { get; set; }
public required string ExpeditionDisplayId { get; init; }
public required string AreaName { get; init; }
public required string ExpeditionName { get; set; }

public MissionClearConditionResult Fleet1Result { get; set; }
public required MissionClearCondition.MissionClearConditionResult Fleet1Result { get; init; }
public required MissionClearCondition.MissionClearConditionResult Fleet2Result { get; init; }
public required MissionClearCondition.MissionClearConditionResult Fleet3Result { get; init; }
public required MissionClearCondition.MissionClearConditionResult Fleet4Result { get; init; }
public required MissionClearCondition.MissionClearConditionResult Conditions { get; init; }

public MissionClearConditionResult Fleet2Result { get; set; }

public MissionClearConditionResult Fleet3Result { get; set; }

public MissionClearConditionResult Fleet4Result { get; set; }

public MissionClearConditionResult Conditions { get; set; }

public ExpeditionType ExpeditionType { get; set; }
public required ExpeditionType ExpeditionType { get; init; }

public string IdDisplay => $"{ExpeditionDisplayId}: {AreaName}";

Expand All @@ -34,6 +30,7 @@ public class ExpeditionCheckRow
public SolidColorBrush Fleet3BackgroundColor => GetBackgroundColor(Fleet3Result).ToBrush();
public SolidColorBrush Fleet4BackgroundColor => GetBackgroundColor(Fleet4Result).ToBrush();
public SolidColorBrush WorldBackgroundColor => GetBackground().ToBrush();

public string Fleet1Text => GetText(Fleet1Result);
public string Fleet2Text => GetText(Fleet2Result);
public string Fleet3Text => GetText(Fleet3Result);
Expand All @@ -48,7 +45,7 @@ public class ExpeditionCheckRow

public int SortId => AreaId * 1000 + ExpeditionId;

private System.Drawing.Color GetBackgroundColor(MissionClearConditionResult result) => result?.IsSuceeded switch
private System.Drawing.Color GetBackgroundColor(MissionClearCondition.MissionClearConditionResult result) => result.IsSuceeded switch
{
false => Utility.Configuration.Config.UI.ThemeMode switch
{
Expand All @@ -57,9 +54,10 @@ public class ExpeditionCheckRow
},
_ => GetBackground()
};

private System.Drawing.Color GetBackground()
{
if(AreaId % 2 == 1 && AreaId != 7)
if (AreaId % 2 == 1 && AreaId != 7)
{
return Utility.Configuration.Config.UI.BackColor;
}
Expand All @@ -68,46 +66,74 @@ private System.Drawing.Color GetBackground()
return Utility.Configuration.Config.UI.SubBackColor;
}
}
private string GetText(MissionClearConditionResult result) => result?.IsSuceeded switch

private string GetText(MissionClearCondition.MissionClearConditionResult result) => result.IsSuceeded switch
{
true => GetSuccessText(result),
false => string.Join(", ", result.FailureReason),
_ => ""
};

private string GetSuccessText(MissionClearConditionResult result) => result?.FailureReason.Any() switch
private string GetSuccessText(MissionClearCondition.MissionClearConditionResult result) => result.FailureReason.Any() switch
{
true => string.Join(", ", result.FailureReason),
false => ExpeditionType switch
{
ExpeditionType.CombatTypeTwoExpedition => result switch
{
{ SuccessType: BattleExpeditionSuccessType.GreatSuccess } => DialogRes.ExpeditionCheckDoubleOkSign,
_ => DialogRes.ExpeditionCheckOkSign
{ SuccessType: BattleExpeditionSuccessType.GreatSuccess } => DialogRes.ExpeditionCheckDoubleOkSign + GreatSuccessRate(result),
_ => GreatSuccessRate(result),
} + string.Join(", ", result.SuccessPercent),

ExpeditionType.CombatTypeOneExpedition => DialogRes.ExpeditionCheckOkSign + string.Join(", ", result.SuccessPercent),
_ => DialogRes.ExpeditionCheckOkSign
ExpeditionType.CombatTypeOneExpedition => GreatSuccessRate(result) + string.Join(", ", result.SuccessPercent),
_ => GreatSuccessRate(result),
},
_ => ""
};

private string? GetResultTooltip(MissionClearConditionResult result) => result?.IsSuceeded switch
private string? GetResultTooltip(MissionClearCondition.MissionClearConditionResult result) => result.IsSuceeded switch
{
true => GetSuccessToolTip(result),
false => string.Join("\n", result.FailureReason),
_ => null
};


private string? GetSuccessToolTip(MissionClearConditionResult result) => result?.FailureReason.Any() switch
private string? GetSuccessToolTip(MissionClearCondition.MissionClearConditionResult result) => result.FailureReason.Any() switch
{
true => string.Join(", ", result.FailureReason),
false => ExpeditionType switch
{
ExpeditionType.CombatTypeTwoExpedition or ExpeditionType.CombatTypeOneExpedition => string.Join("\n", result.SuccessPercent),
ExpeditionType.CombatTypeTwoExpedition or
ExpeditionType.CombatTypeOneExpedition
=> string.Join("\n", [GreatSuccessRate(result), .. result.SuccessPercent]),

_ => null
},
_ => null
};

private string GreatSuccessRate(MissionClearCondition.MissionClearConditionResult result)
{
string unknownGreatSuccess = $"{ExpeditionCalculatorResources.GreatSuccess} ???";

if (result.TargetFleet is not IFleetData fleet) return unknownGreatSuccess;
if (fleet.MembersInstance.FirstOrDefault() is not IShipData flagship) return unknownGreatSuccess;

Expedition? expedition = ExpeditionCalculatorData.Expeditions
.Find(e => e.Id == ExpeditionId);

if (expedition is null) return unknownGreatSuccess;

FleetInfoViewModel fleetInfo = new()
{
AllSparkled = fleet.MembersInstance.OfType<IShipData>().All(s => s.Condition > 49),
SparkleCount = fleet.MembersInstance.OfType<IShipData>().Count(s => s.Condition > 49),
DrumCount = fleet.MembersInstance
.OfType<IShipData>()
.SelectMany(s => s.AllSlotInstance)
.OfType<IEquipmentData>()
.Count(e => e.MasterEquipment.CategoryType is EquipmentTypes.TransportContainer),
FlagshipLevel = flagship.Level,
};

double greatSuccessRate = fleetInfo.GreatSuccessRate(expedition);

return $"{ExpeditionCalculatorResources.GreatSuccess} {greatSuccessRate:P2}";
}
}

0 comments on commit 5d8a609

Please sign in to comment.