# HG changeset patch # User Jeremy Thurgood # Date 1282764758 -7200 # Node ID 278774b31d3cfd0186be0c8475dc218aa34b5004 # Parent 30f2308c1efc0f11ee26f1f4027f95d4f4021811 CloneableItems. diff -r 30f2308c1efc -r 278774b31d3c gamelib/scenes/mess.py --- a/gamelib/scenes/mess.py Wed Aug 25 20:09:19 2010 +0200 +++ b/gamelib/scenes/mess.py Wed Aug 25 21:32:38 2010 +0200 @@ -2,7 +2,7 @@ from random import choice -from gamelib.state import Scene, Item, Thing, InteractImage, InteractNoImage, Result +from gamelib.state import Scene, Item, CloneableItem, Thing, InteractImage, InteractNoImage, Result from gamelib.cursor import CursorSprite @@ -26,31 +26,33 @@ self.add_thing(ToMap()) -class EmptyCan(Item): +class EmptyCan(CloneableItem): "After emptying the full can." INVENTORY_IMAGE = "empty_can.png" CURSOR = CursorSprite('empty_can_cursor.png', 20, 30) -class FullCan(Item): + +class FullCan(CloneableItem): "Found on the shelf." INVENTORY_IMAGE = "full_can.png" CURSOR = CursorSprite('full_can_cursor.png', 20, 30) - def interact_with_titanium_leg(self, tool, state): + def interact_with_titanium_leg(self, item, state): dented = DentedCan("dented_can") + state.add_item(dented) state.replace_inventory_item(self, dented) return Result("You club the can with the femur. The can gets dented, but doesn't open.") -class DentedCan(FullCan): +class DentedCan(CloneableItem): "A can banged on with the femur" INVENTORY_IMAGE = "dented_can.png" CURSOR = CursorSprite('dented_can_cursor.png', 20, 30) - def interact_with_titanium_leg(self, tool, inventory): + def interact_with_titanium_leg(self, item, state): return Result("You club the can with the femur. The dents shift around, but it still doesn't open.") @@ -84,7 +86,9 @@ } def interact_without(self): - self.state.add_inventory_item('full_can') + can = FullCan("full_can") + self.state.add_item(can) + self.state.add_inventory_item(can.name) if not self.data['taken_one']: self.set_data('taken_one', True) return Result("Best before along time in the past. Better not eat these.") diff -r 30f2308c1efc -r 278774b31d3c gamelib/state.py --- a/gamelib/state.py Wed Aug 25 20:09:19 2010 +0200 +++ b/gamelib/state.py Wed Aug 25 21:32:38 2010 +0200 @@ -572,3 +572,11 @@ def interact_default(self, tool, state): return Result("That doesn't do anything useful") + +class CloneableItem(Item): + _counter = 0 + + def __init__(self, name): + my_count = CloneableItem._counter + CloneableItem._counter += 1 + super(CloneableItem, self).__init__("%s.%s" % (name, my_count))