Exemple #1
0
def dropPrompt(player, key, level):
    global inputState
    if key.vk != 65:
        #Display error
        return False
    else:
        keyChar = chr(key.c)
        theItem, count = player.inventory[keyChar]
        if theItem and count != 0:
            # HACK! Need to allow user to specify count
            messager.addMessage("You drop the " + theItem.infostring)
            count -= 1
            if level.floor[player.Z][player.X][player.Y].items:
                if theItem in level.floor[player.Z][player.X][player.Y].items:
                    level.floor[player.Z][player.X][player.Y].items[theItem] += 1
            else:
                level.floor[player.Z][player.X][player.Y].items = {theItem: 1}
            if count > 0:
                player.inventory[keyChar] = theItem, count
            else:
                player.inventory[keyChar] = None, 0
                if player.wieldedSlot == keyChar:
                    player.wieldedSlot = None
                    player.wielded = None
            inputState = normal
            return True
        else:
            inputState = normal
            messager.addMessage("I don't have that item.")
            return False
Exemple #2
0
def enemyTurn(dungeon, player, enemy):
    global pathFoundRooms
    if player.Z != enemy.Z:
        return # Do nothing if on different floor
    # Is player adjacent? If so, attack!
    if areAdjacent(player, enemy):
        entity.attack(enemy, player)
        if enemy.name == "":
            messager.addMessage("The enemy attacks!")
        else:
            messager.addMessage(enemy.name + " attacks!")
        return
    # Else, run pathfinding, then move
    dest = findPath(dungeon, player, enemy)
    X, Y, Z = dest.X, dest.Y, dest.Z
    oldX, oldY, oldZ = enemy.X, enemy.Y, enemy.Z
    if X == oldX and Y == oldY and Z == oldZ:
        print "Staying put."
    elif not dungeon.floor[Z][X][Y].enterEntity(enemy):
        print X, Y, Z
        print dungeon.floor[Z][X][Y].entity
        print "ERROR: ENEMY MOVEMENT FAILED!"
    else:
        dungeon.floor[oldZ][oldX][oldY].entity = None
        enemy.X, enemy.Y, enemy.Z = X, Y, Z
    clearCells(pathFoundRooms)
Exemple #3
0
 def giveExp(self, amount):
     self.exp = self.exp + amount
     if self.exp >= (self.level * 10):
         self.exp = self.exp - (self.level * 10)
         self.level = self.level + 1
         messager.addMessage("Welcome to level " + str(self.level))
         self.hpmax = self.hpmax + 5
Exemple #4
0
def runEndGame():
    messager.addMessage("You have passed Trigger's gauntlet!")
    messager.addMessage("You escape into the Net, discovering freedom...")
    while messager.moreMessages():
        messager.nextMessage()
        libtcod.console_flush()
        libtcod.console_wait_for_keypress(True)
    print "I... have quite perished... yet..."
    exit()
Exemple #5
0
def wearPrompt(player, key, level):
    global inputState
    if key.vk != 65:
        return False
    else:
        keyChar = chr(key.c)
        if not player.wearItem(keyChar):
            messager.addMessage("I don't have that item.")
            inputState = normal
            return False
        inputState = normal
        return True
Exemple #6
0
 def wearItem(self, slot):
     oldWorn = self.worn
     oldSlot = self.wornSlot
     if slot in self.inventory:
         self.worn, _ = self.inventory[slot]
         self.wornSlot = slot
     else:
         return False
     if self.worn == None:
         return False
     elif not isinstance(self.worn, item.Armor):
         messager.addMessage("You cannot wear that!")
         self.worn == oldWorn
         self.wornSlot == oldSlot
         return True
     else:
         return True
Exemple #7
0
 def giveItem(self, item, count):
     # Find an existing stack and add it in.
     for slot, stack in self.inventory.iteritems():
         i, c = stack
         if i == item:
             self.inventory[slot] = (i, c + count)
             tmp = slot, self.inventory[slot]
             itemInfo = inventory.genVisibleInfo(tmp)
             messager.addMessage(itemInfo)
             return
     # If we got here, we need to find an EMPTY stack and add to it.
     for slot, stack in self.inventory.iteritems():
         i, _ = stack
         if i == None:
             self.inventory[slot] = (item, count)
             tmp = slot, self.inventory[slot]
             itemInfo = inventory.genVisibleInfo(tmp)
             messager.addMessage(itemInfo)
             return
