示例#1
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()
示例#2
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()
示例#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()
示例#4
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()
示例#5
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)
示例#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)
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
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()
示例#11
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()
示例#12
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)