Example #1
0
    def get_hang_reward(self, auto_start=True):
        """立即保存掉落,并且返回attachment消息"""
        # if not self.mongo_affairs.hang_city_id:
        #     raise SanguoException(
        #         errormsg.HANG_NOT_EXIST,
        #         self.char_id,
        #         "Get Hang Reward",
        #         "hang not exist"
        #     )

        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)
Example #2
0
        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
Example #3
0
def _vip_change(char_id, old_vip, new_vip, **kwargs):
    Prison(char_id).vip_changed(new_vip)
    m = Mail(char_id)
    m.add(name=MAIL_VIP_CHANGED_TITLE, content=MAIL_VIP_CHANGED_CONTENT.format(new_vip))

    # 增加掠夺次数
    plunder_times_change_value = VIP_FUNCTION[new_vip].plunder - VIP_FUNCTION[old_vip].plunder
    if plunder_times_change_value:
        plunder = Plunder(char_id)
        plunder.change_current_plunder_times(plunder_times_change_value, allow_overflow=True)

    vip_activies = []
    if has_activity(22001):
        vip_activies.append(22001)
    if has_activity(40007):
        vip_activies.append(40007)
    if has_activity(40008):
        vip_activies.append(40008)
    if has_activity(50006):
        vip_activies.append(50006)

    if vip_activies:
        ActivityStatic(char_id).send_update_notify(activity_ids=vip_activies)

    ae = ActivityEntry(char_id, 50006)
    if ae and ae.is_valid():
        ae.enable(new_vip)
        ActivityStatic(char_id).send_update_notify(activity_ids=[50006])
Example #4
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])
Example #5
0
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()
Example #6
0
    def max_plunder_times(self):
        char = Char(self.char_id)
        times = VIP_FUNCTION[char.mc.vip].plunder

        ae = ActivityEntry(self.char_id, 40007)
        if not ae or not ae.is_ok():
            return times

        if times > 10:
            return times

        return 10
Example #7
0
    def max_plunder_times(self):
        char = Char(self.char_id)
        times = VIP_FUNCTION[char.mc.vip].plunder

        ae = ActivityEntry(self.char_id, 40007)
        if not ae or not ae.is_ok():
            return times

        if times > 10:
            return times

        return 10
Example #8
0
    def send_prisoners_notify(self):
        ae = ActivityEntry(self.char_id, 40008)
        if ae and ae.is_ok():
            _add_prob = 80
        else:
            _add_prob = 0

        msg = protomsg.PrisonerListNotify()
        for k, v in self.p.prisoners.iteritems():
            p = msg.prisoner.add()
            self._fill_up_prisoner_msg(p, int(k), v.oid, v.prob + _add_prob, v.active)

        publish_to_char(self.char_id, pack_msg(msg))
Example #9
0
    def get_drop(self, passed_time=None, multi=1):
        ae = ActivityEntry(self.char_id, 60001)

        ho = self.get_hang_obj()
        battle_data = BATTLES[self.mongo_affairs.hang_city_id]

        if not passed_time:
            passed_time = ho.passed_time

        percent = passed_time / float(ho.max_time) * 100
        for _pre, _add in HANG_REWARD_ADDITIONAL:
            if percent >= _pre:
                break
        else:
            _add = 1

        char = Char(self.char_id)
        vip_level = char.mc.vip
        vip_add = VIP_FUNCTION[vip_level].hang_addition

        passed_time = int(passed_time * _add * (1 + vip_add / 100.0))

        reward_gold = passed_time / 15 * battle_data.normal_gold
        reward_gold = self.get_real_gold(reward_gold, self.mongo_affairs.logs)

        if ae and ae.is_valid():
            reward_gold *= 2

        reward_exp = passed_time / 15 * battle_data.normal_exp

        if battle_data.normal_drop:
            # 模拟损失物品
            drop_time = passed_time
            for log in self.mongo_affairs.logs:
                if log.tp == 1:
                    drop_time -= PLUNDER_GET_DROPS_MINUTES * 60

            drop_time_adjusted = max(int(passed_time * 0.25), drop_time)

            multi = int(drop_time_adjusted/15*multi)
            if ae and ae.is_valid():
                multi *= 2
            drops = get_drop([int(i) for i in battle_data.normal_drop.split(',')], multi=multi)
        else:
            drops = make_standard_drop_from_template()

        drops['exp'] = reward_exp
        drops['gold'] = reward_gold
        return drops
Example #10
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
Example #11
0
        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
