Exemplo n.º 1
0
 public LootOption(string typename, JSONNode jsonNode)
 {
     Typename            = typename;
     WeightedProbability = jsonNode.GetAsOrDefault("WeightedProbability", 0);
     MinStackSize        = jsonNode.GetAsOrDefault("MinStackSize", 1);
     MaxStackSize        = jsonNode.GetAsOrDefault("MaxStackSize", 1);
 }
Exemplo n.º 2
0
        public override ITrackableBlock InitializeFromJSON(Players.Player player, JSONNode node)
        {
            originalPosition = (Vector3Int)node[nameof(originalPosition)];
            this.player      = player;
            lastRally        = node.GetAsOrDefault <double>(nameof(lastRally), 0);
            InitializeJob(player, (Vector3Int)node["position"], node.GetAs <int>("npcID"));
            lastDayTrumpeted   = node.GetAsOrDefault <double>(nameof(lastDayTrumpeted), TimeCycle.TotalTime);
            lastNightTrumpeted = node.GetAsOrDefault <double>(nameof(lastNightTrumpeted), TimeCycle.TotalTime);

            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loading a block from JSON
        /// </summary>
        public virtual IGrowableBlock MakeGrowableBlock(JSONNode node)
        {
            Vector3Int position;

            position.x = node.GetAsOrDefault("x", -1);
            position.y = node.GetAsOrDefault("y", -1);
            position.z = node.GetAsOrDefault("z", -1);
            float growth = node.GetAsOrDefault("g", 0f);
            byte  stage  = node.GetAsOrDefault("s", (byte)0);

            return(new GrowableBlock <T>(position, growth, stage));
        }
        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;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        public override ITrackableBlock InitializeFromJSON(Players.Player player, JSONNode node)
        {
            typeBelow = ItemTypes.IndexLookup.GetOrGenerate(node.GetAs <string>("typeBelow"));
            JSONNode customDataNode = ItemTypes.GetType(typeBelow).CustomDataNode;

            if (customDataNode != null)
            {
                MiningCooldown = customDataNode.GetAsOrDefault("minerMiningTime", 8f);
            }
            InitializeJob(player, (Vector3Int)node["position"], node.GetAs <int>("npcID"));
            return(this);
        }
        // need to parse some additional data that the default one doesn't
        public override IAreaJob CreateAreaJob(Colony owner, JSONNode node)
        {
            Vector3Int min = new Vector3Int()
            {
                x = node.GetAsOrDefault("x-", int.MinValue),
                y = node.GetAsOrDefault("y-", int.MinValue),
                z = node.GetAsOrDefault("z-", int.MinValue)
            };

            Vector3Int max = min + new Vector3Int()
            {
                x = node.GetAsOrDefault("xd", 0),
                y = node.GetAsOrDefault("yd", 0),
                z = node.GetAsOrDefault("zd", 0)
            };

            JSONNode args;

            if (!node.TryGetChild("args", out args))
            {
                return(null);
            }

            ConstructionArea area = (ConstructionArea)CreateAreaJob(owner, min, max, true);

            area.SetArgument(args);

            return(area);
        }
Exemplo n.º 8
0
 public ITrackableBlock InitializeOnAdd(Vector3Int position, ushort type, Players.Player player)
 {
     if (World.TryGetTypeAt(position.Add(0, -1, 0), out typeBelow))
     {
         JSONNode customDataNode = ItemTypes.GetType(typeBelow).CustomDataNode;
         if (customDataNode != null)
         {
             MiningCooldown = customDataNode.GetAsOrDefault("minerMiningTime", 8f);
         }
     }
     InitializeJob(player, position, 0);
     return(this);
 }
Exemplo n.º 9
0
        public static void LoadSettigns()
        {
            if (!File.Exists(MODPATH + "/settings.json"))
            {
                Log.Write("<color=red>AdvancedWand: Settings not found</color>");
                return;
            }

            JSONNode json = JSON.Deserialize(MODPATH + "/settings.json");

            AdvancedWand.default_limit = json.GetAsOrDefault <int>("default_limit", 100000);
            int increment = json.GetAsOrDefault <int>("speed", 250);

            if (increment <= 100)
            {
                increment = 100;
            }
            else if (increment >= 1000)
            {
                increment = 1000;
            }

            AdvancedWand.increment = (1010 - increment);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Loading a block from a legacy JSON node format
        /// </summary>
        public virtual IGrowableBlock MakeGrowableBlockLegacy(JSONNode node)
        {
            Vector3Int position = Vector3Int.invalidPos;
            JSONNode   locationNode;

            if (node.TryGetChild("location", out locationNode))
            {
                position.x = locationNode.GetAsOrDefault("x", -1);
                position.y = locationNode.GetAsOrDefault("y", -1);
                position.z = locationNode.GetAsOrDefault("z", -1);
            }
            float growth = node.GetAsOrDefault("growth", 0f);

            return(new GrowableBlock <T>(position, growth, 0));
        }
Exemplo n.º 11
0
        public override IAreaJob CreateAreaJob(Colony owner, JSONNode node)
        {
            Vector3Int min = new Vector3Int()
            {
                x = node.GetAsOrDefault <int>("x-", int.MinValue),
                y = node.GetAsOrDefault <int>("y-", int.MinValue),
                z = node.GetAsOrDefault <int>("z-", int.MinValue)
            };
            Vector3Int max = min + new Vector3Int()
            {
                x = node.GetAsOrDefault <int>("xd", 0),
                y = node.GetAsOrDefault <int>("yd", 0),
                z = node.GetAsOrDefault <int>("zd", 0)
            };
            int asOrDefault = node.GetAsOrDefault <int>("npc", 0);

            RecipeSettingsGroup.GroupID npcGroupID = new RecipeSettingsGroup.GroupID(node.GetAsOrDefault <uint>("gid", 0U));
            return(new PandaBlockFarmAreaJob(this, owner, min, max, asOrDefault, npcGroupID));
        }
Exemplo n.º 12
0
        public virtual IAreaJob CreateAreaJob(Players.Player owner, JSONNode node)
        {
            Vector3Int min = Vector3Int.invalidPos;
            Vector3Int max = Vector3Int.invalidPos;

            JSONNode child;

            if (node.TryGetChild("min", out child))
            {
                min.x = child.GetAsOrDefault("x", -1);
                min.y = child.GetAsOrDefault("y", -1);
                min.z = child.GetAsOrDefault("z", -1);
            }
            if (node.TryGetChild("max", out child))
            {
                max.x = child.GetAsOrDefault("x", -1);
                max.y = child.GetAsOrDefault("y", -1);
                max.z = child.GetAsOrDefault("z", -1);
            }
            int npcID = node.GetAsOrDefault("npcID", 0);

            return(CreateAreaJob(owner, min, max, npcID));
        }
Exemplo n.º 13
0
 public LootboxProperties(JSONNode jsonNode)
 {
     MinCount = jsonNode.GetAsOrDefault("MinCount", 0);
     MaxCount = jsonNode.GetAsOrDefault("MaxCount", 0);
     SetRespawnDelayMinutes(jsonNode.GetAsOrDefault("MinRespawnDelayMinutes", Lootbox.DefaultLootboxMinRespawnDelay), jsonNode.GetAsOrDefault("MaxRespawnDelayMinutes", Lootbox.DefaultLootboxMaxRespawnDelay));
 }
Exemplo n.º 14
0
 public override ITrackableBlock InitializeFromJSON(Players.Player player, JSONNode node)
 {
     storedItems = node.GetAsOrDefault("storedItems", 0);
     InitializeJob(player, (Vector3Int)node["position"], node.GetAs <int>("npcID"));
     return(this);
 }
Exemplo n.º 15
0
 public override ITrackableBlock InitializeFromJSON(Players.Player player, JSONNode node)
 {
     blockType = ItemTypes.IndexLookup.GetIndex(node.GetAsOrDefault("type", "air"));
     InitializeJob(player, (Vector3Int)node["position"], node.GetAs <int>("npcID"));
     return(this);
 }
Exemplo n.º 16
0
        public void SetConstructionType(string type, JSONNode args = null)
        {
            switch (type)
            {
            case "pipliz.digger":
                SetConstructionType(new Types.DiggerBasic());
                SetIterationType(new Iterators.TopToBottom(this));
                break;

            case "pipliz.builder":
                if (args != null)
                {
                    ItemTypes.ItemType buildType = ItemTypes.GetType(ItemTypes.IndexLookup.GetIndex(args.GetAsOrDefault("builderBlockType", "air")));
                    if (buildType != null && buildType.ItemIndex != 0)
                    {
                        SetConstructionType(new Types.BuilderBasic(buildType));
                        SetIterationType(new Iterators.BottomToTop(this));
                    }
                }
                break;

            default:
                Log.WriteWarning("Unexpected construction type: {0}", type);
                break;
            }
        }