示例#1
0
        private AttackResult CalculateAttackResults(Weapon weapon, int hand, LivingObject target)
        {
            int toHit;
            int RtoHit;
            int totalDamage = 0;
            int bonus = 0;
            int defence;
            string attackResult = "";
            string dmgTypeText = "";
            WeaponProficiency wp;
            DamageType dt;
            AttackResult Result = new AttackResult();

            //select damage type
            if(hand == 1)
            {
                if (SelectedRightWeaponDamage == 0)
                {
                    dmgTypeText = Game.Lang[StringName.PROTECTION_PIERCE_ABRV];
                    dt = DamageType.PIERCE;
                }
                else if (SelectedRightWeaponDamage == 1)
                {
                    dmgTypeText = Game.Lang[StringName.PROTECTION_CUT_ABRV];
                    dt = DamageType.CUT;
                }
                else
                {
                    dmgTypeText = Game.Lang[StringName.PROTECTION_BLUNT_ABRV];
                    dt = DamageType.BLUNT;
                }
            }
            else
            {
                if (SelectedLeftWeaponDamage == 0)
                {
                    dmgTypeText = Game.Lang[StringName.PROTECTION_PIERCE_ABRV];
                    dt = DamageType.PIERCE;
                }
                else if (SelectedLeftWeaponDamage == 1)
                {
                    dmgTypeText = Game.Lang[StringName.PROTECTION_CUT_ABRV];
                    dt = DamageType.CUT;
                }
                else
                {
                    dmgTypeText = Game.Lang[StringName.PROTECTION_BLUNT_ABRV];
                    dt = DamageType.BLUNT;
                }
            }
            
            //get weapon proficiency
            wp = GetWeaponProficiency(weapon.WeaponClass);
            //calculate toHit
            toHit = calculateToHit(wp);
            defence = ((Monster)target).Defence.actualValue;
            RtoHit = Math.Max(toHit - defence, 5);
            
            int roll = Dice.Roll("d100");
            if (roll <= RtoHit)
            {
                //hit
                int[] dmg = calculateMeleeDamage(wp, weapon);
                if (hand == 1)
                {
                    totalDamage = dmg[SelectedRightWeaponDamage];
                }
                else
                {
                    totalDamage = dmg[SelectedLeftWeaponDamage];
                }
                roll = Dice.Roll("d100");
                if (roll > 50)
                {
                    bonus = roll - 50;
                }
                else if (roll < 50)
                {
                    bonus = roll - 50;
                }
                totalDamage += bonus;
                if (totalDamage < 0)
                {
                    totalDamage = 0;
                }
                attackResult = Game.Lang[StringName.ATTACK_ANDDEALT_TEXT] + totalDamage + " " + dmgTypeText + Game.Lang[StringName.ATTACK_DAMAGE_TEXT];
            }
            else
            {
                //miss
                attackResult = Game.Lang[StringName.ATTACK_MISSED_TEXT];
            }
            bool isDead = target.takeDamage(totalDamage, dt);
            if (isDead)
            {
                attackResult = Game.Lang[StringName.ATTACK_KILLED_TEXT];
            }
            Result.Text = attackResult;
            Result.IsKilled = isDead;
            return Result;
        }
