Ejemplo n.º 1
0
        private void OnEntitySpawned(BaseNetworkable networkable)
        {
            if (networkable == null || !(networkable is MiniCopter))
            {
                return;
            }

            NextTick(() =>
            {
                MiniCopter copter = networkable as MiniCopter;
                if (copter != null)
                {
                    Item fuelItem = copter.GetFuelSystem().GetFuelItem();
                    if (fuelItem != null)
                    {
                        int wolfAmount = Mathf.FloorToInt((float)fuelItem.info.stackable * 0.2f);
                        if (wolfAmount == fuelItem.amount)
                        {
                            if (copter.PrefabName.Contains("vehicles/scrap heli carrier/scraptransporthelicopter"))
                            {
                                fuelItem.amount = _config.fuelAmountScrapTransportHelicopter;
                            }

                            if (copter.PrefabName.Contains("vehicles/minicopter/minicopter.entity"))
                            {
                                fuelItem.amount = _config.fuelAmountMiniCopter;
                            }
                        }
                    }
                }
            });
        }
Ejemplo n.º 2
0
        private void EnableUnlimitedFuel(MiniCopter minicopter)
        {
            var fuelSystem = minicopter.GetFuelSystem();

            fuelSystem.cachedHasFuel     = true;
            fuelSystem.nextFuelCheckTime = float.MaxValue;
            fuelSystem.GetFuelContainer().SetFlag(BaseEntity.Flags.Locked, true);
        }
Ejemplo n.º 3
0
        private void EnableUnlimitedFuel(MiniCopter minicopter)
        {
            minicopter.fuelPerSec = 0f;

            StorageContainer fuelContainer = minicopter.GetFuelSystem().GetFuelContainer();

            fuelContainer.inventory.AddItem(fuelContainer.allowedItem, 1);
            fuelContainer.SetFlag(BaseEntity.Flags.Locked, true);
        }
Ejemplo n.º 4
0
        private void SpawnMinicopter(string id)
        {
            // Use find incase they put their username
            BasePlayer player = BasePlayer.Find(id);

            if (player == null)
            {
                return;
            }

            if (_data.playerMini.ContainsKey(player.UserIDString))
            {
                player.ChatMessage(lang.GetMessage("mini_current", this, player.UserIDString));
                return;
            }

            // Credit Original MyMinicopter Plugin
            Quaternion rotation = player.GetNetworkRotation();
            Vector3    forward  = rotation * Vector3.forward;
            Vector3    straight = Vector3.Cross(Vector3.Cross(Vector3.up, forward), Vector3.up).normalized;
            Vector3    position = player.transform.position + straight * 5f;

            position.y = player.transform.position.y + 2f;

            if (position == null)
            {
                return;
            }
            BaseVehicle vehicleMini = (BaseVehicle)GameManager.server.CreateEntity(_config.assetPrefab, position, new Quaternion());

            if (vehicleMini == null)
            {
                return;
            }
            vehicleMini.OwnerID = player.userID;
            vehicleMini.Spawn();
            // End

            _data.playerMini.Add(player.UserIDString, vehicleMini.net.ID);

            if (permission.UserHasPermission(player.UserIDString, _noFuel))
            {
                MiniCopter minicopter = vehicleMini as MiniCopter;

                if (minicopter == null)
                {
                    return;
                }

                minicopter.fuelPerSec = 0f;

                StorageContainer fuelContainer = minicopter.GetFuelSystem().GetFuelContainer();
                ItemManager.CreateByItemID(-946369541, 1)?.MoveToContainer(fuelContainer.inventory);
                fuelContainer.SetFlag(BaseEntity.Flags.Locked, true);
            }
        }
Ejemplo n.º 5
0
        private void AddInitialFuel(MiniCopter minicopter)
        {
            if (_config.fuelAmount == 0)
            {
                return;
            }

            StorageContainer fuelContainer = minicopter.GetFuelSystem().GetFuelContainer();
            int fuelAmount = _config.fuelAmount < 0 ? fuelContainer.allowedItem.stackable : _config.fuelAmount;

            fuelContainer.inventory.AddItem(fuelContainer.allowedItem, fuelAmount);
        }