Example #12
0
def _new_purchase(char_id, new_got, total_got, **kwargs):
    VIP(char_id).send_notify()

    plog = MongoPurchaseLog()
    plog.char_id = char_id
    plog.sycee = new_got
    plog.purchase_at = arrow.utcnow().timestamp
    plog.save()

    # 需要发送活动通知的, 就必须用 ActivityStatic trig
    acs = ActivityStatic(char_id)
    acs.trig(5001)
    acs.trig(14001)
    ActivityEntry(char_id, 16001).trig(new_got/2)
    ActivityEntry(char_id, 17001).trig()
    ActivityEntry(char_id, 17002).trig()

    acs.trig(18006)

    ActivityEntry(char_id, 999).trig()
    ActivityEntry(char_id, 1000).trig()

    acs.trig(19001)
    acs.trig(20001)

    if ActivityEntry(char_id, 30006).trig(new_got):
        acs.send_update_notify(activity_ids=[30006])

    ActivityEntry(char_id, 40000).trig()
Example #13
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)

        TimesLogEquipStepUp(self.char_id).inc()

        if self.equip.step == 4:
            ae = ActivityEntry(self.char_id, 50001)
            if ae:
                ae.enable(self.equip.step)
                ActivityStatic(
                    self.char_id).send_update_notify(activity_ids=[50001])

        return stuff_needs
Example #14
0
    def wuxing_update(self, wuxing_id, souls):
        # 五行升级
        str_id = str(wuxing_id)
        if str_id not in self.hero.wuxings:
            raise SanguoException(
                errormsg.WUXING_NOT_FOR_THIS_HERO,
                self.char_id,
                "Hero WuXing Update",
                "hero {0} has no wuxing {1}".format(self.id, wuxing_id)
            )

        hs = HeroSoul(self.char_id)
        add_exp = 0
        for soul_id, soul_amount in souls:
            if not hs.has_soul(soul_id, soul_amount):
                raise SanguoException(
                    errormsg.SOUL_NOT_ENOUGH,
                    self.char_id,
                    "Hero WuXing Update",
                    "soul not enough. {0}: {1}".format(soul_id, soul_amount)
                )

            add_exp += HEROS[soul_id].wuxing_exp * soul_amount

        wx = HeroWuXing(wuxing_id, self.hero.wuxings[str_id].level, self.hero.wuxings[str_id].exp)
        wx.update(add_exp)

        hs.remove_soul(souls)

        self.hero.wuxings[str_id].level = wx.level
        self.hero.wuxings[str_id].exp = wx.exp
        self.hero.save()
        hero_changed_signal.send(
            sender=None,
            hero_id=self.id
        )

        if wx.level >= 5:
            ae = ActivityEntry(self.char_id, 40003)
            if ae:
                ae.enable(wx.level)

                ActivityStatic(self.char_id).send_update_notify(activity_ids=[40003])
Example #15
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)

        TimesLogEquipStepUp(self.char_id).inc()

        if self.equip.step == 4:
            ae = ActivityEntry(self.char_id, 50001)
            if ae:
                ae.enable(self.equip.step)
                ActivityStatic(self.char_id).send_update_notify(activity_ids=[50001])

        return stuff_needs
Example #16
0
def _stuff_remove(char_id, stuff_id, rm_amount, new_amount, **kwargs):
    ae = ActivityEntry(char_id, 7001)
    if ae and stuff_id == ae.STUFF_ID:
        ActivityStatic(char_id).trig(7001)

    ae = ActivityEntry(char_id, 18009)
    if ae and stuff_id == ae.STUFF_ID:
        ActivityStatic(char_id).trig(18009)

    ae = ActivityEntry(char_id, 40005)
    if ae and stuff_id == ae.STUFF_ID:
        ActivityStatic(char_id).trig(40005)

    ae = ActivityEntry(char_id, 50003)
    if ae and stuff_id == ae.STUFF_ID:
        ActivityStatic(char_id).trig(50003)

    ae = ActivityEntry(char_id, 60000)
    if ae and stuff_id == ae.STUFF_ID:
        ActivityStatic(char_id).trig(60000)
Example #17
0
def send_vip_reward(signum):
    logger = Logger("send_vip_reward.log")
    logger.write("Start")

    try:
        docs = MongoCharacter._get_collection().find({'vip': {
            '$gte': 6
        }}, {'_id': 1})

        for doc in docs:
            char_id = doc['_id']

            ac = ActivityEntry(char_id, 22001)
            if ac and ac.is_valid():
                ac.send_mail()
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done")
    finally:
        logger.close()
Example #18
0
def send_vip_reward(signum):
    logger = Logger("send_vip_reward.log")
    logger.write("Start")

    try:
        docs = MongoCharacter._get_collection().find(
            {'vip': {'$gte': 6}},
            {'_id': 1}
        )

        for doc in docs:
            char_id = doc['_id']

            ac = ActivityEntry(char_id, 22001)
            if ac and ac.is_valid():
                ac.send_mail()
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done")
    finally:
        logger.close()
Example #19
0
    def stuff_use(self, _id, amount):
        from core.attachment import standard_drop_to_attachment_protomsg, is_empty_drop, merge_drop
        from core.resource import Resource
        try:
            s = STUFFS[_id]
        except KeyError:
            raise SanguoException(errormsg.STUFF_NOT_EXIST, self.char_id,
                                  "Stuff Use",
                                  "stuff {0} not exist".format(_id))

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

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

        # 活动 10001
        additional_drop_1 = ActivityEntry(self.char_id,
                                          10001).get_additional_drop(_id)
        additional_drop_2 = ActivityEntry(self.char_id,
                                          12001).get_additional_drop(_id)
        additional_drop_3 = ActivityEntry(self.char_id,
                                          15001).get_additional_drop(_id)

        prepare_drop = self.get_sutff_drop(_id)
        drop = merge_drop([
            prepare_drop, additional_drop_1, additional_drop_2,
            additional_drop_3
        ])
        if is_empty_drop(drop):
            return None

        resource = Resource(self.char_id, "Stuff Use", "use {0}".format(_id))
        standard_drop = resource.add(**drop)
        return standard_drop_to_attachment_protomsg(standard_drop)
Example #20
0
    def wuxing_update(self, wuxing_id, souls):
        # 五行升级
        str_id = str(wuxing_id)
        if str_id not in self.hero.wuxings:
            raise SanguoException(
                errormsg.WUXING_NOT_FOR_THIS_HERO, self.char_id,
                "Hero WuXing Update",
                "hero {0} has no wuxing {1}".format(self.id, wuxing_id))

        hs = HeroSoul(self.char_id)
        add_exp = 0
        for soul_id, soul_amount in souls:
            if not hs.has_soul(soul_id, soul_amount):
                raise SanguoException(
                    errormsg.SOUL_NOT_ENOUGH, self.char_id,
                    "Hero WuXing Update",
                    "soul not enough. {0}: {1}".format(soul_id, soul_amount))

            add_exp += HEROS[soul_id].wuxing_exp * soul_amount

        wx = HeroWuXing(wuxing_id, self.hero.wuxings[str_id].level,
                        self.hero.wuxings[str_id].exp)
        wx.update(add_exp)

        hs.remove_soul(souls)

        self.hero.wuxings[str_id].level = wx.level
        self.hero.wuxings[str_id].exp = wx.exp
        self.hero.save()
        hero_changed_signal.send(sender=None, hero_id=self.id)

        if wx.level >= 5:
            ae = ActivityEntry(self.char_id, 40003)
            if ae:
                ae.enable(wx.level)

                ActivityStatic(
                    self.char_id).send_update_notify(activity_ids=[40003])
Example #21
0
        def _get():
            got = False
            prob = self.p.prisoners[str_id].prob + treasures_prob

            ae = ActivityEntry(self.char_id, 40008)
            if ae and ae.is_ok():
                prob += 80

            ae = ActivityEntry(self.char_id, 50005)
            if ae and ae.is_valid():
                _vip = ae.get_current_value(self.char_id)
                if _vip == 4:
                    prob += 30
                elif _vip == 5:
                    prob += 50
                elif _vip == 6:
                    prob += 60
                elif _vip >= 7:
                    prob += 100

            if prob >= random.randint(1, 100):
                # got it
                save_hero(self.char_id, self.p.prisoners[str_id].oid)
                got = True

                self.p.prisoners.pop(str_id)

                msg = protomsg.RemovePrisonerNotify()
                msg.ids.append(_id)
                publish_to_char(self.char_id, pack_msg(msg))
            else:
                self.p.prisoners[str_id].active = False

                msg = protomsg.UpdatePrisonerNotify()
                p = msg.prisoner.add()
                p_obj = self.p.prisoners[str_id]
                self._fill_up_prisoner_msg(p, _id, p_obj.oid, p_obj.prob, p_obj.active)

                publish_to_char(self.char_id, pack_msg(msg))

            self.p.save()
            return got
