Module: Buy
- Defined in:
- lib/lotrd/controller/storeBuy.rb
Class Method Summary collapse
Class Method Details
.armour(item) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/lotrd/controller/storeBuy.rb', line 53 def armour(item) system 'clear' puts "Hephy's Forge -> Armours Menu -> Armour Purchase" + "\n" + "=" * 40 + "\n"*2 player = YAML.load(File.read(ENV['HOME'] + "/." + "playerdata.yml")) arm_stats = YAML.load(File.read("lib/lotrd/model/arm_stats.yml")) gold = player.gold armour = player.armour hp = player.hp str = player.str int = player.int agi = player.agi dex = player.dex lck = player.lck cost = arm_stats.fetch(item).fetch(:cost).to_i if cost > gold ::Store.deficit else if armour != nil hp += arm_stats.fetch(item).fetch(:playerHP) - arm_stats.fetch(armour).fetch(:playerHP) str += arm_stats.fetch(item).fetch(:playerStr) - arm_stats.fetch(armour).fetch(:playerStr) agi += arm_stats.fetch(item).fetch(:playerAgi) - arm_stats.fetch(armour).fetch(:playerAgi) int += arm_stats.fetch(item).fetch(:playerInt) - arm_stats.fetch(armour).fetch(:playerInt) dex += arm_stats.fetch(item).fetch(:playerDex) - arm_stats.fetch(armour).fetch(:playerDex) lck += arm_stats.fetch(item).fetch(:playerLck) - arm_stats.fetch(armour).fetch(:playerLck) puts "You discarded your #{armour} and put on the shiny #{item}!" else hp += arm_stats.fetch(item).fetch(:playerHP) str += arm_stats.fetch(item).fetch(:playerStr) agi += arm_stats.fetch(item).fetch(:playerAgi) int += arm_stats.fetch(item).fetch(:playerInt) dex += arm_stats.fetch(item).fetch(:playerDex) lck += arm_stats.fetch(item).fetch(:playerLck) puts "You put on the #{item}. It's good to be less naked!" end gold -= cost armour = item end player.gold = gold player.armour = armour player.hp = hp player.str = str player.agi = agi player.dex = dex player.int = int player.lck = lck File.open(ENV['HOME'] + "/." + "playerdata.yml", 'w') {|file| File.write(ENV['HOME'] + "/." + "playerdata.yml", player.to_yaml)} sleep(3) ::Store. end |
.weapon(item) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lotrd/controller/storeBuy.rb', line 6 def weapon(item) system 'clear' puts "Hephy's Forge -> Weapons Menu -> Weapon Purchase" + "\n" + "=" * 40 + "\n"*2 player = YAML.load(File.read(ENV['HOME'] + "/." + "playerdata.yml")) weap_stats = YAML.load(File.read("lib/lotrd/model/weap_stats.yml")) gold = player.gold weapon = player.weapon hp = player.hp str = player.str int = player.int agi = player.agi dex = player.dex lck = player.lck cost = weap_stats.fetch(item).fetch(:cost).to_i if cost > gold ::Store.deficit else if weapon != nil str += weap_stats.fetch(item).fetch(:playerStr) - weap_stats.fetch(weapon).fetch(:playerStr) agi += weap_stats.fetch(item).fetch(:playerAgi) - weap_stats.fetch(weapon).fetch(:playerAgi) int += weap_stats.fetch(item).fetch(:playerInt) - weap_stats.fetch(weapon).fetch(:playerInt) dex += weap_stats.fetch(item).fetch(:playerDex) - weap_stats.fetch(weapon).fetch(:playerDex) lck += weap_stats.fetch(item).fetch(:playerLck) - weap_stats.fetch(weapon).fetch(:playerLck) puts "You threw away your #{weapon} and picked up the gleaming #{item}!" else str += weap_stats.fetch(item).fetch(:playerStr) agi += weap_stats.fetch(item).fetch(:playerAgi) int += weap_stats.fetch(item).fetch(:playerInt) dex += weap_stats.fetch(item).fetch(:playerDex) lck += weap_stats.fetch(item).fetch(:playerLck) puts "You give your new #{item} a flourish. It'll be good to stop hitting things with your bare knuckles." end gold -= cost weapon = item end player.gold = gold player.weapon = weapon player.str = str player.agi = agi player.dex = dex player.int = int player.lck = lck File.open(ENV['HOME'] + "/." + "playerdata.yml", 'w') {|file| File.write(ENV['HOME'] + "/." + "playerdata.yml", player.to_yaml)} sleep(3) ::Store. end |