Example #1
0
        public void CMD_CreateFactory(Client player, ProductType type)
        {
            if (API.getPlayerAclGroup(player) != "Admin")
            {
                player.sendChatMessage("~r~ERROR: ~w~Only admins can use this command.");
                return;
            }

            // generate id
            Guid factoryID;

            do
            {
                factoryID = Guid.NewGuid();
            } while (Main.Factories.FirstOrDefault(f => f.ID == factoryID) != null);

            // create factory & save
            Factory newFactory = new Factory(factoryID, player.position, type);

            Main.Factories.Add(newFactory);

            newFactory.CreateEntities();
            newFactory.Save();
        }
Example #2
0
        public void CMD_SetFactoryStock(Client player, int newStock)
        {
            if (API.getPlayerAclGroup(player) != "Admin")
            {
                player.sendChatMessage("~r~ERROR: ~w~Only admins can use this command.");
                return;
            }

            if (!player.hasData("Courier_MarkerID"))
            {
                return;
            }

            Factory factory = Main.Factories.FirstOrDefault(f => f.ID == player.getData("Courier_MarkerID"));

            if (factory == null)
            {
                player.sendChatMessage("~r~ERROR: ~w~You're not in a factory's marker.");
                return;
            }

            factory.Stock = newStock;
            factory.Save(true);
        }
