def __init__(self, doneEvent, petSeed, petNameIndex): zoneId = ZoneUtil.getCanonicalSafeZoneId(base.localAvatar.getZoneId()) name, dna, traitSeed = PetUtil.getPetInfoFromSeed(petSeed, zoneId) name = TTLocalizer.getPetName(petNameIndex) cost = PetUtil.getPetCostFromSeed(petSeed, zoneId) model = loader.loadModel('phase_4/models/gui/AdoptPet') modelPos = (0, 0, -0.3) modelScale = 0.055 DirectFrame.__init__(self, relief=None, state='normal', geom=model, geom_color=ToontownGlobals.GlobalDialogColor, geom_scale=modelScale, frameSize=(-1, 1, -1, 1), pos=modelPos, text=TTLocalizer.PetshopAdoptConfirm % (name, cost), text_wordwrap=12, text_scale=0.05, text_pos=(0, 0.55), text_fg=text0Color) self.initialiseoptions(PetshopGUI.AdoptPetDlg) self.petView = self.attachNewNode('petView') self.petView.setPos(-0.13, 0, 0.8) self.petModel = Pet.Pet(forGui=1) self.petModel.setDNA(dna) self.petModel.fitAndCenterHead(0.395, forGui=1) self.petModel.reparentTo(self.petView) self.petModel.setH(130) self.petModel.setScale(0.125) self.petModel.enterNeutralHappy() self.moneyDisplay = DirectLabel(parent=self, relief=None, text=str(base.localAvatar.getTotalMoney()), text_scale=0.075, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_pos=(0.225, 0.33), text_font=ToontownGlobals.getSignFont()) self.accept(localAvatar.uniqueName('moneyChange'), self.__moneyChange) self.accept(localAvatar.uniqueName('bankMoneyChange'), self.__moneyChange) okImageList = (model.find('**/CheckButtonUp'), model.find('**/CheckButtonDown'), model.find('**/CheckButtonRollover')) cancelImageList = (model.find('**/CancelButtonUp'), model.find('**/CancelButtonDown'), model.find('**/CancelRollover')) cancelIcon = model.find('**/CancelIcon') checkIcon = model.find('**/CheckIcon') self.cancelButton = DirectButton(parent=self, relief=None, image=cancelImageList, geom=cancelIcon, scale=modelScale, text=('', TTLocalizer.PetshopGoBack), text_pos=(-5.8, 4.4), text_scale=0.7, pressEffect=False, command=lambda : messenger.send(doneEvent, [0])) self.okButton = DirectButton(parent=self, relief=None, image=okImageList, geom=checkIcon, scale=modelScale, text=('', TTLocalizer.PetshopAdopt), text_pos=(5.8, 4.4), text_scale=0.7, pressEffect=False, command=lambda : messenger.send(doneEvent, [1])) model.removeNode() return
def makePetList(self): self.numPets = len(self.petSeeds) self.curPet = 0 self.petDNA = [] self.petName = [] self.petDesc = [] self.petCost = [] for i in xrange(self.numPets): random.seed(self.petSeeds[i]) zoneId = ZoneUtil.getCanonicalSafeZoneId(base.localAvatar.getZoneId()) name, dna, traitSeed = PetUtil.getPetInfoFromSeed(self.petSeeds[i], zoneId) cost = PetUtil.getPetCostFromSeed(self.petSeeds[i], zoneId) traits = PetTraits.PetTraits(traitSeed, zoneId) traitList = traits.getExtremeTraitDescriptions() numGenders = len(PetDNA.PetGenders) gender = i % numGenders PetDNA.setGender(dna, gender) self.petDNA.append(dna) self.petName.append(TTLocalizer.PetshopUnknownName) descList = [] descList.append(TTLocalizer.PetshopDescGender % PetDNA.getGenderString(gender=gender)) if traitList: descList.append(TTLocalizer.PetshopDescTrait % traitList[0]) else: descList.append(TTLocalizer.PetshopDescTrait % TTLocalizer.PetshopDescStandard) traitList.extend(['', '', '', '']) for trait in traitList[1:4]: descList.append('\t%s' % trait) descList.append(TTLocalizer.PetshopDescCost % cost) self.petDesc.append('\n'.join(descList)) self.petCost.append(cost)
def __init__(self, doneEvent, petSeed, petNameIndex): zoneId = ZoneUtil.getCanonicalSafeZoneId(base.localAvatar.getZoneId()) name, dna, traitSeed = PetUtil.getPetInfoFromSeed(petSeed, zoneId) name = PetNameGenerator.PetNameGenerator().getName(petNameIndex) cost = PetUtil.getPetCostFromSeed(petSeed, zoneId) model = loader.loadModel('phase_4/models/gui/AdoptPet') modelPos = (0, 0, -0.3) modelScale = 0.055 DirectFrame.__init__(self, relief=None, state='normal', geom=model, geom_color=ToontownGlobals.GlobalDialogColor, geom_scale=modelScale, frameSize=(-1, 1, -1, 1), pos=modelPos, text=TTLocalizer.PetshopAdoptConfirm % (name, cost), text_wordwrap=12, text_scale=0.05, text_pos=(0, 0.55), text_fg=text0Color) self.initialiseoptions(PetshopGUI.AdoptPetDlg) self.petView = self.attachNewNode('petView') self.petView.setPos(-0.13, 0, 0.8) self.petModel = Pet.Pet(forGui=1) self.petModel.setDNA(dna) self.petModel.fitAndCenterHead(0.395, forGui=1) self.petModel.reparentTo(self.petView) self.petModel.setH(130) self.petModel.enterNeutralHappy() self.moneyDisplay = DirectLabel(parent=self, relief=None, text=str(base.localAvatar.getTotalMoney()), text_scale=0.075, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_pos=(0.225, 0.33), text_font=ToontownGlobals.getSignFont()) self.accept(localAvatar.uniqueName('moneyChange'), self.__moneyChange) self.accept(localAvatar.uniqueName('bankMoneyChange'), self.__moneyChange) okImageList = (model.find('**/CheckButtonUp'), model.find('**/CheckButtonDown'), model.find('**/CheckButtonRollover')) cancelImageList = (model.find('**/CancelButtonUp'), model.find('**/CancelButtonDown'), model.find('**/CancelRollover')) cancelIcon = model.find('**/CancelIcon') checkIcon = model.find('**/CheckIcon') self.cancelButton = DirectButton(parent=self, relief=None, image=cancelImageList, geom=cancelIcon, scale=modelScale, text=('', TTLocalizer.PetshopGoBack), text_pos=(-5.8, 4.4), text_scale=0.7, pressEffect=False, command=lambda : messenger.send(doneEvent, [0])) self.okButton = DirectButton(parent=self, relief=None, image=okImageList, geom=checkIcon, scale=modelScale, text=('', TTLocalizer.PetshopAdopt), text_pos=(5.8, 4.4), text_scale=0.7, pressEffect=False, command=lambda : messenger.send(doneEvent, [1])) model.removeNode() return
def makePetList(self): self.numPets = len(self.petSeeds) self.curPet = 0 self.petDNA = [] self.petName = [] self.petDesc = [] self.petCost = [] for i in xrange(self.numPets): random.seed(self.petSeeds[i]) zoneId = ZoneUtil.getCanonicalSafeZoneId(base.localAvatar.getZoneId()) name, dna, traitSeed = PetUtil.getPetInfoFromSeed(self.petSeeds[i], zoneId) cost = PetUtil.getPetCostFromSeed(self.petSeeds[i], zoneId) traits = PetTraits.PetTraits(traitSeed, zoneId) traitList = traits.getExtremeTraitDescriptions() numGenders = len(PetDNA.PetGenders) gender = i % numGenders PetDNA.setGender(dna, gender) self.petDNA.append(dna) self.petName.append(TTLocalizer.PetshopUnknownName) descList = [] descList.append(TTLocalizer.PetshopDescGender % PetDNA.getGenderString(gender=gender)) if traitList: descList.append(TTLocalizer.PetshopDescTrait % traitList[0]) else: descList.append(TTLocalizer.PetshopDescTrait % TTLocalizer.PetshopDescStandard) traitList.extend(['', '', '', '']) for trait in traitList[1:4]: descList.append('\t%s' % trait) descList.append(TTLocalizer.PetshopDescCost % cost) self.petDesc.append(string.join(descList, '\n')) self.petCost.append(cost)
def makePetList(self): """ This should get called when we first enter the PetChooser. It creates the list of toons that are available here. """ self.numPets = len(self.petSeeds) self.curPet = 0 self.petDNA = [] self.petName = [] self.petDesc = [] self.petCost = [] for i in range(self.numPets): random.seed(self.petSeeds[i]) zoneId = ZoneUtil.getCanonicalSafeZoneId( base.localAvatar.getZoneId()) name, dna, traitSeed = PetUtil.getPetInfoFromSeed( self.petSeeds[i], zoneId) cost = PetUtil.getPetCostFromSeed(self.petSeeds[i], zoneId) traits = PetTraits.PetTraits(traitSeed, zoneId) traitList = traits.getExtremeTraitDescriptions() numGenders = len(PetDNA.PetGenders) gender = i % numGenders PetDNA.setGender(dna, gender) self.petDNA.append(dna) self.petName.append(TTLocalizer.PetshopUnknownName) #build the 'description' strings descList = [] descList.append(TTLocalizer.PetshopDescGender % PetDNA.getGenderString(gender=gender)) if traitList: descList.append(TTLocalizer.PetshopDescTrait % traitList[0]) else: descList.append(TTLocalizer.PetshopDescTrait % TTLocalizer.PetshopDescStandard) #buffer the list so there are at least 4 items traitList.extend(["", "", "", ""]) for trait in traitList[1:4]: descList.append("\t%s" % trait) descList.append(TTLocalizer.PetshopDescCost % cost) self.petDesc.append("\n".join(descList)) self.petCost.append(cost)
def petAdopted(self, petNum, nameIndex): avId = self.air.getAvatarIdFromSender() if self.busy != avId: self.air.writeServerEvent('suspicious', avId, 'DistributedNPCPetshopAI.petAdopted busy with %s' % self.busy) self.notify.warning('somebody called petAdopted that I was not busy with! avId: %s' % avId) return av = simbase.air.doId2do.get(avId) if av: from toontown.hood import ZoneUtil zoneId = ZoneUtil.getCanonicalSafeZoneId(self.zoneId) if petNum not in list(range(0, len(self.petSeeds))): self.air.writeServerEvent('suspicious', avId, 'DistributedNPCPetshopAI.petAdopted and no such pet!') self.notify.warning('somebody called petAdopted on a non-existent pet! avId: %s' % avId) return cost = PetUtil.getPetCostFromSeed(self.petSeeds[petNum], zoneId) if cost > av.getTotalMoney(): self.air.writeServerEvent('suspicious', avId, "DistributedNPCPetshopAI.petAdopted and toon doesn't have enough money!") self.notify.warning("somebody called petAdopted and didn't have enough money to adopt! avId: %s" % avId) return if av.petId != 0: simbase.air.petMgr.deleteToonsPet(avId) gender = petNum % len(PetDNA.PetGenders) if nameIndex not in list(range(0, TTLocalizer.PetNameIndexMAX)): self.air.writeServerEvent('avoid_crash', avId, "DistributedNPCPetclerkAI.petAdopted and didn't have valid nameIndex!") self.notify.warning("somebody called petAdopted and didn't have valid nameIndex to adopt! avId: %s" % avId) return simbase.air.petMgr.createNewPetFromSeed(avId, self.petSeeds[petNum], nameIndex=nameIndex, gender=gender, safeZoneId=zoneId) self.transactionType = 'adopt' bankPrice = min(av.getBankMoney(), cost) walletPrice = cost - bankPrice av.b_setBankMoney(av.getBankMoney() - bankPrice) av.b_setMoney(av.getMoney() - walletPrice)
def petAdopted(self, petNum, nameIndex): avId = self.air.getAvatarIdFromSender() if self.busy != avId: self.air.writeServerEvent('suspicious', avId, 'DistributedNPCPetshopAI.petAdopted busy with %s' % self.busy) self.notify.warning('somebody called petAdopted that I was not busy with! avId: %s' % avId) return av = simbase.air.doId2do.get(avId) if av: from toontown.hood import ZoneUtil zoneId = ZoneUtil.getCanonicalSafeZoneId(self.zoneId) if petNum not in xrange(0, len(self.petSeeds)): self.air.writeServerEvent('suspicious', avId, 'DistributedNPCPetshopAI.petAdopted and no such pet!') self.notify.warning('somebody called petAdopted on a non-existent pet! avId: %s' % avId) return cost = PetUtil.getPetCostFromSeed(self.petSeeds[petNum], zoneId) if cost > av.getTotalMoney(): self.air.writeServerEvent('suspicious', avId, "DistributedNPCPetshopAI.petAdopted and toon doesn't have enough money!") self.notify.warning("somebody called petAdopted and didn't have enough money to adopt! avId: %s" % avId) return if av.petId != 0: simbase.air.petMgr.deleteToonsPet(avId) gender = petNum % len(PetDNA.PetGenders) if nameIndex not in xrange(0, len(TTLocalizer.PetNameDictionary) - 1): self.air.writeServerEvent('avoid_crash', avId, "DistributedNPCPetclerkAI.petAdopted and didn't have valid nameIndex!") self.notify.warning("somebody called petAdopted and didn't have valid nameIndex to adopt! avId: %s" % avId) return simbase.air.petMgr.createNewPetFromSeed(avId, self.petSeeds[petNum], nameIndex=nameIndex, gender=gender, safeZoneId=zoneId) self.notify.warning("Created new pet from seed") self.transactionType = 'adopt' bankPrice = min(av.getBankMoney(), cost) walletPrice = cost - bankPrice av.b_setBankMoney(av.getBankMoney() - bankPrice) av.b_setMoney(av.getMoney() - walletPrice)
def createPet(self, ownerId, seed): zoneId = self.interiorZone safeZoneId = ZoneUtil.getCanonicalSafeZoneId(zoneId) name, dna, traitSeed = PetUtil.getPetInfoFromSeed(seed, safeZoneId) pet = DistributedPetAI.DistributedPetAI(self.air, dna=dna) pet.setOwnerId(ownerId) pet.setPetName(name) pet.traits = PetTraits.PetTraits(traitSeed=traitSeed, safeZoneId=safeZoneId) pet.generateWithRequired(zoneId) pet.setPos(0, 0, 0) pet.b_setParent(ToontownGlobals.SPRender)
def __init__(self, doneEvent, petSeed, gender): zoneId = ZoneUtil.getCanonicalSafeZoneId(base.localAvatar.getZoneId()) name, dna, traitSeed = PetUtil.getPetInfoFromSeed(petSeed, zoneId) self.gui = loader.loadModel('phase_4/models/gui/PetNamePanel') self.guiScale = 0.09 DirectFrame.__init__(self, relief=None, geom=self.gui, geom_scale=self.guiScale, state='normal', frameSize=(-1, 1, -1, 1)) self.initialiseoptions(PetshopGUI.NamePicker) self.petView = self.attachNewNode('petView') self.petView.setPos(-0.21, 0, -0.04) self.petModel = Pet.Pet(forGui=1) self.petModel.setDNA(dna) self.petModel.fitAndCenterHead(0.435, forGui=1) self.petModel.reparentTo(self.petView) self.petModel.setH(225) self.petModel.enterNeutralHappy() self.ng = PetNameGenerator.PetNameGenerator() if gender == 1: self.allNames = self.ng.boyFirsts else: self.allNames = self.ng.girlFirsts self.allNames += self.ng.neutralFirsts self.allNames.sort() self.checkNames() self.letters = [] for name in self.allNames: if name[0:TTLocalizer.PGUIcharLength] not in self.letters: self.letters.append(name[0:TTLocalizer.PGUIcharLength]) self.curLetter = self.letters[0] self.curNames = [] self.curName = '' self.alphabetList = self.makeScrollList(self.gui, (-0.012, 0, -0.075), (1, 0.8, 0.8, 1), self.letters, self.makeLabel, [TextNode.ACenter, 'alphabet'], 6) self.nameList = None self.rebuildNameList() self.randomButton = DirectButton(parent=self, relief=None, image=(self.gui.find('**/RandomUpButton'), self.gui.find('**/RandomDownButton'), self.gui.find('**/RandomRolloverButton')), scale=self.guiScale, text=TTLocalizer.RandomButton, text_pos=(-0.8, -5.7), text_scale=0.8, text_fg=text2Color, pressEffect=False, command=self.randomName) self.nameResult = DirectLabel(parent=self, relief=None, scale=self.guiScale, text='', text_align=TextNode.ACenter, text_pos=(-1.85, 2.6), text_fg=text0Color, text_scale=0.6, text_wordwrap=8) self.submitButton = DirectButton(parent=self, relief=None, image=(self.gui.find('**/SubmitUpButton'), self.gui.find('**/SubmitDownButton'), self.gui.find('**/SubmitRolloverButton')), scale=self.guiScale, text=TTLocalizer.PetshopAdopt, text_pos=(3.3, -5.7), text_scale=TTLocalizer.PGUIsubmitButton, text_fg=text0Color, pressEffect=False, command=lambda : messenger.send(doneEvent, [self.ng.returnUniqueID(self.curName)])) model = loader.loadModel('phase_4/models/gui/PetShopInterface') modelScale = 0.1 cancelImageList = (model.find('**/CancelButtonUp'), model.find('**/CancelButtonDown'), model.find('**/CancelButtonRollover')) cancelIcon = model.find('**/CancelIcon') self.cancelButton = DirectButton(parent=self, relief=None, pos=(-0.04, 0, -0.47), image=cancelImageList, geom=cancelIcon, scale=modelScale, pressEffect=False, command=lambda : messenger.send(doneEvent, [-1])) self.randomName() return
def createPet(self, ownerId, seed): zoneId = self.interiorZone safeZoneId = ZoneUtil.getCanonicalSafeZoneId(zoneId) (name, dna, traitSeed) = PetUtil.getPetInfoFromSeed(seed, safeZoneId) pet = DistributedPetAI.DistributedPetAI(self.air, dna=dna) pet.setOwnerId(ownerId) pet.setPetName(name) pet.traits = PetTraits.PetTraits(traitSeed=traitSeed, safeZoneId=safeZoneId) pet.generateWithRequired(zoneId) pet.setPos(0, 0, 0) pet.b_setParent(ToontownGlobals.SPRender)
def __init__(self, air, avId, petSeed, nameIndex, gender, zoneId): name, dna, traitSeed = PetUtil.getPetInfoFromSeed(petSeed, zoneId) self.air = air self.avId = avId self.petSeed = petSeed self.traitSeed = traitSeed self.nameIndex = nameIndex self.dna = dna self.zoneId = ZoneUtil.getCanonicalSafeZoneId(zoneId) self.traits = PetTraits.PetTraits(traitSeed=traitSeed, safeZoneId=zoneId) self.gender = gender self.petId = None self.name = None
def __init__(self, air, avId, petSeed, nameIndex, gender, zoneId): name, dna, traitSeed = PetUtil.getPetInfoFromSeed(petSeed, zoneId) self.air = air self.avId = avId self.petSeed = petSeed self.traitSeed = traitSeed self.nameIndex= nameIndex self.dna=dna self.zoneId = ZoneUtil.getCanonicalSafeZoneId(zoneId) self.traits = PetTraits.PetTraits(traitSeed=traitSeed, safeZoneId=zoneId) self.gender = gender self.petId = None self.name = None
def petAdopted(self, petNum, nameIndex): assert self.notify.debug('petAdopted()') avId = self.air.getAvatarIdFromSender() if self.busy != avId: self.air.writeServerEvent('suspicious', avId, 'DistributedNPCPetshopAI.petAdopted busy with %s' % (self.busy)) self.notify.warning("somebody called petAdopted that I was not busy with! avId: %s" % avId) return av = simbase.air.doId2do.get(avId) if av: from toontown.hood import ZoneUtil zoneId = ZoneUtil.getCanonicalSafeZoneId(self.zoneId) # make sure this isn't a suspicious request if not petNum in range(0, len(self.petSeeds)): # hacker? self.air.writeServerEvent('suspicious', avId, "DistributedNPCPetshopAI.petAdopted and no such pet!") self.notify.warning("somebody called petAdopted on a non-existent pet! avId: %s" % avId) return cost = PetUtil.getPetCostFromSeed(self.petSeeds[petNum], zoneId) if cost > av.getTotalMoney(): #houston, we have a problem self.air.writeServerEvent('suspicious', avId, "DistributedNPCPetshopAI.petAdopted and toon doesn't have enough money!") self.notify.warning("somebody called petAdopted and didn't have enough money to adopt! avId: %s" % avId) return if av.petId != 0: # this function deletes the pet simbase.air.petMgr.deleteToonsPet(avId) #create new pet gender = petNum % len(PetDNA.PetGenders) simbase.air.petMgr.createNewPetFromSeed(avId, self.petSeeds[petNum], nameIndex = nameIndex, gender = gender, safeZoneId = zoneId) self.transactionType = "adopt" #deduct the money from the toon's account bankPrice = min(av.getBankMoney(), cost) walletPrice = cost - bankPrice av.b_setBankMoney(av.getBankMoney() - bankPrice) av.b_setMoney(av.getMoney() - walletPrice) else: # perhaps the avatar got disconnected, just leave the fish # in his tank and let him resell them next time pass
def handlePetGenerated(success, pet): if success: name, dna, traitSeed = PetUtil.getPetInfoFromSeed( seed, safeZoneId) if gender != -1: #make sure the size of the dna array hasn't changed assert (len(dna) == 9) dna[8] = gender if nameIndex != -1: name = PetNameGenerator.PetNameGenerator().getName( nameIndex) pet._initDBVals(toonId, name, traitSeed, dna, safeZoneId) self.assignPetToToon(petId, toonId) message = '%s|%s|%s|%s|%s' % ( petId, name, pet.getSafeZone(), dna, pet.traits.getValueList()) self.air.writeServerEvent('adoptPet', toonId, message) pet.requestDelete() else: self.notify.warning('error summoning pet %s' % petId)
def createNewPetFromSeed(self, avId, seed, nameIndex, gender, safeZoneId): av = self.air.doId2do.get(avId) if not av: return petName = self.nameGenerator.getName(nameIndex) _, dna, traitSeed = PetUtil.getPetInfoFromSeed(seed, safeZoneId) head, ears, nose, tail, bodyTexture, color, colorScale, eyeColor, _ = dna numGenders = len(PetDNA.PetGenders) gender %= numGenders fields = { 'setOwnerId': avId, 'setPetName': petName, 'setTraitSeed': traitSeed, 'setSafeZone': safeZoneId, 'setHead': head, 'setEars': ears, 'setNose': nose, 'setTail': tail, 'setBodyTexture': bodyTexture, 'setColor': color, 'setColorScale': colorScale, 'setEyeColor': eyeColor, 'setGender': gender } def response(doId): if not doId: self.notify.warning('Cannot create pet for %s!' % avId) return self.air.writeServerEvent('bought-pet', avId=avId, petId=doId) av.b_setPetId(doId) self.air.dbInterface.createObject( self.air.dbId, self.air.dclassesByName['DistributedPetAI'], {key: (value, ) for key, value in fields.items()}, response)