Gifting update!!!

This commit is contained in:
John 2015-07-17 14:50:16 +03:00
parent a89e89f99a
commit 61705bbf20
20 changed files with 242 additions and 301 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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]

View file

@ -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:

View file

@ -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

View file

@ -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():

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,8 +896,7 @@ class CatalogScreen(DirectFrame):
self.update()
def update(self, task = None):
if not hasattr(self.giftAvatar, 'doId'):
if self.gifting == 1:
if (not self.friend) and self.gifting == 1:
self.__giftToggle()
if hasattr(self, 'beanBank'):
self.beanBank['text'] = str(base.localAvatar.getTotalMoney())
@ -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
if not self.friendAvId:
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
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,6 +1047,9 @@ 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()
@ -1109,13 +1057,3 @@ class CatalogScreen(DirectFrame):
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

View file

@ -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))

View file

@ -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
@ -101,110 +134,134 @@ class DistributedPhoneAI(DistributedFurnitureItemAI):
return av
def attemptPurchase(self, avBuying, recepient, blob, optional, payMethod, gifting=False):
avId = avBuying.doId
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
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 gifting and not item.isGift():
return ToontownGlobals.P_NotAGift
if all(ep):
ep[payMethod] = 0
price = item.getPrice(CatalogItem.CatalogTypeBackorder if item in av.backCatalog else 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 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)
if gifting:
return self.requestGiftAvatarOperation(avId, gifting, [context, item, price], self.attemptGiftPurchase)
else:
item.giftTag = avBuying.doId
store = CatalogItem.Customization | CatalogItem.DeliveryDate | CatalogItem.GiftTag
self.air.sendNetEvent('CATALOG_addGift_AI2UD', [recepient, item.getBlob(store=store)])
returnCode = self.checkPurchaseLimit(av, item)
return retcode
if returnCode != ToontownGlobals.P_ItemOnOrder:
return returnCode
def requestPurchaseMessage(self, context, blob, optional, payMethod=0):
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, av, blob, optional, payMethod)
if retcode in (ToontownGlobals.P_ItemOnOrder, ToontownGlobals.P_ItemAvailable):
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, retcode])
def requestGiftPurchaseMessage(self, context, targetDoID, blob, optional, payMethod=0):
self.sendUpdateToAvatarId(av.doId, 'requestPurchaseResponse', [context, returnCode])
def requestGiftPurchaseMessage(self, context, targetId, 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, 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)

View file

@ -176,8 +176,6 @@ class DistributedToonAI(DistributedPlayerAI.DistributedPlayerAI, DistributedSmoo
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)
@ -239,8 +237,6 @@ class DistributedToonAI(DistributedPlayerAI.DistributedPlayerAI, DistributedSmoo
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)

View file

@ -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
]

View file

@ -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):
@ -27,8 +26,6 @@ class ToontownUberRepository(ToontownInternalRepository):
db = (urlparse.urlparse(url).path or '/test')[1:]
self.mongodb = self.mongo[db]
self.catalogManager = CatalogManagerUD(self)
self.notify.setInfo(True)
def handleConnected(self):