示例#1
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])
示例#2
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])
示例#3
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
示例#4
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])
示例#5
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
示例#6
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])
示例#7
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])
示例#8
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()
示例#9
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()