Poodletooth-iLand/toontown/coderedemption/TTCodeRedemptionMgrAI.py

107 lines
3.6 KiB
Python
Raw Normal View History

2015-03-03 22:10:12 +00:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
from toontown.catalog import CatalogAccessoryItem
2015-04-20 14:29:11 +00:00
from toontown.catalog import CatalogClothingItem
from toontown.catalog import CatalogNametagItem
from toontown.catalog import CatalogChatItem
from toontown.catalog import CatalogEmoteItem
from toontown.catalog import CatalogGardenItem
from toontown.catalog import CatalogGardenStarterItem
from toontown.catalog import CatalogMouldingItem
from toontown.catalog import CatalogRentalItem
from toontown.catalog import CatalogFurnitureItem
from toontown.catalog import CatalogAnimatedFurnitureItem
from toontown.catalog import CatalogFlooringItem
from toontown.catalog import CatalogPetTrickItem
from toontown.catalog import CatalogWainscotingItem
from toontown.catalog import CatalogToonStatueItem
from toontown.catalog import CatalogWallpaperItem
from toontown.catalog import CatalogWindowItem
2015-04-20 14:29:11 +00:00
from toontown.toonbase import ToontownGlobals
from datetime import datetime, timedelta
2015-04-20 14:29:11 +00:00
import time
2015-03-03 22:10:12 +00:00
"""
Code example:
'codeName': {
'items': [
CatalogTypeItem.CatalogTypeItem(arguments)
]
'expirationDate': datetime(2020, 1, 30),
'month': 1,
'day': 30
}
Expiration date, month and day are optional fields.
"""
2015-03-03 22:10:12 +00:00
class TTCodeRedemptionMgrAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("TTCodeRedemptionMgrAI")
2015-04-20 14:29:11 +00:00
codes = {
'weed': {
2015-03-06 22:19:39 +00:00
'items': [
CatalogClothingItem.CatalogClothingItem(1821, 0)
2015-03-07 08:32:15 +00:00
],
'month': 4,
'day': 20
2015-03-07 21:46:24 +00:00
},
'gardening': {
'items': [
CatalogGardenStarterItem.CatalogGardenStarterItem()
]
2015-04-20 14:29:11 +00:00
}
}
2015-03-03 22:10:12 +00:00
2015-04-20 14:29:11 +00:00
def announceGenerate(self):
DistributedObjectAI.announceGenerate(self)
2015-03-03 22:10:12 +00:00
def getMailboxCount(self, items):
2015-03-06 22:19:39 +00:00
count = 0
for item in items:
2015-03-07 08:10:27 +00:00
if item.getDeliveryTime() > 0:
2015-03-06 22:19:39 +00:00
count += 1
return count
2015-04-20 14:29:11 +00:00
def redeemCode(self, context, code):
avId = self.air.getAvatarIdFromSender()
2015-03-06 22:19:39 +00:00
av = self.air.doId2do.get(avId)
if not av:
return
2015-03-03 22:10:12 +00:00
2015-04-20 14:29:11 +00:00
if code in self.codes:
2015-03-06 22:19:39 +00:00
if av.isCodeRedeemed(code):
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 2])
2015-03-06 22:19:39 +00:00
return
2015-04-20 14:29:11 +00:00
codeInfo = self.codes[code]
date = datetime.now()
2015-03-03 22:10:12 +00:00
if ('month' in codeInfo and date.month is not codeInfo['month']) or ('day' in codeInfo and date.day is not codeInfo['day']) or ('expirationDate' in codeInfo and codeInfo['expirationDate'] - date < timedelta(hours = 1)):
2015-04-20 14:29:11 +00:00
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 2, 0])
return
2015-03-03 22:10:12 +00:00
2015-03-06 22:19:39 +00:00
av.redeemCode(code)
self.requestCodeRedeem(context, avId, av, codeInfo['items'])
2015-04-20 14:29:11 +00:00
else:
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 1, 0])
2015-03-06 22:19:39 +00:00
def requestCodeRedeem(self, context, avId, av, items):
count = self.getMailboxCount(items)
2015-04-20 14:29:11 +00:00
2015-03-06 22:19:39 +00:00
if len(av.onOrder) + count > 5 or len(av.mailboxContents) + len(av.onOrder) + count >= ToontownGlobals.MaxMailboxContents:
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 1])
2015-04-20 14:29:11 +00:00
return
2015-03-06 22:19:39 +00:00
for item in items:
2015-03-07 12:57:43 +00:00
if item in av.onOrder:
continue
2015-03-06 22:19:39 +00:00
item.deliveryDate = int(time.time() / 60) + 0.01
av.onOrder.append(item)
2015-04-20 14:29:11 +00:00
av.b_setDeliverySchedule(av.onOrder)
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 0, 0])