コード例 #1
0
ファイル: character.py プロジェクト: ajventer/mirthless
 def take_damage(self, damage):
     """
     >>> char = Character(load_yaml('characters', 'bardic_rogue.yaml'))
     >>> start = 30
     >>> char.put('combat/hitpoints', start)
     >>> char.take_damage(1)
     (...)
     >>> end = char.get('combat/hitpoints', 1)
     >>> end < start
     True
     """
     messages.message('%s takes %s damage' % (self.displayname(), damage))
     debug("[DEBUG] character.take_damage: damage - %s, player - %s" % (damage, self.displayname()))
     out = ''
     currenthitpoints = self.get('combat/hitpoints', 1)
     if damage >= currenthitpoints:
         debug("[DEBUG] character.take_damage, damage MORE than hitpoints: %s, %s" % (damage, currenthitpoints))
         self.put('combat/hitpoints', 0)
         self.handle_death()
         return (False, '%s has died !' % self.displayname())
     else:
         debug("[DEBUG] character take damage, LESS than hitpoints: damage=%s, player=%s, hitpoints=%s" % (damage, self.displayname(), currenthitpoints))
         hp = int(currenthitpoints)
         hp -= damage
         self.put('combat/hitpoints', hp)
         out += "<br>%s takes %s damage. %s hitpoints remaining" % (self.displayname(), damage, self.get('combat/hitpoints', 1))
         messages.error('')
         return (True, out)
コード例 #2
0
ファイル: inventory.py プロジェクト: ajventer/mirthless
 def equip_item(self, item):
     status = self.char.equip_item(item)
     if status[0]:
         messages.message(status[1])
     else:
         messages.error(status[1])
     self.layout()
コード例 #3
0
ファイル: graphics.py プロジェクト: ajventer/mirthless
def initpygame(settings, caption, settingsfile):
    pygame.init()
    screen = get_screen(settings["res_x"], settings["res_y"], settings["hardware_buffer"], settings["fullscreen"])
    mode = "game"
    if "--editor" in sys.argv:
        mode = "editor"
        debug("Loading game editor")
    global imagecache
    imagecache = ImageCache()
    global frontend
    frontend = Frontend(mode=mode, settingsfile=settingsfile)
    global tilemaps
    tilemaps = Tilemaps()
    global messages
    imagecache.load()
    wallpaper = imagecache["landscape.png"]
    wallpaper = pygame.transform.smoothscale(wallpaper, (settings["res_x"], settings["res_y"]))
    screen.blit(wallpaper, (0, 0))
    pygame.display.set_caption(caption)
    frontend = Frontend(screen, imagecache, eventstack, tilemaps, mode=mode, settingsfile=settingsfile)
    messages = Messages(screen, eventstack)
    messages.error("Welcome to Mirthless")
    if not "--editor" in sys.argv:
        messages.error(
            "Game mode is barely started. The editor is much further along. Try starting the game with --editor"
        )
        messages.message(":)")
    tilemaps.initialize()
    return screen, frontend.screenlayout(), frontend
コード例 #4
0
ファイル: mapview.py プロジェクト: ajventer/mirthless
 def keydown(self, event):
     messages.message('Processing event '+event.unicode)
     loc = self.frontend.game.player.location()
     x = loc['x']
     y = loc['y']
     if event.key == K_LEFT or event.unicode.upper() == 'A':
         x -= 1
     elif event.key == K_RIGHT or event.unicode.upper() == 'D':
         x += 1
     elif event.key == K_UP or event.unicode.upper() == 'W':
         y -= 1
     elif event.key == K_DOWN or event.unicode.upper() == 'S':
         y += 1
     else:
         return False
     if self.player_can_goto(x, y):
         self.goto('player', x, y)
     return True
コード例 #5
0
ファイル: character.py プロジェクト: ajventer/mirthless
 def give_xp(self, xp):
     """
     >>> char = Character(load_yaml('characters', 'bardic_rogue.yaml'))
     >>> level = char.get('combat/level-hitdice', 1)
     >>> nl = char.next_level()
     >>> debug(char.give_xp(nl + 10))
     >>> char.get('combat/level-hitdice', 1) == level + 1
     True
     """
     current_xp = int(self.get('personal/xp', 0))
     new_xp = current_xp + int(xp)
     self.put('personal/xp', str(new_xp))
     messages.message('%s gains %s experience points. XP now: %s' % (self.displayname(), xp, new_xp))
     next_level = self.next_level()
     if new_xp >= next_level and next_level != -1:
         messages.warning(self.level_up())
         messages.error('Check for and apply manual increases to other stats if needed !')
     else:
         messages.message('Next level at %s. %s experience points to go' % (next_level, next_level - new_xp))
     return new_xp
コード例 #6
0
ファイル: item.py プロジェクト: ajventer/mirthless
 def onuse(self, player, target):
     debug("[DEBUG] Item.onuse: player %s, target %s" % (player.displayname(), target.displayname()))
     charges = self.get('/charges', 0)
     if charges == 0:
         return
     if self.itemtype() == 'spell':
         success = player.spell_success()
         messages.message(success[1])
         if not success[0]:
             return
     self.put('/in_use', True)
     #TODO - expect the next line to break in use. Needs to be redone once the 
     #new game class is finished
     self.put('/target', target)
     event(self, "/events/onuse", {'item': self, 'player': player, 'target': target, 'messages': messages})
     try:
         target = messages.characterlist[target.index]
         debug("Item.onround save: %s" % target.savetoslot())
     except:
         return
     messages.error("Item.onuse save: %s" % target.savetoslot())
コード例 #7
0
ファイル: character.py プロジェクト: ajventer/mirthless
    def attack_roll(self, target, mod):
        self.next_weapon()
        messages.message('%s has THAC0 of: %s' % (self.displayname(), self.thac0))
        target_stats = '%s has a defense modifier of %s and armor class %s' % (target.displayname(), target.def_mod(), target.armor_class())

        messages.message(target_stats)
        target_roll = self.thac0 - target.armor_class() - target.def_mod()

        messages.message('%s needs to roll %s to hit %s' % (self.displayname(), target_roll, target.displayname()))
        roll = rolldice(numdice=1, numsides=20, modifier=mod)
        if roll[0] == 1:
                return (roll[0], "Critical Miss !", roll[1])
        elif roll[0] == 20:
            return (roll[0], "Critical Hit !", roll[1])
        else:
            if roll[0] >= target_roll:
                return (roll[0], "Hit !", roll[1])
            else:
                return (roll[0], "Miss !", roll[1])