Skip to content

Commit

Permalink
Adds Worm Bounty Settings
Browse files Browse the repository at this point in the history
- Creates "GreatWorms_Bounty_BaseAmount" to specify the base amount of the great worm bounty (default: 500)
- Creates "GreatWorms_Bounty_Bonus_NonExplosion" to specify the bonus amount to add to the bounty if the great worm is killed by a non-explosive weapon (default: 500)
- Creates "GreatWorms_Bounty_Bonus_RandomMax" to specify the maximum bonus amount to add to the bounty. A number will be selected between 0 and the max and added to the bounty if the great worm is killed. To disable randomness, set to 0. (default: 750)
  • Loading branch information
data-bomb committed May 5, 2024
1 parent 153a1c1 commit 3093faf
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 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", "0.9.1", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(WormBounty), "Worm Bounty", "0.9.2", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand All @@ -48,11 +48,18 @@ public class WormBounty : MelonMod
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<int> _Pref_GreatWorms_MaxNumber = null!;
static MelonPreferences_Entry<float> _Pref_GreatWorms_SpawnChance = null!;
static MelonPreferences_Entry<int> _Pref_GreatWorms_Bounty_BaseAmount = null!;
static MelonPreferences_Entry<int> _Pref_GreatWorms_Bounty_NonExplosionBonus = null!;
static MelonPreferences_Entry<int> _Pref_GreatWorms_Bounty_RandomBonusMax = 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_NonExplosionBonus ??= _modCategory.CreateEntry<int>("GreatWorms_Bounty_Bonus_NonExplosion", 500);
_Pref_GreatWorms_Bounty_RandomBonusMax ??= _modCategory.CreateEntry<int>("GreatWorms_Bounty_Bonus_RandomMax", 750);
_Pref_GreatWorms_SpawnChance ??= _modCategory.CreateEntry<float>("GreatWorms_SpawnChance", 0.25f);
}

Expand Down Expand Up @@ -199,14 +206,18 @@ public static void Prefix(AmbientLife __instance, Unit __0, EDamageType __1, Gam
private static int FindBounty(EDamageType damageType)
{
// explosion kills earn a bit less
int baseAmount = (damageType == EDamageType.Explosion) ? 500 : 1000;
int baseAmount = (damageType == EDamageType.Explosion) ? _Pref_GreatWorms_Bounty_BaseAmount.Value : (_Pref_GreatWorms_Bounty_BaseAmount.Value + _Pref_GreatWorms_Bounty_NonExplosionBonus.Value);

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

// round down to nearest ten
varyingAmount = (int)Math.Round(varyingAmount / 10.0) * 10;
// round down to nearest ten
varyingAmount = (int)Math.Round(varyingAmount / 10.0) * 10;
}

return baseAmount + varyingAmount;
}
Expand Down

0 comments on commit 3093faf

Please sign in to comment.