Ejemplo n.º 1
0
 public void OnUpdate(float ms)
 {
     foreach (IPlayer plr in Game.GetPlayers())
     {
         RifleWeaponItem rifle = plr.CurrentPrimaryWeapon;
         if (rifle.PowerupBouncingRounds == 0 && rifle.PowerupFireRounds == 0)
         {
             // WeaponMagCapacity > 1 indicates it's a shotgun.
             // Let just the very last shell in shotguns be bouncing.
             if (rifle.WeaponMagCapacity == 1 && rifle.CurrentAmmo == 1 || rifle.TotalAmmo == 1)
             {
                 plr.SetCurrentPrimaryWeaponAmmo(1, ProjectilePowerup.Bouncing);
             }
         }
         // Same logic for secondary weapons
         HandgunWeaponItem handgun = plr.CurrentSecondaryWeapon;
         if (handgun.PowerupBouncingRounds == 0 && handgun.PowerupFireRounds == 0)
         {
             // WeaponMagCapacity > 1 indicates it's a shotgun.
             // Let just the very last shell in shotguns be bouncing.
             if (handgun.WeaponMagCapacity == 1 && handgun.CurrentAmmo == 1 || handgun.TotalAmmo == 1)
             {
                 plr.SetCurrentSecondaryWeaponAmmo(1, ProjectilePowerup.Bouncing);
             }
         }
     }
 }
Ejemplo n.º 2
0
            public void BreakWeapon(bool isExplosion)
            {
                IPlayer pl = User.GetPlayer();

                if (pl != null && !pl.IsDead)
                {
                    if (pl.CurrentWeaponDrawn == WeaponItemType.Rifle)
                    {
                        if (GlobalRandom.Next(0, 100) < (int)(WeaponBreakingChance * Armor.BreakWeaponFactor))
                        {
                            Vector2         pos    = pl.GetWorldPosition();
                            RifleWeaponItem weapon = pl.CurrentPrimaryWeapon;
                            if ((weapon.WeaponItem == WeaponItem.BAZOOKA || weapon.WeaponItem == WeaponItem.GRENADE_LAUNCHER ||
                                 weapon.WeaponItem == WeaponItem.FLAMETHROWER) && weapon.CurrentAmmo > 0 && (GlobalRandom.Next(0, 100) < WeaponExplosionChance || isExplosion))
                            {
                                GlobalGame.TriggerExplosion(pos);
                            }
                            pl.RemoveWeaponItemType(WeaponItemType.Rifle);
                            GlobalGame.PlayEffect("CFTXT", pl.GetWorldPosition(), "WEAPON BROKEN");
                            GlobalGame.CreateObject("MetalDebris00A", pos, (float)rnd.NextDouble());
                            pos.X += 5;
                            GlobalGame.CreateObject("MetalDebris00B", pos, (float)rnd.NextDouble());
                            pos.X -= 10;
                            GlobalGame.CreateObject("MetalDebris00C", pos, (float)rnd.NextDouble());
                        }
                    }
                }
            }
