Exemple #1
0
    def get_player_infos(self, pids, CBE=0):
        """ 获取玩家信息
        返回: onlines, {pid:(name, rid, level, CBE)}
        """
        onlines = self.get_online_ids(pids)
        rs = {}
        #等级
        if CBE:
            levels = self.exec_players_func(onlines, _get_level_CBE, has_result=1, _pickle=True)
        else:
            levels = self.exec_players_func(onlines, _get_level, has_result=1, _pickle=True)
        off_ids = set(pids).difference(levels.keys())
        if off_ids:
            off_lvs = PlayerData.get_players_levels(off_ids, CBE=CBE)
            if off_lvs:
                levels.update(off_lvs)

        for pid in pids:
            n_rid = self.get_name_by_id(pid, rid=1)
            if not n_rid:
                continue
            if CBE:
                lv, cbe = levels.get(pid, (1, 0))
                rs[pid] = (n_rid[0], n_rid[1], lv, cbe)
            else:
                rs[pid] = (n_rid[0], n_rid[1], levels.get(pid, 1))
        return onlines, rs
Exemple #2
0
    def _reward(self):
        """ 发放奖励 """
        log.info(u'竞技场排名:%s', self.ranks[:500])
        #log.info('arena_ranks:%s', self.pid2ranks)

        mail_mgr = Game.mail_mgr
        rw_mail = Game.res_mgr.reward_mails.get(RW_MAIL_ARENA)
        levels = {}
        lv_count = 30  #批量读取等级 global arena_level
        ranks = self.ranks[:]
        log.info('arena_reward:%s', len(ranks))
        for index, pid in enumerate(ranks):
            rank = index + 1
            pids = ranks[index:index + lv_count]
            if pid not in levels:  #批量获取等级
                self._get_rivals(pids)
                rs = PlayerData.get_players_levels(pids)
                if rs:
                    levels.update(rs)
            if pid not in levels:  #玩家不存在
                continue
            rs, items, rid = self.get_reward(rank, levels[pid])
            if not rs:
                break
            #content = rw_mail.content % dict(name=self.get_name(pid), rank=rank)
            content = rw_mail.content % dict(rank=rank)
            mail_mgr.send_mails(pid,
                                MAIL_REWARD,
                                rw_mail.title,
                                RW_MAIL_ARENA,
                                items,
                                param=content,
                                rid=rid)
Exemple #3
0
 def _reward(self):
     """ 世界boss战发放奖励并 """
     rank_data = sorted(self.pid_hurts.iteritems(),
                        key=lambda x: x[1],
                        reverse=True)
     #活动奖励广播
     self.boss_mgr.safe_pub(MSG_REWARD_WORLDBOSS, rank_data, self.max_hp)
     pid_levels = PlayerData.get_players_levels(self.pid_hurts.keys())
     res_rw_mail = Game.res_mgr.reward_mails.get(RW_MAIL_BOSS)
     ranks_data = {}
     p_ranks = []
     start_type = self.start_type
     for index, (pid, hurts) in enumerate(rank_data):
         rank = index + 1
         key = (WORLD_BOSS, rank)
         rs_items = self._get_reward(key, hurts, pid_levels[pid])
         #邮件通知玩家
         content = res_rw_mail.content % dict(rank=rank)
         Game.mail_mgr.send_mails(pid,
                                  MAIL_REWARD,
                                  res_rw_mail.title,
                                  RW_MAIL_BOSS,
                                  rs_items,
                                  param=content)
         self.boss_mgr.safe_pub(MSG_REWARD_WORLDITEMS, pid, start_type,
                                rs_items)
         ranks_data[pid] = (rank, hurts)
         p_ranks.append(pid)
     self.boss_mgr.safe_pub(MSG_WBOSS_RANK, ranks_data, p_ranks)
Exemple #4
0
    def get_player_infos(self, pids, CBE=0):
        """ 获取玩家信息
        返回: onlines, {pid:(name, rid, level, CBE)}
        """
        onlines = self.get_online_ids(pids)
        rs = {}
        #等级
        if CBE:
            levels = self.exec_players_func(onlines,
                                            _get_level_CBE,
                                            has_result=1,
                                            _pickle=True)
        else:
            levels = self.exec_players_func(onlines,
                                            _get_level,
                                            has_result=1,
                                            _pickle=True)
        off_ids = set(pids).difference(levels.keys())
        if off_ids:
            off_lvs = PlayerData.get_players_levels(off_ids, CBE=CBE)
            if off_lvs:
                levels.update(off_lvs)

        for pid in pids:
            n_rid = self.get_name_by_id(pid, rid=1)
            if not n_rid:
                continue
            if CBE:
                lv, cbe = levels.get(pid, (1, 0))
                rs[pid] = (n_rid[0], n_rid[1], lv, cbe)
            else:
                rs[pid] = (n_rid[0], n_rid[1], levels.get(pid, 1))
        return onlines, rs
