static StaticClass() { if (BetterWeight.instance.Settings.devMode) { Log.Warning("StaticClass"); LogAllBuildings(); } BetterWeight.SetDefaultSettingsIfNeeded(); }
/// <summary> /// Runs before GetValueUnfinalized /// With nullcheck, if requested value of mass does not exist (So it is using default) then add a mass value and calculate it /// </summary> /// <param name="__result"></param> /// <param name="req"></param> /// <param name="applyPostProcess"></param> /// <returns></returns> static bool Prefix(float __result, StatRequest req, bool applyPostProcess) { // Quick check to make sure thing isn't null if (req.Thing == null) { return(true); } if (req.Thing.def == null) { return(true); } if (req.StatBases == null) { return(true); } if (BetterWeight.ShouldPatch(req.Thing.def)) { bool needsMass = true; for (var index = 0; index < req.StatBases.Count; index++) //iterate through all stats in request { var stat = req.StatBases[index]; //get current stat if (stat.stat.label == "mass") //check if it is the mass { var new_mass = BetterWeight.RoundMass(BetterWeight.CalculateMass(req.Thing.def)); if (stat.value != 0 && stat.value != 1) { //Log.Message("Changed mass for " + req.Def.defName + " to " + new_mass, true); req.StatBases[index].value = new_mass; //set mass of item here } needsMass = false; } } if (needsMass) { if (req.Thing.def.costList == null) { return(true); } if (req.Thing.def.costList.Count == 0) { return(true); } StatModifier statModifier = new StatModifier { stat = StatDefOf.Mass, value = BetterWeight.CalculateMass(req.Thing.def) }; req.StatBases.Add(statModifier); //Log.Message("Added mass for " + req.Thing.def.defName); } } // Returns true so function runs with modifed StatReq return(true); }
static StartupClass() //Constructor { Log.Message("ArchieVBetterWeight"); BetterWeight betterWeight = new BetterWeight(); }