示例#2
0
        /*public bool changePlayerState(PlayerStates state)
        {
            //depends on state, some are exclusive, some are inclusive
            switch (state)
            {
                case PlayerStates.BURDEN:
                    {
                        if (_states[(int)state])
                        {
                            _states[(int)PlayerStates.NORMAL] = true;
                            _states[(int)PlayerStates.IMMOBILIZED] = false;
                            return _states[(int)state] = !_states[(int)state];
                        }
                        else
                        {
                            _states[(int)PlayerStates.NORMAL] = false;
                            _states[(int)PlayerStates.IMMOBILIZED] = false;
                            return _states[(int)state] = !_states[(int)state];
                        }
                        
                    }
                case PlayerStates.IMMOBILIZED:
                    {
                        if (_states[(int)state])
                        {
                            _states[(int)PlayerStates.NORMAL] = true;
                            _states[(int)PlayerStates.BURDEN] = false;
                            return _states[(int)state] = !_states[(int)state];
                        }
                        else
                        {
                            _states[(int)PlayerStates.NORMAL] = false;
                            _states[(int)PlayerStates.BURDEN] = false;
                            return _states[(int)state] = !_states[(int)state];
                        }
                    }
                case PlayerStates.NORMAL:
                    {
                        //normal state we only set to true and only when we want to cancel all other states
                        _states[(int)PlayerStates.BURDEN] = false;
                        _states[(int)PlayerStates.IMMOBILIZED] = false;
                        return _states[(int)state] = true;
                    }
                default: return true;
            }
            
        }*/

        public void Attack(LivingObject target)
        {
            int defence;
            string attackResult = "";
            WeaponProficiency wp;
            Weapon w;
            AttackResult ar;
            //check if player has weapon equipped
            if (_inventory.IsWeaponEquipped)
            {
                //check if weapon is in right hand
                if (!_inventory[5].IsEmpty && _inventory[5].Item.ItemClass == ItemClass.WEAPON)
                {
                    w = _inventory[5].Item as Weapon;
                    defence = ((Monster)target).Defence.actualValue;
                    ar = CalculateAttackResults(w, 1, target);
                    attackResult = ar.Text;
                    Game.topTextArea.AddMessage(Game.Lang[StringName.ATTACK_ATTACKED_TEXT] + target.getDescription() + " with " + Game.Lang[_inventory[5].Item.Description].ToLower() + attackResult);
                    if (ar.IsKilled)
                    {
                        Exp += Game.KillMonster(target as Monster);
                        if (Exp >= PlayerClass.ExpTable[Level])
                        {
                            Game.leveledUp = true;
                        }
                        goto CalcStamina;
                    }
                }
                //check if weapon is in left hand
                if (!_inventory[6].IsEmpty && _inventory[6].Item.ItemClass == ItemClass.WEAPON)
                {
                    w = _inventory[6].Item as Weapon; 
                    defence = ((Monster)target).Defence.actualValue;
                    ar = CalculateAttackResults(w, 2, target);
                    attackResult = ar.Text;
                    Game.topTextArea.AddMessage(Game.Lang[StringName.ATTACK_ATTACKED_TEXT] + target.getDescription() + " with " + Game.Lang[_inventory[6].Item.Description].ToLower() + attackResult);
                    if (ar.IsKilled)
                    {
                        Exp += Game.KillMonster(target as Monster);
                        if (Exp >= PlayerClass.ExpTable[Level])
                        {
                            Game.leveledUp = true;
                        }
                        goto CalcStamina;
                    }
                }
                
            }
            //make unarmed attack
            else
            {
                bool isDead = false;
                int bonus = 0;
                //get weapon proficiency
                wp = GetWeaponProficiency(WeaponClass.BOX);
                string dmgTypeText = Game.Lang[StringName.PROTECTION_BLUNT_ABRV];
                int dmg;
                //calculate damage
                if (wp != null)
                {   
                    dmg = Convert.ToInt16((float)50 * (wp.Value / 100f)) + Convert.ToInt16(Math.Round(Stat[PrimaryStats.STRENGTH].currentValue / 4f));
                }
                else
                {
                    dmg = Convert.ToInt16(Math.Round(Stat[PrimaryStats.STRENGTH].currentValue / 4f));
                }
                int totalDamage = dmg;
                int toHit = calculateToHit(wp);
                int roll = Dice.Roll("d100");
                defence = ((Monster)target).Defence.actualValue;
                toHit -= defence;
                int RtoHit = Math.Max(toHit - defence, 5);
                if (roll <= RtoHit)
                {
                    roll = Dice.Roll("d100");
                    if (roll > 50)
                    {
                        bonus = roll - 50;
                    }
                    else if (roll < 50)
                    {
                        bonus = (roll * -1);
                    }
                    totalDamage += bonus;
                    isDead = target.takeDamage(totalDamage, DamageType.BLUNT);
                    if (isDead)
                    {
                        attackResult = Game.Lang[StringName.ATTACK_KILLED_TEXT];
                    }
                    else
                    {
                        attackResult = Game.Lang[StringName.ATTACK_ANDDEALT_TEXT] + totalDamage + " " + dmgTypeText + Game.Lang[StringName.ATTACK_DAMAGE_TEXT];
                    }
                }
                else
                {
                    attackResult = Game.Lang[StringName.ATTACK_MISSED_TEXT];
                }
                Game.topTextArea.AddMessage(Game.Lang[StringName.ATTACK_ATTACKED_TEXT] + target.getDescription() + " with " + Game.Lang[StringName.WEAPONCLASS_BOX].ToLower() + attackResult);
                if (isDead)
                {
                    Exp += Game.KillMonster(target as Monster);
                    if (Exp >= PlayerClass.ExpTable[Level])
                    {
                        Game.leveledUp = true;
                    }
                }
            }
            CalcStamina:
            //while burden you lose stamina twice as fast
            if (States[(int)PlayerStates.BURDEN])
            {
                ActualStamina -= 2;
            }
            else
            {
                ActualStamina -= 1;
            }
            Game.bottomPanel.needUpdate = true;
        }