예제 #1
0
    def plunder(self, _id):
        if str(_id) not in self.mongo_plunder.chars:
            raise SanguoException(
                errormsg.PLUNDER_NOT_IN_LIST, self.char_id, "Plunder Plunder",
                "Plunder, {0} not in plunder list".format(_id))

        counter = Counter(self.char_id, 'plunder')
        if counter.remained_value <= 0:
            char = Char(self.char_id).mc
            if char.vip < VIP_MAX_LEVEL:
                raise SanguoException(
                    errormsg.PLUNDER_NO_TIMES, self.char_id, "Plunder Battle",
                    "Plunder no times. vip current: {0}, max: {1}".format(
                        char.vip, VIP_MAX_LEVEL))
            raise SanguoException(
                errormsg.PLUNDER_NO_TIMES_FINAL, self.char_id,
                "Plunder Battle",
                "Plunder no times. vip reach max level {0}".format(
                    VIP_MAX_LEVEL))

        msg = MsgBattle()
        pvp = PVP(self.char_id, _id, msg)
        pvp.start()

        if not self.mongo_plunder.chars[str(_id)].is_robot:
            char = Char(self.char_id)
            h = Hang(_id)
            h.plundered(char.cacheobj.name, not msg.self_win)

        t = Task(self.char_id)
        t.trig(3)

        ground_win_times = 0
        if msg.first_ground.self_win:
            ground_win_times += 1
        if msg.second_ground.self_win:
            ground_win_times += 1
        if msg.third_ground.self_win:
            ground_win_times += 1

        got_point = PLUNDER_POINT.get(ground_win_times, 0)
        if got_point:
            self.mongo_plunder.points += got_point

        if msg.self_win:
            counter.incr()
            self.mongo_plunder.target_char = _id

            drop_official_exp = PLUNDER_GET_OFFICIAL_EXP_WHEN_WIN
            drop_gold = PLUNDER_DEFENSE_FAILURE_GOLD

            resource = Resource(self.char_id, "Plunder")
            resource.add(gold=drop_gold, official_exp=drop_official_exp)
        else:
            self.mongo_plunder.target_char = 0

        self.mongo_plunder.got_reward = []
        self.mongo_plunder.save()
        self.send_notify()
        return msg
예제 #2
0
    def add(self, **kwargs):
        from core.character import Char
        from core.hero import save_hero, HeroSoul, FakeSaveHeroResult
        from core.item import Item

        data = _get_resource_data(**kwargs)
        purchase_got = kwargs.get('purchase_got', 0)
        purchase_actual_got = kwargs.get('purchase_actual_got', 0)

        if data['gold'] or data['sycee'] or data['exp'] or data['official_exp'] or purchase_got:
            char = Char(self.char_id)
            char.update(gold=data['gold'], sycee=data['sycee'], exp=data['exp'], official_exp=data['official_exp'],
                        purchase_got=purchase_got,
                        purchase_actual_got=purchase_actual_got,
                        )
    
        if data['heros']:
            heros = []
            for _id, _amount in data['heros']:
                heros.extend([_id] * _amount)
            sh_res = save_hero(self.char_id, heros)
        else:
            sh_res = FakeSaveHeroResult
    
        if data['souls']:
            hs = HeroSoul(self.char_id)
            hs.add_soul(data['souls'])
    
        item = Item(self.char_id)
        for _id, _level, _amount in data['equipments']:
            for i in range(_amount):
                item.equip_add(_id, _level)
    
        if data['gems']:
            item.gem_add(data['gems'])
    
        if data['stuffs']:
            item.stuff_add(data['stuffs'])
    
        # normalize the data
        if data['heros']:
            data['heros'] = sh_res.actual_heros
            souls = dict(data['souls'])
    
            for _sid, _samount in sh_res.to_souls:
                souls[_sid] = souls.get(_sid, 0) + _samount

            data['souls'] = souls.items()

        data['income'] = 1
        data['func_name'] = self.func_name
        data['des'] = self.des
        resource_logger(self.char_id, data)

        data.pop('income')
        data.pop('func_name')
        data.pop('des')
        return data
예제 #3
0
 def get(self):
     try:
         cid = self.team.pop(0)
         c = Char(cid)
         c.union_battle_power = c.power
         c.union_battle_power_original = c.power
         return c
     except IndexError:
         raise UnionBattleRecord.TeamEnd()
