Skip to content

Commit

Permalink
resharp functions & make bonus correct at sortie
Browse files Browse the repository at this point in the history
  • Loading branch information
lasedark committed May 26, 2021
1 parent ca87e6e commit 515b6bb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 54 deletions.
17 changes: 6 additions & 11 deletions LandBasedAirCorpsPlugin/Models/AirRegiment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,12 @@ public double AirSuperiority
{
get
{
if (this.Behavior == AirRegimentBehavior.Defense)
{
var bonus = this.Squadrons
.Where(x => x.State == SquadronState.Deployed)
.MaxByViewRange()
.GetSurveillanceBonus();

return Math.Floor(this.Squadrons.Select(x => x.AirSuperiorityAtDefense).Sum() * bonus);
}

return this.Squadrons.Select(x => x.AirSuperiorityAtSortie).Sum();
var bonus = this.Squadrons
.Where(x => x.State == SquadronState.Deployed)
.MaxByViewRange()
.GetSurveillanceBonus(this.Behavior);

return Math.Floor(this.Squadrons.Select(x => x.GetAirSuperiority(this.Behavior)).Sum() * bonus);
}
}

Expand Down
32 changes: 21 additions & 11 deletions LandBasedAirCorpsPlugin/Models/Calculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,36 @@ public static Squadron MaxByViewRange(this IEnumerable<Squadron> source)
: null;
}

public static double GetSurveillanceBonus(this Squadron squadron)
public static double GetSurveillanceBonus(this Squadron squadron, AirRegimentBehavior behavior)
{
if (squadron == null) return 1;

var info = squadron.Plane.Info;
if (info.Type == SlotItemType.艦上偵察機)
if (behavior == AirRegimentBehavior.Defense)
{
return info.ViewRange <= 7 ? 1.2 : 1.3;
}
else if(info.Type == SlotItemType.大型飛行艇 || info.Type == SlotItemType.水上偵察機)
{
return info.ViewRange <= 7 ? 1.1
: info.ViewRange == 8 ? 1.13
: 1.16;
if (info.Type == SlotItemType.艦上偵察機)
{
return info.ViewRange <= 7 ? 1.2 : 1.3;
}
else if (info.Type == SlotItemType.大型飛行艇 || info.Type == SlotItemType.水上偵察機)
{
return info.ViewRange <= 7 ? 1.1
: info.ViewRange == 8 ? 1.13
: 1.16;
}
else
{
return info.ViewRange == 8 ? 1.18 : 1.23;
}
}
else
{
return 1.18;
if (info.Type == SlotItemType.陸上偵察機)
{
return info.ViewRange == 8 ? 1.15 : 1.18;
}
return 1;
}

}
}
}
47 changes: 15 additions & 32 deletions LandBasedAirCorpsPlugin/Models/Squadron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,22 @@ public SlotItem Plane
}
#endregion

public double AirSuperiorityAtSortie
public double GetAirSuperiority(AirRegimentBehavior behavior)
{
get
{
if (this.State != SquadronState.Deployed) return 0;

var info = this.Plane.Info;
var intercept = this.IsInterceptor ? info.Evade : 0;
var improvementBonus = this.GetImprovementBonus(this.Plane);
var ex = info.Id == 138 && info.Name == "二式大艇" ?
this.WorkingCount >= 4 && this.Plane.Level >= 4 ? 1 :
info.Id == 312 && info.Name == "二式陸上偵察機(熟練)" ?
this.WorkingCount >= 4 && this.Plane.Level >= 2 ? 1 : 0
: 0 : 0;

return Math.Floor((info.AA + (1.5 * intercept) + improvementBonus) * Math.Sqrt(this.WorkingCount) + this.Plane.GetBonus() + ex);
}
}

public double AirSuperiorityAtDefense
{
get
{
if (this.State != SquadronState.Deployed) return 0;

var info = this.Plane.Info;
var intercept = this.IsInterceptor ? info.Evade : 0;
var antiBomber = this.IsInterceptor ? info.Hit : 0;
var improvementBonus = this.GetImprovementBonus(this.Plane);

return Math.Floor((info.AA + intercept + (2 * antiBomber) + improvementBonus) * Math.Sqrt(this.WorkingCount) + this.Plane.GetBonus());
}
}
if (this.State != SquadronState.Deployed) return 0;

var info = this.Plane.Info;
var intercept = this.IsInterceptor ? info.Evade : 0;
var antiBomber = this.IsInterceptor ? info.Hit : 0;
var improvementBonus = this.GetImprovementBonus(this.Plane);
var ex = (info.Id == 138 && info.Name == "二式大艇") ?
(this.WorkingCount >= 4 && this.Plane.Level >= 4) ? 1 :
(info.Id == 312 && info.Name == "二式陸上偵察機(熟練)") ?
(this.WorkingCount >= 4 && this.Plane.Level >= 2) ? 1 : 0 : 0 : 0;

var correctAA = (behavior == AirRegimentBehavior.Defense) ? (info.AA + intercept + (2 * antiBomber)) : (info.AA + (1.5 * intercept));
return Math.Floor((correctAA + improvementBonus) * Math.Sqrt(this.WorkingCount) + this.Plane.GetBonus() + ex);
}

public bool IsInterceptor => this.Plane?.Info.Type == SlotItemType.局地戦闘機;

Expand Down

0 comments on commit 515b6bb

Please sign in to comment.