Exemple #8
0
    libtcod.console_flush()
    if not inputValid:
        continue
    player.tick()
    enemiesToRemove = []
    #Eliminate old enemies
    for enemy in entity.enemies:
        if enemy.dead:
            enemiesToRemove.append(enemy)
            x, y, z = enemy.X, enemy.Y, enemy.Z
            saturnSeven.floor[z][x][y].entity = None
            player.giveExp(enemy.expvalue)

    #Need a second loop because iterators get funky if you take things out from underneath them
    for enemy in enemiesToRemove:
        if enemy.name == "Trigger":
            # Endgame
            util.runEndGame()
        entity.enemies.remove(enemy)

    for enemy in entity.enemies:
        ai.enemyTurn(saturnSeven, player, enemy)
    if player.dead:
        messager.addMessage("You die...")
        while messager.moreMessages():
            messager.nextMessage()
            libtcod.console_flush()
            libtcod.console_wait_for_keypress(True)
        # Final release will delete any save files
        exit()
Exemple #9
0
def handleMovement(player, key, level):
    global inputState
    keyChar = chr(key.c)
    if key.vk != 65:
        keyChar = getUnprintableKeypress(key)
    if keyChar == 'j':
        if level.floor[player.Z][player.X][player.Y + 1].isPassable():
            player.Y += 1
            return True
        elif level.floor[player.Z][player.X][player.Y + 1].entity is not None: 
            entity.attack(player, level.floor[player.Z][player.X][player.Y + 1].entity)
            messager.addAttackMessage(level.floor[player.Z][player.X][player.Y + 1].entity)
            return True
        else:
            messager.addMessage("You can't pass through here.")
            return False
        
    if keyChar == 'k':
        if level.floor[player.Z][player.X][player.Y - 1].isPassable():
            player.Y -= 1
            return True
        elif level.floor[player.Z][player.X][player.Y - 1].entity is not None: 
            entity.attack(player, level.floor[player.Z][player.X][player.Y - 1].entity)
            messager.addAttackMessage(level.floor[player.Z][player.X][player.Y - 1].entity)
            return True
        else:
            messager.addMessage("You can't pass through here.")
            return False
        
    if keyChar == 'h':
        if level.floor[player.Z][player.X - 1][player.Y].isPassable():
            player.X -= 1
            return True
        elif level.floor[player.Z][player.X - 1][player.Y].entity is not None: 
            entity.attack(player, level.floor[player.Z][player.X - 1][player.Y].entity)
            messager.addAttackMessage(level.floor[player.Z][player.X - 1][player.Y].entity)
            return True
        else:
            messager.addMessage("You can't pass through here.")
            return False
        
    if keyChar == 'l':
        if level.floor[player.Z][player.X + 1][player.Y].isPassable():
            player.X += 1
            return True
        elif level.floor[player.Z][player.X + 1][player.Y].entity is not None: 
            entity.attack(player, level.floor[player.Z][player.X + 1][player.Y].entity)
            messager.addAttackMessage(level.floor[player.Z][player.X + 1][player.Y].entity)
            return True
        else:
            messager.addMessage("You can't pass through here.")
            return False
        
    if keyChar == '>' and level.floor[player.Z][player.X][player.Y].terrain == dungeon.stairdown:
        player.Z += 1
        messager.addMessage("You go down the steps...")
        return True
    if keyChar == '<' and level.floor[player.Z][player.X][player.Y].terrain == dungeon.stairup:
        messager.addMessage("You go up the steps...")
        player.Z -= 1
        return True
    if keyChar == 'q':
        exit()
    if keyChar == 's':
        util.saveGame(level, player, None)
        exit()
    if keyChar == 'i':
        inventory.showInventory(player)
        inputState = inventoryDisplay
        return False
    if keyChar == ',':
        theItems = level.floor[player.Z][player.X][player.Y].items
        if not theItems:
            return False
        for i, v in theItems.iteritems():
            player.giveItem(i, v)
        level.floor[player.Z][player.X][player.Y].items = {}
        return True
    if keyChar == 'd':
        inputState = stateDrop
        messager.addMessage("Drop what item?")
        return False
    if keyChar == 'w':
        inputState = wieldPrompt
        messager.addMessage("Wield what item?")
    if keyChar == 'W':
        inputState = wearPrompt
        messager.addMessage("Wear what item?")
    return False