Ejemplo n.º 6
0
        private void AddInitialFuel(MiniCopter minicopter, string userId)
        {
            var fuelAmount = GetPlayerAllowedFuel(userId);

            if (fuelAmount == 0)
            {
                return;
            }

            StorageContainer fuelContainer = minicopter.GetFuelSystem().GetFuelContainer();

            if (fuelAmount < 0)
            {
                // Value of -1 is documented to represent max stack size
                fuelAmount = fuelContainer.allowedItem.stackable;
            }
            fuelContainer.inventory.AddItem(fuelContainer.allowedItem, fuelAmount);
        }
Ejemplo n.º 7
0
        // Credit to WhiteThunder- https://github.com/AnExiledDev/StackSizeController/pull/7
        // Fix initial fuel amount for vendor-spawned helis since they use 20% of max stack size of low grade.
        private void OnEntitySpawned(MiniCopter heli)
        {
            // Ignore if a known plugin is loaded that adjusts heli fuel.
            if (AirFuel != null || GetToDaChoppa != null || VehicleVendorOptions != null)
            {
                return;
            }

            // Must delay for vendor-spawned helis since the creatorEntity is set after spawn.
            NextTick(() =>
            {
                if (heli == null
                    // Make sure it's a vendor-spawned heli.
                    || !heli.IsSafe()
                    // Make sure the game hasn't changed unexpectedly.
                    || heli.StartingFuelUnits() != -1)
                {
                    return;
                }

                var fuelItem = heli.GetFuelSystem()?.GetFuelItem();
                if (fuelItem == null
                    // Ignore other types of fuel since they will have been placed by mods.
                    || fuelItem.info.shortname != "lowgradefuel"
                    // Ignore if the fuel amount is unexpected, since a mod likely adjusted it.
                    || fuelItem.amount != fuelItem.info.stackable / 5)
                {
                    return;
                }

                var hookResult = Interface.CallHook("OnVendorHeliFuelAdjust", heli);
                if (hookResult is bool && (bool)hookResult == false)
                {
                    return;
                }

                fuelItem.amount = 100;
                fuelItem.MarkDirty();
            });
        }
Ejemplo n.º 8
0
        // Spawn hook
        private void SpawnMyMinicopter(BasePlayer player)
        {
            if (player.IsBuildingBlocked() & !allowWhenBlocked)
            {
                PrintMsgL(player, "BlockedMsg");
                return;
            }

            Quaternion rotation = player.GetNetworkRotation();
            Vector3    forward  = rotation * Vector3.forward;
            // Make straight perpendicular to up axis so we don't spawn into ground or above player's head.
            Vector3 straight = Vector3.Cross(Vector3.Cross(Vector3.up, forward), Vector3.up).normalized;
            Vector3 position = player.transform.position + straight * 5f;

            position.y = player.transform.position.y + 2.5f;

            if (position == null)
            {
                return;
            }
            BaseVehicle vehicleMini = (BaseVehicle)GameManager.server.CreateEntity(prefab, position, new Quaternion());

            if (vehicleMini == null)
            {
                return;
            }
            BaseEntity miniEntity = vehicleMini as BaseEntity;

            miniEntity.OwnerID = player.userID;

            MiniCopter miniCopter = vehicleMini as MiniCopter;

            vehicleMini.Spawn();

            if (permission.UserHasPermission(player.UserIDString, MinicopterUnlimited))
            {
                // Set fuel requirements to 0
                miniCopter.fuelPerSec = 0f;
                if (!allowFuelIfUnlimited)
                {
                    // If the player is not allowed to use the fuel container, add 1 fuel so the copter will start.
                    // Also lock fuel container since there is no point in adding/removing fuel
                    var x = miniCopter.GetFuelSystem();
                    StorageContainer fuelCan = miniCopter.GetFuelSystem().GetFuelContainer();
                    ItemManager.CreateByItemID(-946369541, 1)?.MoveToContainer(fuelCan.inventory);
                    fuelCan.SetFlag(BaseEntity.Flags.Locked, true);
                }
            }
            else
            {
                miniCopter.fuelPerSec = stdFuelConsumption;
            }

            PrintMsgL(player, "SpawnedMsg");
            uint minicopteruint = vehicleMini.net.ID;

#if DEBUG
            Puts($"SPAWNED MINICOPTER {minicopteruint.ToString()} for player {player.displayName} OWNER {miniEntity.OwnerID}");
#endif
            storedData.playerminiID.Remove(player.userID);
            var myKey = currentMounts.FirstOrDefault(x => x.Value == player.userID).Key;
            currentMounts.Remove(myKey);
            storedData.playerminiID.Add(player.userID, minicopteruint);
            SaveData();

            miniEntity = null;
            miniCopter = null;
        }
