Start work on pets

This commit is contained in:
Daniel 2015-03-15 00:15:24 +02:00
parent 40ada7cdf1
commit f04bb95b95
6 changed files with 48 additions and 113 deletions

View file

@ -20,7 +20,7 @@ dc-file astron/dclass/toon.dc
dc-file astron/dclass/otp.dc dc-file astron/dclass/otp.dc
# Core features: # Core features:
want-pets #f want-pets #t
want-parties #t want-parties #t
want-cogdominiums #f want-cogdominiums #f
want-achievements #f want-achievements #f

View file

@ -1,88 +0,0 @@
import random
from toontown.toonbase import ToontownGlobals
from toontown.toonbase import TTLocalizer
import os
from direct.showbase import AppRunnerGlobal
from direct.directnotify import DirectNotifyGlobal
from pandac.PandaModules import *
class PetNameGenerator:
notify = DirectNotifyGlobal.directNotify.newCategory('PetNameGenerator')
boyFirsts = []
girlFirsts = []
neutralFirsts = []
def __init__(self):
self.generateLists()
def generateLists(self):
self.boyFirsts = []
self.girlFirsts = []
self.neutralFirsts = []
self.nameDictionary = {}
searchPath = DSearchPath()
if AppRunnerGlobal.appRunner:
searchPath.appendDirectory(Filename.expandFrom('$TT_3_ROOT/phase_3/etc'))
else:
searchPath.appendDirectory(Filename('/phase_3/etc'))
if os.path.expandvars('$TOONTOWN') != '':
searchPath.appendDirectory(Filename.fromOsSpecific(os.path.expandvars('$TOONTOWN/src/configfiles')))
else:
searchPath.appendDirectory(Filename.fromOsSpecific(os.path.expandvars('toontown/src/configfiles')))
searchPath.appendDirectory(Filename('.'))
if __debug__:
filename = '../resources/phase_3/etc/'+TTLocalizer.PetNameMaster
else:
filename = '/phase_3/etc/'+TTLocalizer.PetNameMaster
input = open(filename, 'r')
if not input:
self.notify.error('PetNameGenerator: Error opening name list text file.')
currentLine = input.readline()
while currentLine:
if currentLine.lstrip()[0:1] != '#':
a1 = currentLine.find('*')
a2 = currentLine.find('*', a1 + 1)
self.nameDictionary[int(currentLine[0:a1])] = (int(currentLine[a1 + 1:a2]), currentLine[a2 + 1:len(currentLine) - 1].strip())
currentLine = input.readline()
masterList = [self.boyFirsts, self.girlFirsts, self.neutralFirsts]
for tu in self.nameDictionary.values():
masterList[tu[0]].append(tu[1])
return 1
def getName(self, uniqueID):
try:
return self.nameDictionary[uniqueID][1]
except:
return self.nameDictionary[0][1]
def returnUniqueID(self, name):
newtu = [(), (), ()]
newtu[0] = (0, name)
newtu[1] = (1, name)
newtu[2] = (2, name)
for tu in self.nameDictionary.items():
for g in newtu:
if tu[1] == g:
return tu[0]
return -1
def randomName(self, gender = None, seed = None):
S = random.getstate()
if seed is not None:
random.seed(seed)
if gender is None:
gender = random.choice([0, 1])
retString = ''
firstList = self.neutralFirsts[:]
if gender == 0:
firstList += self.boyFirsts
elif gender == 1:
firstList += self.girlFirsts
else:
self.error('Must be boy or girl.')
retString += random.choice(firstList)
random.setstate(S)
return retString

View file

@ -1,16 +1,12 @@
from toontown.pets import PetDNA, PetTraits, PetConstants from toontown.pets import PetDNA, PetTraits, PetConstants
from toontown.pets import PetNameGenerator from toontown.toonbase import TTLocalizer
from direct.showbase import PythonUtil from direct.showbase import PythonUtil
import random
def getPetInfoFromSeed(seed, safezoneId): def getPetInfoFromSeed(seed, safezoneId):
S = random.getstate()
random.seed(seed)
dnaArray = PetDNA.getRandomPetDNA(safezoneId) dnaArray = PetDNA.getRandomPetDNA(safezoneId)
gender = PetDNA.getGender(dnaArray) gender = PetDNA.getGender(dnaArray)
nameString = PetNameGenerator.PetNameGenerator().randomName(gender=gender, seed=seed + safezoneId) nameString = TTLocalizer.getRandomPetName(gender=gender, seed=seed + safezoneId)
traitSeed = PythonUtil.randUint31() traitSeed = PythonUtil.randUint31()
random.setstate(S)
return (nameString, dnaArray, traitSeed) return (nameString, dnaArray, traitSeed)