예제 #4
0
def _check_character(char_id, gold=0, sycee=0, func_name=""):
    from core.character import Char
    c = Char(char_id)
    mc = c.mc
    if gold < 0 and mc.gold < abs(gold):
        raise SanguoException(GOLD_NOT_ENOUGH, char_id, func_name, 'Gold Not Enough. {0} < {1}'.format(mc.gold, abs(gold)))
    if sycee < 0 and mc.sycee < abs(sycee):
        raise SanguoException(SYCEE_NOT_ENOUGH, char_id, func_name, 'Sycee Not Enough. {0} < {1}'.format(mc.sycee, abs(sycee)))

    yield

    if gold or sycee:
        c.update(gold=gold, sycee=sycee)
예제 #5
0
    def reset_one(self, _id):
        str_id = str(_id)
        if str_id not in self.stage.elites:
            raise SanguoException(
                errormsg.STAGE_ELITE_NOT_OPEN,
                self.char_id,
                "Elite Reset One",
                "reset a not opened stage {0}".format(_id)
            )

        reset_times = self.stage.elites_buy.get(str(_id), 0)
        char = Char(self.char_id).mc
        can_reset_times = VIP_FUNCTION[char.vip].stage_elite_buy
        if reset_times >= can_reset_times:
            raise SanguoException(
                errormsg.STAGE_ELITE_RESET_FULL,
                self.char_id,
                "Elite Reset One",
                "reset {0}".format(_id)
            )

        cost = self.get_reset_cost(_id)

        resource = Resource(self.char_id, "Elite Reset One", "reset {0}".format(_id))
        with resource.check(sycee=-cost):
            self.stage.elites[str(_id)] = 0
            self.stage.elites_buy[str(_id)] = reset_times + 1
            self.stage.save()

        self.send_update_notify(_id)
예제 #6
0
    def plunder(self):
        if not self.mongo_plunder.char_id:
            raise SanguoException(errormsg.PLUNDER_NO_RIVAL, self.char_id,
                                  "Plunder Battle", "no rival target")

        if self.mongo_plunder.current_times <= 0:
            raise SanguoException(errormsg.PLUNDER_NO_TIMES, self.char_id,
                                  "Plunder Battle", "no times")

        self.change_current_plunder_times(change_value=-1)

        rival_battle_heros = dill.loads(
            base64.b64decode(self.mongo_plunder.battle_heros))

        msg = MsgBattle()
        pvp = PlunderBattle(
            self.char_id,
            self.mongo_plunder.char_id,
            msg,
            self.mongo_plunder.char_name,
            rival_battle_heros,
        )
        pvp.start()

        t = Task(self.char_id)
        t.trig(3)

        to_char_id = self.mongo_plunder.char_id
        target_server_url = self.mongo_plunder.server_url

        if msg.self_win:
            standard_drop = self._get_plunder_reward(
                self.mongo_plunder.char_city_id, self.mongo_plunder.char_gold,
                self.mongo_plunder.char_hero_original_ids)

            self.clean_plunder_target()

            achievement = Achievement(self.char_id)
            achievement.trig(12, 1)

            PlunderLeaderboardWeekly.incr(self.char_id)
            TimesLogPlunder(self.char_id).inc()
        else:
            standard_drop = make_standard_drop_from_template()

        self.mongo_plunder.plunder_times += 1
        self.mongo_plunder.save()
        self.send_notify()

        plunder_finished_signal.send(
            sender=None,
            from_char_id=self.char_id,
            from_char_name=Char(self.char_id).mc.name,
            to_char_id=to_char_id,
            from_win=msg.self_win,
            standard_drop=standard_drop,
            target_server_url=target_server_url,
        )

        return (msg, standard_drop)
