Exemplo n.º 1
0
    def send_addition_sycee_via_mail(self, sycee):
        # XXX 充值额外赠送通过邮件发送
        drop = make_standard_drop_from_template()
        drop['sycee'] = sycee

        m = Mail(self.char_id)
        m.add(u"充值额外赠送", u"感谢您的充值,请领取额外赠送", attachment=json.dumps(drop))
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def cron_job(self):
        # 由系统的定时任务触发
        # linux cronjob 每天定时执行
        self.hang.used = 0
        self.hang.save()

        if self.hang_doing:
            stage_id = self.hang_doing.stage_id
            if not self.hang_doing.finished:
                # 到结算点就终止
                self.finish(set_hang=False)
        else:
            stage_id = max_star_stage_id(self.char_id)

        self.send_notify()

        remained = self.get_hang_remained()
        if remained and stage_id:
            stage = STAGES[stage_id]
            exp = remained / 15 * stage.normal_exp
            gold = remained / 15 * stage.normal_gold * 0.5
            standard_drop = make_standard_drop_from_template()
            standard_drop['exp'] = int(exp)
            standard_drop['gold'] = int(gold)

            m = Mail(self.char_id)
            m.add(
                HANG_RESET_MAIL_TITLE,
                HANG_RESET_MAIL_CONTENT,
                arrow.utcnow().to(settings.TIME_ZONE).format('YYYY-MM-DD HH:mm:ss'),
                json.dumps(standard_drop)
            )
Exemplo n.º 4
0
    def cron_job(self):
        # 由系统的定时任务触发
        # linux cronjob 每天定时执行
        self.hang.used = 0
        self.hang.save()

        if self.hang_doing:
            stage_id = self.hang_doing.stage_id
            if not self.hang_doing.finished:
                # 到结算点就终止
                self.finish(set_hang=False)
        else:
            stage_id = max_star_stage_id(self.char_id)

        self.send_notify()

        remained = self.get_hang_remained()
        if remained and stage_id:
            stage = STAGES[stage_id]
            exp = remained / 15 * stage.normal_exp
            gold = remained / 15 * stage.normal_gold * 0.5
            standard_drop = make_standard_drop_from_template()
            standard_drop['exp'] = int(exp)
            standard_drop['gold'] = int(gold)

            m = Mail(self.char_id)
            m.add(
                HANG_RESET_MAIL_TITLE, HANG_RESET_MAIL_CONTENT,
                arrow.utcnow().to(
                    settings.TIME_ZONE).format('YYYY-MM-DD HH:mm:ss'),
                json.dumps(standard_drop))
Exemplo n.º 5
0
def send_yueka_reward(char_id, sycee, remained_days):
    standard_drop = make_standard_drop_from_template()
    standard_drop['sycee'] = sycee

    content = MAIL_YUEKA_CONTENT_TEMPLATE.format(sycee, remained_days)

    Mail(char_id).add(MAIL_YUEKA_TITLE, content, attachment=json.dumps(standard_drop), only_one=True)
Exemplo n.º 6
0
    def checkin(self):
        # 签到
        from core.union.union import Union
        from core.union.battle import UnionBattle

        if not self.mongo_union_member.joined:
            raise SanguoException(
                errormsg.INVALID_OPERATE,
                self.char_id,
                "Union Checkin",
                "not join union"
            )

        if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount:
            raise SanguoException(
                errormsg.UNION_CHECKIN_REACH_MAX_TIMES,
                self.char_id,
                "Union Checkin",
                "reached max times"
            )

        try:
            c = UNION_CHECKIN[self.mongo_union_member.checkin_times+1]
        except KeyError:
            raise SanguoException(
                errormsg.UNION_CHECKIN_REACH_MAX_TIMES,
                self.char_id,
                "Union Checkin",
                "reached max times. UNION_CHECKIN KeyError: {0}".format(self.mongo_union_member.checkin_times+1)
            )

        if c.cost_type == 1:
            needs = {'gold': -c.cost_value}
        else:
            needs = {'sycee': -c.cost_value}

        resources = Resource(self.char_id, "Union Checkin")
        with resources.check(**needs):
            self.mongo_union_member.checkin_times += 1
            self.mongo_union_member.last_checkin_timestamp = arrow.utcnow().timestamp

            self.add_coin(c.got_coin, send_notify=False)
            self.add_contribute_points(c.got_contributes, send_notify=False)
            self.mongo_union_member.save()
        self.send_personal_notify()

        Union(self.char_id).add_contribute_points(c.got_contributes)

        UnionBattle(self.char_id).send_notify()
        doc = MongoUnion._get_collection().find_one(
                {'_id': self.mongo_union_member.joined},
                {'owner': 1}
        )
        owner = doc['owner']
        UnionBattle(owner).send_notify()

        drop = make_standard_drop_from_template()
        drop['union_coin'] = c.got_coin
        drop['union_contribute_points'] = c.got_contributes
        return standard_drop_to_attachment_protomsg(drop)
