From 61705bbf209f1e0cdc36734ad2f10a468855d713 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 17 Jul 2015 14:50:16 +0300 Subject: [PATCH] Gifting update!!! --- dependencies/astron/dclass/stride.dc | 2 + otp/nametag/NametagConstants.py | 7 + toontown/catalog/CatalogAccessoryItem.py | 2 - toontown/catalog/CatalogBeanItem.py | 4 +- toontown/catalog/CatalogChatItem.py | 4 +- toontown/catalog/CatalogClothingItem.py | 2 - toontown/catalog/CatalogEmoteItem.py | 2 +- toontown/catalog/CatalogGardenItem.py | 5 - toontown/catalog/CatalogGardenStarterItem.py | 4 +- toontown/catalog/CatalogItemPanel.py | 7 +- toontown/catalog/CatalogManagerUD.py | 43 ---- toontown/catalog/CatalogNametagItem.py | 2 +- toontown/catalog/CatalogPetTrickItem.py | 2 +- toontown/catalog/CatalogRentalItem.py | 4 +- toontown/catalog/CatalogScreen.py | 174 +++++-------- toontown/estate/DistributedPhone.py | 15 +- toontown/estate/DistributedPhoneAI.py | 243 ++++++++++++------- toontown/toon/DistributedToonAI.py | 10 - toontown/toonbase/TTLocalizerEnglish.py | 8 +- toontown/uberdog/ToontownUberRepository.py | 3 - 20 files changed, 242 insertions(+), 301 deletions(-) delete mode 100644 toontown/catalog/CatalogManagerUD.py diff --git a/dependencies/astron/dclass/stride.dc b/dependencies/astron/dclass/stride.dc index e30e0294..e40ff817 100644 --- a/dependencies/astron/dclass/stride.dc +++ b/dependencies/astron/dclass/stride.dc @@ -2093,6 +2093,8 @@ dclass DistributedPhone : DistributedFurnitureItem { requestGiftPurchaseMessage(uint16, uint32, blob, int32) airecv clsend; requestGiftPurchaseResponse(uint16, int8); purchaseItemComplete(); + requestGiftAvatar(uint32) airecv clsend; + setGiftAvatar(blob); }; dclass DistributedFireworkShow : DistributedObject { diff --git a/otp/nametag/NametagConstants.py b/otp/nametag/NametagConstants.py index d0de16f3..7accb974 100644 --- a/otp/nametag/NametagConstants.py +++ b/otp/nametag/NametagConstants.py @@ -230,3 +230,10 @@ WHISPER_COLORS = { ), # TODO: WTToontownBoardingGroup } + +def getFriendColor(handle): + if handle.isAdmin(): + return CCAdmin + elif settings['trueFriends'] and base.localAvatar.isTrueFriends(handle.doId): + return CCNormal + return CCSpeedChat \ No newline at end of file diff --git a/toontown/catalog/CatalogAccessoryItem.py b/toontown/catalog/CatalogAccessoryItem.py index 8f1121c9..ec13dcc6 100755 --- a/toontown/catalog/CatalogAccessoryItem.py +++ b/toontown/catalog/CatalogAccessoryItem.py @@ -64,8 +64,6 @@ class CatalogAccessoryItem(CatalogItem.CatalogItem): return 1 if avatar.mailboxContents.count(self) != 0: return 1 - if self in avatar.awardMailboxContents or self in avatar.onAwardOrder: - return 1 str = AccessoryTypes[self.accessoryType][ATString] if self.isHat(): defn = ToonDNA.HatStyles[str] diff --git a/toontown/catalog/CatalogBeanItem.py b/toontown/catalog/CatalogBeanItem.py index b2f09b66..5ae535e7 100755 --- a/toontown/catalog/CatalogBeanItem.py +++ b/toontown/catalog/CatalogBeanItem.py @@ -16,9 +16,7 @@ class CatalogBeanItem(CatalogItem.CatalogItem): return 0 def reachedPurchaseLimit(self, avatar): - if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or self in avatar.awardMailboxContents or self in avatar.onAwardOrder: - return 1 - return 0 + return self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder def getAcceptItemErrorText(self, retcode): if retcode == ToontownGlobals.P_ItemAvailable: diff --git a/toontown/catalog/CatalogChatItem.py b/toontown/catalog/CatalogChatItem.py index 51f2e523..9e5f8ecc 100755 --- a/toontown/catalog/CatalogChatItem.py +++ b/toontown/catalog/CatalogChatItem.py @@ -15,9 +15,7 @@ class CatalogChatItem(CatalogItem.CatalogItem): return 1 def reachedPurchaseLimit(self, avatar): - if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or self in avatar.awardMailboxContents or self in avatar.onAwardOrder: - return 1 - return avatar.customMessages.count(self.customIndex) != 0 + return self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or avatar.customMessages.count(self.customIndex) != 0 def getTypeName(self): return TTLocalizer.ChatTypeName diff --git a/toontown/catalog/CatalogClothingItem.py b/toontown/catalog/CatalogClothingItem.py index 6e4eae93..c13d5362 100755 --- a/toontown/catalog/CatalogClothingItem.py +++ b/toontown/catalog/CatalogClothingItem.py @@ -338,8 +338,6 @@ class CatalogClothingItem(CatalogItem.CatalogItem): return 1 if avatar.mailboxContents.count(self) != 0: return 1 - if self in avatar.awardMailboxContents or self in avatar.onAwardOrder: - return 1 str = ClothingTypes[self.clothingType][CTString] dna = avatar.getStyle() if self.isShirt(): diff --git a/toontown/catalog/CatalogEmoteItem.py b/toontown/catalog/CatalogEmoteItem.py index 7e139110..2849a58c 100755 --- a/toontown/catalog/CatalogEmoteItem.py +++ b/toontown/catalog/CatalogEmoteItem.py @@ -17,7 +17,7 @@ class CatalogEmoteItem(CatalogItem.CatalogItem): return 1 def reachedPurchaseLimit(self, avatar): - if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or self in avatar.awardMailboxContents or self in avatar.onAwardOrder: + if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder: return 1 if self.emoteIndex >= len(avatar.emoteAccess): return 0 diff --git a/toontown/catalog/CatalogGardenItem.py b/toontown/catalog/CatalogGardenItem.py index 1d340357..eb6f731c 100755 --- a/toontown/catalog/CatalogGardenItem.py +++ b/toontown/catalog/CatalogGardenItem.py @@ -22,11 +22,6 @@ class CatalogGardenItem(CatalogItem.CatalogItem): else: return 100 - def reachedPurchaseLimit(self, avatar): - if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or self in avatar.awardMailboxContents or self in avatar.onAwardOrder: - return 1 - return 0 - def getAcceptItemErrorText(self, retcode): if retcode == ToontownGlobals.P_ItemAvailable: return TTLocalizer.CatalogAcceptGarden diff --git a/toontown/catalog/CatalogGardenStarterItem.py b/toontown/catalog/CatalogGardenStarterItem.py index 876bbafe..237642ee 100755 --- a/toontown/catalog/CatalogGardenStarterItem.py +++ b/toontown/catalog/CatalogGardenStarterItem.py @@ -16,9 +16,7 @@ class CatalogGardenStarterItem(CatalogItem.CatalogItem): return 0 def reachedPurchaseLimit(self, avatar): - if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or self in avatar.awardMailboxContents or self in avatar.onAwardOrder or hasattr(avatar, 'gardenStarted') and avatar.getGardenStarted(): - return 1 - return 0 + return self in avatar.onOrder or self in avatar.mailboxContents or hasattr(avatar, 'gardenStarted') and avatar.getGardenStarted() def saveHistory(self): return 1 diff --git a/toontown/catalog/CatalogItemPanel.py b/toontown/catalog/CatalogItemPanel.py index 3341f822..caee7b43 100755 --- a/toontown/catalog/CatalogItemPanel.py +++ b/toontown/catalog/CatalogItemPanel.py @@ -402,11 +402,10 @@ class CatalogItemPanel(DirectFrame): 'item': self['item'].getName(), 'price': self['item'].getPrice(self['type'])} else: - friendIndex = self.parentCatalogScreen.friendGiftIndex friendText = 'Error' numFriends = len(base.localAvatar.friendsList) + len(base.cr.avList) - 1 if numFriends > 0: - friendText = self.parentCatalogScreen.receiverName + friendText = self.parentCatalogScreen.friendName message = TTLocalizer.CatalogVerifyGift % {'item': self['item'].getName(), 'price': self['item'].getPrice(self['type']), 'friend': friendText} @@ -456,8 +455,8 @@ class CatalogItemPanel(DirectFrame): auxText = TTLocalizer.CatalogNotAGift self.auxText['text'] = auxText return - elif self.parentCatalogScreen.gotAvatar == 1: - avatar = self.parentCatalogScreen.giftAvatar + elif self.parentCatalogScreen.friend: + avatar = self.parentCatalogScreen.friend if self['item'].forBoysOnly() and avatar.getStyle().getGender() == 'f' or self['item'].forGirlsOnly() and avatar.getStyle().getGender() == 'm': self.giftButton.show() self.giftButton['state'] = DGG.DISABLED diff --git a/toontown/catalog/CatalogManagerUD.py b/toontown/catalog/CatalogManagerUD.py deleted file mode 100644 index d73f8571..00000000 --- a/toontown/catalog/CatalogManagerUD.py +++ /dev/null @@ -1,43 +0,0 @@ -from direct.directnotify import DirectNotifyGlobal -from direct.showbase.DirectObject import DirectObject - -from toontown.catalog import CatalogItem, CatalogItemList - -class CatalogManagerUD(DirectObject): - notify = DirectNotifyGlobal.directNotify.newCategory('CatalogManagerUD') - TIMEOUT = 15 - - def __init__(self, air): - self.air = air - - self.accept('CATALOG_addGift_AI2UD', self.__handleCatalogAddGift) - self.accept('CATALOG_addGift_UD2Toon_resp', self.__handleToonResp) - - self.__context = 0 - - def __handleCatalogAddGift(self, avId, blob): - ctx = self.__context - self.__context += 1 - self.air.sendNetEvent('CATALOG_addGift_UD2Toon_%d' % avId, [blob, ctx]) - taskMgr.doMethodLater(self.TIMEOUT, self.__doTimeout, 'catalogMgr-timeout-%d' % ctx, [blob, avId]) - - def __handleToonResp(self, avId, ctx): - self.notify.info('%d is online, gift deliver order handled by AI' % avId) - taskMgr.remove('catalogMgr-timeout-%d' % ctx) - - def __doTimeout(self, blob, avId): - self.notify.info('%d is offline, adding order to database' % avId) - self.air.dbInterface.queryObject(self.air.dbId, avId, lambda a, b: self.__handleRetrieve(a, b, avId, blob)) - - def __handleRetrieve(self, dclass, fields, avId, blob): - if dclass != self.air.dclassesByName['DistributedToonUD']: - self.notify.warning('Unable to deliver gift: avId is not a DistributedToon!') - return - - store = CatalogItem.Customization | CatalogItem.DeliveryDate - giftOnOrder = CatalogItemList.CatalogItemList(fields.get('setGiftSchedule', [''])[0], store=store) - giftOnOrder.append(CatalogItem.getItem(blob, store=store | CatalogItem.GiftTag)) - fields['setGiftSchedule'] = (giftOnOrder.getBlob(store=store),) - - self.air.dbInterface.updateObject(self.air.dbId, avId, self.air.dclassesByName['DistributedToonUD'], fields) - self.notify.info('Successfully delivered gift to %d' % avId) \ No newline at end of file diff --git a/toontown/catalog/CatalogNametagItem.py b/toontown/catalog/CatalogNametagItem.py index 2d3ffd45..f0796b66 100755 --- a/toontown/catalog/CatalogNametagItem.py +++ b/toontown/catalog/CatalogNametagItem.py @@ -17,7 +17,7 @@ class CatalogNametagItem(CatalogItem.CatalogItem): return 1 def reachedPurchaseLimit(self, avatar): - if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or self in avatar.awardMailboxContents or self in avatar.onAwardOrder: + if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder: return 1 if avatar.nametagStyle == self.nametagStyle: return 1 diff --git a/toontown/catalog/CatalogPetTrickItem.py b/toontown/catalog/CatalogPetTrickItem.py index 7932ee07..c1372855 100755 --- a/toontown/catalog/CatalogPetTrickItem.py +++ b/toontown/catalog/CatalogPetTrickItem.py @@ -17,7 +17,7 @@ class CatalogPetTrickItem(CatalogItem.CatalogItem): return 1 def reachedPurchaseLimit(self, avatar): - if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or self in avatar.awardMailboxContents or self in avatar.onAwardOrder or not hasattr(avatar, 'petTrickPhrases'): + if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or not hasattr(avatar, 'petTrickPhrases'): return 1 return self.trickId in avatar.petTrickPhrases diff --git a/toontown/catalog/CatalogRentalItem.py b/toontown/catalog/CatalogRentalItem.py index 51dd0ae2..40998d83 100755 --- a/toontown/catalog/CatalogRentalItem.py +++ b/toontown/catalog/CatalogRentalItem.py @@ -24,9 +24,7 @@ class CatalogRentalItem(CatalogItem.CatalogItem): return 0 def reachedPurchaseLimit(self, avatar): - if self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder or self in avatar.awardMailboxContents or self in avatar.onAwardOrder: - return 1 - return 0 + return self in avatar.onOrder or self in avatar.mailboxContents or self in avatar.onGiftOrder def saveHistory(self): return 1 diff --git a/toontown/catalog/CatalogScreen.py b/toontown/catalog/CatalogScreen.py index f30e9fab..5ea5e21c 100755 --- a/toontown/catalog/CatalogScreen.py +++ b/toontown/catalog/CatalogScreen.py @@ -15,7 +15,7 @@ import random from toontown.toon import DistributedToon from direct.directnotify import DirectNotifyGlobal from otp.nametag.ChatBalloon import ChatBalloon -from otp.nametag import NametagGroup +from otp.nametag import NametagGroup, NametagConstants NUM_CATALOG_ROWS = 3 NUM_CATALOG_COLS = 2 @@ -31,6 +31,7 @@ class CatalogScreen(DirectFrame): notify = DirectNotifyGlobal.directNotify.newCategory('CatalogScreen') def __init__(self, parent = aspect2d, **kw): + self.gifting = -1 guiItems = loader.loadModel('phase_5.5/models/gui/catalog_gui') background = guiItems.find('**/catalog_background') background.setBin("background", 10) @@ -44,19 +45,11 @@ class CatalogScreen(DirectFrame): ('relief', None, None)) self.defineoptions(kw, optiondefs) DirectFrame.__init__(self, parent) - self.friendGiftIndex = 0 - self.friendGiftHandle = None - self.frienddoId = None - self.receiverName = 'Error Nameless Toon' - self.friends = {} - self.family = {} - self.ffList = [] - self.textRolloverColor = Vec4(1, 1, 0, 1) - self.textDownColor = Vec4(0.5, 0.9, 1, 1) - self.textDisabledColor = Vec4(0.4, 0.8, 0.4, 1) - self.giftAvatar = None - self.gotAvatar = 0 - self.allowGetDetails = 1 + self.friend = None + self.friendAvId = None + self.friendName = 'Error Nameless Toon' + self.friendList = [] + self.friends = [] self.load(guiItems, guiButton, guiBack) self.initialiseoptions(CatalogScreen) self.enableBackorderCatalogButton() @@ -66,10 +59,8 @@ class CatalogScreen(DirectFrame): self.hide() self.clarabelleChatNP = None self.clarabelleChatBalloon = None - self.gifting = -1 self.createdGiftGui = None self.viewing = None - return def show(self): self.accept('CatalogItemPurchaseRequest', self.__handlePurchaseRequest) @@ -91,10 +82,6 @@ class CatalogScreen(DirectFrame): taskMgr.doMethodLater(1.0, clarabelleGreeting, 'clarabelleGreeting') taskMgr.doMethodLater(12.0, clarabelleHelpText1, 'clarabelleHelpText1') - if hasattr(self, 'giftToggle'): - self.giftToggle['state'] = DGG.DISABLED - self.giftToggle['text'] = TTLocalizer.CatalogGiftToggleWait - self.__handleUDack() def hide(self): self.ignore('CatalogItemPurchaseRequest') @@ -544,16 +531,15 @@ class CatalogScreen(DirectFrame): -2.0, -1.45), image_scale=(1.0, 1.0, smash), image_pos=(0.0, 0.0, -1.9 + lift), image=backDown, pressEffect=0, command=self.showEmblemItems, text=TTLocalizer.CatalogEmblem, text_font=ToontownGlobals.getSignFont(), text_pos=(1.75, 0.132), text_scale=0.065, text_fg=(0.353, 0.627, 0.627, 1.0), text2_fg=(0.353, 0.427, 0.427, 1.0)) self.emblemCatalogButton2.hide() - self.__makeFFlist() - print self.ffList - if len(self.ffList) > 0: + self.__makeFriendList() + if len(self.friendList) > 0: if config.GetBool('want-gifting', True): self.giftToggle = DirectButton(self.base, relief=None, pressEffect=0, image=(giftToggleUp, giftToggleDown, giftToggleUp), image_scale=(1.0, 1, 0.7), command=self.__giftToggle, text=TTLocalizer.CatalogGiftToggleOff, text_font=ToontownGlobals.getSignFont(), text_pos=TTLocalizer.CSgiftTogglePos, text_scale=TTLocalizer.CSgiftToggle, text_fg=(0.353, 0.627, 0.627, 1.0), text3_fg=(0.15, 0.3, 0.3, 1.0), text2_fg=(0.353, 0.427, 0.427, 1.0), image_color=Vec4(1.0, 1.0, 0.2, 1.0), image1_color=Vec4(0.9, 0.85, 0.2, 1.0), image2_color=Vec4(0.9, 0.85, 0.2, 1.0), image3_color=Vec4(0.5, 0.45, 0.2, 1.0)) self.giftToggle.setPos(0.0, 0, -0.035) self.giftLabel = DirectLabel(self.base, relief=None, image=giftFriends, image_scale=(1.15, 1, 1.14), text=' ', text_font=ToontownGlobals.getSignFont(), text_pos=(1.2, -0.97), text_scale=0.07, text_fg=(0.392, 0.549, 0.627, 1.0), sortOrder=100, textMayChange=1) self.giftLabel.setPos(-0.15, 0, 0.08) self.giftLabel.hide() - self.friendLabel = DirectLabel(self.base, relief=None, text='Friend Name', text_font=ToontownGlobals.getSignFont(), text_pos=(-0.25, 0.132), text_scale=0.068, text_align=TextNode.ALeft, text_fg=(0.992, 0.949, 0.327, 1.0), sortOrder=100, textMayChange=1) + self.friendLabel = DirectLabel(self.base, relief=None, text=TTLocalizer.CatalogGiftChoose, text_font=ToontownGlobals.getSignFont(), text_pos=(-0.25, 0.132), text_scale=0.068, text_align=TextNode.ALeft, text_fg=(0.992, 0.949, 0.327, 1.0), sortOrder=100, textMayChange=1) self.friendLabel.setPos(0.5, 0, -0.42) self.friendLabel.hide() gui = loader.loadModel('phase_3.5/models/gui/friendslist_gui') @@ -572,9 +558,6 @@ class CatalogScreen(DirectFrame): clipNP = self.scrollList.attachNewNode(clipper) self.scrollList.setClipPlane(clipNP) self.__makeScrollList() - friendId = self.ffList[0] - self.__chooseFriend(self.ffList[0][0], self.ffList[0][1]) - self.update() self.createdGiftGui = 1 for i in xrange(4): self.newCatalogButton.component('text%d' % i).setR(90) @@ -831,8 +814,6 @@ class CatalogScreen(DirectFrame): taskMgr.remove('clarabelleGreeting') taskMgr.remove('clarabelleHelpText1') taskMgr.remove('clarabelleAskAnythingElse') - if self.giftAvatar: - base.cr.cancelAvatarDetailsRequest(self.giftAvatar) self.hide() self.hangup.hide() self.destroy() @@ -864,16 +845,12 @@ class CatalogScreen(DirectFrame): del self.giftLabel del self.friendLabel del self.scrollList + del self.friend + del self.friends self.unloadClarabelle() if self.responseDialog: self.responseDialog.cleanup() self.responseDialog = None - if self.giftAvatar: - if hasattr(self.giftAvatar, 'doId'): - self.giftAvatar.delete() - else: - self.giftAvatar = None - return def unloadClarabelle(self): base.win.removeDisplayRegion(self.cDr) @@ -891,8 +868,6 @@ class CatalogScreen(DirectFrame): del self.clarabelleChatBalloon def hangUp(self): - if hasattr(self, 'giftAvatar') and self.giftAvatar: - self.giftAvatar.disable() self.setClarabelleChat(random.choice(TTLocalizer.CatalogGoodbyeList), type='goodbye') self.setPageIndex(-1) self.showPageItems() @@ -921,9 +896,8 @@ class CatalogScreen(DirectFrame): self.update() def update(self, task = None): - if not hasattr(self.giftAvatar, 'doId'): - if self.gifting == 1: - self.__giftToggle() + if (not self.friend) and self.gifting == 1: + self.__giftToggle() if hasattr(self, 'beanBank'): self.beanBank['text'] = str(base.localAvatar.getTotalMoney()) for item in self.panelList + self.backPanelList + self.specialPanelList + self.emblemPanelList: @@ -935,7 +909,7 @@ class CatalogScreen(DirectFrame): taskMgr.remove('clarabelleAskAnythingElse') def __handleGiftPurchaseRequest(self, item): - item.requestGiftPurchase(self['phone'], self.frienddoId, self.__handleGiftPurchaseResponse) + item.requestGiftPurchase(self['phone'], self.friendAvId, self.__handleGiftPurchaseResponse) taskMgr.remove('clarabelleAskAnythingElse') def __handlePurchaseResponse(self, retCode, item): @@ -954,7 +928,7 @@ class CatalogScreen(DirectFrame): return if self.isEmpty() or self.isHidden(): return - self.setClarabelleChat(item.getRequestGiftPurchaseErrorText(retCode) % self.receiverName) + self.setClarabelleChat(item.getRequestGiftPurchaseErrorText(retCode) % self.friendName) self.__loadFriend() def askAnythingElse(task): @@ -1010,85 +984,56 @@ class CatalogScreen(DirectFrame): self.silverLabel.hide() self.goldLabel.hide() - def checkFamily(self, doId): - test = 0 - for familyMember in base.cr.avList: - if familyMember.id == doId: - test = 1 - - return test - - def __makeFFlist(self): - for familyMember in base.cr.avList: - if familyMember.id != base.localAvatar.doId: - newFF = (familyMember.id, familyMember.name, NametagGroup.CCNonPlayer) - self.ffList.append(newFF) + def __makeFriendList(self): + for av in base.cr.avList: + if av.id != base.localAvatar.doId: + self.friendList.append((av.id, av.name, NametagGroup.CCNonPlayer)) for id, handle in base.cr.friendsMap.items(): if isinstance(handle, FriendHandle.FriendHandle): - self.ffList.append((id, handle.getName(), None))#NametagGlobals.getFriendColor(handle))) + self.friendList.append((id, handle.getName(), NametagConstants.getFriendColor(handle))) def __makeScrollList(self): - for ff in self.ffList: - ffbutton = self.makeFamilyButton(ff[0], ff[1], ff[2]) - if ffbutton: - self.scrollList.addItem(ffbutton, refresh=0) - self.friends[ff] = ffbutton + for friend in self.friendList: + button = self.makeFriendButton(*friend) + self.scrollList.addItem(button, refresh=0) + self.friends.append(button) self.scrollList.refresh() - def makeFamilyButton(self, familyId, familyName, colorCode): - # fg = NametagGlobals.getNameFg(colorCode, PGButton.SInactive) - return DirectButton( - relief=None, - text=familyName, - text_scale=0.04, - text_align=TextNode.ALeft, - # text_fg=fg, - text1_bg=self.textDownColor, - text2_bg=self.textRolloverColor, - text3_fg=self.textDisabledColor, - textMayChange=0, - command=self.__chooseFriend, - extraArgs=[familyId, familyName] - ) + def makeFriendButton(self, avId, name, colorCode): + color = NametagConstants.NAMETAG_COLORS[colorCode] - def __chooseFriend(self, friendId, friendName): + return DirectButton(relief=None, text=name, text_scale=0.04, text_align=TextNode.ALeft, text_fg=color[0][0], text1_bg=(1, 1, 0, 1), + text2_bg=(0.5, 0.9, 1, 1), text3_fg=(0.4, 0.8, 0.4, 1), command=self.__chooseFriend, extraArgs=[avId, name]) + + def __chooseFriend(self, avId, name): messenger.send('wakeup') - self.frienddoId = friendId - self.receiverName = friendName - self.friendLabel['text'] = TTLocalizer.CatalogGiftTo % self.receiverName + + if self.friendAvId == avId: + return + + self.friendAvId = avId + self.friendName = name self.__loadFriend() def __loadFriend(self): - if self.allowGetDetails == 0: - CatalogScreen.notify.warning('smashing requests') - if self.frienddoId and self.allowGetDetails: - if self.giftAvatar: - if hasattr(self.giftAvatar, 'doId'): - self.giftAvatar.disable() - self.giftAvatar.delete() - self.giftAvatar = None - self.giftAvatar = DistributedToon.DistributedToon(base.cr) - self.giftAvatar.doId = self.frienddoId - self.giftAvatar.forceAllowDelayDelete() - self.giftAvatar.generate() - base.cr.getAvatarDetails(self.giftAvatar, self.__handleAvatarDetails, 'DistributedToon') - self.gotAvatar = 0 - self.allowGetDetails = 0 - self.scrollList['state'] = DGG.DISABLED - return - - def __handleAvatarDetails(self, gotData, avatar, dclass): - if self.giftAvatar.doId != avatar.doId or gotData == 0: - CatalogScreen.notify.error('Get Gift Avatar Failed') - self.gotAvatar = 0 + if not self.friendAvId: return - else: - self.gotAvatar = 1 - self.giftAvatar = avatar - self.scrollList['state'] = DGG.NORMAL - self.allowGetDetails = 1 + + for friendButton in self.friends: + friendButton['state'] = DGG.DISABLED + + self.friend = None + self.friendLabel['text'] = TTLocalizer.CatalogGiftUpdating + self['phone'].requestGiftAvatar(self.friendAvId) + + def setFriendReady(self, friend): + for friendButton in self.friends: + friendButton['state'] = DGG.NORMAL + + self.friend = friend + self.friendLabel['text'] = TTLocalizer.CatalogGiftTo % self.friendName self.update() def __giftToggle(self): @@ -1102,20 +1047,13 @@ class CatalogScreen(DirectFrame): self.giftToggle['text'] = TTLocalizer.CatalogGiftToggleOn self.__loadFriend() else: + self.friend = None + self.friendAvId = 0 + self.friendName = None self.gifting = -1 self.giftLabel.hide() self.friendLabel.hide() self.scrollList.hide() self.showEmblems() self.giftToggle['text'] = TTLocalizer.CatalogGiftToggleOff - self.update() - - def __handleUDack(self, caller = None): - taskMgr.remove('ackTimeOut') - if hasattr(self, 'giftToggle') and self.giftToggle: - self.giftToggle['state'] = DGG.NORMAL - self.giftToggle['text'] = TTLocalizer.CatalogGiftToggleOff - - def __handleNoAck(self, caller = None): - if hasattr(self, 'giftToggle') and self.giftToggle: - self.giftToggle['text'] = TTLocalizer.CatalogGiftToggleNoAck \ No newline at end of file + self.update() \ No newline at end of file diff --git a/toontown/estate/DistributedPhone.py b/toontown/estate/DistributedPhone.py index c97beede..bfabe965 100755 --- a/toontown/estate/DistributedPhone.py +++ b/toontown/estate/DistributedPhone.py @@ -2,6 +2,7 @@ from toontown.toonbase import ToontownGlobals import PhoneGlobals from toontown.catalog import CatalogScreen from toontown.catalog import CatalogItem +from toontown.catalog import GiftAvatar from toontown.toontowngui import TTDialog from toontown.toonbase import TTLocalizer import DistributedHouseInterior @@ -13,7 +14,6 @@ from direct.showutil import Rope from direct.directnotify.DirectNotifyGlobal import * from panda3d.core import * from direct.interval.IntervalGlobal import * -import string from toontown.quest import Quests from direct.task import Task @@ -274,7 +274,6 @@ class DistributedPhone(DistributedFurnitureItem.DistributedFurnitureItem): self.sendUpdate('requestPurchaseMessage', [context, blob, optional]) def requestGiftPurchase(self, item, targetDoID, callback, optional = -1): - print 'in the client phone' blob = item.getBlob(store=CatalogItem.Customization) context = self.getCallbackContext(callback, [item]) self.sendUpdate('requestGiftPurchaseMessage', [context, targetDoID, blob, optional]) @@ -382,3 +381,15 @@ class DistributedPhone(DistributedFurnitureItem.DistributedFurnitureItem): ringIval = Parallel(Func(base.playSfx, self.ringSfx), shakeSeq, Func(phone.setR, 0)) self.playInterval(ringIval, 0.0, None) return + + def requestGiftAvatar(self, doId): + if not self.phoneGui: + return + + self.sendUpdate('requestGiftAvatar', [doId]) + + def setGiftAvatar(self, fields): + if not self.phoneGui: + return + + self.phoneGui.setFriendReady(GiftAvatar.createFromJson(fields)) \ No newline at end of file diff --git a/toontown/estate/DistributedPhoneAI.py b/toontown/estate/DistributedPhoneAI.py index 0df7c825..38e80db8 100755 --- a/toontown/estate/DistributedPhoneAI.py +++ b/toontown/estate/DistributedPhoneAI.py @@ -4,20 +4,53 @@ from toontown.estate.DistributedFurnitureItemAI import DistributedFurnitureItemA from PhoneGlobals import * from toontown.toonbase import ToontownGlobals -from toontown.catalog import CatalogItem, CatalogInvalidItem +from toontown.catalog import CatalogItem, CatalogInvalidItem, GiftAvatar from toontown.catalog.CatalogItemList import CatalogItemList from toontown.uberdog import TopToonsGlobals +import base64 +import json import time MAX_MAILBOX = 10 MAX_ON_ORDER = 10 +class LoadGiftAvatar: + + def __init__(self, phone, avId, targetId, optional, callback): + self.air = phone.air + self.phone = phone + self.avId = avId + self.targetId = targetId + self.optional = optional + self.callback = callback + + def start(self): + self.air.dbInterface.queryObject(self.air.dbId, self.targetId, self.__gotAvatar) + + def copyDict(self, dict, *keys): + return {key: dict[key] for key in keys} + + def __gotAvatar(self, dclass, fields): + if dclass != self.air.dclassesByName['DistributedToonAI']: + return + + for key in ('setDNAString', 'setMailboxContents', 'setGiftSchedule', 'setDeliverySchedule'): + fields[key] = base64.b64encode(fields[key][0]) + + newDict = self.copyDict(fields, 'setDNAString', 'setMailboxContents', 'setGiftSchedule', 'setDeliverySchedule', 'setHat', 'setGlasses', 'setBackpack', + 'setShoes', 'setHatList', 'setGlassesList', 'setBackpackList', 'setShoes', 'setShoesList', 'setCustomMessages', 'setEmoteAccess', + 'setClothesTopsList', 'setClothesBottomsList', 'setPetTrickPhrases') + + self.callback(self.avId, self.targetId, newDict, self.optional) + del self.phone.fsms[self.avId] + class DistributedPhoneAI(DistributedFurnitureItemAI): notify = DirectNotifyGlobal.directNotify.newCategory("DistributedPhoneAI") def __init__(self, air, furnitureMgr, catalogItem): DistributedFurnitureItemAI.__init__(self, air, furnitureMgr, catalogItem) + self.fsms = {} self.initialScale = (0.8, 0.8, 0.8) self.inUse = False self.currAvId = 0 @@ -100,111 +133,135 @@ class DistributedPhoneAI(DistributedFurnitureItemAI): return return av + + def checkPurchaseLimit(self, recipient, item): + if len(recipient.onOrder) >= MAX_ON_ORDER: + return ToontownGlobals.P_ReachedPurchaseLimit + elif len(recipient.mailboxContents) >= MAX_MAILBOX: + return ToontownGlobals.P_MailboxFull + elif item.reachedPurchaseLimit(recipient): + return ToontownGlobals.P_ReachedPurchaseLimit - def attemptPurchase(self, avBuying, recepient, blob, optional, payMethod, gifting=False): - avId = avBuying.doId - + return ToontownGlobals.P_ItemOnOrder + + def chargeAvatar(self, av, money, emblems): + av.takeMoney(money) + av.subtractEmblems(emblems) + + def attemptPurchase(self, context, av, blob, optional, gifting=False): + avId = av.doId item = CatalogItem.getItem(blob, CatalogItem.Customization) + if isinstance(item, CatalogInvalidItem.CatalogInvalidItem): self.air.writeServerEvent('suspicious', avId, 'tried purchasing invalid item') self.notify.warning('%d tried purchasing invalid item' % avId) return ToontownGlobals.P_NotInCatalog - - if item in avBuying.backCatalog: - priceType = CatalogItem.CatalogTypeBackorder - - elif item in avBuying.weeklyCatalog or item in avBuying.monthlyCatalog: - priceType = 0 - - elif item.__class__.__name__ == "CatalogHouseItem": - priceType = 0 - - else: + elif (not item.hasEmblemPrices()) and item not in av.backCatalog and item not in av.weeklyCatalog and item not in av.monthlyCatalog: self.air.writeServerEvent('suspicious', avId, 'tried purchasing non-existing item') self.notify.warning('%d tried purchasing non-existing item' % avId) return ToontownGlobals.P_NotInCatalog - - def _getEmblemPrices(): - if config.GetBool('catalog-emblems-OR', False): - ep = list(item.getEmblemPrices()) - if len(ep) != 2: - return [] - - if all(ep): - ep[payMethod] = 0 - - else: - ep = item.getEmblemPrices() - - return ep - - def charge(): - ep = _getEmblemPrices() - if ep: - avBuying.subtractEmblems(ep) - - avBuying.takeMoney(item.getPrice(priceType)) - - if not gifting and item.reachedPurchaseLimit(recepient): - retcode = ToontownGlobals.P_ReachedPurchaseLimit - - elif not gifting and len(recepient.onOrder) >= MAX_ON_ORDER: - retcode = ToontownGlobals.P_ReachedPurchaseLimit - - elif not gifting and len(recepient.mailboxContents) >= MAX_MAILBOX: - retcode = ToontownGlobals.P_MailboxFull - - elif item.getPrice(priceType) >= avBuying.getTotalMoney(): - retcode = ToontownGlobals.P_NotEnoughMoney - - elif not avBuying.isEnoughEmblemsToBuy(_getEmblemPrices()): - retcode = ToontownGlobals.P_NotEnoughMoney - - elif gifting and not item.isGift(): - retcode = ToontownGlobals.P_NotAGift - - elif not item.getDeliveryTime() and not gifting: - retcode = item.recordPurchase(recepient, optional) - if retcode == ToontownGlobals.P_ItemAvailable: - - charge() - - else: - retcode = ToontownGlobals.P_ItemOnOrder - charge() - deliveryTime = item.getDeliveryTime() - if config.GetBool('want-instant-delivery', False): - deliveryTime = 0 - + if gifting and not item.isGift(): + return ToontownGlobals.P_NotAGift + + price = item.getPrice(CatalogItem.CatalogTypeBackorder if item in av.backCatalog else 0) + + if price > av.getTotalMoney() or (item.hasEmblemPrices() and not av.isEnoughEmblemsToBuy(item.getEmblemPrices())): + return ToontownGlobals.P_NotEnoughMoney + + if item.getDeliveryTime() or gifting: + deliveryTime = 0 if config.GetBool('want-instant-delivery', False) else item.getDeliveryTime() item.deliveryDate = int(time.time() / 60. + deliveryTime + .5) - - if not gifting: - recepient.onOrder.append(item) - recepient.b_setDeliverySchedule(recepient.onOrder) - - else: - item.giftTag = avBuying.doId - store = CatalogItem.Customization | CatalogItem.DeliveryDate | CatalogItem.GiftTag - self.air.sendNetEvent('CATALOG_addGift_AI2UD', [recepient, item.getBlob(store=store)]) - - return retcode - - def requestPurchaseMessage(self, context, blob, optional, payMethod=0): - av = self.__getCaller() - if av: - retcode = self.attemptPurchase(av, av, blob, optional, payMethod) - if retcode in (ToontownGlobals.P_ItemOnOrder, ToontownGlobals.P_ItemAvailable): - messenger.send('topToonsManager-event', [av.doId, TopToonsGlobals.CAT_CATALOG, 1]) - self.sendUpdateToAvatarId(av.doId, 'requestPurchaseResponse', [context, retcode]) - def requestGiftPurchaseMessage(self, context, targetDoID, blob, optional, payMethod=0): + if gifting: + return self.requestGiftAvatarOperation(avId, gifting, [context, item, price], self.attemptGiftPurchase) + else: + returnCode = self.checkPurchaseLimit(av, item) + + if returnCode != ToontownGlobals.P_ItemOnOrder: + return returnCode + + if item.getDeliveryTime(): + self.chargeAvatar(av, price, item.getEmblemPrices()) + av.onOrder.append(item) + av.b_setDeliverySchedule(av.onOrder) + else: + returnCode = item.recordPurchase(av, optional) + + if returnCode == ToontownGlobals.P_ItemAvailable: + self.chargeAvatar(av, price, item.getEmblemPrices()) + + return returnCode + + return None + + def attemptGiftPurchase(self, avId, targetId, avatar, optional): + av = self.air.doId2do.get(avId) + + if not av: + return + + recipient = GiftAvatar.createFromFields(avatar) + context = optional[0] + item = optional[1] + returnCode = self.checkPurchaseLimit(recipient, item) + + if returnCode != ToontownGlobals.P_ItemOnOrder: + self.sendGiftPurchaseResponse(context, avId, returnCode) + return + + item.giftTag = avId + self.chargeAvatar(av, optional[2], item.getEmblemPrices()) + recipient.onGiftOrder.append(item) + + dg = self.air.dclassesByName['DistributedToonAI'].aiFormatUpdate('setGiftSchedule', targetId, targetId, self.air.ourChannel, [recipient.getGiftScheduleBlob()]) + self.air.send(dg) + self.sendGiftPurchaseResponse(context, avId, ToontownGlobals.P_ItemOnOrder) + + def sendGiftPurchaseResponse(self, context, avId, returnCode): + if returnCode in (ToontownGlobals.P_ItemOnOrder, ToontownGlobals.P_ItemAvailable): + messenger.send('topToonsManager-event', [avId, TopToonsGlobals.CAT_CATALOG | TopToonsGlobals.CAT_GIFTS, 1]) + + self.sendUpdateToAvatarId(avId, 'requestGiftPurchaseResponse', [context, returnCode]) + + def requestPurchaseMessage(self, context, blob, optional): av = self.__getCaller() - if av: - retcode = self.attemptPurchase(av, targetDoID, blob, optional, payMethod, gifting=True) - if retcode in (ToontownGlobals.P_ItemOnOrder, ToontownGlobals.P_ItemAvailable): - messenger.send('topToonsManager-event', [av.doId, TopToonsGlobals.CAT_CATALOG | TopToonsGlobals.CAT_GIFTS, 1]) - self.sendUpdateToAvatarId(av.doId, 'requestGiftPurchaseResponse', [context, retcode]) + + if not av: + return + + returnCode = self.attemptPurchase(context, av, blob, optional) + + if returnCode in (ToontownGlobals.P_ItemOnOrder, ToontownGlobals.P_ItemAvailable): + messenger.send('topToonsManager-event', [av.doId, TopToonsGlobals.CAT_CATALOG, 1]) + + self.sendUpdateToAvatarId(av.doId, 'requestPurchaseResponse', [context, returnCode]) + + def requestGiftPurchaseMessage(self, context, targetId, blob, optional): + av = self.__getCaller() + + if not av: + return + + returnCode = self.attemptPurchase(context, av, blob, optional, gifting=targetId) + + if returnCode: + self.sendGiftPurchaseResponse(context, av.doId, returnCode) + + def requestGiftAvatar(self, doId): + self.requestGiftAvatarOperation(self.air.getAvatarIdFromSender(), doId, None, self.sendGiftAvatarResponse) + + def requestGiftAvatarOperation(self, avId, doId, optional, callback): + if avId in self.fsms: + return + + loadOperation = LoadGiftAvatar(self, avId, doId, optional, callback) + loadOperation.start() + self.fsms[avId] = loadOperation + return None + + def sendGiftAvatarResponse(self, avId, targetId, avatar, optional): + self.sendUpdateToAvatarId(avId, 'setGiftAvatar', [json.dumps(avatar)]) def resetMovie(self, task): self.d_setMovie(PHONE_MOVIE_CLEAR, 0) diff --git a/toontown/toon/DistributedToonAI.py b/toontown/toon/DistributedToonAI.py index 4f34b883..58cfae0b 100755 --- a/toontown/toon/DistributedToonAI.py +++ b/toontown/toon/DistributedToonAI.py @@ -175,8 +175,6 @@ class DistributedToonAI(DistributedPlayerAI.DistributedPlayerAI, DistributedSmoo from toontown.toon.DistributedNPCToonBaseAI import DistributedNPCToonBaseAI if not isinstance(self, DistributedNPCToonBaseAI): self.sendUpdate('setDefaultShard', [self.air.districtId]) - - self.accept('CATALOG_addGift_UD2Toon_%d' % self.doId, self.__handleAddGift) def setLocation(self, parentId, zoneId): DistributedPlayerAI.DistributedPlayerAI.setLocation(self, parentId, zoneId) @@ -238,8 +236,6 @@ class DistributedToonAI(DistributedPlayerAI.DistributedPlayerAI, DistributedSmoo PetLookerAI.PetLookerAI.destroy(self) del self.kart self._sendExitServerEvent() - - self.ignore('CATALOG_addGift_UD2Toon_%d' % self.doId) DistributedSmoothNodeAI.DistributedSmoothNodeAI.delete(self) DistributedPlayerAI.DistributedPlayerAI.delete(self) @@ -2187,12 +2183,6 @@ class DistributedToonAI(DistributedPlayerAI.DistributedPlayerAI, DistributedSmoo self.b_setCatalogNotify(self.catalogNotify, ToontownGlobals.NewItems) return Task.done - def __handleAddGift(self, blob, ctx): - store = CatalogItem.Customization | CatalogItem.DeliveryDate | CatalogItem.GiftTag - self.onGiftOrder.append(CatalogItem.getItem(blob, store=store)) - self.b_setBothSchedules(self.onOrder, self.onGiftOrder) - self.air.sendNetEvent('CATALOG_addGift_UD2Toon_resp', [self.doId, ctx]) - def __deliverPurchase(self, task): now = int(time.time() / 60 + 0.5) delivered, remaining = self.onOrder.extractDeliveryItems(now) diff --git a/toontown/toonbase/TTLocalizerEnglish.py b/toontown/toonbase/TTLocalizerEnglish.py index 5bb247e3..8e0a38fd 100755 --- a/toontown/toonbase/TTLocalizerEnglish.py +++ b/toontown/toonbase/TTLocalizerEnglish.py @@ -5466,8 +5466,8 @@ CatalogGiftFor = 'Buy Gift for:' CatalogGiftTo = 'To: %s' CatalogGiftToggleOn = 'Stop Gifting' CatalogGiftToggleOff = 'Buy Gifts' -CatalogGiftToggleWait = 'Trying!...' -CatalogGiftToggleNoAck = 'Unavailable' +CatalogGiftUpdating = 'Updating...' +CatalogGiftChoose = 'Choose a friend!' CatalogPurchaseItemAvailable = 'Congratulations on your new purchase! You can start using it right away.' CatalogPurchaseGiftItemAvailable = 'Excellent! %s can start using your gift right away.' CatalogPurchaseItemOnOrder = 'Congratulations! Your purchase will be delivered to your mailbox soon.' @@ -8601,7 +8601,7 @@ CEOSpeech = [ 'And thus we, the Cog Nation, are striving.', 'I am very delighted by this news, I just wanted to thank you all for working so hard for this news.', "Wait, what's going on? I can't see but I hear explosions." - ] +] # Len of words + 10 Blacklist = [ "$1ut", "$h1t", @@ -9864,4 +9864,4 @@ Blacklist = [ "willy", "xrated", "xxx" - ] # Len of words + 10 \ No newline at end of file +] \ No newline at end of file diff --git a/toontown/uberdog/ToontownUberRepository.py b/toontown/uberdog/ToontownUberRepository.py index d4821459..7ead157f 100755 --- a/toontown/uberdog/ToontownUberRepository.py +++ b/toontown/uberdog/ToontownUberRepository.py @@ -3,7 +3,6 @@ import urlparse from otp.distributed.OtpDoGlobals import * from otp.distributed.DistributedDirectoryAI import DistributedDirectoryAI from toontown.distributed.ToontownInternalRepository import ToontownInternalRepository -from toontown.catalog.CatalogManagerUD import CatalogManagerUD import toontown.minigame.MinigameCreatorAI if config.GetBool('want-rpc-server', False): @@ -26,8 +25,6 @@ class ToontownUberRepository(ToontownInternalRepository): self.mongo = pymongo.MongoClient(url) db = (urlparse.urlparse(url).path or '/test')[1:] self.mongodb = self.mongo[db] - - self.catalogManager = CatalogManagerUD(self) self.notify.setInfo(True)