Skip to content

Commit

Permalink
Adds Worm Bounty Scaling
Browse files Browse the repository at this point in the history
- Scales the amount of the bounty reward for killing a Great Worm based on the current team technology tier
- The bounty is multiplied by a scaling factor between 1 and 3. 1 representing tech tier 0 and 3 representing the maximum tech tier.
- The default preferences will allow a bounty of 2000 in the early game up to a bounty of 6000 in the late game
  • Loading branch information
data-bomb committed Nov 23, 2024
1 parent fcc2083 commit 8d4ebac
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions Si_WormBounty/Si_WormBounty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You should have received a copy of the GNU General Public License
using Si_WormBounty;


[assembly: MelonInfo(typeof(WormBounty), "Worm Bounty", "1.0.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(WormBounty), "Worm Bounty", "1.1.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand All @@ -50,14 +50,16 @@ public class WormBounty : MelonMod
static MelonPreferences_Entry<float> _Pref_GreatWorms_SpawnChance = null!;
static MelonPreferences_Entry<int> _Pref_GreatWorms_Bounty_BaseAmount = null!;
static MelonPreferences_Entry<int> _Pref_GreatWorms_Bounty_RandomBonusMax = null!;
static MelonPreferences_Entry<bool> _Pref_GreatWorms_Bounty_TechScaling = null!;


public override void OnInitializeMelon()
{
_modCategory ??= MelonPreferences.CreateCategory("Silica");
_Pref_GreatWorms_MaxNumber ??= _modCategory.CreateEntry<int>("GreatWorms_MaxNumber", 2);
_Pref_GreatWorms_Bounty_BaseAmount ??= _modCategory.CreateEntry<int>("GreatWorms_Bounty_BaseAmount", 500);
_Pref_GreatWorms_Bounty_BaseAmount ??= _modCategory.CreateEntry<int>("GreatWorms_Bounty_BaseAmount", 1250);
_Pref_GreatWorms_Bounty_RandomBonusMax ??= _modCategory.CreateEntry<int>("GreatWorms_Bounty_Bonus_RandomMax", 750);
_Pref_GreatWorms_Bounty_TechScaling ??= _modCategory.CreateEntry<bool>("GreatWorms_Bounty_TechScaling", true);
_Pref_GreatWorms_SpawnChance ??= _modCategory.CreateEntry<float>("GreatWorms_SpawnChance", 0.25f);
}

Expand Down Expand Up @@ -195,7 +197,7 @@ public static void Prefix(AmbientLife __instance, Unit __0, GameObject __1)
}

// determine bounty amount
int bountyAmount = FindBounty();
int bountyAmount = FindBounty(attackerPlayer.Team);

// award bounty
AwardBounty(attackerPlayer, bountyAmount);
Expand All @@ -207,23 +209,38 @@ public static void Prefix(AmbientLife __instance, Unit __0, GameObject __1)
}
}

private static int FindBounty()
private static int FindBounty(Team team)
{
// explosion kills earn a bit less
int baseAmount = _Pref_GreatWorms_Bounty_BaseAmount.Value;
int baseBounty = _Pref_GreatWorms_Bounty_BaseAmount.Value;

// give a little more, perhaps
int varyingAmount = 0;
int varyingBounty = 0;
if (_Pref_GreatWorms_Bounty_RandomBonusMax.Value > 0)
{
System.Random randomIndex = new System.Random();
varyingAmount = randomIndex.Next(0, _Pref_GreatWorms_Bounty_RandomBonusMax.Value);
varyingBounty = randomIndex.Next(0, _Pref_GreatWorms_Bounty_RandomBonusMax.Value);
}

int bountyTotal = baseBounty + varyingBounty;

// round down to nearest ten
varyingAmount = (int)Math.Round(varyingAmount / 10.0) * 10;
// scale up for later tech tiers, perhaps
if (_Pref_GreatWorms_Bounty_TechScaling.Value)
{
bountyTotal = (int)Math.Round(bountyTotal * FindTechScalingFactor(team));
}

return baseAmount + varyingAmount;
// round down to nearest ten
bountyTotal = (int)Math.Round(bountyTotal / 10.0) * 10;

return bountyTotal;
}

// map the technology tier to a multiplier between 1 and 3
private static float FindTechScalingFactor(Team team)
{
float techTierPercentage = (float)team.CurrentTechnologyTier / (float)team.MaximumTechnologyTier;
return 1f + techTierPercentage * (2f);
}

private static void AwardBounty(Player player, int bounty)
Expand Down

0 comments on commit 8d4ebac

Please sign in to comment.