コード例 #1
0
        public int DealDamage(int[] health, HUD ui, bool isEnemy, int[] shield = null) // calculates damage and deals it out
        {
            int damageToHealth = -1;

            //calculate damage
            damageToHealth = Toolkit.RandomNumBetween(_damage[0], _damage[1]); //random runber between a high and low value
            int damageToShield = damageToHealth;                               //names for convenience and to display to HUD textbox
            int passDamage     = 0;                                            // null if not passing

            if (shield != null)                                                /// this if statement could alternatively be in enemy.dealdamage() but it was moved here and now makes more sense
            {
                // calculate spill damage
                int calcDamageSpill = damageToShield - shield[(int)STATUS.CURRENT];

                // deal damage to player shield
                shield[(int)STATUS.CURRENT] -= damageToShield;

                // passes spill damage and sets stat to limit
                if (shield[(int)STATUS.CURRENT] < 0)
                {
                    passDamage = calcDamageSpill;
                }
                shield[(int)STATUS.CURRENT] = SetStatToLimits(shield[(int)STATUS.CURRENT], shield[(int)STATUS.MAX]);
            }

            if (shield == null || shield[(int)STATUS.CURRENT] == 0)
            {
                // calculate damage
                if (passDamage != 0)
                {
                    damageToHealth = passDamage;
                }                                                     // sets the damage to the leftover shield break damage

                //deal damage to character health and checks the limits
                health[(int)STATUS.CURRENT] -= damageToHealth;
                health[(int)STATUS.CURRENT]  = SetStatToLimits(health[(int)STATUS.CURRENT], health[(int)STATUS.MAX]); // does nothing if limit doesnt break
            }

            if (!isEnemy)
            {
                //update player HUD bar
                ui.setHudHealthAndShield(health, shield);
                ui.Draw();
            }

            //sets damage to total amount of damage done if it spills into health
            if (passDamage != 0)
            {
                damageToHealth = damageToShield;
            }
            return(damageToHealth);
        }
コード例 #2
0
        public void UseShieldPot(Player player, Item item, HUD hud)
        {
            if (stockItems[(int)ITEM.POTSHELL] > 0)
            {
                DecreaseStock(ITEM.POTSHELL);
                player.HealShell(item.Power(Global.ITEM_AVATAR(ITEM.POTSHELL)), this, hud);

                //update HUD bar and display to HUD text box
                hud.setHudHealthAndShield(player.Health(), player.Shield());
                hud.Draw();// updates visible inventory
                hud.UpdateHotBar(player, this);
            }
            else
            {
                hud.DisplayText($"< {player.Name()} {Global.MESSAGE_POTSHIELDMISSING} >", false);
            }
        }