コード例 #1
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)
コード例 #2
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)
コード例 #3
0
ファイル: purchase.py プロジェクト: yaosj/sanguo-server
    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)
コード例 #4
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
コード例 #5
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()
コード例 #6
0
ファイル: mail.py プロジェクト: hx002/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_notify()
        return attachment
コード例 #7
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)
コード例 #8
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()
コード例 #9
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)
コード例 #10
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)])
コード例 #11
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)])
コード例 #12
0
ファイル: purchase.py プロジェクト: hx002/sanguo-server
    def send_reward_sycee(self, goods_id, is_first):
        # 元宝
        p = PURCHASE[goods_id]
        addition = p.first_addition_sycee if is_first else p.addition_sycee

        purchase_got = p.sycee
        purchase_actual_got = purchase_got + addition

        resource = Resource(self.char_id, "Purchase")
        resource.add(purchase_got=purchase_got, purchase_actual_got=purchase_actual_got)
コード例 #13
0
ファイル: purchase.py プロジェクト: yaosj/sanguo-server
    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)
コード例 #14
0
ファイル: heropanel.py プロジェクト: yaosj/sanguo-server
def _open_hero(char_id, hero_oid, **kwargs):
    drop1 = ActivityEntry(char_id, 9001).get_additional_drop()
    drop2 = ActivityEntry(char_id, 13001).get_additional_drop()

    drop = merge_drop([drop1, drop2])
    if is_empty_drop(drop):
        return

    resource = Resource(char_id, "HeroPanel open")
    resource.add(**drop)
コード例 #15
0
ファイル: horse.py プロジェクト: yueyoum/sanguo-server
    def sell(self, _id):
        self.check_sell(_id)

        h = self.mongo_horse.horses[str(_id)]
        got_gold = HORSE[h.oid].sell_gold

        resource = Resource(self.char_id, "Horse Sell", "sell horse {0}".format(_id))
        resource.add(gold=got_gold)

        self.remove(_id)
コード例 #16
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)
コード例 #17
0
ファイル: heropanel.py プロジェクト: yueyoum/sanguo-server
def _open_hero(char_id, hero_oid, sycee, **kwargs):
    drop1 = ActivityEntry(char_id, 9001).get_additional_drop()
    drop2 = ActivityEntry(char_id, 13001).get_additional_drop()

    drop = merge_drop([drop1, drop2])
    if not is_empty_drop(drop):
        resource = Resource(char_id, "HeroPanel open")
        resource.add(**drop)

    if sycee:
        TimesLogGetHeroBySycee(char_id).inc()
コード例 #18
0
ファイル: heropanel.py プロジェクト: zhifuliu/sanguo-server
def _open_hero(char_id, hero_oid, sycee, **kwargs):
    drop1 = ActivityEntry(char_id, 9001).get_additional_drop()
    drop2 = ActivityEntry(char_id, 13001).get_additional_drop()

    drop = merge_drop([drop1, drop2])
    if not is_empty_drop(drop):
        resource = Resource(char_id, "HeroPanel open")
        resource.add(**drop)

    if sycee:
        TimesLogGetHeroBySycee(char_id).inc()
コード例 #19
0
ファイル: store.py プロジェクト: yaosj/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)])
コード例 #20
0
ファイル: store.py プロジェクト: yaosj/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)])
コード例 #21
0
    def sell(self, _id):
        self.check_sell(_id)

        h = self.mongo_horse.horses[str(_id)]
        got_gold = HORSE[h.oid].sell_gold

        resource = Resource(self.char_id, "Horse Sell",
                            "sell horse {0}".format(_id))
        resource.add(gold=got_gold)

        self.remove(_id)
コード例 #22
0
ファイル: purchase.py プロジェクト: hx002/sanguo-server
    def send_reward_sycee(self, goods_id, is_first):
        # 元宝
        p = PURCHASE[goods_id]
        addition = p.first_addition_sycee if is_first else p.addition_sycee

        purchase_got = p.sycee
        purchase_actual_got = purchase_got + addition

        resource = Resource(self.char_id, "Purchase")
        resource.add(purchase_got=purchase_got,
                     purchase_actual_got=purchase_actual_got)
コード例 #23
0
ファイル: plunder.py プロジェクト: yaosj/sanguo-server
    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
コード例 #24
0
ファイル: item.py プロジェクト: zhifuliu/sanguo-server
    def gem_sell(self, _id, amount):
        try:
            this_gem = GEMS[_id]
        except KeyError:
            raise SanguoException(errormsg.GEM_NOT_EXIST, self.char_id,
                                  "Gem Sell", "Gem {0} not exist".format(_id))

        gold = this_gem.sell_gold * amount

        resource = Resource(self.char_id, "Gem Sell",
                            "sell: {0}, amount {1}".format(_id, amount))
        resource.check_and_remove(gems=[(_id, amount)])
        resource.add(gold=gold)
コード例 #25
0
ファイル: views.py プロジェクト: wyrover/sanguo-server
def purchase_done(request):
    try:
        char_id = int(request.POST['char_id'])
        sycee = int(request.POST['sycee'])
        actual_sycee = int(request.POST['actual_sycee'])
    except (KeyError, ValueError):
        return {'ret': 1}

    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)
    return {'ret': 0}
コード例 #26
0
ファイル: item.py プロジェクト: zhifuliu/sanguo-server
    def stuff_sell(self, _id, amount):
        try:
            this_stuff = STUFFS[_id]
        except KeyError:
            raise SanguoException(errormsg.STUFF_NOT_EXIST, self.char_id,
                                  "Stuff Sell",
                                  "Stuff {0} not exist".format(_id))

        gold = this_stuff.sell_gold * 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)
