Exemple #1
0
        /// <summary>
        /// Gets called whenever a player interacts with a ammo-supply.
        /// </summary>
        /// <param name="ammoPickedUp"></param>
        public override void OnEvent(AmmoPickedUp ammoPickedUp)
        {
            //Get the player-state of the player who interacted with it.
            var playerState = ammoPickedUp.Player.GetState <IPlayer>();

            //Get the weapon the ammo is intended to.
            var targetWeapon = playerState.Weapons[ConvertWeaponNameToId(ammoPickedUp.AmmoType)];

            //Get the ammo-pickup-state.
            var ammoPickupState = ammoPickedUp.ObjectEntity.GetState <IAmmoPickup>();

            //Cancel if player has no such weapon equipped or if the ammo-pickup has no more ammo left to pickup.
            if (!targetWeapon.IsEquipped || ammoPickupState.AmmoAmount <= 0)
            {
                return;
            }

            //Calculate the amount that can be added.
            var canAddAmount = targetWeapon.MaxCarryAmmo - targetWeapon.EntireAmmo;

            if (ammoPickupState.AmmoAmount >= canAddAmount)
            {
                targetWeapon.EntireAmmo    += canAddAmount;
                ammoPickupState.AmmoAmount -= canAddAmount;
            }
            else
            {
                targetWeapon.EntireAmmo   += ammoPickupState.AmmoAmount;
                ammoPickupState.AmmoAmount = 0;
            }
        }
Exemple #2
0
        public override void Interact(BoltEntity boltEntity)
        {
            var ammoPickedUp = AmmoPickedUp.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered);

            ammoPickedUp.Player       = boltEntity;
            ammoPickedUp.AmmoType     = state.AmmoType;
            ammoPickedUp.AmmoAmount   = state.AmmoAmount;
            ammoPickedUp.ObjectEntity = entity;
            ammoPickedUp.Send();
        }