private static void LoadHomes()
        {
            Log.Write("Loading homes...");
            string jsonFilePath = "./gamedata/savegames/" + ServerManager.WorldName + "/homes.json";

            if (!File.Exists(jsonFilePath))
            {
                Log.Write("Could not locate homes.json! Ignoring");
                return;
            }

            JSONNode homesJSON = JSON.Deserialize(jsonFilePath);

            foreach (JSONNode playerJSON in homesJSON.LoopArray())
            {
                NetworkID player = NetworkID.Parse(playerJSON.GetAs <string>("i"));
                Dictionary <string, UnityEngine.Vector3Int> playerHomesJSON = new Dictionary <string, UnityEngine.Vector3Int>();

                // Load homes
                foreach (var v in playerJSON.GetAs <JSONNode>("h").LoopArray())
                {
                    UnityEngine.Vector3Int position = new UnityEngine.Vector3Int(v["x"].GetAs <int>(), v["y"].GetAs <int>(), v["z"].GetAs <int>());
                    playerHomesJSON.Add(v.GetAs <string>("n"), position);
                }


                homes.Add(player, playerHomesJSON);
            }

            Log.Write("Loaded homes.");
        }
        public override void FinishLoading()
        {
            base.FinishLoading();
            if (legacyJSON != null)
            {
                foreach (var pair in legacyJSON.LoopObject())
                {
                    try {
                        Players.Player player = Players.GetPlayer(NetworkID.Parse(pair.Key));

                        for (int i = 0; i < pair.Value.ChildCount; i++)
                        {
                            JSONNode jobNode = pair.Value[i];

                            int        npcID = jobNode.GetAsOrDefault("npcID", 0);
                            Vector3Int min   = (Vector3Int)jobNode["positionMin"];
                            Vector3Int max   = (Vector3Int)jobNode["positionMax"];

                            var job = new DefaultFarmerAreaJob <TemperateForesterDefinition>(player, min, max, npcID);
                            if (!AreaJobTracker.RegisterAreaJob(job))
                            {
                                job.OnRemove();
                            }
                        }
                    } catch (System.Exception e) {
                        Log.WriteException("Exception loading legacy area job data", e);
                    }
                }
                legacyJSON = null;
            }
        }
Beispiel #3
0
        //Load & saving
        public Team(JSONNode json)
        {
            if (!json.TryGetAs <uint>("fake_playerID", out uint fake_playerID))
            {
                Log.Write("<color=orange>Error loading the fake_playerID</color>");
            }

            fake_player        = Players.GetPlayer(new NetworkID(new Steamworks.CSteamID(new Steamworks.AccountID_t(fake_playerID), Steamworks.EUniverse.k_EUniversePublic, Steamworks.EAccountType.k_EAccountTypeAnonUser)));
            this.fake_playerID = fake_playerID;

            playersOnTeam = new List <NetworkID>();

            if (!json.TryGetChild("players", out JSONNode players))
            {
                Log.Write("<color=orange>Error loading the players</color>");
            }

            foreach (var player in players.LoopArray())
            {
                playersOnTeam.Add(NetworkID.Parse(player.GetAs <string>()));
            }

            if (fake_AcountID <= fake_playerID)
            {
                fake_AcountID = fake_playerID + 1;
            }

            TeamManager.GetTeamManager().AddTeam(this);
        }
Beispiel #4
0
        public static void LoadWarnings()
        {
            Log.Write("<color=lime>Loading warnings</color>");
            string jsonFilePath = "./gamedata/savegames/" + ServerManager.WorldName + "/warning.json";

            if (!File.Exists(jsonFilePath))
            {
                return;
            }

            JSONNode warninJSON = JSON.Deserialize(jsonFilePath);

            foreach (JSONNode warn in warninJSON.LoopArray())
            {
                NetworkID player = NetworkID.Parse(warn.GetAs <string>("player"));

                Dictionary <ushort, int> warning = new Dictionary <ushort, int>();

                //Load checkItems
                foreach (var checkItem in warn.GetAs <JSONNode>("checkItems").LoopArray())
                {
                    ushort type   = checkItem.GetAs <ushort>("type");
                    int    amount = checkItem.GetAs <int>("amount");

                    warning.Add(type, amount);
                }

                warnings.Add(player, warning);
            }
        }
