Crossfire Server, Trunk
commongive.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # commongive.py
3 # This is a common block of 'give' code to handle give item and give contents.
4 
5 itemname = args[0]
6 if len(args) == 2:
7  quantity = int(args[1])
8 else:
9  quantity = 1
10 if itemname == "money":
11  # we can't guarentee that the player has any particular type of coin already
12  # so create the object first, then add 1 less than the total.
13  if quantity >= 50:
14  id = character.CreateObject('platinum coin')
15  CFItemBroker.Item(id).add(int(quantity/50))
16  if quantity % 50 > 0:
17  id = character.CreateObject('gold coin')
18  CFItemBroker.Item(id).add(int((quantity % 50)/10))
19  if quantity % 50 > 0:
20  id = character.CreateObject('silver coin')
21  CFItemBroker.Item(id).add(int(quantity % 10))
22 else:
23  # what we will do, is increase the number of items the NPC is holding, then
24  # split the stack into the players inventory.
25  # first we will check if there is an NPC_Gift_Box, and look in there.
26  lookin = speaker.CheckInventory("NPC_Gift_Box")
27  if lookin:
28  inv = lookin.CheckInventory(itemname)
29  if not inv:
30  # ok, the NPC has no 'Gift Box', we'll check the other items.
31  inv = speaker.CheckInventory(itemname)
32  else:
33  inv = speaker.CheckInventory(itemname)
34 
35  if inv:
36  if contents:
37  nextob=inv.Inventory
38  while nextob:
39  # when giving the contents of a container, always give the
40  # number of items in the container, not the quantity number.
41  quantity = nextob.Quantity
42  if quantity == 0:
43  # if quantity is 0, then we need to set it to one, otherwise bad things happen.
44  nextob.Quantity = 1
45  quantity = 1
46  newob = nextob.Clone(0)
47  newob.Quantity = quantity
48  newob.InsertInto(character)
49  nextob=nextob.Below
50  else:
51  if quantity == 0:
52  nextob.Quantity = 2
53  quantity = 1
54  else:
55  CFItemBroker.Item(inv).add(quantity+1)
56  newob = inv.Split(quantity)
57 
58  newob.InsertInto(character)
59  else:
60  # ok, we didn't find any
61  Crossfire.Log(Crossfire.LogError, "Dialog script tried to give a non-existant item to a player")
CFItemBroker.Item
Definition: CFItemBroker.py:15
make_face_from_files.int
int
Definition: make_face_from_files.py:26