Exemplo n.º 7
0
def _get_reward_by_rank(rank):
    for _rank, _reward in ARENA_WEEK_REWARD_TUPLE:
        if rank <= _rank:
            drop = make_standard_drop_from_template()
            drop['stuffs'] = [(_reward.stuff, 1)]
            return drop

    return None
Exemplo n.º 8
0
def cmd(request):
    req = request._proto
    char_id = request._char_id

    if req.action == 2:
        print "Unsupported"
        return HttpResponse('', content_type='text/plain')

    drop = make_standard_drop_from_template()
    if req.tp == 1:
        drop['exp'] = req.param
    elif req.tp == 2:
        drop['official_exp'] = req.param
    elif req.tp == 3:
        drop['gold'] = req.param
    elif req.tp == 4:
        drop['sycee'] = req.param

    elif req.tp == 5:
        if req.param not in EQUIPMENTS:
            return HttpResponse('', content_type='text/plain')
        drop['equipments'].append((req.param, 1, 1))

    elif req.tp == 6:
        if req.param not in GEMS:
            return HttpResponse('', content_type='text/plain')
        drop['gems'].append((req.param, 1))

    elif req.tp == 7:
        if req.param not in HEROS:
            return HttpResponse('', content_type='text/plain')
        drop['heros'].append((req.param, 1))

    elif req.tp == 8:
        if req.param not in STUFFS:
            return HttpResponse('', content_type='text/plain')
        drop['stuffs'].append((req.param, 1))

    elif req.tp == 9:
        if req.param not in HEROS:
            return HttpResponse('', content_type='text/plain')
        drop['souls'].append((req.param, 1))

    elif req.tp == 10:
        drop['purchase_got'] = req.param
        drop['purchase_actual_got'] = req.param


    resource = Resource(char_id, "CMD", "tp: {0}, param: {1}".format(req.tp, req.param))
    standard_drop = resource.add(**drop)
    print standard_drop

    if req.tp == 11:
        fo = FunctionOpen(char_id)
        fo._open_all()
        fo.send_notify()

    return HttpResponse('', content_type='text/plain')
Exemplo n.º 9
0
def _get_reward_by_score(score):
    for _score, _reward in ARENA_DAY_REWARD_TUPLE:
        if score >= _score:
            data = make_standard_drop_from_template()
            data['sycee'] = _reward.sycee
            data['gold'] = _reward.gold
            return json.dumps(data)

    return None
Exemplo n.º 10
0
    def trig(self, extra_sycee):
        if not self.is_valid():
            return

        attachment = make_standard_drop_from_template()
        attachment["sycee"] = extra_sycee

        mail = Mail(self.char_id)
        mail.add(self.activity_data.mail_title, self.activity_data.mail_content, attachment=json.dumps(attachment))
Exemplo n.º 11
0
def _get_reward_by_score(score):
    for _score, _reward in ARENA_DAY_REWARD_TUPLE:
        if score >= _score:
            data = make_standard_drop_from_template()
            data['sycee'] = _reward.sycee
            data['gold'] = _reward.gold
            return json.dumps(data)

    return None
