All pastes #180743 Raw Edit

Miscellany

public text v1 · immutable
#180743 ·published 2006-09-24 05:38 UTC
rendered paste body
  attributes = { 'vitality' : 'hp', 'stamina' : 'sp', 'essence' : 'mp' }
 
  def updateAttribute(self, attribute, newValue, newMax=None):
    newValue = float(newValue)
    setattr(self, attribute, newValue)
    maxAttribute = attribute + 'max'
    if newMax is None:
      if newValue > getattr(self, maxAttribute):
        setattr(self, maxAttribute, newValue)
    else:
      setattr(self, maxAttribute, newMax)
 
  def updateHPInfo(self,m):
    self.updateAttribute('hp', m.group(1))
    self.updateAttribute('sp', m.group(2))
    self.updateAttribute('mp', m.group(3))
 
  def inputText(self,c,s):
    s = stripAnsi(s)
    lines = s.splitlines()
    needToRender = False
    for line in lines:
      m = re.match(r'You have (\d+) out of (\d+) (vitality|stamina|essence) points\.$', line)
      if m:
        newValue = m.group(1)
        newMax = m.group(2)
        attribute = self.attributes[m.group(3)]
        self.updateAttribute(attribute, newValue, newMax)
        needToRender = True
    if needToRender:
      hpinfo.render(self.hp,self.sp,self.mp,self.hpmax,self.spmax,self.mpmax)