+ # get and interact with objects and characters if present in a particular row/col
+ def level_interact (self, level, row, col):
+ objs = []
+ # get list of objects at current location
+ for obj in level.objects:
+ if obj.row == row and obj.col == col:
+ objs.append (obj)
+
+ notblock = self.interact_objects (level, objs)
+
+ return notblock
+
+
+ # interaction with objects
+ def interact_objects (self, container, objs):
+ # overall flag for blocking/non-blocking objects
+ notblock = True
+
+ # now perform interaction
+ for obj in objs:
+ # run the object interact function
+ if obj.interact () is False:
+ notblock = False
+ # if object can be picked up ask
+ if obj.can_pickup is True:
+ ans = utility.ask_question (self.screen, "Found %s." % obj.text, ["Pick up", "Use", "Ignore"], self.img_menu)
+ # if the answer is "pick up"
+ if ans == 1:
+ self.pickup_object (container, obj)
+ elif ans == 2:
+ # use the object according to its type
+ self.use_object (container, obj)
+ # if it cannot be picked up, try to use it anyway
+ else:
+ ans = utility.ask_question (self.screen, "Found %s." % obj.text, ["Use", "Ignore"], self.img_menu)
+ if ans == 1:
+ self.use_object (container, obj)
+
+ return notblock
+
+ # picking up an object
+ def pickup_object (self, container, obj):
+ # only if object can be picked up, pick it up or use it
+ if obj.can_pickup is True:
+ # check if the inventory is full
+ if len (self.butaba.objects) >= butaba.Butaba.MAXITEMS:
+ self.status_message = "Cannot pick up item. Inventory full"
+ else:
+ # add item to inventory
+ self.butaba.objects.append (obj)
+ # remove from container
+ container.objects.remove (obj)
+
+ self.status_message = "You picked up %s" % obj.text
+
+ # this method uses the object first by calling the object use () method
+ # and then performing specific actions as necessary
+ def use_object (self, container, obj):
+ # if the object is a health potion
+ if isinstance (obj, gameobjects.HealthPotion) is True:
+ if self.butaba.health < butaba.Butaba.MAXHEALTH:
+ obj.use (self.butaba)
+ container.objects.remove (obj)
+ self.status_message = "You gained health"
+ else:
+ self.status_message = "You already have maximum health!"
+ # if the object is a chest
+ elif isinstance (obj, gameobjects.Chest) is True:
+ # if chest is locked, try to open it
+ if obj.locked is True:
+ # try opening the chest with every item 9the use () function
+ # of the chest determines if item is a key anyway
+ fittedkey = None
+ for invobj in self.butaba.objects:
+ fittedkey = obj.use (invobj)
+ # if a key fits
+ if fittedkey is not None:
+ break
+ # if no key found
+ if fittedkey is None:
+ self.status_message = "No key found to open %s" % obj.text
+ # chest successfully unlocked
+ else:
+ self.status_message = "You unlocked the %s" % obj.text
+ # remove the key from Butaba
+ self.butaba.objects.remove (fittedkey)
+ # add an experience point for unlocking chest subject
+ # to a limit of KNOWLEDGEMAX_CHEST_UNLOCK
+ if self.butaba.experience < constants.KNOWLEDGEMAX_CHEST_UNLOCK:
+ self.butaba.experience += 1
+ self.status_message += " and gained experience!"
+ # display the contents of the chest
+ else:
+ item = utility.get_container_object (self.screen, obj, self.img_chestbg, 30)
+ if item is not None:
+ self.interact_objects (obj, [ item, ])
+
+ # if the object is gold coins
+ elif isinstance (obj, gameobjects.GoldCoins) is True:
+ obj.use (self.butaba)
+ self.status_message = "You picked up %d gold." % obj.value
+ # remove the gold coins after adding it to Butaba's gold
+ container.objects.remove (obj)
+