Class: Item
Overview
this is the structure for a base Object wraps an instance of GameObj and adds the ability for tags, queries
Constant Summary
Constants inherited
from Exist
Exist::GETTER, Exist::PATTERN
Instance Attribute Summary collapse
Attributes inherited from Exist
#gameobj, #id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Exist
#==, #deconstruct_keys, #effects, #exists?, #fetch, #gone?, #method_missing, normalize_type_data, #respond_to_missing?, scan, #tags, #to_h, #to_s
Constructor Details
#initialize(obj, container = nil) ⇒ Item
When created, it should be passed an instance of GameObj
Example:
Item.new(GameObj.right_hand)
26
27
28
29
|
# File 'lib/Olib/core/item.rb', line 26
def initialize(obj, container = nil)
super(obj.id)
@container = container
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Exist
Instance Attribute Details
#container ⇒ Object
Returns the value of attribute container.
21
22
23
|
# File 'lib/Olib/core/item.rb', line 21
def container
@container
end
|
Class Method Details
.fetch(id) ⇒ Object
17
18
19
|
# File 'lib/Olib/core/item.rb', line 17
def self.fetch(id)
new Exist.fetch(id)
end
|
.of(item, container = nil) ⇒ Object
11
12
13
14
|
# File 'lib/Olib/core/item.rb', line 11
def self.of(item, container = nil)
return Scroll.new(item, container) if item.type.include?("scroll")
return Item.new(item, container)
end
|
Instance Method Details
#appraise(**args) ⇒ Object
59
60
61
|
# File 'lib/Olib/core/item.rb', line 59
def appraise(**args)
transaction(**args).appraise()
end
|
#held? ⇒ Boolean
39
40
41
|
# File 'lib/Olib/core/item.rb', line 39
def held?
[Char.left, Char.right].map(&:id).include?(id.to_s)
end
|
#sell(**args) ⇒ Object
63
64
65
|
# File 'lib/Olib/core/item.rb', line 63
def sell(**args)
transaction(**args).sell()
end
|
#stash ⇒ Object
67
68
69
|
# File 'lib/Olib/core/item.rb', line 67
def stash
@container.add(self) unless @container.nil?
end
|
#take ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/Olib/core/item.rb', line 43
def take()
return self if held?
waitrt?
fail Exception, "Error #{inspect}\nyour hands are full" if Char.left && Char.right
Command.try_or_fail(command: "get ##{id}") do held? end
return self
end
|
#to_json(*args) ⇒ Object
51
52
53
|
# File 'lib/Olib/core/item.rb', line 51
def to_json(*args)
to_h.to_json(*args)
end
|
#transaction(**args) ⇒ Object
55
56
57
|
# File 'lib/Olib/core/item.rb', line 55
def transaction(**args)
Transaction.new(take, **args)
end
|
#use(&block) ⇒ Object
35
36
37
|
# File 'lib/Olib/core/item.rb', line 35
def use(&block)
Use.new(self, &block)
end
|
#worn? ⇒ Boolean
31
32
33
|
# File 'lib/Olib/core/item.rb', line 31
def worn?
GameObj.inv.map(&:id).include?(id)
end
|