Ejemplo n.º 9
0
        private void SpawnMinicopter(BasePlayer player)
        {
            if (!player.IsBuildingBlocked() || _config.canSpawnBuildingBlocked)
            {
                RaycastHit hit;
                if (Physics.Raycast(player.eyes.HeadRay(), out hit, Mathf.Infinity,
                                    LayerMask.GetMask("Construction", "Default", "Deployed", "Resource", "Terrain", "Water", "World")))
                {
                    if (hit.distance > _config.maxSpawnDistance)
                    {
                        player.ChatMessage(lang.GetMessage("mini_sdistance", this, player.UserIDString));
                    }
                    else
                    {
                        Vector3     position   = hit.point + Vector3.up * 2f;
                        BaseVehicle miniEntity = (BaseVehicle)GameManager.server.CreateEntity(_config.assetPrefab, position, new Quaternion());
                        miniEntity.OwnerID = player.userID;
                        miniEntity.health  = _config.spawnHealth;
                        miniEntity.Spawn();

                        // Credit Original MyMinicopter Plugin
                        if (permission.UserHasPermission(player.UserIDString, _noFuel))
                        {
                            MiniCopter minicopter = miniEntity as MiniCopter;

                            if (minicopter == null)
                            {
                                return;
                            }

                            minicopter.fuelPerSec = 0f;

                            StorageContainer fuelContainer = minicopter.GetFuelSystem().GetFuelContainer();
                            ItemManager.CreateByItemID(-946369541, 1)?.MoveToContainer(fuelContainer.inventory);
                            fuelContainer.SetFlag(BaseEntity.Flags.Locked, true);
                        }

                        _data.playerMini.Add(player.UserIDString, miniEntity.net.ID);

                        if (!permission.UserHasPermission(player.UserIDString, _noCooldown))
                        {
                            // Sloppy but works
                            // TODO: Improve later
                            Dictionary <string, float> perms = new Dictionary <string, float>();
                            foreach (var perm in _config.cooldowns)
                            {
                                if (permission.UserHasPermission(player.UserIDString, perm.Key))
                                {
                                    perms.Add(perm.Key, perm.Value);
                                }
                            }

                            if (!perms.IsEmpty())
                            {
                                _data.cooldown.Add(player.UserIDString, DateTime.Now.AddSeconds(perms.Aggregate((l, r) => l.Value < r.Value ? l : r).Value));
                            }

                            // Incase players don't have any cooldown permission default to one day
                            if (!_data.cooldown.ContainsKey(player.UserIDString))
                            {
                                _data.cooldown.Add(player.UserIDString, DateTime.Now.AddDays(1));
                            }
                        }
                    }
                }
                else
                {
                    player.ChatMessage(lang.GetMessage("mini_terrain", this, player.UserIDString));
                }
            }
            else
            {
                player.ChatMessage(lang.GetMessage("mini_priv", this, player.UserIDString));
            }
        }