Beispiel #1
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);
        }