Beispiel #5
0
        public Empire(JSONNode json)
        {
            Name = json.GetAs <string>("Name");
            Tag  = json.GetAsOrDefault <string>("Tag", "");

            //announcement = json.GetAs<string>("Announcement");
            automaticRequest = json.GetAs <bool>("automaticRequest");

            //Load Permissions
            int i = (int)Rank.Emperor;

            foreach (var permission in json.GetAs <JSONNode>("Permissions").LoopArray())
            {
                permissions[i++] = (Permissions)Enum.Parse(typeof(Permissions), permission.GetAs <string>());
            }

            //Load members
            foreach (var member in json.GetAs <JSONNode>("Members").LoopArray())
            {
                NetworkID nID  = NetworkID.Parse(member.GetAs <string>("ID"));
                Rank      rank = (Rank)Enum.Parse(typeof(Rank), member.GetAs <string>("Rank"));

                members.Add(nID, rank);
            }

            //Load Request
            foreach (var requests in json.GetAs <JSONNode>("Requests").LoopArray())
            {
                NetworkID nID = NetworkID.Parse(requests.GetAs <string>());
                joinRequest.Add(nID);
            }

            empires.Add(this);
        }
        public virtual void InitFromJson(JSONNode jsonNode)
        {
            if (!jsonNode.TryGetAs("NpcID", out NpcID))
            {
                NpcID = KingdomsTracker.GetNextNpcID();
            }
            string name;

            if (jsonNode.TryGetAs("Name", out name))
            {
                Name = name;
            }
            JSONNode jsonOrigin;

            if (jsonNode.TryGetAs("Origin", out jsonOrigin))
            {
                Origin = (Vector3Int)jsonOrigin;
            }
            string networkID;

            if (jsonNode.TryGetAs("NetworkID", out networkID))
            {
                NetworkID = NetworkID.Parse(networkID);
            }
            else
            {
                NetworkID = CreateFakeNetworkID(NpcID);
            }
            FinishInitialization();
        }
Beispiel #7
0
        private static void LoadGliders(JObject rootObj)
        {
            JToken jtoken1;

            if (!rootObj.TryGetValue("transports", out jtoken1))
            {
                return;
            }
            if (jtoken1.Type != JTokenType.Array)
            {
                Log.WriteWarning("Didn't load gliders as transports wasn't an array");
            }
            else
            {
                JArray jarray = (JArray)jtoken1;
                int    count  = jarray.Count;
                for (int index = 0; index < count; ++index)
                {
                    JToken jtoken2 = jarray[index];
                    if (jtoken2.Type == JTokenType.Object)
                    {
                        JObject jobject = (JObject)jtoken2;
                        if (jobject.TryGetValue("type", out jtoken2) && jtoken2.Type == JTokenType.String)
                        {
                            if (!(jtoken2.Value <string>() != "fastglider"))
                            {
                                try
                                {
                                    Vector3    spawnPosition = ReadVector3((JObject)jobject["position"]);
                                    Quaternion rotation      = Quaternion.Euler(ReadVector3((JObject)jobject["rotation"]));
                                    MeshedVehicleDescription vehicleDescription = FastGlider.CreateVehicleDescription(MeshedObjectID.GetNew());
                                    Players.Player           player             = (Players.Player)null;
                                    JToken jtoken3;
                                    if (jobject.TryGetValue("player", out jtoken3) && jtoken3.Type == JTokenType.String)
                                    {
                                        player = Players.GetPlayer(NetworkID.Parse((string)jtoken3));
                                        MeshedObjectManager.Attach(player, vehicleDescription);
                                    }
                                    FastGlider.CreateGlider(spawnPosition, rotation, vehicleDescription, player);
                                }
                                catch (Exception ex)
                                {
                                    Log.WriteException("Exception loading gliders:", ex);
                                }
                            }
                        }
                    }
                }
            }

            Vector3 ReadVector3(JObject obj)
            {
                return(new Vector3(obj.Value <float>((object)"x"), obj.Value <float>((object)"y"), obj.Value <float>((object)"z")));
            }
        }
        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);
            }
        }
