From 7505459b5974f45b40c58d879f6b2231e13588a7 Mon Sep 17 00:00:00 2001 From: Loudrob Date: Sat, 18 Jul 2015 12:17:05 -0400 Subject: [PATCH] Newer pet manager. --- toontown/pets/PetManagerAI.py | 55 ++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/toontown/pets/PetManagerAI.py b/toontown/pets/PetManagerAI.py index 79c03f7b..1e1f081f 100755 --- a/toontown/pets/PetManagerAI.py +++ b/toontown/pets/PetManagerAI.py @@ -1,67 +1,68 @@ +import PetUtil, PetDNA from toontown.toonbase import ToontownGlobals, TTLocalizer -import PetUtil, PetDNA, time, random +import time, random, os -DAY = 24 * 60 * 60 +MINUTE = 60 +HOUR = 60 * MINUTE +DAY = 24 * HOUR def getDayId(): - return int(time.time() / DAY) - + return int(time.time() // DAY) + class PetManagerAI: - NUM_DAILY_PETS = 10 - + NUM_DAILY_PETS = 5 # per hood + def __init__(self, air): self.air = air - self.seeds = simbase.backups.load('pet-seeds', (self.air.districtId,), default={}) - - if self.seeds.get('day', -1) != getDayId(): - self.generateSeeds() - + self.generateSeeds() + def generateSeeds(self): seeds = range(0, 255) - random.shuffle(seeds) - + random.Random(getDayId()).shuffle(seeds) + self.seeds = {} for hood in (ToontownGlobals.ToontownCentral, ToontownGlobals.DonaldsDock, ToontownGlobals.DaisyGardens, - ToontownGlobals.MinniesMelodyland, ToontownGlobals.TheBrrrgh, ToontownGlobals.DonaldsDreamland): - self.seeds[str(hood)] = [seeds.pop() for _ in xrange(self.NUM_DAILY_PETS)] - + ToontownGlobals.MinniesMelodyland, ToontownGlobals.TheBrrrgh, ToontownGlobals.DonaldsDreamland, + ToontownGlobals.FunnyFarm): + self.seeds[hood] = [seeds.pop() for _ in xrange(self.NUM_DAILY_PETS)] + self.seeds['day'] = getDayId() - simbase.backups.save('pet-seeds', (self.air.districtId,), self.seeds) - def getAvailablePets(self, safezoneId): + def getAvailablePets(self, seed, safezoneId): if self.seeds.get('day', -1) != getDayId(): self.generateSeeds() - - return self.seeds.get(str(safezoneId), [random.randint(0, 255)]) + + return list(set(self.seeds.get(safezoneId, [seed]))) def createNewPetFromSeed(self, avId, seed, nameIndex, gender, safeZoneId): av = self.air.doId2do[avId] - + name = TTLocalizer.getPetName(nameIndex) _, dna, traitSeed = PetUtil.getPetInfoFromSeed(seed, safeZoneId) head, ears, nose, tail, body, color, cs, eye, _ = dna numGenders = len(PetDNA.PetGenders) gender %= numGenders - + fields = {'setOwnerId' : avId, 'setPetName' : name, 'setTraitSeed' : traitSeed, 'setSafeZone' : safeZoneId, 'setHead' : head, 'setEars' : ears, 'setNose' : nose, 'setTail' : tail, 'setBodyTexture' : body, 'setColor' : color, 'setColorScale' : cs, 'setEyeColor' : eye, 'setGender' : gender} - + def response(doId): if not doId: self.air.notify.warning("Cannot create pet for %s!" % avId) return - + self.air.writeServerEvent('bought-pet', avId, doId) av.b_setPetId(doId) - + self.air.dbInterface.createObject(self.air.dbId, self.air.dclassesByName['DistributedPetAI'], {k: (v,) for k,v in fields.items()}, response) - + def deleteToonsPet(self, avId): av = self.air.doId2do[avId] pet = av.getPetId() if pet: if pet in self.air.doId2do: self.air.doId2do[pet].requestDelete() - av.b_setPetId(0) + + av.b_setPetId(0) \ No newline at end of file