コード例 #1
0
ファイル: daily.py プロジェクト: zhifuliu/sanguo-server
    def get_reward(self):
        counter = Counter(self.char_id, 'official_reward')
        if counter.remained_value <= 0:
            raise SanguoException(
                errormsg.OFFICAL_ALREADY_GET_REWARD,
                self.char_id,
                "OfficialDailyReward Get Reward",
                "already got"
            )


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

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

        gold = OFFICIAL[official_level].gold

        resource = Resource(self.char_id, "Daily Official", 'official reward')
        standard_drop = resource.add(gold=gold)
        return standard_drop_to_attachment_protomsg(standard_drop)
コード例 #2
0
ファイル: levy.py プロジェクト: zhifuliu/sanguo-server
    def levy(self):
        char = Char(self.char_id).mc

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

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

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

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

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

        self.send_notify()
        return standard_drop
コード例 #3
0
ファイル: affairs.py プロジェクト: zhifuliu/sanguo-server
    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"
        #     )

        drops = self.get_drop()
        ac = ActivityEntry(self.char_id, 30004)
        if ac and ac.is_valid():
            drops['gold'] *= 2

        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, self.get_hang_obj().passed_time / 3600)
        achievement.trig(29, drops['exp'])

        return standard_drop_to_attachment_protomsg(standard_drop)
コード例 #4
0
ファイル: levy.py プロジェクト: wyrover/sanguo-server
    def levy(self):
        char = Char(self.char_id).mc

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

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

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

            got_gold *= v

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

        self.send_notify()
コード例 #5
0
    def equip_sell(self, ids):
        if not isinstance(ids, (set, list, tuple)):
            ids = [ids]

        f = Formation(self.char_id)
        ids = set(ids)
        for _id in ids:
            if not self.has_equip(_id):
                raise SanguoException(
                    errormsg.EQUIPMENT_NOT_EXIST,
                    self.char_id,
                    "Equipment Sell",
                    "Equipment {0} NOT exist".format(_id)
                )

            if f.find_socket_by_equip(_id):
                raise SanguoException(
                    errormsg.EQUIPMENT_CANNOT_SELL_FORMATION,
                    self.char_id,
                    "Equipment Sell",
                    "Equipment {0} in Formation, Can not sell".format(_id)
                )

        gold = 0
        for _id in ids:
            e = Equipment(self.char_id, _id, self.item)
            gold += e.sell_gold()

        resource = Resource(self.char_id, "Equipment Sell", "equipments {0}".format(ids))
        resource.check_and_remove(equipments=list(ids))
        resource.add(gold=gold)
コード例 #6
0
    def step_up(self):
        to = self.equip.upgrade_to
        if not to:
            raise SanguoException(
                errormsg.EQUIPMENT_REACH_MAX_STEP,
                self.char_id,
                "Equipment Step Up",
                "Equipment {0} Can not step up".format(self.equip_id)
            )

        step_up_need_gold = self.step_up_need_gold()

        stuff_needs = []
        for x in self.equip.stuff_needs.split(','):
            _id, _amount = x.split(':')
            stuff_needs.append((int(_id), int(_amount)))

        resouce = Resource(self.char_id, "Equipment Step Up", "equipment {0}".format(self.equip_id))
        with resouce.check(gold=-step_up_need_gold, stuffs=stuff_needs):
            self.oid = to
            self.equip = EQUIPMENTS[self.oid]

            self.mongo_item.equipments[str(self.equip_id)].oid = to
            add_gem_slots = self.equip.slots - len(self.mongo_item.equipments[str(self.equip_id)].gems)
            for i in range(add_gem_slots):
                self.mongo_item.equipments[str(self.equip_id)].gems.append(0)

            self.mongo_item.save()

        achievement = Achievement(self.char_id)
        achievement.trig(22, 1)
        if not self.equip.upgrade_to:
            achievement.trig(23, 1)

        return stuff_needs
コード例 #7
0
    def battle(self):
        need_sycee = 0

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

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

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

        counter.incr()

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

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

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

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

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

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

        self.send_notify(score=new_score)

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

        return msg
コード例 #8
0
    def get_plunder_target(self, city_id):
        """
        @:rtype: PlunderRival
        """

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

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

        return target
