public override void Pickup(PlayerHandler ph)
    {
        AmmunitionInventory ai = ph.ammo;

        if (ai != null)
        {
            bool hasBeenConsumed = false;
            for (int i = 0; i < System.Enum.GetValues(typeof(AmmunitionType)).Length; i++)
            {
                AmmunitionType a = (AmmunitionType)i;
                if (ai.GetStock(a) < ai.GetMax(a))
                {
                    int amountToRestore = Mathf.RoundToInt(ai.GetMax(a) * (percentageValue / 100));
                    amountToRestore = Mathf.Clamp(amountToRestore, 1, ai.GetMax(a));
                    ai.Collect(a, amountToRestore);
                    hasBeenConsumed = true;
                }
            }

            if (hasBeenConsumed == true)
            {
                Destroy(gameObject);
            }
        }
    }
    // Checks if the player is capable of carrying this ammunition, and that they have empty space to carry it.
    public override bool CanPlayerInteract(PlayerHandler ph)
    {
        AmmunitionInventory ai = ph.ammo;

        if (ai != null && ai.GetStock(ammoData.ammoType) < ai.GetMax(ammoData.ammoType))
        {
            return(true);
        }

        return(false);
    }
예제 #3
0
    private void Awake()
    {
        ph  = GetComponent <PlayerHealth>();
        pc  = GetComponent <PlayerController>();
        wh  = GetComponent <WeaponHandler>();
        a   = GetComponent <AmmunitionInventory>();
        hud = GetComponent <HeadsUpDisplay>();
        gsh = GetComponent <GameStateHandler>();

        playerAudio = GetComponent <AudioSource>();
    }
    public override void Awake()
    {
        movement     = GetComponent <PlayerController>();
        weapons      = GetComponent <WeaponHandler>();
        ammo         = GetComponent <AmmunitionInventory>();
        stateHandler = GetComponent <GameStateHandler>();

        audio = GetComponent <AudioSource>();


        hud.player = this;

        base.Awake();
    }
예제 #5
0
    public override void Pickup(Collider c)
    {
        AmmunitionInventory ai = c.GetComponent <AmmunitionInventory>();

        if (ai != null && ai.GetStock(ammoType) <= ai.GetMax(ammoType))
        {
            amount -= ai.Collect(ammoType, amount);
            if (amount <= 0)
            {
                Destroy(gameObject);
            }

            base.Pickup(c);
        }
    }
예제 #6
0
    public override void Pickup(Collider c)
    {
        AmmunitionInventory ai = c.GetComponent <AmmunitionInventory>();

        if (ai != null)
        {
            for (int i = 0; i < System.Enum.GetValues(typeof(AmmunitionType)).Length; i++)
            {
                AmmunitionType a = (AmmunitionType)i;
                if (a != AmmunitionType.None)
                {
                    int amountToRestore = Mathf.RoundToInt(ai.GetMax(a) * (percentageValue / 100));
                    ai.Collect(a, amountToRestore);
                }
            }
        }

        base.Pickup(c);
    }
    public override void Pickup(PlayerHandler ph)
    {
        AmmunitionInventory ai = ph.GetComponent <AmmunitionInventory>();

        if (ai != null)
        {
            if (ai.GetStock(ammoType) < ai.GetMax(ammoType))
            {
                amount -= ai.Collect(ammoType, amount);
                if (amount <= 0)
                {
                    Destroy(gameObject);
                }
                else
                {
                    base.Pickup(ph);
                }
            }
        }
    }