예제 #7
0
    def get_plunder_target(self, city_id):
        """
        @:rtype: PlunderRival
        """

        target = PlunderRival.search_all_servers(city_id,
                                                 exclude_char_id=self.char_id)
        self.mongo_plunder.char_id = target.char_id
        self.mongo_plunder.char_name = target.name
        self.mongo_plunder.char_gold = target.get_plunder_gold(
            Char(self.char_id).mc.level)
        self.mongo_plunder.char_power = target.power
        self.mongo_plunder.char_leader = target.leader
        self.mongo_plunder.char_formation = target.formation
        self.mongo_plunder.char_hero_original_ids = target.hero_original_ids
        self.mongo_plunder.char_city_id = target.city_id
        self.mongo_plunder.battle_heros = target.battle_heros
        self.mongo_plunder.server_url = target.server_url
        self.mongo_plunder.save()

        if target:
            gold_needs = BATTLES[city_id].refresh_cost_gold
            resource = Resource(self.char_id, "Plunder Refresh")
            resource.check_and_remove(gold=-gold_needs)

        return target
예제 #8
0
    def levy(self):
        char = Char(self.char_id).mc

        if self.counter.remained_value <= 0:
            if char.vip < VIP_MAX_LEVEL:
                raise SanguoException(
                    errormsg.LEVY_NO_TIMES, self.char_id, "Levy",
                    "no times. but can get additional times by increase vip level. current: {0}, max: {1}"
                    .format(char.vip, VIP_MAX_LEVEL))
            raise SanguoException(
                errormsg.LEVY_NO_TIMES_FINAL, self.char_id, "Levy",
                "no times. vip reach the max level {0}".format(VIP_MAX_LEVEL))

        resource = Resource(self.char_id, "Levy")
        cost_cyess = self.get_cost_sycee()

        with resource.check(sycee=-cost_cyess):
            drop = self.get_levy_drop()

            self.counter.incr()
            standard_drop = resource.add(**drop)

        t = Task(self.char_id)
        t.trig(4)

        self.send_notify()
        return standard_drop
예제 #9
0
def create_character_infomation_message(char_id):
    from core.character import Char
    from core.formation import Formation
    from core.hero import char_heros_dict

    msg = CharacterInfomation()

    char = Char(char_id)
    heros = char_heros_dict(char_id)
    f = Formation(char_id)

    msg.id = char.mc.id
    msg.name = char.mc.name
    msg.level = char.mc.level
    msg.vip = char.mc.vip
    msg.power = char.power

    msg.leader = f.get_leader_oid()

    for hid in f.in_formation_hero_ids():
        msg_hero = msg.formation.add()
        if hid == 0:
            msg_hero.id = 0
            msg_hero.oid = 0
            msg_hero.step = 0
        else:
            h = heros[hid]
            msg_hero.id = h.id
            msg_hero.oid = h.oid
            msg_hero.step = h.step

    return msg
예제 #10
0
    def get_reward(self):
        counter = Counter(self.char_id, 'official_reward')
        if counter.remained_value <= 0:
            raise SanguoException(
                errormsg.OFFICAL_ALREADY_GET_REWARD,
                self.char_id,
                "OfficialDailyReward Get Reward",
                "already got"
            )


        char = Char(self.char_id)
        official_level = char.mc.official
        if official_level == 0:
            raise SanguoException(
                errormsg.OFFICAL_ZERO_GET_REWARD,
                self.char_id,
                "OfficialDailyReward Get Reward",
                "char official level = 0"
            )

        counter = Counter(self.char_id, 'official_reward')
        counter.incr()

        gold = OFFICIAL[official_level].gold

        resource = Resource(self.char_id, "Daily Official", 'official reward')
        standard_drop = resource.add(gold=gold)
        return standard_drop_to_attachment_protomsg(standard_drop)