コード例 #9
0
    def stuff_sell(self, _id, amount):
        # TODO get gold
        gold = 10 * amount

        resource = Resource(self.char_id, "Stuff Sell", "sell {0}, amount: {1}".format(_id, amount))
        resource.check_and_remove(stuffs=[(_id, amount)])
        resource.add(gold=gold)
コード例 #10
0
ファイル: mail.py プロジェクト: wyrover/sanguo-server
    def get_attachment(self, mail_id):
        if str(mail_id) not in self.mail.mails:
            raise SanguoException(
                errormsg.MAIL_NOT_EXIST,
                self.char_id,
                "Mail Get Attachment",
                "mail {0} not exist".format(mail_id)
            )

        if not self.mail.mails[str(mail_id)].attachment:
            raise SanguoException(
                errormsg.MAIL_HAS_NO_ATTACHMENT,
                self.char_id,
                "Mail Get Attachment",
                "mail {0} has no attachment".format(mail_id)
            )

        resource = Resource(self.char_id, "Mail Attachment")
        attachment = json.loads(self.mail.mails[str(mail_id)].attachment)
        resource.add(**attachment)

        self.mail.mails[str(mail_id)].attachment = ''
        self.mail.mails[str(mail_id)].has_read = True
        self.mail.save()
        self.send_mail_notify()
コード例 #11
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
コード例 #12
0
    def create(self,name):
        if len(name) > UNION_NAME_MAX_LENGTH:
            raise SanguoException(
                    errormsg.UNION_NAME_TOO_LONG,
                    self.char_id,
                    "Union Create",
                    "name too long: {0}".format(name.encode('utf-8'))
                    )


        if MongoUnion.objects.filter(name=name).count() > 0:
            raise SanguoException(
                    errormsg.UNION_NAME_ALREADY_EXIST,
                    self.char_id,
                    "Union Create",
                    "name already exist: {0}".format(name.encode('utf-8'))
                    )


        resource = Resource(self.char_id, "Union Create")

        with resource.check(sycee=-UNION_CREATE_NEEDS_SYCEE):
            new_id = id_generator('union')[0]
            mu = MongoUnion(id=new_id)
            mu.owner = self.char_id
            mu.name = name
            mu.bulletin = UNION_DEFAULT_DES
            mu.level = 1
            mu.contribute_points = 0
            mu.save()
            UnionMember(self.char_id).join_union(new_id)

        Union(self.char_id, new_id).send_notify()
        UnionBattle(self.char_id).send_notify()
コード例 #13
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
コード例 #14
0
    def reset_one(self, _id):
        str_id = str(_id)
        if str_id not in self.stage.elites:
            raise SanguoException(
                errormsg.STAGE_ELITE_NOT_OPEN,
                self.char_id,
                "Elite Reset One",
                "reset a not opened stage {0}".format(_id)
            )

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

        cost = self.get_reset_cost(_id)

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

        self.send_update_notify(_id)
コード例 #15
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)
コード例 #16
0
    def checkin(self):
        if self.c.has_checked:
            raise SanguoException(
                errormsg.CHECKIN_ALREADY_CHECKIN,
                self.char_id,
                "CheckIn checkin",
                "already checkin",
            )

        self.c.has_checked = True
        day = self.c.day

        self.c.save()

        resource = Resource(self.char_id, "Daily Checkin",
                            'checkin reward. day {0}'.format(day))
        resource_add = CHECKIN_DATA[str(day)]['package']
        resource_add = get_drop_from_raw_package(resource_add)

        standard_drop = resource.add(**resource_add)

        msg = CheckInResponse()
        msg.ret = 0
        msg.reward.MergeFrom(
            standard_drop_to_attachment_protomsg(standard_drop))

        self.send_update_notify(day)
        return msg
コード例 #17
0
ファイル: stage.py プロジェクト: wyrover/sanguo-server
    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)
コード例 #18
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)
コード例 #19
0
ファイル: purchase.py プロジェクト: hx002/sanguo-server
def verify_buy(char_id, receipt):
    data = {
        'char_id': char_id,
        'receipt': receipt,
    }

    # FIXME error handle
    res = api_purchase_verify(data)
    if res['ret'] != 0:
        return VerifyResult(res['ret'])

    log_id = res['data']['log_id']
    char_id = res['data']['char_id']
    product_id = res['data']['product_id']
    name = res['data']['name']
    sycee = res['data']['sycee']
    actual_sycee = res['data']['actual_sycee']

    resource = Resource(
        char_id, "Purchase Done",
        "purchase got: sycee {0}, actual sycee {1}".format(
            sycee, actual_sycee))
    resource.add(purchase_got=sycee, purchase_actual_got=actual_sycee)

    api_purchase_done({'log_id': log_id})

    return VerifyResult(0,
                        product_id=product_id,
                        name=name,
                        add_sycee=actual_sycee)
コード例 #20
0
    def send_reward_with_custom_price(self, goods_id, price):
        # 这里 price 是新台币,而且不一定是这个goods_id所对应的价格
        # 所以这里按照比例给东西
        p = PURCHASE[goods_id]

        xintaibi = p.rmb * 5

        buy_div, buy_mod = divmod(price, xintaibi)
        for i in xrange(buy_div):
            self.send_reward(goods_id)

        if buy_mod:
            # 换算成对应的元宝
            sycee = buy_mod * 2

            # 任意金额也要双倍!!!
            buy_times = self.buy_times_of_this_goods(goods_id)
            if buy_times == 0:
                actual_sycee = sycee * 2
            else:
                actual_sycee = sycee

            resource = Resource(self.char_id, "Purchase With Custom Price")
            resource.add(purchase_got=sycee, purchase_actual_got=actual_sycee)

            self.mongo_record.times[str(goods_id)] = buy_times + 1
            self.mongo_record.save()
            self.send_notify()

            title = u'充值成功'
            content = u'获得了 {0} 元宝'.format(actual_sycee)
            mail = Mail(self.char_id)
            mail.add(title, content)
コード例 #21
0
    def plunder(self, _id):
        if str(_id) not in self.mongo_plunder.chars:
            raise SanguoException(
                errormsg.PLUNDER_NOT_IN_LIST, self.char_id, "Plunder Plunder",
                "Plunder, {0} not in plunder list".format(_id))

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

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

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

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

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

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

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

            drop_official_exp = PLUNDER_GET_OFFICIAL_EXP_WHEN_WIN
            drop_gold = PLUNDER_DEFENSE_FAILURE_GOLD

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

        self.mongo_plunder.got_reward = []
        self.mongo_plunder.save()
        self.send_notify()
        return msg
コード例 #22
0
ファイル: store.py プロジェクト: zhifuliu/sanguo-server
    def _buy_items(self, _id, item_id, amount):
        if item_id not in STUFFS:
            raise SanguoException(errormsg.INVALID_OPERATE, self.char_id,
                                  "UnionStore Buy",
                                  "stuff {0} not exist".format(item_id))

        resources = Resource(self.char_id, "UnionStore Buy")
        resources.add(stuffs=[(item_id, amount)])
コード例 #23
0
ファイル: store.py プロジェクト: zhifuliu/sanguo-server
    def _buy_horse(self, _id, item_id, amount):
        if item_id not in HORSE:
            raise SanguoException(errormsg.INVALID_OPERATE, self.char_id,
                                  "UnionStore Buy",
                                  "horse {0} not exist".format(item_id))

        resources = Resource(self.char_id, "UnionStore Buy")
        resources.add(horses=[(item_id, amount)])
コード例 #24
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')
コード例 #25
0
    def release(self, _id):
        p = self._abandon(_id, action="Prisoner Release")
        got_gold = p.gold
        got_treasure = random.choice(
            PRISONER_RELEASE_GOT_TREASURE[HEROS[p.oid].quality])

        resource = Resource(self.char_id, "Prisoner Release")
        standard_drop = resource.add(gold=got_gold, stuffs=[(got_treasure, 1)])
        return standard_drop_to_attachment_protomsg(standard_drop)
コード例 #26
0
ファイル: affairs.py プロジェクト: hx002/sanguo-server
    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)