Exemplo n.º 12
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)
Exemplo n.º 13
0
    def special_buy(self, socket_id, tp):
        # FIXME
        try:
            this_socket = self.formation.sockets[str(socket_id)]
        except KeyError:
            raise SanguoException(errormsg.FORMATION_NONE_EXIST_SOCKET,
                                  self.char_id, "Formation Special Buy",
                                  "socket {0} not exist".format(socket_id))

        if not this_socket.hero:
            raise SanguoException(errormsg.FORMATION_NO_HERO, self.char_id,
                                  "Formation Special Buy",
                                  "socket {0} no hero".format(socket_id))

        oid = MongoHero.objects.get(id=this_socket.hero).oid

        this_hero = HEROS[oid]
        special_cls = [int(i) for i in this_hero.special_equip_cls.split(',')]

        def _find_speicial_id(equipments):
            for e in equipments:
                if e.step == 0 and e.cls in special_cls:
                    return e.id

            # FIXME
            raise Exception("Special buy, not find. tp = {0}".format(tp))

        from core.item import Item
        item = Item(self.char_id)

        if tp == SpecialEquipmentBuyRequest.SOCKET_WEAPON:
            on_id = _find_speicial_id(ALL_WEAPONS.values())
            new_id = item.equip_add(on_id)
            self.formation.sockets[str(socket_id)].weapon = new_id
        elif tp == SpecialEquipmentBuyRequest.SOCKET_ARMOR:
            on_id = _find_speicial_id(ALL_ARMORS.values())
            new_id = item.equip_add(on_id)
            self.formation.sockets[str(socket_id)].armor = new_id
        else:
            on_id = _find_speicial_id(ALL_JEWELRY.values())
            new_id = item.equip_add(on_id)
            self.formation.sockets[str(socket_id)].jewelry = new_id

        self.formation.save()
        socket_changed_signal.send(
            sender=None, socket_obj=self.formation.sockets[str(socket_id)])

        standard_drop = make_standard_drop_from_template()
        standard_drop['equipments'] = [(new_id, 1, 1)]
        standard_drop['income'] = 1
        standard_drop['func_name'] = "Special Buy"
        standard_drop['des'] = ''
        resource_logger(self.char_id, standard_drop)

        self.send_socket_changed_notify(socket_id,
                                        self.formation.sockets[str(socket_id)])
Exemplo n.º 14
0
def send_yueka_reward(char_id, sycee, remained_days):
    standard_drop = make_standard_drop_from_template()
    standard_drop['sycee'] = sycee

    content = MAIL_YUEKA_CONTENT_TEMPLATE.format(sycee, remained_days)

    Mail(char_id).add(MAIL_YUEKA_TITLE,
                      content,
                      attachment=json.dumps(standard_drop),
                      only_one=True)
Exemplo n.º 15
0
    def save_drop(self):
        if self.this_stage.tp == 1:
            prepare_drop = make_standard_drop_from_template()
            prepare_drop['gold'] = self.this_stage.normal_gold
        else:
            prepare_drop = get_drop([int(i) for i in self.this_stage.normal_drop.split(',') if i.isdigit()])

        resource = Resource(self.char_id, "ActivityStage Drop", "stage {0}".format(self.this_stage.id))
        standard_drop = resource.add(**prepare_drop)

        return standard_drop
Exemplo n.º 16
0
    def boss_has_been_killed(self, boss_id):
        # 击杀boss后发送奖励
        logs = self.get_battle_members_in_ordered(boss_id)
        member_ids = [log.char_id for log in logs]

        killer = self.char_id

        m = Mail(killer)
        drop = make_standard_drop_from_template()
        drop['union_coin'] = UNION_BOSS_KILLER_REWARD.coin
        m.add(
            UNION_BOSS_KILLER_REWARD.mail_title,
            UNION_BOSS_KILLER_REWARD.mail_content,
            attachment=json.dumps(drop)
            )

        LOWEST_RANK = max(UNION_BOSS_REWARD.keys())
        UNION_BOSS_REWARD_TUPLE = UNION_BOSS_REWARD.items()
        UNION_BOSS_REWARD_TUPLE.sort(key=lambda item: item[0])

        for index, mid in enumerate(member_ids):
            rank = index + 1
            if rank > LOWEST_RANK:
                break

            m = Mail(mid)

            for _rank, _reward in UNION_BOSS_REWARD_TUPLE:
                if _rank >= rank:
                    drop = make_standard_drop_from_template()
                    drop['union_coin'] = _reward.coin
                    m.add(
                        _reward.mail_title.format(rank),
                        _reward.mail_content.format(rank),
                        attachment=json.dumps(drop)
                    )

                    break

        # 工会获得贡献度
        self.union.add_contribute_points(UNION_BOSS[boss_id].contribute_points)
