Skip to content

Commit

Permalink
feat: update to wakfu 1.85
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlotteAuHaras committed Nov 29, 2024
1 parent 615d451 commit 54a768b
Show file tree
Hide file tree
Showing 62 changed files with 687 additions and 159,645 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout project sources
uses: actions/checkout@v4
uses: actions/checkout@v4.2.2

- name: Setup Gradle
uses: gradle/[email protected]
uses: gradle/actions/setup-gradle@v4

- name: Verify everything is working fine
run: ./gradlew test
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v4.2.2

- name: Setup Gradle
uses: gradle/[email protected]
uses: gradle/actions/setup-gradle@v4

- name: Create Jars
run: ./gradlew jar

- name: Run Conveyor
uses: hydraulic-software/conveyor/actions/build@v14.3
uses: hydraulic-software/conveyor/actions/build@v15.1
env:
OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion autobuilder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
implementation(platform(libs.kotlinx.coroutine.bom))
implementation(libs.kotlinx.coroutine.core)
implementation(libs.kotlinx.serialization.json)
implementation("com.github.ajalt.clikt:clikt:5.0.0")
implementation("com.github.ajalt.clikt:clikt:5.0.1")
implementation("com.github.ajalt.mordant:mordant:3.0.0")
implementation("io.github.oshai:kotlin-logging-jvm:7.0.0")
implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1")
Expand Down
20 changes: 10 additions & 10 deletions autobuilder/src/main/kotlin/me/chosante/autobuilder/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import com.github.ajalt.mordant.widgets.progress.progressBar
import com.github.ajalt.mordant.widgets.progress.progressBarContextLayout
import com.github.ajalt.mordant.widgets.progress.text
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlin.system.exitProcess
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.buffer
Expand Down Expand Up @@ -85,12 +88,9 @@ import me.chosante.common.Equipment
import me.chosante.common.Rarity
import me.chosante.common.skills.Assignable
import me.chosante.createZenithBuild
import kotlin.system.exitProcess
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

private val logger = KotlinLogging.logger {}
internal const val VERSION = "1.84.1.25"
internal const val VERSION = "1.85.1.29"

fun main(args: Array<String>) = WakfuAutobuild().main(args)

