comparison objects/action.py @ 134:73b7188a461d

Changed BrewBeerAction to work with components.
author KarstenBock@gmx.net
date Sat, 08 Oct 2011 14:19:35 +0200
parents a93b38d7e02b
children 9397f3e4516d
comparison
equal deleted inserted replaced
133:18391ebe137b 134:73b7188a461d
455 455
456 class BrewBeerAction(Action): 456 class BrewBeerAction(Action):
457 """Action for brewing beer in a pot""" 457 """Action for brewing beer in a pot"""
458 def __init__(self, controller, pot, commands = None): 458 def __init__(self, controller, pot, commands = None):
459 super(BrewBeerAction, self).__init__(controller, commands) 459 super(BrewBeerAction, self).__init__(controller, commands)
460 self.pot = pot 460 self.pot = pot.container
461 self.view = controller.view 461 self.view = controller.view
462 462
463 def execute(self): 463 def execute(self):
464 """Brew the beer""" 464 """Brew the beer"""
465 has_water = False 465 has_water = False
466 has_yeast = False 466 has_yeast = False
467 has_fruit = False 467 has_fruit = False
468 has_wood = False 468 has_wood = False
469 has_bottle = False 469 has_bottle = False
470 player_character = self.model.game_state.getObjectById("PlayerCharacter").fifeagent 470 player_character = (self.model.game_state.
471 for item in self.pot.items.itervalues(): 471 getObjectById("PlayerCharacter").container)
472 for item in self.pot.children:
473 if not item:
474 continue
472 if item.item_type == "Questionable water": 475 if item.item_type == "Questionable water":
473 if has_water: 476 if has_water:
474 self.view.hud.addAction(unicode(\ 477 self.view.hud.addAction(unicode(\
475 "Please put only 1 water in the pot")) 478 "Please put only 1 water in the pot"))
476 return 479 return
515 "Please put only 1 yeast in the pot")) 518 "Please put only 1 yeast in the pot"))
516 return 519 return
517 has_yeast = True 520 has_yeast = True
518 yeast = item 521 yeast = item
519 else: 522 else:
520 self.view.hud.addAction(unicode("Item " + item.name + \ 523 self.view.hud.addAction(unicode(
521 " is not needed for brewing beer")) 524 "Item " + (item.entity.description.view_name) +
525 " is not needed for brewing beer"))
522 self.view.hud.addAction(unicode(\ 526 self.view.hud.addAction(unicode(\
523 "Please put only ingredients for the beer in the pot.\ 527 "Please put only ingredients for the beer in the pot.\
524 Things like bottles and wood have to be in your inventory")) 528 Things like bottles and wood have to be in your inventory"))
525 return 529 return
526 wood = player_character.hasItem("Wood") 530 wood = container.get_item(player_character, "Wood")
527 if wood: 531 if wood:
528 has_wood = True 532 has_wood = True
529 bottle = player_character.hasItem("Empty beer bottle") 533 bottle = container.get_item(player_character, "Empty beer bottle")
530 if bottle: 534 if bottle:
531 has_bottle = True 535 has_bottle = True
532 if has_water and has_fruit and has_wood and has_bottle: 536 if has_water and has_fruit and has_wood and has_bottle:
533 self.pot.removeItem(water) 537 container.remove_item(self.pot, water.slot)
534 self.pot.removeItem(fruit) 538 container.remove_item(self.pot, fruit.slot)
535 if has_yeast: 539 if has_yeast:
536 self.pot.removeItem(yeast) 540 container.remove_item(self.pot, yeast.slot)
537 player_character.inventory.removeItem(wood) 541 container.remove_item(player_character, wood.slot)
538 inst_dict = {} 542 new_item = (self.model.createItemByType("Beer", "Beer",
539 inst_dict["ID"] = "Beer" 543 self.pot.entity.world)
540 inst_dict["object_type"] = "Beer" 544 )
541 new_item = self.model.createContainerObject(inst_dict) 545 container.put_item(player_character, new_item.containable)
542 player_character.inventory.placeItem(new_item) 546 self.view.hud.inventory.updateImages()
543 self.view.hud.inventory.updateInventoryButtons()
544 beer_quality = 0 547 beer_quality = 0
545 if water_type == 1: 548 if water_type == 1:
546 if fruit_type == 1: 549 if fruit_type == 1:
547 beer_quality = -1 550 beer_quality = -1
548 elif fruit_type == 2: 551 elif fruit_type == 2: