Class: Lich::Common::Char

Inherits:
Object
  • Object
show all
Defined in:
lib/Olib/character/char.rb

Constant Summary collapse

INJURIES =
Wounds.singleton_methods.map(&:to_s).select do |m| m.downcase == m and not m.include?("_") end.map(&:to_sym)
@@silvers =
0
@@aiming =
nil

Class Method Summary collapse

Class Method Details

.aim(location) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/Olib/character/char.rb', line 46

def self.aim(location)
  unless @@aiming == location
    fput "aim #{location}"
    @@aiming = location
  end
  self
end

.armObject



23
24
25
26
# File 'lib/Olib/character/char.rb', line 23

def self.arm
  fput "gird"
  self
end

.deplete_wealth(silvers) ⇒ Object



110
111
112
# File 'lib/Olib/character/char.rb', line 110

def self.deplete_wealth(silvers)
  #@@silvers = @@silvers - silvers
end

.deposit(amt) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/Olib/character/char.rb', line 91

def self.deposit(amt)
  wealth
  if wealth >= amt
    Go2.bank
    fput "unhide" if invisible? || hidden?
    fput "deposit #{amt}"
  end
  return self
end

.deposit_allObject



83
84
85
86
87
88
89
# File 'lib/Olib/character/char.rb', line 83

def self.deposit_all
  Go2.bank
  fput "unhide" unless visible?
  fput "deposit all"
  @@silvers = 0
  return self
end

.empty_handsObject



161
162
163
164
165
166
167
168
169
# File 'lib/Olib/character/char.rb', line 161

def self.empty_hands
  hands = [Char.left, Char.right].compact

  hands.each do |hand| Containers.Lootsack.add hand end

  yield

  hands.each(&:take)
end

.hideObject



9
10
11
12
13
14
# File 'lib/Olib/character/char.rb', line 9

def self.hide()
  return unless visible?
  fput "hide"
  waitrt?
  self
end

.in_town?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/Olib/character/char.rb', line 59

def self.in_town?
  Room.current.location =~ /the Adventurer's Guild|kharam|teras|landing|sol|icemule trace|mist|vaalor|illistim|rest|cysaegir|logoth/i
end

.leftObject



63
64
65
# File 'lib/Olib/character/char.rb', line 63

def self.left
  GameObj.left_hand.name == "Empty" ? nil : Item.new(GameObj.left_hand)
end

.rightObject



67
68
69
# File 'lib/Olib/character/char.rb', line 67

def self.right
  GameObj.right_hand.name == "Empty" ? nil : Item.new(GameObj.right_hand)
end

.shareObject

naive share does not check if you’re actually in a group or not



103
104
105
106
107
108
# File 'lib/Olib/character/char.rb', line 103

def self.share
  wealth
  fput "share #{@silvers}"
  wealth
  self
end

.smart_wealthObject



114
115
116
117
# File 'lib/Olib/character/char.rb', line 114

def self.smart_wealth
  return @@silvers if @@silvers 
  Char.wealth
end

.standObject



38
39
40
41
42
43
44
# File 'lib/Olib/character/char.rb', line 38

def self.stand
  unless standing?
    fput "stand"
    waitrt?
  end
  self
end

.swapObject



33
34
35
36
# File 'lib/Olib/character/char.rb', line 33

def self.swap
  fput "swap"
  self
end

.total_wound_severityObject



152
153
154
155
# File 'lib/Olib/character/char.rb', line 152

def self.total_wound_severity
  INJURIES
    .reduce(0) do |sum, method| sum + Wounds.send(method) end
end

.unarmObject



28
29
30
31
# File 'lib/Olib/character/char.rb', line 28

def self.unarm
  fput "store both"
  self
end

.unhideObject



16
17
18
19
20
21
# File 'lib/Olib/character/char.rb', line 16

def self.unhide()
  return if visible?
  fput "unhide"
  wait_until do visible? end
  self
end

.visible?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/Olib/character/char.rb', line 55

def self.visible?
  hiding? or invisible?
end

.wealthObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/Olib/character/char.rb', line 132

def self.wealth
  silvers = nil
  DownstreamHook.add("Olib_check_silvers", Proc.new do |server_string|
    if server_string =~ /^\s*Name\:|^\s*Gender\:|^\s*Normal \(Bonus\)|^\s*Strength \(STR\)\:|^\s*Constitution \(CON\)\:|^\s*Dexterity \(DEX\)\:|^\s*Agility \(AGI\)\:|^\s*Discipline \(DIS\)\:|^\s*Aura \(AUR\)\:|^\s*Logic \(LOG\)\:|^\s*Intuition \(INT\)\:|^\s*Wisdom \(WIS\)\:|^\s*Influence \(INF\)\:/
      nil
    elsif server_string =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
      silvers = $1.to_i
      DownstreamHook.remove("Olib_check_silvers")
      nil
    else
      server_string
    end
  end)
  $_SERVER_.puts "#{$cmd_prefix}info\n"
  wait_until { silvers }
  silvers
  @@silvers = silvers
  @@silvers
end

.withdraw(amount) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/Olib/character/char.rb', line 71

def self.withdraw(amount)
  Go2.bank
  result = Olib.do "withdraw #{amount} silvers", /I'm sorry|hands you/
  if result =~ /I'm sorry/ 
    Go2.origin
    echo "Unable to withdraw the amount requested for this script to run from your bank account"
    exit
  end
  wealth
  return self
end

.wounded?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/Olib/character/char.rb', line 157

def self.wounded?
  total_wound_severity.gt(0)
end