def cast(self, context): from level import makeFloor from traps import TrapDoor, clearTraps context.log( "Dig in which direction?" ) dxdy = context.game.main.query( DirectionWidget, acceptZ = True ) nodig = [ "stairs up", "stairs down" ] if dxdy == '<': tile = context.player.tile prevLev = tile.level.previousLevel if not prevLev: context.log( "You fail to dig through the ceiling." ) else: tileAbove = prevLev.randomTile( lambda tile : not tile.impassable and not tile.trap and not tile.mobile and not tile.name in nodig ) td = TrapDoor( tileAbove, context = context ) td.difficulty = 0 td.setTarget( tile ) context.log( "You dig through the ceiling!" ) items = tileAbove.items tileAbove.items = [] if items: tile.level.scatterItemsAround( items, (tile.x, tile.y) ) msg = [ capitalizeFirst( grammar.makeCountingList( countItems( items ) ) ), "fall" if len(items) > 1 else "falls", "through the hole!" ] context.log( " ".join( msg ) ) elif dxdy == '>': tile = context.player.tile nexLev = tile.level.generateDeeperLevel() if nexLev and tile.name not in nodig: clearTraps( tile ) td = TrapDoor( tile, context = context ) td.difficulty = 0 items = tile.items tile.items = [] target = td.getTarget() context.log( "You dig through the floor!" ) if items: tile.level.scatterItemsAround( items, target ) msg = [ capitalizeFirst( grammar.makeCountingList( countItems( items ) ) ), "fall" if len(items) > 1 else "falls", "through the hole!" ] context.log( " ".join( msg ) ) tile.enters( context.player ) # trigger? might not, flying etc. else: context.log( "You fail to dig through the floor." ) else: rayLength = 8 region = context.game.showStraightRay( (context.player.tile.x,context.player.tile.y), dxdy, rayLength, 'black', 'magenta', lambda (x,y) : not context.player.tile.level.tiles[x,y].diggable() ) for x, y in region: try: tile = context.player.tile.level.tiles[x,y] if tile.diggable() and tile.impassable: makeFloor( tile ) if tile.mobile and tile.mobile.destroyedByDigging: tile.mobile.killmessage() tile.mobile.kill() except KeyError: # shouldn't happen break
def writeReport( game, won, books = 0, didQuit = False ): import harmless7drl import time unfriendlytime = time.strftime( "%Y-%m-%d-%H-%M-%S" ) friendlytime = time.strftime( "%d/%m/%Y %H:%M" ) name = game.player.name.singular Psub = capitalizeFirst( game.player.name.pronounSubject() ) reportName = "harmless7drl-%s-%s.txt" % (name, unfriendlytime ) harmless7drl.ensureDirPresent( "logs" ) reportName = harmless7drl.fullFilename( "logs", reportName ) f = open( reportName, "w" ) if won: print >>f, "%s successfully retrieved the Professor at %s." % (name, friendlytime) if books > 0: if books == 1: print >>f, "%s also returned a valuable books to the library." % (Psub) else: print >>f, "%s also returned %d valuable books to the library." % (Psub, books) elif didQuit: print >>f, "%s quit the game at %s." % (name, friendlytime) else: print >>f, "%s perished in the dungeon at %s." % (name, friendlytime) print >>f if game.context.debugmode: print >>f, "%s was playing in debugging mode." % (Psub) print >>f print >>f, "%s spent %d ticks in the dungeon." % (Psub, game.context.totalTime) print >>f, "%s reached dungeon level %d." % (Psub, game.player.greatestDepth ) print >>f, "%s drained %d points' worth of magical energy from artifacts while in the dungeon." % (Psub, game.player.manaUsed) print >>f, "%s had %d hit points, out of a maximum of %d." % (Psub, game.player.hitpoints, game.player.maxHitpoints ) if game.player.weapon: print >>f, "%s was wielding %s." % (Psub, game.player.weapon.name.indefiniteSingular() ) print >>f identifiedProtorunes = [ protorune for protorune in game.context.protorunes if protorune.identified ] if identifiedProtorunes: for protorune in identifiedProtorunes: print >>f, "%s had identified the \"%s\" rune as \"%s\"." % (Psub, protorune.arcaneName, protorune.englishName ) else: print >>f, "%s hadn't identified any runes." % Psub if game.player.inventory: print >>f, "%s was carrying:" % Psub for name, items in countItems( game.player.inventory ).items(): print >>f, "\t", name.amount( len(items) ) else: print >>f, "%s was not carrying anything." % Psub print >>f if game.player.spellbook: print >>f, "%s had the following spells in %s spellbook:" % (Psub, game.player.name.pronounPossessive() ) for spell in game.player.spellbook: if spell.castCount == 0: x = "(never cast)" else: if spell.castCount == 1: x = "(cast once)" else: x = "(cast %d times)" % spell.castCount print >>f, "\t", spell.name, x else: print >>f, "%s had no spells in %s spellbook." % (Psub, game.player.name.pronounPossessive() ) print >>f print >>f, "%s encountered the following creatures:" % (Psub) for protomonster in game.context.protomonsters: if protomonster.spawnCount == 0: continue x = [] if protomonster.killCount > 0: x.append( "%d perished" % protomonster.killCount ) if protomonster.directKillCount > 0: x.append( "%d %s directly" % (protomonster.directKillCount, "killed" if not protomonster.nonalive else "destroyed" ) ) if x: x = " (" + ", of which ".join( x ) + ")" else: x = "" print >>f, "\t", protomonster.name.amount( protomonster.spawnCount ), x f.close()