Exemplo n.º 1
0
    def get_reward(self, vip):
        if vip > self.mc.vip:
            raise SanguoException(
                errormsg.VIP_LEVEL_NOT_ENOUGH,
                self.char_id,
                "VIP GET REWARD",
                "vip not enough. {0} < {1}".format(self.mc.vip, vip)
            )

        vips = self.can_reward_vips()
        if vip not in vips:
            raise SanguoException(
                errormsg.VIP_HAS_GOT_REWARD,
                self.char_id,
                "VIP GET REWARD",
                "vip {0} has got reward".format(vip)
            )

        # send reward
        prepare_drop = get_drop([VIP_REWARD[vip].package])
        resource = Resource(self.char_id, "VIP GET REWARD", "vip {0}".format(vip))
        standard_drop = resource.add(**prepare_drop)

        self.mc.vip_has_reward.append(vip)
        self.mc.save()
        self.send_notify()

        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 2
0
    def save_drop(self):
        stage_id = self.hang_doing.stage_id
        actual_seconds = self.hang_doing.actual_seconds
        times = actual_seconds / 15

        stage = STAGES[stage_id]

        drop_exp = stage.normal_exp * times
        drop_gold = stage.normal_gold * times
        drop_gold = self._actual_gold(drop_gold)

        drop_ids = [int(i) for i in stage.normal_drop.split(',')]
        prepare_drop = get_drop(drop_ids, multi=times, gaussian=True)

        prepare_drop['exp'] += drop_exp
        prepare_drop['gold'] += drop_gold

        self.hang_doing.delete()
        self.hang_doing = None
        self.send_notify()

        prepare_drop = drop_after_stage_type(stage_id, prepare_drop)

        resource = Resource(self.char_id, "Hang Reward", "actual seconds = {0}, times = {1}".format(actual_seconds, times))
        standard_drop = resource.add(**prepare_drop)

        achievement = Achievement(self.char_id)
        achievement.trig(29, drop_exp)

        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 3
0
    def save_drop(self):
        stage_id = self.hang_doing.stage_id
        actual_seconds = self.hang_doing.actual_seconds
        times = actual_seconds / 15

        stage = STAGES[stage_id]

        drop_exp = stage.normal_exp * times
        drop_gold = stage.normal_gold * times
        drop_gold = self._actual_gold(drop_gold)

        drop_ids = [int(i) for i in stage.normal_drop.split(',')]
        prepare_drop = get_drop(drop_ids, multi=times, gaussian=True)

        prepare_drop['exp'] += drop_exp
        prepare_drop['gold'] += drop_gold

        self.hang_doing.delete()
        self.hang_doing = None
        self.send_notify()

        prepare_drop = drop_after_stage_type(stage_id, prepare_drop)

        resource = Resource(
            self.char_id, "Hang Reward",
            "actual seconds = {0}, times = {1}".format(actual_seconds, times))
        standard_drop = resource.add(**prepare_drop)

        achievement = Achievement(self.char_id)
        achievement.trig(29, drop_exp)

        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 4
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.º 5
0
    def trig(self, *args):
        if not self.is_valid():
            return

        ac_record = ActivityConditionRecord(self.char_id, self.CONDITION_ID, self.activity_time)
        send_times = ac_record.send_times()

        if send_times >= 10:
            return

        condition = Q(char_id=self.char_id) & Q(purchase_at__gte=self.activity_time.nearest_open_date.timestamp) & Q(purchase_at__lte=self.activity_time.nearest_close_date.timestamp)
        logs = MongoPurchaseLog.objects.filter(condition)

        sycee_list = [log.sycee for log in logs if log.sycee >= self.CONDITION_VALUE]

        if len(sycee_list) > send_times:
            for i in range(len(sycee_list) - send_times):
                attachment = get_drop([self.activity_data.package])
                mail = Mail(self.char_id)
                mail.add(
                    self.activity_data.mail_title,
                    self.activity_data.mail_content,
                    attachment=json.dumps(attachment)
                )

                ac_record.add_send(1)
