GameEntities.PlayerCharacter.TakeBullets C# (CSharp) Method

TakeBullets() public method

public TakeBullets ( BulletType bulletType, int count ) : bool
bulletType BulletType
count int
return bool
        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;
        }

Usage Example

コード例 #1
0
ファイル: BulletItem.cs プロジェクト: gsaone/forklift
        protected override bool OnTake(Unit unit)
        {
            bool take = base.OnTake(unit);

            PlayerCharacter character = unit as PlayerCharacter;

            if (character != null)
            {
                bool taked  = false;
                bool taked2 = false;

                if (Type.BulletType != null)
                {
                    taked = character.TakeBullets(Type.BulletType, Type.BulletCount);
                }
                if (Type.BulletType2 != null)
                {
                    taked2 = character.TakeBullets(Type.BulletType2, Type.BulletCount2);
                }

                if (taked || taked2)
                {
                    take = true;
                }
            }

            return(take);
        }