Skip to content

Commit

Permalink
Merge pull request #40 from Aviuz/2.7.5
Browse files Browse the repository at this point in the history
2.7.5
  • Loading branch information
Hazzer authored Jul 15, 2022
2 parents bbaaa8c + 92a30d9 commit 2b46f36
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 8 deletions.
Binary file modified 1.3/Assemblies/Locks.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li>
</modDependencies>
<description>Version 2.7.4\nThis addon adds Lock command on every door.\n - Left-click to lock toggle.\n - Right click for more options\n - Alternatively you can use "Lock" inspector tab\n\nNote: Door lock must be flicked by colonist.</description>
<description>Version 2.7.5\nThis addon adds Lock command on every door.\n - Left-click to lock toggle.\n - Right click for more options\n - Alternatively you can use "Lock" inspector tab\n\nNote: Door lock must be flicked by colonist.</description>
</ModMetaData>
12 changes: 11 additions & 1 deletion Languages/English/Keyed/Keys.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
<Locks_ModName>Locks</Locks_ModName>
<Locks_ChildrenLock>Child lock minimal age: {0}</Locks_ChildrenLock>
<Lock_ChildrenLock_Description>Minimal age needed for humanlike pawn to open doors</Lock_ChildrenLock_Description>

<Locks_Label>Lock</Locks_Label>
<Locks_Description>When unlocked all pawn will be allowed to use this door.\n[Right click for more options]</Locks_Description>

<Locks_PrisonBreak>Escaping prisoners respecting locks</Locks_PrisonBreak>
<Locks_SlaveRebel>Rebeling slaves respecting locks</Locks_SlaveRebel>

<Locks_StatePrefix>Door</Locks_StatePrefix>
<Locks_StateLocked>locked</Locks_StateLocked>
<Locks_StateUnlocked>unlocked</Locks_StateUnlocked>
Expand All @@ -20,7 +27,10 @@
<Locks_ITabSlaveDoorsDesc>When disabled slaves are not allowed to pass through this door. This setting do not apply when owners are set.</Locks_ITabSlaveDoorsDesc>
<Locks_ITabAnimalAllowed>Animals allowed</Locks_ITabAnimalAllowed>
<Locks_ITabAnimalAllowedDesc>When disabled all animals will not be allowed to pass through this door. This setting is checked after pens and pet door settings.</Locks_ITabAnimalAllowedDesc>

<Locks_ITabChildrenLock>Children lock</Locks_ITabChildrenLock>
<Locks_ITabChildrenLockDesc>When enabled only humanlike pawn over age (check options) are allowed to pass through this door. Works only on pawn from that same faction as door.</Locks_ITabChildrenLockDesc>


<Locks_ITabOwners>Owners</Locks_ITabOwners>
<Locks_ITabChangeLocksNotification>Change lock in order to apply settings!</Locks_ITabChangeLocksNotification>

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>
<p align="center">
<a href="https://github.com/Aviuz/Locks/releases">
<img src="https://img.shields.io/badge/version-2.7.4-blue.svg?style=flat" alt="v2.7.4" />
<img src="https://img.shields.io/badge/version-2.7.5-blue.svg?style=flat" alt="v2.7.5" />
</a>
</p>

Expand Down
10 changes: 10 additions & 0 deletions Source/CompLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public CompProperties_Lock()

