diff options
author | David Gay <david@davidgay.org> | 2021-05-22 15:39:16 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-22 15:39:16 -0400 |
commit | 38f3a39221869483e3468e9f4d8cab5450a70f89 (patch) | |
tree | ef831c35d61e05b46c356d39e30ecc6d6f7353b1 /app/controllers/characters | |
parent | 88bd4f77db3a4372c118a9faef613615db66bc52 (diff) |
Equiping and unequiping items
Diffstat (limited to 'app/controllers/characters')
-rw-r--r-- | app/controllers/characters/items_controller.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/app/controllers/characters/items_controller.rb b/app/controllers/characters/items_controller.rb index e1a30f8..8df23c8 100644 --- a/app/controllers/characters/items_controller.rb +++ b/app/controllers/characters/items_controller.rb @@ -1,5 +1,24 @@ class Characters::ItemsController < ApplicationController def index - @character_items = Character.find(params[:character_id]).character_items + @character = Character.find(params[:character_id]) + end + + def equip + @item = Item.find(params[:item_id]) + current_char.equip(@item) + flash[:notice] = "Equipped #{@item.name}." + rescue EquipmentError + flash[:alert] = "Couldn't equip #{@item.name}." + ensure + redirect_to character_items_path(current_char) + end + + def unequip + current_char.unequip(params[:slot].to_sym) + flash[:notice] = "Unequipped item." + rescue EquipmentError + flash[:alert] = "Couldn't unequip item." + ensure + redirect_to character_items_path(current_char) end end |