summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/controllers/characters/items_controller.rb7
-rw-r--r--app/models/character.rb13
-rw-r--r--app/models/item.rb13
-rw-r--r--data/items.yml60
5 files changed, 63 insertions, 31 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65a38ca..0b2273e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- Distill manadross tincture recipe awarded mending salve instead of manadross tincture.
+- Equip requirements were ignored.
## [0.1.3.1] - 2021-05-31
diff --git a/app/controllers/characters/items_controller.rb b/app/controllers/characters/items_controller.rb
index 722c8ff..470e21c 100644
--- a/app/controllers/characters/items_controller.rb
+++ b/app/controllers/characters/items_controller.rb
@@ -5,10 +5,15 @@ class Characters::ItemsController < ApplicationController
def equip
@item = Item.find(params[:item_id])
+ unless current_char.can_equip? @item
+ flash[:alert] = "Couldn't equip #{@item.name}"
+ flash[:alert] += " (requires #{@item.equip_requirements&.join(", ")})" if @item.equip_requirements.any?
+ return
+ end
current_char.equip(@item)
flash[:notice] = "Equipped #{@item.name}."
rescue EquipmentError
- flash[:alert] = "Couldn't equip #{@item.name}."
+ flash[:alert] = "Couldn't equip #{@item.name}. Make sure the slot is free."
ensure
redirect_to character_items_path(current_char)
end
diff --git a/app/models/character.rb b/app/models/character.rb
index 7e80d65..56be0c0 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -133,8 +133,21 @@ class Character < ApplicationRecord
end
end
+ def can_equip?(item)
+ item.whatnot[:equip_requirements]&.each do |requirement|
+ case requirement[:type]
+ when "skill"
+ return false unless self.skill_level(requirement[:gid]) >= requirement[:level]
+ else
+ raise "Invalid requirement type string (#{requirement[:type]})"
+ end
+ end
+ true
+ end
+
def equip(item)
Character.transaction do
+ raise EquipmentError unless self.can_equip?(item)
open_slots = self.open_slots_for(item)
raise EquipmentError unless open_slots.any?
self.shift_item(item, -1)
diff --git a/app/models/item.rb b/app/models/item.rb
index 1ef5d7d..8b80788 100644
--- a/app/models/item.rb
+++ b/app/models/item.rb
@@ -17,4 +17,17 @@ class Item < ApplicationRecord
return [] unless self.equipment?
self.whatnot[:equip_slots].map { |data| data.to_sym }
end
+
+ def equip_requirements
+ requirements = []
+ self.whatnot[:equip_requirements]&.each do |req|
+ case req[:type]
+ when "skill"
+ requirements.push "level #{req[:level]} #{Skill.find_by_gid(req[:gid]).name}"
+ else
+ raise "Invalid equip requirement type string (#{req[:type]})"
+ end
+ end
+ requirements
+ end
end
diff --git a/data/items.yml b/data/items.yml
index da5e6fb..394e97c 100644
--- a/data/items.yml
+++ b/data/items.yml
@@ -57,9 +57,9 @@ iron_short_sword:
equip_slots:
- "mainhand"
equip_requirements:
- skills:
- - gid: "beastslay"
- level: 2
+ - type: "skill"
+ gid: "beastslay"
+ level: 2
equip_effects:
- type: "stat_change"
gid: "accuracy"
@@ -74,9 +74,9 @@ iron_longsword:
equip_slots:
- "mainhand"
equip_requirements:
- skills:
- - gid: "beastslay"
- level: 5
+ - type: "skill"
+ gid: "beastslay"
+ level: 5
equip_effects:
- type: "stat_change"
gid: "accuracy"
@@ -104,9 +104,9 @@ iron_shield:
equip_slots:
- "offhand"
equip_requirements:
- skills:
- - gid: "beastslay"
- level: 3
+ - type: "skill"
+ gid: "beastslay"
+ level: 3
equip_effects:
- type: "stat_change"
gid: "block"
@@ -121,9 +121,9 @@ arcanite_dagger:
equip_slots:
- "mainhand"
equip_requirements:
- skills:
- - gid: "beastslay"
- level: 10
+ - type: "skill"
+ gid: "beastslay"
+ level: 10
equip_effects:
- type: "stat_change"
gid: "accuracy"
@@ -138,9 +138,9 @@ arcanite_short_sword:
equip_slots:
- "mainhand"
equip_requirements:
- skills:
- - gid: "beastslay"
- level: 12
+ - type: "skill"
+ gid: "beastslay"
+ level: 12
equip_effects:
- type: "stat_change"
gid: "accuracy"
@@ -155,9 +155,9 @@ arcanite_longsword:
equip_slots:
- "mainhand"
equip_requirements:
- skills:
- - gid: "beastslay"
- level: 15
+ - type: "skill"
+ gid: "beastslay"
+ level: 15
equip_effects:
- type: "stat_change"
gid: "accuracy"
@@ -170,9 +170,9 @@ arcanite_buckler:
description: "A buckler made of arcanite."
whatnot:
equip_requirements:
- skills:
- - gid: "beastslay"
- level: 10
+ - type: "skill"
+ gid: "beastslay"
+ level: 10
equip_slots:
- "offhand"
equip_effects:
@@ -189,9 +189,9 @@ arcanite_shield:
equip_slots:
- "offhand"
equip_requirements:
- skills:
- - gid: "beastslay"
- level: 13
+ - type: "skill"
+ gid: "beastslay"
+ level: 13
equip_effects:
- type: "stat_change"
gid: "block"
@@ -451,9 +451,9 @@ arcanite_pickaxe:
equip_slots:
- "mainhand"
equip_requirements:
- skills:
- - gid: "planequarry"
- level: 10
+ - type: "skill"
+ gid: "planequarry"
+ level: 10
equip_effects:
- type: "stat_change"
gid: "planequarry_speed"
@@ -471,9 +471,9 @@ arcanite_axe:
equip_slots:
- "mainhand"
equip_requirements:
- skills:
- - gid: "wealdreap"
- level: 10
+ - type: "skill"
+ gid: "wealdreap"
+ level: 10
equip_effects:
- type: "stat_change"
gid: "wealdreap_speed"