Ejemplo n.º 1
0
        public override void OnBlockPlaced(ItemStack byItemStack = null)
        {
            base.OnBlockPlaced(byItemStack);

            // min(1, 1.5 - x/40)
            // http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJtaW4oMSwxLjUteC80MCkiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjEwMDAsIndpbmRvdyI6WyIwIiwiMTIwIiwiMCIsIjEuNSJdfV0-
            float corrupLocustNestChance = Math.Min(1, 1.5f - (float)Pos.Y / (0.36f * Api.World.SeaLevel));

            string entityCode = "locust-bronze";


            if (Api.World.Rand.NextDouble() < corrupLocustNestChance)
            {
                entityCode = "locust-corrupt";
            }

            Data = new BESpawnerData()
            {
                EntityCodes          = new string[] { entityCode },
                InGameHourInterval   = 0.1f + 0.9f * (float)Api.World.Rand.NextDouble(),
                MaxCount             = Api.World.Rand.Next(7) + 3,
                SpawnArea            = new Cuboidi(-5, -5, -5, 5, 2, 5),
                GroupSize            = 2 + Api.World.Rand.Next(4),
                SpawnOnlyAfterImport = false,
                InitialSpawnQuantity = 4 + Api.World.Rand.Next(7),
                MinPlayerRange       = 36
            };
        }
Ejemplo n.º 2
0
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve)
        {
            base.FromTreeAttributes(tree, worldAccessForResolve);

            Data = new BESpawnerData()
            {
                EntityCodes        = (tree["entityCodes"] as StringArrayAttribute)?.value,
                MaxCount           = tree.GetInt("maxCount"),
                InGameHourInterval = tree.GetFloat("intervalHours"),
                SpawnArea          = new Cuboidi(
                    tree.GetInt("x1"), tree.GetInt("y1"), tree.GetInt("z1"),
                    tree.GetInt("x2"), tree.GetInt("y2"), tree.GetInt("z2")
                    ),
                RemoveAfterSpawnCount  = tree.GetInt("spawnCount"),
                SpawnOnlyAfterImport   = tree.GetBool("spawnOnlyAfterImport"),
                GroupSize              = tree.GetInt("groupSize"),
                InitialQuantitySpawned = tree.GetInt("initialQuantitySpawned"),
                InitialSpawnQuantity   = tree.GetInt("initialSpawnQuantity"),
                WasImported            = tree.GetBool("wasImported"),
            };

            long[] values = (tree["spawnedEntities"] as LongArrayAttribute)?.value;

            lastSpawnTotalHours = tree.GetDecimal("lastSpawnTotalHours");

            this.spawnedEntities = new List <long>(values == null ? new long[0] : values);
        }
Ejemplo n.º 3
0
        public void UpdateFromServer(BESpawnerData data)
        {
            updating         = true;
            this.spawnerData = data;
            SingleComposer.GetNumberInput("x1").SetValue(data.SpawnArea.X1);
            SingleComposer.GetNumberInput("y1").SetValue(data.SpawnArea.Y1);
            SingleComposer.GetNumberInput("z1").SetValue(data.SpawnArea.Z1);
            SingleComposer.GetNumberInput("x2").SetValue(data.SpawnArea.X2);
            SingleComposer.GetNumberInput("y2").SetValue(data.SpawnArea.Y2);
            SingleComposer.GetNumberInput("z2").SetValue(data.SpawnArea.Z2);
            SingleComposer.GetNumberInput("maxentities").SetValue(data.MaxCount);
            SingleComposer.GetNumberInput("spawncount").SetValue(data.RemoveAfterSpawnCount);

            SingleComposer.GetSwitch("primerSwitch").SetValue(data.SpawnOnlyAfterImport);

            SingleComposer.GetNumberInput("interval").SetValue(data.InGameHourInterval);
            SingleComposer.GetDropDown("entityCode").SetSelectedValue(data.EntityCodes);

            if (spawnerData.EntityCodes == null)
            {
                codes = new HashSet <string>();
            }
            else
            {
                codes = new HashSet <string>(spawnerData.EntityCodes);
            }


            capi.World.HighlightBlocks(capi.World.Player, (int)EnumHighlightSlot.Spawner, new List <BlockPos>()
            {
                spawnerData.SpawnArea.Start.AsBlockPos.Add(blockEntityPos), spawnerData.SpawnArea.End.AsBlockPos.Add(blockEntityPos)
            }, EnumHighlightBlocksMode.Absolute, API.Common.EnumHighlightShape.Cube);

            updating = false;
        }
Ejemplo n.º 4
0
 public override void OnReceivedClientPacket(IPlayer fromPlayer, int packetid, byte[] bytes)
 {
     if (packetid == 1001)
     {
         Data = SerializerUtil.Deserialize <BESpawnerData>(bytes);
         MarkDirty();
     }
 }
Ejemplo n.º 5
0
 public override void OnReceivedServerPacket(int packetid, byte[] bytes)
 {
     if (packetid == 1000)
     {
         Data = SerializerUtil.Deserialize <BESpawnerData>(bytes);
         if (dlg?.IsOpened() == true)
         {
             dlg.UpdateFromServer(Data);
         }
     }
 }
