public static void AfterWorldLoad()
        {
            try
            {
                string folder = $"{GameLoader.SavedGameFolder}/{ServerManager.WorldName}/";
                string file   = $"{folder}ColonyAddOnsJobs.json";

                if (File.Exists(file))
                {
                    if (JSON.Deserialize(file, out var n))
                    {
                        foreach (KeyValuePair <string, JSONNode> p in n.LoopObject())
                        {
                            Logger.Log("Player {0}", p.Key);
                            foreach (JSONNode j in p.Value.LoopArray())
                            {
                                if (j.TryGetAs <string>("type", out string result))
                                {
                                    Logger.Log("Type {0} Player {1}", result, Players.GetPlayer(NetworkID.Parse(p.Key)).Name);
                                    //Add new jobs here to create them

                                    switch (result)
                                    {
                                    case "Ulfric.ColonyAddOns.Militia":
                                        MilitiaJob m = new MilitiaJob();
                                        m.InitializeFromJSON(Players.GetPlayer(NetworkID.Parse(p.Key)), j);
                                        JobList.Add(m);
                                        break;

                                    case "Ulfric.ColonyAddOns.Sick":
                                        SickJob s = new SickJob();
                                        s.InitializeFromJSON(Players.GetPlayer(NetworkID.Parse(p.Key)), j);
                                        JobList.Add(s);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Logger.Log("{0}.AfterWorldLoad had an error : {1}", ColonyManager.MOD_NAMESPACE, e.Message);
            }
        }
Example #2
0
        private static string InfectNPC(Colony c)
        {
            string sickNPC = null;

            if (Pipliz.Random.NextFloat(0.0f, 1.0f) <= Configuration.ChanceOfDiseaseSpread)
            {
                foreach (NPCBase follower in c.Followers)
                {
                    if (!follower.Job.NPCType.Equals(SickJob.SickNPCType))
                    {
                        if (follower.Job != null)
                        {
                            follower.Job.NPC = null;
                            follower.ClearJob();
                        }

                        //Create the sickjob, save the old job so it can be reset with the NPC is health again and if it is available.  Init job and assign the NPC to the sickjob.
                        SickJob sickjob = new SickJob();
                        sickjob.OldJob = (Job)follower.Job;
                        sickjob.InitializeJob(follower.Colony.Owner, follower.Position, follower.ID);
                        sickjob.OnAssignedNPC(follower);
                        follower.TakeJob(sickjob);

                        //add job so it will be saved and loaded with server restarts
                        ColonyManager.AddJobs(sickjob);

                        //Make old job available
                        JobTracker.Add(sickjob.OldJob);

                        //Set so the name of the old job can be returned
                        sickNPC = follower.Job.NPCType.ToString();

                        break;
                    }
                }
            }
            return(sickNPC);
        }