Expand Down Expand Up @@ -185,25 +185,25 @@ HUPPERMAGE"""
"--max-rarity",
"--rarete-max",
help =
"Used to tell the algorithm to not take items into account that above this rarity, " +
"here the list of value possible in order: ${Rarity.entries}"
"Used to tell the algorithm to not take items into account that above this rarity, " +
"here the list of value possible in order: ${Rarity.entries}"
).convert { Rarity.valueOf(it.uppercase()) }
.default(Rarity.EPIC)

private val forceItems: List<String> by option(
"--items-a-force",
"--forced-items",
help =
"Used to tell the algorithm to force specific items to be in the final build," +
" the names have to be French for now, can be used like that: --forced-items 'Gelano','Amulette du Bouftou',..."
"Used to tell the algorithm to force specific items to be in the final build," +
" the names have to be French for now, can be used like that: --forced-items 'Gelano','Amulette du Bouftou',..."
).split(",").default(listOf())

private val excludedItems: List<String> by option(
"--items-a-exclure",
"--excluded-items",
help =
"Used to tell the algorithm to exclude specific items to not be in the final build," +
" the names have to be in french for now, can be used like that: --excluded-items 'Gelano','Amulette du Bouftou',..."
"Used to tell the algorithm to exclude specific items to not be in the final build," +
" the names have to be in french for now, can be used like that: --excluded-items 'Gelano','Amulette du Bouftou',..."
).split(",").default(listOf())

private val paWanted: TargetStat? by option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ data class BuildCombination(
fun isValid(): Boolean {
val numberOfEquipmentByType = equipments.groupingBy { it.itemType }.eachCount()
if (numberOfEquipmentByType.any { (key, count) ->
count > 1 && key != ItemType.RING || count > 2
}
count > 1 && key != ItemType.RING || count > 2
}
) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.chosante.autobuilder.domain

import me.chosante.common.Characteristic
import java.math.RoundingMode
import me.chosante.common.Characteristic

class TargetStats(
targetStats: List<TargetStat>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package me.chosante.autobuilder.genetic

import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import java.math.BigDecimal
import java.math.RoundingMode
import java.time.Instant
import kotlin.math.floor
import kotlin.time.Duration
import kotlin.time.toKotlinDuration
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

internal class GeneticAlgorithm<T>(
var population: Collection<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.chosante.autobuilder.genetic.wakfu

import kotlin.random.Random
import me.chosante.autobuilder.domain.BuildCombination
import me.chosante.common.ItemType
import me.chosante.common.Rarity
import kotlin.random.Random

fun cross(parents: Pair<BuildCombination, BuildCombination>): BuildCombination {
val (parent1, parent2) = parents
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package me.chosante.autobuilder.genetic.wakfu

import me.chosante.autobuilder.domain.BuildCombination
import me.chosante.autobuilder.domain.TargetStat
import me.chosante.autobuilder.domain.TargetStats
import me.chosante.common.Characteristic
import java.math.BigDecimal
import java.math.MathContext
import java.math.RoundingMode
import kotlin.math.min
import kotlin.math.roundToInt
import me.chosante.autobuilder.domain.BuildCombination
import me.chosante.autobuilder.domain.TargetStat
import me.chosante.autobuilder.domain.TargetStats
import me.chosante.common.Characteristic

object FindClosestBuildFromInputScoring {
fun computeScore(
Expand Down Expand Up @@ -151,11 +151,11 @@ fun computeCharacteristicsValues(
Characteristic.ACTION_POINT to (
characteristicsGivenByEquipmentCombination[Characteristic.MAX_ACTION_POINT]
?: 0
),
),
Characteristic.MOVEMENT_POINT to (
characteristicsGivenByEquipmentCombination[Characteristic.MAX_MOVEMENT_POINT]
?: 0
),
),
Characteristic.WAKFU_POINT to (characteristicsGivenByEquipmentCombination[Characteristic.MAX_WAKFU_POINTS] ?: 0)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
package me.chosante.autobuilder.genetic.wakfu

import java.math.BigDecimal
import java.math.RoundingMode
import me.chosante.autobuilder.domain.BuildCombination
import me.chosante.autobuilder.domain.TargetStats
import me.chosante.common.Characteristic
import java.math.BigDecimal
import java.math.RoundingMode

object FindMostMasteriesFromInputScoring {
private val characteristicsToCheckBeforeCheckingMasteries =
listOf(
Characteristic.ACTION_POINT,
Characteristic.CONTROL,
Characteristic.MOVEMENT_POINT,
Characteristic.RANGE,
Characteristic.WAKFU_POINT,
Characteristic.CRITICAL_HIT,
Characteristic.HP,
Characteristic.LOCK,
Characteristic.DODGE,
Characteristic.BLOCK_PERCENTAGE,
Characteristic.GIVEN_ARMOR_PERCENTAGE,
Characteristic.RECEIVED_ARMOR_PERCENTAGE,
Characteristic.INITIATIVE,
Characteristic.RESISTANCE_BACK,
Characteristic.RESISTANCE_CRITICAL
)

private val masteryCharacteristicsWithoutElementaries =
listOf(
Characteristic.MASTERY_BACK,
Characteristic.MASTERY_BERSERK,
Characteristic.MASTERY_CRITICAL,
Characteristic.MASTERY_DISTANCE,
Characteristic.MASTERY_HEALING,
Characteristic.MASTERY_MELEE
)

private val elementaryMasteries =
listOf(
Characteristic.MASTERY_ELEMENTARY_WATER,
Characteristic.MASTERY_ELEMENTARY_FIRE,
Characteristic.MASTERY_ELEMENTARY_EARTH,
Characteristic.MASTERY_ELEMENTARY_WIND
)

fun computeScore(
targetStats: TargetStats,
buildCombination: BuildCombination,
Expand All @@ -25,106 +62,53 @@ object FindMostMasteriesFromInputScoring {
.sumOf { targetStat ->
val weight = targetStats.weight(targetStat)
val actualScore =
when (targetStat.characteristic) {
in
listOf(
Characteristic.ACTION_POINT,
Characteristic.CONTROL,
Characteristic.MOVEMENT_POINT,
Characteristic.RANGE,
Characteristic.WAKFU_POINT,
Characteristic.CRITICAL_HIT,
Characteristic.HP,
Characteristic.LOCK,
Characteristic.DODGE,
Characteristic.BLOCK_PERCENTAGE,
Characteristic.GIVEN_ARMOR_PERCENTAGE,
Characteristic.RECEIVED_ARMOR_PERCENTAGE,
Characteristic.INITIATIVE,
Characteristic.RESISTANCE_BACK,
Characteristic.RESISTANCE_CRITICAL
),
-> (actualCharacteristicsValues[targetStat.characteristic] ?: 0) * weight

else -> 0.0
if (targetStat.characteristic in characteristicsToCheckBeforeCheckingMasteries) {
(actualCharacteristicsValues[targetStat.characteristic] ?: 0) * weight
} else {
0.0
}
actualScore.coerceAtMost(targetStats.expectedScoreByCharacteristic.getValue(targetStat))
actualScore.coerceAtMost(targetStats.expectedScoreByCharacteristic[targetStat] ?: 0.0)
}.toBigDecimal()
.setScale(4, RoundingMode.FLOOR)

val totalExpectedScore =
targetStats
.filter {
it.characteristic in
listOf(
Characteristic.ACTION_POINT,
Characteristic.CONTROL,
Characteristic.MOVEMENT_POINT,
Characteristic.RANGE,
Characteristic.WAKFU_POINT,
Characteristic.CRITICAL_HIT,
Characteristic.HP,
Characteristic.LOCK,
Characteristic.DODGE,
Characteristic.BLOCK_PERCENTAGE,
Characteristic.GIVEN_ARMOR_PERCENTAGE,
Characteristic.RECEIVED_ARMOR_PERCENTAGE,
Characteristic.INITIATIVE,
Characteristic.RESISTANCE_BACK,
Characteristic.RESISTANCE_CRITICAL
)
}.sumOf {
it.target * targetStats.weight(it)
}.toBigDecimal()
.filter { it.characteristic in characteristicsToCheckBeforeCheckingMasteries }
.sumOf { it.target * targetStats.weight(it) }
.toBigDecimal()
.setScale(4, RoundingMode.FLOOR)

val successPercentageOnAskedCharacteristic =
((totalActualScore.coerceAtLeast(1.0.toBigDecimal()) / totalExpectedScore.coerceAtLeast(1.0.toBigDecimal())) * 100.0.toBigDecimal()).coerceAtMost(100.0.toBigDecimal())
// we calculate a penalty factor to penalize the score if the stats asked are too low compared to the stats we have
val penaltyFactor = (100.0.toBigDecimal().setScale(4) / successPercentageOnAskedCharacteristic.coerceAtLeast(1.0.toBigDecimal())).pow(6)
val targetedStats =
targetStats.filter {
it.characteristic in
listOf(
Characteristic.MASTERY_BACK,
Characteristic.MASTERY_BERSERK,
Characteristic.MASTERY_CRITICAL,
Characteristic.MASTERY_DISTANCE,
Characteristic.MASTERY_HEALING,
Characteristic.MASTERY_MELEE
)

val masteriesStatsWithoutElementary = targetStats.filter { it.characteristic in masteryCharacteristicsWithoutElementaries }
val sumOfMasteriesWithoutElementary =
masteriesStatsWithoutElementary.sumOf {
actualCharacteristicsValues[it.characteristic] ?: 0
}
return targetedStats
.sumOf {
(actualCharacteristicsValues[it.characteristic] ?: 0)
}.let { sumOfMasteriesWithoutElementary ->
val removeNegativeMasteries =
actualCharacteristicsValues.entries.sumOf {
if (it.key in
listOf(
Characteristic.MASTERY_BACK,
Characteristic.MASTERY_CRITICAL,
Characteristic.MASTERY_BERSERK
) &&
it.value < 0
) {
it.value
} else {
0
}
}

val lowestWantedElementaryMasteryValue =
targetStats
.filter {
it.characteristic in
listOf(
Characteristic.MASTERY_ELEMENTARY_WATER,
Characteristic.MASTERY_ELEMENTARY_FIRE,
Characteristic.MASTERY_ELEMENTARY_EARTH,
Characteristic.MASTERY_ELEMENTARY_WIND
)
}.minOfOrNull { (actualCharacteristicsValues[it.characteristic] ?: 0) } ?: 0
((sumOfMasteriesWithoutElementary + lowestWantedElementaryMasteryValue + removeNegativeMasteries).toBigDecimal() / penaltyFactor)
val removeNegativeMasteries =
actualCharacteristicsValues
.filterKeys {
it in listOf(Characteristic.MASTERY_BACK, Characteristic.MASTERY_CRITICAL, Characteristic.MASTERY_BERSERK) && it !in targetStats.map { it.characteristic }
}.filterValues { it < 0 }
.values
.sum()

val lowestWantedElementaryMasteryValue =
if (targetStats.any { it.characteristic == Characteristic.MASTERY_ELEMENTARY }) {
elementaryMasteries.minOfOrNull { actualCharacteristicsValues[it] ?: 0 } ?: 0
} else {
targetStats
.filter { it.characteristic in elementaryMasteries }
.minOfOrNull { actualCharacteristicsValues[it.characteristic] ?: 0 } ?: 0
}

// Combine sums and adjust for negative mastery penalties
val finalMasteryScore = sumOfMasteriesWithoutElementary + lowestWantedElementaryMasteryValue + removeNegativeMasteries

return (finalMasteryScore.toBigDecimal() / penaltyFactor)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.chosante.autobuilder.genetic.wakfu

import kotlin.random.Random.Default.nextInt
import me.chosante.autobuilder.domain.BuildCombination
import me.chosante.autobuilder.domain.TargetStats
import me.chosante.common.Equipment
Expand All @@ -11,7 +12,6 @@ import me.chosante.common.skills.Luck
import me.chosante.common.skills.Major
import me.chosante.common.skills.Strength
import me.chosante.common.skills.assignRandomPoints
import kotlin.random.Random.Default.nextInt

fun mutateCombination(
individual: BuildCombination,
Expand Down
Loading

0 comments on commit 54a768b

Please sign in to comment.