public class CompLock : ThingComp
{
private static readonly string FENCE = "FenceGate";
public override string CompInspectStringExtra()
{
string text = "Locks_StatePrefix".Translate() + " ";
Expand Down Expand Up @@ -45,5 +46,14 @@ public override IEnumerable<Gizmo> CompGetGizmosExtra()
{
yield return new LockGizmo(this.parent);
}

public override void PostSpawnSetup(bool respawningAfterLoad)
{
if (this.parent.def.defName == FENCE)
{
LockUtility.GetData(this.parent).CurrentState.pensDoor = true;
LockUtility.GetData(this.parent).WantedState.pensDoor = true;
}
}
}
}
29 changes: 29 additions & 0 deletions Source/HarmonyPatches/RespectLockPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using HarmonyLib;
using Locks.Options;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Locks.HarmonyPatches
{
[HarmonyPatch(typeof(LordJob_PrisonBreak), "CanOpenAnyDoor")]
public class PrisonerEscapePatch
{
static bool Postfix(bool __result)
{
return !LocksSettings.prisonerBreakRespectsLock;
}
}

[HarmonyPatch(typeof(LordJob_SlaveRebellion), "CanOpenAnyDoor")]
public class SlaveRebelionPatch
{
static bool Postfix(bool __result)
{
return !LocksSettings.revoltRespectsLocks;
}
}
}
11 changes: 10 additions & 1 deletion Source/ITab_Lock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ITab_Lock : ITab
private static readonly Vector2 WinSize = new Vector2(310f + WindowGap, ButtonsHeight + OwnersWindowHeight + OwnersTitleHeight + MainSettingsHeight + WindowGap + 2 * Spacing + WarningHeight);
private const float ButtonsHeight = 25f;
private const float WindowGap = 15f;
private const float MainSettingsHeight = 6 * 32f;
private const float MainSettingsHeight = 7 * 32f;
private const float OwnersTitleHeight = 24f;
private const float OwnersWindowHeight = 200f;
private const float WarningHeight = 24f;
Expand All @@ -29,6 +29,7 @@ public class ITab_Lock : ITab
private bool petDoor;
private bool pensDoor;
private bool slaveDoor;
private bool childLock;
private bool animalsAllowed;

private Thing lastSelectedThing;
Expand Down Expand Up @@ -83,6 +84,11 @@ protected override void FillTab()
}
if (Data.WantedState.IsVisible(nameof(LockState.mode)))
listing.CheckboxLabeled("Locks_ITabVisitorsAllowed".Translate(), ref vistitorsAllowed, "Locks_ITabVisitorsAllowedDesc".Translate());
if (Data.WantedState.IsVisible(nameof(LockState.childLock)))
{
listing.CheckboxLabeled("Locks_ITabChildrenLock".Translate(), ref childLock, "Locks_ITabChildrenLockDesc".Translate());
}

if (Data.WantedState.IsVisible(nameof(LockState.petDoor)))
listing.CheckboxLabeled("Locks_ITabPetDoor".Translate(), ref petDoor, "Locks_ITabPetDoorDesc".Translate());
if (Data.WantedState.IsVisible(nameof(LockState.pensDoor)))
Expand All @@ -91,6 +97,7 @@ protected override void FillTab()
{
listing.CheckboxLabeled("Locks_ITabAnimalAllowed".Translate(), ref animalsAllowed, "Locks_ITabAnimalAllowedDesc".Translate());
}

listing.End();

if (Data.WantedState.IsVisible(nameof(LockState.owners)))
Expand Down Expand Up @@ -157,6 +164,7 @@ private void UpdateSettings()
Data.WantedState.pensDoor = pensDoor;
Data.WantedState.allowSlave = slaveDoor;
Data.WantedState.allowAnimals = animalsAllowed;
Data.WantedState.childLock = childLock;
if (Data.NeedChange)
LockUtility.UpdateLockDesignation(SelDoor);
}
Expand All @@ -175,6 +183,7 @@ public override void OnOpen()
pensDoor = Data.WantedState.pensDoor;
slaveDoor = Data.WantedState.allowSlave;
animalsAllowed = Data.WantedState.allowAnimals;
childLock = Data.WantedState.childLock;
}

private void OwnerCheckbox(Rect rect, Pawn pawn)
Expand Down
4 changes: 2 additions & 2 deletions Source/LockData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class LockData : IExposable