Ejemplo n.º 6
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            ItemStack stack = base.OnPickBlock(world, pos);

            BESpawnerData spawnerdata = (world.BlockAccessor.GetBlockEntity(pos) as BlockEntitySpawner)?.Data;

            if (spawnerdata != null)
            {
                stack.Attributes.SetBytes("spawnerData", SerializerUtil.Serialize(spawnerdata));
            }

            return(stack);
        }
Ejemplo n.º 7
0
        public override void OnBlockPlaced(ItemStack byItemStack = null)
        {
            base.OnBlockPlaced(byItemStack);

            Data = new BESpawnerData()
            {
                EntityCodes          = new string[] { "locust" },
                InGameHourInterval   = 1,
                MaxCount             = api.World.Rand.Next(9) + 5,
                SpawnArea            = new Cuboidi(-5, -5, -5, 5, 0, 5),
                GroupSize            = 2 + api.World.Rand.Next(2),
                SpawnOnlyAfterImport = false,
                InitialSpawnQuantity = 6 + api.World.Rand.Next(13)
            };
        }
Ejemplo n.º 8
0
        public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve)
        {
            base.FromTreeAtributes(tree, worldAccessForResolve);

            data = new BESpawnerData()
            {
                EntityCode         = tree.GetString("entityCode"),
                MaxCount           = tree.GetInt("maxCount"),
                InGameHourInterval = tree.GetFloat("intervalHours"),
                SpawnArea          = new Cuboidi(
                    tree.GetInt("x1"), tree.GetInt("y1"), tree.GetInt("z1"),
                    tree.GetInt("x2"), tree.GetInt("y2"), tree.GetInt("z2")
                    )
            };

            long[] values = (tree["spawnedEntities"] as LongArrayAttribute)?.value;

            this.spawnedEntities = new List <long>(values == null ? new long[0] : values);
        }
Ejemplo n.º 9
0
        public void UpdateFromServer(BESpawnerData data)
        {
            updating         = true;
            this.spawnerData = data;
            SingleComposer.GetNumberInput("x1").SetValue(data.SpawnArea.X1);
            SingleComposer.GetNumberInput("y1").SetValue(data.SpawnArea.Y1);
            SingleComposer.GetNumberInput("z1").SetValue(data.SpawnArea.Z1);
            SingleComposer.GetNumberInput("x2").SetValue(data.SpawnArea.X2);
            SingleComposer.GetNumberInput("y2").SetValue(data.SpawnArea.Y2);
            SingleComposer.GetNumberInput("z2").SetValue(data.SpawnArea.Z2);
            SingleComposer.GetNumberInput("maxentities").SetValue(data.MaxCount);
            SingleComposer.GetNumberInput("interval").SetValue(data.InGameHourInterval);
            SingleComposer.GetDropDown("entityCode").SetSelectedValue(data.EntityCode);

            capi.World.HighlightBlocks(capi.World.Player, new List <BlockPos>()
            {
                spawnerData.SpawnArea.Start.AsBlockPos.Add(blockEntityPos), spawnerData.SpawnArea.End.AsBlockPos.Add(blockEntityPos)
            }, EnumHighlightBlocksMode.Absolute, API.Common.EnumHighlightShape.Cube);
            updating = false;
        }
Ejemplo n.º 10
0
        public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            byte[] data = inSlot.Itemstack.Attributes.GetBytes("spawnerData", null);
            if (data != null)
            {
                try
                {
                    BESpawnerData spawnderdata = SerializerUtil.Deserialize <BESpawnerData>(data);
                    if (spawnderdata.EntityCodes == null)
                    {
                        dsc.AppendLine("Spawns: Nothing");
                    }
                    else
                    {
                        string names = "";
                        foreach (var val in spawnderdata.EntityCodes)
                        {
                            if (names.Length > 0)
                            {
                                names += ", ";
                            }
                            names += Lang.Get("item-creature-" + val);
                        }

                        dsc.AppendLine("Spawns: " + names);
                    }

                    dsc.AppendLine("Area: " + spawnderdata.SpawnArea);
                    dsc.AppendLine("Interval: " + spawnderdata.InGameHourInterval);
                    dsc.AppendLine("Max count: " + spawnderdata.MaxCount);
                }
                catch { }
            }

            base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);
        }
Ejemplo n.º 11
0
        public override void OnBlockPlaced(ItemStack byItemStack = null)
        {
            base.OnBlockPlaced(byItemStack);

            lastSpawnTotalHours = Api.World.Calendar.TotalHours;

            if (byItemStack == null)
            {
                return;
            }
            byte[] data = byItemStack.Attributes.GetBytes("spawnerData", null);
            if (data == null)
            {
                return;
            }

            try
            {
                this.Data = SerializerUtil.Deserialize <BESpawnerData>(data);
            }
            catch {
                this.Data = new BESpawnerData().initDefaults();
            }
        }