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

FREE AirfieldEvent : 1.1.7 1.1.7

Нет прав для скачивания
C#:
using UnityEngine;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
using System.Collections.Generic;
///Скачано с дискорд сервера Rust Edit [PRO+]
///discord.gg/9vyTXsJyKR
namespace Oxide.Plugins {
    [Info("AirfieldEvent", "discord.gg/9vyTXsJyKR", "1.1.7")]
    [Description("AirfieldEvent")]
    class AirfieldEvent : CovalencePlugin {
        private BaseEntity planeEntity;
        private Vector3 airfieldPosition;
        private Quaternion airfieldRotation;
        private List<Vector3> planeWayPoints = new List<Vector3>();
        private int stage;
        private float rotationSpeed = 1.3f;
        private float speed;
        private float maxSpeed = 5;
        private Vector3 dir;
        private Quaternion oldRot;
        private bool fix;
        private int dropsAmount;
        private int supplyAmount;
        private int cratesAmount;
        private int npcsAmount;
        private string npcPrefab;
        private const string supplyPrefab = "assets/prefabs/misc/supply drop/supply_drop.prefab";
        private const string cratePrefab = "assets/prefabs/deployable/chinooklockedcrate/codelockedhackablecrate.prefab";
        private int lifeTimeCrates;
        private int lifeTimeSupply;
        private int lifeTimeNpcs;
        private int remainToEvent;
        private int remain;
        private string message;
        private int typeNpcs;
        private int npcHealth;
        private bool eventFlag;
        private bool callHeli;
        private int patrolTime;
        private bool eventMarker;
        private bool afterLanding;
        private int markerLifetime;
        private float markerAlpha;
        private float markerRadius;
        private string markerName;
        private bool npcForceFreeze;
        private Color markerColor = Color.red;
        private MapMarkerGenericRadius marker;
        private VendingMachineMapMarker vending;
        private float npcDamageMultiplier;
        private const string npcName = "afeguardnpc";
        private const string heliName = "afeHelicopter";
        private ConfigData Configuration;
        private bool randomEventTime;
        private int minimumRemainToEvent;
        private int maximumRemainToEvent;
        private float heliDamageMultiplier;
        private float heliHealth;
        [PluginReference]
        Plugin Kits;
        private List<BaseEntity> entityList = new List<BaseEntity>();
        private int xSum;
        private List<string> kitsListNPC;
        private float npcAttackRange;
        private const int layerS = ~(1 << 2 | 1 << 3 | 1 << 4 | 1 << 10 | 1 << 18 | 1 << 28 | 1 << 29);
        private List<List<Vector3>> wayPointsList = new List<List<Vector3>>();
        private List<List<BaseEntity>> botList = new List<List<BaseEntity>>();
        private int chaseRadius = 60;
        private int coolDownTime = 10;
        private int homeRadius = 20;
        private Timer eventTimer;
        private class NpcBrain : FacepunchBehaviour {
            public Vector3 homePosition;
            public Vector3 targetPosition;
            public BaseEntity target;
            public int stateTimer;
            public int moveChance;
        }
        class ConfigData {
            [JsonProperty("Time to event start(in seconds, minimum 900)")]
            public int remainToEvent = 3900;
            [JsonProperty("Random time to event start")]
            public bool randomEventTime = false;
            [JsonProperty("Minimum time to event start(in seconds, minimum 900)")]
            public int minimumRemainToEvent = 900;
            [JsonProperty("Maximum time to event start(in seconds)")]
            public int maximumRemainToEvent = 10800;
            [JsonProperty("Drops amount(number of cargo spawns after plane landing, maximum 10)")]
            public int dropsAmount = 3;
            [JsonProperty("Crates amount(spawn every cargo drop)")]
            public int cratesAmount = 1;
            [JsonProperty("Crates lifetime(in seconds).The crate will not be destroyed if it has been activated")]
            public int lifeTimeCrates = 3600;
            [JsonProperty("Crates timer(in seconds)")]
            public int timerCrates = 900;
            [JsonProperty("Airdrops amount(spawn every cargo drop)")]
            public int supplyAmount = 1;
            [JsonProperty("Airdrops lifetime(in seconds)")]
            public int lifeTimeSupply = 3600;
            [JsonProperty("NPCs amount(spawn every cargo drop)")]
            public int npcsAmount = 0;
            [JsonProperty("NPCs lifetime(in seconds)")]
            public int lifeTimeNpcs = 3600;
            [JsonProperty("NPCs type(NPCs prefab, experimental setting, it is not known how the NPCs will behave) 0 - tunneldweller; 1 - underwaterdweller; 2 - excavator; 3 - full_any; 4 - lr300; 5 - mp5; 6 - pistol; 7 - shotgun; 8 - heavy; 9 - junkpile_pistol; 10 - oilrig; 11 - patrol; 12 - peacekeeper; 13 - roam; 14 - roamtethered; 15 - bandit_guard; 16 - cargo; 17 - cargo_turret_any; 18 - cargo_turret_lr300; 19 - ch47_gunner")]
            public int typeNpcs = 0;
            [JsonProperty("NPCs health(0 - default)")]
            public int npcHealth = 0;
            [JsonProperty("NPCs damage multiplier")]
            public float npcDamageMultiplier = 1f;
            [JsonProperty("NPCs attack range")]
            public float npcAttackRange = 75f;
            [JsonProperty("Minimum distance to NPC damage")]
            public float npcMinDistToDmg = 75f;
            [JsonProperty("Forcibly immobilize an NPC")]
            public bool npcForceFreeze = false;
            [JsonProperty("List of kits for each NPC(requires Kits plugin)")]
            public List<string> kitsListNPC = new List<string> {
                "kit1", "kit2", "kit3"
            }
            ;
            [JsonProperty("Default displayName for NPC(for SimpleKillFeed/DeathNotes plugin)")]
            public string displayNameNPC = "Airfield NPC";
            [JsonProperty("List of displayNames for each NPC(for SimpleKillFeed/DeathNotes plugin)")]
            public List<string> displayNamesListNPC = new List<string> {
                "Airfield NPC1", "Airfield NPC2", "Airfield NPC3"
            }
            ;
            [JsonProperty("Event message(if empty, no message will be displayed)")]
            public string message = "Airfield event started";
            [JsonProperty("Calls a helicopter to the airfield after landing a cargo plane")]
            public bool callHeli = false;
            [JsonProperty("How long the helicopter will patrol the airfield (in minutes)")]
            public int patrolTime = 5;
            [JsonProperty("Helicopter damage multiplier")]
            public float heliDamageMultiplier = 1;
            [JsonProperty("Helicopter health")]
            public float heliHealth = 10000;
            [JsonProperty("Event marker on the map(will spawn a marker immediately after the start of the event)")]
            public bool eventMarker = false;
            [JsonProperty("If true, spawn the marker only after the plane lands")]
            public bool afterLanding = false;
            [JsonProperty("Event marker name")]
            public string markerName = "Airfield event";
            [JsonProperty("Event marker lifetime(in seconds)")]
            public int markerLifetime = 3600;
            [JsonProperty("Event marker transparency(0-1)")]
            public float markerAlpha = 0.75f;
            [JsonProperty("Event marker radius")]
            public float markerRadius = 0.5f;
            [JsonProperty("Event marker color.R(0-1)")]
            public float markerColorR = 1.0f;
            [JsonProperty("Event marker color.G(0-1)")]
            public float markerColorG = 0f;
            [JsonProperty("Event marker color.B(0-1)")]
            public float markerColorB = 0f;
            [JsonProperty("Use a custom place to land a cargo plane")]
            public bool customLanding = false;
            [JsonProperty("Custom place position")]
            public Vector3 customPosition = Vector3.zero;
            [JsonProperty("Custom place rotation")]
            public Vector3 customRotation = Vector3.zero;
        }
        private void OnServerInitialized() {
            LoadConfig();
            eventFlag = false;
            remainToEvent = Configuration.remainToEvent;
            if (remainToEvent < 900) remainToEvent = 900;
            remain = remainToEvent;
            dropsAmount = Configuration.dropsAmount;
            if (dropsAmount > 10) dropsAmount = 10;
            cratesAmount = Configuration.cratesAmount;
            lifeTimeCrates = Configuration.lifeTimeCrates;
            supplyAmount = Configuration.supplyAmount;
            lifeTimeSupply = Configuration.lifeTimeSupply;
            npcsAmount = Configuration.npcsAmount;
            lifeTimeNpcs = Configuration.lifeTimeNpcs;
            typeNpcs = Configuration.typeNpcs;
            message = Configuration.message;
            callHeli = Configuration.callHeli;
            patrolTime = Configuration.patrolTime;
            npcHealth = Configuration.npcHealth;
            npcForceFreeze = Configuration.npcForceFreeze;
            eventMarker = Configuration.eventMarker;
            afterLanding = Configuration.afterLanding;
            markerName = Configuration.markerName;
            markerLifetime = Configuration.markerLifetime;
            markerAlpha = Configuration.markerAlpha;
            markerRadius = Configuration.markerRadius;
            markerColor.r = Configuration.markerColorR;
            markerColor.g = Configuration.markerColorG;
            markerColor.b = Configuration.markerColorB;
            npcDamageMultiplier = Configuration.npcDamageMultiplier;
            randomEventTime = Configuration.randomEventTime;
            minimumRemainToEvent = Configuration.minimumRemainToEvent;
            maximumRemainToEvent = Configuration.maximumRemainToEvent;
            heliHealth = Configuration.heliHealth;
            heliDamageMultiplier = Configuration.heliDamageMultiplier;
            kitsListNPC = Configuration.kitsListNPC;
            npcAttackRange = Configuration.npcAttackRange;
            GameObject mon = new GameObject();
            if (Configuration.customLanding) {
                mon.transform.position = Configuration.customPosition;
                mon.transform.rotation = Quaternion.Euler(Configuration.customRotation.x, Configuration.customRotation.y, Configuration.customRotation.z);
                eventFlag = true;
            }
            else foreach (var monument in TerrainMeta.Path.Monuments) if (monument.name == "assets/bundled/prefabs/autospawn/monument/large/airfield_1.prefab") {
                mon.transform.position = monument.transform.position;
                mon.transform.rotation = monument.transform.rotation;
                eventFlag = true;
                break;
            }
            CreateWaypoints(mon);
            if (randomEventTime) remainToEvent = Random.Range(minimumRemainToEvent, maximumRemainToEvent);
            if (!eventFlag) Puts("Airfield not found on map, event will not start! You can set up a custom landing spot for your cargo plane");
            else {
                if (!Configuration.customLanding) Puts("Airfield found on map, event will start in " + remainToEvent.ToString() + " seconds");
                else Puts("Cargoplane will land at a custom airfield, event will start in " + remainToEvent.ToString() + " seconds");
            }
            switch (typeNpcs) {
                case 0 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/tunneldweller/npc_tunneldweller.prefab";
                break;
                case 1 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/underwaterdweller/npc_underwaterdweller.prefab";
                break;
                case 2 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_excavator.prefab";
                break;
                case 3 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_full_any.prefab";
                break;
                case 4 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_full_lr300.prefab";
                break;
                case 5 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_full_mp5.prefab";
                break;
                case 6 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_full_pistol.prefab";
                break;
                case 7 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_full_shotgun.prefab";
                break;
                case 8 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_heavy.prefab";
                break;
                case 9 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_junkpile_pistol.prefab";
                break;
                case 10 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_oilrig.prefab";
                break;
                case 11 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_patrol.prefab";
                break;
                case 12 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_peacekeeper.prefab";
                break;
                case 13 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_roam.prefab";
                break;
                case 14 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_roamtethered.prefab";
                break;
                case 15 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/banditguard/npc_bandit_guard.prefab";
                break;
                case 16 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_cargo.prefab";
                break;
                case 17 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_cargo_turret_any.prefab";
                break;
                case 18 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_cargo_turret_lr300.prefab";
                break;
                case 19 : npcPrefab = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_ch47_gunner.prefab";
                break;
            }
            if (eventFlag) timer.Every(1f, () => {
                remain--;
                if (remain < 0 && planeEntity == null) EventStart();
            }
            );
        }
        void SaveConfig(object config) => Config.WriteObject(config, true);
        void LoadConfig() {
            base.Config.Settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
            Configuration = Config.ReadObject<ConfigData>();
            SaveConfig(Configuration);
        }
        private void CreateWaypoints(GameObject monument) {
            dir = monument.transform.position - monument.transform.right * 1000f - monument.transform.up * -2f - monument.transform.forward * 43.5f;
            airfieldPosition = monument.transform.position;
            airfieldRotation = monument.transform.rotation;
            planeWayPoints.Add(monument.transform.position - monument.transform.right - monument.transform.up * -1200f - monument.transform.forward * 1500f);
            planeWayPoints.Add(monument.transform.position - monument.transform.right * -4500 - monument.transform.up * -1200f - monument.transform.forward * 1300f);
            planeWayPoints.Add(monument.transform.position - monument.transform.right * -3700 - monument.transform.up * -1200f - monument.transform.forward * 550f);
            planeWayPoints.Add(monument.transform.position - monument.transform.right * -3000 - monument.transform.up * -900f - monument.transform.forward * 43.5f);
            for (float i = -2100; i < -150f; i += 78.64f) planeWayPoints.Add(monument.transform.position - monument.transform.right * i - monument.transform.up * i / 2.6f - monument.transform.forward * 43.5f - Vector3.up * 45f);
            planeWayPoints.Add(monument.transform.position - monument.transform.right * -100f - monument.transform.up * -4f - monument.transform.forward * 43.5f);
            planeWayPoints.Add(monument.transform.position - monument.transform.right * 80f - monument.transform.up * -2f - monument.transform.forward * 43.5f);
            for (float i = 160f; i < 2100; i += 78.64f) planeWayPoints.Add(monument.transform.position - monument.transform.right * i + monument.transform.up * i / 2.6f - monument.transform.forward * 43.5f - Vector3.up * 45f);
            planeWayPoints.Add(monument.transform.position - monument.transform.right * 12000f - monument.transform.up * -700f - monument.transform.forward * 43.5f);
            planeWayPoints.Add(monument.transform.position - monument.transform.right * 13000f - monument.transform.up * -700f - monument.transform.forward * 43.5f);
        }
        private void EventCalc() {
            if (planeEntity) {
                if (Vector3.Distance(planeEntity.transform.position, planeWayPoints[stage]) < speed) {
                    stage++;
                    ChangeSpeed(stage);
                }
                planeEntity.transform.rotation = oldRot;
                Vector3 lTargetDir = planeWayPoints[stage] - planeEntity.transform.position;
                planeEntity.transform.rotation = Quaternion.RotateTowards(planeEntity.transform.rotation, Quaternion.LookRotation(lTargetDir), rotationSpeed);
                var direction = planeEntity.transform.forward;
                planeEntity.transform.position += direction * speed;
                oldRot = planeEntity.transform.rotation;
                if (fix) planeEntity.transform.LookAt(dir);
            }
        }
        void DrawMarker() {
            string markerPrefab = "assets/prefabs/tools/map/genericradiusmarker.prefab";
            marker = GameManager.server.CreateEntity(markerPrefab, airfieldPosition).GetComponent<MapMarkerGenericRadius>();
            markerPrefab = "assets/prefabs/deployable/vendingmachine/vending_mapmarker.prefab";
            vending = GameManager.server.CreateEntity(markerPrefab, airfieldPosition).GetComponent<VendingMachineMapMarker>();
            vending.markerShopName = markerName;
            vending.enableSaving = false;
            vending.Spawn();
            marker.radius = markerRadius;
            marker.alpha = markerAlpha;
            marker.color1 = markerColor;
            marker.enableSaving = false;
            marker.Spawn();
            marker.SetParent(vending);
            marker.transform.localPosition = new Vector3(0, 0, 0);
            marker.SendUpdate();
            vending.SendNetworkUpdate();
            timer.Once(markerLifetime, () => {
                if (vending) vending.Kill();
            }
            );
        }
        protected override void LoadDefaultConfig() {
            var config = new ConfigData();
            SaveConfig(config);
        }
        private BaseHelicopter CallHeli(Vector3 destination) {
            var heli = (BaseHelicopter)GameManager.server.CreateEntity("assets/prefabs/npc/patrol helicopter/patrolhelicopter.prefab", new Vector3(), new Quaternion(), true);
            if (heli == null) return null;
            var heliAI = heli?.GetComponent<PatrolHelicopterAI>() ?? null;
            if (heliAI == null) return null;
            heliAI.SetInitialDestination(destination, 0.25f);
            heli.Spawn();
            heli.name = heliName;
            heli.SetMaxHealth(heliHealth);
            heli.Heal(heliHealth);
            timer.Repeat(10f, patrolTime * 6, () => {
                if (heli) heliAI.SetTargetDestination(airfieldPosition + new Vector3(Random.Range(-150, 150), 25f, Random.Range(-150, 150)), 5f, 30f);
            }
            );
            return heli;
        }
        void ChangeSpeed(int stage) {
            switch (stage) {
                case 5 : fix = true;
                break;
                case 22 : speed = maxSpeed / 1.2f;
                break;
                case 26 : speed = maxSpeed / 1.4f;
                break;
                case 30 : if (callHeli) CallHeli(airfieldPosition + new Vector3(Random.Range(-150, 150), 25f, Random.Range(-150, 150)));
                if (eventMarker && afterLanding) DrawMarker();
                speed = maxSpeed / 1.6f;
                timer.Repeat(6.5f / (dropsAmount + 1), dropsAmount, () => {
                    SpawnDrop();
                }
                );
                break;
                case 31 : fix = false;
                break;
                case 32 : speed = maxSpeed / 1.4f;
                break;
                case 34 : speed = maxSpeed / 1.2f;
                break;
                case 36 : speed = maxSpeed;
                break;
                case 38 : speed = maxSpeed * 1.1f;
                break;
                case 40 : speed = maxSpeed * 1.2f;
                break;
                case 42 : speed = maxSpeed * 1.4f;
                break;
                case 57 : eventTimer.Destroy();
                planeEntity.Kill();
                Puts("Event ended");
                break;
            }
        }
        void SpawnDrop() {
            Vector3 pos;
            xSum++;
            for (int i = 0; i < supplyAmount; i++) {
                float offset = 2f;
                pos = planeEntity.transform.position - planeEntity.transform.forward * 12f + Vector3.up * 2f - planeEntity.transform.right * supplyAmount + planeEntity.transform.right * i * offset;
                var drop = GameManager.server.CreateEntity(supplyPrefab, pos, airfieldRotation);
                drop.Spawn();
                entityList.Add(drop);
                if (drop is SupplyDrop) {
                    SupplyDrop supplyDrop = drop as SupplyDrop;
                    var box = supplyDrop.GetComponent<Rigidbody>();
                    supplyDrop.RemoveParachute();
                    box.drag = 1f;
                    timer.Once(lifeTimeSupply, () => {
                        if (drop) drop.Kill();
                    }
                    );
                }
            }
            List<BaseEntity> tempBotsList = new List<BaseEntity>();
            List<Vector3> tempWayPointsList = new List<Vector3>();
            for (int i = 0; i < npcsAmount; i++) {
                float x = i;
                int offset = 0;
                if (x / 2 == (int)(x / 2)) offset = 9;
                pos = planeEntity.transform.position - planeEntity.transform.forward * offset - planeEntity.transform.forward * Random.Range(5, 9) - planeEntity.transform.right * npcsAmount / 2f + planeEntity.transform.right * i;
                pos.y = dir.y - 1.7f;
                var npc = GameManager.server.CreateEntity(npcPrefab, pos, new Quaternion(), true);
                npc.Spawn();
                entityList.Add(npc);
                BasePlayer player = npc as BasePlayer;
                player.name = npcName;
                player.displayName = Configuration.displayNameNPC;
                ScientistBrain brain = npc.GetComponent<ScientistBrain>();
                BaseNavigator navigator = npc.GetComponent<BaseNavigator>();
                NpcBrain brainNPC = npc.gameObject.AddComponent<NpcBrain>();
                brain.AttackRangeMultiplier = 10f;
                brain.VisionCone = -1;
                brain.SenseRange = npcAttackRange;
                brain.ListenRange = 15f;
                brain.SenseTypes = EntityType.Player;
                brain.MemoryDuration = 5f;
                brain.TargetLostRange = npcAttackRange;
                brain.CheckVisionCone = false;
                brain.CheckLOS = true;
                brain.IgnoreNonVisionSneakers = true;
                brain.HostileTargetsOnly = false;
                brain.IgnoreSafeZonePlayers = false;
                brain.RefreshKnownLOS = true;
                navigator.CanUseNavMesh = false;
                brainNPC.homePosition = pos;
                brainNPC.stateTimer = 5;
                brainNPC.moveChance = 22;
                timer.Once(1f, () => {
                    if (npc) MoveToPosition(brain, navigator, npc.transform.position + Vector3.forward * 0.1f, 0);
                }
                );
                if (!npcForceFreeze) timer.Every(3f, () => {
                    if (npc) NpcAI(npc);
                }
                );
                int y = npcsAmount * (xSum - 1) + i;
                if (y < Configuration.displayNamesListNPC.Count) if (Configuration.displayNamesListNPC[y] != null) player.displayName = Configuration.displayNamesListNPC[y];
                if (y < kitsListNPC.Count) if (kitsListNPC[y] != null) {
                    if (Kits?.Call("IsKit", kitsListNPC[y]).ToString() == "True") {
                        player.inventory.Strip();
                        Kits?.Call("GiveKit", player, kitsListNPC[y]);
                    }
                }
                if (npcHealth > 0) {
                    player.startHealth = npcHealth;
                    player.health = npcHealth;
                }
                timer.Once(lifeTimeNpcs, () => {
                    if (npc) npc.Kill();
                }
                );
                tempBotsList.Add(npc);
            }
            botList.Add(tempBotsList);
            timer.Once(0.1f, () => AddWayPoints(planeEntity.transform.position - planeEntity.transform.forward * 15, 20));
            for (int i = 0; i < cratesAmount; i++) {
                float offset = 2f;
                pos = planeEntity.transform.position - planeEntity.transform.forward * 10f + Vector3.up * 2f - planeEntity.transform.right * cratesAmount + planeEntity.transform.right * i * offset;
                var crate = GameManager.server.CreateEntity(cratePrefab, pos, airfieldRotation);
                crate.Spawn();
                entityList.Add(crate);
                HackableLockedCrate ent = crate.GetComponent<HackableLockedCrate>();
                ent.hackSeconds = 900 - Configuration.timerCrates;
                timer.Once(lifeTimeCrates, () => {
                    if (crate) {
                        ent = crate.GetComponent<HackableLockedCrate>();
                        if (ent.hackSeconds == 900 - Configuration.timerCrates) crate.Kill();
                    }
                }
                );
            }
        }
        public void AddWayPoints(Vector3 center, float radius) {
            List<Vector3> tempWayPointsList = new List<Vector3>();
            float off = 1;
            for (float i = -radius / 2 + off; i < radius / 2 + off; i += 1) for (float ii = -radius / 2 + off; ii < radius / 2 + off; ii += 1) {
                RaycastHit check;
                Vector3 offset = new Vector3(i, 0, ii);
                if (Physics.Raycast(center + offset + Vector3.up * 100, Vector3.down, out check, 200, layerS)) {
                    BaseEntity entity = check.GetEntity();
                    if (!entity) tempWayPointsList.Add(check.point);
                }
            }
            wayPointsList.Add(tempWayPointsList);
        }
        public void NpcAI(BaseEntity npc) {
            BaseNavigator navigator = npc.GetComponent<BaseNavigator>();
            ScientistBrain brain = npc.GetComponent<ScientistBrain>();
            NpcBrain x = npc.gameObject.GetComponent<NpcBrain>();
            List<Vector3> wayPoints = new List<Vector3>();
            int speed = 0;
            int s = 0;
            foreach (var item in botList) {
                for (int i = 0; i < item.Count; i++) if (npc == item[i]) wayPoints = wayPointsList[s];
                s++;
            }
            if (brain.Senses.Players.Count == 0) {
                if (x.stateTimer == 0) {
                    brain.SwitchToState(AIState.Idle, 0);
                    x.moveChance = 22;
                }
                x.stateTimer--;
            }
            else {
                x.stateTimer = coolDownTime;
                speed = 1;
                x.moveChance = 100;
                if (brain.Senses.Players[0]) if (Vector3.Distance(brain.Senses.Players[0].transform.position, npc.transform.position) < chaseRadius) {
                    float xx = UnityEngine.Random.Range(-2, 2);
                    float zz = UnityEngine.Random.Range(-2, 2);
                    Vector3 offset = new Vector3(xx, 0, zz);
                    x.targetPosition = brain.Senses.Players[0].transform.position + offset;
                    MoveToPosition(brain, navigator, x.targetPosition, 1);
                    return;
                }
            }
            if (Vector3.Distance(npc.transform.position, x.homePosition) < homeRadius) {
                if (!navigator.Moving) {
                    var chanсe = UnityEngine.Random.Range(0, 100);
                    if (chanсe < x.moveChance) {
                        var y = UnityEngine.Random.Range(0, wayPoints.Count);
                        Vector3 point = wayPoints[y] + Vector3.up * 0.5f;
                        RaycastHit check;
                        Vector3 vec = new Vector3(point.x - npc.transform.position.x, point.y - npc.transform.position.y, point.z - npc.transform.position.z);
                        if (!Physics.Raycast(npc.transform.position + Vector3.up * 0.5f, vec, out check, Vector3.Distance(npc.transform.position, point), layerS)) x.targetPosition = wayPoints[y];
                        else x.targetPosition = check.point - Vector3.Normalize(vec) * 0.5f;
                        MoveToPosition(brain, navigator, x.targetPosition, speed);
                    }
                }
            }
            else if (x.stateTimer < 0) MoveToPosition(brain, navigator, x.homePosition, 1);
        }
        public void MoveToPosition(ScientistBrain brain, BaseNavigator navigator, Vector3 pos, int moveSpeed) {
            var speed = BaseNavigator.NavigationSpeed.Slow;
            if (moveSpeed == 1) speed = BaseNavigator.NavigationSpeed.Fast;
            navigator.CanUseNavMesh = true;
            brain.Navigator.SetDestination(pos, speed, 0f, 0f);
            navigator.CanUseNavMesh = false;
        }
        void EventStart() {
            if (eventFlag) {
                RemoveEvent();
                entityList.Clear();
                botList.Clear();
                wayPointsList.Clear();
                xSum = 0;
                if (planeEntity == null) {
                    if (eventMarker && !afterLanding) DrawMarker();
                    Puts("Event started");
                    remain = remainToEvent;
                    string prefabstr = "assets/prefabs/npc/cargo plane/cargo_plane.prefab";
                    planeEntity = GameManager.server.CreateEntity(prefabstr, new Vector3(0, 1000, 0), new Quaternion(), false);
                    planeEntity.Spawn();
                    stage = 0;
                    speed = maxSpeed;
                    oldRot = planeEntity.transform.rotation;
                    fix = false;
                    eventTimer = timer.Every(0.1f, () => {
                        EventCalc();
                    }
                    );
                    if (message != null) foreach (BasePlayer player in BasePlayer.activePlayerList) player.ChatMessage(message);
                }
                else Puts("The event is already running");
                if (randomEventTime) remainToEvent = Random.Range(minimumRemainToEvent, maximumRemainToEvent);
                Puts("Next event will start in " + remainToEvent.ToString() + " seconds");
            }
        }
        [Command("afe_addcustom")]
        private void afe_addcustom(IPlayer iplayer) {
            var player = (BasePlayer)iplayer.Object;
            if (player) if (player.IsAdmin) {
                PlayerEyes capsule = player.GetComponentInChildren<PlayerEyes>();
                GameObject monument = new GameObject();
                monument.transform.rotation = Quaternion.Euler(capsule.rotation.eulerAngles.x, capsule.rotation.eulerAngles.y + 90, capsule.rotation.eulerAngles.z);
                monument.transform.position = capsule.transform.position - monument.transform.right * 100f - monument.transform.up * 0.3f - monument.transform.forward * -43.5f;
                planeWayPoints.Clear();
                CreateWaypoints(monument);
                player.SendConsoleCommand("ddraw.text", 30f, Color.green, planeWayPoints[29], "<size=24>start</size>");
                player.SendConsoleCommand("ddraw.text", 30f, Color.green, planeWayPoints[30], "<size=24>end</size>");
                player.SendConsoleCommand("ddraw.arrow", 30, Color.green, planeWayPoints[29], planeWayPoints[30], 2f);
                player.ChatMessage("Cargo plane landing site has been successfully added and saved");
                Configuration.customRotation = new Vector3(monument.transform.rotation.eulerAngles.x, monument.transform.rotation.eulerAngles.y, monument.transform.rotation.eulerAngles.z);
                Configuration.customPosition = monument.transform.position;
                SaveConfig(Configuration);
            }
        }
        [Command("afestart")]
        private void afestart(IPlayer iplayer) {
            var player = (BasePlayer)iplayer.Object;
            if (!player || player.IsAdmin) EventStart();
        }
        [Command("afefast")]
        private void afefast(IPlayer iplayer) {
            var player = (BasePlayer)iplayer.Object;
            if (!player || player.IsAdmin) {
                if (planeEntity == null) {
                    EventStart();
                    timer.Once(1f, () => {
                        if (planeEntity) {
                            planeEntity.transform.position = planeWayPoints[20];
                            planeEntity.transform.LookAt(dir);
                            oldRot = planeEntity.transform.rotation;
                            stage = 21;
                            fix = true;
                        }
                    }
                    );
                    timer.Once(30f, () => {
                        if (planeEntity) {
                            planeEntity.transform.position = planeWayPoints[56];
                            stage = 56;
                        }
                    }
                    );
                }
                else Puts("The event is already running");
            }
        }
        void OnPlayerSleepEnded(BasePlayer player) {
            if (vending != null) {
                marker.SendUpdate();
                vending.SendNetworkUpdate();
            }
        }
        void OnServerShutdown() {
            RemoveEvent();
        }
        void Unload() {
            RemoveEvent();
        }
        void RemoveEvent() {
            if (planeEntity) planeEntity.Kill();
            if (vending) vending.Kill();
            for (int i = 0; i < entityList.Count; i++) if (entityList[i]) entityList[i].Kill();
        }
        private void OnEntityTakeDamage(BaseEntity entity, HitInfo info) {
            var killer = info.Initiator;
            if (killer) {
                switch (killer.name) {
                    case npcName : info.damageTypes.ScaleAll(npcDamageMultiplier);
                    break;
                    case heliName : info.damageTypes.ScaleAll(heliDamageMultiplier);
                    break;
                }
                if (entity.name == npcName) if (Vector3.Distance(entity.transform.position, killer.transform.position) > Configuration.npcMinDistToDmg) info.damageTypes.ScaleAll(0);
            }
        }
    }
}

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

Другие ресурсы пользователя 15FPS

Сверху