View file

@ -10,7 +10,6 @@ from toontown.hood import ZoneUtil
from toontown.pets import Pet, PetConstants from toontown.pets import Pet, PetConstants
from toontown.pets import PetDNA from toontown.pets import PetDNA
from toontown.pets import PetDetail from toontown.pets import PetDetail
from toontown.pets import PetNameGenerator
from toontown.pets import PetTraits from toontown.pets import PetTraits
from toontown.pets import PetUtil from toontown.pets import PetUtil
from toontown.toonbase import TTLocalizer from toontown.toonbase import TTLocalizer
@ -66,14 +65,12 @@ class PetshopGUI(DirectObject):
self.petModel.reparentTo(self.petView) self.petModel.reparentTo(self.petView)
self.petModel.setH(225) self.petModel.setH(225)
self.petModel.enterNeutralHappy() self.petModel.enterNeutralHappy()
self.ng = PetNameGenerator.PetNameGenerator() self.allNames = TTLocalizer.NeutralPetNames
if gender == 1: if gender == 0:
self.allNames = self.ng.boyFirsts self.allNames += TTLocalizer.BoyPetNames
else: else:
self.allNames = self.ng.girlFirsts self.allNames += TTLocalizer.GirlPetNames
self.allNames += self.ng.neutralFirsts
self.allNames.sort() self.allNames.sort()
self.checkNames()
self.letters = [] self.letters = []
for name in self.allNames: for name in self.allNames:
if name[0:TTLocalizer.PGUIcharLength] not in self.letters: if name[0:TTLocalizer.PGUIcharLength] not in self.letters:
@ -87,7 +84,7 @@ class PetshopGUI(DirectObject):
self.rebuildNameList() 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.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.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)])) 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, [TTLocalizer.getPetNameId(self.curName)]))
model = loader.loadModel('phase_4/models/gui/PetShopInterface') model = loader.loadModel('phase_4/models/gui/PetShopInterface')
modelScale = 0.1 modelScale = 0.1
cancelImageList = (model.find('**/CancelButtonUp'), model.find('**/CancelButtonDown'), model.find('**/CancelButtonRollover')) cancelImageList = (model.find('**/CancelButtonUp'), model.find('**/CancelButtonDown'), model.find('**/CancelButtonRollover'))
@ -95,12 +92,6 @@ class PetshopGUI(DirectObject):
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.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() self.randomName()
def checkNames(self):
if __dev__:
for name in self.allNames:
if not name.replace(' ', '').isalpha():
self.notify.warning('Bad name:%s' % name)
def destroy(self): def destroy(self):
self.petModel.delete() self.petModel.delete()
DirectFrame.destroy(self) DirectFrame.destroy(self)
@ -208,7 +199,7 @@ class PetshopGUI(DirectObject):
def __init__(self, doneEvent, petSeed, petNameIndex): def __init__(self, doneEvent, petSeed, petNameIndex):
zoneId = ZoneUtil.getCanonicalSafeZoneId(base.localAvatar.getZoneId()) zoneId = ZoneUtil.getCanonicalSafeZoneId(base.localAvatar.getZoneId())
name, dna, traitSeed = PetUtil.getPetInfoFromSeed(petSeed, zoneId) name, dna, traitSeed = PetUtil.getPetInfoFromSeed(petSeed, zoneId)
name = PetNameGenerator.PetNameGenerator().getName(petNameIndex) name = TTLocalizer.getPetName(petNameIndex)
cost = PetUtil.getPetCostFromSeed(petSeed, zoneId) cost = PetUtil.getPetCostFromSeed(petSeed, zoneId)
model = loader.loadModel('phase_4/models/gui/AdoptPet') model = loader.loadModel('phase_4/models/gui/AdoptPet')
modelPos = (0, 0, -0.3) modelPos = (0, 0, -0.3)

View file

@ -104,7 +104,7 @@ class DistributedNPCPetclerkAI(DistributedNPCToonBaseAI):
if av.petId != 0: if av.petId != 0:
simbase.air.petMgr.deleteToonsPet(avId) simbase.air.petMgr.deleteToonsPet(avId)
gender = petNum % len(PetDNA.PetGenders) gender = petNum % len(PetDNA.PetGenders)
if nameIndex not in xrange(0, TTLocalizer.PetNameIndexMAX): 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.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) self.notify.warning("somebody called petAdopted and didn't have valid nameIndex to adopt! avId: %s" % avId)
return return

File diff suppressed because one or more lines are too long