Poodletooth-iLand/toontown/pets/PetUtil.py

30 lines
1 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from toontown.pets import PetDNA, PetTraits, PetConstants
from direct.showbase import PythonUtil
2015-03-29 17:16:26 -05:00
from toontown.toonbase import TTLocalizer
import random
2015-03-03 16:10:12 -06:00
def getPetInfoFromSeed(seed, safezoneId):
2015-03-29 17:16:26 -05:00
S = random.getstate()
random.seed(seed)
dnaArray = PetDNA.getRandomPetDNA(safezoneId)
2015-03-03 16:10:12 -06:00
gender = PetDNA.getGender(dnaArray)
2015-03-29 11:46:50 -05:00
nameString = TTLocalizer.getRandomPetName(gender=gender, seed=seed)
2015-03-03 16:10:12 -06:00
traitSeed = PythonUtil.randUint31()
2015-03-29 17:16:26 -05:00
random.setstate(S)
2015-03-03 16:10:12 -06:00
return (nameString, dnaArray, traitSeed)
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