-
Notifications
You must be signed in to change notification settings - Fork 43
/
DailyTroopExperienceTweak.cs
52 lines (48 loc) · 2.24 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
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 || Settings.Instance.DailyTroopExperienceApplyToAllNPC ||
Settings.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 (Settings.Instance.DisplayMessageDailyExperienceGain)
{
string troops = count == 1 ? "soldier" : "troops";
//Debug
//InformationManager.DisplayMessage(new InformationMessage($"{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 (leadership >= Settings.Instance.DailyTroopExperienceRequiredLeadershipLevel)
return (int)(Settings.Instance.LeadershipPercentageForDailyExperienceGain * leadership);
return 0;
}
}
}