Exemplo n.º 6
0
    def trig(self):
        if not self.is_valid():
            return

        now = arrow.utcnow().to(settings.TIME_ZONE)
        if now.hour != 20:
            return

        date_str = now.format('YYYY-MM-DD')
        key = 'activity40006#{0}#{1}'.format(
            date_str, self.char_id
        )

        try:
            MongoKeyRecord.objects.get(id=key)
        except DoesNotExist:
            kr = MongoKeyRecord(id=key)
            kr.value = 1
            kr.save()

            m = Mail(self.char_id)
            m.add(
                self.activity_data.mail_title,
                self.activity_data.mail_content,
                attachment=json.dumps(get_drop([self.activity_data.package]))
            )
Exemplo n.º 7
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.º 8
0
    def get_reward(self, vip):
        if vip > self.mc.vip:
            raise SanguoException(
                errormsg.VIP_LEVEL_NOT_ENOUGH,
                self.char_id,
                "VIP GET REWARD",
                "vip not enough. {0} < {1}".format(self.mc.vip, vip)
            )

        vips = self.can_reward_vips()
        if vip not in vips:
            raise SanguoException(
                errormsg.VIP_HAS_GOT_REWARD,
                self.char_id,
                "VIP GET REWARD",
                "vip {0} has got reward".format(vip)
            )

        # send reward
        prepare_drop = get_drop([VIP_REWARD[vip].package])
        resource = Resource(self.char_id, "VIP GET REWARD", "vip {0}".format(vip))
        standard_drop = resource.add(**prepare_drop)

        self.mc.vip_has_reward.append(vip)
        self.mc.save()
        self.send_notify()

        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 9
0
    def save_drop(self, stage_id, first=False, star=False):
        this_stage = STAGES[stage_id]

        drop_ids = []
        if this_stage.normal_drop:
            drop_ids.extend([int(i) for i in this_stage.normal_drop.split(',')])
        if first and this_stage.first_drop:
            drop_ids.extend([int(i) for i in this_stage.first_drop.split(',')])
        if star and this_stage.star_drop:
            drop_ids.extend([int(i) for i in this_stage.star_drop.split(',')])

        perpare_drop = get_drop(drop_ids)
        perpare_drop['gold'] += this_stage.normal_exp
        perpare_drop['exp'] += this_stage.normal_gold

        if first:
            perpare_drop['gold'] += this_stage.first_gold
            perpare_drop['exp'] += this_stage.first_exp
        if star:
            perpare_drop['gold'] += this_stage.star_gold
            perpare_drop['exp'] += this_stage.star_exp

        perpare_drop = drop_after_stage_type(stage_id, perpare_drop)

        resource = Resource(self.char_id, "Stage Drop", "stage {0}".format(stage_id))
        standard_drop = resource.add(**perpare_drop)

        return standard_drop
Exemplo n.º 10
0
    def get_reward(self, char_id, condition_id):
        key = self.make_key(condition_id)
        try:
            doc = MongoActivityEnabledCondition.objects.get(id=key)
        except DoesNotExist:
            raise SanguoException(
                errormsg.ACTIVITY_CAN_NOT_GET_REWARD,
                char_id,
                "Activity Get Reward",
                "condition {0} can not get".format(condition_id)
            )

        if doc.value == 1:
            raise SanguoException(
                errormsg.ACTIVITY_ALREADY_GOT_REWARD,
                char_id,
                "Activity Get Reward",
                "condition {0} already got".format(condition_id)
            )

        doc.value = 1
        doc.save()

        standard_drop = get_drop([ACTIVITY_STATIC_CONDITIONS[condition_id].package])
        resource = Resource(char_id, "Activity Get Reward", "get condition id {0}".format(condition_id))
        standard_drop = resource.add(**standard_drop)

        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 11
0
    def send_first_reward(self):
        standard_drop = get_drop(PURCHASE_FIRST_REWARD_PACKAGE_IDS)

        mail = Mail(self.char_id)
        mail.add(MAIL_PURCHASE_FIRST_TITLE,
                 MAIL_PURCHASE_FIRST_CONTENT,
                 attachment=json.dumps(standard_drop))
