forked from mipen/BannerlordTweaks
-
Notifications
You must be signed in to change notification settings - Fork 3
/
DailyTroopExperienceTweak.cs
55 lines (51 loc) · 2.44 KB
/
DailyTroopExperienceTweak.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
using System.Linq;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
namespace BannerlordTweaks
{
public class DailyTroopExperienceTweak
{
public static void Apply(Campaign campaign)
{
var obj = new DailyTroopExperienceTweak();
CampaignEvents.DailyTickPartyEvent.AddNonSerializedListener(obj, (MobileParty mp) => { obj.DailyTick(mp); });
}
private void DailyTick(MobileParty party)
{
if (party.LeaderHero != null)
{
int count = party.MemberRoster.Troops.Count();
if (party.LeaderHero == Hero.MainHero || BannerlordTweaksSettings.Instance is { } settings && settings.DailyTroopExperienceApplyToAllNPC ||
BannerlordTweaksSettings.Instance.DailyTroopExperienceApplyToPlayerClanMembers && party.LeaderHero.Clan == Clan.PlayerClan)
{
int experienceAmount = ExperienceAmount(party.LeaderHero);
if (experienceAmount > 0)
{
foreach (var troop in party.MemberRoster.Troops)
{
party.MemberRoster.AddXpToTroop(experienceAmount, troop);
}
if (BannerlordTweaksSettings.Instance is { } settings2 && settings2.DisplayMessageDailyExperienceGain)
{
string troops = count == 1 ? "soldier" : "troops";
//Debug
//DebugHelpers.DebugMessage($"{party.LeaderHero.Name}'s party granted {experienceAmount} experience to {count} {troops}."));
if (party.LeaderHero == Hero.MainHero)
InformationManager.DisplayMessage(new InformationMessage($"Granted {experienceAmount} experience to {count} {troops}."));
}
}
}
}
}
private static int ExperienceAmount(Hero h)
{
int leadership = h.GetSkillValue(DefaultSkills.Leadership);
if (BannerlordTweaksSettings.Instance != null)
{
if (leadership >= BannerlordTweaksSettings.Instance.DailyTroopExperienceRequiredLeadershipLevel)
return (int)(BannerlordTweaksSettings.Instance.LeadershipPercentageForDailyExperienceGain * leadership);
}
return 0;
}
}
}