Debian Codegraph @

python/dialog/post/takeitem.py

raw
1 # -*- coding: utf-8 -*-
2 # takeitem.py
3 # This is one of the files that can be called by an npc_dialog,
4 # The following code runs when a dialog has a post rule of 'takeitem'
5 # The syntax is ["takeitem", "itemtotake", "quantitytotake"]
6 # "quantitytotake" is optional, if it is missing, then 1 is assumed.
7 # if it is 0, then *all* instances of the item are taken.
8 # The player must have a sufficiant quantity of the item being taken
9 # This should normally be determined by doing an "item" check in the
10 # pre-block of the rule
11 # items are matched by item name, not arch name.
12 ## DIALOGCHECK
13 ## MINARGS 1
14 ## MAXARGS 2
15 ## .*
16 ## \d+
17 ## ENDDIALOGCHECK
18
19 itemname = args[0]
20 if len(args) == 2:
21 quantity = args[1]
22 else:
23 quantity = 1
24 Crossfire.Log(Crossfire.LogDebug, "CFDialog: trying to take: %s of item %s from character %s" %(quantity, itemname, character.Name ))
25 if itemname == "money":
26 paid = character.PayAmount(int(quantity))
27 if paid == 0:
28 Crossfire.Log(Crossfire.LogError, "Tried to make player %s pay more than they had" %(character.Name))
29 else:
30 inv = character.CheckInventory(itemname)
31 if inv:
32 if quantity == 0:
33 inv.Remove()
34 else:
35 status = CFItemBroker.Item(inv).subtract(int(quantity))
36 if status == 0:
37 Crossfire.Log(Crossfire.LogError, "Dialog script tried to remove more items than available from player %s" %(character.Name))
38 # we might have been wearing an item that was taken.
39 character.Fix()
40 else:
41 Crossfire.Log(Crossfire.LogError, "Dialog script tried to remove non-existant item from player %s" %(character.Name))