예제 #1
0
            private void SpawnGuns()
            {
                var rotation = mainBoat.transform.rotation;
                var position = mainBoat.transform.position;

                BaseEntity entity = GameManager.server.CreateEntity("assets/prefabs/npc/autoturret/autoturret_deployed.prefab", position, rotation, true);

                entity.SetParent(mainBoat, 0);
                entity.transform.localPosition    = new Vector3(0f, 1.2f, 4.2f);
                entity.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
                entity?.Spawn();

                turret = entity.GetComponent <AutoTurret>();
                turret.SetPeacekeepermode(true);
                turret.InitializeControl(null);
                turret.UpdateFromInput(100, 0);
                turret.isLootable = false;
                turret.dropChance = 0;

                spawnedEntities.Add(entity);

                turret.inventory.Clear();

                ItemManager.CreateByName("lmg.m249", 1).MoveToContainer(turret.inventory, 0);
                ItemManager.CreateByName("ammo.rifle", 1000).MoveToContainer(turret.inventory, 1);

                turret.UpdateAttachedWeapon();
                turret.Reload();
            }
예제 #2
0
        void UpdateAutoTurret(AutoTurret turret, bool justCreated = false)
        {
            CheckAutoTurretAmmo(turret);

            string userID = turret.OwnerID.ToString();

            float  turretHealth = FromPermission(userID, autoHealths, defaultAutoHealth);
            string ammoType     = FromPermission(userID, ammoTypes, defaultAmmoType);

            InitializeTurret(turret, turretHealth, justCreated);

            turret.bulletSpeed = FromPermission(userID, bulletSpeeds, defaultBulletSpeed);
            turret.sightRange  = FromPermission(userID, sightRanges, defaultSightRange);
            turret.aimCone     = FromPermission(userID, aimCones, defaultAimCone);

            var def = ItemManager.FindItemDefinition(ammoType);

            if (def is ItemDefinition)
            {
                turret.ammoType = def;
                ItemModProjectile projectile = def.GetComponent <ItemModProjectile> ();
                if (projectile is ItemModProjectile)
                {
                    turret.gun_fire_effect.guid = projectile.projectileObject.guid;
                    turret.bulletEffect.guid    = projectile.projectileObject.guid;
                }
            }
            else
            {
                PrintWarning("No ammo of type ({0})", ammoType);
            }

            turret.Reload();
            turret.SendNetworkUpdateImmediate(justCreated);
        }
예제 #3
0
        private void UpdateTurret(AutoTurret turret, bool justCreated = false)
        {
            CheckAmmo(turret);

            string userID = turret.OwnerID.ToString();

            float  turretHealth = GetHealth(userID);
            string ammoType     = GetAmmoType(userID);

            bulletDamageField.SetValue(turret, GetBulletDamage(userID));
            if (justCreated)
            {
                healthField.SetValue(turret, turretHealth);
            }
            maxHealthField.SetValue(turret, turretHealth);

            if (justCreated)
            {
                turret.InitializeHealth(turretHealth, turretHealth);
            }
            else
            {
                turret.InitializeHealth(turret.health, turretHealth);
            }

            turret.bulletSpeed = GetBulletSpeed(userID);
            turret.sightRange  = GetSightRange(userID);
            turret.startHealth = turretHealth;
            turret.aimCone     = GetAimCone(userID);

            var def = ItemManager.FindItemDefinition(ammoType);

            if (def is ItemDefinition)
            {
                turret.ammoType = def;
                ItemModProjectile projectile = def.GetComponent <ItemModProjectile>();
                if (projectile is ItemModProjectile)
                {
                    turret.gun_fire_effect.guid = projectile.projectileObject.guid;
                    turret.bulletEffect.guid    = projectile.projectileObject.guid;
                }
            }
            else
            {
                PrintWarning("No ammo of type ({0})", ammoType);
            }

            turret.Reload();

            //turret.enableSaving = false;
            //turret.ServerInit();
            turret.SendNetworkUpdateImmediate(justCreated);
        }