예제 #1
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
예제 #2
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)
예제 #3
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
예제 #4
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
예제 #5
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)