public RoamingJobState(JSONNode baseNode, Colony colony)
        {
            Position = (Vector3Int)baseNode[nameof(Position)];
            Colony   = colony;

            if (baseNode.TryGetAs <string>(nameof(RoamObjective), out var ro))
            {
                RoamObjective = ro;
            }

            if (baseNode.TryGetAs(nameof(ActionEnergy), out JSONNode ItemsRemovedNode) && ItemsRemovedNode.NodeType == NodeType.Object)
            {
                foreach (var aNode in ItemsRemovedNode.LoopObject())
                {
                    ActionEnergy.Add(aNode.Key, aNode.Value.GetAs <int>());
                }
            }

            RoamingJobSettings = RoamingJobManager.GetCallbacks(RoamObjective);
            Initialize();
        }
示例#2
0
        public static void OnLoadingColony(Colony c, JSONNode n)
        {
            if (!_colonyStates.ContainsKey(c))
            {
                _colonyStates.Add(c, new ColonyState(c));
            }

            if (n.TryGetChild(GameLoader.NAMESPACE + ".ColonyState", out var stateNode))
            {
                if (stateNode.TryGetAs(nameof(ItemsPlaced), out JSONNode ItemsPlacedNode))
                {
                    foreach (var aNode in ItemsPlacedNode.LoopObject())
                    {
                        _colonyStates[c].ItemsPlaced.Add(ushort.Parse(aNode.Key), aNode.Value.GetAs <int>());
                    }
                }

                if (stateNode.TryGetAs(nameof(ItemsRemoved), out JSONNode ItemsRemovedNode))
                {
                    foreach (var aNode in ItemsRemovedNode.LoopObject())
                    {
                        _colonyStates[c].ItemsRemoved.Add(ushort.Parse(aNode.Key), aNode.Value.GetAs <int>());
                    }
                }

                if (stateNode.TryGetAs(nameof(ItemsInWorld), out JSONNode ItemsInWorldNode))
                {
                    foreach (var aNode in ItemsInWorldNode.LoopObject())
                    {
                        _colonyStates[c].ItemsInWorld.Add(ushort.Parse(aNode.Key), aNode.Value.GetAs <int>());
                    }
                }

                if (stateNode.TryGetAs(nameof(Stats), out JSONNode itterations))
                {
                    foreach (var skill in itterations.LoopObject())
                    {
                        _colonyStates[c].Stats[skill.Key] = skill.Value.GetAs <double>();
                    }
                }

                if (stateNode.TryGetAs("Difficulty", out string diff))
                {
                    _colonyStates[c].DifficultyStr = diff;
                }

                if (stateNode.TryGetAs(nameof(BossesEnabled), out bool bosses))
                {
                    _colonyStates[c].BossesEnabled = bosses;
                }

                if (stateNode.TryGetAs(nameof(NotifySettlers), out bool settlers))
                {
                    _colonyStates[c].NotifySettlers = settlers;
                }

                if (stateNode.TryGetAs(nameof(SettlersEnabled), out bool notify))
                {
                    _colonyStates[c].SettlersEnabled = notify;
                }

                if (stateNode.TryGetAs(nameof(HighestColonistCount), out int hsc))
                {
                    _colonyStates[c].HighestColonistCount = hsc;
                }

                if (stateNode.TryGetAs(nameof(NeedsABed), out int nb))
                {
                    _colonyStates[c].NeedsABed = nb;
                }

                if (stateNode.TryGetAs(nameof(SettlersToggledTimes), out int stt))
                {
                    _colonyStates[c].SettlersToggledTimes = stt;
                }

                if (stateNode.TryGetAs(nameof(CreationDate), out string joindate) && DateTime.TryParse(joindate, out var parsedJoinDate))
                {
                    _colonyStates[c].CreationDate = parsedJoinDate;
                }
            }
        }
