Class: Transaction
Constant Summary collapse
- Appraise =
Rill.new( start: %[to appraise (?:a |an |)<a exist="{{id}}"], close: Regexp.union( %r[I already appraised that], %r[Sorry, #{Char.name}, I'm not buying anything this valuable today\.], %r[(I'll give you|How's|I'll offer you|worth at least) (?<value>[,\d]+)], %r[(?<value>[,\d]+) silvers]) )
- Sell =
Rill.new( start: %[You offer|You ask (?<merchant>.*?) if (he|she) would like to buy (?:a |an |)<a exist="{{id}}"], close: Regexp.union( %r[(hands you|for) (?<value>[,\d]+)], %r[No #{Char.name}, I won't buy that], %r[I'm sorry, #{Char.name}, but I have no use for that\.], %r[He hands it back to you], %r[Nope #{Char.name}, I ain't buying that\.], %r[basically worthless here, #{Char.name}]) )
Constants inherited from Exist
Instance Attribute Summary collapse
-
#err ⇒ Object
readonly
Returns the value of attribute err.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Exist
Instance Method Summary collapse
- #appraise ⇒ Object
-
#initialize(item, **args) ⇒ Transaction
constructor
A new instance of Transaction.
- #sell ⇒ Object
- #shop_appraise ⇒ Object
- #skilled_appraise ⇒ Object
- #take ⇒ Object
Methods inherited from Exist
#==, #deconstruct_keys, #effects, #exists?, #fetch, fetch, #gone?, #method_missing, normalize_type_data, #respond_to_missing?, scan, #tags, #to_h, #to_s
Constructor Details
#initialize(item, **args) ⇒ Transaction
Returns a new instance of Transaction.
29 30 31 32 |
# File 'lib/Olib/core/transaction.rb', line 29 def initialize(item, **args) super(item) @threshold = args.fetch(:threshold, false) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Exist
Instance Attribute Details
#err ⇒ Object (readonly)
Returns the value of attribute err.
24 25 26 |
# File 'lib/Olib/core/transaction.rb', line 24 def err @err end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
24 25 26 |
# File 'lib/Olib/core/transaction.rb', line 24 def quality @quality end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
24 25 26 |
# File 'lib/Olib/core/transaction.rb', line 24 def threshold @threshold end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
24 25 26 |
# File 'lib/Olib/core/transaction.rb', line 24 def value @value end |
Instance Method Details
#appraise ⇒ Object
65 66 67 68 69 |
# File 'lib/Olib/core/transaction.rb', line 65 def appraise() return self unless @value.nil? return self.skilled_appraise unless Room.current..any? {|tag| %w(gemshop furrier pawnshop).include?(tag)} return self.shop_appraise end |
#sell ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/Olib/core/transaction.rb', line 71 def sell() self.take if @threshold && appraise && @value > @threshold return Err[ transaction: self, reason: "Value[#{@value}] is over Threshold[#{@threshold}]"] end (_, match, _lines) = Sell.capture(self.to_h, "sell \#{{id}}") if match[:value].is_a?(String) && match[:value] =~ /[\d,]+/ match[:value] = match[:value].to_s.delete(",").to_i end match[:value] = 0 unless match[:value].is_a?(Integer) Ok[**match] end |
#shop_appraise ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/Olib/core/transaction.rb', line 53 def shop_appraise self.take (_, match, lines) = Appraise.capture(self.to_h, "appraise \#{{id}}") if lines.any? {|line| line.include?(%[Sorry, #{Char.name}, I'm not buying anything this valuable today.])} @value = Float::INFINITY else @value = match[:value].to_s.delete(",").to_i end self end |
#skilled_appraise ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/Olib/core/transaction.rb', line 39 def skilled_appraise() if Skills.trading < 25 @err = :no_trading return self end self.take res = dothistimeout("appraise #%s" % self.id, 3, /is of (\w+) quality and worth approximately (\d+) silvers/) if res =~ /is of (\w+) quality and worth approximately (\d+) silvers/ @quality = $1 @value = $2.delete(",").to_i end self end |