makeatoon: pattern names work now

This commit is contained in:
Open Toontown 2019-11-15 22:28:30 -05:00
parent 651de8ddd8
commit e3b96e2cfd
4 changed files with 167 additions and 33 deletions

View file

@ -536,4 +536,6 @@ dclass AstronLoginManager : DistributedObject {
avatarListResponse(PotentialAvatar[]); avatarListResponse(PotentialAvatar[]);
createAvatar(blob, uint8) clsend; createAvatar(blob, uint8) clsend;
createAvatarResponse(uint32); createAvatarResponse(uint32);
setNamePattern(uint32, int16, uint8, int16, uint8, int16, uint8, int16, uint8) clsend;
namePatternAnswer(uint32, uint8);
}; };

View file

@ -13,6 +13,7 @@ class AstronLoginManager(DistributedObjectGlobal):
def __init__(self, cr): def __init__(self, cr):
DistributedObjectGlobal.__init__(self, cr) DistributedObjectGlobal.__init__(self, cr)
self.doneEvent = None self.doneEvent = None
self._callback = None
def handleRequestLogin(self, doneEvent): def handleRequestLogin(self, doneEvent):
self.doneEvent = doneEvent self.doneEvent = doneEvent
@ -127,3 +128,10 @@ class AstronLoginManager(DistributedObjectGlobal):
def createAvatarResponse(self, avId): def createAvatarResponse(self, avId):
messenger.send('nameShopCreateAvatarDone', [avId]) messenger.send('nameShopCreateAvatarDone', [avId])
def sendSetNamePattern(self, avId, p1, f1, p2, f2, p3, f3, p4, f4, callback):
self._callback = callback
self.sendUpdate('setNamePattern', [avId, p1, f1, p2, f2, p3, f3, p4, f4])
def namePatternAnswer(self, avId, status):
self._callback(avId, status)

View file

@ -10,6 +10,7 @@ from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobal
from direct.distributed.PyDatagram import * from direct.distributed.PyDatagram import *
from toontown.toon.ToonDNA import ToonDNA from toontown.toon.ToonDNA import ToonDNA
from toontown.toonbase import TTLocalizer from toontown.toonbase import TTLocalizer
from toontown.makeatoon.NameGenerator import NameGenerator
class AccountDB: class AccountDB:
""" """
@ -345,11 +346,87 @@ class CreateAvatarOperation:
del self.loginManager.account2operation[self.sender] del self.loginManager.account2operation[self.sender]
class SetNamePatternOperation:
notify = DirectNotifyGlobal.directNotify.newCategory('SetNamePatternOperation')
def __init__(self, loginManager, sender):
self.loginManager = loginManager
self.sender = sender
self.avId = None
self.pattern = None
def start(self, avId, pattern):
self.avId = avId
self.pattern = pattern
self.__handleRetrieveAccount()
def __handleRetrieveAccount(self):
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.sender, self.__handleAccountRetrieved)
def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu
return
self.account = fields
self.avList = self.account['ACCOUNT_AV_SET']
self.avList = self.avList[:6]
self.avList += [0] * (6 - len(self.avList))
self.__handleRetrieveAvatar()
def __handleRetrieveAvatar(self):
if self.avId and self.avId not in self.avList:
# Main screen turn on.
# It's you!
return
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId, self.__handleAvatarRetrieved)
def __handleAvatarRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']:
# How are you gentlemen?
# All your base are belong to us
return
if fields['WishNameState'][0] != 'OPEN':
# You are on your way to destruction
# What you say?
return
self.__handleSetName()
def __handleSetName(self):
parts = []
for p, f in self.pattern:
part = self.loginManager.nameGenerator.nameDictionary.get(p, ('', ''))[1]
if f:
part = part[:1].upper() + part[1:]
else:
part = part.lower()
parts.append(part)
parts[2] += parts.pop(3)
while '' in parts:
parts.remove('')
name = ' '.join(parts)
self.loginManager.air.dbInterface.updateObject(self.loginManager.air.dbId, self.avId, self.loginManager.air.dclassesByName['DistributedToonUD'],
{'WishNameState': ('LOCKED',),
'WishName': ('',),
'setName': (name,)})
self.loginManager.sendUpdateToAccountId(self.sender, 'namePatternAnswer', [self.avId, 1])
del self.loginManager.account2operation[self.sender]
class AstronLoginManagerUD(DistributedObjectGlobalUD): class AstronLoginManagerUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManagerUD') notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManagerUD')
def __init__(self, air): def __init__(self, air):
DistributedObjectGlobalUD.__init__(self, air) DistributedObjectGlobalUD.__init__(self, air)
self.nameGenerator = None
self.accountDb = None self.accountDb = None
self.sender2loginOperation = {} self.sender2loginOperation = {}
self.account2operation = {} self.account2operation = {}
@ -357,6 +434,9 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD):
def announceGenerate(self): def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self) DistributedObjectGlobalUD.announceGenerate(self)
# This is for processing name patterns.
self.nameGenerator = NameGenerator()
# Instantiate the account database backend. # Instantiate the account database backend.
# TODO: In the future, add more database interfaces & make this configurable. # TODO: In the future, add more database interfaces & make this configurable.
self.accountDb = DeveloperAccountDB(self) self.accountDb = DeveloperAccountDB(self)
@ -402,3 +482,18 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD):
newOperation = CreateAvatarOperation(self, sender) newOperation = CreateAvatarOperation(self, sender)
self.account2operation[sender] = newOperation self.account2operation[sender] = newOperation
newOperation.start(avDNA, avPosition) newOperation.start(avDNA, avPosition)
def setNamePattern(self, avId, p1, f1, p2, f2, p3, f3, p4, f4):
sender = self.air.getAccountIdFromSender()
if not sender:
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = SetNamePatternOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start(avId, [(p1, f1), (p2, f2),
(p3, f3), (p4, f4)])

