2015-05-13 11:54:42 -05:00
|
|
|
from toontown.toonbase import ToontownGlobals, TTLocalizer
|
|
|
|
import PetUtil, PetDNA, time, random
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-05-13 12:12:04 -05:00
|
|
|
DAY = 24 * 60 * 60
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
def getDayId():
|
2015-05-13 12:12:04 -05:00
|
|
|
return int(time.time() / DAY)
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-03 16:10:12 -06:00
|
|
|
class PetManagerAI:
|
2015-05-13 12:30:03 -05:00
|
|
|
NUM_DAILY_PETS = 10
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-03 16:10:12 -06:00
|
|
|
def __init__(self, air):
|
|
|
|
self.air = air
|
2015-05-13 11:54:42 -05:00
|
|
|
self.seeds = simbase.backups.load('pet-seeds', (self.air.districtId,), default={})
|
|
|
|
|
2015-05-13 12:12:04 -05:00
|
|
|
if self.seeds.get('day', -1) != getDayId():
|
2015-04-27 23:24:58 -05:00
|
|
|
self.generateSeeds()
|
2015-03-29 17:16:26 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
def generateSeeds(self):
|
|
|
|
seeds = range(0, 255)
|
|
|
|
random.shuffle(seeds)
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
self.seeds = {}
|
|
|
|
for hood in (ToontownGlobals.ToontownCentral, ToontownGlobals.DonaldsDock, ToontownGlobals.DaisyGardens,
|
2015-05-09 01:34:19 -05:00
|
|
|
ToontownGlobals.MinniesMelodyland, ToontownGlobals.TheBrrrgh, ToontownGlobals.DonaldsDreamland):
|
2015-05-13 12:40:06 -05:00
|
|
|
self.seeds[str(hood)] = [seeds.pop() for _ in xrange(self.NUM_DAILY_PETS)]
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
self.seeds['day'] = getDayId()
|
2015-05-13 11:54:42 -05:00
|
|
|
simbase.backups.save('pet-seeds', (self.air.districtId,), self.seeds)
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-05-13 12:30:03 -05:00
|
|
|
def getAvailablePets(self, safezoneId):
|
2015-03-29 10:41:02 -05:00
|
|
|
if self.seeds.get('day', -1) != getDayId():
|
|
|
|
self.generateSeeds()
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-05-13 12:40:06 -05:00
|
|
|
return self.seeds.get(str(safezoneId), [random.randint(0, 255)])
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
def createNewPetFromSeed(self, avId, seed, nameIndex, gender, safeZoneId):
|
|
|
|
av = self.air.doId2do[avId]
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
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
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
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}
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
def response(doId):
|
|
|
|
if not doId:
|
|
|
|
self.air.notify.warning("Cannot create pet for %s!" % avId)
|
|
|
|
return
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
self.air.writeServerEvent('bought-pet', avId, doId)
|
|
|
|
av.b_setPetId(doId)
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
self.air.dbInterface.createObject(self.air.dbId, self.air.dclassesByName['DistributedPetAI'],
|
|
|
|
{k: (v,) for k,v in fields.items()}, response)
|
2015-04-27 23:24:58 -05:00
|
|
|
|
2015-03-29 10:41:02 -05:00
|
|
|
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()
|
2015-05-13 11:54:42 -05:00
|
|
|
av.b_setPetId(0)
|