From f029299c3a60df8301a4ab32ab693b672798e8ad Mon Sep 17 00:00:00 2001 From: David Gay Date: Sun, 23 May 2021 17:50:06 -0400 Subject: Have equipment stats affect combat stats --- app/controllers/bazaar_controller.rb | 4 ++-- app/models/character.rb | 31 ++++++++++++++++++++++++------- data/items.yml | 30 +++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/app/controllers/bazaar_controller.rb b/app/controllers/bazaar_controller.rb index b31e8fb..b699d28 100644 --- a/app/controllers/bazaar_controller.rb +++ b/app/controllers/bazaar_controller.rb @@ -38,7 +38,7 @@ class BazaarController < ApplicationController current_char.shift_item(@bazaar_order.item, -quantity) current_char.shift_item("vestige", profit) @bazaar_order.character.shift_item(@bazaar_order.item, quantity) - @bazaar_order.decrement!(:quantity, quantity) + @bazaar_order.decrement(:quantity, quantity) @bazaar_order.save! flash[:notice] = "You sold #{quantity} #{@bazaar_order.item.name} and got #{profit} vg." end @@ -49,7 +49,7 @@ class BazaarController < ApplicationController current_char.shift_item("vestige", -cost) current_char.shift_item(@bazaar_order.item, quantity) @bazaar_order.character.shift_item("vestige", cost) - @bazaar_order.decrement!(:quantity, quantity) + @bazaar_order.decrement(:quantity, quantity) @bazaar_order.save! flash[:notice] = "You bought #{quantity} #{@bazaar_order.item.name} for #{cost} vg." end diff --git a/app/models/character.rb b/app/models/character.rb index 003f8af..fd0f540 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -45,7 +45,7 @@ class Character < ApplicationRecord item = Item.find_by_gid(item) if item.is_a? String CharacterItem.transaction do ci = self.character_items.find_or_initialize_by(item: item) - ci.increment!(:quantity, amount) + ci.increment(:quantity, amount) ci.save! end end @@ -138,32 +138,49 @@ class Character < ApplicationRecord self.update(activity: activity, activity_started_at: Time.now) if self.can_do_activity?(activity) end + def equipment_stats + stats = {} + self.equipment.each do |eq| + eq.item.whatnot[:effects]&.each do |effect| + if effect[:type] == "stat" + stats[effect[:gid]] ||= 0 + stats[effect[:gid]] += effect[:modifier] + end + end + end + stats + end + def can_fight? self.wounds < 1 end def max_hp - 10 + self.beastslay_level + 10 + self.beastslay_level + (equipment_stats["max_hp"] || 0) end def speed - self.beastslay_level + self.beastslay_level + (equipment_stats["speed"] || 0) end def accuracy - self.beastslay_level + self.beastslay_level + (equipment_stats["accuracy"] || 0) end def power - self.beastslay_level + self.beastslay_level + (equipment_stats["power"] || 0) end def evasion - self.beastslay_level + self.beastslay_level + (equipment_stats["evasion"] || 0) end def block - self.beastslay_level + self.beastslay_level + (equipment_stats["block"] || 0) + end + + def block_value + equipment_stats["block_value"] || 0 end private diff --git a/data/items.yml b/data/items.yml index f97d339..48e9b22 100644 --- a/data/items.yml +++ b/data/items.yml @@ -28,12 +28,32 @@ pig_iron_ingot: iron_ingot: name: "iron ingot" description: "A simple bar of iron." +iron_dagger: + name: "Iron dagger" + description: "A dagger made of iron." + whatnot: + equip_slots: + - "mainhand" + effects: + - type: "stat" + gid: "accuracy" + modifier: 2 + - type: "stat" + gid: "power" + modifier: 2 iron_short_sword: name: "Iron short sword" description: "A short sword made of iron." whatnot: equip_slots: - "mainhand" + effects: + - type: "stat" + gid: "accuracy" + modifier: 3 + - type: "stat" + gid: "power" + modifier: 3 iron_longsword: name: "Iron longsword" description: "A longsword made of iron." @@ -42,7 +62,15 @@ iron_longsword: - "mainhand" equip_requirements: skills: - beastslay: 3 + - gid: "beastslay" + level: 3 + effects: + - type: "stat" + gid: "accuracy" + modifier: 4 + - type: "stat" + gid: "power" + modifier: 4 mending_salve: name: "Mending salve" description: "A healing mixture capable of closing wounds." -- cgit v1.2.3