Exemplo n.º 17
0
    def boss_has_been_killed(self, boss_id):
        # 击杀boss后发送奖励
        logs = self.get_battle_members_in_ordered(boss_id)
        member_ids = [log.char_id for log in logs]

        killer = self.mongo_boss.opened[str(boss_id)].killer

        m = Mail(killer)
        drop = make_standard_drop_from_template()
        drop['union_coin'] = UNION_BOSS_KILLER_REWARD.coin
        m.add(
            UNION_BOSS_KILLER_REWARD.mail_title,
            UNION_BOSS_KILLER_REWARD.mail_content,
            attachment=json.dumps(drop)
            )

        LOWEST_RANK = max(UNION_BOSS_REWARD.keys())
        UNION_BOSS_REWARD_TUPLE = UNION_BOSS_REWARD.items().sort(key=lambda item: item[0])

        for index, mid in enumerate(member_ids):
            rank = index + 1
            if rank > LOWEST_RANK:
                break

            m = Mail(mid)

            for _rank, _reward in UNION_BOSS_REWARD_TUPLE:
                if _rank >= rank:
                    drop = make_standard_drop_from_template()
                    drop['union_coin'] = _reward.coin
                    m.add(
                        _reward.mail_title.format(rank),
                        _reward.mail_content.format(rank),
                        attachment=json.dumps(drop)
                    )

                    break

        # 工会获得贡献度
        self.union.add_contribute_points(UNION_BOSS[boss_id].contribute_points)
Exemplo n.º 18
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)
        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)
Exemplo n.º 19
0
    def _get_plunder_reward(self, city_id, gold, hero_original_ids):
        def _get_prisoner():
            prison = 0
            heros = [hid for hid in hero_original_ids if hid]

            while heros:
                hid = random.choice(heros)
                heros.remove(hid)
                if hid in PRISONER_POOL:
                    prison = hid
                    break

            if random.randint(1, 100) <= PLUNDER_GET_PRISONER_PROB:
                return prison
            return 0

        char = Char(self.char_id).mc
        vip_plus = VIP_FUNCTION[char.vip].plunder_addition

        standard_drop = make_standard_drop_from_template()
        standard_drop["gold"] = int(gold * (1 + vip_plus / 100.0))

        # 战俘
        got_hero_id = _get_prisoner()
        if got_hero_id:
            p = Prison(self.char_id)
            p.prisoner_add(got_hero_id, gold / 2)

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

        # 掉落
        city = BATTLES[city_id]
        if city.normal_drop:
            drop_ids = [int(i) for i in city.normal_drop.split(",")]
            drop_prob = max(
                PLUNDER_GET_DROPS_TIMES - (self.mongo_plunder.plunder_times - 1) * PLUNDER_DROP_DECREASE_FACTOR,
                PLUNDER_GET_DROPS_TIMES * PLUNDER_DROP_MIN_FACTOR,
            )

            drop = get_drop(drop_ids, multi=int(drop_prob))
            drop.pop("gold")
            standard_drop.update(drop)

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

        self.send_notify()
        if got_hero_id:
            standard_drop["heros"] = [(got_hero_id, 1)]

        return standard_drop
Exemplo n.º 20
0
    def trig(self, extra_sycee):
        if not self.is_valid():
            return

        attachment = make_standard_drop_from_template()
        attachment['sycee'] = extra_sycee

        mail = Mail(self.char_id)
        mail.add(
            self.activity_data.mail_title,
            self.activity_data.mail_content,
            attachment=json.dumps(attachment)
        )
