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  character.Write("{} gives you {}".format(speaker.Name, Crossfire.CostStringFromValue(quantity)))
23 else:
24  # what we will do, is increase the number of items the NPC is holding, then
25  # split the stack into the players inventory.
26  # first we will check if there is an NPC_Gift_Box, and look in there.
27  lookin = speaker.CheckInventory("NPC_Gift_Box")
28  if lookin:
29  inv = lookin.CheckInventory(itemname)
30  if not inv:
31  # ok, the NPC has no 'Gift Box', we'll check the other items.
32  inv = speaker.CheckInventory(itemname)
33  else:
34  inv = speaker.CheckInventory(itemname)
35 
36  if inv:
37  if contents:
38  nextob=inv.Inventory
39  while nextob:
40  # when giving the contents of a container, always give the
41  # number of items in the container, not the quantity number.
42  quantity = nextob.Quantity
43  if quantity == 0:
44  # if quantity is 0, then we need to set it to one, otherwise bad things happen.
45  nextob.Quantity = 1
46  quantity = 1
47  newob = nextob.Clone(0)
48  newob.Quantity = quantity
49  character.Write("{} gives you {} {}".format(speaker.Name, quantity, newob.Name))
50  newob.InsertInto(character)
51  nextob=nextob.Below
52  else:
53  if quantity == 0:
54  nextob.Quantity = 2
55  quantity = 1
56  else:
57  CFItemBroker.Item(inv).add(quantity+1)
58  newob = inv.Split(quantity)
59 
60  character.Write("{} gives you {} {}".format(speaker.Name, quantity, newob.Name))
61  newob.InsertInto(character)
62  else:
63  # ok, we didn't find any
64  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:32