View file

@ -866,41 +866,70 @@ class NameShop(StateData.StateData):
def checkNamePattern(self): def checkNamePattern(self):
self.notify.debug('checkNamePattern') self.notify.debug('checkNamePattern')
datagram = PyDatagram() if base.cr.astronSupport:
datagram.addUint16(CLIENT_SET_NAME_PATTERN) base.cr.astronLoginManager.sendSetNamePattern(self.avId,
datagram.addUint32(self.avId) self.nameIndices[0], self.nameFlags[0],
datagram.addInt16(self.nameIndices[0]) self.nameIndices[1], self.nameFlags[1],
datagram.addInt16(self.nameFlags[0]) self.nameIndices[2], self.nameFlags[2],
datagram.addInt16(self.nameIndices[1]) self.nameIndices[3], self.nameFlags[3],
datagram.addInt16(self.nameFlags[1]) self.handleSetNamePatternAnswerMsg)
datagram.addInt16(self.nameIndices[2]) else:
datagram.addInt16(self.nameFlags[2]) datagram = PyDatagram()
datagram.addInt16(self.nameIndices[3]) datagram.addUint16(CLIENT_SET_NAME_PATTERN)
datagram.addInt16(self.nameFlags[3]) datagram.addUint32(self.avId)
messenger.send('nameShopPost', [datagram]) datagram.addInt16(self.nameIndices[0])
datagram.addInt16(self.nameFlags[0])
datagram.addInt16(self.nameIndices[1])
datagram.addInt16(self.nameFlags[1])
datagram.addInt16(self.nameIndices[2])
datagram.addInt16(self.nameFlags[2])
datagram.addInt16(self.nameIndices[3])
datagram.addInt16(self.nameFlags[3])
messenger.send('nameShopPost', [datagram])
self.waitForServer() self.waitForServer()
def handleSetNamePatternAnswerMsg(self, di): if not config.GetBool('astron-support', True):
self.notify.debug('handleSetNamePatternAnswerMsg') def handleSetNamePatternAnswerMsg(self, di):
self.cleanupWaitForServer() self.notify.debug('handleSetNamePatternAnswerMsg')
newavId = di.getUint32() self.cleanupWaitForServer()
if newavId != self.avId: newavId = di.getUint32()
self.notify.debug("doid's don't match up!") if newavId != self.avId:
self.rejectName(TTLocalizer.NameError) self.notify.debug("doid's don't match up!")
returnCode = di.getUint8() self.rejectName(TTLocalizer.NameError)
if returnCode == 0: returnCode = di.getUint8()
style = self.toon.getStyle() if returnCode == 0:
avDNA = style.makeNetString() style = self.toon.getStyle()
self.notify.debug('pattern name accepted') avDNA = style.makeNetString()
newPotAv = PotentialAvatar.PotentialAvatar(newavId, self.names, avDNA, self.index, 0) self.notify.debug('pattern name accepted')
self.avList.append(newPotAv) newPotAv = PotentialAvatar.PotentialAvatar(newavId, self.names, avDNA, self.index, 0)
self.doneStatus = 'done' self.avList.append(newPotAv)
self.storeSkipTutorialRequest() self.doneStatus = 'done'
messenger.send(self.doneEvent) self.storeSkipTutorialRequest()
else: messenger.send(self.doneEvent)
self.notify.debug('name pattern rejected') else:
self.rejectName(TTLocalizer.NameError) self.notify.debug('name pattern rejected')
return None self.rejectName(TTLocalizer.NameError)
return None
else:
def handleSetNamePatternAnswerMsg(self, newavId, returnCode):
self.notify.debug('handleSetNamePatternAnswerMsg')
self.cleanupWaitForServer()
if newavId != self.avId:
self.notify.debug("doid's don't match up!")
self.rejectName(TTLocalizer.NameError)
if returnCode == 1:
style = self.toon.getStyle()
avDNA = style.makeNetString()
self.notify.debug('pattern name accepted')
newPotAv = PotentialAvatar.PotentialAvatar(newavId, self.names, avDNA, self.index, 0)
self.avList.append(newPotAv)
self.doneStatus = 'done'
self.storeSkipTutorialRequest()
messenger.send(self.doneEvent)
else:
self.notify.debug('name pattern rejected')
self.rejectName(TTLocalizer.NameError)
return None
def _submitTypeANameAsPickAName(self): def _submitTypeANameAsPickAName(self):
pnp = TTPickANamePattern(self.nameEntry.get(), self.toon.style.gender) pnp = TTPickANamePattern(self.nameEntry.get(), self.toon.style.gender)