1 |
root |
1.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 |
|
|
|
21 |
|
|
def add(self, number): |
22 |
|
|
tmp = (self.numberof + number)-1 |
23 |
|
|
self.object.Quantity=tmp |
24 |
|
|
return 1 |
25 |
|
|
|
26 |
|
|
def subtract(self, number): |
27 |
|
|
remainder = self.numberof - number |
28 |
|
|
if remainder >= number: |
29 |
|
|
self.object.Quantity=remainder |
30 |
|
|
return 1 |
31 |
|
|
elif remainder == 0: |
32 |
|
|
self.object.Remove() |
33 |
|
|
return 1 |
34 |
|
|
else: |
35 |
|
|
return 0 |