Esempio n. 1
0
def reset():
    amount = MongoArenaWeek.objects.count()

    logger = Logger("reset_arena_week.log")
    logger.write("Reset Arena Week: Start. chars amount: {0}".format(amount))

    data = MongoArenaWeek.objects.all()
    MongoArenaWeek.objects.delete()

    for d in data:
        reward = _get_reward(d.rank)
        gold = reward.week_gold
        attachment = Attachment(d.id)
        attachment.save_to_attachment(3, gold=gold)

        achievement = Achievement(d.id)
        achievement.trig(10, d.rank)

        if d.rank in TOP_RANKS:
            try:
                top = MongoArenaTopRanks.objects.get(id=d.rank)
            except DoesNotExist:
                top = MongoArenaTopRanks(id=d.rank)

            char_name = Char(d.id).cacheobj.name
            top.name = char_name
            top.save()

    logger.write("Reset Arena Week: Complete")
    logger.close()
Esempio n. 2
0
    def trig(self, tp, times=1):
        if tp not in TASKS_ALL_TP:
            system_logger(errormsg.INVALID_OPERATE, self.char_id, "Task Trig",
                          "invalid tp {0}".format(tp))
            return

        self.task.tasks[str(tp)] += times

        for t in self.task.doing:
            if t in self.task.complete:
                continue

            this_task = TASKS[t]
            if this_task.tp != tp:
                continue

            if self.task.tasks[str(tp)] >= this_task.times:
                # 此任务完成
                if t not in self.task.finished:
                    self.task.finished.append(t)

                attachment = Attachment(self.char_id)
                attachment.save_to_prize(5)

        self.task.save()
        self.send_notify()
Esempio n. 3
0
    def check(self):
        attachment = Attachment(self.char_id)

        for t in self.task.doing:
            if t in self.task.complete:
                continue

            this_task = TASKS[t]
            tp = this_task.tp

            if self.task.tasks[str(tp)] >= this_task.times:
                # 此任务完成
                if t not in self.task.finished:
                    self.task.finished.append(t)

                attachment.save_to_prize(5)

        self.task.save()

        # XXX
        # BUG 一些时候没有任务可领奖,但是 attachment 中 还有 5 prize,
        # 不知道为何……
        if not self.task.finished:
            if 5 in attachment.attachment.prize_ids:
                attachment.attachment.prize_ids.remove(5)
                attachment.attachment.save()
Esempio n. 4
0
def reset():
    amount = MongoArenaWeek.objects.count()

    logger = Logger("reset_arena_week.log")
    logger.write("Reset Arena Week: Start. chars amount: {0}".format(amount))

    data = MongoArenaWeek.objects.all()
    MongoArenaWeek.objects.delete()


    for d in data:
        reward = _get_reward(d.rank)
        gold = reward.week_gold
        attachment = Attachment(d.id)
        attachment.save_to_attachment(3, gold=gold)

        achievement = Achievement(d.id)
        achievement.trig(10, d.rank)

        if d.rank in TOP_RANKS:
            try:
                top = MongoArenaTopRanks.objects.get(id=d.rank)
            except DoesNotExist:
                top = MongoArenaTopRanks(id=d.rank)

            char_name = Char(d.id).cacheobj.name
            top.name = char_name
            top.save()

    logger.write("Reset Arena Week: Complete")
    logger.close()
Esempio n. 5
0
    def trig(self, tp, times=1):
        if tp not in TASKS_ALL_TP:
            system_logger(errormsg.INVALID_OPERATE, self.char_id, "Task Trig", "invalid tp {0}".format(tp))
            return

        self.task.tasks[str(tp)] += times

        for t in self.task.doing:
            if t in self.task.complete:
                continue

            this_task = TASKS[t]
            if this_task.tp != tp:
                continue

            if self.task.tasks[str(tp)] >= this_task.times:
                # 此任务完成
                if t not in self.task.finished:
                    self.task.finished.append(t)

                attachment = Attachment(self.char_id)
                attachment.save_to_prize(5)


        self.task.save()
        self.send_notify()
Esempio n. 6
0
    def finish(self, actual_seconds=None, set_hang=True):
        if not self.hang_doing:
            raise SanguoException(
                errormsg.HANG_NOT_EXIST,
                self.char_id,
                "Hang Finish",
                "Hang Finish. But no hang exist"
            )

        if not actual_seconds:
            actual_seconds = arrow.utcnow().timestamp - self.hang_doing.start

        if set_hang:
            self.hang.used += actual_seconds
            self.hang.save()

        self.hang_doing.finished = True
        self.hang_doing.actual_seconds = actual_seconds
        self.hang_doing.save()

        self.send_notify()

        attachment = Attachment(self.char_id)
        attachment.save_to_prize(1)

        actual_hours = actual_seconds / 3600
        achievement = Achievement(self.char_id)
        achievement.trig(28, actual_hours)
Esempio n. 7
0
    def check(self):
        attachment = Attachment(self.char_id)

        for t in self.task.doing:
            if t in self.task.complete:
                continue

            this_task = TASKS[t]
            tp = this_task.tp

            if self.task.tasks[str(tp)] >= this_task.times:
                # 此任务完成
                if t not in self.task.finished:
                    self.task.finished.append(t)

                attachment.save_to_prize(5)

        self.task.save()

        # XXX
        # BUG 一些时候没有任务可领奖,但是 attachment 中 还有 5 prize,
        # 不知道为何……
        if not self.task.finished:
            if 5 in attachment.attachment.prize_ids:
                attachment.attachment.prize_ids.remove(5)
                attachment.attachment.save()
Esempio n. 8
0
    def finish(self, actual_seconds=None, set_hang=True):
        if not self.hang_doing:
            raise SanguoException(errormsg.HANG_NOT_EXIST, self.char_id,
                                  "Hang Finish",
                                  "Hang Finish. But no hang exist")

        if not actual_seconds:
            actual_seconds = arrow.utcnow().timestamp - self.hang_doing.start

        if set_hang:
            self.hang.used += actual_seconds
            self.hang.save()

        self.hang_doing.finished = True
        self.hang_doing.actual_seconds = actual_seconds
        self.hang_doing.save()

        self.send_notify()

        attachment = Attachment(self.char_id)
        attachment.save_to_prize(1)

        actual_hours = actual_seconds / 3600
        achievement = Achievement(self.char_id)
        achievement.trig(28, actual_hours)
Esempio n. 9
0
    def check(self):
        char = Char(self.char_id)
        official_level = char.cacheobj.official
        if official_level == 0:
            return

        counter = Counter(self.char_id, 'official_reward')
        remained_value = counter.remained_value
        if remained_value > 0:
            attachment = Attachment(self.char_id)
            attachment.save_to_prize(6)
Esempio n. 10
0
    def check(self):
        char = Char(self.char_id)
        official_level = char.cacheobj.official
        if official_level == 0:
            return

        counter = Counter(self.char_id, 'official_reward')
        remained_value = counter.remained_value
        if remained_value > 0:
            attachment = Attachment(self.char_id)
            attachment.save_to_prize(6)
Esempio n. 11
0
def prize_get(request):
    req = request._proto
    char_id = request._char_id

    attachment = Attachment(char_id)
    att_msg = attachment.get_attachment(req.prize.id, req.prize.param)

    response = PrizeResponse()
    response.ret = 0
    response.prize.MergeFrom(req.prize)
    response.drop.MergeFrom(att_msg)
    return pack_msg(response)
Esempio n. 12
0
def reset(signum):
    logger = Logger('reset_prize.log')
    logger.write("Start")

    try:
        Attachment.cron_job()
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done")
    finally:
        logger.close()
Esempio n. 13
0
def prize_get(request):
    req = request._proto
    char_id = request._char_id

    attachment = Attachment(char_id)
    att_msg = attachment.get_attachment(req.prize.id, req.prize.param)

    response = PrizeResponse()
    response.ret = 0
    response.prize.MergeFrom(req.prize)
    response.drop.MergeFrom(att_msg)
    return pack_msg(response)
Esempio n. 14
0
    def get_reward(self, achievement_id):
        try:
            ach = ACHIEVEMENTS[achievement_id]
        except KeyError:
            raise SanguoException(
                errormsg.ACHIEVEMENT_NOT_EXIST,
                self.char_id,
                "Achievement Get Reward",
                "{0} not exist".format(achievement_id)
            )

        if achievement_id not in self.achievement.display:
            raise SanguoException(
                errormsg.ACHIEVEMENT_NOT_FINISH,
                self.char_id,
                "Achievement Get Reward",
                "{0} not in display".format(achievement_id)
            )

        if achievement_id not in self.achievement.finished:
            raise SanguoException(
                errormsg.ACHIEVEMENT_NOT_FINISH,
                self.char_id,
                "Achievement Get Reward",
                "{0} not finished".format(achievement_id)
            )

        self.achievement.finished.remove(achievement_id)
        self.achievement.complete.append(achievement_id)

        updated_achs = [ach]

        if ach.next:
            index = self.achievement.display.index(achievement_id)
            self.achievement.display[index] = ach.next

            updated_achs.append(ACHIEVEMENTS[ach.next])

            if ach.next in self.achievement.finished:
                attachment = Attachment(self.char_id)
                attachment.save_to_prize(4)

        self.achievement.save()

        for up_ach in updated_achs:
            msg = UpdateAchievementNotify()
            self._fill_up_achievement_msg(msg.achievement, up_ach)
            publish_to_char(self.char_id, pack_msg(msg))

        standard_drop = self.send_reward(achievement_id, ach.sycee, ach.package)
        return standard_drop_to_attachment_protomsg(standard_drop)