예제 #11
0
    def battle(self):
        need_sycee = 0

        counter = Counter(self.char_id, 'arena')
        if counter.remained_value <= 0:
            counter = Counter(self.char_id, 'arena_buy')
            if counter.remained_value <= 0:
                char = Char(self.char_id).mc
                if char.vip < VIP_MAX_LEVEL:
                    raise SanguoException(
                        errormsg.ARENA_NO_TIMES, self.char_id, "Arena Battle",
                        "arena no times. vip current: {0}, max {1}".format(
                            char.vip, VIP_MAX_LEVEL))
                raise SanguoException(
                    errormsg.ARENA_NO_TIMES_FINAL, self.char_id,
                    "Arena Battle",
                    "arena no times. vip reach max level {0}".format(
                        VIP_MAX_LEVEL))
            else:
                need_sycee = ARENA_COST_SYCEE

        rival_id = self.choose_rival()
        if not rival_id:
            raise SanguoException(errormsg.ARENA_NO_RIVAL, self.char_id,
                                  "Arena Battle", "no rival.")

        if need_sycee:
            resource = Resource(self.char_id, "Arena Battle",
                                "battle for no free times")
            resource.check_and_remove(sycee=-need_sycee)

        counter.incr()

        # set battle cd
        redis_client.setex(REDIS_ARENA_BATTLE_CD_KEY(rival_id), 1, ARENA_CD)

        msg = protomsg.Battle()
        b = PVP(self.char_id, rival_id, msg)
        b.start()

        if msg.self_win:
            achievement = Achievement(self.char_id)
            achievement.trig(11, 1)

        self_score = self.score
        rival_arena = Arena(rival_id)
        rival_score = rival_arena.score

        new_score = calculate_score(self_score, rival_score, msg.self_win)
        self.set_score(new_score)

        t = Task(self.char_id)
        t.trig(2)

        self.send_notify(score=new_score)

        rival_arena.be_beaten(rival_score, self_score, not msg.self_win,
                              self.char_id)

        return msg
예제 #12
0
    def got_plundered(self, from_char_id, from_win, standard_drop):
        from_char = Char(from_char_id)
        from_name = from_char.mc.name

        if from_win:
            tp = 1
        else:
            tp = 2

        gold = standard_drop['gold']
        item_text = standard_drop_to_readable_text(standard_drop, sign='-')

        log = MongoEmbeddedHangLog()
        log.timestamp = arrow.utcnow().timestamp
        log.tp = tp
        log.who = from_name
        log.gold = gold
        log.item_text = item_text

        self.mongo_affairs.logs.append(log)

        if len(self.mongo_affairs.logs) > PLUNDER_LOG_MAX_AMOUNT:
            self.mongo_affairs.logs.pop(0)

        self.mongo_affairs.save()
        self.send_hang_notify()
예제 #13
0
    def levy(self):
        char = Char(self.char_id).mc

        if self.counter.remained_value <= 0:
            if char.vip < VIP_MAX_LEVEL:
                raise SanguoException(
                    errormsg.LEVY_NO_TIMES, self.char_id, "Levy",
                    "no times. but can get additional times by increase vip level. current: {0}, max: {1}"
                    .format(char.vip, VIP_MAX_LEVEL))
            raise SanguoException(
                errormsg.LEVY_NO_TIMES_FINAL, self.char_id, "Levy",
                "no times. vip reach the max level {0}".format(VIP_MAX_LEVEL))

        resource = Resource(self.char_id, "Levy")
        cost_cyess = self.get_cost_sycee()

        with resource.check(sycee=-cost_cyess):
            got_gold = LEVY_GOT_GOLD_FUNCTION(char.level)
            prob = random.randint(1, 100)
            for k, v in LEVY_CRIT_PROB_TABLE:
                if prob <= k:
                    break

            got_gold *= v

            self.counter.incr()
            resource.add(gold=got_gold)

        self.send_notify()
예제 #14
0
def reset():
    amount = MongoArenaWeek.objects.count()

    logger = Logger("reset_arena_week.log")
    logger.write("Reset Arena Week: Start. chars amount: {0}".format(amount))

    data = MongoArenaWeek.objects.all()
    MongoArenaWeek.objects.delete()

    for d in data:
        reward = _get_reward(d.rank)
        gold = reward.week_gold
        attachment = Attachment(d.id)
        attachment.save_to_attachment(3, gold=gold)

        achievement = Achievement(d.id)
        achievement.trig(10, d.rank)

        if d.rank in TOP_RANKS:
            try:
                top = MongoArenaTopRanks.objects.get(id=d.rank)
            except DoesNotExist:
                top = MongoArenaTopRanks(id=d.rank)

            char_name = Char(d.id).cacheobj.name
            top.name = char_name
            top.save()

    logger.write("Reset Arena Week: Complete")
    logger.close()