Exemplo n.º 21
0
    def checkin(self):
        # 签到
        from core.union.union import Union
        from core.union.battle import UnionBattle

        if not self.mongo_union_member.joined:
            raise SanguoException(errormsg.INVALID_OPERATE, self.char_id,
                                  "Union Checkin", "not join union")

        if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount:
            raise SanguoException(errormsg.UNION_CHECKIN_REACH_MAX_TIMES,
                                  self.char_id, "Union Checkin",
                                  "reached max times")

        try:
            c = UNION_CHECKIN[self.mongo_union_member.checkin_times + 1]
        except KeyError:
            raise SanguoException(
                errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id,
                "Union Checkin",
                "reached max times. UNION_CHECKIN KeyError: {0}".format(
                    self.mongo_union_member.checkin_times + 1))

        if c.cost_type == 1:
            needs = {'gold': -c.cost_value}
        else:
            needs = {'sycee': -c.cost_value}

        resources = Resource(self.char_id, "Union Checkin")
        with resources.check(**needs):
            self.mongo_union_member.checkin_times += 1
            self.mongo_union_member.last_checkin_timestamp = arrow.utcnow(
            ).timestamp

            self.add_coin(c.got_coin, send_notify=False)
            self.add_contribute_points(c.got_contributes, send_notify=False)
            self.mongo_union_member.save()
        self.send_personal_notify()

        Union(self.char_id).add_contribute_points(c.got_contributes)

        UnionBattle(self.char_id).send_notify()
        doc = MongoUnion._get_collection().find_one(
            {'_id': self.mongo_union_member.joined}, {'owner': 1})
        owner = doc['owner']
        UnionBattle(owner).send_notify()

        drop = make_standard_drop_from_template()
        drop['union_coin'] = c.got_coin
        drop['union_contribute_points'] = c.got_contributes
        return standard_drop_to_attachment_protomsg(drop)
Exemplo n.º 22
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
Exemplo n.º 23
0
def arena_battle(request):
    char_id = request._char_id

    arena = Arena(char_id)
    msg, adding_score = arena.battle()

    response = ArenaResponse()
    response.ret = 0
    response.battle.MergeFrom(msg)

    drop = make_standard_drop_from_template()
    drop["stuffs"] = [(1001, adding_score)]

    response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop))
    return pack_msg(response)
Exemplo n.º 24
0
    def send_reward(self, aid, sycee, packages):
        if not sycee and not packages:
            return make_standard_drop_from_template()

        if packages:
            ps = [int(i) for i in packages.split(',')]
        else:
            ps = []

        drops = get_drop(ps)
        drops['sycee'] += sycee if sycee else 0

        resource = Resource(self.char_id, "Achievement Reward", "achievement {0}".format(aid))
        drops = resource.add(**drops)
        return drops
Exemplo n.º 25
0
    def get_sutff_drop(cls, _id):
        # 获得宝箱中的 drop
        from core.attachment import get_drop, is_empty_drop, make_standard_drop_from_template

        s = STUFFS[_id]
        packages = s.packages
        if not packages:
            return make_standard_drop_from_template()

        package_ids = [int(i) for i in packages.split(',')]
        prepare_drop = get_drop(package_ids)
        if is_empty_drop(prepare_drop) and s.default_package:
            package_ids = [s.default_package]
            prepare_drop = get_drop(package_ids)

        return prepare_drop
Exemplo n.º 26
0
    def send_reward(self, aid, sycee, packages):
        if not sycee and not packages:
            return make_standard_drop_from_template()

        if packages:
            ps = [int(i) for i in packages.split(',')]
        else:
            ps = []

        drops = get_drop(ps)
        drops['sycee'] += sycee if sycee else 0

        resource = Resource(self.char_id, "Achievement Reward",
                            "achievement {0}".format(aid))
        drops = resource.add(**drops)
        return drops
Exemplo n.º 27
0
    def get_sutff_drop(cls, _id):
        # 获得宝箱中的 drop
        from core.attachment import get_drop, is_empty_drop, make_standard_drop_from_template

        s = STUFFS[_id]
        packages = s.packages
        if not packages:
            return make_standard_drop_from_template()

        package_ids = [int(i) for i in packages.split(',')]
        prepare_drop = get_drop(package_ids)
        if is_empty_drop(prepare_drop) and s.default_package:
            package_ids = [s.default_package]
            prepare_drop = get_drop(package_ids)

        return prepare_drop
Exemplo n.º 28
0
    def get_drop(self, passed_time=None, multi=1):
        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)

        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)
            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
