source: trunk/game/scripts/objects/composed.py @ 568

Revision 568, 4.4 KB checked in by beliar, 10 years ago (diff)

Patch by Beliar.

  • The Basic Action now has a commands property. The execute method of the class now loops through this dictionary, parses the values and executes special commands based on these values.
  • Implemented "SetQuestVariable?" command in the Action class. This sets a variable of a quest.
  • Added action property to Usable
  • Added ReadAction? class. For now this prints a name and a text to the console.
  • When right clicking on an item in a container or the pc's inventory the item will be checked for available actions and create a menu from these.
  • Implemented "Read" action to container/inventory items
  • Moved Pamphlet from pc inventory to "DirtyOldCrate?"
  • Added "Grain" object to ObjectDatabase?
  • Gave "Grain" object with ID "bushel_of_grain" to "Farmer Manslow" NPC
  • With these changes it is now possible to advance a bit into the Beer-Quest without using the console. It is still not finishable though.
  • Property svn:eol-style set to native
Line 
1#!/usr/bin/python
2
3#   This file is part of PARPG.
4
5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
9
10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18"""Composite game object classes are kept here"""
19
20from base import GameObject, Container, Lockable, \
21                Scriptable, Trappable, Destructable, Carryable, \
22                Usable
23
24class ImmovableContainer(GameObject, Container, Lockable, Scriptable, 
25                         Trappable, Destructable):
26    """Composite class that can be used for crates, chests, etc."""
27    def __init__ (self, **kwargs):
28        GameObject   .__init__(self, **kwargs)
29        Container    .__init__(self, **kwargs)
30        Lockable     .__init__(self, **kwargs)
31        Scriptable   .__init__(self, **kwargs)
32        Trappable    .__init__(self, **kwargs)
33        Destructable .__init__(self, **kwargs)
34        self.blocking = True
35
36class CarryableContainer(Container, Carryable):
37    """Composite class that will be used for backpack, pouches, etc."""
38    def __init__ (self, **kwargs):
39        Container.__init__(self, **kwargs)
40        Carryable.__init__(self, **kwargs)
41        self.own_bulk = 0
42        self.own_weight = 0
43
44    def getWeight(self):
45        """Resulting weight of a container"""
46        return sum((item.weight for item in self.items.values()), 
47                   self.own_weight)
48
49    def setWeight(self, weight):
50        """Set container's own weight.
51        For compatibility with inherited methods"""
52        self.own_weight = weight
53
54    weight = property(getWeight, setWeight, "Total weight of container")
55
56    def getBulk(self):
57        """Resulting bulk of container"""
58        return self.getContentsBulk()+self.own_bulk
59
60    def setBulk(self, bulk):
61        """Set container's own bulk. For compatibility with inherited methods"""
62        self.own_bulk = bulk
63
64    bulk = property(getBulk, setBulk, "Total bulk of container")
65
66    def __repr__(self):
67        return "[%s" % self.name + str(reduce((lambda a, b: a + ', ' + \
68                                    str(self.items[b])), self.items, "")) + " ]"
69   
70class SingleItemContainer (CarryableContainer) :
71    """Container that can only store a single item.
72       This class can represent single-item inventory slots"""
73    def __init__ (self, **kwargs):
74        CarryableContainer.__init__(self, **kwargs)
75
76    def placeItem(self,item, index=None):
77        if len(self.items) > 0 :
78            raise self.SlotBusy ('%s is already busy' % self)
79        CarryableContainer.placeItem(self, item)
80
81class CarryableItem (GameObject, Carryable, Usable):
82    """Composite class that will be used for all carryable items"""
83    def __init__(self, **kwargs):
84        GameObject.__init__(self, **kwargs)
85        Carryable.__init__(self, **kwargs)
86        Usable.__init__(self, **kwargs)
87
88    def prepareStateForSaving(self, state):
89        """Prepares state for saving
90        @type state: dictionary
91        @param state: State of the object 
92        """
93        del state["in_container"]
94
95    def getStateForSaving(self):
96        """Returns state for saving
97        @type state: dictionary
98        @param state: State of the object 
99        """
100        ret_dict = self.__dict__.copy()
101        self.prepareStateForSaving(ret_dict)
102        return ret_dict
103       
104class Door(GameObject, Lockable, Scriptable, Trappable):
105    """Composite class that can be used to create doors on a map."""
106    def __init__ (self, target_map_name = 'my-map',
107                  target_x = 0.0, target_y = 0.0, **kwargs):
108        GameObject.__init__(self, **kwargs)
109        Lockable.__init__(self, **kwargs)
110        Scriptable.__init__(self, **kwargs)
111        Trappable.__init__(self, **kwargs)
112        self.is_door = True
113        self.target_map_name = target_map_name
114        self.target_pos = (target_x, target_y)
115        self.blocking = True
116
117    def getStateForSaving(self):
118        """Returns state for saving
119        """
120        ret_dict = super(Door, self).getStateForSaving()
121        return ret_dict
Note: See TracBrowser for help on using the repository browser.