예제 #15
0
    def make_log_message(self, boss_id):
        try:
            this_boss = self.mongo_boss.opened[str(boss_id)]
        except KeyError:
            raise SanguoException(
                errormsg.INVALID_OPERATE,
                self.char_id,
                "UnionBoss Get Log",
                "no log for boss {0}".format(boss_id)
            )

        hp = float(UNION_BOSS[boss_id].hp)

        msg = protomsg.UnionBossGetLogResponse()
        msg.ret = 0
        msg.boss_id = boss_id
        for log in self.get_battle_members_in_ordered(boss_id):
            msg_log = msg.logs.add()
            msg_log.char_id = log.char_id
            msg_log.char_name = Char(log.char_id).mc.name
            msg_log.damage = log.damage
            msg_log.precent = int(log.damage/hp * 100)

        if this_boss.hp <= 0:
            this_boss.killer.MergeFrom(msg.logs[-1])

        return msg
예제 #16
0
    def max_value(self):
        value = COUNTER[self.func_name]
        if value:
            return value

        char = Char(self.char_id).mc
        vip = VIP_FUNCTION[char.vip]
        return getattr(vip, self.func_name)
예제 #17
0
def _check_character(char_id, gold=0, sycee=0, func_name=""):
    from core.character import Char
    c = Char(char_id)
    mc = c.mc
    if gold < 0 and mc.gold < abs(gold):
        raise SanguoException(
            GOLD_NOT_ENOUGH, char_id, func_name,
            'Gold Not Enough. {0} < {1}'.format(mc.gold, abs(gold)))
    if sycee < 0 and mc.sycee < abs(sycee):
        raise SanguoException(
            SYCEE_NOT_ENOUGH, char_id, func_name,
            'Sycee Not Enough. {0} < {1}'.format(mc.sycee, abs(sycee)))

    yield

    if gold or sycee:
        c.update(gold=gold, sycee=sycee)
예제 #18
0
def _hero_change(hero_id, **kwargs):
    hero = Hero(hero_id)
    hero.save_cache()

    update_hero_notify(hero.char_id, [
        hero,
    ])

    Char(hero.char_id).send_notify()
예제 #19
0
    def get_hang_reward(self, auto_start=True):
        """立即保存掉落,并且返回attachment消息"""
        if not self.mongo_affairs.hang_city_id:
            raise SanguoException(errormsg.HANG_NOT_EXIST, self.char_id,
                                  "Get Hang Reward", "hang not exist")

        ho = self.get_hang_obj()
        battle_data = BATTLES[self.mongo_affairs.hang_city_id]

        percent = ho.passed_time / float(ho.max_time) * 100
        for _pre, _add in HANG_REWARD_ADDITIONAL:
            if percent >= _pre:
                break
        else:
            _add = 1

        char = Char(self.char_id)
        vip_level = char.mc.vip
        vip_add = VIP_FUNCTION[vip_level].hang_addition

        passed_time = int(ho.passed_time * _add * (1 + vip_add / 100.0))

        reward_gold = passed_time / 15 * battle_data.normal_gold
        reward_gold = self.get_real_gold(reward_gold, self.mongo_affairs.logs)

        reward_exp = passed_time / 15 * battle_data.normal_exp

        if battle_data.normal_drop:
            # 模拟损失物品
            drop_time = passed_time
            for log in self.mongo_affairs.logs:
                if log.tp == 1:
                    drop_time -= PLUNDER_GET_DROPS_MINUTES * 60

            drop_time_adjusted = max(int(passed_time * 0.25), drop_time)

            drops = get_drop(
                [int(i) for i in battle_data.normal_drop.split(',')],
                multi=drop_time_adjusted / 15)
        else:
            drops = make_standard_drop_from_template()

        drops['exp'] += reward_exp
        drops['gold'] += reward_gold

        resource = Resource(self.char_id, "Hang Reward")
        standard_drop = resource.add(**drops)

        if auto_start:
            # 领取奖励后自动开始
            self.start_hang(self.mongo_affairs.hang_city_id, get_reward=False)

        achievement = Achievement(self.char_id)
        achievement.trig(28, ho.passed_time / 3600)
        achievement.trig(29, reward_exp)

        return standard_drop_to_attachment_protomsg(standard_drop)
