Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
Add an override config for Random Bonuses!
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Aug 22, 2014
1 parent 0be830d commit e9d609b
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 5 deletions.
Expand Up @@ -56,6 +56,8 @@ public class RandomBonuses {
public static Map<Modifier, Integer> weaponWeights = new HashMap<Modifier, Integer>();
public static Map<Modifier, Integer> bowWeights = new HashMap<Modifier, Integer>();

public static Integer usageBonusWeight = 70;

private static Map<String, ItemModifier> modCache = new HashMap<String, ItemModifier>();

static {
Expand Down Expand Up @@ -116,7 +118,7 @@ else if(tool.getItem() instanceof BowBase) {
// basically if we didn't do this, the higher the xp required, the higher the chance.
bonus /= (float)LevelingLogic.getRequiredXp(tool, tags);
// maximal bonus obtainable should be ~70
bonus *= 70;
bonus *= usageBonusWeight;
chances[i] += bonus;
}

Expand Down Expand Up @@ -197,7 +199,7 @@ else if(tool.getItem() instanceof BowBase) {
// same as above
float bonus = tags.getInteger(String.format("Extra%s", choice.toString()));
bonus /= (float)LevelingLogic.getRequiredXp(tool, tags);
bonus *= 70;
bonus *= usageBonusWeight;

// now relativize the weight bonus to the total.
Log.info(String.format("Bonus weight for getting %s was %f", choice.toString(), bonus));
Expand Down Expand Up @@ -628,5 +630,14 @@ public String toString() {
default: return super.toString();
}
}

public static Modifier getEnumByString(String string) throws IllegalArgumentException
{
for(Modifier mod : Modifier.values())
if(mod.toString().equals(string))
return mod;

throw new IllegalArgumentException();
}
}
}
Expand Up @@ -15,10 +15,10 @@
import java.io.File;
import java.util.LinkedList;

public final class BlockOverride implements IOverride {
public class BlockOverride implements IOverride {
@Override
public void createDefault(Configuration config) {
Log.info("Loading Block Overrides");
Log.info("Creating Block Default File");

// oredict entries
for(int i = 0; i < HarvestLevelTweaks.allOreDicLevels.length; i++)
Expand Down Expand Up @@ -60,7 +60,7 @@ public void createDefault(Configuration config) {

@Override
public void processConfig(Configuration config) {
Log.info("Creating Block Default File");
Log.info("Loading Block Overrides");

StringBuilder comment = new StringBuilder();
comment.append("Mining Levels:\n");
Expand Down
Expand Up @@ -25,6 +25,7 @@ public void postInit(FMLPostInitializationEvent event)
doOverride("Material", new MaterialOverride());
doOverride("Tool", new ToolOverride());
doOverride("Block", new BlockOverride());
doOverride("BonusModifier", new ModifierOverride());
}

public static void doOverride(String type, IOverride overrider)
Expand Down
@@ -0,0 +1,90 @@
package iguanaman.iguanatweakstconstruct.override;

import iguanaman.iguanatweakstconstruct.leveling.RandomBonuses;
import iguanaman.iguanatweakstconstruct.util.Log;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

import java.util.Map;
import java.util.Set;

public class ModifierOverride implements IOverride {

@Override
public void createDefault(Configuration config) {
Log.info("Creating Modifier Default File");

config.get("UsageBonus", "bonusWeight", RandomBonuses.usageBonusWeight, "The average amount of weight added if a tool does one action for a whole levelup.");


for(RandomBonuses.Modifier mod : RandomBonuses.Modifier.values()) {
// tool modifiers
config.get("ToolWeights", mod.toString(), RandomBonuses.toolWeights.get(mod));
// weapon modifiers
config.get("WeaponWeights", mod.toString(), RandomBonuses.weaponWeights.get(mod));
// bow modifiers
config.get("BowWeights", mod.toString(), RandomBonuses.bowWeights.get(mod));

// useful modifiers
config.get("UsefulToolBonuses", mod.toString(), RandomBonuses.usefulToolModifiers.contains(mod));
config.get("UsefulWeaponBonuses", mod.toString(), RandomBonuses.usefulWeaponModifiers.contains(mod));
config.get("UsefulBowBonuses", mod.toString(), RandomBonuses.usefulBowModifiers.contains(mod));
}
}

@Override
public void processConfig(Configuration config) {
Log.info("Loading Modifier Overrides");

StringBuilder comment = new StringBuilder();
comment.append("Tools, Weapons and Bows use separate data to determine which modifier should be rewarded.\n");
comment.append("The weights work like this: All weights are summed up to a total. then a random number in between is picked, and depending on where the number is, that modifier is picked.\n");
comment.append("So basically: Modifier A has a weight of 5, Modifier B has a weight of 20. Sum is 25.\n");
comment.append(" -> Modifier A is B times more likely than modifier A, since a number between 0 and 25 has 5/25 chance to be modifier A, but 20/25 chance to be modifier B.\n");
comment.append("Additionally a bonus is added to the different weights depending on the tool usage. How big that bonus is, is defined by the usageWeight.");

config.setCategoryComment(" Info", comment.toString());

config.setCategoryComment("UsageBonus", "Tools gain a bonus for specific modifiers on doing specific things.\nThe value below determines how much weight is added (on average) to a modifier if only that action is done for the whole level.\nAn example: Mining blocks increases the chance to obtain the redstone modifier. If you'd only mine stone blocks from 0xp to levelup, the weigth of the redstone modifier woudl be increased by that amount. (That's why it's relatively low by default)");

RandomBonuses.usageBonusWeight = config.get("UsageBonus", "bonusWeight", RandomBonuses.usageBonusWeight, "The average amount of weight added if a tool does one action for a whole levelup.").getInt();

// tool weights
doWeightUpdate(config, "ToolWeights", RandomBonuses.toolWeights);
doWeightUpdate(config, "WeaponWeights", RandomBonuses.weaponWeights);
doWeightUpdate(config, "BowWeights", RandomBonuses.bowWeights);

// useful bonuses
for(RandomBonuses.Modifier mod : RandomBonuses.Modifier.values()) {
doUsefulnessUpdate(config, "UsefulToolBonuses", mod, RandomBonuses.usefulToolModifiers);
doUsefulnessUpdate(config, "UsefulWeaponBonuses", mod, RandomBonuses.usefulWeaponModifiers);
doUsefulnessUpdate(config, "UsefulBowBonuses", mod, RandomBonuses.usefulToolModifiers);
}
}

private void doWeightUpdate(Configuration config, String categoryName, Map<RandomBonuses.Modifier, Integer> map)
{
ConfigCategory cat = config.getCategory(categoryName);
for(Property prop : cat.values())
{
try {
RandomBonuses.Modifier mod = RandomBonuses.Modifier.getEnumByString(prop.getName());
map.put(mod, prop.getInt());
} catch(IllegalArgumentException e)
{
Log.error(String.format("Found invalid entry when parsing %s: %s", categoryName, prop.getName()));
}
}
}

private void doUsefulnessUpdate(Configuration config, String category, RandomBonuses.Modifier mod, Set<RandomBonuses.Modifier> set)
{
boolean useful = config.get(category, mod.toString(), set.contains(mod)).getBoolean();
if(useful)
set.add(mod);
else
set.remove(mod);
}

}

0 comments on commit e9d609b

Please sign in to comment.