Exemplo n.º 29
0
    def after_battle(self, boss_id, damage, kill=False):
        # 每次打完给予奖励
        member = Member(self.char_id)
        boss = UNION_BOSS[boss_id]
        contribute_points = int( float(damage)/boss.hp * boss.contribute_points )
        lowest = 1
        highest = int(boss.contribute_points * 0.05)
        if contribute_points < lowest:
            contribute_points = lowest
        if contribute_points > highest:
            contribute_points = highest

        coin = 9 + contribute_points

        member.add_coin(coin, send_notify=False)
        member.add_contribute_points(contribute_points, send_notify=True)
        if not kill:
            self.union.add_contribute_points(contribute_points)

        drop = make_standard_drop_from_template()
        drop['union_coin'] = coin
        drop['union_contribute_points'] = contribute_points
        return standard_drop_to_attachment_protomsg(drop)
Exemplo n.º 30
0
    def after_battle(self, boss_id, damage, kill=False):
        # 每次打完给予奖励
        member = Member(self.char_id)
        boss = UNION_BOSS[boss_id]
        contribute_points = int(
            float(damage) / boss.hp * boss.contribute_points)
        lowest = 1
        highest = int(boss.contribute_points * 0.05)
        if contribute_points < lowest:
            contribute_points = lowest
        if contribute_points > highest:
            contribute_points = highest

        coin = 9 + contribute_points

        member.add_coin(coin, send_notify=False)
        member.add_contribute_points(contribute_points, send_notify=True)
        if not kill:
            self.union.add_contribute_points(contribute_points)

        drop = make_standard_drop_from_template()
        drop['union_coin'] = coin
        drop['union_contribute_points'] = contribute_points
        return standard_drop_to_attachment_protomsg(drop)
Exemplo n.º 31
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()

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

        drop = make_standard_drop_from_template()
        adding_score = 0
        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)
            adding_score = new_score - self_score

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

            TimesLogArenaWin(self.char_id).inc()

            ae = ActivityEntry(self.char_id, 50004)
            if ae and ae.is_valid():
                drop = ae.get_additional_drop()
                Resource(self.char_id, "Arena Win").add(**drop)

        TimesLogArena(self.char_id).inc()
        ae = ActivityEntry(self.char_id, 40006)
        if ae:
            ae.trig()

        self.send_notify()
        drop['stuffs'].append((1001, adding_score))
        return msg, drop
Exemplo n.º 32
0
    def get_reward(self, tp):
        if not self.mongo_plunder.target_char:
            raise SanguoException(
                errormsg.PLUNDER_GET_REWARD_NO_TARGET,
                self.char_id,
                "Plunder Get Reward",
                "no Target char"
            )

        if tp in self.mongo_plunder.got_reward:
            raise SanguoException(
                errormsg.PLUNDER_GET_REWARD_ALREADY_GOT,
                self.char_id,
                "Plunder Get Reward",
                "tp {0} already got".format(tp)
            )

        need_points = PLUNDER_REWARD_NEEDS_POINT[tp]
        if self.mongo_plunder.points < need_points:
            raise SanguoException(
                errormsg.PLUNDER_GET_REWARD_POINTS_NOT_ENOUGH,
                self.char_id,
                "Plunder Get Reward",
                "points not enough. {0} < {1}".format(self.mongo_plunder.points, need_points)
            )

        self.mongo_plunder.points -= need_points
        self.mongo_plunder.got_reward.append(tp)
        self.mongo_plunder.save()

        standard_drop = make_standard_drop_from_template()
        plunder_gold = self.mongo_plunder.chars[str(self.mongo_plunder.target_char)].gold

        char = Char(self.char_id).mc
        vip_plus = VIP_FUNCTION[char.vip].plunder_addition

        got_hero_id = 0
        if tp == PLUNDER_HERO:
            f = Formation(self.mongo_plunder.target_char)
            heros = f.in_formation_hero_original_ids()
            got_hero_id = random.choice([hid for hid in heros if hid])
            p = Prison(self.char_id)
            p.prisoner_add(got_hero_id, plunder_gold/2)

        elif tp == PLUNDER_STUFF:
            stage = Stage(self.mongo_plunder.target_char)
            max_star_stage = stage.stage.max_star_stage
            if not max_star_stage:
                max_star_stage = 1

            drop_ids = [int(i) for i in STAGES[max_star_stage].normal_drop.split(',')]
            drop = get_drop(drop_ids, multi=int(PLUNDER_GOT_ITEMS_HOUR * 3600 * (1+vip_plus/100.0) / 15))
            standard_drop.update(drop)

        elif tp == PLUNDER_GOLD:
            standard_drop['gold'] = int(plunder_gold * (1+vip_plus/100.0))

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

        self.send_notify()
        if got_hero_id:
            standard_drop['heros'] = [got_hero_id]
        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 33
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)


        msg = MsgBattle()
        pvp = PVPFromRivalCache(
            self.char_id,
            self.mongo_plunder.char_id,
            msg,
            self.mongo_plunder.char_name,
            self.mongo_plunder.char_formation
        )
        pvp.start()

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

        to_char_id = self.mongo_plunder.char_id

        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)
        else:
            standard_drop = make_standard_drop_from_template()

        self.mongo_plunder.save()
        self.send_notify()

        plunder_finished_signal.send(
            sender=None,
            from_char_id=self.char_id,
            to_char_id=to_char_id,
            from_win=msg.self_win,
            standard_drop=standard_drop
        )

        return (msg, standard_drop)