Exemple #5
0
 def _reward(self):
     """ 世界boss战发放奖励并 """
     rank_data = sorted(self.pid_hurts.iteritems(), key=lambda x:x[1], reverse=True)
     #活动奖励广播
     self.boss_mgr.safe_pub(MSG_REWARD_WORLDBOSS, rank_data, self.max_hp)
     pid_levels = PlayerData.get_players_levels(self.pid_hurts.keys())
     res_rw_mail = Game.res_mgr.reward_mails.get(RW_MAIL_BOSS)
     p_ranks = {}
     for index, (pid, hurts) in enumerate(rank_data):
         rank = index + 1
         key = (WORLD_BOSS, rank)
         rs_items = self._get_reward(key, hurts, pid_levels[pid])
         #邮件通知玩家
         content = res_rw_mail.content % dict(rank=rank)
         Game.mail_mgr.send_mails(pid, MAIL_REWARD,
             res_rw_mail.title, RW_MAIL_BOSS, rs_items, param=content)
         self.boss_mgr.safe_pub(MSG_REWARD_WORLDITEMS, pid, rs_items)
         p_ranks[str(pid)] = (rank, hurts)
     self.boss_mgr.safe_pub(MSG_WBOSS_RANK, p_ranks)
Exemple #6
0
 def _reward(self):
     """ 同盟boss战发放奖励并 """
     a_level = Game.rpc_ally_mgr.ally_level_by_aid(self.data.aid)
     pid_levels = PlayerData.get_players_levels(self.pid_hurts.keys())
     for rank, pid in enumerate(self.rank_pids):
         key = (ALLY_BOSS, a_level, rank+1)
         hurt = self.pid_hurts.get(pid)
         rs_items = self._get_reward(key, hurt, pid_levels[pid], a_level)
         #邮件通知玩家
         Game.mail_mgr.send_mails(pid, MAIL_REWARD,
             language.ALLY_BOSS_REWARD, RW_MAIL_ABOSS, rs_items)
     for pid, hurt in self.pid_hurts.iteritems():
         if pid in self.rank_pids:
             continue
         key = (ALLY_BOSS, a_level)
         rs_items = self._get_reward(key, hurt, pid_levels[pid], a_level)
         #邮件通知玩家
         Game.mail_mgr.send_mails(pid, MAIL_REWARD,
             language.ALLY_BOSS_REWARD, RW_MAIL_ABOSS, rs_items)
Exemple #7
0
 def _reward(self):
     """ 同盟boss战发放奖励并 """
     a_level = Game.rpc_ally_mgr.ally_level_by_aid(self.data.aid)
     pid_levels = PlayerData.get_players_levels(self.pid_hurts.keys())
     for rank, pid in enumerate(self.rank_pids):
         key = (ALLY_BOSS, a_level, rank+1)
         hurt = self.pid_hurts.get(pid)
         rs_items = self._get_reward(key, hurt, pid_levels[pid], a_level)
         #邮件通知玩家
         Game.mail_mgr.send_mails(pid, MAIL_REWARD,
             language.ALLY_BOSS_REWARD, RW_MAIL_ABOSS, rs_items)
     for pid, hurt in self.pid_hurts.iteritems():
         if pid in self.rank_pids:
             continue
         key = (ALLY_BOSS, a_level)
         rs_items = self._get_reward(key, hurt, pid_levels[pid], a_level)
         #邮件通知玩家
         Game.mail_mgr.send_mails(pid, MAIL_REWARD,
             language.ALLY_BOSS_REWARD, RW_MAIL_ABOSS, rs_items)
Exemple #8
0
    def init(self):
        """ 初始化竞技场数据:根据30级以上的玩家战斗力排名,得到竞技场排名 """
        log.warn(u"初始化竞技场")
        self.clear()
        #删除记录
        Game.rpc_store.deletes(TN_ARENA_RANKS)
        Game.rpc_store.deletes(TN_P_ARENA)
        #Game.rpc_store.insert(TN_ARENA_RANK, {FN_ID:0, FN_NEXT:END})
        #根据30级以上玩家战斗力排名
        CBEs = [(i[FN_P_ATTR_PID], i.get(FN_P_ATTR_CBE, index))
                for index, i in enumerate(PlayerAttr.get_CBE_ranks())]
        levels = PlayerData.get_players_levels(None)
        #插入机器人
        for i in xrange(self.BOT_RANK):
            self.update_rank(END, END - (i + 1))

        #真实玩家
        for pid, CBE in CBEs:
            if pid not in levels or levels[pid] < arena_level:
                continue
            self.update_rank(END, pid)