예제 #20
0
    def battle(self):
        counter = Counter(self.char_id, 'arena')
        try:
            # 免费次数
            counter.incr()
        except CounterOverFlow:
            counter = Counter(self.char_id, 'arena_buy')

            try:
                # 花费元宝次数
                counter.incr()
            except CounterOverFlow:
                char = Char(self.char_id).mc
                if char.vip < VIP_MAX_LEVEL:
                    raise SanguoException(
                        errormsg.ARENA_NO_TIMES, self.char_id, "Arena Battle",
                        "arena no times. vip current: {0}, max {1}".format(
                            char.vip, VIP_MAX_LEVEL))
                raise SanguoException(
                    errormsg.ARENA_NO_TIMES_FINAL, self.char_id,
                    "Arena Battle",
                    "arena no times. vip reach max level {0}".format(
                        VIP_MAX_LEVEL))

            else:
                resource = Resource(self.char_id, "Arena Battle",
                                    "battle for no free times")
                resource.check_and_remove(sycee=-ARENA_COST_SYCEE)

        rival_id = self.choose_rival()

        msg = protomsg.Battle()
        b = PVP(self.char_id, rival_id, msg)
        b.start()

        achievement = Achievement(self.char_id)

        if msg.self_win:
            score = ARENA_GET_SCORE_WHEN_WIN
            achievement.trig(11, 1)
            self.mongo_arena.continues_win += 1
        else:
            score = ARENA_GET_SCORE_WHEN_LOST
            self.mongo_arena.continues_win = 0

        self.mongo_arena.save()

        if score:
            self.mongo_day.score += score
            self.mongo_day.save()

        t = Task(self.char_id)
        t.trig(2)

        self.send_notify()
        return msg
예제 #21
0
def character_information(request):
    char_id = int(request.POST['char_id'])
    char = Char(char_id).mc
    return {
        'gold': char.gold,
        'sycee': char.sycee,
        'level': char.level,
        'exp': char.exp,
        'vip': char.vip,
    }
예제 #22
0
    def prisoner_get(self, _id, treasures):
        str_id = str(_id)
        if str_id not in self.p.prisoners:
            raise SanguoException(errormsg.PRISONER_NOT_EXIST, self.char_id,
                                  "Prisoner Get", "{0} not exist".format(_id))

        if not self.p.prisoners[str_id].active:
            raise SanguoException(errormsg.PRISONER_NOT_ACTIVE, self.char_id,
                                  "Prisoner Get", "{0} not active".format(_id))

        treasures_prob = 0
        for tid in treasures:
            try:
                treasures_prob += TREASURES[tid].value
            except KeyError:
                raise SanguoException(errormsg.STUFF_NOT_EXIST, self.char_id,
                                      "Prisoner Get",
                                      "treasure {0} not exist".format(tid))

        using_stuffs = [(tid, 1) for tid in treasures]

        resource = Resource(self.char_id, "Prisoner Get")
        with resource.check(stuffs=using_stuffs):
            got = False
            prob = self.p.prisoners[str_id].prob + treasures_prob
            char = Char(self.char_id).mc
            vip_plus = VIP_FUNCTION[char.vip].prisoner_get
            prob += vip_plus
            if prob >= random.randint(1, 100):
                # got it
                save_hero(self.char_id, self.p.prisoners[str_id].oid)
                got = True

                self.p.prisoners.pop(str_id)

                msg = protomsg.RemovePrisonerNotify()
                msg.ids.append(_id)
                publish_to_char(self.char_id, pack_msg(msg))
            else:
                self.p.prisoners[str_id].active = False

                msg = protomsg.UpdatePrisonerNotify()
                p = msg.prisoner.add()
                p_obj = self.p.prisoners[str_id]
                self._fill_up_prisoner_msg(p, _id, p_obj.oid, p_obj.prob,
                                           p_obj.active)

                publish_to_char(self.char_id, pack_msg(msg))

            self.p.save()

        t = Task(self.char_id)
        t.trig(5)

        return got
예제 #23
0
    def __init__(self, char_id):
        self.char_id = char_id
        self.char = Char(self.char_id)

        try:
            self.mf = MongoFriend.objects.get(id=self.char_id)
        except DoesNotExist:
            self.mf = MongoFriend(id=self.char_id)
            self.mf.friends = {}
            self.mf.accepting = []
            self.mf.save()