Example #22
0
    def battle(self):
        need_sycee = 0

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

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

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

        counter.incr()

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

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

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

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

            # 只有打赢才设置积分
            self_score = self.score
            rival_arena = Arena(rival_id)
            rival_score = rival_arena.score

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

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

            TimesLogArenaWin(self.char_id).inc()

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

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

        self.send_notify()
        drop['stuffs'].append((1001, adding_score))
        return msg, drop
Example #23
0
def login_notify(char_id):
    message_clean(char_id)
    function_open = FunctionOpen(char_id)
    function_open.send_notify()

    hero_objs = char_heros_obj(char_id)

    Char(char_id).send_notify()
    VIP(char_id).send_notify()

    hero_notify(char_id, hero_objs)
    Item(char_id).send_notify()

    f = Formation(char_id)
    f.send_socket_notify()
    f.send_formation_notify()

    Plunder(char_id).send_notify()

    p = Prison(char_id)
    p.send_prisoners_notify()

    a = Arena(char_id)
    a.send_notify()
    a.login_process()

    f = Friend(char_id)
    f.send_friends_notify()
    f.send_friends_amount_notify()

    CheckIn(char_id).send_notify()

    stage = Stage(char_id)
    stage.send_already_stage_notify()
    stage.send_new_stage_notify()

    stage_elite = EliteStage(char_id)
    stage_elite.send_notify()
    stage_elite.send_times_notify()

    stage_activity = ActivityStage(char_id)
    stage_activity.check(send_notify=False)
    stage_activity.send_notify()
    stage_activity.send_remained_times_notify()

    HeroPanel(char_id).send_notify()
    Task(char_id).send_notify()
    Achievement(char_id).send_notify()
    HeroSoul(char_id).send_notify()
    Levy(char_id).send_notify()
    Attachment(char_id).send_notify()

    BasePurchaseAction(char_id).send_notify()

    SystemBroadcast(char_id).send_global_broadcast()
    ChatMessagePublish(char_id).send_notify()

    affairs = Affairs(char_id)
    affairs.send_city_notify()
    affairs.send_hang_notify()

    HorseFreeTimesManager(char_id).send_notify()
    Horse(char_id).send_notify()

    union.send_notify(char_id)

    ae = ActivityEntry(char_id, 50006)
    if ae and ae.is_valid():
        ae.enable(ae.get_current_value(char_id))

    ActivityStatic(char_id).send_notify()

    # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件
    Mail(char_id).send_notify()
Example #24
0
def login_notify(char_id):
    message_clean(char_id)
    function_open = FunctionOpen(char_id)
    function_open.send_notify()

    hero_objs = char_heros_obj(char_id)

    Char(char_id).send_notify()
    VIP(char_id).send_notify()

    hero_notify(char_id, hero_objs)
    Item(char_id).send_notify()

    f = Formation(char_id)
    f.send_socket_notify()
    f.send_formation_notify()


    Plunder(char_id).send_notify()

    p = Prison(char_id)
    p.send_prisoners_notify()

    a = Arena(char_id)
    a.send_notify()
    a.login_process()

    f = Friend(char_id)
    f.send_friends_notify()
    f.send_friends_amount_notify()

    CheckIn(char_id).send_notify()

    stage = Stage(char_id)
    stage.send_already_stage_notify()
    stage.send_new_stage_notify()

    stage_elite = EliteStage(char_id)
    stage_elite.send_notify()
    stage_elite.send_times_notify()

    stage_activity = ActivityStage(char_id)
    stage_activity.check(send_notify=False)
    stage_activity.send_notify()
    stage_activity.send_remained_times_notify()

    HeroPanel(char_id).send_notify()
    Task(char_id).send_notify()
    Achievement(char_id).send_notify()
    HeroSoul(char_id).send_notify()
    Levy(char_id).send_notify()
    Attachment(char_id).send_notify()

    BasePurchaseAction(char_id).send_notify()

    SystemBroadcast(char_id).send_global_broadcast()
    ChatMessagePublish(char_id).send_notify()

    affairs = Affairs(char_id)
    affairs.send_city_notify()
    affairs.send_hang_notify()

    HorseFreeTimesManager(char_id).send_notify()
    Horse(char_id).send_notify()

    union.send_notify(char_id)


    ae = ActivityEntry(char_id, 50006)
    if ae and ae.is_valid():
        ae.enable(ae.get_current_value(char_id))

    ActivityStatic(char_id).send_notify()

    # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件
    Mail(char_id).send_notify()
Example #25
0
 def max_value(self):
     ac = ActivityEntry(self.char_id, 21001)
     if not ac:
         return ACTIVITY_STAGE_MAX_TIMES
     return ac.get_max_times()
Example #26
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])