Иконка ресурса

FREE PooBot : 1.1.1 1.1.1

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Linq;
using Oxide.Core;
using Oxide.Core.Configuration;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using Facepunch;
using Rust;
using Oxide.Game.Rust.Cui;


namespace Oxide.Plugins
{
    [Info("PooBot", "Colon Blow", "1.1.1")]
    [Description("This plugin was fixed by Инкуб to order [Rust Plugin Sliv]: https://discord.gg/pFgKw6Dyyq")]
    class PooBot : RustPlugin
    {

        //fix for entity movement jerks
        //fixed rocket speed
        //fixed rockets working
        //changed looks to prevent culling of parts as much as possible

        #region Load

        BaseEntity robotEntity;

        void Loaded()
        {
            LoadVariables();
            permission.RegisterPermission("poobot.spawn", this);
            permission.RegisterPermission("poobot.craft", this);
            permission.RegisterPermission("poobot.repack", this);
            data = Interface.Oxide.DataFileSystem.GetFile("poobot_data");
        }

        #endregion

        #region Configuration

        static bool AllowNormalDamage = false;
        static bool AllowPlayerDamage = false;
        static bool DoKnockbackEffect = true;
        static bool AllowResourceGather = true;
        static bool RequireFuel = false;
        static bool AllowRepackLowHealth = false;
        static bool AllowRepackUnderCooldown = false;

        static int FuelUsagePerTick = 5;
        static float FuelTickRate = 60;
        static int FuelItemID = -946369541;

        static int WoodGatherAmount = 100;
        static int WoodGatherCycles = 5;

        static int OreGatherAmount = 100;
        static int OreGatherCycles = 5;

        static int CraftItemAmount = 10000;
        static int CraftItemID = 69511070;

        static float RepairAmountPerHit = 1000f;
        static int RepairItemAmountNeeded = 100;
        static int RepairItemID = 69511070;

        static float RobotStartHealth = 10000f;
        static float MinRepairHealth = 2000f;

        static float PunchDamageRadius = 1.3f;
        static float RocketReuseTime = 120f;
        static float DamageToNonRobots = 50f;
        static float DamageToRobots = 500f;
        static float ConditionLossByHittingRobots = 10f;
        static float ConditionLossByHittingNonRobots = 50f;

        static bool EnabledNonRobotConditionLoss = false;
        static bool EnableRobotConditionLoss = false;

        static int KnockdownChance = 5;

        string messagetxt1 = "You Cannot repack Robot when Health is not Full";
        string messagetxt2 = "You Cannot repack Robot if weapons cooldown is active";
        string messagetxt3 = "Repacking robot puts it back in your inventory as a item";
        string messagetxt4 = "Press your RELOAD key with arm extended to Fire Weapons";
        string messagetxt5 = "Spar Mode allows you to practice fighting a robot by yourself";
        string messagetxt6 = "Jump out of seat to dismount Robot";
        string messagetxt7 = "Damage to player is redirected to Robot when seated in Robot";
        string messagetxt8 = "Robots can gather wood and ore if enabled by admin";
        string messagetxt9 = "Robots can attack players, npcs, buildings, etc...if enabled by admin";
        string messagetxt10 = "Hitting robot with hammer and proper materials will repair robot";

        bool Changed;

        void LoadVariables()
        {
            LoadConfigVariables();
            SaveConfig();
        }

        void LoadDefaultConfig()
        {
            Puts("Creating a new config file");
            Config.Clear();
            LoadVariables();
        }

        void LoadConfigVariables()
        {

            CheckCfg("Global - Damage - Allow Robot to damage players/buildings ? ", ref AllowNormalDamage);
            CheckCfg("Global - Damage - Allow Player to damage players/buildings while operating Poobot (weapons on player)? ", ref AllowPlayerDamage);
            CheckCfg("Global - Do Knockback effects when robots hit each other ", ref DoKnockbackEffect);
            CheckCfg("Global - Allow Robot to gather resources from Tree/Ore ", ref AllowResourceGather);
            CheckCfg("Global - Require Fuel to run Robot ?", ref RequireFuel);
            CheckCfg("Global - Allow Robot Repack if Robot Health is not 100% ", ref AllowRepackLowHealth);
            CheckCfg("Global - Allow Robot Repack if Robot is under Weapons reload Cooldown ", ref AllowRepackUnderCooldown);

            CheckCfg("Fuel - Item ID of Fuel needed to run Robot ", ref FuelItemID);
            CheckCfg("Fuel - Amount of fuel needed per tick to run Robot ", ref FuelUsagePerTick);
            CheckCfgFloat("Fuel - Seconds between fuel ticks ", ref FuelTickRate);

            CheckCfg("Global - Enable Condition Loss when hitting other Robots ? ", ref EnableRobotConditionLoss);
            CheckCfg("Global - Enable Condition Loss when hitting other Non Robots (players, buildings, ets..) ? ", ref EnabledNonRobotConditionLoss);

            CheckCfg("Gather - Wood - Amount gathered per cycle when hitting Trees ", ref WoodGatherAmount);
            CheckCfg("Gather - Ore - Amount gathered per cycle when hitting Ore nodes ", ref OreGatherAmount);
            CheckCfg("Gather - Wood - Number of cycles before Tree is empty ", ref WoodGatherCycles);
            CheckCfg("Global - Ore - Number of cycles before Ore nodes are empty ", ref OreGatherCycles);

            CheckCfgFloat("Health - Starting / Max Health of all Robots ", ref RobotStartHealth);
            CheckCfgFloat("Health - Minimum Health needed when repairing to stand robot back up ", ref MinRepairHealth);

            CheckCfg("Craft - Amount of Materials needed to craft a full robot ", ref CraftItemAmount);
            CheckCfg("Craft - Item ID of the material needed to craft robot (default Metal Fragments) ", ref CraftItemID);

            CheckCfgFloat("Repair - Amount of health restored by one hit when repairing ", ref RepairAmountPerHit);
            CheckCfg("Repair - Amount of Materials needed to repair per hit ", ref RepairItemAmountNeeded);
            CheckCfg("Repair - Item ID of the material needed to repair (default Metal Fragments) ", ref RepairItemID);

            CheckCfgFloat("Punch - Radius - how wide of a fist will the robot have when punching and looking for something to damage ", ref PunchDamageRadius);
            CheckCfgFloat("Punch - Damge - Damage to Non robots entities when being hit by robot punch ", ref DamageToNonRobots);
            CheckCfgFloat("Punch - Damage - Damage to Robots when hit by other robots ", ref DamageToRobots);

            CheckCfgFloat("Punch - Condition Loss - How much condidtion loss damage will robot take when punching other robots ", ref ConditionLossByHittingRobots);
            CheckCfgFloat("Punch - Condition Loss - How much condidtion loss damage will robot take when punching NON robots (players, buildings..etc) ", ref ConditionLossByHittingNonRobots);

            CheckCfg("Punch - Knowndown - Chances a landed robot punch will knock down a roboat for a few seconds ", ref KnockdownChance);

            CheckCfgFloat("Rocket - Cooldown - How long must player wait to reuse the rockets on the robot ", ref RocketReuseTime);
        }

