-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquest.py
71 lines (54 loc) · 1.7 KB
/
quest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# coding:utf8
"""任务系统"""
class Quest(object):
"""任务基类"""
WAIT = 0 # 等待任务请求
ACCEPTED = 1 # 已接受,正在执行任务
DONE = 2 # 已完成任务要求,但尚未交还
COMPLETED = 3 # 已交还任务,彻底完成任务目标
OUTOFDATE = 4 # 任务已过期
def __init__(self, *args, **kwargs):
#任务目标对象列表
self.targets = kwargs.get('targets', [])
# 任务内容的简要描述(一行)
self.title = kwargs.get('title', "")
# 任务内容的详细描述(多行)
self.description = kwargs.get('description', "")
# 任务状态
self.status = Quest.WAIT
def execute(self, player, target):
"""执行任务"""
pass
class TalkQuest(Quest):
"""对话类任务"""
def __init__(self, talkto, msg, *args, **kwargs):
super(TalkQuest, self).__init__(
targets=[talkto],
*kargs, **kwargs)
self.msg = msg
def execute(self, player, target):
assert target in self.targets
MsgBox(self.msg).show()
self.status = Quest.DONE
class CollectQuest(Quest):
"""收集类任务"""
class FightQuest(Quest):
"""战斗类任务"""
class QuestMaster(Npc):
"""提供任务的NPC"""
quest_class = Quest
def __init__(self, *args, **kwargs):
super(QuestMaster, self).__init__(*args, **kwargs)
self.quest = self.quest_class()
def do_collide(self, player):
if self.quest.status == Quest.WAIT:
player.quests.append(self.quest)
elif self.quest.status == Quest.ACCEPTED:
MsgBox("Please complete your quest!").show()
elif self.quest.status == Quest.DONE:
self.commit()
def commit(self):
self.quest.status = Quest.COMPLETE
def TestQM(QuestMaster):
def __init__(self, *args, **kwargs):
self.quest = TalkQuest(talkto, "asfsdf")