Example #1
0
        /// <summary>
        /// Fires the weapon
        /// </summary>
        public override void Fire()
        {
            var facingRightFactor = this.Mech.IsFacingRight ? 1 : -1;

            // Set overriding animation
            this.Animatable.PlayClip("fire", 1, true);
            this.EquippedOnArm.PlayClip(this.ArmAnimationClipName, 1, true);

            // Set shoot pellet count
            int   shootCount = (int)this.PelletCount;
            float diff       = this.PelletCount - shootCount;

            if (GlobalRandom.NextFloat() < diff)
            {
                shootCount++;
            }

            // Camera shake
            MainCamera.CurrentInstance.Shake(this.ScreenShake);

            // Adjust knock back
            var hitX        = this.BaseHit.KnockBack.x * facingRightFactor;
            var adjustedHit = new WeaponHitStat(this.BaseHit);

            adjustedHit.KnockBack = new Vector2(hitX, this.BaseHit.KnockBack.y);

            // Apply recoil
            var recoilX = -this.BaseStats.Recoil * facingRightFactor;

            this.Mech.ApplyKnockback(new Vector2(recoilX, 0), this.BaseStats.Recoil, 0);

            // Fire  all pellets
            for (int shoot = 0; shoot < shootCount; shoot++)
            {
                // Determine inaccuracy
                var inaccuracy = (100 - this.BaseStats.Accuracy) / 200 * GlobalRandom.NextFloat() * Mathf.PI;
                if (GlobalRandom.NextBool())
                {
                    inaccuracy *= -1;
                }

                var shootX = Mathf.Cos(inaccuracy) * facingRightFactor;
                var shootY = Mathf.Sin(inaccuracy);

                var rayCastHits = Physics2D.RaycastAll(this.MuzzleLocation.transform.position, new Vector2(shootX, shootY));
                for (var i = 0; i < rayCastHits.Length; i++)
                {
                    var curHit   = rayCastHits[i];
                    var hittable = curHit.collider.GetComponent <IHittable>();
                    if (hittable != null && hittable.Faction != adjustedHit.Faction)
                    {
                        hittable.OnHit(adjustedHit);
                        var newBullet = Instantiate(this.BulletLinePrefab);
                        newBullet.OnBulletHit(this.MuzzleLocation.transform.position, curHit);
                        break;
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 public WeaponHitStat(WeaponHitStat hit)
 {
     this.Damage         = hit.Damage;
     this.HitStunSeconds = hit.HitStunSeconds;
     this.Impact         = hit.Impact;
     this.KnockBack      = hit.KnockBack;
     this.Faction        = hit.Faction;
 }