comparison gamelib/scenes/mess.py @ 816:eed75a1d50c4 pyntnclick

Better Item handling.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 27 Jan 2013 22:19:39 +0200
parents 374d96e0b55e
children
comparison
equal deleted inserted replaced
815:8f94fbf05ab9 816:eed75a1d50c4
26 self.add_thing(CansOnShelf()) 26 self.add_thing(CansOnShelf())
27 self.add_thing(Tubes()) 27 self.add_thing(Tubes())
28 self.add_thing(ToMap()) 28 self.add_thing(ToMap())
29 self.add_thing(DetergentThing()) 29 self.add_thing(DetergentThing())
30 self.add_thing(Boomslang()) 30 self.add_thing(Boomslang())
31 self.add_item(DetergentBottle('detergent_bottle')) 31 self.add_item_factory(DetergentBottle)
32 self.add_item_factory(EmptyCan)
33 self.add_item_factory(FullCan)
34 self.add_item_factory(DentedCan)
32 # Flavour items 35 # Flavour items
33 # extra cans on shelf 36 # extra cans on shelf
34 self.add_thing(GenericDescThing('mess.cans', 1, 37 self.add_thing(GenericDescThing('mess.cans', 1,
35 _("A large collection of rusted, useless cans."), 38 _("A large collection of rusted, useless cans."),
36 ( 39 (
46 49
47 50
48 class BaseCan(CloneableItem): 51 class BaseCan(CloneableItem):
49 """Base class for the cans""" 52 """Base class for the cans"""
50 53
54 MAX_COUNT = 3
55
51 def interact_with_full_can(self, item): 56 def interact_with_full_can(self, item):
52 return Result(_("You bang the cans together. It sounds like two" 57 return Result(_("You bang the cans together. It sounds like two"
53 " cans being banged together."), 58 " cans being banged together."),
54 soundfile="can_hit.ogg") 59 soundfile="can_hit.ogg")
55 60
61 66
62 def interact_with_machete(self, item): 67 def interact_with_machete(self, item):
63 return Result(_("You'd mangle it beyond usefulness.")) 68 return Result(_("You'd mangle it beyond usefulness."))
64 69
65 def interact_with_canopener(self, item): 70 def interact_with_canopener(self, item):
66 empty = EmptyCan('empty_can') 71 self.game.replace_inventory_item(self.name, 'empty_can')
67 self.game.add_item(empty)
68 self.game.replace_inventory_item(self.name, empty.name)
69 return Result(_("You open both ends of the can, discarding the" 72 return Result(_("You open both ends of the can, discarding the"
70 " hideous contents.")) 73 " hideous contents."))
71 74
72 75
73 class EmptyCan(BaseCan): 76 class EmptyCan(BaseCan):
74 "After emptying the full can." 77 "After emptying the full can."
75 78
79 NAME = 'empty_can'
76 INVENTORY_IMAGE = "empty_can.png" 80 INVENTORY_IMAGE = "empty_can.png"
77 CURSOR = CursorSprite('empty_can_cursor.png') 81 CURSOR = CursorSprite('empty_can_cursor.png')
78 82
79 def interact_with_titanium_leg(self, item): 83 def interact_with_titanium_leg(self, item):
80 return Result(_("Flattening the can doesn't look like a useful" 84 return Result(_("Flattening the can doesn't look like a useful"
85 89
86 90
87 class FullCan(BaseCan): 91 class FullCan(BaseCan):
88 "Found on the shelf." 92 "Found on the shelf."
89 93
94 NAME = 'full_can'
90 INVENTORY_IMAGE = "full_can.png" 95 INVENTORY_IMAGE = "full_can.png"
91 CURSOR = CursorSprite('full_can_cursor.png') 96 CURSOR = CursorSprite('full_can_cursor.png')
92 97
93 def interact_with_titanium_leg(self, item): 98 def interact_with_titanium_leg(self, item):
94 dented = DentedCan("dented_can") 99 self.game.replace_inventory_item(self.name, 'dented_can')
95 self.game.add_item(dented)
96 self.game.replace_inventory_item(self.name, dented.name)
97 return Result(_("You club the can with the femur. The can gets dented," 100 return Result(_("You club the can with the femur. The can gets dented,"
98 " but doesn't open."), soundfile="can_hit.ogg") 101 " but doesn't open."), soundfile="can_hit.ogg")
99 102
100 103
101 class DentedCan(BaseCan): 104 class DentedCan(BaseCan):
102 "A can banged on with the femur" 105 "A can banged on with the femur"
103 106
107 NAME = 'dented_can'
104 INVENTORY_IMAGE = "dented_can.png" 108 INVENTORY_IMAGE = "dented_can.png"
105 CURSOR = CursorSprite('dented_can_cursor.png') 109 CURSOR = CursorSprite('dented_can_cursor.png')
106 110
107 def interact_with_titanium_leg(self, item): 111 def interact_with_titanium_leg(self, item):
108 return Result(_("You club the can with the femur. The dents shift" 112 return Result(_("You club the can with the femur. The dents shift"
134 return '%icans' % (self.get_data('cans_available'),) 138 return '%icans' % (self.get_data('cans_available'),)
135 139
136 def interact_without(self): 140 def interact_without(self):
137 starting_cans = self.get_data('cans_available') 141 starting_cans = self.get_data('cans_available')
138 if starting_cans > 0: 142 if starting_cans > 0:
139 can = FullCan("full_can") 143 self.game.add_inventory_item('full_can')
140 self.game.add_item(can)
141 self.game.add_inventory_item(can.name)
142 self.set_data('cans_available', starting_cans - 1) 144 self.set_data('cans_available', starting_cans - 1)
143 self.set_interact() 145 self.set_interact()
144 if starting_cans == 1: 146 if starting_cans == 1:
145 self.scene.remove_thing(self) 147 self.scene.remove_thing(self)
146 return Result({ 148 return Result({
322 return _("Empty plastic containers. " 324 return _("Empty plastic containers. "
323 "They used to hold dishwasher soap.") 325 "They used to hold dishwasher soap.")
324 326
325 327
326 class DetergentBottle(Item): 328 class DetergentBottle(Item):
329 NAME = 'detergent_bottle'
327 INVENTORY_IMAGE = 'bottle_empty.png' 330 INVENTORY_IMAGE = 'bottle_empty.png'
328 CURSOR = CursorSprite('bottle_empty_cursor.png', 27, 7) 331 CURSOR = CursorSprite('bottle_empty_cursor.png', 27, 7)
329 332
330 333
331 class ToMap(Door): 334 class ToMap(Door):