Crossfire Server, Trunk
CFItemBroker.py
Go to the documentation of this file.
1
#CFItemBroker.py
2
#An often used bit of code to add or remove a number of objects
3
#Useful for removing items (like in payment or as part of
4
#an inventory check) This is also useful for setting the number
5
#of a newly created item(s) as it will check for existing item(s) and add
6
#the appropriate number of new items avoiding such silliness as the
7
#number of the existing items being reset.
8
#This will not check for the existence of an item as that would better
9
#be done in the calling script so you can be flexible.
10
#
11
#ToddMitchell
12
13
import
Crossfire
14
15
class
Item
:
16
17
def
__init__
(self, object):
18
self.
object
= object
19
self.
numberof
= self.
object
.Quantity
20
# 0 for non merging items
21
if
self.
numberof
== 0:
22
self.
numberof
= 1
23
24
def
add
(self, number):
25
tmp = (self.
numberof
+ number)-1
26
self.
object
.Quantity=tmp
27
return
1
28
29
def
subtract
(self, number):
30
remainder = self.
numberof
- number
31
if
remainder >= number:
32
self.
object
.Quantity=remainder
33
return
1
34
elif
remainder == 0:
35
self.
object
.Remove()
36
return
1
37
else
:
38
return
0
39
40
def
quantity
(self):
41
return
self.
numberof
CFItemBroker.Item.__init__
def __init__(self, object)
Definition:
CFItemBroker.py:17
CFItemBroker.Item.object
object
Definition:
CFItemBroker.py:18
CFItemBroker.Item.subtract
def subtract(self, number)
Definition:
CFItemBroker.py:29
CFItemBroker.Item
Definition:
CFItemBroker.py:15
CFItemBroker.Item.add
def add(self, number)
Definition:
CFItemBroker.py:24
CFItemBroker.Item.numberof
numberof
Definition:
CFItemBroker.py:19
CFItemBroker.Item.quantity
def quantity(self)
Definition:
CFItemBroker.py:40
crossfire-crossfire-maps
python
CFItemBroker.py
Generated by
1.8.17