        void CheckCfg<T>(string Key, ref T var)
        {
            if (Config[Key] is T)
                var = (T)Config[Key];
            else
                Config[Key] = var;
        }

        void CheckCfgFloat(string Key, ref float var)
        {

            if (Config[Key] != null)
                var = System.Convert.ToSingle(Config[Key]);
            else
                Config[Key] = var;
        }

        void CheckCfgUlong(string Key, ref ulong var)
        {

            if (Config[Key] != null)
                var = Convert.ToUInt64(Config[Key]);
            else
                Config[Key] = var;
        }

        #endregion

        #region Data

        static List<ulong> storedPooBots = new List<ulong>();
        private DynamicConfigFile data;
        private bool initialized;

        private void OnServerInitialized()
        {
            initialized = true;
            LoadData();
            timer.In(3, RestorePooBots);
        }
        private void OnServerSave()
        {
            SaveData();
        }

        private void RestorePooBots()
        {
            if (storedPooBots.Count > 0)
            {
                BaseEntity[] objects = BaseEntity.saveList.Where(x => x is BaseEntity).ToArray();
                if (objects != null)
                {
                    foreach (var obj in objects)
                    {
                        if (!obj.IsValid() || obj.IsDestroyed)
                            continue;

                        if (storedPooBots.Contains(obj.net.ID.Value))
                        {
                            var spawnpos = obj.transform.position;
                            var spawnrot = obj.transform.rotation;
                            var userid = obj.OwnerID;

                            storedPooBots.Remove(obj.net.ID.Value);
                            obj.Invoke("KillMessage", 0.1f);
                            timer.Once(2f, () => RespawnPooBot(spawnpos, spawnrot, userid));
                        }
                    }
                }
                PrintWarning("All Saved PooBots have be respawned.");
            }
        }

        void SaveData() => data.WriteObject(storedPooBots.ToList());
        void LoadData()
        {
            try
            {
                storedPooBots = data.ReadObject<List<ulong>>();
            }
            catch
            {
                storedPooBots = new List<ulong>();
            }
        }

        #endregion

        #region Commands

        [ChatCommand("poobot")]
        void chatPooBot(BasePlayer player, string command, string[] args)
        {
            SendReply(player, messagetxt1);
            SendReply(player, messagetxt2);
            SendReply(player, messagetxt3);
            SendReply(player, messagetxt4);
            SendReply(player, messagetxt5);
            SendReply(player, messagetxt6);
            SendReply(player, messagetxt7);
            SendReply(player, messagetxt8);
            SendReply(player, messagetxt9);
            SendReply(player, messagetxt10);

        }

