Class: ItemLibrary::DoorObject
- Inherits:
-
Object
- Object
- Object
- ItemLibrary::DoorObject
show all
- Defined in:
- lib/natural_20/item_library/door_object.rb
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, #color, #current_hit_die, #death_fails, #death_saves, #effects, #entity_event_hooks, #entity_uid, #max_hit_die, #session, #statuses
Instance Method Summary
collapse
Methods inherited from Object
#armor_class, #can_hide?, #color, #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.
4
5
6
|
# File 'lib/natural_20/item_library/door_object.rb', line 4
def key_name
@key_name
end
|
Returns the value of attribute locked.
4
5
6
|
# File 'lib/natural_20/item_library/door_object.rb', line 4
def locked
@locked
end
|
Returns the value of attribute state.
4
5
6
|
# File 'lib/natural_20/item_library/door_object.rb', line 4
def state
@state
end
|
Instance Method Details
#available_interactions(entity, battle = nil) ⇒ Array
Returns available interaction with this object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/natural_20/item_library/door_object.rb', line 66
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?
{ close: { disabled: someone_blocking_the_doorway?, disabled_text: t('object.door.door_blocked') } }
else
{ open: {}, lock: { disabled: !entity.item_count(:"#{key_name}").positive?,
disabled_text: t('object.door.key_required') } }
end
end
|
38
39
40
|
# File 'lib/natural_20/item_library/door_object.rb', line 38
def close!
@state = :closed
end
|
#closed? ⇒ Boolean
26
27
28
|
# File 'lib/natural_20/item_library/door_object.rb', line 26
def closed?
@state == :closed
end
|
#interactable? ⇒ Boolean
86
87
88
|
# File 'lib/natural_20/item_library/door_object.rb', line 86
def interactable?
true
end
|
14
15
16
|
# File 'lib/natural_20/item_library/door_object.rb', line 14
def lock!
@locked = true
end
|
#locked? ⇒ Boolean
18
19
20
|
# File 'lib/natural_20/item_library/door_object.rb', line 18
def locked?
@locked
end
|
#lockpick_dc ⇒ Object
171
172
173
|
# File 'lib/natural_20/item_library/door_object.rb', line 171
def lockpick_dc
(@properties[:lockpick_dc].presence || 10)
end
|
#opaque? ⇒ Boolean
6
7
8
|
# File 'lib/natural_20/item_library/door_object.rb', line 6
def opaque?
closed? && !dead?
end
|
34
35
36
|
# File 'lib/natural_20/item_library/door_object.rb', line 34
def open!
@state = :opened
end
|
#opened? ⇒ Boolean
30
31
32
|
# File 'lib/natural_20/item_library/door_object.rb', line 30
def opened?
@state == :opened
end
|
#passable? ⇒ Boolean
22
23
24
|
# File 'lib/natural_20/item_library/door_object.rb', line 22
def passable?
opened? || dead?
end
|
#resolve(entity, action, _other_params, opts = {}) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/natural_20/item_library/door_object.rb', line 92
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 :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
|
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/natural_20/item_library/door_object.rb', line 42
def token
return '`' if dead?
pos_x, pos_y = position
t = if map.wall?(pos_x - 1, pos_y) || map.wall?(pos_x + 1, pos_y)
opened? ? '-' : '='
else
opened? ? '|' : '║'
end
[t]
end
|
#token_closed ⇒ Object
59
60
61
|
# File 'lib/natural_20/item_library/door_object.rb', line 59
def token_closed
@properties[:token_closed].presence || '='
end
|
#token_opened ⇒ Object
55
56
57
|
# File 'lib/natural_20/item_library/door_object.rb', line 55
def token_opened
@properties[:token_open].presence || '-'
end
|
10
11
12
|
# File 'lib/natural_20/item_library/door_object.rb', line 10
def unlock!
@locked = false
end
|
#use!(entity, result) ⇒ Object
127
128
129
130
131
132
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
167
168
169
|
# File 'lib/natural_20/item_library/door_object.rb', line 127
def use!(entity, result)
case (result[:action])
when :open
open! if closed?
when :close
return unless opened?
if someone_blocking_the_doorway?
return Natural20::EventManager.received_event(source: self, user: entity, event: :object_interaction,
sub_type: :close_failed, result: :failed, reason: 'Cannot close door since something is in the doorway')
end
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: 'Door unlocked using lockpick.')
when :lockpick_fail
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: 'Lockpicking failed and the theives tools are now broken')
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.door.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.door.lock'))
when :door_locked
Natural20::EventManager.received_event(source: self, user: entity, event: :object_interaction,
sub_type: :open_failed, result: :failed, reason: 'Cannot open door since door 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
|