Ejemplo n.º 1
0
        //Incin - give weapons to players
        public bool GiveWeapon(WeaponType weaponType, Unit unit)
        {
            Weapon          weapon          = null;
            PlayerCharacter playerCharacter = null;

            playerCharacter = unit as PlayerCharacter;

            int index = GetWeaponIndex(weaponType);

            if (index == -1)
            {
                return(false);
            }

            if (weapons[index].exists)
            {
                return(true);
            }

            weapons[index].exists = true;
            SetActiveWeapon(index);

            if (playerCharacter != null)
            {
                weapon = playerCharacter.ActiveWeapon;
            }
            else
            {
                return(false);
            }

            Gun gun = weapon as Gun;

            if (gun != null)
            {
                if (gun.Type.NormalMode != null && (gun.Type.NormalMode.BulletType != null && gun.Type.NormalMode.BulletCapacity != 0))
                {
                    gun.AddBullets(gun.Type.NormalMode.BulletType, gun.Type.NormalMode.BulletCapacity);
                    TakeBullets(gun.Type.NormalMode.BulletType, gun.Type.NormalMode.BulletCapacity);
                    //BulletItem bullet = (Bullet)gun.Type.NormalMode.BulletType.GetType();
                    //bullet.GiveBullets(unit);
                }
                else
                {
                    ;
                }

                if (gun.Type.AlternativeMode != null && (gun.Type.AlternativeMode.BulletType != null && gun.Type.AlternativeMode.BulletCapacity != 0))
                {
                    gun.AddBullets(gun.Type.AlternativeMode.BulletType, gun.Type.AlternativeMode.BulletCapacity);
                    TakeBullets(gun.Type.AlternativeMode.BulletType, gun.Type.AlternativeMode.BulletCapacity);
                }
                else
                {
                    ;
                }
            }

            return(true);
        }
        public bool TakeBullets(BulletType bulletType, int count)
        {
            bool taked = false;

            for (int n = 0; n < weapons.Count; n++)
            {
                GunType gunType = Type.Weapons[n].WeaponType as GunType;
                if (gunType == null)
                {
                    continue;
                }

                if (gunType.NormalMode.BulletType == bulletType)
                {
                    if (weapons[n].normalBulletCount < gunType.NormalMode.BulletCapacity)
                    {
                        taked = true;
                        weapons[n].normalBulletCount += count;
                        if (weapons[n].normalBulletCount > gunType.NormalMode.BulletCapacity)
                        {
                            weapons[n].normalBulletCount = gunType.NormalMode.BulletCapacity;
                        }
                    }
                }
                if (gunType.AlternativeMode.BulletType == bulletType)
                {
                    if (weapons[n].alternativeBulletCount < gunType.AlternativeMode.BulletCapacity)
                    {
                        taked = true;
                        weapons[n].alternativeBulletCount += count;
                        if (weapons[n].alternativeBulletCount > gunType.AlternativeMode.BulletCapacity)
                        {
                            weapons[n].alternativeBulletCount = gunType.AlternativeMode.BulletCapacity;
                        }
                    }
                }
            }

            if (ActiveWeapon != null)
            {
                Gun activeGun = activeWeapon as Gun;
                if (activeGun != null)
                {
                    activeGun.AddBullets(bulletType, count);
                }
            }

            return(taked);
        }