Exemplo n.º 34
0
    def get_reward(self, tp):
        if not self.mongo_plunder.target_char:
            raise SanguoException(errormsg.PLUNDER_GET_REWARD_NO_TARGET,
                                  self.char_id, "Plunder Get Reward",
                                  "no Target char")

        if tp in self.mongo_plunder.got_reward:
            raise SanguoException(errormsg.PLUNDER_GET_REWARD_ALREADY_GOT,
                                  self.char_id, "Plunder Get Reward",
                                  "tp {0} already got".format(tp))

        need_points = PLUNDER_REWARD_NEEDS_POINT[tp]
        if self.mongo_plunder.points < need_points:
            raise SanguoException(
                errormsg.PLUNDER_GET_REWARD_POINTS_NOT_ENOUGH, self.char_id,
                "Plunder Get Reward", "points not enough. {0} < {1}".format(
                    self.mongo_plunder.points, need_points))

        self.mongo_plunder.points -= need_points
        self.mongo_plunder.got_reward.append(tp)
        self.mongo_plunder.save()

        standard_drop = make_standard_drop_from_template()
        plunder_gold = self.mongo_plunder.chars[str(
            self.mongo_plunder.target_char)].gold

        char = Char(self.char_id).mc
        vip_plus = VIP_FUNCTION[char.vip].plunder_addition

        got_hero_id = 0
        if tp == PLUNDER_HERO:
            f = Formation(self.mongo_plunder.target_char)
            heros = f.in_formation_hero_original_ids()
            got_hero_id = random.choice([hid for hid in heros if hid])
            p = Prison(self.char_id)
            p.prisoner_add(got_hero_id, plunder_gold / 2)

        elif tp == PLUNDER_STUFF:
            stage = Stage(self.mongo_plunder.target_char)
            max_star_stage = stage.stage.max_star_stage
            if not max_star_stage:
                max_star_stage = 1

            drop_ids = [
                int(i) for i in STAGES[max_star_stage].normal_drop.split(',')
            ]
            drop = get_drop(drop_ids,
                            multi=int(PLUNDER_GOT_ITEMS_HOUR * 3600 *
                                      (1 + vip_plus / 100.0) / 15))
            standard_drop.update(drop)

        elif tp == PLUNDER_GOLD:
            standard_drop['gold'] = int(plunder_gold * (1 + vip_plus / 100.0))

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

        self.send_notify()
        if got_hero_id:
            standard_drop['heros'] = [got_hero_id]
        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 35
