def _initDBVals(self, ownerId, name=None, traitSeed=0, dna=None, safeZone=ToontownGlobals.ToontownCentral): self.b_setOwnerId(ownerId) if name is None: name = 'pet%s' % self.doId self.b_setPetName(name) self.b_setTraitSeed(traitSeed) self.b_setSafeZone(safeZone) traits = PetTraits.PetTraits(traitSeed, safeZone) for traitName in PetTraits.getTraitNames(): setter = self.getSetterName(traitName, 'b_set') self.__dict__[setter](traits.getTraitValue(traitName)) self.traits = traits for component in PetMood.PetMood.Components: setterName = self.getSetterName(component, 'b_set') self.__dict__[setterName](0.0) if not dna: dna = PetDNA.getRandomPetDNA() self.setDNA(dna) self.b_setLastSeenTimestamp(self.getCurEpochTimestamp()) for component in PetMood.PetMood.Components: self.setMoodComponent(component, 0.0) self.b_setTrickAptitudes([]) return
def announceGenerate(self): DistributedSmoothNodeAI.DistributedSmoothNodeAI.announceGenerate(self) self._hasCleanedUp = False self.setHasRequestedDelete(False) self.b_setParent(ToontownGlobals.SPHidden) self.lockedDown = 0 self.leashMode = 0 self.leashAvId = None self.leashGoal = None self.traits = PetTraits.PetTraits(self.traitSeed, self.safeZone) if not hasattr(self, '_beingCreatedInDB'): for i in xrange(len(self.traitList)): value = self.traitList[i] if value == 0.0: traitName = PetTraits.getTraitNames()[i] traitValue = self.traits.getTraitValue(traitName) DistributedPetAI.notify.info( "%s: initializing new trait '%s' to %s, seed=%s" % (self.doId, traitName, traitValue, self.traitSeed)) setterName = self.getSetterName(traitName, 'b_set') self.__dict__[setterName](traitValue) self.mood = PetMood.PetMood(self) if not self.active: return self.activated = 1 self.announceZoneChange(self.zoneId, ToontownGlobals.QuietZone) self.b_setParent(ToontownGlobals.SPRender) self.setPos(randFloat(-20, 20), randFloat(-20, 20), 0) self.setH(randFloat(360)) if self.initialDNA: self.setDNA(self.initialDNA) for mood, value in self.requiredMoodComponents.items(): self.mood.setComponent(mood, value, announce=0) self.requiredMoodComponents = {} self.brain = PetBrain.PetBrain(self) self.mover = PetMoverAI(self) self.enterPetLook() self.actionFSM = PetActionFSM.PetActionFSM(self) self.teleportIn() self.handleMoodChange(distribute=0) taskMgr.doMethodLater(simbase.petMovePeriod * random.random(), self.move, self.getMoveTaskName()) self.startPosHprBroadcast() self.accept(PetObserve.getEventName(self.zoneId), self.brain.observe) self.accept(self.mood.getMoodChangeEvent(), self.handleMoodChange) self.mood.start() self.brain.start() return
def _initDBVals(self, ownerId, name = None, traitSeed = 0, dna = None, safeZone = ToontownGlobals.ToontownCentral): self.b_setOwnerId(ownerId) if name is None: name = 'pet%s' % self.doId self.b_setPetName(name) self.b_setTraitSeed(traitSeed) self.b_setSafeZone(safeZone) traits = PetTraits.PetTraits(traitSeed, safeZone) for traitName in PetTraits.getTraitNames(): setter = self.getSetterName(traitName, 'b_set') self.__dict__[setter](traits.getTraitValue(traitName)) self.traits = traits for component in PetMood.PetMood.Components: setterName = self.getSetterName(component, 'b_set') self.__dict__[setterName](0.0) if not dna: dna = PetDNA.getRandomPetDNA() self.setDNA(dna) self.b_setLastSeenTimestamp(self.getCurEpochTimestamp()) for component in PetMood.PetMood.Components: self.setMoodComponent(component, 0.0) self.b_setTrickAptitudes([]) return
def __generateDistTraitFuncs(self): for i in xrange(PetTraits.PetTraits.NumTraits): traitName = PetTraits.getTraitNames()[i] getterName = self.getSetterName(traitName, 'get') b_setterName = self.getSetterName(traitName, 'b_set') d_setterName = self.getSetterName(traitName, 'd_set') setterName = self.getSetterName(traitName) def traitGetter(i = i): return self.traitList[i] def b_traitSetter(value, setterName = setterName, d_setterName = d_setterName): self.__dict__[d_setterName](value) self.__dict__[setterName](value) def d_traitSetter(value, setterName = setterName): self.sendUpdate(setterName, [value]) def traitSetter(value, i = i): self.traitList[i] = value self.__dict__[getterName] = traitGetter self.__dict__[b_setterName] = b_traitSetter self.__dict__[d_setterName] = d_traitSetter self.__dict__[setterName] = traitSetter self.__funcsToDelete.append(getterName) self.__funcsToDelete.append(b_setterName) self.__funcsToDelete.append(d_setterName) self.__funcsToDelete.append(setterName)
def __generateDistTraitFuncs(self): for i in xrange(PetTraits.PetTraits.NumTraits): traitName = PetTraits.getTraitNames()[i] getterName = self.getSetterName(traitName, 'get') b_setterName = self.getSetterName(traitName, 'b_set') d_setterName = self.getSetterName(traitName, 'd_set') setterName = self.getSetterName(traitName) def traitGetter(i=i): return self.traitList[i] def b_traitSetter(value, setterName=setterName, d_setterName=d_setterName): self.__dict__[d_setterName](value) self.__dict__[setterName](value) def d_traitSetter(value, setterName=setterName): self.sendUpdate(setterName, [value]) def traitSetter(value, i=i): self.traitList[i] = value self.__dict__[getterName] = traitGetter self.__dict__[b_setterName] = b_traitSetter self.__dict__[d_setterName] = d_traitSetter self.__dict__[setterName] = traitSetter self.__funcsToDelete.append(getterName) self.__funcsToDelete.append(b_setterName) self.__funcsToDelete.append(d_setterName) self.__funcsToDelete.append(setterName)
def __generateDistTraitFuncs(self): for i in xrange(PetTraits.PetTraits.NumTraits): traitName = PetTraits.getTraitNames()[i] setterName = self.getSetterName(traitName) def traitSetter(value, self = self, i = i): self.traitList[i] = value self.__dict__[setterName] = traitSetter self.__funcsToDelete.append(setterName)
def __generateDistTraitFuncs(self): for i in xrange(PetTraits.PetTraits.NumTraits): traitName = PetTraits.getTraitNames()[i] setterName = self.getSetterName(traitName) def traitSetter(value, self=self, i=i): self.traitList[i] = value self.__dict__[setterName] = traitSetter self.__funcsToDelete.append(setterName)
def __init__(self, avatar): self.doId = avatar.doId self.name = avatar.name self.style = avatar.style self.ownerId = avatar.ownerId self.bFake = False self.cr = avatar.cr self.traits = PetTraits.PetTraits(avatar.traitSeed, avatar.safeZone, traitValueList=avatar.traitList) self._grabMood(avatar)
def getPetCostFromSeed(seed, safezoneId): name, dna, traitSeed = getPetInfoFromSeed(seed, safezoneId) traits = PetTraits.PetTraits(traitSeed, safezoneId) traitValue = traits.getOverallValue() traitValue -= 0.3 traitValue = max(0, traitValue) rarity = PetDNA.getRarity(dna) rarity *= 1.0 - traitValue rarity = pow(0.001, rarity) - 0.001 minCost, maxCost = PetConstants.ZoneToCostRange[safezoneId] cost = rarity * (maxCost - minCost) + minCost cost = int(cost) return cost
def generate(self): DistributedObjectAI.DistributedObjectAI.generate(self) self.traits = PetTraits.PetTraits(self.traitSeed, self.safeZone) print self.traits.traits for i in xrange(len(self.traitList)): value = self.traitList[i] if value == 0.0: traitName = PetTraits.getTraitNames()[i] traitValue = self.traits.getTraitValue(traitName) DistributedPetProxyAI.notify.info( "%s: initializing new trait '%s' to %s, seed=%s" % (self.doId, traitName, traitValue, self.traitSeed)) setterName = self.getSetterName(traitName, 'b_set') self.__dict__[setterName](traitValue) self.mood = PetMood.PetMood(self) for mood, value in self.requiredMoodComponents.items(): self.mood.setComponent(mood, value, announce=0) self.requiredMoodComponents = {} self.accept(self.mood.getMoodChangeEvent(), self.handleMoodChange) self.mood.start()
def announceGenerate(self): DistributedSmoothNodeAI.DistributedSmoothNodeAI.announceGenerate(self) self._hasCleanedUp = False self.setHasRequestedDelete(False) self.b_setParent(ToontownGlobals.SPHidden) self.lockedDown = 0 self.leashMode = 0 self.leashAvId = None self.leashGoal = None self.traits = PetTraits.PetTraits(self.traitSeed, self.safeZone) if not hasattr(self, '_beingCreatedInDB'): for i in xrange(len(self.traitList)): value = self.traitList[i] if value == 0.0: traitName = PetTraits.getTraitNames()[i] traitValue = self.traits.getTraitValue(traitName) DistributedPetAI.notify.info("%s: initializing new trait '%s' to %s, seed=%s" % (self.doId, traitName, traitValue, self.traitSeed)) setterName = self.getSetterName(traitName, 'b_set') self.__dict__[setterName](traitValue) self.mood = PetMood.PetMood(self) if not self.active: return self.activated = 1 self.announceZoneChange(self.zoneId, ToontownGlobals.QuietZone) self.b_setParent(ToontownGlobals.SPRender) self.setPos(randFloat(-20, 20), randFloat(-20, 20), 0) self.setH(randFloat(360)) if self.initialDNA: self.setDNA(self.initialDNA) for mood, value in self.requiredMoodComponents.items(): self.mood.setComponent(mood, value, announce=0) self.requiredMoodComponents = {} self.brain = PetBrain.PetBrain(self) self.mover = PetMoverAI(self) self.enterPetLook() self.actionFSM = PetActionFSM.PetActionFSM(self) self.teleportIn() self.handleMoodChange(distribute=0) taskMgr.doMethodLater(simbase.petMovePeriod * random.random(), self.move, self.getMoveTaskName()) self.startPosHprBroadcast() self.accept(PetObserve.getEventName(self.zoneId), self.brain.observe) self.accept(self.mood.getMoodChangeEvent(), self.handleMoodChange) self.mood.start() self.brain.start() return
def announceGenerate(self): DistributedObject.DistributedObject.announceGenerate(self) self.traits = PetTraits.PetTraits(self.traitSeed, self.safeZone) print self.traits.traits self.mood = PetMood.PetMood(self) self.lastKnownMood = self.mood.makeCopy() for mood, value in self.requiredMoodComponents.items(): self.mood.setComponent(mood, value, announce=0) self.requiredMoodComponents = {} DistributedPetProxy.notify.debug('time since last seen: %s' % self.getTimeSinceLastSeen()) self.style = [ self.head, self.ears, self.nose, self.tail, self.bodyTexture, self.color, self.colorScale, self.eyeColor, self.gender ] self.setLastSeenTimestamp(self.lastSeenTimestamp) self.updateOfflineMood() self.sendGenerateMessage = 1
def generate(self): DistributedObjectAI.DistributedObjectAI.generate(self) self.traits = PetTraits.PetTraits(self.traitSeed, self.safeZone) print self.traits.traits for i in xrange(len(self.traitList)): value = self.traitList[i] if value == 0.0: traitName = PetTraits.getTraitNames()[i] traitValue = self.traits.getTraitValue(traitName) DistributedPetProxyAI.notify.info("%s: initializing new trait '%s' to %s, seed=%s" % (self.doId, traitName, traitValue, self.traitSeed)) setterName = self.getSetterName(traitName, 'b_set') self.__dict__[setterName](traitValue) self.mood = PetMood.PetMood(self) for mood, value in self.requiredMoodComponents.items(): self.mood.setComponent(mood, value, announce=0) self.requiredMoodComponents = {} self.accept(self.mood.getMoodChangeEvent(), self.handleMoodChange) self.mood.start()