Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function that simulates loot drops in RPG games:
- function getRndLoot() {
- const lootTable = [
- {item: "health potion", chance: 0.2},
- {item: "speed potion", chance: 1.2},
- {item: "rare coin", chance: 1.1},
- ];
- const randomNum = Math.random();
- var selectedItem = null;
- for(const loot of lootTable) {
- if(randomNum < loot.chance) {
- selectedItem = loot.item;
- break;
- }
- }
- return selectedItem || `no loot`;
- }
- const droppedItem = getRndLoot();
- console.log(droppedItem)
- // function that tracks quests completed by players:
- const completedQuests = [];
- function completeQuest(questName) {
- if(!completedQuests.includes(questName)) {
- completedQuests.push(questName);
- }
- }
- completeQuest("Find Darkost in the Armageddon");
- completeQuest("Retrieve the crown from the forgotten dungeon");
- console.log(`Completed quests: ${completedQuests.join(', ')}`);
- // function that simulates combat system:
- function simulateCombat(playerHP, enemyHP) {
- while (playerHP > 0 && enemyHP > 0) {
- const playerDamage = Math.floor(Math.random() * 20) + 1;
- enemyHP -= playerDamage;
- const enemyDamage =
- Math.floor(Math.random() * 8) + 1;
- playerHP -= enemyDamage;
- }
- if(playerHP <= 0) {
- console.log("You DIED");
- } else {
- console.log("You have WON");
- }
- }
- const playerHealth = 100;
- const enemyHealth = 80;
- simulateCombat(playerHealth, enemyHealth);
- //function that generates random loot from treasure chests:
- function openChest() {
- const possibleLoot = ["gold", "medkit", "magic wand", "gemstone"];
- const randomLoot = Math.floor(Math.random() * possibleLoot.length);
- return possibleLoot[randomLoot];
- }
- const foundLoot = openChest();
- console.log(foundLoot);
- // function that handles skill leveling
- const playerSkills = {
- attack: 1,
- defense: 1,
- magic: 1,
- };
- function levelUpSkill(skill) {
- playerSkills[skill] += 1
- }
- levelUpSkill("attack");
- console.log(playerSkills.attack);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement