Debian Codegraph @

python/items/deposit_box.py

raw
1 import CFBank
2 import Crossfire
3
4 activator = Crossfire.WhoIsActivator()
5 whoami = Crossfire.WhoAmI()
6
7 def get_inventory(obj):
8 """An iterator for a given object's inventory."""
9 current_item = obj.Inventory
10 while current_item != None:
11 next_item = current_item.Below
12 yield current_item
13 current_item = next_item
14
15 def deposit_box_close():
16 """Find the total value of items in the deposit box and deposit."""
17 total_value = 0
18 for obj in get_inventory(whoami):
19 if obj.Name != 'event_close':
20 total_value += obj.Value * obj.Quantity
21 obj.Remove()
22 with CFBank.open() as bank:
23 bank.deposit(activator.Name, total_value)
24 whoami.Say("%s credited to your account." \
25 % Crossfire.CostStringFromValue(total_value))
26
27 deposit_box_close()