Ejemplo n.º 3
0
        public static void ApplyWeaponMod(TPlayer player, int id)
        {
            IPlayer pl = player.User.GetPlayer();

            switch (id)
            {
            case 1:
            {
                pl.GiveWeaponItem(WeaponItem.LAZER);
                break;
            }

            case 2:
            {
                WeaponItem first  = pl.CurrentPrimaryWeapon.WeaponItem;
                WeaponItem second = pl.CurrentSecondaryWeapon.WeaponItem;
                if (ExtraAmmoWeapon.Contains(first))
                {
                    pl.GiveWeaponItem(first);
                }
                if (ExtraAmmoWeapon.Contains(second))
                {
                    pl.GiveWeaponItem(second);
                }
                break;
            }

            case 3:
            {
                WeaponItem first  = pl.CurrentPrimaryWeapon.WeaponItem;
                WeaponItem second = pl.CurrentSecondaryWeapon.WeaponItem;
                WeaponItem thrown = pl.CurrentThrownItem.WeaponItem;
                if (ExtraExplosiveWeapon.Contains(first))
                {
                    pl.GiveWeaponItem(first);
                }
                if (ExtraExplosiveWeapon.Contains(second))
                {
                    pl.GiveWeaponItem(second);
                }
                if (ExtraExplosiveWeapon.Contains(thrown))
                {
                    pl.GiveWeaponItem(thrown);
                }
                break;
            }

            case 4:
            {
                WeaponItem first  = pl.CurrentPrimaryWeapon.WeaponItem;
                WeaponItem second = pl.CurrentSecondaryWeapon.WeaponItem;
                if (ExtraHeavyAmmoWeapon.Contains(first))
                {
                    pl.GiveWeaponItem(first);
                    player.HasExtraHeavyAmmo = true;
                    DebugLogger.DebugOnlyDialogLog("player.HasExtraHeavyAmmo = " + player.HasExtraHeavyAmmo);
                }
                if (ExtraHeavyAmmoWeapon.Contains(second))
                {
                    pl.GiveWeaponItem(second);
                    player.HasExtraHeavyAmmo = true;
                    DebugLogger.DebugOnlyDialogLog("player.HasExtraHeavyAmmo = " + player.HasExtraHeavyAmmo);
                }
                break;
            }

            case 5:
            {
                if (player.PrimaryWeapon != null)
                {
                    player.PrimaryWeapon.DNAProtection = true;
                    player.PrimaryWeapon.TeamDNA       = player.Team;
                }
                else if (player.SecondaryWeapon != null)
                {
                    player.SecondaryWeapon.DNAProtection = true;
                    player.SecondaryWeapon.TeamDNA       = player.Team;
                }
                break;
            }

            case 6:
            {
                if (player.PrimaryWeapon != null && pl.CurrentPrimaryWeapon.WeaponItem != WeaponItem.FLAMETHROWER)
                {
                    RifleWeaponItem first = pl.CurrentPrimaryWeapon;
                    int[]           ammo  = CalculateSpecialAmmoPrimary(first);
                    pl.SetCurrentPrimaryWeaponAmmo(ammo[0], ammo[1], ProjectilePowerup.Bouncing);
                    pl.GiveWeaponItem(first.WeaponItem);
                }
                else if (player.SecondaryWeapon != null)
                {
                    HandgunWeaponItem second = pl.CurrentSecondaryWeapon;
                    int[]             ammo   = CalculateSpecialAmmoSecondary(second);
                    pl.SetCurrentSecondaryWeaponAmmo(ammo[0], ammo[1], ProjectilePowerup.Bouncing);
                    pl.GiveWeaponItem(second.WeaponItem);
                }
                break;
            }

            case 7:
            {
                if (player.PrimaryWeapon != null && pl.CurrentPrimaryWeapon.WeaponItem != WeaponItem.FLAMETHROWER)
                {
                    RifleWeaponItem first = pl.CurrentPrimaryWeapon;
                    int[]           ammo  = CalculateSpecialAmmoPrimary(first);
                    pl.SetCurrentPrimaryWeaponAmmo(ammo[0], ammo[1], ProjectilePowerup.Fire);
                    pl.GiveWeaponItem(first.WeaponItem);
                }
                else if (player.SecondaryWeapon != null)
                {
                    HandgunWeaponItem second = pl.CurrentSecondaryWeapon;
                    int[]             ammo   = CalculateSpecialAmmoSecondary(second);
                    pl.SetCurrentSecondaryWeaponAmmo(ammo[0], ammo[1], ProjectilePowerup.Fire);
                    pl.GiveWeaponItem(second.WeaponItem);
                }
                break;
            }
            }
        }
Ejemplo n.º 4
0
 public static int[] CalculateSpecialAmmoPrimary(RifleWeaponItem primary)
 {
     int[] ammo = { (int)Math.Ceiling((double)primary.MaxTotalAmmo / 4), 0 };
     return(ammo);
 }
