File: deposit_box.py

package info (click to toggle)
crossfire-maps 1.75.0%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 275,656 kB
  • sloc: python: 7,711; sql: 92; sh: 73; makefile: 7
file content (27 lines) | stat: -rw-r--r-- 830 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import CFBank
import Crossfire

activator = Crossfire.WhoIsActivator()
whoami = Crossfire.WhoAmI()

def get_inventory(obj):
    """An iterator for a given object's inventory."""
    current_item = obj.Inventory
    while current_item != None:
        next_item = current_item.Below
        yield current_item
        current_item = next_item

def deposit_box_close():
    """Find the total value of items in the deposit box and deposit."""
    total_value = 0
    for obj in get_inventory(whoami):
        if obj.Name != 'event_close':
            total_value += obj.Value * obj.Quantity
            obj.Remove()
    with CFBank.open() as bank:
        bank.deposit(activator.Name, total_value)
        whoami.Say("%s credited to your account." \
                % Crossfire.CostStringFromValue(total_value))

deposit_box_close()