def _hero_buy_info_select_callback(menu, player_index, choice): """Hero Buy Info menu's select_callback function.""" if choice.value == 7: player = Player(player_index) if player.gold > menu.hero.cost: hero = menu.hero() player.gold -= hero.cost player.heroes.append(hero) player.hero = hero
def _buy_item_categories_build_callback(menu, player_index): """Buy Hero Categories menu's build_callback function.""" player = Player(player_index) menu.entities = [] for item in Item.get_subclasses(): if (len(tuple(find_elements(player.hero.items, 'cid', item.cid))) >= item.limit): continue elif (item.allowed_players and player.steamid not in item.allowed_players): continue menu.entities.append(item) menu.clear() categories = dict() for entity in menu.entities: if entity.category not in categories: categories[entity.category] = [entity] else: categories[entity.category].append(entity) for category in categories: menu.append( PagedOption( '{category} ({size})'.format(category=category, size=len(categories[category])), categories[category]))
def say_command_admin(command, index, team): player = Player(index) if player.steamid in cfg.admins: menus['Admin'].send(index) else: other_messages['Not Admin'].send(index) return CommandReturn.BLOCK
def _buy_hero_categories_build_callback(menu, player_index): """Buy Hero Categories menu's build_callback function.""" player = Player(player_index) menu.entities = [] for hero_cls in Hero.get_subclasses(): if find_element(player.heroes, 'cid', hero_cls.cid): continue elif (hero_cls.allowed_players and player.steamid not in hero_cls.allowed_players): continue menu.entities.append(hero_cls) menu.clear() categories = dict() for entity in menu.entities: if entity.category not in categories: categories[entity.category] = [entity] else: categories[entity.category].append(entity) for category in categories: menu.append( PagedOption( '{category} ({size})'.format(category=category, size=len(categories[category])), categories[category]))
def say_command_showxp(command, index, team): player = Player(index) other_messages['Hero Status'].send(player.index, name=player.hero.name, level=player.hero.level, current=player.hero.exp, required=player.hero.required_exp) return CommandReturn.BLOCK
def on_player_say(game_event): """Executes ultimate skills and opens the menu.""" # Get the player and the text player = Player.from_userid(game_event.get_int('userid')) text = game_event.get_string('text') # Finally, execute hero's player_say skills player.hero.execute_skills('player_say', player=player, text=text)
def on_hostage_rescued(game_event): """Give exp from hostage rescue. Also executes hostage_rescued skills. """ player = Player.from_userid(game_event.get_int('userid')) give_exp(player, 'Hostage Rescue') give_team_exp(player, 'Hostage Rescue Team') player.hero.execute_skills('hostage_rescued', player=player)
def on_bomb_defused(game_event): """Give exp from bomb defusion. Also executes bomb_defused skills. """ player = Player.from_userid(game_event.get_int('userid')) give_exp(player, 'Bomb Defuse') give_team_exp(player, 'Bomb Defuse Team') player.hero.execute_skills('bomb_defused', player=player)
def client_command_ability(command, index): ability_index = int(command.get_arg_string()) player = Player(index) if len(player.hero.abilities) >= ability_index: ability = player.hero.abilities[ability_index - 1] eargs = {'player': player} ability.execute_method('player_use', **eargs) return CommandReturn.BLOCK
def on_bomb_planted(game_event): """Give exp from bomb planting. Also executes bomb_planted skills. """ player = Player.from_userid(game_event.get_int('userid')) give_exp(player, 'Bomb Plant') give_team_exp(player, 'Bomb Plant Team') player.hero.execute_skills('bomb_planted', player=player)
def on_hostage_follows(game_event): """Give exp from hostage pick up. Also executes hostage_follows skills. """ player = Player.from_userid(game_event.get_int('userid')) give_exp(player, 'Hostage Pick Up') give_team_exp(player, 'Hostage Pick Up Team') player.hero.execute_skills('hostage_follows', player=player)
def _sell_items_build_callback(menu, player_index): """Sell Items menu's build_callback function.""" player = Player(player_index) menu.clear() for item in player.hero.items: menu.append( PagedOption( '{name} (${sell_value})'.format(name=item.name, sell_value=item.sell_value), item))
def on_player_death(game_event): """Executes kill, assist and death skills. Also gives exp from kill and assist. """ # Get the defender defender = Player.from_userid(game_event.get_int('userid')) # Create the event arguments dict eargs = { 'defender': defender, 'attacker': None, 'headshot': game_event.get_bool('headshot'), 'weapon': game_event.get_string('weapon') } # Get the attacker and execute his and defender's skills attacker_id = game_event.get_int('attacker') if attacker_id and attacker_id != defender.userid: attacker = Player.from_userid(attacker_id) eargs['attacker'] = attacker attacker.hero.execute_skills('player_kill', **eargs) defender.hero.execute_skills('player_death', **eargs) # Give attacker exp from kill and headshot give_exp(attacker, 'Kill') if eargs['headshot']: give_exp(attacker, 'Headshot') # Give attacker gold from kill give_gold(attacker, 'Kill') # Else execute player_suicide skills else: defender.hero.execute_skills('player_suicide', **eargs) # Finally, remove defender's items for item in defender.hero.items: if not item.permanent: defender.hero.items.remove(item)
def _buy_items_select_callback(menu, player_index, choice): """Buy Items menu's select_callback function.""" player = Player(player_index) player.hero.items.append(choice.value()) player.cash -= choice.value.cost eargs = {'player': player, 'item': item} item.execute_method('item_purchase', **eargs) return menu.previous_menu
def _current_hero_build_callback(menu, player_index): """Current Hero menu's build_callback function.""" # Get player and hero player = Player(player_index) hero = player.hero # Set menu's base attributes menu.title = hero.name menu.description = _TR['Description'].get_string( level=hero.level, skill_points=hero.skill_points) # Clear the menu menu.clear() # Loop through hero's skills for skill in hero.skills: # Set the default arguments for the PagedOption info = '({0}{1})'.format( skill.level, '/' + str(skill.max_level) if skill.max_level is not None else '') selectable = True # If skill is already maxed out if skill.max_level is not None and skill.level >= skill.max_level: info = ' ({0})'.format(_translate_text(_TR['Maxed'], player_index)) selectable = False # If the hero hasn't reached skill's required level elif skill.required_level > hero.level: info += ' ({0})'.format( _translate_text( _TR['Required'].get_string(req=skill.required_level), player_index)) selectable = False # If skill costs more than one, show the cost elif skill.cost > 1: info += ' ({0})'.format( _translate_text(_TR['Cost'].get_string(cost=skill.cost), player_index)) # And if hero doesn't have enough skill points, disable skill if skill.cost > hero.skill_points: selectable = False # Add the PagedOption to the menu menu.append( PagedOption('{0} {1}'.format(skill.name, info), skill, selectable=selectable, highlight=selectable))
def _owned_heroes_build_callback(menu, player_index): """Owned Heroes menu's build_callback function.""" player = Player(player_index) menu.clear() for hero in menu.entities: option = PagedOption( '{0} ({1}{2})'.format( hero.name, hero.level, '/' + str(hero.max_level) if hero.max_level is not None else ''), hero) menu.append(option)
def _sell_items_select_callback(menu, player_index, choice): """Sell Items menu's select_callback function.""" player = Player(player_index) eargs = {'player': player} choice.value.execute_method('item_sold', **eargs) player.hero.items.remove(choice.value) player.cash += choice.value.sell_value menu.send(player.index)
def _buy_heroes_build_callback(menu, player_index): """Buy Heroes menu's build_callback function.""" player = Player(player_index) menu.clear() for hero_cls in menu.entities: option = PagedOption( '{0} ({1})'.format( hero_cls.name, _translate_text(_TR['Cost'].get_string(cost=hero_cls.cost), player_index)), hero_cls) if hero_cls.cost > player.gold: option.selectable = option.highlight = False menu.append(option)
def on_player_hurt(game_event): """Executes attack and defend skills.""" # Get the defender defender = Player.from_userid(game_event.get_int('userid')) # Get the attacker attacker_id = game_event.get_int('attacker') if attacker_id and attacker_id != defender.userid: attacker = Player.from_userid(attacker_id) # Create event arguments dict eargs = { 'defender': defender, 'attacker': attacker, 'damage': game_event.get_int('dmg_health'), 'damage_armor': game_event.get_int('dmg_armor'), 'weapon': game_event.get_string('weapon') } # Execute attacker's and defender's skills attacker.hero.execute_skills('player_attack', **eargs) defender.hero.execute_skills('player_defend', **eargs)
def _buy_items_build_callback(menu, player_index): """Buy Items menu's build_callback function.""" player = Player(player_index) menu.clear() for item in menu.entities: option = PagedOption( '{name} ({cost})'.format( name=item.name, cost=_translate_text(_TR['Cost'].get_string( cost=item.cost), player_index) if not item in player.hero.restricted_items else 'RESTRICTED'), item) if item.cost > player.gold or item in player.hero.restricted_items: option.selectable = option.highlight = False menu.append(option)
def _admin_build_callback(menu, player_index): """Admin menu's build_callback function.""" player = Player(player_index) menu.clear() if player.steamid in admins: menu.extend([ Text('Admin'), Text(' '), SimpleOption(1, 'Player Management', menus['Admin Players Menu']), SimpleOption(2, 'Experience Rate', menus['Change Exp']), Text(' '), SimpleOption(9, _TR['Close'], 0, highlight=False) ]) else: menu.append(Text('Not an admin!'))
def on_player_spawn(game_event): """Saves player's data. Also executes spawn skills and shows current exp/level progress. """ # Get the player and his hero player = Player.from_userid(game_event.get_int('userid')) hero = player.hero # Show current exp and level other_messages['Hero Status'].send(player.index, name=hero.name, level=hero.level, current=hero.exp, required=hero.required_exp) # Execute spawn skills if the player's on a valid team if player.team > 1: hero.execute_skills('player_spawn', player=player)
def _current_hero_select_callback(menu, player_index, choice): """Current Hero menu's select_callback function.""" player = Player(player_index) if choice.value == 6: if player.gold >= 50: for skill in player.hero.skills: skill.level = 0 player.gold -= 50 else: message( player.index, '\x01You need \x04({}) \x01more \x09gold \x01to \x04reset skills\x01.' .format(50 - player.gold)) else: skill = choice.value if (skill.cost <= player.hero.skill_points and skill.required_level <= player.hero.level and (skill.max_level is None or skill.level < skill.max_level)): skill.level += 1 return menu
def on_player_spawn(game_event): """Saves player's data. Also executes spawn skills and shows current exp/level progress. """ # Get the player and his hero player = Player.from_userid(game_event.get_int('userid')) hero = player.hero # Show current exp and level other_messages['Hero Status'].send( player.index, name=hero.name, level=hero.level, current=hero.exp, required=hero.required_exp ) # Execute spawn skills if the player's on a valid team if player.team > 1: hero.execute_skills('player_spawn', player=player)
def _owned_hero_categories_build_callback(menu, player_index): player = Player(player_index) menu.entities = [] for hero_cls in player.heroes: menu.entities.append(hero_cls) menu.clear() categories = dict() for entity in menu.entities: if entity.category not in categories: categories[entity.category] = [entity] else: categories[entity.category].append(entity) for category in categories: menu.append( PagedOption( '{category} ({size})'.format(category=category, size=len(categories[category])), categories[category]))
def _hero_owned_info_select_callback(menu, player_index, choice): """Hero Owned Info menu's select_callback function.""" if choice.value == 7: Player(player_index).hero = menu.hero
def _main_build_callback(menu, player_index): """Main menu's build_callback function.""" menu[1].text.get_string(gold=Player(player_index).gold)
def on_player_jump(game_event): """Executes jump skills.""" player = Player.from_userid(game_event.get_int('userid')) player.hero.execute_skills('player_jump', player=player)
def client_command_ultimate(command, index): player = Player(index) player.hero.execute_skills('player_ultimate', player=player) return CommandReturn.BLOCK
def client_command_ability(command, index): player = Player(index) menu = _make_heroinfo(player.hero) menu.send(index) return CommandReturn.BLOCK
def say_command_raceinfo(command, index, team): player = Player(index) menu = _make_heroinfo(player.hero) menu.send(index) return CommandReturn.BLOCK