예제 #1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(delegate
            {
                Designation designation = Map.designationManager.DesignationOn(TargetThingA, LockUtility.DesDef);
                return(designation == null);
            });
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(15).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch));

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.actor;
                Building_DoorExpanded door = (Building_DoorExpanded)actor.CurJob.targetA.Thing;
                this.FailOn(() => !LockUtility.GetData(door).CanChangeLocks(actor));
                LockUtility.GetData(door).CurrentState.CopyFrom(LockUtility.GetData(door).WantedState);
                SoundDefOf.FlickSwitch.PlayOneShot(new TargetInfo(door.Position, door.Map, false));
                door.Map.reachability.ClearCache();
                //actor.records.Increment(RecordDefOf.SwitchesFlicked);
                Designation designation = Map.designationManager.DesignationOn(door, LockUtility.DesDef);
                if (designation != null)
                {
                    designation.Delete();
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil);
        }
예제 #2
0
        public static bool PawnCanOpen(Building_DoorExpanded door, Pawn p)
        {
            Lord lord = p.GetLord();

            bool canOpenAnyDoor = lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(p);
            bool noFaction      = door.Faction == null;

            if (canOpenAnyDoor || noFaction)
            {
                return(true);
            }

            LockState respectedState;

            if (!p.IsPrisoner && !door.Faction.HostileTo(p.Faction) && !p.InMentalState)
            {
                respectedState = GetData(door).WantedState;
            }
            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);
            }

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

            if (respectedState.Private && !respectedState.owners.Contains(p))
            {
                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);
            }

            return(false);
        }
예제 #3
0
 public static LockData GetData(Building_DoorExpanded key)
 {
     if (!Map.ContainsKey(key))
     {
         Map[key] = new LockData();
     }
     Map[key].UpdateReference(key);
     return(Map[key]);
 }
        private static void Postfix(Building_DoorExpanded __instance)
        {
            //TODO disable utility
            if (false)
            {
                return;
            }

            LockUtility.GetData(__instance).ExposeData();
        }
예제 #5
0
        public LockGizmo(Building_DoorExpanded door)
        {
            parent       = door;
            defaultLabel = "Locks_Label".Translate();
            defaultDesc  = "Locks_Description".Translate();
            lockTexture  = ContentFinder <Texture2D> .Get("lock", false);

            unlockTexture = ContentFinder <Texture2D> .Get("unlock", false);

            isActive = () => LockUtility.GetData(parent).WantedState.locked;
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_DoorExpanded door = (Building_DoorExpanded)t;

            if (!LockUtility.GetData(door).CanChangeLocks(pawn))
            {
                JobFailReason.Is("Locks_FailOnWrongUser".Translate(pawn));
                return(null);
            }
            return(new Job(LockUtility.JobDef, t));
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_DoorExpanded door = (Building_DoorExpanded)t;

            if (!LockUtility.GetData(door).CanChangeLocks(pawn))
            {
                JobFailReason.Is("Locks_FailOnWrongUser".Translate(pawn));
                return(false);
            }
            return(pawn.Map.designationManager.DesignationOn(t, LockUtility.DesDef) != null && pawn.CanReserveAndReach(t, PathEndMode.Touch, pawn.NormalMaxDanger(), 1, -1, null, forced));
        }
예제 #8
0
        public static void UpdateLockDesignation(Thing t)
        {
            bool flag = false;
            Building_DoorExpanded door = t as Building_DoorExpanded;

            if (door != null)
            {
                flag = GetData(door).NeedChange;
            }
            Designation designation = t.Map.designationManager.DesignationOn(t, DesDef);

            if (flag && designation == null)
            {
                t.Map.designationManager.AddDesignation(new Designation(t, DesDef));
                door.Map.reachability.ClearCache();
            }
            else if (!flag && designation != null)
            {
                designation.Delete();
            }
        }
예제 #9
0
 public void UpdateReference(Building_DoorExpanded door)
 {
     parent = door;
 }
예제 #10
0
 public static void Remove(Building_DoorExpanded key)
 {
     Map.Remove(key);
 }
예제 #11
0
 private static void Postfix(Building_DoorExpanded __instance)
 {
     LockUtility.Remove(__instance);
 }
예제 #12
0
 public static IEnumerable <Gizmo> AddLockGizmo(IEnumerable <Gizmo> collection, Building_DoorExpanded door)
 {
     return(collection.Add(new LockGizmo(door)));
 }