Example #1
0
 def get(self):
     for match in Match.query(Match.winning_faction == None, Match.date <= datetime.datetime.now()):
         match.play_match()
         for match_player in MatchPlayer.query(MatchPlayer.match == match.key):
             player = match_player.player.get()
             player.doing = None
             player.put()
             websocket_notify_player("Match_Finished", player.key, None, match.get_data("full"))
             websocket_notify_player("Player_StatsChanged", player.key, "player", {'stats': player.get_stats_data()})
Example #2
0
 def _trigger_played_match(self, match_type):
     if MatchSoloQueue.query(MatchSoloQueue.type == match_type).count() >= 2:
         match_solo_queues = [match_queue for match_queue in MatchSoloQueue.query(MatchSoloQueue.type == match_type).fetch(10)]
         players = [match_queue.player.get() for match_queue in match_solo_queues]
         match = Match(type=match_type)
         match.setup_soloqueue_match(players)
         ndb.delete_multi([queue.key for queue in match_solo_queues])
         for player in players:
             player.doing = match.key
             player.put()
             websocket_notify_player("Player_MatchFound", player.key, None, match.get_data())
Example #3
0
    def _update_or_create_player_hero_stats(player, hero, stat, outcome):
        player_hero_stats = PlayerHeroStats.query(PlayerHeroStats.player == player.key, PlayerHeroStats.hero == hero).get()
        if not player_hero_stats:
            player_hero_stats = PlayerHeroStats(player=player.key, hero=hero)

        current_stat_value = getattr(player_hero_stats, stat)
        new_stat_value = current_stat_value + outcome
        setattr(player_hero_stats, stat, new_stat_value)

        player_hero_stats = player_hero_stats.put().get()
        websocket_notify_player("Player_HeroStatsChanged", player.key, "player.hero_stats.[%s]" % player_hero_stats.key.id(), player_hero_stats.get_data())
Example #4
0
    def get(self):
        now_hour = datetime.datetime.now().hour
        eligible_teams = []
        for team in Team.query().order(Team.ranked_last_match):
            if team.ranked_start_hour is None or team.ranked_end_hour is None:
                continue
            if not is_hour_in_start_end_time_range_adjusted_for_timezone_offset_issue(team.ranked_start_hour, team.ranked_end_hour, now_hour):
                continue
            if Player.query(Player.team == team.key, Player.doing == None).count() > 0: # Be aware that Player.doing == None will bug if you removed doing manually in dev console
                eligible_teams.append(team)

        while len(eligible_teams) >= 2:
            match = TeamMatch(type="TeamRanked")
            players = match.setup_team_match([eligible_teams.pop(), eligible_teams.pop()])
            for player in players:
                player.doing = match.key
                player.put()
                websocket_notify_player("Player_MatchFound", player.key, None, match.get_data())
Example #5
0
 def get(self):
     for player in Player.query():
         player.cash += CashConfig.tick_amount
         player.put()
         websocket_notify_player("Player_NewCashValue", player.key, "player", {'cash': player.cash})
Example #6
0
 def get(self):
     for player in Player.query(Player.energy < EnergyConfig.max_energy):
         if player.energy < EnergyConfig.max_energy:
             player.energy = min(EnergyConfig.max_energy, player.energy + EnergyConfig.tick_amount)
             player.put()
             websocket_notify_player("Player_NewEnergyValue", player.key, "player", {'energy': player.energy})
Example #7
0
 def websocket_notify_players(self, event, object_path, object, filter_player_key=None):
     for match_player in MatchPlayer.query(MatchPlayer.match == self.key):
         if not match_player.player == filter_player_key:
             websocket_notify_player(event, match_player.player, object_path, object)
Example #8
0
 def _pre_delete_hook(cls, key):
     match_queues = MatchSoloQueue.query(MatchSoloQueue.type == key.get().type)
     match_queues_after_deletion_count = match_queues.count() - 1
     for match_queue in match_queues:
         websocket_notify_player("Match_NewQueueCount", match_queue.player, "player.doing", {'queued': match_queues_after_deletion_count})