0
    def _get_plunder_reward(self, city_id, gold, hero_original_ids):
        def _get_prisoner():
            prison = 0
            heros = [hid for hid in hero_original_ids if hid]

            while heros:
                hid = random.choice(heros)
                heros.remove(hid)
                if hid in PRISONER_POOL:
                    prison = hid
                    break

            ac = ActivityEntry(self.char_id, 30005)
            """@type: core.activity.Activity30005"""
            if not ac:
                _prob = PLUNDER_GET_PRISONER_PROB
            else:
                _prob = ac.get_prisoner_prob()

            ae = ActivityEntry(self.char_id, 50005)
            if ae and ae.is_valid():
                _vip = ae.get_current_value(self.char_id)
                if _vip == 6:
                    _prob = 50
                elif _vip >= 7:
                    _prob = 100

            if random.randint(1, 100) <= _prob:
                return prison
            return 0

        char = Char(self.char_id).mc
        vip_plus = VIP_FUNCTION[char.vip].plunder_addition

        standard_drop = make_standard_drop_from_template()
        standard_drop['gold'] = int(gold * (1 + vip_plus / 100.0))

        # 战俘
        got_hero_id = _get_prisoner()
        if got_hero_id:
            p = Prison(self.char_id)
            p.prisoner_add(got_hero_id, gold/2)

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

        # 掉落
        city = BATTLES[city_id]
        if city.normal_drop:
            drop_ids = [int(i) for i in city.normal_drop.split(',')]
            drop_prob = max(
                PLUNDER_GET_DROPS_TIMES - (self.mongo_plunder.plunder_times - 1) * PLUNDER_DROP_DECREASE_FACTOR,
                PLUNDER_GET_DROPS_TIMES * PLUNDER_DROP_MIN_FACTOR
            )

            drop = get_drop(drop_ids, multi=int(drop_prob))
            drop.pop('gold')
            standard_drop.update(drop)

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

        self.send_notify()
        if got_hero_id:
            standard_drop['heros'] = [(got_hero_id, 1)]

        return standard_drop
Exemplo n.º 36
0
    def _get_plunder_reward(self, city_id, gold, hero_original_ids):
        def _get_prisoner():
            prison = 0
            heros = [hid for hid in hero_original_ids if hid]

            while heros:
                hid = random.choice(heros)
                heros.remove(hid)
                if hid in PRISONER_POOL:
                    prison = hid
                    break

            ac = ActivityEntry(self.char_id, 30005)
            """@type: core.activity.Activity30005"""
            if not ac:
                _prob = PLUNDER_GET_PRISONER_PROB
            else:
                _prob = ac.get_prisoner_prob()

            ae = ActivityEntry(self.char_id, 50005)
            if ae and ae.is_valid():
                _vip = ae.get_current_value(self.char_id)
                if _vip == 6:
                    _prob = 50
                elif _vip >= 7:
                    _prob = 100

            if random.randint(1, 100) <= _prob:
                return prison
            return 0

        char = Char(self.char_id).mc
        vip_plus = VIP_FUNCTION[char.vip].plunder_addition

        standard_drop = make_standard_drop_from_template()
        standard_drop['gold'] = int(gold * (1 + vip_plus / 100.0))

        # 战俘
        got_hero_id = _get_prisoner()
        if got_hero_id:
            p = Prison(self.char_id)
            p.prisoner_add(got_hero_id, gold / 2)

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

        # 掉落
        city = BATTLES[city_id]
        if city.normal_drop:
            drop_ids = [int(i) for i in city.normal_drop.split(',')]
            drop_prob = max(
                PLUNDER_GET_DROPS_TIMES -
                (self.mongo_plunder.plunder_times - 1) *
                PLUNDER_DROP_DECREASE_FACTOR,
                PLUNDER_GET_DROPS_TIMES * PLUNDER_DROP_MIN_FACTOR)

            drop = get_drop(drop_ids, multi=int(drop_prob))
            drop.pop('gold')
            standard_drop.update(drop)

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

        self.send_notify()
        if got_hero_id:
            standard_drop['heros'] = [(got_hero_id, 1)]

        return standard_drop
Exemplo n.º 37
0
 def get_additional_drop(self, stuff_id):
     if stuff_id != 33:
         return make_standard_drop_from_template()
     return ActivityTriggerAdditionalDrop.get_additional_drop(self)
Exemplo n.º 38
0
    def get_additional_drop(self, *args, **kwargs):
        if not self.is_valid():
            return make_standard_drop_from_template()

        package_id = self.activity_data.package
        return get_drop([package_id])