Class: ItemLibrary::Chest
Constant Summary
Natural20::Entity::ALL_SKILLS, Natural20::Entity::ATTRIBUTE_TYPES, Natural20::Entity::ATTRIBUTE_TYPES_ABBV, Natural20::Entity::SKILL_AND_ABILITY_MAP
Instance Attribute Summary collapse
Attributes inherited from Object
#hp, #map, #name, #resistances, #statuses
#casted_effects, #current_hit_die, #death_fails, #death_saves, #effects, #entity_event_hooks, #entity_uid, #max_hit_die, #session, #statuses
Instance Method Summary
collapse
#retrieve, #store
Methods inherited from Object
#armor_class, #can_hide?, #concealed?, #cover_ac, #describe_health, #half_cover?, #initialize, #items_label, #jump_required?, #label, #light_properties, #movement_cost, #npc?, #object?, #pc?, #placeable?, #position, #size, #three_quarter_cover?, #total_cover?, #wall?
#list_notes
#ability_mod, #acrobatics_proficient?, #action?, #active_effects, #add_casted_effect, #add_item, #all_ability_mods, #all_ability_scores, #any_class_feature?, #athletics_proficient?, #attach_handler, #attack_ability_mod, #attack_roll_mod, #available_movement, #available_spells, #break_stealth!, #can_see?, #carry_capacity, #cha_mod, #check_equip, #class_feature?, #con_mod, #conscious!, #conscious?, #darkvision?, #dead!, #dead?, #death_saving_throw!, #deduct_item, #description, #dex_mod, #dexterity_check!, #disengage!, #disengage?, #dismiss_effect!, #dodge?, #dodging!, #drop_grapple!, #drop_items!, #entered_melee?, #equip, #equipped?, #equipped_items, #equipped_weapons, #escape_grapple_from!, #expertise, #expertise?, #free_object_interaction?, #grappled?, #grappled_by!, #grapples, #grappling, #grappling?, #grappling_targets, #hand_slots_required, #has_reaction?, #has_spell_effect?, #has_spells?, #heal!, #help!, #help?, #hiding!, #hiding?, #hit_die, #incapacitated?, #initiative!, #insight_proficient?, #int_mod, #inventory, #inventory_count, #inventory_weight, #investigation_proficient?, #item_count, #items_label, #label, #languages, #light_properties, #locate_melee_positions, #lockpick!, #long_jump_distance, #max_spell_slots, #medicine_check!, #medicine_proficient?, #melee_distance, #melee_squares, #npc?, #object?, #passive_perception, #pc?, #perception_proficient?, #proficiency_bonus, #proficient?, #proficient_with_armor?, #proficient_with_equipped_armor?, #proficient_with_weapon?, #prone!, #prone?, #push_from, #race, #ranged_spell_attack!, #register_effect, #register_event_hook, #reset_turn!, #resistant_to?, #saving_throw!, #sentient?, #shield_equipped?, #short_rest!, #size_identifier, #speed, #spell_slots, #squeezed!, #squeezed?, #stable!, #stable?, #stand!, #standing_jump_distance, #stealth_proficient?, #str_mod, #strength_check!, #take_damage!, #to_item, #token_size, #total_actions, #total_bonus_actions, #total_reactions, #trigger_event, #unconscious!, #unconscious?, #unequip, #unequip_all, #ungrapple, #unsqueeze, #usable_items, #usable_objects, #use_hit_die!, #used_hand_slots, #wearing_armor?, #wis_mod, #wisdom_check!
#apply_effect, #eval_if
Instance Attribute Details
Returns the value of attribute key_name.
6
7
8
|
# File 'lib/natural_20/item_library/chest.rb', line 6
def key_name
@key_name
end
|
Returns the value of attribute locked.
6
7
8
|
# File 'lib/natural_20/item_library/chest.rb', line 6
def locked
@locked
end
|
Returns the value of attribute state.
6
7
8
|
# File 'lib/natural_20/item_library/chest.rb', line 6
def state
@state
end
|
Instance Method Details
#available_interactions(entity, battle = nil) ⇒ Array
Returns available interaction with this object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/natural_20/item_library/chest.rb', line 107
def available_interactions(entity, battle = nil)
interaction_actions = {}
if locked?
interaction_actions[:unlock] = { disabled: !entity.item_count(:"#{key_name}").positive?,
disabled_text: t('object.door.key_required') }
if entity.item_count('thieves_tools').positive? && entity.proficient?('thieves_tools')
interaction_actions[:lockpick] =
{ disabled: !entity.action?(battle), disabled_text: t('object.door.action_required') }
end
return interaction_actions
end
if opened?
i[close store loot]
else
{ open: {}, lock: { disabled: !entity.item_count(:"#{key_name}").positive?,
disabled_text: t('object.door.key_required') } }
end
end
|
#build_map(action, action_object) ⇒ OpenStruct
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
52
53
54
55
|
# File 'lib/natural_20/item_library/chest.rb', line 12
def build_map(action, action_object)
case action
when :store
OpenStruct.new({
action: action_object,
param: [
{
type: :select_items,
label: action_object.source.items_label,
items: action_object.source.inventory
}
],
next: lambda { |items|
action_object.other_params = items
OpenStruct.new({
param: nil,
next: lambda {
action_object
}
})
}
})
when :loot
OpenStruct.new({
action: action_object,
param: [
{
type: :select_items,
label: items_label,
items: inventory
}
],
next: lambda { |items|
action_object.other_params = items
OpenStruct.new({
param: nil,
next: lambda {
action_object
}
})
}
})
end
end
|
89
90
91
|
# File 'lib/natural_20/item_library/chest.rb', line 89
def close!
@state = :closed
end
|
#closed? ⇒ Boolean
77
78
79
|
# File 'lib/natural_20/item_library/chest.rb', line 77
def closed?
@state == :closed
end
|
100
101
102
|
# File 'lib/natural_20/item_library/chest.rb', line 100
def color
opened? ? :white : super
end
|
#interactable? ⇒ Boolean
127
128
129
|
# File 'lib/natural_20/item_library/chest.rb', line 127
def interactable?
true
end
|
65
66
67
|
# File 'lib/natural_20/item_library/chest.rb', line 65
def lock!
@locked = true
end
|
#locked? ⇒ Boolean
69
70
71
|
# File 'lib/natural_20/item_library/chest.rb', line 69
def locked?
@locked
end
|
#lockpick_dc ⇒ Object
216
217
218
|
# File 'lib/natural_20/item_library/chest.rb', line 216
def lockpick_dc
(@properties[:lockpick_dc].presence || 10)
end
|
#opaque? ⇒ Boolean
57
58
59
|
# File 'lib/natural_20/item_library/chest.rb', line 57
def opaque?
false
end
|
85
86
87
|
# File 'lib/natural_20/item_library/chest.rb', line 85
def open!
@state = :opened
end
|
#opened? ⇒ Boolean
81
82
83
|
# File 'lib/natural_20/item_library/chest.rb', line 81
def opened?
@state == :opened
end
|
#passable? ⇒ Boolean
73
74
75
|
# File 'lib/natural_20/item_library/chest.rb', line 73
def passable?
true
end
|
#resolve(entity, action, other_params, opts = {}) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/natural_20/item_library/chest.rb', line 133
def resolve(entity, action, other_params, opts = {})
return if action.nil?
case action
when :open
if !locked?
{
action: action
}
else
{
action: :door_locked
}
end
when :loot, :store
{ action: action, items: other_params, source: entity, target: self, battle: opts[:battle] }
when :close
{
action: action
}
when :lockpick
lock_pick_roll = entity.lockpick!(opts[:battle])
if lock_pick_roll.result >= lockpick_dc
{ action: :lockpick_success, roll: lock_pick_roll, cost: :action }
else
{ action: :lockpick_fail, roll: lock_pick_roll, cost: :action }
end
when :unlock
entity.item_count(:"#{key_name}").positive? ? { action: :unlock } : { action: :unlock_failed }
when :lock
entity.item_count(:"#{key_name}").positive? ? { action: :lock } : { action: :lock_failed }
end
end
|
93
94
95
96
97
98
|
# File 'lib/natural_20/item_library/chest.rb', line 93
def token
return '`' if dead?
t = opened? ? "\u2610" : "\u2610"
[t]
end
|
61
62
63
|
# File 'lib/natural_20/item_library/chest.rb', line 61
def unlock!
@locked = false
end
|
#use!(entity, result) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/natural_20/item_library/chest.rb', line 170
def use!(entity, result)
case result[:action]
when :store
store(result[:battle], result[:source], result[:target], result[:items])
when :loot
retrieve(result[:battle], result[:source], result[:target], result[:items])
when :open
open! if closed?
when :close
return unless opened?
close!
when :lockpick_success
return unless locked?
unlock!
Natural20::EventManager.received_event(source: self, user: entity, event: :object_interaction,
sub_type: :unlock, result: :success, lockpick: true, roll: result[:roll], reason: t(:"object.chest.unlock"))
when :lockpick_fail
return unless locked?
entity.deduct_item('thieves_tools')
Natural20::EventManager.received_event(source: self, user: entity, event: :object_interaction,
sub_type: :unlock, result: :failed, roll: result[:roll], reason: t('object.lockpick_failed'))
when :unlock
return unless locked?
unlock!
Natural20::EventManager.received_event(source: self, user: entity, event: :object_interaction,
sub_type: :unlock, result: :success, reason: t(:"object.chest.unlock"))
when :lock
return unless unlocked?
lock!
Natural20::EventManager.received_event(source: self, user: entity, event: :object_interaction,
sub_type: :lock, result: :success, reason: t(:"object.chest.lock"))
when :door_locked
Natural20::EventManager.received_event(source: self, user: entity, event: :object_interaction,
sub_type: :open_failed, result: :failed, reason: 'Cannot open chest since chest is locked.')
when :unlock_failed
Natural20::EventManager.received_event(source: self, user: entity, event: :object_interaction,
sub_type: :unlock_failed, result: :failed, reason: 'Correct Key missing.')
end
end
|