From e9ffbadbd60399b21e24b50e7fadb43057ee5907 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 20 Apr 2015 02:58:09 +0300 Subject: [PATCH] Upgrade the code redemption system - you can't use the same code twice anymore and expiration dates are added. --- astron/dclass/toon.dc | 1 + otp/distributed/DCClassImports.py | 2 +- .../coderedemption/TTCodeRedemptionMgrAI.py | 35 ++++++++++++------- toontown/shtiker/OptionsPage.py | 4 --- toontown/toon/DistributedToon.py | 4 +++ toontown/toon/DistributedToonAI.py | 34 +++++++++++------- toontown/toon/DistributedToonUD.py | 3 ++ toontown/toonbase/TTLocalizerEnglish.py | 2 -- 8 files changed, 52 insertions(+), 33 deletions(-) diff --git a/astron/dclass/toon.dc b/astron/dclass/toon.dc index fdae39f7..cc06c1ee 100644 --- a/astron/dclass/toon.dc +++ b/astron/dclass/toon.dc @@ -626,6 +626,7 @@ dclass DistributedToon : DistributedPlayer { flagAv(uint32, uint16, string []) airecv ownsend; setAnimalSound(uint8 index) ram broadcast ownrecv; setBuffs(uint32[] = []) required ownrecv db; + setRedeemedCodes(string [] = []) required ownrecv db; }; dclass DistributedCCharBase : DistributedObject { diff --git a/otp/distributed/DCClassImports.py b/otp/distributed/DCClassImports.py index b2b16c96..7b063f86 100644 --- a/otp/distributed/DCClassImports.py +++ b/otp/distributed/DCClassImports.py @@ -2,7 +2,7 @@ from pandac.PandaModules import * -hashVal = 1907452799 +hashVal = 1165841663 from toontown.coghq import DistributedCashbotBossSafe, DistributedCashbotBossCrane, DistributedBattleFactory, DistributedCashbotBossTreasure, DistributedCogHQDoor, DistributedSellbotHQDoor, DistributedFactoryElevatorExt, DistributedMintElevatorExt, DistributedLawOfficeElevatorExt, DistributedLawOfficeElevatorInt, LobbyManager, DistributedMegaCorp, DistributedFactory, DistributedLawOffice, DistributedLawOfficeFloor, DistributedLift, DistributedDoorEntity, DistributedSwitch, DistributedButton, DistributedTrigger, DistributedCrushableEntity, DistributedCrusherEntity, DistributedStomper, DistributedStomperPair, DistributedLaserField, DistributedGolfGreenGame, DistributedSecurityCamera, DistributedMover, DistributedElevatorMarker, DistributedBarrelBase, DistributedGagBarrel, DistributedBeanBarrel, DistributedHealBarrel, DistributedGrid, ActiveCell, DirectionalCell, CrusherCell, DistributedCrate, DistributedSinkingPlatform, BattleBlocker, DistributedMint, DistributedMintRoom, DistributedMintBattle, DistributedStage, DistributedStageRoom, DistributedStageBattle, DistributedLawbotBossGavel, DistributedLawbotCannon, DistributedLawbotChair, DistributedCogKart, DistributedCountryClub, DistributedCountryClubRoom, DistributedMoleField, DistributedCountryClubBattle, DistributedMaze, DistributedFoodBelt, DistributedBanquetTable, DistributedGolfSpot diff --git a/toontown/coderedemption/TTCodeRedemptionMgrAI.py b/toontown/coderedemption/TTCodeRedemptionMgrAI.py index 691c3248..b4303199 100644 --- a/toontown/coderedemption/TTCodeRedemptionMgrAI.py +++ b/toontown/coderedemption/TTCodeRedemptionMgrAI.py @@ -2,9 +2,23 @@ from direct.directnotify import DirectNotifyGlobal from direct.distributed.DistributedObjectAI import DistributedObjectAI from toontown.catalog import CatalogClothingItem from toontown.toonbase import ToontownGlobals -from datetime import datetime +from datetime import datetime, timedelta import time +""" +Code example: + +'codeName': { + 'items': [ + CatalogTypeItem.CatalogTypeItem(arguments) + ] + 'expirationDate': datetime(2020, 1, 30), + 'month': 1, + 'day': 30 +} + +Expiration date, month and day are optional fields. +""" class TTCodeRedemptionMgrAI(DistributedObjectAI): notify = DirectNotifyGlobal.directNotify.newCategory("TTCodeRedemptionMgrAI") codes = { @@ -20,7 +34,7 @@ class TTCodeRedemptionMgrAI(DistributedObjectAI): def announceGenerate(self): DistributedObjectAI.announceGenerate(self) - def getMailboxCount(items): + def getMailboxCount(self, items): count = 0 for item in items: @@ -38,13 +52,13 @@ class TTCodeRedemptionMgrAI(DistributedObjectAI): if code in self.codes: if av.isCodeRedeemed(code): - self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 4]) + self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 2]) return codeInfo = self.codes[code] date = datetime.now() - if ('month' in codeInfo and date.month is not codeInfo['month']) or ('day' in codeInfo and date.day is not codeInfo['day']): + 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)): self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 2, 0]) return @@ -54,21 +68,16 @@ class TTCodeRedemptionMgrAI(DistributedObjectAI): self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 1, 0]) def requestCodeRedeem(self, context, avId, av, items): - if item in av.onOrder: - self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 2]) - return - - if item.reachedPurchaseLimit(av): - self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 3]) - return - - count = getMailboxCount(items) + count = self.getMailboxCount(items) if len(av.onOrder) + count > 5 or len(av.mailboxContents) + len(av.onOrder) + count >= ToontownGlobals.MaxMailboxContents: self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 1]) return for item in items: + if item in av.onOrder or item.reachedPurchaseLimit: + continue + item.deliveryDate = int(time.time() / 60) + 0.01 av.onOrder.append(item) diff --git a/toontown/shtiker/OptionsPage.py b/toontown/shtiker/OptionsPage.py index 22eafc85..79bff0eb 100644 --- a/toontown/shtiker/OptionsPage.py +++ b/toontown/shtiker/OptionsPage.py @@ -657,10 +657,6 @@ class CodesTabPage(DirectFrame): if awardMgrResult == 1: self.resultPanel['text'] = TTLocalizer.CdrResultMailboxFull elif awardMgrResult == 2: - self.resultPanel['text'] = TTLocalizer.CdrResultAlreadyInMailbox - elif awardMgrResult == 3: - self.resultPanel['text'] = TTLocalizer.CdrResultReachedLimit - elif awardMgrResult == 4: self.resultPanel['text'] = TTLocalizer.CdrResultAlreadyRedeemed if result == 0: self.successSfx.play() diff --git a/toontown/toon/DistributedToon.py b/toontown/toon/DistributedToon.py index ce313e32..baa9ebe7 100644 --- a/toontown/toon/DistributedToon.py +++ b/toontown/toon/DistributedToon.py @@ -185,6 +185,7 @@ class DistributedToon(DistributedPlayer.DistributedPlayer, Toon.Toon, Distribute self.canEarnAchievements = False self.promotionStatus = [0, 0, 0, 0] self.buffs = [] + self.redeemedCodes = [] def disable(self): for soundSequence in self.soundSequenceList: @@ -2635,6 +2636,9 @@ class DistributedToon(DistributedPlayer.DistributedPlayer, Toon.Toon, Distribute self.buffs = buffs self.applyBuffs() + def setRedeemedCodes(self, redeemedCodes): + self.redeemedCodes = redeemedCodes + def applyBuffs(self): for id, timestamp in enumerate(self.buffs): if id == ToontownGlobals.BMovementSpeed: diff --git a/toontown/toon/DistributedToonAI.py b/toontown/toon/DistributedToonAI.py index a8fcdb8f..50a68957 100644 --- a/toontown/toon/DistributedToonAI.py +++ b/toontown/toon/DistributedToonAI.py @@ -566,19 +566,6 @@ class DistributedToonAI(DistributedPlayerAI.DistributedPlayerAI, DistributedSmoo def getMaxNPCFriends(self): return self.maxNPCFriends - def b_setRedeemedCodes(self, redeemedCodes): - self.redeemedCodes = redeemedCodes - - def getRedeemedCodes(self, redeemedCodes): - return self.redeemedCodes - - def isCodeRedeemed(self, code): - return code in self.redeemedCodes - - def redeemCode(self, code): - if not isCodeReedemed(code): - self.redeemedCodes.append(code) - def getBattleId(self): if self.battleId >= 0: return self.battleId @@ -4292,6 +4279,27 @@ class DistributedToonAI(DistributedPlayerAI.DistributedPlayerAI, DistributedSmoo self.setBuffs(buffs) self.d_setBuffs(buffs) + def setRedeemedCodes(self, redeemedCodes): + self.redeemedCodes = redeemedCodes + + def d_setRedeemedCodes(self, redeemedCodes): + self.sendUpdate('setRedeemedCodes', [redeemedCodes]) + + def b_setRedeemedCodes(self, redeemedCodes): + self.setRedeemedCodes(redeemedCodes) + self.d_setRedeemedCodes(redeemedCodes) + + def getRedeemedCodes(self, redeemedCodes): + return self.redeemedCodes + + def isCodeRedeemed(self, code): + return code in self.redeemedCodes + + def redeemCode(self, code): + if not self.isCodeRedeemed(code): + self.redeemedCodes.append(code) + self.b_setRedeemedCodes(self.redeemedCodes) + @magicWord(category=CATEGORY_PROGRAMMER, types=[str, int, int]) def cheesyEffect(value, hood=0, expire=0): diff --git a/toontown/toon/DistributedToonUD.py b/toontown/toon/DistributedToonUD.py index 49a5ab82..007e1600 100644 --- a/toontown/toon/DistributedToonUD.py +++ b/toontown/toon/DistributedToonUD.py @@ -543,3 +543,6 @@ class DistributedToonUD(DistributedObjectUD): def setAchievements(self, achievements): pass + + def setRedeemedCodes(self, redeemedCodes): + pass diff --git a/toontown/toonbase/TTLocalizerEnglish.py b/toontown/toonbase/TTLocalizerEnglish.py index 86ddcd6e..6c172911 100644 --- a/toontown/toonbase/TTLocalizerEnglish.py +++ b/toontown/toonbase/TTLocalizerEnglish.py @@ -4699,8 +4699,6 @@ CdrResultSuccess = 'Congratulations! Check your mailbox to claim your item!' CdrResultInvalidCode = "You've entered an invalid code. Please check the code and try again." CdrResultExpiredCode = "We're sorry. This code has expired." CdrResultMailboxFull = 'Your mailbox is full. Please remove an item, then enter your code again.' -CdrResultAlreadyInMailbox = "You've already received this item. Check your mailbox to confirm." -CdrResultReachedLimit = "You reached your limit for today. Please try again later." CdrResultAlreadyRedeemed = "You've already redeemed this item!" TrackPageTitle = 'Gag Track Training' TrackPageShortTitle = 'Gag Training'