Skip to content

Commit

Permalink
Merge pull request #30 from Aviuz/2.6.2
Browse files Browse the repository at this point in the history
2.6.2
  • Loading branch information
Hazzer authored Jul 26, 2021
2 parents 79dd1ce + 7b5ad10 commit 14755f2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 14 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 @@ -20,5 +20,5 @@
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li>
</modDependencies>
<description>Version 2.6.1\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.6.2\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>
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.6.1-blue.svg?style=flat" alt="v2.6.1" />
<img src="https://img.shields.io/badge/version-2.6.2-blue.svg?style=flat" alt="v2.6.2" />
</a>
</p>

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, false, new List<Pawn>());
WantedState = new LockState(LockMode.Allies, true, false, false, new List<Pawn>());
CurrentState = new LockState(LockMode.Allies, true, false, true, new List<Pawn>());
WantedState = new LockState(LockMode.Allies, true, false, true, new List<Pawn>());
}

// Utilities
Expand Down
16 changes: 16 additions & 0 deletions Source/LockState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,35 @@ public void CopyFrom(LockState copy)
public static bool operator !=(LockState a, LockState b)
{
if (a.mode != b.mode)
{
return true;
}
if (a.locked != b.locked)
{
return true;
}
if (a.petDoor != b.petDoor)
{
return true;
}
if (a.pensDoor != b.pensDoor)
{
return true;
}
foreach (var p in a.owners)
{
if (!b.owners.Contains(p))
{
return true;
}
}
foreach (var p in b.owners)
{
if (!a.owners.Contains(p))
{
return true;
}
}
return false;
}

Expand Down
28 changes: 18 additions & 10 deletions Source/LockUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,42 @@ public static bool PawnCanOpen(Building_Door door, Pawn p)
else
respectedState = GetData(door).CurrentState;


if (GetData(door).CurrentState.locked == false && p.RaceProps != null && p.RaceProps.intelligence >= Intelligence.Humanlike)
{
return true;
}

if (p.Faction == null || p.Faction.HostileTo(door.Faction))
return false;
Log.Message($"State check: {respectedState.pensDoor}, { p.RaceProps.FenceBlocked} {!door.def.building.roamerCanOpen} {!p.roping.IsRopedByPawn}");
if( p.roping.RopedByPawn != null)
if (respectedState.pensDoor && p.RaceProps.FenceBlocked && !door.def.building.roamerCanOpen && (!p.roping.IsRopedByPawn || !PawnCanOpen(door, p.roping.RopedByPawn)))
{
Log.Message($"{!PawnCanOpen(door, p.roping.RopedByPawn)}");
return false;
}
if (respectedState.pensDoor && p.RaceProps.FenceBlocked && !door.def.building.roamerCanOpen && (!p.roping.IsRopedByPawn || !PawnCanOpen(door, p.roping.RopedByPawn)))
if (p.Faction == null || p.Faction.HostileTo(door.Faction))
{
return false;
}

if (respectedState.Private && respectedState.petDoor && p.RaceProps != null && p.RaceProps.Animal && p.RaceProps.baseBodySize <= MaxPetSize && p.Faction == door.Faction)
{
return true;
}

if (respectedState.Private && !respectedState.owners.Contains(p))
return false;
{ return false; }

if (p.Faction == door.Faction && !p.IsPrisoner)
{
return true;

}
bool guestCondition = !p.IsPrisoner || p.HostFaction != door.Faction;
if (respectedState.mode == LockMode.Allies && guestCondition)
{
return true;
}

if (door.Map != null && door.Map.Parent.doorsAlwaysOpenForPlayerPawns && p.Faction == Faction.OfPlayer && !p.IsPrisonerOfColony)
{
return true;
}
return false;
}

Expand Down Expand Up @@ -135,7 +143,7 @@ public static bool IsVisible(this LockState state, string propertyName)
case nameof(LockState.petDoor):
return state.locked;
case nameof(LockState.pensDoor):
return state.locked;
return true;
case nameof(LockState.owners):
return state.locked;
default:
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Changelog:
2.6.2
- Pens door are turned on by default
- Doors can be unlocked and still works as pens door
- Varius fixes
2.6.1
- Add option to set door as pens door. Animals should not leave pens now.
2.6.0
Expand Down

0 comments on commit 14755f2

Please sign in to comment.