Esempio n. 15
0
    def check(self):
        for t in self.task.doing:
            if t in self.task.complete:
                continue

            this_task = TASKS[t]
            tp = this_task.tp

            if self.task.tasks[str(tp)] >= this_task.times:
                # 此任务完成
                if t not in self.task.finished:
                    self.task.finished.append(t)

                attachment = Attachment(self.char_id)
                attachment.save_to_prize(5)

        self.task.save()
Esempio n. 16
0
    def check(self):
        for t in self.task.doing:
            if t in self.task.complete:
                continue

            this_task = TASKS[t]
            tp = this_task.tp

            if self.task.tasks[str(tp)] >= this_task.times:
                # 此任务完成
                if t not in self.task.finished:
                    self.task.finished.append(t)

                attachment = Attachment(self.char_id)
                attachment.save_to_prize(5)

        self.task.save()
Esempio n. 17
0
    def get_reward(self, achievement_id):
        try:
            ach = ACHIEVEMENTS[achievement_id]
        except KeyError:
            raise SanguoException(errormsg.ACHIEVEMENT_NOT_EXIST, self.char_id,
                                  "Achievement Get Reward",
                                  "{0} not exist".format(achievement_id))

        if achievement_id not in self.achievement.display:
            raise SanguoException(errormsg.ACHIEVEMENT_NOT_FINISH,
                                  self.char_id, "Achievement Get Reward",
                                  "{0} not in display".format(achievement_id))

        if achievement_id not in self.achievement.finished:
            raise SanguoException(errormsg.ACHIEVEMENT_NOT_FINISH,
                                  self.char_id, "Achievement Get Reward",
                                  "{0} not finished".format(achievement_id))

        self.achievement.finished.remove(achievement_id)
        self.achievement.complete.append(achievement_id)

        updated_achs = [ach]

        if ach.next:
            index = self.achievement.display.index(achievement_id)
            self.achievement.display[index] = ach.next

            updated_achs.append(ACHIEVEMENTS[ach.next])

            if ach.next in self.achievement.finished:
                attachment = Attachment(self.char_id)
                attachment.save_to_prize(4)

        self.achievement.save()

        for up_ach in updated_achs:
            msg = UpdateAchievementNotify()
            self._fill_up_achievement_msg(msg.achievement, up_ach)
            publish_to_char(self.char_id, pack_msg(msg))

        standard_drop = self.send_reward(achievement_id, ach.sycee,
                                         ach.package)
        return standard_drop_to_attachment_protomsg(standard_drop)
Esempio n. 18
0
def reset():
    amount = MongoArenaDay.objects.count()

    logger = Logger('reset_arena_day.log')
    logger.write("Reset Arena Day: Start. chars amount: {0}".format(amount))

    arena_day = MongoArenaDay.objects.all()
    MongoArenaDay.objects.delete()

    chars_data = []
    for ad in arena_day:
        char_id = ad.id
        char_score = ad.score
        char_power = Char(char_id).power
        chars_data.append((char_id, char_score, char_power))

    chars_data.sort(key=lambda item: (-item[1], -item[2]))

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

        try:
            arena_week = MongoArenaWeek.objects.get(id=char_id)
        except DoesNotExist:
            arena_week = MongoArenaWeek(id=char_id)
            arena_week.score = 0

        arena_week.score += score
        arena_week.rank = rank
        arena_week.save()

        # FIXME reward
        attachment = Attachment(char_id)
        attachment.save_to_attachment(2, gold=100)


    logger.write("Reset Arena Day: Complete")
    logger.close()
Esempio n. 19
0
def reset():
    amount = MongoArenaDay.objects.count()

    logger = Logger('reset_arena_day.log')
    logger.write("Reset Arena Day: Start. chars amount: {0}".format(amount))

    arena_day = MongoArenaDay.objects.all()
    MongoArenaDay.objects.delete()

    chars_data = []
    for ad in arena_day:
        char_id = ad.id
        char_score = ad.score
        char_power = Char(char_id).power
        chars_data.append((char_id, char_score, char_power))

    chars_data.sort(key=lambda item: (-item[1], -item[2]))

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

        try:
            arena_week = MongoArenaWeek.objects.get(id=char_id)
        except DoesNotExist:
            arena_week = MongoArenaWeek(id=char_id)
            arena_week.score = 0

        arena_week.score += score
        arena_week.rank = rank
        arena_week.save()

        # FIXME reward
        attachment = Attachment(char_id)
        attachment.save_to_attachment(2, gold=100)

    logger.write("Reset Arena Day: Complete")
    logger.close()
Esempio n. 20
0
def login_notify(char_id):
    hero_objs = char_heros_obj(char_id)

    Char(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()

    hang = Hang(char_id)
    hang.send_notify()

    Plunder(char_id).send_notify()

    p = Prison(char_id)
    p.send_prisoners_notify()

    Arena(char_id).send_notify()

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

    m = Mail(char_id)
    m.send_mail_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_remained_times_notify()

    stage_activity = ActivityStage(char_id)
    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()
    FunctionOpen(char_id).send_notify()
    Levy(char_id).send_notify()
    Attachment(char_id).send_notify()
Esempio n. 21
0
    def trig_achievement(self, ach, new_value, send_notify=True):
        achievement_id = ach.id
        if achievement_id in self.achievement.complete or achievement_id in self.achievement.finished:
            return

        attachment = Attachment(self.char_id)
        str_id = str(achievement_id)

        decoded_condition_value = ach.decoded_condition_value

        def finish_it():
            if achievement_id not in self.achievement.finished:
                self.achievement.finished.append(achievement_id)
            if str_id in self.achievement.doing:
                self.achievement.doing.pop(str_id)

            if achievement_id in self.achievement.display:
                attachment.save_to_prize(4)

        if ach.mode == 1:
            # 多个ID条件
            actual_new_value = [
                i for i in new_value if i in decoded_condition_value
            ]
            if not actual_new_value:
                return

            if str_id in self.achievement.doing:
                values = [
                    int(i) for i in self.achievement.doing[str_id].split(',')
                ]
            else:
                values = []

            for av in actual_new_value:
                if av not in values:
                    values.append(av)

            if set(values) == set(decoded_condition_value):
                # FINISH
                finish_it()
            else:
                self.achievement.doing[str_id] = ','.join(
                    [str(i) for i in values])

        elif ach.mode == 2:
            # 单个ID条件
            if new_value != decoded_condition_value:
                return
            # FINISH
            finish_it()

        elif ach.mode == 3:
            # 普通数量条件 数量累加
            if str_id in self.achievement.doing:
                value = self.achievement.doing[str_id]
            else:
                value = 0

            value += new_value
            if value >= decoded_condition_value:
                # FINISH
                finish_it()
            else:
                self.achievement.doing[str_id] = value

        elif ach.mode == 4:
            # 阀值数量条件
            # 这里不叠加,只是简单的比较
            if new_value >= decoded_condition_value:
                # FINISH
                finish_it()
            else:
                self.achievement.doing[str_id] = new_value

        else:
            # 反向阀值条件, 比较小于就完成
            if new_value <= decoded_condition_value:
                # FINISH
                finish_it()
            else:
                self.achievement.doing[str_id] = new_value

        self.achievement.save()

        if send_notify and achievement_id in self.achievement.display:
            msg = UpdateAchievementNotify()
            self._fill_up_achievement_msg(msg.achievement, ach)
            publish_to_char(self.char_id, pack_msg(msg))
Esempio n. 22
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()
Esempio n. 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()

    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()

    if Arena.FUNC_ID not in function_open.mf.freeze:
        arena = Arena(char_id)
        arena.send_notify()
        arena.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_remained_times_notify()

    stage_activity = ActivityStage(char_id)
    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()

    PurchaseAction(char_id).send_notify()

    SystemBroadcast(char_id).send_global_broadcast()

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

    # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件
    Mail(char_id).send_notify()
Esempio n. 24
0
 def check(self):
     if not self.achievement.finished:
         attachment = Attachment(self.char_id)
         if 4 in attachment.attachment.prize_ids:
             attachment.attachment.prize_ids.remove(4)
             attachment.attachment.save()