public LockData()
{
CurrentState = new LockState(LockMode.Allies, true, false, true, new List<Pawn>());
WantedState = new LockState(LockMode.Allies, true, false, true, new List<Pawn>());
CurrentState = new LockState(LockMode.Allies, true, false, false, new List<Pawn>());
WantedState = new LockState(LockMode.Allies, true, false, false, new List<Pawn>());
}

// Utilities
Expand Down
11 changes: 10 additions & 1 deletion Source/LockState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct LockState
public bool petDoor;
public bool pensDoor;
public bool allowAnimals;
public bool childLock;
public List<Pawn> owners;

public LockState(LockMode mode, bool locked, bool petDoor, bool pensDoor, List<Pawn> owners,
Expand All @@ -30,7 +31,7 @@ public LockState(LockMode mode, bool locked, bool petDoor, bool pensDoor, List<P
this.petDoor = petDoor;
this.pensDoor = pensDoor;
this.owners = owners;

childLock = false;
this.allowSlave = allowSlave;
this.allowAnimals = allowAnimals;
}
Expand All @@ -46,6 +47,8 @@ public void CopyFrom(LockState copy)

allowSlave = copy.allowSlave;
allowAnimals = copy.allowAnimals;

childLock = copy.childLock;
}

public static bool operator ==(LockState a, LockState b)
Expand Down Expand Up @@ -74,6 +77,10 @@ public void CopyFrom(LockState copy)
{
return false;
}
if (a.childLock != b.childLock)
{
return false;
}
foreach (var p in a.owners)
{
if (!b.owners.Contains(p))
Expand Down Expand Up @@ -114,6 +121,8 @@ public void ExposeData(String postfix)
Scribe_Values.Look(ref allowSlave, $"Locks_LockData_SlaveDoor_{postfix}", true, false);
Scribe_Values.Look(ref allowAnimals, $"Locks_LockData_NonAnimalDoor_{postfix}", true, false);

Scribe_Values.Look(ref childLock, $"Locks_LockData_ChildLock_{postfix}", false, false);

Scribe_Collections.Look(ref owners, $"Locks_LockData_Owners_{postfix}", LookMode.Reference);
}
}
Expand Down
17 changes: 16 additions & 1 deletion Source/LockUtility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Locks.CompatibilityPatches;
using Locks.Options;
using RimWorld;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -51,7 +52,7 @@ public static bool PawnCanOpen(ThingWithComps door, Pawn p)

bool canOpenAnyDoor = lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(p);
bool noFaction = door.Faction == null;
bool specialGuest = WildManUtility.WildManShouldReachOutsideNow(p) || (p.guest != null && p.guest.Released);
bool specialGuest = p.guest != null && p.guest.Released;
if (canOpenAnyDoor || noFaction || specialGuest)
return true;

Expand All @@ -71,6 +72,11 @@ public static bool PawnCanOpen(ThingWithComps door, Pawn p)
{
return false;
}
if (respectedState.mode == LockMode.Allies && WildManUtility.WildManShouldReachOutsideNow(p))
{
return true;
}

