Esempio n. 1
0
        public static bool DeRegisterPawn(MapPawns __instance, Pawn p)
        {
            EnsureFactionsListsInit(__instance);
            lock (__instance)
            {
                List <Pawn> newPawnsSpawned = new List <Pawn>(__instance.pawnsSpawned);
                newPawnsSpawned.Remove(p);
                __instance.pawnsSpawned = newPawnsSpawned;

                List <Faction> allFactionsListForReading = Find.FactionManager.AllFactionsListForReading;
                Dictionary <Faction, List <Pawn> > newPawnsInFactionSpawned =
                    new Dictionary <Faction, List <Pawn> >(__instance.pawnsInFactionSpawned);
                for (int i = 0; i < allFactionsListForReading.Count; i++)
                {
                    Faction key = allFactionsListForReading[i];
                    newPawnsInFactionSpawned[key].Remove(p);
                }
                __instance.pawnsInFactionSpawned = newPawnsInFactionSpawned;
                List <Pawn> newPrisonersOfColonySpawned = new List <Pawn>(__instance.prisonersOfColonySpawned);
                newPrisonersOfColonySpawned.Remove(p);
                __instance.prisonersOfColonySpawned = newPrisonersOfColonySpawned;
            }
            __instance.DoListChangedNotifications();

            return(false);
        }
Esempio n. 2
0
        public static bool RegisterPawn(MapPawns __instance, Pawn p)
        {
            if (p.Dead)
            {
                Log.Warning(string.Concat("Tried to register dead pawn ", p, " in ", __instance.GetType(), "."));
                return(false);
            }
            if (!p.Spawned)
            {
                Log.Warning(string.Concat("Tried to register despawned pawn ", p, " in ", __instance.GetType(), "."));
                return(false);
            }
            if (p.Map != __instance.map)
            {
                Log.Warning(string.Concat("Tried to register pawn ", p, " but his Map is not this one."));
                return(false);
            }

            if (!p.mindState.Active)
            {
                return(false);
            }

            EnsureFactionsListsInit(__instance);
            List <Pawn> pawnList = __instance.pawnsSpawned;

            if (!pawnList.Contains(p))
            {
                lock (__instance)
                {
                    if (!pawnList.Contains(p))
                    {
                        pawnList.Add(p);
                    }
                }
            }

            Dictionary <Faction, List <Pawn> > pawnsInFactionSpawned = __instance.pawnsInFactionSpawned;

            if (p.Faction != null)
            {
                List <Pawn> pawnList2 = pawnsInFactionSpawned[p.Faction];
                if (!pawnList2.Contains(p))
                {
                    lock (__instance)
                    {
                        if (!pawnList2.Contains(p))
                        {
                            pawnList2.Add(p);
                            if (p.Faction == Faction.OfPlayer)
                            {
                                pawnList2.InsertionSort(delegate(Pawn a, Pawn b)
                                {
                                    int num   = a.playerSettings?.joinTick ?? 0;
                                    int value = b.playerSettings?.joinTick ?? 0;
                                    return(num.CompareTo(value));
                                });
                            }
                        }
                    }
                }
            }

            if (p.IsPrisonerOfColony)
            {
                List <Pawn> pawnList3 = __instance.prisonersOfColonySpawned;
                if (!pawnList3.Contains(p))
                {
                    lock (__instance)
                    {
                        if (!pawnList3.Contains(p))
                        {
                            pawnList3.Add(p);
                        }
                    }
                }
            }

            __instance.DoListChangedNotifications();

            return(false);
        }