Beispiel #9
0
        public virtual void LoadJSON(JSONNode node)
        {
            JSONNode table = node.GetAs <JSONNode>("table");

            foreach (var pair in table.LoopObject())
            {
                Players.Player player = Players.GetPlayer(NetworkID.Parse(pair.Key));
                JSONNode       array  = pair.Value;
                for (int i = 0; i < array.ChildCount; i++)
                {
                    var job = CreateAreaJob(player, array[i]);
                    if (!AreaJobTracker.RegisterAreaJob(job))
                    {
                        job.OnRemove();
                    }
                }
            }
        }
Beispiel #10
0
        public static void LoadSigns()
        {
            signFile = "./gamedata/savegames/" + ServerManager.WorldName + "/signs.json";

            if (!File.Exists(signFile))
            {
                return;
            }

            JSONNode json = JSON.Deserialize(signFile);

            foreach (JSONNode sign in json.LoopArray())
            {
                Vector3Int pos   = (Vector3Int)sign["position"];
                NetworkID  owner = NetworkID.Parse(sign.GetAs <string>("owner"));
                string     text  = sign.GetAs <string>("text");

                signs.Add(pos, new Sign(owner, text));
            }
        }
        public TrainTransport(TransportSave transportSave)
        {
            if (transportSave.type == _trackCalculationType.name)
            {
                Position                  = transportSave.position;
                _prevPosition             = transportSave.prevPos;
                _trainId                  = transportSave.itemName;
                TrackPosition             = transportSave.trackPos;
                TrainType                 = Train.TrainTypes[transportSave.itemName];
                _animatedObject           = Train.TrainAnimations[transportSave.itemName];
                _meshedVehicleDescription = new MeshedVehicleDescription(new ClientMeshedObject(_animatedObject.ObjType, new MeshedObjectID(transportSave.meshid)), TrainType.TrainConfiguration.playerSeatOffset, TrainType.TrainConfiguration.AllowPlayerToEditBlocksWhileRiding);
                _idealHeightFromTrack     = TrainType.TrainConfiguration.IdealHeightFromTrack;
                _energy          = transportSave.energy;
                Delay            = TrainType.TrainConfiguration.MoveTimePerBlockMs;
                ManaCostPerBlock = TrainType.TrainConfiguration.EnergyCostPerBlock;

                if (!string.IsNullOrEmpty(transportSave.player))
                {
                    _player = Players.GetPlayer(NetworkID.Parse(transportSave.player));
                    MeshedObjectManager.Attach(_player, _meshedVehicleDescription);
                }
            }
        }
