113 lines
4.4 KiB
C#
113 lines
4.4 KiB
C#
|
|
using System;
|
||
|
|
using HarmonyLib;
|
||
|
|
using RimWorld;
|
||
|
|
using UnityEngine;
|
||
|
|
using Verse;
|
||
|
|
|
||
|
|
namespace BlaxSlaves
|
||
|
|
{
|
||
|
|
public class BlaxSlavesSettings : ModSettings
|
||
|
|
{
|
||
|
|
public bool returnRunaways = true;
|
||
|
|
public float returnChance = 0.8f;
|
||
|
|
public int returnDelayMinDays = 3;
|
||
|
|
public int returnDelayMaxDays = 10;
|
||
|
|
public bool suppressSlaveHarmMood = true;
|
||
|
|
public bool keepRelationGrief = true;
|
||
|
|
public float traderBrandChance = 0.35f;
|
||
|
|
|
||
|
|
public override void ExposeData()
|
||
|
|
{
|
||
|
|
base.ExposeData();
|
||
|
|
Scribe_Values.Look(ref returnRunaways, "returnRunaways", true);
|
||
|
|
Scribe_Values.Look(ref returnChance, "returnChance", 0.8f);
|
||
|
|
Scribe_Values.Look(ref returnDelayMinDays, "returnDelayMinDays", 3);
|
||
|
|
Scribe_Values.Look(ref returnDelayMaxDays, "returnDelayMaxDays", 10);
|
||
|
|
Scribe_Values.Look(ref suppressSlaveHarmMood, "suppressSlaveHarmMood", true);
|
||
|
|
Scribe_Values.Look(ref keepRelationGrief, "keepRelationGrief", true);
|
||
|
|
Scribe_Values.Look(ref traderBrandChance, "traderBrandChance", 0.35f);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class BlaxSlavesMod : Mod
|
||
|
|
{
|
||
|
|
public static BlaxSlavesSettings Settings;
|
||
|
|
|
||
|
|
public BlaxSlavesMod(ModContentPack content) : base(content)
|
||
|
|
{
|
||
|
|
Settings = GetSettings<BlaxSlavesSettings>();
|
||
|
|
}
|
||
|
|
|
||
|
|
public override string SettingsCategory() => "Blax Slaves";
|
||
|
|
|
||
|
|
public override void DoSettingsWindowContents(Rect inRect)
|
||
|
|
{
|
||
|
|
var l = new Listing_Standard();
|
||
|
|
l.Begin(inRect);
|
||
|
|
|
||
|
|
l.CheckboxLabeled("BlaxSlaves_SettingReturn".Translate(), ref Settings.returnRunaways, "BlaxSlaves_SettingReturnTip".Translate());
|
||
|
|
l.Label("BlaxSlaves_SettingReturnChance".Translate(Settings.returnChance.ToStringPercent()));
|
||
|
|
Settings.returnChance = l.Slider(Settings.returnChance, 0f, 1f);
|
||
|
|
l.Label("BlaxSlaves_SettingReturnDelayMin".Translate(Settings.returnDelayMinDays));
|
||
|
|
Settings.returnDelayMinDays = Mathf.RoundToInt(l.Slider(Settings.returnDelayMinDays, 1f, 30f));
|
||
|
|
l.Label("BlaxSlaves_SettingReturnDelayMax".Translate(Settings.returnDelayMaxDays));
|
||
|
|
Settings.returnDelayMaxDays = Mathf.RoundToInt(l.Slider(Settings.returnDelayMaxDays, 1f, 60f));
|
||
|
|
if (Settings.returnDelayMaxDays < Settings.returnDelayMinDays)
|
||
|
|
Settings.returnDelayMaxDays = Settings.returnDelayMinDays;
|
||
|
|
|
||
|
|
l.GapLine();
|
||
|
|
l.CheckboxLabeled("BlaxSlaves_SettingMood".Translate(), ref Settings.suppressSlaveHarmMood, "BlaxSlaves_SettingMoodTip".Translate());
|
||
|
|
l.CheckboxLabeled("BlaxSlaves_SettingGrief".Translate(), ref Settings.keepRelationGrief, "BlaxSlaves_SettingGriefTip".Translate());
|
||
|
|
|
||
|
|
l.GapLine();
|
||
|
|
l.Label("BlaxSlaves_SettingTraderBrand".Translate(Settings.traderBrandChance.ToStringPercent()));
|
||
|
|
Settings.traderBrandChance = l.Slider(Settings.traderBrandChance, 0f, 1f);
|
||
|
|
|
||
|
|
l.End();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Applies the Harmony patches after every Mod class exists (so the Harmony mod has set up
|
||
|
|
/// its 1.7 backend), one class at a time so a single broken target can't take the rest down.
|
||
|
|
/// </summary>
|
||
|
|
[StaticConstructorOnStartup]
|
||
|
|
public static class BlaxSlavesStartup
|
||
|
|
{
|
||
|
|
public static readonly Harmony Harmony = new Harmony("blax.slaves");
|
||
|
|
|
||
|
|
static BlaxSlavesStartup()
|
||
|
|
{
|
||
|
|
int ok = 0, failed = 0;
|
||
|
|
foreach (Type type in typeof(BlaxSlavesStartup).Assembly.GetTypes())
|
||
|
|
{
|
||
|
|
if (!type.IsDefined(typeof(HarmonyPatch), false))
|
||
|
|
continue;
|
||
|
|
try
|
||
|
|
{
|
||
|
|
Harmony.CreateClassProcessor(type).Patch();
|
||
|
|
ok++;
|
||
|
|
}
|
||
|
|
catch (Exception e)
|
||
|
|
{
|
||
|
|
failed++;
|
||
|
|
Log.Error("[Blax Slaves] Patch " + type.Name + " failed: " + e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ok += Compat.Apply(Harmony);
|
||
|
|
Log.Message("[Blax Slaves] " + ok + " patches applied" + (failed > 0 ? ", " + failed + " failed" : ""));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
[DefOf]
|
||
|
|
public static class BlaxDefOf
|
||
|
|
{
|
||
|
|
public static HediffDef BlaxSlaves_SlaveBrand;
|
||
|
|
|
||
|
|
static BlaxDefOf()
|
||
|
|
{
|
||
|
|
DefOfHelper.EnsureInitializedInCtor(typeof(BlaxDefOf));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|