Skip to content

Commit

Permalink
Initial web UI, refactoring to support JSExport limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
secretbis committed Feb 17, 2021
1 parent 1fdb3ae commit 00a7123
Show file tree
Hide file tree
Showing 7,047 changed files with 18,755 additions and 405 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
55 changes: 55 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: build-and-publish


on:
push:
branches: [ main ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

# JDK/Gradle
- name: Set up JDK 14
uses: actions/setup-java@v1
with:
java-version: 14
- uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Kotlin Build
run: ./gradlew build

# NPM/UI
- uses: actions/setup-node@v2
with:
node-version: '12'
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: npm install
run: npm install
working-directory: ./ui
- name: npm build
run: npm run build
working-directory: ./ui

# Ship to gh-pages
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./ui/build
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
Expand Down Expand Up @@ -59,7 +58,11 @@ kotlin {
})
}

browser()
browser {
webpackTask {
output.libraryTarget = "commonjs2"
}
}

binaries.executable().forEach { binary ->
// Looks like we don't need this task anymore?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ open class ChainLightning : Ability() {
val mq = sim.subject.klass.talents[MentalQuickness.name] as MentalQuickness?
val mqRed = mq?.instantManaCostReduction() ?: 0.0

val eleFocus = sim.buffs.find { it.name == ElementalFocus.name }
val eleFocus = sim.buffs[ElementalFocus.name]
val elefRed = if(eleFocus != null) { 0.40 } else 0.0

return General.resourceCostReduction(760.0, listOf(cvRed, mqRed, elefRed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class EarthShock : Ability() {
val mq = sim.subject.klass.talents[MentalQuickness.name] as MentalQuickness?
val mqRed = mq?.instantManaCostReduction() ?: 0.0

val shFocus = sim.buffs.find { it.name == ShamanisticFocus.name }
val shFocus = sim.buffs[ShamanisticFocus.name]
val shfRed = if(shFocus != null) { 0.60 } else 0.0

val eleFocus = sim.buffs.find { it.name == ElementalFocus.name }
val eleFocus = sim.buffs[ElementalFocus.name]
val elefRed = if(eleFocus != null) { 0.40 } else 0.0

return General.resourceCostReduction(535.0, listOf(cvRed, mqRed, shfRed, elefRed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ElementalMastery : Ability() {
override val name: String = Companion.name

override fun gcdMs(sim: SimIteration): Int = 0
override fun cooldownMs(sim: SimIteration): Int = 180000

private fun makeProc(buff: Buff): Proc {
return object : Proc() {
Expand All @@ -40,7 +41,7 @@ class ElementalMastery : Ability() {
}

val emBuff = object : Buff() {
override val name: String = Companion.name
override val name: String = "${Companion.name} (static)"
override val durationMs: Int = -1
override val hidden: Boolean = true
override val maxCharges: Int = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class FlameShock : Ability() {
val mq = sim.subject.klass.talents[MentalQuickness.name] as MentalQuickness?
val mqRed = mq?.instantManaCostReduction() ?: 0.0

val shFocus = sim.buffs.find { it.name == ShamanisticFocus.name }
val shFocus = sim.buffs[ShamanisticFocus.name]
val shfRed = if(shFocus != null) { 0.60 } else 0.0

val eleFocus = sim.buffs.find { it.name == ElementalFocus.name }
val eleFocus = sim.buffs[ElementalFocus.name]
val elefRed = if(eleFocus != null) { 0.40 } else 0.0

return General.resourceCostReduction(500.0, listOf(cvRed, mqRed, shfRed, elefRed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class LightningBolt : Ability() {
val mq = sim.subject.klass.talents[MentalQuickness.name] as MentalQuickness?
val mqRed = mq?.instantManaCostReduction() ?: 0.0

val eleFocus = sim.buffs.find { it.name == ElementalFocus.name }
val eleFocus = sim.buffs[ElementalFocus.name]
val elefRed = if(eleFocus != null) { 0.40 } else 0.0

return General.resourceCostReduction(300.0, listOf(cvRed, mqRed, elefRed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WindfuryWeapon(sourceItem: Item) : ItemBuff(listOf(sourceItem)) {
return WindfuryWeaponState()
}

override val name = "Windfury Weapon"
override val name = "Windfury Weapon (static) $sourceItem"
override val durationMs: Int = 30 * 60 * 1000
override val hidden: Boolean = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Flurry(currentRank: Int) : Talent(currentRank) {
}

val wrapper = object : Buff() {
override val name: String = Companion.name
override val name: String = "${Companion.name} (static)"
override val durationMs: Int = -1
override val hidden: Boolean = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UnleashedRage(currentRank: Int) : Talent(currentRank) {
override val maxRank: Int = 5

val buff = object : Buff() {
override val name: String = Companion.name
override val name: String = "${Companion.name} (static)"
override val durationMs: Int = -1
override val hidden: Boolean = true

Expand Down
4 changes: 0 additions & 4 deletions src/commonMain/kotlin/character/classes/warrior/Warrior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import character.classes.warrior.talents.Rampage as RampageTalent
import data.model.Item

class Warrior(talents: Map<String, Talent>) : Class(talents) {
companion object {
const val rampageFlagBuffName = "Rampage (available)"
}

override val baseStats: Stats = Stats(
agility = 154,
intellect = 123,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package character.classes.warrior.abilities

import character.*
import character.classes.warrior.Warrior
import character.classes.warrior.buffs.RampageBase
import data.model.Item
import sim.Event
import character.classes.warrior.talents.Rampage as RampageTalent
Expand All @@ -22,7 +23,7 @@ class Rampage : Ability() {

override fun available(sim: SimIteration): Boolean {
val talented = sim.subject.klass.talents[RampageTalent.name]?.currentRank == 1
val hasTriggerBuff = sim.buffs.find { it.name == Warrior.rampageFlagBuffName } != null
val hasTriggerBuff = sim.buffs[RampageBase.rampageFlagBuff.name] != null
return talented && hasTriggerBuff && super.available(sim)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import sim.Event
import sim.SimIteration

class RampageBase : Buff() {
companion object {
// This is just a marker to tell the rotation that we can cast Rampage
val rampageFlagBuff = object : Buff() {
override val name: String = "Rampage (available)"
override val durationMs: Int = 3000 // TODO: 1 server tick? Needs confirmation
override val hidden: Boolean = true
}
}
override val name: String = "Rampage (base)"
override val durationMs: Int = -1
override val hidden: Boolean = true

// This is just a marker to tell the rotation that we can cast Rampage
val canUseBuff = object : Buff() {
override val name: String = Warrior.rampageFlagBuffName
override val durationMs: Int = 3000 // TODO: 1 server tick? Needs confirmation
override val hidden: Boolean = true
}

// On crit, proc the buff that lets us use Rampage
val proc = object : Proc() {
override val triggers: List<Trigger> = listOf(
Expand All @@ -30,7 +31,7 @@ class RampageBase : Buff() {
override val type: Type = Type.STATIC

override fun proc(sim: SimIteration, items: List<Item>?, ability: Ability?, event: Event?) {
sim.addBuff(canUseBuff)
sim.addBuff(rampageFlagBuff)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/data/abilities/raid/SunderArmor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SunderArmor : Ability() {
override val hidden: Boolean = true

override fun modifyStats(sim: SimIteration): Stats? {
val impEaActive = sim.debuffs.find { it.name == "Improved Expose Armor" } != null
val impEaActive = sim.debuffs[ImprovedExposeArmor.name] != null
return if(impEaActive) {
null
} else {
Expand Down
24 changes: 13 additions & 11 deletions src/commonMain/kotlin/data/buffs/BSHammerHaste.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ import sim.SimIteration
// Same for all the hammers
class BSHammerHaste(val sourceItem: Item) : ItemBuff(listOf(sourceItem)) {
override val id: Int = 21165
override val name: String = "Haste (BS Hammer)"
override val name: String = "Haste (BS Hammer) (static) $sourceItem"
override val durationMs: Int = -1
override val hidden: Boolean = true

private fun makeName(sim: SimIteration): String {
val suffix = if (sourceItem === sim.subject.gear.mainHand) {
"(MH)"
} else if (sourceItem === sim.subject.gear.offHand) {
"(OH)"
} else {
throw IllegalArgumentException("BSHammerHaste can only be applied to weapons")
}
return "Haste (BS Hammer) $suffix".trim()
}

private var _procs: List<Proc>? = null
private fun makeProcs(sim: SimIteration): List<Proc> {
if(_procs == null) {
Expand All @@ -33,16 +44,7 @@ class BSHammerHaste(val sourceItem: Item) : ItemBuff(listOf(sourceItem)) {

val buff = object : Buff() {
override val name: String
get() {
val suffix = if (sourceItem === sim.subject.gear.mainHand) {
"(MH)"
} else if (sourceItem === sim.subject.gear.offHand) {
"(OH)"
} else {
throw IllegalArgumentException("BSHammerHaste can only be applied to weapons")
}
return "Haste (BS Hammer) $suffix".trim()
}
get() = makeName(sim)

override val durationMs: Int = 10000

Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/data/buffs/RageOfTheUnraveller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import sim.SimIteration

class RageOfTheUnraveller : Buff() {
override val id: Int = 33648
override val name: String = "Rage of the Unraveller"
override val name: String = "Rage of the Unraveller (static)"
override val durationMs: Int = -1
override val hidden: Boolean = true

Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/data/enchants/Mongoose.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sim.SimIteration
// Fun blog about Goose and Executioner:
// https://warcraft.blizzplanet.com/blog/comments/world_of_warcraft_burning_crusade___enchanting___executioner_vs_mongoose
class Mongoose(val item: Item) : ItemBuff(listOf(item)) {
override val name: String = "Mongoose (enchant)"
override val name: String = "Mongoose (static) $item"
override val durationMs: Int = -1
override val hidden: Boolean = true

Expand Down
22 changes: 11 additions & 11 deletions src/commonMain/kotlin/sim/Sim.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ import kotlin.time.ExperimentalTime
@ExperimentalTime
class Sim (
val config: Config,
val opts: SimOptions
val opts: SimOptions,
val progressCb:(SimProgress) -> Unit
) {
val logger = KotlinLogging.logger {}

suspend fun sim() {
suspend fun sim(): List<SimIteration> {
// Iteration coroutines
val startTime = Clock.System.now()

val iterations = (1..opts.iterations).map {
GlobalScope.async(Dispatchers.Default) {
GlobalScope.async {
progressCb(SimProgress(
opts,
it
))

iterate(it)
}
}.awaitAll()

val endTime = Clock.System.now()
val totalTime = endTime.minus(startTime).inMilliseconds
val totalTime = endTime.minus(startTime).inSeconds
println("Completed ${iterations.size} iterations in $totalTime seconds")

// Stats
SimStats.resourceUsage(iterations, config.character.klass.resourceType)
SimStats.resultsByBuff(iterations)
SimStats.resultsByDebuff(iterations)
SimStats.resultsByDamageType(iterations)
SimStats.resultsByAbility(iterations)
SimStats.dps(iterations)
return iterations
}

private fun iterate(num: Int) : SimIteration {
Expand Down
20 changes: 20 additions & 0 deletions src/commonMain/kotlin/sim/SimDefaults.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package sim

import kotlin.js.JsExport

@JsExport
object SimDefaults {
// The length of the fight you wish to simulate, in millseconds
const val durationMs: Int = 180000
// Randomly alters the fight duration by adding or subtracting a random number of milliseconds, up to the configured value
// This helps model the real world more effectively, and can better evaluate things like haste effects or potion usage timings
const val durationVaribilityMs: Int = 0
const val stepMs: Int = 1
const val latencyMs: Int = 0
const val iterations: Int = 1000
const val targetLevel: Int = 73
// Per ancient forums, most TBC bosses have 7700 or 6200 armor
const val targetArmor: Int = 7700
const val allowParryAndBlock: Boolean = false
const val showHiddenBuffs: Boolean = false
}
Loading

0 comments on commit 00a7123

Please sign in to comment.