Пример #1
0
        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);
        }
Пример #2
0
        public static void OpenMenu(Players.Player player, PlayerClickedData playerClickData)
        {
            if (ItemTypes.IndexLookup.TryGetIndex(SchematicTool.NAME, out var schematicItem) &&
                playerClickData.TypeSelected == schematicItem)
            {
                if (player.ActiveColony == null)
                {
                    PandaChat.Send(player, _localizationHelper, "ErrorOpening", ChatColor.red);
                    return;
                }

                if (!_awaitingClick.ContainsKey(player))
                {
                    SendMainMenu(player);
                }
                else
                {
                    var tuple = _awaitingClick[player];
                    _awaitingClick.Remove(player);

                    switch (tuple.Item1)
                    {
                    case SchematicClickType.Build:
                        Vector3Int location = playerClickData.GetVoxelHit().BlockHit.Add(0, 1, 0);
                        var        args     = new JSONNode();
                        args.SetAs("constructionType", GameLoader.NAMESPACE + ".SchematicBuilder");
                        args.SetAs(SchematicBuilderLoader.NAME + ".SchematicName", tuple.Item2);
                        args.SetAs(SchematicBuilderLoader.NAME + ".Rotation", tuple.Item3);

                        if (SchematicReader.TryGetSchematic(tuple.Item2, player.ActiveColony.ColonyID, location, out var schematic))
                        {
                            if (tuple.Item3 >= Schematic.Rotation.Right)
                            {
                                schematic.Rotate();
                            }

                            if (tuple.Item3 >= Schematic.Rotation.Back)
                            {
                                schematic.Rotate();
                            }

                            if (tuple.Item3 >= Schematic.Rotation.Left)
                            {
                                schematic.Rotate();
                            }

                            var maxSize = location.Add(schematic.XMax - 1, schematic.YMax - 1, schematic.ZMax - 1);
                            AreaJobTracker.CreateNewAreaJob("pipliz.constructionarea", args, player.ActiveColony, location, maxSize);
                            AreaJobTracker.SendData(player);
                        }

                        break;

                    case SchematicClickType.Archetect:

                        break;
                    }
                }
            }
        }
Пример #3
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
        {
            if (userData.TypeNew == ItemTypes.IndexLookup.GetIndex("Ulfric.ColonyAddOns.Blocks.AppleBasket") && userData.TypeOld == BuiltinBlocks.Air)
            {
                Logger.Log("Check if area is clear for AppleFarmer");
                Vector3Int position = userData.Position;
                int        xlen     = 7;
                int        zlen     = 7;
                int        radius   = 3;

                //set NW corner
                Vector3Int nwcorner = new Vector3Int(position.x - radius, position.y, position.z - radius);
                Vector3Int secorner = new Vector3Int(position.x + radius, position.y, position.z + radius);

                bool blocked = false;
                for (int x = 0; x <= xlen; x++)
                {
                    for (int z = 0; z <= zlen; z++)
                    {
                        if (World.TryGetTypeAt(nwcorner.Add(x, 0, z), out ushort val) && val != BuiltinBlocks.Air)
                        {
                            blocked = true;
                        }
                    }
                }

                if (blocked)
                {
                    Chat.Send(userData.RequestedByPlayer, "Apple Farmer 9 x 9 area is blocked.");
                }
                else
                {
                    AreaJobTracker.CreateNewAreaJob("Ulfric.ColonyAddOns.AreaJobs.AppleFarm", userData.RequestedByPlayer, nwcorner, secorner);

                    ThreadManager.InvokeOnMainThread(delegate()
                    {
                        ServerManager.TryChangeBlock(position, userData.TypeNew);
                    }, 0.1f);
                }
            }
            if (userData.TypeOld == ItemTypes.IndexLookup.GetIndex("Ulfric.ColonyAddOns.Blocks.AppleBasket") && userData.TypeNew == BuiltinBlocks.Air)
            {
                Logger.Log("Remove job");
                Vector3Int position = userData.Position;
                int        xlen     = 7;
                int        zlen     = 7;
                int        radius   = 3;

                //set NW corner
                Vector3Int nwcorner = new Vector3Int(position.x - radius, position.y, position.z - radius);
                Vector3Int secorner = new Vector3Int(position.x + radius, position.y, position.z + radius);
                AreaJobTracker.RemoveJobAt(nwcorner, secorner);
            }
        }