@@ -9,6 +9,7 @@ import kotlin.random.Random
99enum class PersonaType (
1010 val weight : Double ,
1111 val grade : PersonaGrade = PersonaGrade .DEFAULT ,
12+ val personaEvolution : PersonaEvolution = PersonaEvolution .nothing,
1213 private var dropRate : String? = null ,
1314) {
1415 GOOSE (1.0 ) {
@@ -1510,7 +1511,7 @@ enum class PersonaType(
15101511 StringBuilder ().moveRandomly(" mole" , id, 40 , " 180s" , 5 , 14.0 )
15111512 .toString()
15121513 },
1513- RABBIT (0.9 ) {
1514+ RABBIT (weight = 0.9 , personaEvolution = PersonaEvolution (weight = 0.001 , PersonaEvolutionType . RABBIT ) ) {
15141515 override fun loadSvg (name : String , animationId : Long , level : Long , mode : Mode ): String {
15151516 return rabbitSvg.replace(" *{act}" , act(animationId))
15161517 .replace(" *{id}" , animationId.toString())
@@ -1530,7 +1531,7 @@ enum class PersonaType(
15301531 StringBuilder ().moveRandomly(" rabbit" , id, 40 , " 180s" , 5 , 10.0 )
15311532 .toString()
15321533 },
1533- RABBIT_BROWN_RUDOLPH (0.007 ) {
1534+ RABBIT_BROWN_RUDOLPH (weight = 0.007 , personaEvolution = PersonaEvolution (weight = 0.01 , PersonaEvolutionType . RABBIT ) ) {
15341535 override fun loadSvg (name : String , animationId : Long , level : Long , mode : Mode ): String {
15351536 return rabbitBrownRudolphSvg.replace(" *{act}" , act(animationId))
15361537 .replace(" *{id}" , animationId.toString())
@@ -1570,7 +1571,7 @@ enum class PersonaType(
15701571 StringBuilder ().moveRandomly(" rabbit" , id, 40 , " 180s" , 5 , 10.0 )
15711572 .toString()
15721573 },
1573- RABBIT_TUBE (0.01 ) {
1574+ RABBIT_TUBE (weight = 0.01 , personaEvolution = PersonaEvolution (weight = 0.02 , PersonaEvolutionType . RABBIT ) ) {
15741575 override fun loadSvg (name : String , animationId : Long , level : Long , mode : Mode ): String {
15751576 return rabbitTubeSvg.replace(" *{act}" , act(animationId))
15761577 .replace(" *{id}" , animationId.toString())
@@ -2352,6 +2353,14 @@ enum class PersonaType(
23522353 }
23532354 }
23542355
2356+ fun randomEvolution (): PersonaType {
2357+ val evolutionCandidates = personasPerEvolutionType[personaEvolution.type]
2358+ require(evolutionCandidates.isNullOrEmpty().not ()) {
2359+ " Cannot find evolution candidates. personaType: ${this .name} , evolutionType: ${this .personaEvolution.type} "
2360+ }
2361+ return evolutionCandidates!! .random()
2362+ }
2363+
23552364 companion object {
23562365 private val dropRateFormat = DecimalFormat (" #.##" )
23572366
@@ -2373,6 +2382,30 @@ enum class PersonaType(
23732382 weightedPersonas.shuffled()
23742383 }.value
23752384
2385+ private val personasPerEvolutionType: Map <PersonaEvolutionType , List <PersonaType >> = lazy {
2386+ val weightedEvolutionPersonas = PersonaEvolutionType .entries.filterNot {
2387+ it == PersonaEvolutionType .NOTHING
2388+ }.associateWith { mutableListOf<PersonaType >() }
2389+
2390+ entries.filterNot {
2391+ it.personaEvolution == PersonaEvolution .nothing
2392+ }.forEach { personaType ->
2393+ val personaTypes = weightedEvolutionPersonas.getOrElse(personaType.personaEvolution.type) {
2394+ mutableListOf ()
2395+ }
2396+
2397+ repeat((personaType.personaEvolution.weight * 1000 ).toInt()) {
2398+ personaTypes.add(personaType)
2399+ }
2400+ }
2401+
2402+ weightedEvolutionPersonas.forEach { (_, value) ->
2403+ value.shuffle()
2404+ }
2405+
2406+ weightedEvolutionPersonas
2407+ }.value
2408+
23762409 fun random (): PersonaType = personas[Random .nextInt(0 , maxWeight)]
23772410
23782411 private fun StringBuilder.moveRandomly (
0 commit comments