示例#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 _hero_add(char_id, hero_ids, hero_original_ids, send_notify, **kwargs):
    if send_notify:
        heros = [Hero.cache_obj(i) for i in hero_ids]
        add_hero_notify(char_id, heros)

    heros_dict = char_heros_dict(char_id)

    achievement = Achievement(char_id)
    achievement.trig(1, len(heros_dict), send_notify=send_notify)

    quality_one_heros_amount = 0
    quality_two_heros_amount = 0
    quality_three_heros_amount = 0
    gender_female_heros_amount = 0

    for h in heros_dict.values():
        original_hero = HEROS[h.oid]
        if original_hero.quality == 1:
            quality_one_heros_amount += 1
        if original_hero.quality == 2:
            quality_two_heros_amount += 1
        if original_hero.quality == 3:
            quality_three_heros_amount += 1
        if original_hero.gender == 2:
            gender_female_heros_amount += 1

    achievement.trig(2, quality_one_heros_amount, send_notify=send_notify)
    achievement.trig(3, quality_two_heros_amount, send_notify=send_notify)
    achievement.trig(4, quality_three_heros_amount, send_notify=send_notify)
    achievement.trig(5, gender_female_heros_amount, send_notify=send_notify)

    ActivityStatic(char_id).trig(2001)
    ActivityStatic(char_id).trig(8001)
    ActivityStatic(char_id).trig(30003)
示例#3
0
def get_reward(request):
    req = request._proto

    ac = ActivityStatic(request._char_id)
    reward = ac.get_reward(req.condition_id)

    response = ActivityGetRewardResponse()
    response.ret = 0
    response.reward.MergeFrom(reward)
    return pack_msg(response)
示例#4
0
def get_reward(request):
    req = request._proto

    ac = ActivityStatic(request._char_id)
    reward = ac.get_reward(req.condition_id)

    response = ActivityGetRewardResponse()
    response.ret = 0
    response.reward.MergeFrom(reward)
    return pack_msg(response)
示例#5
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])
示例#6
0
def _char_level_up(char_id, new_level, **kwargs):
    _all_hero_changed(char_id)

    achievement = Achievement(char_id)
    achievement.trig(18, new_level)
    activity_stage = ActivityStage(char_id)
    activity_stage.check(new_level)

    ActivityStatic(char_id).trig(1001)
示例#7
0
    def inc(self):
        from core.activity import has_activity, ActivityStatic

        log = MongoTimesLog(id=str(uuid.uuid4()))
        log.key = self.key
        log.timestamp = arrow.utcnow().timestamp
        log.save()

        if self.ACTIVITY_ID and has_activity(self.ACTIVITY_ID):
            ActivityStatic(self.char_id).trig(self.ACTIVITY_ID)
示例#8
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)
示例#9
0
def _char_sycee_changed(char_id, now_value, cost_value, add_value, **kwargs):
    if cost_value:
        cost_value = abs(cost_value)
        achievement = Achievement(char_id)
        achievement.trig(31, cost_value)

        cslog = MongoCostSyceeLog()
        cslog.char_id = char_id
        cslog.sycee = cost_value
        cslog.cost_at = arrow.utcnow().timestamp
        cslog.save()

        ActivityStatic(char_id).trig(6001)
示例#10
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
示例#11
0
def pve_finish(char_id, stage_id, win, star, **kwargs):
    achievement = Achievement(char_id)
    if win:
        achievement.trig(7, stage_id)
        if star:
            achievement.trig(9, 1)

        t = Task(char_id)
        t.trig(1)
    else:
        achievement.trig(8, 1)

    # 开启城镇
    if win:
        if STAGES[stage_id].battle_open:
            affairs = Affairs(char_id)
            affairs.open_city(STAGES[stage_id].battle)

    # 判断活动
    if win:
        ActivityStatic(char_id).trig(3001)
示例#12
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])
示例#13
0
def _hero_del(char_id, hero_id, hero_oid, **kwargs):
    remove_hero_notify(char_id, [hero_id])
    ActivityStatic(char_id).trig(8001)
示例#14
0
def reset(signum):
    logger = Logger("reset_arena_week.log")
    logger.write("Start Arena Week")

    try:
        # 每周奖励
        rank_data = get_rank_data(ARENA_WEEK_REWARD_LOWEST_RANK)
        rank_info_log = ["\n",]

        for index, data in enumerate(rank_data):
            rank = index + 1
            char_id = data[0]
            score = data[1]

            _info_text = "Rank: {0}, Char: {1}, Score: {2}".format(rank, char_id, score)

            if score < ARENA_RANK_LINE:
                continue

            reward = _get_reward_by_rank(rank)
            if not reward:
                continue

            mail = Mail(char_id)
            mail.add(
                MAIL_ARENA_WEEK_REWARD_TITLE,
                MAIL_ARENA_WEEK_REWARD_CONTENT,
                attachment=json.dumps(reward))

            _info_text = "{0}. Send Mail: True".format(_info_text)
            rank_info_log.append(_info_text)
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("\n".join(rank_info_log))
        logger.write("Done  Arena Week")
    finally:
        logger.close()


    logger = Logger("reset_arena_week.log")
    logger.write("Start Arena Achievement")

    try:
        # 成就
        rank_data = get_rank_data(None)
        for index, data in enumerate(rank_data):
            rank = index + 1
            char_id = data[0]

            achievement = Achievement(char_id)
            achievement.trig(10, rank)
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done  Arena Achievement")
    finally:
        logger.close()


    logger = Logger("reset_arena_week.log")
    logger.write("Start Arena Activity 4001")

    try:
        # 开服比武奖励
        _activity_anera_values = []
        for _c in ACTIVITY_STATIC[4001].condition_objs:
            _activity_anera_values.append(_c.condition_value)

        LOWEST_RANK = max(_activity_anera_values)
        rank_data = get_rank_data(LOWEST_RANK)
        for index, data in enumerate(rank_data):
            char_id = data[0]

            ActivityStatic(char_id).trig(4001)
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done  Arena Activity 4001")
    finally:
        logger.close()
示例#15
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()
示例#16
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()