Class: Char

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

Defined Under Namespace

Classes: Duration

Constant Summary collapse

EMPATH =
"Empath"
INJURIES =
Wounds.singleton_methods
.map(&:to_s)
.select do |m| m.downcase == m && m !~ /_/ end.map(&:to_sym)
@@silvers =
0
@@routines =
{}
@@aiming =
nil

Class Method Summary collapse

Class Method Details

.aim(location) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/Olib/character/char.rb', line 58

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

.armObject



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

def Char.arm
  fput "gird"
  self
end

.deplete_wealth(silvers) ⇒ Object



130
131
132
# File 'lib/Olib/character/char.rb', line 130

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

.deposit(amt) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/Olib/character/char.rb', line 111

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

.deposit_allObject



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

def Char.deposit_all
  Go2.bank
  fput "unhide" if invisible? || hidden?
  fput "deposit all"
  @@silvers = 0
  return self
end

.empty_handsObject



174
175
176
177
178
179
180
181
182
# File 'lib/Olib/character/char.rb', line 174

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

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

  yield

  hands.each(&:take)
end

.fwi_teleporterObject



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

def Char.fwi_teleporter
  Vars.teleporter || Vars.mapdb_fwi_trinket
end

.hideObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/Olib/character/char.rb', line 12

def Char.hide
  while not hiding?
    waitrt?
    if @@routines[:hiding]
      @@routines[:hiding].call
    else
      fput 'hide'
    end
  end
  Char
end

.hiding_routine(procedure) ⇒ Object



74
75
76
77
# File 'lib/Olib/character/char.rb', line 74

def Char.hiding_routine(procedure)
  @@routines[:hiding] = procedure
  Char
end

.in_town?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/Olib/character/char.rb', line 79

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

.leftObject



83
84
85
# File 'lib/Olib/character/char.rb', line 83

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

.rightObject



87
88
89
# File 'lib/Olib/character/char.rb', line 87

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

.shareObject

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



123
124
125
126
127
128
# File 'lib/Olib/character/char.rb', line 123

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

.smart_wealthObject



134
135
136
137
# File 'lib/Olib/character/char.rb', line 134

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

.spell(num) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/Olib/character/char.rb', line 47

def Char.spell(num)
  hour, minutes, seconds = Spell[num].remaining.split(":").map(&:to_f)
  total_seconds = seconds + (minutes * 60.00) + (hour * 60.00 * 60.00)

  Duration.new(
    total_seconds,
    total_seconds/60,
    total_seconds/60/60,
  )
end

.standObject



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

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

.swapObject



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

def Char.swap
  fput "swap"
  self
end

.total_wound_severityObject



165
166
167
168
# File 'lib/Olib/character/char.rb', line 165

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

.unarmObject



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

def Char.unarm
  fput "store both"
  self
end

.unhideObject



139
140
141
142
# File 'lib/Olib/character/char.rb', line 139

def Char.unhide
  fput 'unhide' if Spell[916].active? or hidden?
  self
end

.visible?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/Olib/character/char.rb', line 70

def Char.visible?
  hiding? || invisible?
end

.wealthObject



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/Olib/character/char.rb', line 152

def Char.wealth
  fput "info"
  while(line=get)
    next    if line =~ /^\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\)\:/
    if line =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
      @@silvers= $1.to_i
      break
    end
    sleep 0.1
  end
  @@silvers
end

.withdraw(amount) ⇒ Object



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

def Char.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)


170
171
172
# File 'lib/Olib/character/char.rb', line 170

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