bool CreateFieldAndJob(Vector3Int center)
        {
            if (!IsClear(center.Add(-5, 0, -5), 11, 2, 11))
            {
                return(false);
            }
            var crateZ = -4 + Random.Next(10);

            BlockPlacementHelper.PlaceBlock(center.Add(-5, 0, crateZ), BuiltinBlocks.Crate, Owner);
            BlockPlacementHelper.PlaceBlock(center.Add(-5, 1, crateZ), BuiltinBlocks.TorchYP, Owner);
            var min = center.Add(-4, 0, -4);
            var max = center.Add(5, 0, 5);

            for (int x = min.x; x < max.x; x++)
            {
                for (int z = min.z; z < max.z; z++)
                {
                    bool solid;
                    if (!World.TryIsSolid(new Vector3Int(x, center.y - 1, z), out solid) || !solid)
                    {
                        return(false);
                    }
                }
            }
            AreaJobTracker.CreateNewAreaJob("pipliz.wheatfarm", Owner, min, max);
            return(true);
        }
        void CreateFarmHouse()
        {
            Vector3Int houseOrigin = FarmOrigin.Add(-3, 0, -2);

            BlockPlacementHelper.FillPlane(houseOrigin.Add(0, -1, 0), 7, 8, BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin, 1, 1, 8, BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(6, 0, 0), 1, 1, 8, BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(1, 0, 7), 5, 1, 1, BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(1, 0, 0), 2, 1, 1, BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(4, 0, 0), 2, 1, 1, BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(0, 1, 0), BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(6, 1, 0), BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(0, 1, 7), BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(6, 1, 7), BuiltinBlocks.StoneBricks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(0, 1, 1), BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(0, 1, 3), 1, 1, 2, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(0, 1, 6), BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(6, 1, 1), BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(6, 1, 3), 1, 1, 2, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(6, 1, 6), BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(1, 1, 7), BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(3, 1, 7), BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(5, 1, 7), BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(1, 1, 0), 2, 1, 1, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(1, 1, -1), BuiltinBlocks.TorchZP, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(4, 1, 0), 2, 1, 1, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.PlaceBlock(houseOrigin.Add(5, 1, -1), BuiltinBlocks.TorchZP, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(0, 2, 0), 1, 1, 8, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(6, 2, 0), 1, 1, 8, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(1, 2, 0), 5, 1, 1, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(1, 2, 7), 5, 1, 1, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(-1, 3, -1), 3, 1, 10, BuiltinBlocks.Straw, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(5, 3, -1), 3, 1, 10, BuiltinBlocks.Straw, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(2, 3, 0), 3, 1, 1, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(2, 3, 7), 3, 1, 1, BuiltinBlocks.Planks, Owner);
            BlockPlacementHelper.FillArea(houseOrigin.Add(0, 4, -1), 7, 1, 10, BuiltinBlocks.Straw, Owner);
            List <Vector3Int> possibleBedSpots = new List <Vector3Int> ();

            for (int c = 0; c < 6; c++)
            {
                possibleBedSpots.Add(houseOrigin.Add(1, 0, 1 + c));
                possibleBedSpots.Add(houseOrigin.Add(4, 0, 1 + c));
                LootSpots.Add(houseOrigin.Add(1, 0, 1 + c));
                LootSpots.Add(houseOrigin.Add(5, 0, 1 + c));
            }
            PlaceBeds(possibleBedSpots);
        }
 void PlaceBeds(List <Vector3Int> possibleBedSpots)
 {
     for (int c = 0; c < FarmSize && possibleBedSpots.Count > 0; c++)
     {
         var spot        = Random.Next(possibleBedSpots.Count);
         var bedPosition = possibleBedSpots [spot];
         possibleBedSpots.RemoveAt(spot);
         var flipped = Random.NextBool();
         if (flipped)
         {
             BlockPlacementHelper.PlaceBlock(bedPosition.Add(1, 0, 0), BuiltinBlocks.BedXN, Owner);
         }
         else
         {
             BlockPlacementHelper.PlaceBlock(bedPosition, BuiltinBlocks.BedXP, Owner);
         }
     }
 }
Exemple #4
0
        void UpdateLoot()
        {
            var invocationDelay = Properties.MinRespawnDelayMinutes + Pipliz.Random.Next(Properties.MaxRespawnDelayMinutes - Properties.MinRespawnDelayMinutes);

            ThreadManager.InvokeOnMainThread(delegate {
                try {
                    if (Dead)
                    {
                        return;
                    }
                    var lootType = ItemTypes.IndexLookup.GetIndex(Lootbox.ITEMKEY);
                    foreach (var oldPlacedLoot in new List <Vector3Int> (PlacedLoot))
                    {
                        ushort actualType;
                        if (World.TryGetTypeAt(oldPlacedLoot, out actualType) && actualType != lootType)
                        {
                            PlacedLoot.Remove(oldPlacedLoot);
                        }
                    }
                    int spawnCount      = Properties.MinCount + Pipliz.Random.Next(Properties.MaxCount - Properties.MinCount - PlacedLoot.Count);
                    var player          = Players.GetPlayer(NetworkID);
                    var currentSpotList = new List <Vector3Int> (PossibleLootSpots);
                    for (int c = 0; c < spawnCount && currentSpotList.Count > 0;)
                    {
                        var spot     = Pipliz.Random.Next(currentSpotList.Count);
                        var position = currentSpotList [spot];
                        currentSpotList.RemoveAt(spot);
                        ushort actualType;
                        if (World.TryGetTypeAt(position, out actualType) && actualType == BuiltinBlocks.Air)
                        {
                            PlacedLoot.Add(position);
                            BlockPlacementHelper.PlaceBlock(position, lootType, player);
                            c++;
                            KingdomsTracker.SendLootboxNotification($"Unclaimed lootbox at {position}");
                        }
                    }
                } catch (Exception exception) {
                    Log.WriteError($"Exception while spawning loot; {exception.Message}");
                }
                UpdateLoot();
            }, invocationDelay * 60);
        }
 void CreatePaths()
 {
     BlockPlacementHelper.FillArea(FarmOrigin.Add(-1, -1, -6), 3, 1, 4, BuiltinBlocks.Dirt, Owner);
 }