Example #3
0
        public void Courier_EventTrigger(Client player, string eventName, params object[] args)
        {
            switch (eventName)
            {
            case "Courier_RequestVehicleProducts":
            {
                if (args.Length < 1)
                {
                    return;
                }

                NetHandle vehHandle = (NetHandle)args[0];
                Vehicle   vehicle   = API.getEntityFromHandle <Vehicle>(vehHandle);
                if (vehicle == null)
                {
                    player.sendErrorMessage("Invalid vehicle.");
                    return;
                }

                player.triggerEvent("Courier_ReceiveVehicleProducts", API.toJson(vehicle.getLoadedProducts()));
                break;
            }

            case "Courier_LoadToVehicle":
            {
                if (args.Length < 2)
                {
                    return;
                }

                if (!player.isCarrying())
                {
                    player.sendErrorMessage("You're not carrying a product.");
                    return;
                }

                NetHandle vehHandle = (NetHandle)args[0];
                Vehicle   vehicle   = API.getEntityFromHandle <Vehicle>(vehHandle);
                if (vehicle == null)
                {
                    player.sendErrorMessage("Invalid vehicle.");
                    return;
                }

                if (player.position.DistanceTo(vehicle.position) > 5f)
                {
                    player.sendErrorMessage("Vehicle is too far away.");
                    return;
                }

                int idx = Convert.ToInt32(args[1]);
                if (vehicle.loadProduct(idx, player.getCarryingType(), (NetHandle?)player.getData("Courier_BoxHandle")))
                {
                    player.stopCarrying(false);
                }
                else
                {
                    player.sendErrorMessage("Couldn't load your product to the vehicle.");
                }

                break;
            }

            case "Courier_TakeFromVehicle":
            {
                if (args.Length < 2)
                {
                    return;
                }

                if (player.isCarrying())
                {
                    player.sendErrorMessage("You're already carrying a product.");
                    return;
                }

                NetHandle vehHandle = (NetHandle)args[0];
                Vehicle   vehicle   = API.getEntityFromHandle <Vehicle>(vehHandle);
                if (vehicle == null)
                {
                    player.sendErrorMessage("Invalid vehicle.");
                    return;
                }

                if (player.position.DistanceTo(vehicle.position) > 5f)
                {
                    player.sendErrorMessage("Vehicle is too far away.");
                    return;
                }

                int idx = Convert.ToInt32(args[1]);
                if (!vehicle.unloadProduct(player, idx))
                {
                    player.sendErrorMessage("Couldn't take the product from the vehicle.");
                    return;
                }

                break;
            }

            case "Courier_Drop":
            {
                if (args.Length < 1)
                {
                    return;
                }

                if (!player.isCarrying())
                {
                    player.sendErrorMessage("You're not carrying a product.");
                    return;
                }

                Vector3 position = (Vector3)args[0];
                if (player.position.DistanceTo(position) >= 5)
                {
                    player.sendErrorMessage("You can't drop your product.");
                    return;
                }

                DroppedProduct.Add(new WorldProduct(player.getCarryingType(), (NetHandle?)player.getData("Courier_BoxHandle"), position, player.rotation));
                player.stopCarrying(false);
                break;
            }

            case "Courier_Take":
            {
                if (args.Length < 1)
                {
                    return;
                }

                if (player.isCarrying())
                {
                    player.sendErrorMessage("You already have a product.");
                    return;
                }

                Guid         productID = new Guid(args[0].ToString());
                WorldProduct product   = DroppedProduct.FirstOrDefault(p => p.ID == productID);
                if (product == null)
                {
                    player.sendErrorMessage("Invalid product.");
                    return;
                }

                product.DeleteEntities(false);
                product.Object.resetSyncedData("Courier_DetectorID");
                player.startCarrying(product.Type, product.Object.handle);
                DroppedProduct.Remove(product);
                break;
            }

            case "Courier_FactoryBuy":
            {
                if (player.isCarrying())
                {
                    player.sendErrorMessage("You already have a product.");
                    return;
                }

                if (!player.hasData("Courier_MarkerID"))
                {
                    player.sendErrorMessage("You're not in a factory's marker.");
                    return;
                }

                Factory factory = Methods.GetFactory(player.getData("Courier_MarkerID"));
                if (factory == null)
                {
                    player.sendErrorMessage("Invalid factory.");
                    return;
                }

                if (API.exported.MoneyAPI.GetMoney(player) < ProductDefinitions.Products[factory.Type].Price)
                {
                    player.sendErrorMessage("You can't afford this product.");
                    return;
                }

                if (factory.Stock < 1)
                {
                    player.sendErrorMessage("This factory has no product left.");
                    return;
                }

                API.exported.MoneyAPI.ChangeMoney(player, -ProductDefinitions.Products[factory.Type].Price);
                player.startCarrying(factory.Type);

                factory.Stock--;
                factory.Save();
                break;
            }

            case "Courier_FactoryRefund":
            {
                if (!player.isCarrying())
                {
                    player.sendErrorMessage("You're not carrying a product.");
                    return;
                }

                if (!player.hasData("Courier_MarkerID"))
                {
                    player.sendErrorMessage("You're not in a factory's marker.");
                    return;
                }

                Factory factory = Methods.GetFactory(player.getData("Courier_MarkerID"));
                if (factory == null)
                {
                    player.sendErrorMessage("Invalid factory.");
                    return;
                }

                if (factory.Type != player.getCarryingType())
                {
                    player.sendErrorMessage("This factory doesn't refund the product you have.");
                    return;
                }

                API.exported.MoneyAPI.ChangeMoney(player, ProductDefinitions.Products[factory.Type].Price);
                player.stopCarrying();

                factory.Stock++;
                factory.Save();
                break;
            }

            case "Courier_BuyerSell":
            {
                if (!player.isCarrying())
                {
                    player.sendErrorMessage("You're not carrying a product!");
                    return;
                }

                if (!player.hasData("Courier_MarkerID"))
                {
                    player.sendErrorMessage("You're not in a buyer's marker.");
                    return;
                }

                Buyer buyer = Methods.GetBuyer(player.getData("Courier_MarkerID"));
                if (buyer == null)
                {
                    player.sendErrorMessage("Invalid buyer.");
                    return;
                }

                if (buyer.Type != player.getCarryingType())
                {
                    player.sendErrorMessage("This buyer doesn't buy the product you're selling.");
                    return;
                }

                if ((buyer.Stock + 1) > buyer.MaxStock)
                {
                    player.sendErrorMessage("This buyer can't accept any more product.");
                    return;
                }

                API.exported.MoneyAPI.ChangeMoney(player, Methods.GetFinalPrice(player.getCarryingType()));
                player.stopCarrying();

                buyer.Stock++;
                buyer.Save();
                break;
            }
            }
        }