public void PlayerUseWeapon(Weapon weapon) { int attackRoll = RandomNumberGenerator.NumberBetween(1, 20) + _player.attackMod; if (attackRoll >= _monster.AC) { // Determine the amount of damage to do to the monster int damageToMonster = RandomNumberGenerator.NumberBetween(weapon.minimumDamage, weapon.maximumDamage) + _player.damageMod; // Apply the damage to the monster's CurrentHitPoints _monster.currentHitPoints -= damageToMonster; // Display message RaiseMessage("You hit the " + _monster.name + " for " + damageToMonster + " points."); } else { RaiseMessage("You missed the " + _monster.name + "!"); } }
public void UseWeapon(Weapon weapon) { int attackRoll = RandomNumberGenerator.NumberBetween(1, 20) + attackMod; if(attackRoll >= _currentMonster.AC) { // Determine the amount of damage to do to the monster int damageToMonster = RandomNumberGenerator.NumberBetween(weapon.minimumDamage, weapon.maximumDamage) + damageMod; // Apply the damage to the monster's CurrentHitPoints _currentMonster.currentHitPoints -= damageToMonster; // Display message RaiseMessage("You hit the " + _currentMonster.name + " for " + damageToMonster + " points."); } else { RaiseMessage("You missed the " + _currentMonster.name + "!"); } // Check if the monster is dead if (_currentMonster.currentHitPoints <= 0) { // Monster is dead RaiseMessage(""); RaiseMessage("You defeated the " + _currentMonster.name); // Give player experience points for killing the monster AddExperiencePoints(_currentMonster.rewardExperiencePoints); RaiseMessage("You receive " + _currentMonster.rewardExperiencePoints + " experience points"); // Give player gold for killing the monster gold += _currentMonster.rewardGold; RaiseMessage("You receive " + _currentMonster.rewardGold + " gold"); // Get random loot items from the monster List<InventoryItem> lootedItems = new List<InventoryItem>(); // Add items to the lootedItems list, comparing a random number to the drop percentage foreach (LootItem lootItem in _currentMonster.lootTable) { if (RandomNumberGenerator.NumberBetween(1, 100) <= lootItem.dropPercentage) { lootedItems.Add(new InventoryItem(lootItem.details, 1)); } } // If no items were randomly selected, then add the default loot item(s). if (lootedItems.Count == 0) { foreach (LootItem lootItem in _currentMonster.lootTable) { if (lootItem.isDefaultItem) { lootedItems.Add(new InventoryItem(lootItem.details, 1)); } } } // Add the looted items to the player's inventory foreach (InventoryItem inventoryItem in lootedItems) { AddItemToInventory(inventoryItem.details); if (inventoryItem.quantity == 1) { RaiseMessage("You loot " + inventoryItem.quantity + " " + inventoryItem.details.name); } else { RaiseMessage("You loot " + inventoryItem.quantity + " " + inventoryItem.details.namePlural); } } // Add a blank line to the messages box, just for appearance. RaiseMessage(""); // Move player to current location (to heal player and create a new monster to fight) MoveTo(currentLocation); } else { // Monster is still alive attackRoll = RandomNumberGenerator.NumberBetween(1, 20) + _currentMonster.attackMod; if(attackRoll >= AC) { // Determine the amount of damage the monster does to the player int damageToPlayer = RandomNumberGenerator.NumberBetween(_currentMonster.minimumDamage, _currentMonster.maximumDamage); // Display message RaiseMessage("The " + _currentMonster.name + " did " + damageToPlayer + " points of damage."); // Subtract damage from player currentHitPoints -= damageToPlayer; } if (currentHitPoints <= 0) { // Display message RaiseMessage("The " + _currentMonster.name + " killed you."); /* Keep for debug */ currentHitPoints = maximumHitPoints; // Move player to "Home" MoveHome(); } } }