Exemplo n.º 12
0
    def save_drop(self, _id=None):
        if _id:
            this_stage = STAGE_ELITE[_id]
        else:
            this_stage = self.this_stage

        exp = this_stage.normal_exp
        gold = this_stage.normal_gold

        drop_ids = [int(i) for i in this_stage.normal_drop.split(',') if i.isdigit()]

        prepare_drop = get_drop(drop_ids)
        prepare_drop['gold'] += gold
        prepare_drop['exp'] += exp

        if self.is_circle_reward:
            drop_hero_ids = this_stage.drop_hero_ids
            if drop_hero_ids:
                _drop_id = random.choice([int(i) for i in drop_hero_ids.split(',')])
                prepare_drop['heros'].append((_drop_id, 1))

        additional_drop = ActivityEntry(self.char_id, 11001).get_additional_drop()
        drop = merge_drop([prepare_drop, additional_drop])

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

        return standard_drop
Exemplo n.º 13
0
 def send_mail(self):
     attachment = get_drop([self.activity_data.package])
     mail = Mail(self.char_id)
     mail.add(
         self.activity_data.mail_title,
         self.activity_data.mail_content,
         attachment=json.dumps(attachment)
     )
Exemplo n.º 14
0
    def send_first_reward(self):
        standard_drop = get_drop(PURCHASE_FIRST_REWARD_PACKAGE_IDS)

        mail = Mail(self.char_id)
        mail.add(
            MAIL_PURCHASE_FIRST_TITLE,
            MAIL_PURCHASE_FIRST_CONTENT,
            attachment=json.dumps(standard_drop)
        )
Exemplo n.º 15
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.º 16
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.º 17
0
def _get_reward_by_rank(score, rank):
    data = None

    for _rank, _reward in ARENA_WEEK_REWARD_TUPLE:
        if rank >= _rank and _reward.packages:
            drop_ids = [int(i) for i in _reward.packages.split(',')]
            data = get_drop(drop_ids)
            break

    if data:
        return json.dumps(data)
    return None
Exemplo n.º 18
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.º 19
0
    def stuff_use(self, _id, amount):
        from core.attachment import get_drop, standard_drop_to_attachment_protomsg, is_empty_drop
        from core.resource import Resource
        try:
            s = STUFFS[_id]
        except KeyError:
            raise SanguoException(
                errormsg.STUFF_NOT_EXIST,
                self.char_id,
                "Stuff Use",
                "stuff {0} not exist".format(_id)
            )

        # XXX
        if s.tp != 3:
            raise SanguoException(
                errormsg.STUFF_CAN_NOT_USE,
                self.char_id,
                "Stuff Use",
                "stuff {0} tp is {1}. Can not use".format(_id, s.tp)
            )

        # XXX 忽略amount,只能一个一个用
        self.stuff_remove(_id, amount)

        packages = s.packages
        if not packages:
            return None

        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)

        resource = Resource(self.char_id, "Stuff Use", "use {0}".format(_id))
        standard_drop = resource.add(**prepare_drop)
        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 20
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.º 21
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.º 22
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.º 23
0
    def trig(self, *args):
        if not self.is_valid():
            return

        ac_record = ActivityConditionRecord(self.char_id, self.CONDITION_ID, self.activity_time)
        send_times = ac_record.send_times()

        if send_times > 0:
            return

        attachment = get_drop([self.activity_data.package])
        mail = Mail(self.char_id)
        mail.add(
            self.activity_data.mail_title,
            self.activity_data.mail_content,
            attachment=json.dumps(attachment)
        )

        ac_record.add_send(1)
Exemplo n.º 24
0
    def save_drop(self, _id=None):
        if _id:
            this_stage = STAGE_ELITE[_id]
        else:
            this_stage = self.this_stage

        exp = this_stage.normal_exp
        gold = this_stage.normal_gold

        drop_ids = [int(i) for i in this_stage.normal_drop.split(',') if i.isdigit()]

        prepare_drop = get_drop(drop_ids)
        prepare_drop['gold'] += gold
        prepare_drop['exp'] += exp

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

        return standard_drop
