def test_weapon(): full_name = "the +9 sword of Zonguldrok (weapon) {reap}" name = "long sword" enchantment = 9 character = Character(morgue_filepath="support/GucciMane.txt", local_mode=True) subject = Weapon(full_name=full_name, name=name, enchantment=enchantment, character=character) assert subject.max_damage() == 13.85
def load_next_battle(self, name=None): if name is None: opponent_names = list(self.opponents.keys()) name = opponent_names[opponent_names.index(self.opponent.name) + 1] self.next_battle = Battle(self, self.opponents[name](self)) if name == "Spook Dog": opponent = Character(self, name, 200, 150) opponent.ghost_dog_stage = 1 # Variable showing which frame of idle movement the ghost dog is in opponent.ghost_dog_glide_x = 930 opponent.started_glowing = False opponent.ghost_dog_attack_time = self.fps/2 opponent.already_clawed = False
def print_max_damage(self): if True: weapons = fetch_weapons(self.character.morgue_file()) return WeaponsFormatter(character=self.character, weapons=weapons).format_max_damages() else: max_damages = {} from morgue_stalker import fetch_characters characters = morgue_stalker.fetch_characters() for character in characters: max_damages[character] = max_damage( Character(name=character).morgue_file()) return max_damages
def celebrate_awards(max_by_type): send_chat_to_stream(["PorscheWIN Fourth Annual Weapon Awards!!! PorscheWIN"]) for weapon_info in max_by_type: character = Character(name=weapon_info["character"]) emoji = find_emoji(weapon_info["type"]) pawn_star = PawnStar(weapon_info["weapon"]) if pawn_star.is_unrand(): unrand_emoji = "PraiseIt" else: unrand_emoji = "" send_chat_to_stream( [ f"{emoji} {unrand_emoji} Winner {weapon_info['character']} {unrand_emoji} {emoji} - Category: {weapon_info['type']}", WeaponsFormatter(character, []).format_weapon(weapon_info), ] )
def _look_for_unrands(msg): try: new_unrands = [] # Why are we decoded as the first thing we do in a function??? decoded_msg = json.loads(msg) message = decoded_msg["Message"] print(f"\033[33mmessage: {message}\033[0m") character_weapon_info = json.loads(message) character = Character(name=character_weapon_info["character"]) new_weapons = character_weapon_info["weapons"] new_unrands = [ weapon for weapon in new_weapons if PawnStar(weapon).is_unrand() ] if new_unrands: send_chat_to_stream( f"OSFrog {character.name} got a New Unrand! OSFrog {' || '.join(new_unrands)}" ) except Exception as e: print(f"Error: {e} | msg: {msg}")
def process_event(event): morgue_event = MorgueEvent.from_event(event) if morgue_event.command == "!h?": return print_the_help() # Elif Island msg = None if morgue_event.is_character_command(): print("A single Character Command!") character = Character(name=morgue_event.character) formatter = Formatter(character) if morgue_event.command == "!armour": msg = formatter.print_armour() elif morgue_event.command == "!weapons": msg = formatter.print_weapons() elif morgue_event.command == "!runes": msg = formatter.print_runes() elif morgue_event.command == "!spells": if morgue_event.level_barrier: msg = character.spells_above(morgue_event.level_barrier) else: msg = formatter.print_spells() elif morgue_event.command == "!skills": msg = formatter.print_skills() elif morgue_event.command == "!version": msg = formatter.print_version() elif morgue_event.command == "!jewellery": msg = formatter.print_jewellery() print( f"WE are looking for jewellery and this is what we found {msg}" ) elif morgue_event.command == "!max_damage": msg = formatter.print_max_damage() elif morgue_event.command == "!mutations": msg = formatter.print_mutations() elif morgue_event.command == "!scrolls": msg = formatter.print_scrolls() elif morgue_event.command == "!potions": msg = formatter.print_potions() elif morgue_event.command == "!gods": msg = formatter.print_gods() elif morgue_event.command == "!overview": morgue_parser = MorgueParser(character.non_saved_morgue_file()) msg = morgue_parser.overview() elif morgue_event.command == "!fetch": morgue_saver(character, character.non_saved_morgue_file(), True) elif morgue_event.command == "!fetch_s3_morgue": print(f"We are fetching the S3 Morgue for {character.name}") with open(f"tmp/s3_{character.name}.txt", "w") as f: f.write(character.s3_morgue_file()) elif morgue_event.command == "!save_morgue": save_morgue(character) elif morgue_event.command == "!search": pass # for c in ["!armour", "!weapons", "!jewellery"]: # call_command_with_arg(formatter, c, morgue_event.args[0]) elif morgue_event.is_multi_character_command(): print("A multiple Character Command!") if morgue_event.command == "!stalk_all": characters = fetch_characters() for character in characters: character = Character(name=character) morgue_saver(character, character.non_saved_morgue_file(), True) elif morgue_event.command == "!rune_awards": rune_awards() elif morgue_event.command == "!characters": characters = fetch_characters() msg = ["All The Characters"] + [", ".join(characters)] elif morgue_event.command == "!clean_morgue": print("COMING SOON") # clean_the_morgue() elif morgue_event.command == "!weapon_awards": find_the_max_damage_for_all_characters() else: print("WE DON'T KNOW THAT COMMAND!!!!!!!") if morgue_event.search: print(f"We are searching: {morgue_event.search}") if type(msg) is list: print("Search a List") msg = [item for item in msg if morgue_event.search in item] else: print("Search a strang") if morgue_event.search not in msg: msg = None if msg: send_chat_to_stream(msg) else: print( f"No Message return for command: {morgue_event.command} character: {morgue_event.character}" )
def test_lookup_skill(): character = Character(morgue_filepath="support/GucciMane.txt", local_mode=True) assert character.lookup_skill("Conjurations").level == 4.6
def test_spellcasting(): character = Character(morgue_filepath="support/GucciMane.txt", local_mode=True) assert character.spellcasting() == 3.5
def test_morgue_filepath(): local_mode = True character = Character(name="GucciMane", local_mode=local_mode) expected_filepath = f"/Users/begin/Library/Application Support/Dungeon Crawl Stone Soup/morgue/GucciMane.txt" assert character.morgue_filepath == expected_filepath
def test_spells(): character = Character(name="GucciMane", local_mode=True) spells = list(character.spells()) assert type(spells[0]) == Spell
def test_morgue_url(): character = Character(name="GucciMane") expected_url = "http://crawl.akrasiac.org/rawdata/GucciMane/GucciMane.txt" assert character.morgue_url == expected_url
def main(): parser = OptionParser() # Where to find the Morgue File parser.add_option("-c", "--char", action="store", type="string", dest="character") parser.add_option("-l", "--local", action="store_true", dest="local_mode") parser.add_option("-m", "--morgue-file", action="store", type="string", dest="morgue_filepath") parser.add_option("-u", "--morgue-url", action="store", type="string", dest="morgue_url") parser.add_option("-s", "--search", action="store", type="string", dest="search") parser.add_option("-b", "--level-barrier", action="store", type="string", dest="level_barrier") # Run in Different Modes parser.add_option("-e", "--exec-cmd", action="store", type="string", dest="exec_command") # Whether to have the bot post back to Twitch parser.add_option("-d", "--disable-twitch", action="store_true", dest="disable_twitch") (options, args) = parser.parse_args() server = connect_to_twitch() character = Character( morgue_filepath=options.morgue_filepath, morgue_url=options.morgue_url, name=options.character, local_mode=options.local_mode, ) # Create a MorgueEvent # LOCAL # CommandLineParser.from_options(options) # MorgueEvent(command=, character= args=f]) if options.exec_command: # send_chat_to_stream(f"pastaThat Character: {character.name} pastaThat") process_event({ "character": options.character, "command": f"!{options.exec_command}", "level_barrier": options.level_barrier, "search": options.search, }) else: # TWITCH CHAT run_bot(server, character=character)
def fetch(name): character = Character(name=name) morgue_saver(character, character.non_saved_morgue_file(), True) return f"Fetched {name}'s Morgue File!"
class Game: def __init__(self): # Pygame launch pygame.display.set_caption("SANTARENA") # Screen (camera) self.camera = Camera() # Tilemap self.tilemap = Tilemap(MAP_H, MAP_W) # Characters self.character = Character() self.enemies = [] # Clock self.clock = Clock() self.dt = 0 def start(self): """ Called once. """ # Set the camera in the center of the map self.camera.posH = (self.tilemap.h - self.camera.h) / 2 self.camera.posW = (self.tilemap.w - self.camera.w) / 2 # Set the character sprite in the center of the screen self.character.posH = (self.camera.posH + (self.camera.h - self.character.rectH) / 2) self.character.posW = (self.camera.posW + (self.camera.w - self.character.rectW) / 2) # Spawn some enemies for _ in range(3): randH = randrange(400) randW = randrange(700) self.enemies.append(Enemy(randH, randW)) def event(self): # Quit for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() # Full screen toggle if event.type is pygame.KEYDOWN and event.key == pygame.K_f: if self.camera.screen.get_flags() & pygame.FULLSCREEN: pygame.display.set_mode(self.camera.size) else: pygame.display.set_mode((0, 0), pygame.FULLSCREEN) # Character self.character.event( pygame.key.get_pressed(), self.camera, self.enemies, self.tilemap.blocks, self.dt, ) # Enemies for enemy in self.enemies: enemy.event(self.character, self.enemies, self.tilemap.blocks) # Camera self.camera.move(pygame.key.get_pressed(), self.character, self.dt) def update(self): # Map self.tilemap.update(self.camera) # Character & projectiles self.character.update(self.camera, self.tilemap.blocks, self.dt) # Enemies for enemy in self.enemies: enemy.update(self.character, self.enemies, self.camera, self.dt) # Tic tac self.dt = self.clock.tick(FPS) def draw(self): # Reset self.camera.screen.fill(COLORS["BLACK"]) # Tilemap self.tilemap.draw(self.camera) # Enemies for enemy in self.enemies: enemy.draw(self.camera) # Character self.character.draw(self.camera) pygame.display.update()