This repository has been archived by the owner on Apr 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeroEvaluator.cs
63 lines (59 loc) · 3.06 KB
/
HeroEvaluator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using JetBrains.Annotations;
using TaleWorlds.CampaignSystem;
namespace PreventEscape
{
public static class HeroEvaluator
{
public static int Evaluate(Hero prisoner, Hero captor, Hero ransomer, IFaction evaluatorFaction)
{
if (prisoner == null || ransomer == null || evaluatorFaction == null || Campaign.Current == null)
return 0;
var estimatedValue = (prisoner.Clan?.TotalStrength * Settings.Instance.StrengthFactor ?? 0)
+ (prisoner.Clan?.Renown * Settings.Instance.RenownFactor ?? 0)
+ (Campaign.Current?.Models?.PartyWageModel?.GetTroopRecruitmentCost(prisoner.CharacterObject, null) * Settings.Instance.RecruitmentCostFactor ?? 0);
estimatedValue *= (1.0f + (ransomer.GetRelation(prisoner)/100.0f) * Settings.Instance.RelationsFactor);
if (prisoner.IsFactionLeader)
if (prisoner.MapFaction?.IsKingdomFaction ?? false)
estimatedValue *= Settings.Instance.KingdomLeaderFactor;
else
estimatedValue *= Settings.Instance.FactionLeaderFactor;
else
estimatedValue *= Settings.Instance.OtherFactor;
var clanGoldChange = Math.Max(0, Campaign.Current.Models?.ClanFinanceModel?.CalculateClanGoldChange(prisoner.Clan, null, true) ?? 0);
var clanGold = 0;
if (prisoner.Clan?.Heroes != null)
{
if (prisoner.Clan.Leader == prisoner)
foreach (var hero in prisoner.Clan.Heroes)
clanGold += hero.Gold;
else
clanGold = prisoner.Clan.Leader?.Gold ?? 0;
}
// Limit ransom price, so it's not greater than clan could pay.
var maxRansom = Math.Max(clanGold, clanGoldChange * Settings.Instance.PriceAgreementDelay * 0.8f);
if (estimatedValue > maxRansom)
estimatedValue = maxRansom;
if ((prisoner.PartyBelongedToAsPrisoner?.MapFaction?.IsBanditFaction ?? true) || evaluatorFaction.IsBanditFaction)
{
if (!evaluatorFaction.IsBanditFaction)
return (int) (estimatedValue * Settings.Instance.BanditsFactor * HalfLifeFactor(prisoner, true));
return (int) (-estimatedValue * Settings.Instance.BanditsFactor * HalfLifeFactor(prisoner, false));
}
estimatedValue = (int)estimatedValue;
// If prisoner is enemy of evaluator's kingdom
if (FactionManager.IsAtWarAgainstFaction(prisoner.MapFaction, evaluatorFaction) ||
FactionManager.IsAtWarAgainstFaction(prisoner.Clan?.MapFaction, captor?.Clan?.MapFaction))
estimatedValue *= Settings.Instance.AtWarFactor;
if(evaluatorFaction == captor?.Clan || evaluatorFaction == captor?.MapFaction || evaluatorFaction == prisoner.PartyBelongedToAsPrisoner?.MapFaction)
return -(int)(estimatedValue * HalfLifeFactor(prisoner, false));
return evaluatorFaction == prisoner.Clan || evaluatorFaction == prisoner.MapFaction || evaluatorFaction.MapFaction == prisoner.MapFaction
? (int)(estimatedValue * HalfLifeFactor(prisoner, true))
: 0;
}
private static double HalfLifeFactor([NotNull]Hero prisoner, bool ransomer)
{
return Math.Pow(ransomer ? 2 : 0.5, (prisoner.CaptivityStartTime.ElapsedDaysUntilNow - Settings.Instance.PriceAgreementDelay) / Settings.Instance.PriceHalfLife);
}
}
}