Exemplo n.º 25
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.º 26
0
    def get_reward(self, char_id, condition_id):
        key = self.reward_key(condition_id)
        if not key:
            raise SanguoException(
                errormsg.ACTIVITY_CAN_NOT_GET_REWARD,
                self.char_id,
                "Activity Get Reward",
                "condition {0} can not get".format(condition_id)
            )

        standard_drop = get_drop([ACTIVITY_STATIC_CONDITIONS[condition_id].package])
        resource = Resource(self.char_id, "Activity Get Reward", "get condition id {0}".format(condition_id))
        standard_drop = resource.add(**standard_drop)

        MongoKeyRecord._get_collection().update(
            {'_id': key},
            {'$set': {'value': 1}}
        )

        return standard_drop_to_attachment_protomsg(standard_drop)
Exemplo n.º 27
0
    def save_drop(self, _id=None):
        if _id:
            this_stage = STAGE_ELITE[_id]
        else:
            this_stage = self.this_stage

        exp = this_stage.normal_exp
        gold = this_stage.normal_gold

        drop_ids = [int(i) for i in this_stage.normal_drop.split(',')]

        prepare_drop = get_drop(drop_ids)
        prepare_drop['gold'] += gold
        prepare_drop['exp'] += exp

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

        return standard_drop
Exemplo n.º 28
0
    def trig(self, *args):
        ac_record = ActivityConditionRecord(self.char_id, self.CONDITION_ID, self.activity_time)
        send_times = ac_record.send_times()

        if send_times:
            return

        value = self.get_current_value(self.char_id)
        if value < self.CONDITION_VALUE:
            return

        attachment = get_drop([self.activity_data.package])
        mail = Mail(self.char_id)
        mail.add(
            self.activity_data.mail_title,
            self.activity_data.mail_content,
            attachment=json.dumps(attachment)
        )

        ac_record.add_send(1)
Exemplo n.º 29
0
    def trig(self):
        if not self.is_valid():
            return

        now = arrow.utcnow().to(settings.TIME_ZONE)
        now_begin = arrow.Arrow(now.year, now.month, now.day).replace(tzinfo=now.tzinfo)

        condition = (
            Q(char_id=self.char_id) & Q(purchase_at__gte=now_begin.timestamp) & Q(purchase_at__lte=now.timestamp)
        )
        logs = MongoPurchaseLog.objects.filter(condition)
        if logs.count() == 0 or logs.count() > 1:
            # 没有充值,或者充值次数大于1,都返回
            # 只有当天第一次充值的时候,才给额外的东西
            return

        attachment = get_drop([self.activity_data.package])

        mail = Mail(self.char_id)
        mail.add(self.activity_data.mail_title, self.activity_data.mail_content, attachment=json.dumps(attachment))
Exemplo n.º 30
0
    def trig(self, *args):
        if not self.is_valid():
            return

        now = arrow.utcnow().to(settings.TIME_ZONE)
        now_begin = arrow.Arrow(now.year, now.month, now.day).replace(tzinfo=now.tzinfo)

        condition = Q(char_id=self.char_id) & Q(purchase_at__gte=now_begin.timestamp) & Q(purchase_at__lte=now.timestamp)
        logs = MongoPurchaseLog.objects.filter(condition)
        if logs.count() == 0 or logs.count() > 1:
            # 没有充值,或者充值次数大于1,都返回
            # 只有当天第一次充值的时候,才给额外的东西
            return

        attachment = get_drop([self.activity_data.package])

        mail = Mail(self.char_id)
        mail.add(
            self.activity_data.mail_title,
            self.activity_data.mail_content,
            attachment=json.dumps(attachment)
        )
Exemplo n.º 31
0
 def get_mail_attachment(self, p):
     drop = get_drop([ACTIVITY_STATIC_CONDITIONS[p].package])
     return json.dumps(drop)
Exemplo n.º 32
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.º 33
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.º 34
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.º 35
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.º 36
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])
Exemplo n.º 37
0
    def get_reward_done(self, char_id, condition_id):
        standard_drop = get_drop([ACTIVITY_STATIC_CONDITIONS[condition_id].package])
        resource = Resource(char_id, "Activity Get Reward", "get condition id {0}".format(condition_id))
        standard_drop = resource.add(**standard_drop)

        return standard_drop_to_attachment_protomsg(standard_drop)