if (p.Faction == null || p.Faction.HostileTo(door.Faction))
{
return false;
Expand All @@ -87,6 +93,11 @@ public static bool PawnCanOpen(ThingWithComps door, Pawn p)
{
return false;
}
if (respectedState.childLock && p.RaceProps != null && p.RaceProps.Humanlike && p.Faction == door.Faction && p.ageTracker != null
&& p.ageTracker.AgeBiologicalYears < LocksSettings.childLockAge)
{
return false;
}

if (p.Faction == door.Faction && !p.IsPrisoner && !p.IsSlave)
{
Expand All @@ -96,6 +107,7 @@ public static bool PawnCanOpen(ThingWithComps door, Pawn p)
{
return true;
}

bool guestCondition = p.GuestStatus == GuestStatus.Guest || !p.IsPrisoner && !p.IsSlave && p.HostFaction != door.Faction;
if (respectedState.mode == LockMode.Allies && guestCondition)
{
Expand All @@ -106,6 +118,7 @@ public static bool PawnCanOpen(ThingWithComps door, Pawn p)
{
return true;
}

return false;
}

Expand Down Expand Up @@ -160,6 +173,8 @@ public static bool IsVisible(this LockState state, string propertyName)
return state.locked;
case nameof(LockState.allowSlave):
return state.locked;
case nameof(LockState.childLock):
return state.locked;
default:
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions Source/Locks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@
<Compile Include="CompLock.cs" />
<Compile Include="HarmonyPatches\HPatcher.cs" />
<Compile Include="HarmonyPatches\Patch_InjectLockCheck.cs" />
<Compile Include="HarmonyPatches\RespectLockPatches.cs" />
<Compile Include="Initialization.cs" />
<Compile Include="ITab_Lock.cs" />
<Compile Include="JobDriver_ToggleLock.cs" />
<Compile Include="LockData.cs" />
<Compile Include="LockGizmo.cs" />
<Compile Include="LockState.cs" />
<Compile Include="LockUtility.cs" />
<Compile Include="Options\LocksMod.cs" />
<Compile Include="Options\LocksSettings.cs" />
<Compile Include="WorkGiver_ToggleLock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions Source/Options/LocksMod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

namespace Locks.Options
{
class LocksMod : Mod
{
private const string MOD_NAME = "Locks_ModName";
private const string CHILD_LOCK = "Locks_ChildrenLock";
private const string CHILD_LOCK_DESC = "Lock_ChildrenLock_Description";
private const string PRISON_BREAK= "Locks_PrisonBreak";
private const string SLAVE_REBELION ="Locks_SlaveRebel";

public LocksMod(ModContentPack content) : base(content)
{
this.GetSettings<LocksSettings>();
}

public override void DoSettingsWindowContents(Rect inRect)
{
Listing_Standard listingStandard = new Listing_Standard();

listingStandard.Begin(inRect);
listingStandard.Gap(12f);

listingStandard.Label(CHILD_LOCK.Translate(LocksSettings.childLockAge), tooltip: CHILD_LOCK_DESC.Translate());
LocksSettings.childLockAge = (int)listingStandard.Slider(LocksSettings.childLockAge, 0, 18);
listingStandard.Gap(12f);

listingStandard.CheckboxLabeled(PRISON_BREAK.Translate(), ref LocksSettings.prisonerBreakRespectsLock);
listingStandard.Gap(12f);

listingStandard.CheckboxLabeled(SLAVE_REBELION.Translate(), ref LocksSettings.revoltRespectsLocks);
listingStandard.Gap(12f);

listingStandard.End();
}

public override string SettingsCategory()
{
return MOD_NAME.Translate();
}
}
}
24 changes: 24 additions & 0 deletions Source/Options/LocksSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace Locks.Options
{
public class LocksSettings : ModSettings
{
public static int childLockAge = 6;
public static bool prisonerBreakRespectsLock = true;
public static bool revoltRespectsLocks = true;

public override void ExposeData()
{
Scribe_Values.Look<int>(ref childLockAge, "Locks_childLockAge", 6, true);

Scribe_Values.Look<bool>(ref prisonerBreakRespectsLock, "Locks_BreakRespectsLocks", true, true);
Scribe_Values.Look<bool>(ref revoltRespectsLocks, "Locks_RevoltRespectLocks", true, true);
}
}
}
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Changelog:
2.7.5
- Pens door option will be turned on only for fence gate
- Added child lock option - age can by configured in mod options
- Revolting slaves and prisoners should respect locks - can be configured in options
- Wild man should be only able to use locked doors with "allow visitiors" option on
2.7.4
- Fixes for "Slaves allowed" option
2.7.3
Expand Down

0 comments on commit 2b46f36

Please sign in to comment.