コード例 #1
0
    private int CalculateWeaponDamage(FloatingTextGUI ftg, MonsterAI target)
    {
        Weapon wep = playerNew.EquipedWeapon as Weapon;
        //For now all damage scales off Strength, this is set in scaling of PlayerNew

        int   critNum        = Random.Range(0, 100 + 1);
        bool  critHit        = false;
        float critChance     = playerNew.CritChance;
        float critMultiplier = playerNew.CritDamage;

        if (critNum < (critChance * 100))
        {
            critHit = true;
        }
        else
        {
            critHit = false;
        }


        //Random WepDamage
        physicalDamageDealt = Damage = Random.Range((int)(playerNew.MaxDamage * playerNew.DmgVariance), playerNew.MaxDamage + 1);

        if (critHit)
        {
            Damage = (int)(Damage * critMultiplier);
        }

        string damageString = ToolTipStyle.Red + Damage.ToString() + ToolTipStyle.EndColor;

        ftg.AddToText(damageString);

        //Random Elemental Damage
        if (playerNew.EquipedWeapon != null)
        {
            if (wep.DmgType != DamageType.Normal)
            {
                int eleDmg = Random.Range((int)(wep.DmgValue * wep.DmgVariance), wep.DmgValue + 1);

                if (critHit)
                {
                    eleDmg = (int)(eleDmg * critMultiplier);
                }

                Damage += eleDmg;
                //find color
                string eleDmgString = FindElementalDamageString(eleDmg, wep);
                ftg.AddToText(eleDmgString);
            }
        }

        if (critHit)
        {
            ftg.damageText.text = ToolTipStyle.Large + ToolTipStyle.Italic + ftg.damageText.text + ToolTipStyle.EndItalic + ToolTipStyle.EndSize;
        }

        return(Damage);
    }
コード例 #2
0
    public void DealDamage(int damage)
    {
        int damageToDeal = (int)Random.Range(damage * 0.3f, damage + 1);
        int baseDamage   = (int)(damageToDeal * Random.Range(0.1f, 0.2f));

        damageToDeal -= baseDamage;
        if (!Invincible)
        {
            //Armor blocks it
            damageToDeal -= _pc.PlayerArmor;


            GameObject dmgTxt = Instantiate(globalPrefabs.floatingDamageText, transform.position, Quaternion.identity) as GameObject;
            dmgTxt.transform.parent = this.transform;
            FloatingTextGUI dmgText = dmgTxt.GetComponent <FloatingTextGUI>();
            dmgText.PlayerDamage("", _pc.transform.position, 0.5f);

            //Chance to block (damage blocked always equal to Pc.DamageBlocked)
            int blockRandom = Random.Range(0, 100 + 1);

            if (blockRandom < (_pc.PlayerChanceToBlock * 100))
            {
                damageToDeal -= _pc.PlayerDamageBlocked;

                dmgText.AddToText(ToolTipStyle.Italic + "\t" + ToolTipStyle.Small + "Block!" + ToolTipStyle.EndSize + ToolTipStyle.EndItalic);
            }

            //deal the damage
            if (damageToDeal < 0)
            {
                damageToDeal = 0;
            }

            damageToDeal += baseDamage;             //will always do some damage

            dmgText.AddToText(ToolTipStyle.Break + ToolTipStyle.Brown + "-" + damageToDeal.ToString() + ToolTipStyle.EndColor);
            _pc.GetVital((int)VitalName.Health).CurValue -= damageToDeal;
        }
    }