示例#3
0
        public static void OnLoadingPlayer(JSONNode n, Players.Player p)
        {
            if (!_playerStates.ContainsKey(p))
            {
                _playerStates.Add(p, new PlayerState(p));
            }

            if (n.TryGetChild(GameInitializer.NAMESPACE + ".PlayerState", out var stateNode))
            {
                if (stateNode.TryGetAs(nameof(ItemsPlaced), out JSONNode ItemsPlacedNode))
                {
                    foreach (var aNode in ItemsPlacedNode.LoopObject())
                    {
                        _playerStates[p].ItemsPlaced.Add(ushort.Parse(aNode.Key), aNode.Value.GetAs <int>());
                    }
                }

                if (stateNode.TryGetAs(nameof(Tutorials), out JSONNode tutorials))
                {
                    foreach (var aNode in tutorials.LoopObject())
                    {
                        _playerStates[p].Tutorials.Add(aNode.Key, aNode.Value.GetAs <bool>());
                    }
                }

                if (stateNode.TryGetAs(nameof(Positions), out JSONNode positions))
                {
                    foreach (var aNode in positions.LoopObject())
                    {
                        _playerStates[p].Positions.Add(aNode.Key, (Vector3Int)aNode.Value);
                    }
                }

                if (stateNode.TryGetAs(nameof(ItemsRemoved), out JSONNode ItemsRemovedNode))
                {
                    foreach (var aNode in ItemsRemovedNode.LoopObject())
                    {
                        _playerStates[p].ItemsRemoved.Add(ushort.Parse(aNode.Key), aNode.Value.GetAs <int>());
                    }
                }

                if (stateNode.TryGetAs(nameof(ItemsInWorld), out JSONNode ItemsInWorldNode))
                {
                    foreach (var aNode in ItemsInWorldNode.LoopObject())
                    {
                        _playerStates[p].ItemsInWorld.Add(ushort.Parse(aNode.Key), aNode.Value.GetAs <int>());
                    }
                }

                if (stateNode.TryGetAs(nameof(Backpack), out JSONNode backpack))
                {
                    foreach (var aNode in backpack.LoopObject())
                    {
                        _playerStates[p].Backpack.Add(ushort.Parse(aNode.Key), aNode.Value.GetAs <int>());
                    }
                }

                if (stateNode.TryGetAs("Armor", out JSONNode armorNode) && armorNode.NodeType == NodeType.Object)
                {
                    foreach (var aNode in armorNode.LoopObject())
                    {
                        _playerStates[p].Armor[(ArmorFactory.ArmorSlot)Enum.Parse(typeof(ArmorFactory.ArmorSlot), aNode.Key)] =
                            new ItemState(aNode.Value);
                    }
                }

                if (stateNode.TryGetAs("FlagsPlaced", out JSONNode flagsPlaced) &&
                    flagsPlaced.NodeType == NodeType.Array)
                {
                    foreach (var aNode in flagsPlaced.LoopArray())
                    {
                        _playerStates[p].FlagsPlaced.Add((Vector3Int)aNode);
                    }
                }

                if (stateNode.TryGetAs("TeleporterPlaced", out JSONNode teleporterPlaced))
                {
                    _playerStates[p].TeleporterPlaced = (Vector3Int)teleporterPlaced;
                }

                if (stateNode.TryGetAs("Weapon", out JSONNode wepNode))
                {
                    _playerStates[p].Weapon = new ItemState(wepNode);
                }

                if (stateNode.TryGetAs(nameof(BuildersWandCharge), out int wandCharge))
                {
                    _playerStates[p].BuildersWandCharge = wandCharge;
                }

                if (stateNode.TryGetAs(nameof(BuildersWandTarget), out ushort wandTarget))
                {
                    _playerStates[p].BuildersWandTarget = wandTarget;
                }

                if (stateNode.TryGetAs(nameof(JoinDate), out string joindate) && DateTime.TryParse(joindate, out var parsedJoinDate))
                {
                    _playerStates[p].JoinDate = parsedJoinDate;
                }

                _playerStates[p].BuildersWandPreview.Clear();

                if (stateNode.TryGetAs(nameof(BuildersWandPreview), out JSONNode wandPreview))
                {
                    foreach (var node in wandPreview.LoopArray())
                    {
                        _playerStates[p].BuildersWandPreview.Add((Vector3Int)node);
                    }
                }

                var playerMagicItems = new List <IPlayerMagicItem>();

                if (stateNode.TryGetAs(nameof(MagicItems), out JSONNode magicItems))
                {
                    foreach (var magicItem in magicItems.LoopArray())
                    {
                        if (MagicItemsCache.PlayerMagicItems.TryGetValue(magicItem.GetAs <string>(), out var pmi))
                        {
                            playerMagicItems.Add(pmi);
                        }
                    }
                }

                _playerStates[p].MagicItems = playerMagicItems.ToArray();

                if (stateNode.TryGetAs(nameof(Stats), out JSONNode itterations))
                {
                    foreach (var skill in itterations.LoopObject())
                    {
                        _playerStates[p].Stats[skill.Key] = skill.Value.GetAs <double>();
                    }
                }

                _playerStates[p].RecaclculateMagicItems();
            }
        }