Poodletooth-iLand/toontown/coderedemption/TTCodeRedemptionMgrAI.py

120 lines
4.6 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
from toontown.catalog import CatalogAccessoryItem
2015-04-20 09:29:11 -05: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 09:29:11 -05:00
from toontown.toonbase import ToontownGlobals
from datetime import datetime, timedelta
2015-04-20 09:29:11 -05:00
import time
2015-03-03 16:10:12 -06:00
"""
Code example:
'codeName': {
'items': [
CatalogTypeItem.CatalogTypeItem(arguments)
2015-03-13 14:00:22 -05:00
],
'expirationDate': datetime(2020, 1, 30),
'month': 1,
'day': 30,
'year': 2000'
}
Expiration date, month, day and year are optional fields.
2015-03-13 14:00:22 -05:00
If you for some reason are not familiar with arrays or lists, you
only include the comma if there are multiple arguments.
"""
2015-04-28 02:07:50 -05:00
2015-03-03 16:10:12 -06:00
class TTCodeRedemptionMgrAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("TTCodeRedemptionMgrAI")
2015-04-20 09:29:11 -05:00
codes = {
2015-03-07 15:46:24 -06:00
'gardening': {
'items': [
CatalogGardenStarterItem.CatalogGardenStarterItem()
2015-03-13 13:43:49 -05:00
]
},
'sillymeter': {
'items': [
CatalogClothingItem.CatalogClothingItem(1753, 0)
]
2015-05-24 18:23:54 -05:00
},
'toonstatue': {
'items': [
CatalogToonStatueItem.CatalogToonStatueItem(105, endPoseIndex=108)
]
},
'donaldstatue': {
'items': [
CatalogGardenItem.CatalogGardenItem(100, 1)
]
2015-03-13 13:43:49 -05:00
}
2015-04-20 09:29:11 -05:00
}
2015-03-03 16:10:12 -06:00
2015-04-20 09:29:11 -05:00
def announceGenerate(self):
DistributedObjectAI.announceGenerate(self)
2015-03-03 16:10:12 -06:00
2015-04-04 05:29:27 -05:00
def redeemCode(self, code):
2015-04-20 09:29:11 -05:00
avId = self.air.getAvatarIdFromSender()
2015-03-06 16:19:39 -06:00
av = self.air.doId2do.get(avId)
if not av:
return
2015-03-03 16:10:12 -06:00
code = code.lower()
2015-04-20 09:29:11 -05:00
if code in self.codes:
2015-03-06 16:19:39 -06:00
if av.isCodeRedeemed(code):
2015-04-04 05:29:27 -05:00
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [4])
self.air.writeServerEvent('suspicious', avId, 'Toon tried to redeem already redeemed code %s' % code)
2015-03-06 16:19:39 -06:00
return
2015-04-20 09:29:11 -05:00
codeInfo = self.codes[code]
date = datetime.now()
2015-03-03 16:10:12 -06:00
if ('year' in codeInfo and date.year is not codeInfo['year']) and date.year > codeInfo['year'] or ('expirationDate' in codeInfo and codeInfo['expirationDate'] - date < timedelta(hours = 1)):
2015-04-04 05:29:27 -05:00
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [2])
self.air.writeServerEvent('suspicious', avId, 'Toon attempted to redeem code %s but it was expired!' % code)
2015-04-20 09:29:11 -05:00
return
elif ('year' in codeInfo and date.year is not codeInfo['year']) and date.year < codeInfo['year'] or ('month' in codeInfo and date.month is not codeInfo['month']) or ('day' in codeInfo and date.day is not codeInfo['day']):
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [5])
self.air.writeServerEvent('suspicious', avId, "Toon attempted to redeem code %s but it wasn't usable yet!" % code)
return
2015-05-11 02:12:24 -05:00
2015-03-06 16:19:39 -06:00
av.redeemCode(code)
2015-04-04 05:29:27 -05:00
self.requestCodeRedeem(avId, av, codeInfo['items'])
self.air.writeServerEvent('code-redeemed', avId, 'Toon successfully redeemed %s' % code)
2015-04-20 09:29:11 -05:00
else:
2015-04-04 05:29:27 -05:00
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [1])
self.air.writeServerEvent('suspicious', avId, 'Toon tried to redeem non-existent code %s' % code)
2015-04-28 02:07:50 -05:00
2015-04-04 05:29:27 -05:00
def requestCodeRedeem(self, avId, av, items):
2015-07-17 07:29:08 -05:00
if len(av.mailboxContents) + len(av.onOrder) + len(av.onGiftOrder) + len(items) >= ToontownGlobals.MaxMailboxContents:
2015-04-04 05:29:27 -05:00
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [3])
2015-04-20 09:29:11 -05:00
return
2015-03-06 16:19:39 -06:00
for item in items:
2015-03-07 06:57:43 -06:00
if item in av.onOrder:
continue
2015-04-28 02:07:50 -05:00
2015-03-06 16:19:39 -06:00
item.deliveryDate = int(time.time() / 60) + 0.01
av.onOrder.append(item)
2015-04-20 09:29:11 -05:00
av.b_setDeliverySchedule(av.onOrder)
2015-04-04 05:29:27 -05:00
self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [0])
self.air.writeServerEvent('code-redeemed', avId, 'Toon is being sent %s from redeemed code' % items)