Ejemplo n.º 1
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(), "."));
            }
            else if (!p.Spawned)
            {
                Log.Warning(string.Concat("Tried to register despawned pawn ", p, " in ", __instance.GetType(), "."));
            }
            else if (p.Map != mapFieldRef(__instance))
            {
                Log.Warning(string.Concat("Tried to register pawn ", p, " but his Map is not this one."));
            }
            else
            {
                if (!p.mindState.Active)
                {
                    return(false);
                }

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

                if (p.IsPrisonerOfColony && !prisonersOfColonySpawned(__instance).Contains(p))
                {
                    lock (__instance)
                    {
                        if (p.IsPrisonerOfColony && !prisonersOfColonySpawned(__instance).Contains(p))
                        {
                            List <Pawn> newPrisonersOfColonySpawned = new List <Pawn>
                            {
                                p
                            };
                            prisonersOfColonySpawned(__instance) = newPrisonersOfColonySpawned;
                        }
                    }
                }

                actionDoListChangedNotifications(__instance);
            }
            return(false);
        }
Ejemplo n.º 2
0
 public static bool RegisterPawn(MapPawns __instance, Pawn p)
 {
     if (p.Dead)
     {
         Log.Warning("Tried to register dead pawn " + (object)p + " in " + (object)__instance.GetType() + ".", false);
     }
     else if (!p.Spawned)
     {
         Log.Warning("Tried to register despawned pawn " + (object)p + " in " + (object)__instance.GetType() + ".", false);
     }
     else if (p.Map != map(__instance))
     {
         Log.Warning("Tried to register pawn " + (object)p + " but his Map is not this one.", false);
     }
     else
     {
         if (!p.mindState.Active)
         {
             return(false);
         }
         EnsureFactionsListsInit(__instance);
         RegisterPawn1(__instance, p);
         RegisterPawn2(__instance, p);
         RegisterPawn3(__instance, p);
         DoListChangedNotifications(__instance);
     }
     return(false);
 }
Ejemplo n.º 3
0
 public static bool RegisterPawn(MapPawns __instance, Pawn p)
 {
     if (p.Dead)
     {
         Log.Warning("Tried to register dead pawn " + (object)p + " in " + (object)__instance.GetType() + ".", false);
     }
     else if (!p.Spawned)
     {
         Log.Warning("Tried to register despawned pawn " + (object)p + " in " + (object)__instance.GetType() + ".", false);
     }
     else if (p.Map != map(__instance))
     {
         Log.Warning("Tried to register pawn " + (object)p + " but his Map is not this one.", false);
     }
     else
     {
         if (!p.mindState.Active)
         {
             return(false);
         }
         EnsureFactionsListsInit(__instance);
         lock (pawnsSpawned(__instance))
         {
             if (!pawnsSpawned(__instance).Contains(p))
             {
                 pawnsSpawned(__instance).Add(p);
             }
         }
         lock (pawnsInFactionSpawned(__instance))
         {
             if (p.Faction != null && !pawnsInFactionSpawned(__instance)[p.Faction].Contains(p))
             {
                 pawnsInFactionSpawned(__instance)[p.Faction].Add(p);
                 if (p.Faction == Faction.OfPlayer)
                 {
                     pawnsInFactionSpawned(__instance)[Faction.OfPlayer].InsertionSort <Pawn>((Comparison <Pawn>)((a, b) => (a.playerSettings != null ? a.playerSettings.joinTick : 0).CompareTo(b.playerSettings != null ? b.playerSettings.joinTick : 0)));
                 }
             }
         }
         lock (prisonersOfColonySpawned(__instance))
         {
             if (p.IsPrisonerOfColony && !prisonersOfColonySpawned(__instance).Contains(p))
             {
                 prisonersOfColonySpawned(__instance).Add(p);
             }
         }
         DoListChangedNotifications(__instance);
     }
     return(false);
 }
Ejemplo n.º 4
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);
        }