        [ChatCommand("poobot.craft")]
        void chatPooBotCraft(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, "poobot.craft")) { SendReply(player, "You do not have permssion to use that command"); return; }
            CraftPooBot(player);
        }

        [ChatCommand("poobot.spawn")]
        void chatPooBotSpawn(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, "poobot.spawn")) { SendReply(player, "You do not have permssion to use that command"); return; }
            if (player.IsOnGround())
            {
                SpawnPooBotOnPlayer(player);
                return;
            }
            else
            {
                SendReply(player, "You must be standing on ground to spawn a Poobot !!");
            }
        }

        [ConsoleCommand("givepoobot")]
        void cmdConsolePoobotGive(ConsoleSystem.Arg arg)
        {
            var player = arg.Player() ?? null;
            if (player != null)
            {
                if (!permission.UserHasPermission(player.UserIDString, "poobot.spawn")) return;
                GivePooBot(player);
                return;
            }
            if (arg.Args.Length > 0)
            {
                ulong id = Convert.ToUInt64(arg.Args[0]);
                GivePooBot(BasePlayer.FindByID(id));
            }
        }

        [ChatCommand("poobot.repack")]
        void chatPooBotRepack(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, "poobot.repack")) { SendReply(player, "You do not have permssion to use that command"); return; }
            if (!player.isMounted) return;
            var poobot = player.GetMounted().GetComponentInParent<PooBotEntity>();
            if (poobot == null) return;
            if (poobot.botentity.OwnerID != player.userID) return;
            if (!AllowRepackLowHealth && poobot.health < RobotStartHealth) { SendInfoMessage(player, "<color=red>Cannot repack Robot when Health is not Full !!</color>", 10f); return; }
            if (!AllowRepackUnderCooldown && !poobot.canfireleft || !poobot.canfireright) { SendInfoMessage(player, "<color=red>Cannot repack Robot with a Weapons Cooldown active !!</color>", 10f); return; }
            DestroyStaticCui(player);
            DestroyRefreshCui(player);
            if (storedPooBots.Contains(poobot.botentity.net.ID.Value))
            {
                storedPooBots.Remove(poobot.botentity.net.ID.Value);
                SaveData();
            }
            GameObject.Destroy(poobot);
            GivePooBot(player);
        }

        [ConsoleCommand("poobotrepack")]
        void cmdConsolePooBotRepack(ConsoleSystem.Arg arg)
        {
            var player = arg.Player() ?? null;
            if (player != null)
            {
                if (!permission.UserHasPermission(player.UserIDString, "poobot.repack")) { SendReply(player, "You do not have permssion to use that command"); return; }
                if (!player.isMounted) return;
                var poobot = player.GetMounted().GetComponentInParent<PooBotEntity>();
                if (poobot == null) return;
                if (poobot.botentity.OwnerID != player.userID) return;
                if (!AllowRepackLowHealth && poobot.health < RobotStartHealth) { SendInfoMessage(player, "<color=red>Cannot repack Robot when Health is not Full !!</color>", 10f); return; }
                if (!AllowRepackUnderCooldown && !poobot.canfireleft || !poobot.canfireright) { SendInfoMessage(player, "<color=red>Cannot repack Robot with a Weapons Cooldown active !!</color>", 10f); return; }
                DestroyStaticCui(player);
                DestroyRefreshCui(player);
                if (storedPooBots.Contains(poobot.botentity.net.ID.Value))
                {
                    storedPooBots.Remove(poobot.botentity.net.ID.Value);
                    SaveData();
                }
                GameObject.Destroy(poobot);
                GivePooBot(player);
            }
        }


        [ConsoleCommand("poobotswapweapon")]
        void cmdConsolePooBotSwapWeapon(ConsoleSystem.Arg arg)
        {
            var player = arg.Player() ?? null;
            if (player != null)
            {
                if (!player.isMounted) return;
                var poobot = player.GetMounted().GetComponentInParent<PooBotEntity>();
                if (poobot == null) return;
                SendInfoMessage(player, "Robot Weapon Swap Feature Coming soon !!", 10f);
            }
        }

        [ConsoleCommand("poobotactivatesentry")]
        void cmdConsolePooBotSentryMode(ConsoleSystem.Arg arg)
        {
            var player = arg.Player() ?? null;
            if (player != null)
            {
                if (!player.isMounted) return;
                var poobot = player.GetMounted().GetComponentInParent<PooBotEntity>();
                if (poobot == null) return;

                if (!poobot.activatesentry) { poobot.activatesentry = true; poobot.RobotButtons(player); SendInfoMessage(player, "Robot Sentry Mode Coming Soon !!", 10f); return; }
                else { poobot.activatesentry = false; poobot.StopPooBot(); poobot.RobotButtons(player); }
            }
        }

        [ChatCommand("poobot.dismount")]
        void chatPooBotDisMount(BasePlayer player, string command, string[] args)
        {
            DestroyStaticCui(player);
            DestroyRefreshCui(player);
            var dismountloc = player.transform.position + (Vector3.down * 2f) + (Vector3.forward);
            player?.EnsureDismounted();
            player.MovePosition(dismountloc);
            player.SendNetworkUpdateImmediate(false);
            player.ClientRPCPlayer<Vector3>(null, player, "ForcePositionTo", dismountloc);
            Interface.CallHook("OnEntityDismounted", this, player);
        }

        [ChatCommand("poobot.repair")]
        void chatPooBotRepair(BasePlayer player, string command, string[] args)
        {
            if (!player.isMounted) return;
            var poobot = player.GetMounted().GetComponentInParent<PooBotEntity>();
            if (poobot == null) return;
            if (!permission.UserHasPermission(player.UserIDString, "poobot.spawn")) return;
            poobot.RestoreHealth();
        }

        [ChatCommand("poobot.activatenpc")]
        void chatPooBotActivateNPC(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, "poobot.spawn")) { SendReply(player, "You do not have permssion to use that command"); return; }
            if (!player.isMounted) return;
            var poobot = player.GetMounted().GetComponentInParent<PooBotEntity>();
            if (poobot == null) return;
            if (!poobot.activatenpc) { poobot.activatenpc = true; poobot.RobotButtons(player); SendInfoMessage(player, "Robot Spar Mode Activated", 10f); return; }
            else { poobot.activatenpc = false; poobot.StopPooBot(); poobot.RobotButtons(player); }
        }

        [ConsoleCommand("poobotactivatenpc")]
        void cmdConsolePoobotActivateNPC(ConsoleSystem.Arg arg)
        {
            var player = arg.Player() ?? null;
            if (player != null)
            {
                if (!permission.UserHasPermission(player.UserIDString, "poobot.spawn")) { SendReply(player, "You do not have permssion to use that command"); return; }
                if (!player.isMounted) return;
                var poobot = player.GetMounted().GetComponentInParent<PooBotEntity>();
                if (poobot == null) return;
                if (!poobot.activatenpc) { poobot.activatenpc = true; poobot.RobotButtons(player); SendInfoMessage(player, "Robot Spar Mode Activated", 10f); return; }
                else { poobot.activatenpc = false; poobot.StopPooBot(); poobot.RobotButtons(player); }
            }
        }

        #endregion

        #region Hooks

        private void SpawnPooBotOnPlayer(BasePlayer player)
        {
            Vector3 startloc = player.transform.position;
            float groundy = TerrainMeta.HeightMap.GetHeight(startloc);
            string sphereprefab = "assets/prefabs/deployable/chair/chair.deployed.prefab";
            robotEntity = GameManager.server.CreateEntity(sphereprefab, new Vector3(startloc.x, groundy + 4.1f, startloc.z), player.transform.rotation, true);
            var mount = robotEntity.GetComponent<BaseMountable>();
            mount.isMobile = true;
            robotEntity.OwnerID = player.userID;
            robotEntity.skinID = 112233;
            robotEntity.Spawn();
            var addbody = robotEntity.gameObject.AddComponent<PooBotEntity>();
            storedPooBots.Add(robotEntity.net.ID.Value);
            SaveData();
        }

        private void RespawnPooBot(Vector3 spawnpos, Quaternion spawnrot, ulong userid)
        {
            Vector3 startloc = spawnpos;
            float groundy = TerrainMeta.HeightMap.GetHeight(startloc);
            string sphereprefab = "assets/prefabs/deployable/chair/chair.deployed.prefab";
            robotEntity = GameManager.server.CreateEntity(sphereprefab, new Vector3(startloc.x, groundy + 4.1f, startloc.z), spawnrot, true);
            var mount = robotEntity.GetComponent<BaseMountable>();
            mount.isMobile = true;
            robotEntity.OwnerID = userid;
            robotEntity.skinID = 112233;
            robotEntity.Spawn();
            var addbody = robotEntity.gameObject.AddComponent<PooBotEntity>();
            storedPooBots.Add(robotEntity.net.ID.Value);
            SaveData();
        }

        private object CanPickupEntity(BasePlayer player, BaseCombatEntity entity)
        {
            if (entity == null || player == null) return null;
            var ispoobot = entity.GetComponentInParent<PooBotEntity>() ?? null;
            if (ispoobot != null) return false;
            return null;
        }

        private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            if (entity == null) return;
            if (storedPooBots.Contains(entity.net.ID.Value))
            {
                storedPooBots.Remove(entity.net.ID.Value);
                SaveData();
            }
        }

        private void CraftPooBot(BasePlayer player)
        {
            if (!TakeItem1Mats(player, CraftItemID, CraftItemAmount))
            {
                ItemDefinition itemDefinition = ItemManager.FindItemDefinition(CraftItemID);
                { SendReply(player, "You need " + CraftItemAmount.ToString() + " " + itemDefinition.shortname + "to craft a Robot !!"); return; }
            }
            GivePooBot(player);
        }

        private void GivePooBot(BasePlayer player)
        {
            var item = ItemManager.CreateByItemID(833533164, 1, 1428017435);
            player.inventory.GiveItem(item);
        }

        private void OnEntityBuilt(Planner plan, GameObject obj)
        {
            var entity = obj.GetComponent<BaseEntity>();
            if (entity != null && entity.ShortPrefabName == "box.wooden.large")
            {
                if (entity.GetComponent<BaseEntity>().skinID == 1428017435L)
                {
                    BasePlayer player = plan.GetOwnerPlayer();

                    if (player != null && player.IsOnGround())
                    {
                        ServerMgr.Instance.StartCoroutine(PoobotSpawnProcess(player, entity));
                        return;
                    }
                    else
                    {
                        SendReply(player, "You Must deploy the Poobot on ground !!!!");
                        timer.Once(1f, () => DestroyBox(entity));
                        GivePooBot(player);
                    }

                }
            }
        }

        private IEnumerator PoobotSpawnProcess(BasePlayer player, BaseEntity entity)
        {
            yield return new WaitForSeconds(0.5f);
            entity.Kill();
            yield return new WaitForSeconds(0.5f);
            SpawnPooBotOnPlayer(player);
        }

        private void DestroyBox(BaseEntity boxEntity)
        {
            if (boxEntity != null)
            {
                boxEntity.Kill();
            }
        }

        private void OnLootEntity(BasePlayer player, BaseEntity entity)
        {
            var ispoobot = entity.GetComponentInParent<PooBotEntity>();
            if (ispoobot) MountPooBot(player, ispoobot);
        }

        private void MountPooBot(BasePlayer player, PooBotEntity poobot)
        {
            if (!poobot.botentity.GetComponent<BaseMountable>()._mounted) poobot.botentity.GetComponent<BaseMountable>().MountPlayer(player);
        }

        private void OnPlayerInput(BasePlayer player, InputState input)
        {
            if (!player.isMounted || input == null) return;
            var poobot = player.GetMounted().GetComponentInParent<PooBotEntity>();
            if (poobot)
            {
                if (player.isMounted && input.IsDown(BUTTON.FORWARD)) poobot.moveforward = true;
                else poobot.moveforward = false;

                if (player.isMounted && input.IsDown(BUTTON.BACKWARD)) poobot.movebackward = true;
                else poobot.movebackward = false;

                if (player.isMounted && input.IsDown(BUTTON.SPRINT)) poobot.sprinting = true;
                else poobot.sprinting = false;

                if (input.IsDown(BUTTON.RIGHT)) poobot.rotright = true;
                else poobot.rotright = false;

                if (input.IsDown(BUTTON.LEFT)) poobot.rotleft = true;
                else poobot.rotleft = false;

                if (input.WasJustPressed(BUTTON.FIRE_PRIMARY)) poobot.moveleftarm = true;
                if (input.WasJustReleased(BUTTON.FIRE_PRIMARY)) { poobot.moveleftarm = false; poobot.lefthandready = true; }
                if (input.WasJustPressed(BUTTON.FIRE_SECONDARY)) poobot.moverightarm = true;
                if (input.WasJustReleased(BUTTON.FIRE_SECONDARY)) { poobot.moverightarm = false; poobot.righthandready = true; }
                if (input.WasJustPressed(BUTTON.FIRE_THIRD)) poobot.docharge = true;
                if (input.WasJustPressed(BUTTON.RELOAD)) FireOrReloadRockets(player, poobot);
                if (input.WasJustReleased(BUTTON.RELOAD)) poobot.fireweapon = false;
                if (input.WasJustPressed(BUTTON.DUCK)) poobot.docrouch = true;
                if (input.WasJustReleased(BUTTON.DUCK)) poobot.docrouch = false;

                if (input == null)
                {
                    poobot.moveforward = false;
                    poobot.movebackward = false;
                    poobot.sprinting = false;
                    poobot.rotright = false;
                    poobot.rotleft = false;
                    poobot.moveleftarm = false;
                    poobot.moverightarm = false;
                    poobot.fireweapon = false;
                }
            }
        }

        private void FireOrReloadRockets(BasePlayer player, PooBotEntity pooBot)
        {
            if (!pooBot.moveleftarm && !pooBot.moverightarm) { SendReply(player, "Robot arm must be extended to fire Rockets !!"); return; }
            if ((pooBot.canfireleft && pooBot.moveleftarm) || (pooBot.canfireright && pooBot.moverightarm))
            {
                if (TakeItem1Mats(player, -742865266, 1)) { pooBot.fireweapon = true; pooBot.rocketprefab = "assets/prefabs/ammo/rocket/rocket_basic.prefab"; return; }
                if (TakeItem1Mats(player, 1638322904, 1)) { pooBot.fireweapon = true; pooBot.rocketprefab = "assets/prefabs/ammo/rocket/rocket_fire.prefab"; return; }
                if (TakeItem1Mats(player, -1841918730, 1)) { pooBot.fireweapon = true; pooBot.rocketprefab = "assets/prefabs/ammo/rocket/rocket_hv.prefab"; return; }
                else { SendReply(player, "You need to have Rocket Ammo in your inventory"); pooBot.fireweapon = false; return; }
            }
            else
                SendReply(player, "Rocket launcher is under cooldown..please wait !!");
        }

        private void OnHammerHit(BasePlayer player, HitInfo info)
        {
            var entity = info.HitEntity;
            var ispoobot = entity.GetComponentInParent<PooBotEntity>();
            if (!ispoobot) return;
            if (ispoobot)
            {
                RepairRobot(player, ispoobot);
            }
        }

        private void RepairRobot(BasePlayer player, PooBotEntity pooBot)
        {
            var currenthealth = pooBot.health;
            if (currenthealth >= RobotStartHealth) { SendReply(player, "Robot is at Max Health Already !!"); return; }
            if (pooBot.botdefeated && currenthealth >= MinRepairHealth) { pooBot.botdefeated = false; pooBot.StandBotUp(); }
            if (TakeItem1Mats(player, RepairItemID, RepairItemAmountNeeded))
            {
                pooBot.health = currenthealth + RepairAmountPerHit;
                SendReply(player, "Robot repaired...Current health is : " + pooBot.health);
            }
            else
                SendReply(player, "You do not have the required materials to repair this Robot !!");
        }

        public bool HasRockets(BasePlayer player)
        {
            int HasReq1 = player.inventory.GetAmount(-742865266);
            int HasReq2 = player.inventory.GetAmount(1638322904);
            int HasReq3 = player.inventory.GetAmount(-1841918730);
            if (HasReq1 > 0 || HasReq2 > 0 || HasReq3 > 0) return true;
            return false;
        }

        private bool TakeItem1Mats(BasePlayer player, int itemID, int itemamount)
        {
            int HasReq1 = player.inventory.GetAmount(itemID);

            if (HasReq1 >= itemamount)
            {
                player.inventory.Take(null, itemID, itemamount);
                player.Command("note.inv", itemID, -itemamount);
                return true;
            }
            return false;
        }

        private void OnEntityDismounted(BaseMountable mountable, BasePlayer player)
        {
            if (player == null) return;
            DestroyStaticCui(player);
            DestroyRefreshCui(player);
        }

        private void OnEntityMounted(BaseMountable mountable, BasePlayer player)
        {
            if (player == null || mountable == null) return;
            var poobot = mountable.GetComponentInParent<PooBotEntity>();
            if (poobot == null) return;
            GiveRandomHelpMessage(player);
            poobot.RobotButtons(player);
        }

        private object OnEntityGroundMissing(BaseEntity entity)
        {
            var isbot = entity.GetComponentInParent<PooBotEntity>() ?? null;
            if (isbot != null) return false;
            return null;
        }

        private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
        {
            if (entity == null || hitInfo == null) return;
            if (!AllowPlayerDamage && hitInfo.Initiator is BasePlayer)
            {
                var attacker = (BasePlayer)hitInfo.Initiator ?? null;
                if (attacker != null && !(entity is BaseNpc))
                {
                    var inpoobot = attacker.GetMounted()?.GetComponentInParent<PooBotEntity>() ?? null;
                    if (inpoobot) hitInfo.damageTypes.ScaleAll(0);
                    return;
                }
            }
            if (hitInfo.HitEntity is BasePlayer)
            {
                var victim = (BasePlayer)hitInfo.HitEntity;
                if (!victim.isMounted) return;
                var poobot = victim.GetMounted().GetComponentInParent<PooBotEntity>();
                if (poobot == null) return;
                poobot.health = poobot.health - Convert.ToSingle(hitInfo.damageTypes.Total());
                hitInfo.damageTypes.ScaleAll(0);
                return;
            }
            var ispoobot = entity.GetComponentInParent<PooBotEntity>() ?? null;
            if (ispoobot != null)
            {
                ispoobot.health = ispoobot.health - Convert.ToSingle(hitInfo.damageTypes.Total());
                hitInfo.damageTypes.ScaleAll(0);
                return;
            }
        }

        public void DestroyRefreshCui(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, "HealthGui");
            CuiHelper.DestroyUi(player, "RightRocketGui");
            CuiHelper.DestroyUi(player, "LeftRocketGui");
            CuiHelper.DestroyUi(player, "FuelGui");
            CuiHelper.DestroyUi(player, "FuelStr");
        }

        public void DestroyStaticCui(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, "RepackButton");
            CuiHelper.DestroyUi(player, "NPCButton");
            CuiHelper.DestroyUi(player, "SentryButton");
            CuiHelper.DestroyUi(player, "SwapWeaponButton");
        }

        static void DestroyAll<T>()
        {
            var objects = GameObject.FindObjectsOfType(typeof(T));
            if (objects != null)
                foreach (var gameObj in objects)
                    GameObject.Destroy(gameObj);
        }

        #endregion

        #region Info Panel

        void SendInfoMessage(BasePlayer player, string message, float time)
        {
            player?.SendConsoleCommand("gametip.showgametip", message);
            timer.Once(time, () => player?.SendConsoleCommand("gametip.hidegametip"));
        }

        void GiveRandomHelpMessage(BasePlayer player)
        {
            player?.SendConsoleCommand("gametip.hidegametip");
            int getmessagenum = UnityEngine.Random.Range(0, 10);
            if (getmessagenum == 0) { SendInfoMessage(player, messagetxt1, 10f); return; }
            if (getmessagenum == 1) { SendInfoMessage(player, messagetxt2, 10f); return; }
            if (getmessagenum == 2) { SendInfoMessage(player, messagetxt3, 10f); return; }
            if (getmessagenum == 3) { SendInfoMessage(player, messagetxt4, 10f); return; }
            if (getmessagenum == 4) { SendInfoMessage(player, messagetxt5, 10f); return; }
            if (getmessagenum == 5) { SendInfoMessage(player, messagetxt6, 10f); return; }
            if (getmessagenum == 6) { SendInfoMessage(player, messagetxt7, 10f); return; }
            if (getmessagenum == 7) { SendInfoMessage(player, messagetxt8, 10f); return; }
            if (getmessagenum == 8) { SendInfoMessage(player, messagetxt9, 10f); return; }
            if (getmessagenum == 9) { SendInfoMessage(player, messagetxt10, 10f); return; }
        }

        #endregion

        #region SentryMode 

        class SentryMode : MonoBehaviour
        {

            PooBotEntity poobot;
            ulong poobotownerid;

            void Awake()
            {
                poobot = GetComponentInParent<PooBotEntity>();
                poobotownerid = poobot.ownerid;
            }

            void OnDestroy()
            {
                GameObject.Destroy(this);
            }
        }

        #endregion

        #region PooBotEntity

        class PooBotEntity : BaseEntity
        {
            #region Awake

            PooBot instance;
            public BaseEntity botentity;
            BasePlayer botplayer;
            BaseEntity bodytop, bodybottom, armRightShoulder, armLeftShoulder, armrightupper, armrighthand, armleftupper, armlefthand, legRight, legLeft;
            BaseEntity flamechunkerleft, flamechunkerright, currentweaponright, currentweaponleft, chainsaw1, armspikes, chainsaw3, jackhammer;

            public string rocketprefab;

            int counter;
            int npccounter;
            float fireleftcooldown;
            float firerightcoolodwn;
            int refreshcounter;
            int gathercounter;
            float fueltickcounter;
            int chargecooldowntimer;
            public bool moveforward, movebackward, ismoving, sprinting, docharge, chargecooldown, rotright, rotleft, docrouch;
            public bool moverightarm, moveleftarm, fireweapon, canfireright, canfireleft, righthandready, lefthandready, botdefeated, botstandup, botfalldown, activatenpc, activatesentry;
            bool setactive;

            ulong armskin;
            public ulong ownerid;

            Vector3 movedirection, rotdirection, startpos;
            float steps;
            public float health;

            private float secsToTake, secsTaken;

            private float initialRot;
            private Vector3 startRot;
            private Vector3 endRot;

            void Awake()
            {
                instance = new PooBot();
                botentity = GetComponentInParent<BaseEntity>();
                startpos = botentity.transform.position;
                botplayer = botentity.GetComponent<BaseMountable>()._mounted as BasePlayer;
                ownerid = botentity.OwnerID;
                rocketprefab = "assets/prefabs/ammo/rocket/rocket_basic.prefab";
                gameObject.name = "PooBot";
                counter = 0;
                npccounter = 0;
                gathercounter = 0;
                fueltickcounter = 0f;
                chargecooldowntimer = 0;
                setactive = false;
                moveforward = false;
                movebackward = false;
                sprinting = false;
                docharge = false;
                chargecooldown = false;
                rotright = false;
                rotleft = false;
                moverightarm = false;
                moveleftarm = false;
                ismoving = false;
                fireweapon = false;
                docrouch = false;

                canfireright = true;
                canfireleft = true;

                righthandready = true;
                lefthandready = true;
                botdefeated = false;
                botfalldown = false;
                botstandup = false;
                activatenpc = false;
                activatesentry = false;
                health = RobotStartHealth;
                fireleftcooldown = RocketReuseTime;
                firerightcoolodwn = RocketReuseTime;
                refreshcounter = 0;

                movedirection = botentity.transform.position + (botentity.transform.forward * steps * Time.deltaTime);
                steps = 10f;

                initialRot = botentity.transform.localEulerAngles.x;
                secsToTake = 2f;
                startRot = new Vector3(0.01f, botentity.transform.localEulerAngles.y, botentity.transform.localEulerAngles.z);
                endRot = new Vector3(85.99f, botentity.transform.localEulerAngles.y, botentity.transform.localEulerAngles.z);

                botentity.transform.position = startpos;
                botentity.transform.hasChanged = true;
                botentity.SendNetworkUpdateImmediate();
                botentity.UpdateNetworkGroup();
                SpawnPooBot();
            }

            #endregion

            #region Spawn PooBot

            private void SpawnPooBot()
            {
                string prefabMissleLauncher = "assets/prefabs/npc/sam_site_turret/sam_static.prefab";

                string prefabbbq = "assets/prefabs/deployable/bbq/bbq.deployed.prefab";

                string prefabOilRef = "assets/prefabs/deployable/oil refinery/refinery_small_deployed.prefab";

                string prefabflamechunker = "assets/prefabs/npc/flame turret/flameturret.deployed.prefab";

                bodytop = GameManager.server.CreateEntity(prefabOilRef, botentity.transform.position, Quaternion.identity, setactive);
                bodytop.enableSaving = false;
                bodytop.SetFlag(BaseEntity.Flags.Busy, true, false);
                bodytop.Spawn();
                bodytop.SetParent(botentity, 0);
                bodytop.transform.localPosition = new Vector3(0f, 1.2f, 0f);
                bodytop.transform.localEulerAngles = new Vector3(0, 0, 0);

                bodybottom = GameManager.server.CreateEntity(prefabOilRef, botentity.transform.position, Quaternion.identity, setactive);
                bodybottom.enableSaving = false;
                bodybottom.SetFlag(BaseEntity.Flags.Busy, true, false);
                bodybottom.Spawn();
                bodybottom.SetParent(botentity, 0);
                bodybottom.transform.localPosition = new Vector3(0f, 0.5f, 0f);
                bodybottom.transform.localEulerAngles = new Vector3(0, 0, 180);

                armRightShoulder = GameManager.server.CreateEntity(prefabbbq, botentity.transform.position, Quaternion.identity, setactive);
                armRightShoulder.enableSaving = false;
                armRightShoulder.SetFlag(BaseEntity.Flags.Busy, true, false);
                armRightShoulder.Spawn();
                armRightShoulder.SetParent(bodytop, 0);
                armRightShoulder.transform.localPosition = new Vector3(1.5f, 0f, -0.5f);
                armRightShoulder.transform.localEulerAngles = new Vector3(90, 0, 0);

                armrightupper = GameManager.server.CreateEntity(prefabOilRef, botentity.transform.position, Quaternion.identity, setactive);
                armrightupper.enableSaving = false;
                armrightupper.SetFlag(BaseEntity.Flags.Busy, true, false);
                armrightupper.Spawn();
                armrightupper.SetParent(armRightShoulder, 0);
                armrightupper.transform.localPosition = new Vector3(0f, 0.5f, 0f);
                armrightupper.transform.localEulerAngles = new Vector3(90, 30, 0);

                armrighthand = GameManager.server.CreateEntity(prefabbbq, botentity.transform.position, Quaternion.identity, setactive);
                armrighthand.enableSaving = false;
                armrighthand.Spawn();
                armrighthand.SetParent(armrightupper, 0);
                armrighthand.transform.localPosition = new Vector3(0f, 3.5f, 0f);
                armrighthand.transform.localEulerAngles = new Vector3(180, 0, 0);

                armLeftShoulder = GameManager.server.CreateEntity(prefabbbq, botentity.transform.position, Quaternion.identity, setactive);
                armLeftShoulder.enableSaving = false;
                armLeftShoulder.SetFlag(BaseEntity.Flags.Busy, true, false);
                armLeftShoulder.Spawn();
                armLeftShoulder.SetParent(bodytop, 0);
                armLeftShoulder.transform.localPosition = new Vector3(-1.5f, 0f, -0.5f);
                armLeftShoulder.transform.localEulerAngles = new Vector3(90, 0, 0);

                armleftupper = GameManager.server.CreateEntity(prefabOilRef, botentity.transform.position, Quaternion.identity, setactive);
                armleftupper.enableSaving = false;
                armleftupper.SetFlag(BaseEntity.Flags.Busy, true, false);
                armleftupper.Spawn();
                armleftupper.SetParent(armLeftShoulder, 0, true, true);
                armleftupper.transform.localPosition = new Vector3(0f, 0.5f, 0f);
                armleftupper.transform.localEulerAngles = new Vector3(90, -30, 0);

                armlefthand = GameManager.server.CreateEntity(prefabbbq, botentity.transform.position, Quaternion.identity, setactive);
                armlefthand.enableSaving = false;
                armlefthand.Spawn();
                armlefthand.SetParent(armleftupper, 0);
                armlefthand.transform.localPosition = new Vector3(0f, 3.5f, 0f);
                armlefthand.transform.localEulerAngles = new Vector3(180, 0, 0);

                ////////////////////////////////////////////////////////////////////////////////////////////////////////

                legRight = GameManager.server.CreateEntity(prefabOilRef, botentity.transform.position, Quaternion.identity, setactive);
                legRight.enableSaving = false;
                legRight.SetFlag(BaseEntity.Flags.Busy, true, false);
                legRight.Spawn();
                legRight.SetParent(bodybottom, 0);
                legRight.transform.localPosition = new Vector3(1.25f, 4f, 0f);
                legRight.transform.localEulerAngles = new Vector3(0, 180, 180);

                ////////////////////////////////////////////////////////////////////////////////////////////////////////


                legLeft = GameManager.server.CreateEntity(prefabOilRef, botentity.transform.position, Quaternion.identity, setactive);
                legLeft.enableSaving = false;
                legLeft.SetFlag(BaseEntity.Flags.Busy, true, false);
                legLeft.Spawn();
                legLeft.SetParent(bodybottom, 0);
                legLeft.transform.localPosition = new Vector3(-1.25f, 4f, 0f);
                legLeft.transform.localEulerAngles = new Vector3(0, 0, 180);

                flamechunkerleft = GameManager.server.CreateEntity(prefabflamechunker, botentity.transform.position, Quaternion.identity, setactive);
                flamechunkerleft.enableSaving = false;
                flamechunkerleft.SetFlag(BaseEntity.Flags.Busy, true, false);
                flamechunkerleft.Spawn();
                flamechunkerleft.SetParent(bodybottom, 0);
                flamechunkerleft.transform.localPosition = new Vector3(0.2f, 1f, 0.2f);
                flamechunkerleft.transform.localEulerAngles = new Vector3(0, 45, 0);

                RefreshMovement();
            }

            #endregion

            #region Hooks

            public void StopPooBot()
            {
                moveforward = false;
                movebackward = false;
                sprinting = false;
                rotright = false;
                rotleft = false;
                moveleftarm = false;
                moverightarm = false;
                fireweapon = false;
                activatenpc = false;
                activatesentry = false;
            }

            public void RestoreHealth()
            {
                if (health > 0) return;
                botdefeated = false;
                botfalldown = false;
                botstandup = true;
                health = 10000f;
            }

            private void PooBotDefeated()
            {
                botdefeated = true;
                activatenpc = false;
                activatesentry = false;
                npccounter = 0;
                botfalldown = true;
                botstandup = false;
                counter = 0;
            }

            public void StandBotUp()
            {
                botdefeated = false;
                botfalldown = false;
                botstandup = true;
            }

            private bool PlayerIsMounted()
            {
                bool flag = botentity.GetComponentInParent<BaseMountable>().IsMounted();
                return flag;
            }

            private bool hitSomething(Vector3 position)
            {
                var directioncheck = new Vector3();
                if (moveforward) directioncheck = (position + Vector3.down) + (transform.forward * 3);
                if (movebackward) directioncheck = (position + Vector3.down) - (transform.forward * 3);
                if (GamePhysics.CheckSphere(directioncheck, 2f, UnityEngine.LayerMask.GetMask("World", "Construction", "Default", "Debris", "Clutter", "Deployed", "Tree"), 0)) return true;
                return false;
            }

            private void OnDestroy()
            {
                if (botplayer != null) instance.DestroyRefreshCui(botplayer);
                if (botplayer != null) instance.DestroyStaticCui(botplayer);
                if (botentity != null && !botentity.IsDestroyed) { botentity.Invoke("KillMessage", 0.1f); }
            }

            #endregion

            #region Damage and Weapons

            private void ToggleWeaponsRight()
            {
                AddJackHammer(armrighthand);
                AddChainSaws(armrighthand);
            }

            private void NPCSwingArm()
            {
                int moveroll = UnityEngine.Random.Range(0, 2);
                if (moveroll == 0) { moverightarm = true; moveleftarm = false; }
                if (moveroll == 1) { moverightarm = false; moveleftarm = true; }
            }

            private void AddChainSaws(BaseEntity entity)
            {
                string prefabchainsaw = "assets/prefabs/weapons/chainsaw/chainsaw.entity.prefab";
                chainsaw1 = GameManager.server.CreateEntity(prefabchainsaw, entity.transform.position, Quaternion.identity, false);
                chainsaw1.enableSaving = false;
                chainsaw1.Spawn();
                chainsaw1.SetParent(entity, 0);
                chainsaw1.transform.localPosition = new Vector3(0f, 0f, 0f);
                chainsaw1.transform.localEulerAngles = new Vector3(0, 90, 0);
            }

            private void AddJackHammer(BaseEntity entity)
            {
                string prefabjackhammer = "assets/prefabs/tools/jackhammer/jackhammer.entity.prefab";
                jackhammer = GameManager.server.CreateEntity(prefabjackhammer, entity.transform.position, Quaternion.identity, true) as AttackEntity;
                jackhammer.enableSaving = false;
                var hammer = jackhammer.GetComponent<Jackhammer>();
                //hammer.SetHeld(true);
                //hammer.SetFlag(BaseEntity.Flags.Reserved8, true, false);
                jackhammer.Spawn();
                jackhammer.SetParent(entity, 0);
                jackhammer
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху