示例#1
0
        public override void MapComponentTick()
        {
            AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>();

            if (mapCompOn && !(AvaliPackDriver.packs == null) && AvaliPackDriver.packs.Count > 0)
            {
                if (onTick == 120)
                {
                    Map map = this.map;
                    if (multiThreaded)
                    {
                        ThreadStart packThreadRef = new ThreadStart(UpdateThreaded);
                        Thread      packThread    = new Thread(packThreadRef);
                        packThread.Start();
                    }
                    else
                    {
                        UpdatePawns(map);
                    }
                    onTick = 0;
                }
                else
                {
                    onTick += 1;
                }
            }
        }
示例#2
0
        public static void CleanupPacks(this Pawn pawn)
        {
            AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>();

            while (AvaliPackDriver.packs.Where(p => p.pawns.Contains(pawn)).Count() > 1)
            {
                AvaliPackDriver.packs.Remove(AvaliPackDriver.packs.Where(p => p.pawns.Contains(pawn)).Last());
            }
        }
示例#3
0
        public static AvaliPack GetPackWithoutSelf(this Pawn pawn)
        {
            AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>();

            if (pawn == null)
            {
                if (RimValiMod.settings.enableDebugMode)
                {
                    Log.Error("Pawn check is null!");
                }
                return(null);
            }
            if (AvaliPackDriver.packs == null || AvaliPackDriver.packs.Count == 0)
            {
                if (RimValiMod.settings.enableDebugMode)
                {
                    Log.Message("No packs");
                }
                return(null);
            }
            //We really should be getting here
            if (AvaliPackDriver.packs.Count > 0)
            {
                foreach (AvaliPack APack in AvaliPackDriver.packs)
                {
                    //Checks if somehow a pack has 0 pawns (never should happen), then checks if the pawn is in it.
                    if (APack.pawns.Count > 0)
                    {
                        if (APack.pawns.Contains(pawn))
                        {
                            AvaliPack returnPack = new AvaliPack(APack.faction);
                            returnPack.pawns.AddRange(APack.pawns);
                            returnPack.pawns.Remove(pawn);
                            //returnPack.size = APack.size;
                            returnPack.deathDates.AddRange(APack.deathDates);
                            returnPack.creationDate = APack.creationDate;
                            return(returnPack);
                        }
                    }
                }
            }
            else
            {
                return(null);
            }
            //If somehow nothing worked, just return null.

            /*if (enableDebug)
             * {
             *  Log.Message("Didn't find pack, returning null.");
             * }*/
            return(null);
        }
示例#4
0
 public static void UpdatePackAvailibilty(this Pawn pawn)
 {
     if (pawn.GetPack() != null && pawn.GetPack().pawns.Count >= 2)
     {
         AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>();
         if (!AvaliPackDriver.pawnsHaveHadPacks.ContainsKey(pawn))
         {
             AvaliPackDriver.pawnsHaveHadPacks.Add(pawn, true);
         }
         AvaliPackDriver.pawnsHaveHadPacks[pawn] = true;
     }
 }
示例#5
0
        public static AvaliPack EiCreatePack(Pawn pawn)
        {
            AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>();
            AvaliPack       PawnPack        = new AvaliPack(pawn.Faction);

            PawnPack.name = pawn.Name.ToStringShort + "'s pack";
            if (RimValiMod.settings.enableDebugMode)
            {
                Log.Message("Creating pack: " + PawnPack.name);
            }
            PawnPack.pawns.Add(pawn);
            return(PawnPack);
        }
示例#6
0
        public void UpdatePawns(Map map)
        {
            AvaliPackDriver         AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>();
            IEnumerable <Pawn>      pawns           = RimValiUtility.CheckAllPawnsInMapAndFaction(map, Faction.OfPlayer).Where(x => AvaliPackDriver.racesInPacks.Contains(x.def));
            IEnumerable <AvaliPack> packs           = AvaliPackDriver.packs;

            foreach (Pawn pawn in pawns)
            {
                AvaliThoughtDriver avaliThoughtDriver = pawn.TryGetComp <AvaliThoughtDriver>();
                PackComp           packComp           = pawn.TryGetComp <PackComp>();
                if (!(avaliThoughtDriver == null))
                {
                    //Log.Message("Pawn has pack comp, moving to next step...");
                    if (AvaliPackDriver.packs == null || AvaliPackDriver.packs.Count == 0)
                    {
                        //Log.Message("How did we get here? [Pack list was 0 or null]");
                        return;
                    }
                    AvaliPack pawnPack = null;
                    //This errors out when pawns dont have a pack, in rare cases. That is bad. This stops it from doing that.
                    try { pawnPack = pawn.GetPack(); }
                    catch
                    {
                        return;
                    }
                    //Log.Message("Tried to get packs pack, worked.");
                    if (pawnPack == null)
                    {
                        //Log.Message("How did we get here? [Pack was null.]");
                        break;
                    }
                    foreach (Pawn packmate in pawnPack.pawns)
                    {
                        Thought_Memory thought_Memory2 = (Thought_Memory)ThoughtMaker.MakeThought(packComp.Props.togetherThought);
                        if (!(packmate == pawn) && packmate != null && pawn != null)
                        {
                            bool bubble;
                            if (!thought_Memory2.TryMergeWithExistingMemory(out bubble))
                            {
                                //Log.Message("Adding thought to pawn.");
                                pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory2, packmate);
                            }
                        }
                    }
                }
            }
        }
示例#7
0
        public static AvaliPack JoinPack(Pawn pawn, ref AvaliPack pack)
        {
            Date            date            = new Date();
            AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>();


            if (!AvaliPackDriver.pawnsHaveHadPacks.ContainsKey(pawn) || !AvaliPackDriver.pawnsHaveHadPacks[pawn] && date.ToString() == pack.creationDate.ToString())
            {
                pack.pawns.Add(pawn);
                return(pack);
            }
            else
            {
                if (GetPackAvgOP(pack, pawn) >= LoadedModManager.GetMod <RimValiMod>().GetSettings <RimValiModSettings>().packOpReq)
                {
                    pack.pawns.Add(pawn);
                    return(pack);
                }
            }
            return(pack);
        }
示例#8
0
        /// <summary>
        /// Handles the job of managing pack related functions, such as creating packs for a pawn, making a pawn join packs, etc.
        /// </summary>
        /// <param name="packs"></param>
        /// <param name="pawn"></param>
        /// <param name="racesInPacks"></param>
        /// <param name="packLimit"></param>
        /// <returns></returns>
        public static List <AvaliPack> EiPackHandler(List <AvaliPack> packs, Pawn pawn, IEnumerable <ThingDef> racesInPacks, int packLimit)
        {
            AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>();

            void createPack(string reason = null)
            {
                AvaliPack newPack = EiCreatePack(pawn);

                if (!AvaliPackDriver.packs.Contains(newPack))
                {
                    packs.Add(newPack);
                }
                if (reason != null)
                {
                    if (RimValiMod.settings.enableDebugMode)
                    {
                        Log.Message($"Creating pack for reason: {reason}");
                    }
                }
            }

            //We only want to run this if there are packs, otherwise we'll automatically make a "base" pack.
            if (packs.Count > 0)
            {
                //If the pawn isn't spawned, we don't care.
                if (!pawn.Spawned)
                {
                    return(packs);
                }
                IEnumerable <AvaliPack> packsToUse = packs.Where <AvaliPack>(x => x.faction == pawn.Faction && x.pawns.Any(p => p.Map == pawn.Map));
                if (packsToUse.Count() <= 0)
                {
                    createPack("packs is less than or equal to zero");
                }
                AvaliPack pack = pawn.GetPack();
                //This checks if a pack only has one pawn or if it is null, and also if we can join a random pack.
                if (((pack != null && !pack.pawns.NullOrEmpty() && pack.pawns.Count == 1) || pack == null) && packsToUse.Any(p => p != pack && p.pawns.Count < packLimit))
                {
                    AvaliPack pack2 = packsToUse.Where(p => p.pawns.Count < packLimit).RandomElement();
                    if (pack2 != null && pack2.pawns.Count < packLimit)
                    {
                        //If we did have a previous pack, just remove it. It's not needed anymore.
                        if (pack != null)
                        {
                            AvaliPackDriver.packs.Remove(pack);
                        }
                        JoinPack(pawn, ref pack2);
                    }
                }
                //If we get here, we'll create a new pack.
                else if (!(pack != null && !pack.pawns.NullOrEmpty() && !(pack.pawns.Count == 1)))
                {
                    createPack("No pack for pawn");
                    if (RimValiMod.settings.enableDebugMode)
                    {
                        Log.Message((!(pack != null && !pack.pawns.NullOrEmpty() && !(pack.pawns.Count == 1))).ToString());
                    }
                }
            }
            else
            {
                createPack("No packs in list");
            }
            //Avoids pawns with double packs
            pawn.CleanupPacks();
            //Does pack boosts
            foreach (AvaliPack pack in AvaliPackDriver.packs.Where(p => p.pawns.Count > 1))
            {
                if (RimValiMod.settings.enableDebugMode)
                {
                    Log.Message("Updating pack hediffs");
                }
                pack.UpdateHediffForAllMembers();
            }
            //This automatically updates if a pawn can join a pack without opinion and pack loss.
            pawn.UpdatePackAvailibilty();
            return(packs);
        }