コード例 #27
0
ファイル: daily.py プロジェクト: yueyoum/sanguo-server
    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 = self.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
コード例 #28
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
コード例 #29
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)
コード例 #30
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
コード例 #31
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
コード例 #32
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)
コード例 #33
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)
コード例 #34
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)
コード例 #35
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
コード例 #36
0
ファイル: vip.py プロジェクト: yaosj/sanguo-server
    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)
コード例 #37
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)
コード例 #38
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)
コード例 #39
0
ファイル: levy.py プロジェクト: yaosj/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
コード例 #40
0
ファイル: item.py プロジェクト: yueyoum/sanguo-server
    def stuff_sell(self, _id, amount):
        try:
            this_stuff = STUFFS[_id]
        except KeyError:
            raise SanguoException(
                errormsg.STUFF_NOT_EXIST,
                self.char_id,
                "Stuff Sell",
                "Stuff {0} not exist".format(_id)
            )

        gold = this_stuff.sell_gold * 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)
コード例 #41
0
ファイル: item.py プロジェクト: yueyoum/sanguo-server
    def gem_sell(self, _id, amount):
        try:
            this_gem = GEMS[_id]
        except KeyError:
            raise SanguoException(
                errormsg.GEM_NOT_EXIST,
                self.char_id,
                "Gem Sell",
                "Gem {0} not exist".format(_id)
            )

        gold = this_gem.sell_gold * amount

        resource = Resource(self.char_id, "Gem Sell", "sell: {0}, amount {1}".format(_id, amount))
        resource.check_and_remove(gems=[(_id, amount)])
        resource.add(gold=gold)
コード例 #42
0
ファイル: prison.py プロジェクト: wyrover/sanguo-server
    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)
コード例 #43
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')
コード例 #44
0
ファイル: attachment.py プロジェクト: yaosj/sanguo-server
    def get_attachment(self, prize_id, param=0):
        # prizie_id == 1 挂机不在这里
        if prize_id == 4:
            # 成就
            from core.achievement import Achievement

            ach = Achievement(self.char_id)
            att_msg = ach.get_reward(param)
            if ach.has_prizes():
                prize_id = None

        elif prize_id == 5:
            # 任务
            from core.task import Task

            task = Task(self.char_id)
            att_msg = task.get_reward(param)
            if task.has_prizes():
                prize_id = None

        elif prize_id == 6:
            # 官职每日登录
            # from core.daily import OfficialDailyReward
            # od = OfficialDailyReward(self.char_id)
            # att_msg = od.get_reward()
            att_msg = None
        elif prize_id == 7:
            # 团队本
            att_msg = None

        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:
            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
コード例 #45
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)
コード例 #46
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)
コード例 #47
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
コード例 #48
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
コード例 #49
0
ファイル: item.py プロジェクト: yueyoum/sanguo-server
    def equip_sell(self, ids):
        if not isinstance(ids, (set, list, tuple)):
            ids = [ids]

        self.equip_check_sell(ids)

        off_gems = {}

        gold = 0
        for _id in ids:
            e = Equipment(self.char_id, _id, self.item)
            gold += e.sell_gold()
            for gid in e.get_embedded_gems():
                if gid:
                    off_gems[gid] = off_gems.get(gid, 0) + 1

        resource = Resource(self.char_id, "Equipment Sell", "equipments {0}".format(ids))
        resource.check_and_remove(equipments=list(ids))
        resource.add(gold=gold)

        self.gem_add(off_gems.items())
コード例 #50
0
ファイル: task.py プロジェクト: hx002/sanguo-server
    def get_reward(self, _id):
        try:
            this_task = TASKS[_id]
        except KeyError:
            raise SanguoException(
                errormsg.TASK_NOT_EXIST,
                self.char_id,
                "Task Get Reward",
                "Task {0} not exist".format(_id)
            )

        if _id not in self.task.finished:
            raise SanguoException(
                errormsg.TASK_NOT_FINISH,
                self.char_id,
                "Task Get Reward",
                "Task {0} not finish".format(_id)
            )

        if _id in self.task.complete:
            raise SanguoException(
                errormsg.TASK_ALREADY_GOT_REWARD,
                self.char_id,
                "Task Get Reward",
                "Task {0} already got reward".format(_id)
            )

        sycee = this_task.sycee if this_task.sycee else 0
        gold = this_task.gold if this_task.gold else 0

        resource = Resource(self.char_id, "Task Reward", "task {0}".format(_id))
        standard_drop = resource.add(gold=gold, sycee=sycee)

        if this_task.next_task:
            next_task = TASKS[this_task.next_task]
            if self.task.tasks[str(this_task.tp)] >= next_task.times:
                self.task.finished.append(this_task.next_task)

            index = self.task.doing.index(_id)
            self.task.doing.pop(index)
            self.task.doing.insert(index, this_task.next_task)

        self.task.finished.remove(_id)
        self.task.complete.append(_id)
        self.task.save()
        self.send_notify()

        if self.all_complete():
            achievement = Achievement(self.char_id)
            achievement.trig(30, 1)

        return standard_drop_to_attachment_protomsg(standard_drop)
コード例 #51
0
ファイル: prison.py プロジェクト: yueyoum/sanguo-server
    def kill(self, _id):
        p = self._abandon(_id, action="Prisoner Kill")

        soul_amount = random.randint(3, 10)
        souls = [(p.oid, soul_amount)]

        resource = Resource(self.char_id, "Prisoner Kill")
        standard_drop = resource.add(souls=souls)

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

        return standard_drop_to_attachment_protomsg(standard_drop)
コード例 #52
0
ファイル: levy.py プロジェクト: hx002/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)

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

        self.send_notify()
        return got_gold