def talk(player, npcs, npc=None): if npc == None: if npcs != {}: print("Characters you can talk with:") for key, character in npcs.items(): print("\t{} = {}".format(key, character.NPCName)) else: print("There are no characters to talk with in room.") if npc in npcs.keys(): if player.roomID == 10: quest = conversation.talk(npcs[npc]) if quest == 1: db.updateMovements(player, 12, 9, 'NULL', 11, 'NULL', 'NULL') db.updateRoomState(player.roomID, 4) db.modifypoints(db.getPointsFromNPC(npcs[npc].ID)) db.cleanNPCFromRoom(npcs[npc]) npcs = db.getNPCsInRoom(player.roomID) printRoomStateOrDescription(player) elif player.roomID == 34: quest = conversation.talk(npcs[npc], player) if quest == 1: db.updateMovements(player, 31, 33, 'NULL', 'NULL', 'NULL', 'NULL') db.updateRoomState(player.roomID, 1) else: print("Conversation with {} has not written yet.".format( npcs[npc].NPCName))
def fight(player=None, npcs={}, npc=None): if npc == None: while npcs != {}: for i in range(0,len(npcs)): npcs = fight(player,npcs,'0') elif npcs[npc].NPCName=='Dragon': db.updateRoomState(player.roomID, 2) printRoomStateOrDescription(player) raise SystemExit elif npcs[npc].NPCName=='Spider': db.updateRoomState(player.roomID, 1) printRoomStateOrDescription(player) raise SystemExit elif npcs[npc].NPCName == "Zhaltrauc": shieldIsActive = False useShield = input("The gem on Zhaltrauc's crown begins to glow!") if useShield.lower() == "use shield" and "shield" in player.inventory: shieldIsActive=True print("Zhaltrauc shoot's a beam of light from his gem. You lift " "your shield just in time and deflect the shot, blinding " "Zhaltrauc!") else: print("Blinding light flashes from Zhaltrauc's gem! You are blinded by the light!") # Attack turn if shieldIsActive: attack = action.attack(player, npcs[npc]) db.modifyNPCHP(attack, npcs[npc]) npcs[npc] = db.updateNPC(npcs[npc]) player = db.updatePlayer(player) if npcs[npc].HP <= 0: print("{} {} died.".format(npcs[npc].NPCName, npcs[npc].ID)) db.modifypoints(db.getPointsFromNPC(npcs[npc].ID)) db.cleanNPCFromRoom(npcs[npc]) npcs = db.getNPCsInRoom(player.roomID) db.updateRoomState(player.roomID,1) printRoomStateOrDescription(player) raise SystemExit # Dodge turn if not shieldIsActive: if npcs[npc].HP > 0: dodge = action.dodge(player, npcs[npc]) db.modifyhp(dodge) npcs[npc] = db.updateNPC(npcs[npc]) player = db.updatePlayer(player) if player.HP <= 0: print("You died.") raise SystemExit elif npc in npcs.keys(): enemyIsAlive = True while enemyIsAlive: # Attack turn attack = action.attack(player, npcs[npc]) db.modifyNPCHP(attack, npcs[npc]) npcs[npc] = db.updateNPC(npcs[npc]) player = db.updatePlayer(player) input('Press "Enter"') # Dodge turn for npc in npcs.keys(): npcs = db.getNPCsInRoom(player.roomID) if npc in npcs.keys(): if npcs[npc].HP > 0: dodge = action.dodge(player, npcs[npc]) db.modifyhp(dodge) npcs[npc] = db.updateNPC(npcs[npc]) player = db.updatePlayer(player) if player.HP <= 0: print("You died.") raise SystemExit if npc in npcs.keys(): if npcs[npc].HP <= 0: print("{} {} died.".format(npcs[npc].NPCName, npcs[npc].ID)) db.modifypoints(db.getPointsFromNPC(npcs[npc].ID)) db.cleanNPCFromRoom(npcs[npc]) npcs = db.getNPCsInRoom(player.roomID) enemyIsAlive = False if player.roomID == 1: db.updateMovements(player, 2, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL') if player.roomID == 6 and npcs == {}: db.updateMovements(player, 'NULL', 'NULL', 5, 'NULL', 'NULL', 'NULL') db.updateRoomState(player.roomID, 1) printRoomStateOrDescription(player) db.updateRoomState(player.roomID, 2) if player.roomID == 10: db.updateRoomState(player.roomID, 2) printRoomStateOrDescription(player) if player.roomID == 12 and npcs == {}: db.updateMovements(player, 'NULL', 10, 13, 'NULL', 'NULL', 'NULL') db.updateRoomState(player.roomID, 1) printRoomStateOrDescription(player) db.updateRoomState(player.roomID, 2) input('Press "Enter"') else: print('Cannot fight with "{}".'.format(npc)) return npcs