예제 #24
0
def get_rank_data(lowest_rank):
    # lowest_rank 最低排名,可以视为按照score从高到底排序后,最多要取多少人
    score_data = ArenaScoreManager.get_all_desc(lowest_rank)

    # 对于相同积分的人,用战斗力排序
    rank_data = []
    for char_id, score in score_data:
        rank_data.append( (char_id, score, Char(char_id).power) )

    rank_data.sort(key=lambda item: (-item[1], -item[2]))
    return rank_data
예제 #25
0
    def check(self):
        char = Char(self.char_id)
        official_level = char.cacheobj.official
        if official_level == 0:
            return

        counter = Counter(self.char_id, 'official_reward')
        remained_value = counter.remained_value
        if remained_value > 0:
            attachment = Attachment(self.char_id)
            attachment.save_to_prize(6)
예제 #26
0
    def max_plunder_times(self):
        char = Char(self.char_id)
        times = VIP_FUNCTION[char.mc.vip].plunder

        ae = ActivityEntry(self.char_id, 40007)
        if not ae or not ae.is_ok():
            return times

        if times > 10:
            return times

        return 10
예제 #27
0
    def be_beaten(self, self_score, rival_score, win, rival_id):
        score = calculate_score(self_score, rival_score, win)
        self.set_score(score)

        rival_name = Char(rival_id).mc.name

        record = MongoEmbeddedArenaBeatenRecord()
        record.name = rival_name
        record.old_score = self_score
        record.new_score = score

        self.mongo_arena.beaten_record.append(record)
        self.mongo_arena.save()
예제 #28
0
def login_notify(char_id):
    hero_objs = char_heros_obj(char_id)

    Char(char_id).send_notify()

    hero_notify(char_id, hero_objs)
    Item(char_id).send_notify()

    f = Formation(char_id)
    f.send_socket_notify()
    f.send_formation_notify()

    hang = Hang(char_id)
    hang.send_notify()

    Plunder(char_id).send_notify()

    p = Prison(char_id)
    p.send_prisoners_notify()

    Arena(char_id).send_notify()

    f = Friend(char_id)
    f.send_friends_notify()
    f.send_friends_amount_notify()

    m = Mail(char_id)
    m.send_mail_notify()

    CheckIn(char_id).send_notify()


    stage = Stage(char_id)
    stage.send_already_stage_notify()
    stage.send_new_stage_notify()

    stage_elite = EliteStage(char_id)
    stage_elite.send_notify()
    stage_elite.send_remained_times_notify()

    stage_activity = ActivityStage(char_id)
    stage_activity.send_notify()
    stage_activity.send_remained_times_notify()

    HeroPanel(char_id).send_notify()
    Task(char_id).send_notify()
    Achievement(char_id).send_notify()
    HeroSoul(char_id).send_notify()
    FunctionOpen(char_id).send_notify()
    Levy(char_id).send_notify()
    Attachment(char_id).send_notify()
예제 #29
0
    def get_top_ranks(self):
        # return [(char_id, score, power, name,  leader), ...]
        top_data = redis_client.zrevrange(REDIS_ARENA_KEY,
                                          0,
                                          2,
                                          withscores=True)
        tops = []
        for _id, _score in top_data:
            char = Char(int(_id))
            tops.append(
                (int(_id), _score, char.power, char.mc.name, char.leader_oid))

        tops.sort(key=lambda item: (-item[1], -item[2]))
        return tops
예제 #30
0
    def get_hang_remained(self, char=None):
        if not char:
            char = Char(self.char_id).mc
        vip = char.vip
        max_seconds = HANG_MAX_SECONDS_FUNCTION(vip)
        remained = max_seconds - self.hang.used
        if remained > 0:
            if self.hang_doing and not self.hang_doing.finished:
                remained = remained - (arrow.utcnow().timestamp -
                                       self.hang_doing.start)

        if remained <= 0:
            remained = 0
        return remained
예제 #31
0
    def check(self, char_level=None, send_notify=True):
        if not char_level:
            char = Char(self.char_id)
            char_level = char.mc.level

        enabled = []
        for k, v in STAGE_ACTIVITY_CONDITION.iteritems():
            if char_level >= k:
                for _v in v:
                    if _v not in self.stage.activities:
                        enabled.append(_v)

        if enabled:
            self.enable(enabled, send_notify=send_notify)