Beispiel #12
0
        public static void EmpireButtonManager(ButtonPressCallbackData data)
        {
            Empire empire;

            Players.Player plr;

            switch (data.ButtonIdentifier)
            {
            case "Imperium_NewEmpire":
            {
                SendMenuFoundEmpire(data.Player);
            }
            break;

            case "Imperium_FoundEmpire":
            {
                Empire.CreateEmpire(data.Storage.GetAs <string>("EmpireName"), data.Storage.GetAs <string>("EmpireTag"), data.Player);
            }
            break;

            case "Imperium_Apply":
            {
                empire = Empire.GetEmpire(data.ButtonPayload.Value <string>("empire"));

                if (null != empire)
                {
                    empire.ApplyFor(data.Player);
                }
                SendMenuEmpireList(data.Player);
            }
            break;

            case "Imperium_Request":
            {
                empire = Empire.GetEmpire(data.Player);

                if (empire == null)
                {
                    return;
                }

                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    if (data.ButtonPayload.Value <bool>("accept"))
                    {
                        empire.Invite(plr, data.Player);
                    }
                    else
                    {
                        empire.joinRequest.Remove(plr.ID);
                        Chatting.Chat.Send(plr, string.Format("<color=green>{0} has rejected your request of joining.</color>", empire.Name));
                    }
                }

                if (empire.joinRequest.Count > 0)
                {
                    SendMenuEmpireRequest(data.Player);
                }
                else
                {
                    SendMenuEmpire(data.Player);
                }
            }
            break;

            case "Imperium_HELP":
            {
                SendMenuHelp(data.Player);
            }
            break;

            case "Imperium_ApplyManage":
            {
                SendMenuEmpireRequest(data.Player);
            }
            break;

            case "Imperium_BackPermission":
            {
                SendMenuPermissions(data.Player);
            }
            break;

            case "Imperium_SettingsMenu":
            {
                SendMenuEmpireSettings(data.Player);
            }
            break;

            case "Imperium_Manage":
            {
                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    SendMenuEmpireManage(data.Player, plr);
                }
            }
            break;

            case "Imperium_Promote":
            {
                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    empire = Empire.GetEmpire(data.Player);

                    if (null != empire)
                    {
                        empire.Promote(plr, data.Player);
                        SendMenuEmpireManage(data.Player, plr);
                    }
                }
            }
            break;

            case "Imperium_Demote":
            {
                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    empire = Empire.GetEmpire(data.Player);

                    if (null != empire)
                    {
                        empire.Demote(plr, data.Player);
                        SendMenuEmpireManage(data.Player, plr);
                    }
                }
            }
            break;

            case "Imperium_Kick":
            {
                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    empire = Empire.GetEmpire(data.Player);

                    if (null != empire)
                    {
                        empire.Kick(plr, data.Player);
                        SendMenuEmpireManage(data.Player, plr);
                    }
                }
            }
            break;

            case "Imperium_SetSettings":
            {
                empire = Empire.GetEmpire(data.Player);

                if (null != empire)
                {
                    string newName = data.Storage.GetAs <string>("EmpireName");
                    if (!empire.Name.Equals(newName))
                    {
                        empire.SetEmpireName(newName, data.Player);
                    }

                    string newTag = data.Storage.GetAs <string>("EmpireTag");
                    if (!empire.Tag.Equals(newTag))
                    {
                        empire.SetEmpireTag(newTag, data.Player);
                    }

                    bool automaticRequest = data.Storage.GetAs <bool>("AutomaticRequest");
                    if (empire.automaticRequest != automaticRequest)
                    {
                        empire.SetAutomaticRequest(automaticRequest, data.Player);
                    }
                }
            }
            break;

            case "Imperium_Permission":
            {
                int rank = data.ButtonPayload.Value <int>("rank");
                SendMenuPermissionsManagement(data.Player, rank);
            }
            break;

            case "Imperium_SetPermission":
            {
                empire = Empire.GetEmpire(data.Player);

                if (empire != null)
                {
                    int rank = data.ButtonPayload.Value <int>("rank");

                    Permissions newPermission = 0;

                    for (int i = (int)Permissions.Invite; i < (int)Permissions.Disband; i *= 2)
                    {
                        if (data.Storage.GetAs <bool>(((Permissions)i).ToString()))
                        {
                            newPermission |= (Permissions)i;
                        }
                    }

                    empire.SetPermissions(data.Player, (Rank)rank, newPermission);
                }
            }
            break;

            case "Imperium_ManageAsEmperor":
            {
                empire = Empire.GetEmpire(data.ButtonPayload.Value <string>("empire"));

                if (null != empire)
                {
                    empire.AddEmperor(data.Player);
                }
            }
            break;

            case "Imperium_SetRank":
            {
                empire = Empire.GetEmpire(data.Player);

                if (empire == null)
                {
                    return;
                }

                Rank rank = (Rank)data.ButtonPayload.Value <int>("rank");

                empire.SetRank(data.Player, rank);

                Chatting.Chat.Send(data.Player, "Rank set to " + rank.ToString());
            }
            break;
            }
        }