Mercurial > fife-parpg
annotate demos/rpg/scripts/actors/questgiver.py @ 534:65a92a2449d5
Doing some re-factoring.
Minor change to the way the console commands are parsed.
Added the spawn command to the help file.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 31 May 2010 17:45:04 +0000 |
parents | |
children | 2e739ae9a8bc |
rev | line source |
---|---|
534
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 #!/usr/bin/env python |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # -*- coding: utf-8 -*- |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # #################################################################### |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # Copyright (C) 2005-2010 by the FIFE team |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # http://www.fifengine.net |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # This file is part of FIFE. |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # FIFE is free software; you can redistribute it and/or |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # modify it under the terms of the GNU Lesser General Public |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # License as published by the Free Software Foundation; either |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # version 2.1 of the License, or (at your option) any later version. |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # This library is distributed in the hope that it will be useful, |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # Lesser General Public License for more details. |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # You should have received a copy of the GNU Lesser General Public |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # License along with this library; if not, write to the |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # Free Software Foundation, Inc., |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 # #################################################################### |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 # This is the rio de hola client for FIFE. |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 import sys, os, re, math, random, shutil |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 from fife import fife |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 from scripts.objects.baseobject import BaseGameObject, GameObjectTypes |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 from scripts.actors.baseactor import Actor |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 class QuestGiver(Actor): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 self._type = GameObjectTypes["QUESTGIVER"] |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance) |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 self._quests = [] |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 self._activequest = None |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 def addQuest(self, quest): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 self._quests.append(quest) |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 def offerNextQuest(self): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 if self._activequest: |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 return |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 if len(self._quests) > 0: |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 self._gamecontroller.guicontroller.showQuestDialog(self) |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 def getNextQuest(self): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 if len(self._quests) > 0: |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 return self._quests[0] |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 return None |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 def activateQuest(self, quest): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 self._activequest = quest |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 def completeQuest(self): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 if self._activequest in self._quests: |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 if self._activequest.checkQuestCompleted(self._gamecontroller.scene.player): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 self.say("That everything I need. Thank you!") |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - self._activequest.requiredgold |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 for itemid in self._activequest.requireditems: |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 self._gamecontroller.scene.player.removeItemFromInventory(itemid) |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 self._quests.remove(self._activequest) |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 self._activequest = None |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 else: |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 self.say("Come back when you have all the items I requested!") |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 else: |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 #something went wrong |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 self._activequest = None |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 def haveQuest(self): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 return len(self._quests) > 0 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 def _getActiveQuest(self): |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 return self._activequest |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 activequest = property(_getActiveQuest) |