Ejemplo n.º 1
0
    void Weapon.FireDown()
    {
        //start firing, button down
        if (firing && !automatic)
        {
            //print("firing must be false");
            return;
        }
        firing = true;
        //if enough time has not passed
        if (firingTime < coolDown * salvoMode)
        {
            //print ("not enough time has passed");
            return;
        }
        if (ammo <= 0)
        {
            //print ("out of ammo");
            return;
        }
        ammo--;
        int startSalvo = salvoIndex;

        for (int index = startSalvo; index < startSalvo + salvoMode; index++)
        {
            WeaponValues wv = weapons [index % weapons.Length];
            for (int i = 0; i < itemsPerHit; i++)
            {
                //spawn gameobject where it is
                GameObject g = (GameObject)GameObject.Instantiate(itemToShoot, wv.shootDir.position, Quaternion.identity);
                g.transform.LookAt(wv.shootDir.position);
                //need to call shoot because we will look at first
                RaycastBullet rb;
                if (rb = g.GetComponent <RaycastBullet> ())
                {
                    rb.damage = damage;
                    rb.SendMessage("Shoot", (wv.shootDir.position - wv.body.position));
                }
                Explosive ex;
                if (ex = g.GetComponent <Explosive> ())
                {
                    ex.damage = damage;
                }

                Rigidbody r;
                if (r = g.GetComponent <Rigidbody> ())
                {
                    r.velocity = myRigid.velocity;
                    r.AddForce((wv.shootDir.position - wv.body.position) * firingSpeed * 6000);
                }
                //play particle system (if exists)
                if (wv.particles)
                {
                    wv.particles.Play();
                }
            }
        }
        firingTime = 0;
        salvoIndex = (salvoIndex + salvoMode) % weapons.Length;
    }
Ejemplo n.º 2
0
        private void StorageSetup()
        {
            try
            {
                if (MyCube.Storage == null)
                {
                    State.StorageInit();
                }

                State.LoadState();
                Set.LoadSettings();
                CompMids.Load(this);

                if (!Session.IsClient)
                {
                    Set.Value.Overrides.TargetPainter      = false;
                    Set.Value.Overrides.ManualControl      = false;
                    State.Value.OtherPlayerTrackingReticle = false;
                }

                var maxTrajectory = 0f;
                for (int i = 0; i < Platform.Weapons.Length; i++)
                {
                    var weapon = Platform.Weapons[i];
                    weapon.Set   = Set.Value.Weapons[i];
                    weapon.State = State.Value.Weapons[i];

                    weapon.ActiveAmmoDef = weapon.System.WeaponAmmoTypes.Length > 0 ? weapon.System.WeaponAmmoTypes[weapon.Set.AmmoTypeId] : new WeaponAmmoTypes();

                    if (weapon.ActiveAmmoDef.AmmoDef == null || !weapon.ActiveAmmoDef.AmmoDef.Const.IsTurretSelectable)
                    {
                        Log.Line($"Your first ammoType is broken, I am crashing now Dave.");
                        return;
                    }

                    weapon.UpdateWeaponRange();
                    if (maxTrajectory < weapon.MaxTargetDistance)
                    {
                        maxTrajectory = (float)weapon.MaxTargetDistance;
                    }
                }

                if (Set.Value.Range < 0)
                {
                    Set.Value.Range = maxTrajectory;
                }

                WeaponValues.Load(this);
            }
            catch (Exception ex) { Log.Line($"Exception in StorageSetup: {ex} - StateNull:{State == null}({State?.Value == null})[{State?.Value?.Weapons == null}] - SetNull:{Set == null}({Set?.Value == null})[{Set?.Value?.Weapons == null}] - cubeMarked:{MyCube.MarkedForClose} - WeaponsNull:{Platform.Weapons == null} - FirstWeaponNull:{Platform.Weapons?[0] == null}"); }
        }
Ejemplo n.º 3
0
 public override bool IsSerialized()
 {
     if (Session.IsServer && Platform.State == MyWeaponPlatform.PlatformState.Ready)
     {
         if (MyCube?.Storage != null)
         {
             State.SaveState();
             Set.SaveSettings();
             WeaponValues.Save(this);
             SyncIds.Save(this);
         }
     }
     return(false);
 }