コード例 #27
0
    def step_up(self):
        # 升阶
        if self.step >= HERO_MAX_STEP:
            raise SanguoException(
                errormsg.HERO_REACH_MAX_STEP, self.char_id, "Hero Step Up",
                "Hero {0} reach max step {1}".format(self.id, HERO_MAX_STEP))

        resource_needs = {}
        cost_gold = self.get_step_up_gold_needs()

        resource_needs['gold'] = -cost_gold
        soul_needs_amount = self.get_step_up_soul_needs()

        resource_needs['souls'] = [(self.oid, soul_needs_amount)]

        hs = HeroSoul(self.char_id)
        self_soul_amount = hs.soul_amount(self.oid)
        common_soul_needs = soul_needs_amount - self_soul_amount
        if common_soul_needs > 0:
            # need common soul
            resource_needs['stuffs'] = [(22, common_soul_needs)]

        resource = Resource(self.char_id, "Hero Step Up",
                            'step up {0}'.format(self.id))
        try:
            resource.check_and_remove(**resource_needs)
        except SanguoException as e:
            if e.error_id == errormsg.SOUL_NOT_ENOUGH or e.error_id == errormsg.STUFF_NOT_ENOUGH:
                raise SanguoException(errormsg.HERO_STEP_UP_ALL_NOT_ENOUGH,
                                      self.char_id, "Hero Step Up",
                                      "soul not enough")
            raise e

        # 扣完东西了,开始搞一次
        self.hero.progress += 1
        if self.hero.progress >= self.max_socket_amount:
            # 真正的升阶
            # 否则仅仅是记录当前状态
            self.hero.step += 1
            self.hero.progress = 0

            hero_step_up_signal.send(sender=None,
                                     char_id=self.char_id,
                                     hero_id=self.id,
                                     new_step=self.hero.step)

        self.step = self.hero.step
        self.hero.save()
        hero_changed_signal.send(sender=None, hero_id=self.id)

        TimesLogHeroStepUp(self.char_id).inc()
        if self.step >= 5:
            ae = ActivityEntry(self.char_id, 40004)
            if ae:
                ae.enable(self.step)
                ActivityStatic(
                    self.char_id).send_update_notify(activity_ids=[40004])
コード例 #28
0
ファイル: attachment.py プロジェクト: wyrover/sanguo-server
    def get_attachment(self, prize_id, param=0):
        if prize_id == 1:
            # 挂机
            from core.stage import Hang
            h = Hang(self.char_id)
            att_msg = h.save_drop()
        elif prize_id == 4:
            # 成就
            from core.achievement import Achievement
            ach = Achievement(self.char_id)
            att_msg = ach.get_reward(param)
        elif prize_id == 5:
            # 任务
            from core.task import Task
            task = Task(self.char_id)
            att_msg = task.get_reward(param)
        elif prize_id == 6:
            # 官职每日登录
            from core.daily import OfficalDailyReward
            od = OfficalDailyReward(self.char_id)
            att_msg = od.get_reward()
        elif prize_id == 7:
            # 团队本
            from core.stage import TeamBattle
            tb = TeamBattle(self.char_id)
            att_msg = tb.get_reward()
        else:
            try:
                attachment = self.attachment.attachments[str(prize_id)]
            except KeyError:
                raise SanguoException(
                    errormsg.ATTACHMENT_NOT_EXIST,
                    self.char_id,
                    "Attachment Get",
                    "{0} not exist".format(prize_id)
                )

            attachment = json.loads(attachment)
            resource = Resource(self.char_id, "Prize {0}".format(prize_id))
            standard_drop = resource.add(**attachment)

            self.attachment.attachments.pop(str(prize_id))
            self.attachment.save()

            att_msg = standard_drop_to_attachment_protomsg(standard_drop)

        # 删除此prize_id
        if prize_id in self.attachment.prize_ids:
            self.attachment.prize_ids.remove(prize_id)
        if str(prize_id) in self.attachment.attachments:
            self.attachment.attachments.pop(str(prize_id))

        self.attachment.save()
        self.send_notify()

        return att_msg
コード例 #29
0
    def battle(self):
        counter = Counter(self.char_id, 'arena')
        try:
            # 免费次数
            counter.incr()
        except CounterOverFlow:
            counter = Counter(self.char_id, 'arena_buy')

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

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

        rival_id = self.choose_rival()

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

        achievement = Achievement(self.char_id)

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

        self.mongo_arena.save()

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

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

        self.send_notify()
        return msg
コード例 #30
0
    def add_to_resource(self, sycee, addition, **kwargs):
        purchase_got = sycee
        purchase_actual_got = purchase_got + addition

        data = kwargs
        data['purchase_got'] = purchase_got
        data['purchase_actual_got'] = purchase_actual_got

        resource = Resource(self.char_id, "Purchase")
        resource.add(**data)