Ejemplo n.º 5
0
            public void WeaponTrackingUpdate(bool onlyAdd)
            {
                IPlayer           pl     = User.GetPlayer();
                RifleWeaponItem   rifle  = pl.CurrentPrimaryWeapon;
                HandgunWeaponItem pistol = pl.CurrentSecondaryWeapon;
                ThrownWeaponItem  thrown = pl.CurrentThrownItem;

                if (onlyAdd)
                {
                    if (rifle.WeaponItem != WeaponItem.NONE)
                    {
                        if (PrimaryWeapon == null)
                        {
                            PrimaryWeapon = new TWeapon(rifle.WeaponItem);
                        }
                        PrimaryWeapon.TotalAmmo = rifle.TotalAmmo;
                    }
                    if (pistol.WeaponItem != WeaponItem.NONE)
                    {
                        if (SecondaryWeapon == null)
                        {
                            SecondaryWeapon = new TWeapon(pistol.WeaponItem);
                        }
                        SecondaryWeapon.TotalAmmo = pistol.TotalAmmo;
                    }
                    if (thrown.WeaponItem != WeaponItem.NONE)
                    {
                        if (ThrownWeapon == null)
                        {
                            ThrownWeapon = new TWeapon(thrown.WeaponItem);
                        }
                        ThrownWeapon.TotalAmmo = thrown.CurrentAmmo;
                    }
                    return;
                }
                if (rifle.WeaponItem == WeaponItem.NONE && PrimaryWeapon != null)
                {
                    PrimaryWeapon = null;
                }
                else if ((PrimaryWeapon == null && rifle.WeaponItem != WeaponItem.NONE) ||
                         (PrimaryWeapon != null && (rifle.WeaponItem != PrimaryWeapon.Weapon || PrimaryWeapon.TotalAmmo < rifle.TotalAmmo)))
                {
                    TWeapon pickUp = PlayerPickUpWeaponUpdate(Position, rifle.WeaponItem);
                    if (pickUp != null)
                    {
                        PrimaryWeapon = pickUp;
                    }
                    else
                    {
                        PrimaryWeapon = new TWeapon(rifle.WeaponItem);
                    }
                    PrimaryWeapon.TotalAmmo = rifle.TotalAmmo;
                }
                else if (PrimaryWeapon != null && rifle.TotalAmmo < PrimaryWeapon.TotalAmmo)
                {
                    PrimaryWeapon.TotalAmmo = rifle.TotalAmmo;
                    if (!pl.IsReloading)
                    {
                        PrimaryWeapon.OnFire(this, WeaponItemType.Rifle);
                    }
                }
                if (pistol.WeaponItem == WeaponItem.NONE && SecondaryWeapon != null)
                {
                    SecondaryWeapon = null;
                }
                else if ((SecondaryWeapon == null && pistol.WeaponItem != WeaponItem.NONE) ||
                         (SecondaryWeapon != null && (pistol.WeaponItem != SecondaryWeapon.Weapon || SecondaryWeapon.TotalAmmo < pistol.TotalAmmo)))
                {
                    TWeapon pickUp = PlayerPickUpWeaponUpdate(Position, pistol.WeaponItem);
                    if (pickUp != null)
                    {
                        SecondaryWeapon = pickUp;
                    }
                    else
                    {
                        SecondaryWeapon = new TWeapon(pistol.WeaponItem);
                    }
                    SecondaryWeapon.TotalAmmo = pistol.TotalAmmo;
                }
                else if (SecondaryWeapon != null && pistol.TotalAmmo < SecondaryWeapon.TotalAmmo)
                {
                    SecondaryWeapon.TotalAmmo = pistol.TotalAmmo;
                    if (!pl.IsReloading)
                    {
                        SecondaryWeapon.OnFire(this, WeaponItemType.Handgun);
                    }
                }
                if (thrown.WeaponItem == WeaponItem.NONE && ThrownWeapon != null)
                {
                    if (!IsPlayerDropWeapon(Position, thrown.WeaponItem))
                    {
                        ThrownWeapon.OnFire(this, WeaponItemType.Thrown);
                    }
                    ThrownWeapon = null;
                }
                else if ((ThrownWeapon == null && thrown.WeaponItem != WeaponItem.NONE) ||
                         (ThrownWeapon != null && (thrown.WeaponItem != ThrownWeapon.Weapon || ThrownWeapon.TotalAmmo < thrown.CurrentAmmo)))
                {
                    TWeapon pickUp = PlayerPickUpWeaponUpdate(Position, thrown.WeaponItem);
                    if (pickUp != null)
                    {
                        if (ThrownWeapon != null && ThrownWeapon.CustomId != pickUp.CustomId)
                        {
                            pickUp.CustomId = 0;
                        }
                        ThrownWeapon = pickUp;
                    }
                    else
                    {
                        ThrownWeapon = new TWeapon(thrown.WeaponItem);
                    }
                    ThrownWeapon.TotalAmmo = thrown.CurrentAmmo;
                }
                else if (ThrownWeapon != null && thrown.CurrentAmmo < ThrownWeapon.TotalAmmo)
                {
                    ThrownWeapon.TotalAmmo = thrown.CurrentAmmo;
                    ThrownWeapon.OnFire(this, WeaponItemType.Thrown);
                }
                if (PrimaryWeapon != null)
                {
                    PrimaryWeapon.Update();
                }
                if (SecondaryWeapon != null)
                {
                    SecondaryWeapon.Update();
                }
                if (ThrownWeapon != null)
                {
                    ThrownWeapon.Update();
                }
            }