예제 #32
0
    def get_drop(self, passed_time=None, multi=1):
        ae = ActivityEntry(self.char_id, 60001)

        ho = self.get_hang_obj()
        battle_data = BATTLES[self.mongo_affairs.hang_city_id]

        if not passed_time:
            passed_time = ho.passed_time

        percent = passed_time / float(ho.max_time) * 100
        for _pre, _add in HANG_REWARD_ADDITIONAL:
            if percent >= _pre:
                break
        else:
            _add = 1

        char = Char(self.char_id)
        vip_level = char.mc.vip
        vip_add = VIP_FUNCTION[vip_level].hang_addition

        passed_time = int(passed_time * _add * (1 + vip_add / 100.0))

        reward_gold = passed_time / 15 * battle_data.normal_gold
        reward_gold = self.get_real_gold(reward_gold, self.mongo_affairs.logs)

        if ae and ae.is_valid():
            reward_gold *= 2

        reward_exp = passed_time / 15 * battle_data.normal_exp

        if battle_data.normal_drop:
            # 模拟损失物品
            drop_time = passed_time
            for log in self.mongo_affairs.logs:
                if log.tp == 1:
                    drop_time -= PLUNDER_GET_DROPS_MINUTES * 60

            drop_time_adjusted = max(int(passed_time * 0.25), drop_time)

            multi = int(drop_time_adjusted/15*multi)
            if ae and ae.is_valid():
                multi *= 2
            drops = get_drop([int(i) for i in battle_data.normal_drop.split(',')], multi=multi)
        else:
            drops = make_standard_drop_from_template()

        drops['exp'] = reward_exp
        drops['gold'] = reward_gold
        return drops
예제 #33
0
def _socket_hero_changed(char_id, socket_id, hero_id, **kwargs):
    if socket_id == 1:
        char = Char(char_id)
        char.send_notify()
예제 #34
0
    def add(self, **kwargs):
        from core.character import Char
        from core.hero import save_hero, HeroSoul, FakeSaveHeroResult
        from core.item import Item
        from core.horse import Horse
        from core.union.member import Member

        notify_settings = {}
        notify_settings['purchase_notify'] = kwargs.get('purchase_notify', True)

        data = _get_resource_data(**kwargs)
        purchase_got = kwargs.get('purchase_got', 0)
        purchase_actual_got = kwargs.get('purchase_actual_got', 0)

        if data['gold'] or data['sycee'] or data['exp'] or data['official_exp'] or purchase_got:
            char = Char(self.char_id)
            char.update(gold=data['gold'], sycee=data['sycee'], exp=data['exp'], official_exp=data['official_exp'],
                        purchase_got=purchase_got,
                        purchase_actual_got=purchase_actual_got,
                        notify_settings=notify_settings
                        )

        union_coin = kwargs.get('union_coin', 0)
        union_contribute_points = kwargs.get('union_contribute_points', 0)
        if union_coin or union_contribute_points:
            m = Member(self.char_id)
            m.add_coin(union_coin, send_notify=False)
            m.add_contribute_points(union_contribute_points)

    
        if data['heros']:
            heros = []
            for _id, _amount in data['heros']:
                heros.extend([_id] * _amount)
            sh_res = save_hero(self.char_id, heros)
        else:
            sh_res = FakeSaveHeroResult
    
        if data['souls']:
            hs = HeroSoul(self.char_id)
            hs.add_soul(data['souls'])
    
        item = Item(self.char_id)
        for _id, _level, _amount in data['equipments']:
            for i in range(_amount):
                item.equip_add(_id, _level)
    
        if data['gems']:
            item.gem_add(data['gems'])
    
        if data['stuffs']:
            item.stuff_add(data['stuffs'])

        if data['horses']:
            horse = Horse(self.char_id)
            for _id, _amount in data['horses']:
                for i in range(_amount):
                    horse.add(_id)
    
        # normalize the data
        if data['heros']:
            data['heros'] = sh_res.actual_heros
            souls = dict(data['souls'])
    
            for _sid, _samount in sh_res.to_souls:
                souls[_sid] = souls.get(_sid, 0) + _samount

            data['souls'] = souls.items()

        data['income'] = 1
        data['func_name'] = self.func_name
        data['des'] = self.des
        resource_logger(self.char_id, data)

        data.pop('income')
        data.pop('func_name')
        data.pop('des')
        return data