Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- title: "vard sim"
- author: "jeb"
- date: "8/7/2023"
- output: html_document
- ---
- ```{r constants}
- # lord forgive me for how sloppy this code becomes the further down you scroll
- library(dplyr)
- set.seed(69420)
- # Fang on slash
- # 1-handed weapons assumed to be used with Avernic
- gear_values <- matrix(c(111, 75, 121, 18, 12, 10, 8, 12, 6, 8, 88, 56, 132, 48,
- 104, 110, 134, 0, 0, 15, 10, 0, 20, 0, 109, 57, 132, 49),ncol=14,byrow=TRUE)
- colnames(gear_values) <- c("fang", "scythe", "axe", "torva", "bandos", "torture", "fury", "ultor", "bellator", "berserker", "vw", "claws", "bgs", "dds")
- rownames(gear_values) <- c("strength", "attack")
- str_level <- floor(118 * 1.23) + 3 + 8
- atk_level <- floor(118 * 1.2) + 8
- vard_max_hp <- 700
- vard_base_def <- 215
- vard_slash_def <- 65
- vard_def <- vard_base_def
- vard_lowered_def <- vard_base_def
- ```
- ```{r top level attack functions}
- # the basic attack roll is the same no matter what weapon you use
- # returns TRUE on a hit and FALSE on a miss
- attack <- function(atk_roll_max, vard_hp, weapon) {
- vard_def <- vard_base_def - (floor((vard_max_hp - vard_hp)/10)) # comment out this line to disable vard's defense decay, useful to compare to DPS calc
- # BGS mechanics: assume that if the lowered defense is lower than Vard's naturally decaying defense, it takes priority, but does not stack
- if (vard_lowered_def < vard_def) {
- vard_def <- vard_lowered_def
- }
- def_roll_max <- (vard_def + 9) * (vard_slash_def + 64)
- # these are not ints but it shouldn't really matter
- atk_roll <- runif(1, 0, atk_roll_max)
- def_roll <- runif(1, 0, def_roll_max)
- if (atk_roll > def_roll) {
- return (TRUE)
- }
- # fang rolls again if the first misses
- if (weapon == "fang") {
- atk_roll <- runif(1, 0, atk_roll_max)
- }
- return (atk_roll > def_roll)
- }
- attack_with <- function(gear, hp) {
- if (!is.vector(gear) || length(gear) != 4) {
- stop("must pass gear loadout as a vector of 4 strings")
- }
- # assumes infernal cape, ferocious gloves, and prims for a total 27 strength and 22 attack bonus
- gear_bonuses <- rowSums(gear_values[,gear])
- str_bonus <- gear_bonuses[["strength"]] + 27
- atk_bonus <- gear_bonuses[["attack"]] + 22
- if (gear[1] == "fang") {
- return (attack_with_fang(str_bonus, atk_bonus, hp))
- } else if (gear[1] == "scythe") {
- return (attack_with_scythe(str_bonus, atk_bonus, hp))
- } else if (gear[1] == "axe") {
- return (attack_with_axe(str_bonus, atk_bonus, hp))
- } else {
- stop("must pass fang, scythe, or axe as weapon parameter")
- }
- }
- attack_with_spec <- function(gear, hp) {
- # assumes infernal cape, ferocious gloves, and prims for a total 27 strength and 22 attack bonus
- gear_bonuses <- rowSums(gear_values[,gear])
- str_bonus <- gear_bonuses[["strength"]] + 27
- atk_bonus <- gear_bonuses[["attack"]] + 22
- if (gear[1] == "vw") {
- return (spec_with_vw(str_bonus, atk_bonus, hp))
- } else if (gear[1] == "claws") {
- return (spec_with_claws(str_bonus, atk_bonus, hp))
- } else if (gear[1] == "bgs") {
- return (spec_with_bgs(str_bonus, atk_bonus, hp))
- } else if (gear[1] == "dds") {
- return (spec_with_dds(str_bonus, atk_bonus, hp))
- } else if (gear[1] == "axe") {
- return (spec_with_axe(str_bonus, atk_bonus, hp))
- } else {
- stop("must pass vw, claws, bgs, dds, or axe as weapon parameter in first element of 'gear' vector")
- }
- }
- ```
- ```{r basic autoattacks}
- attack_with_fang <- function(str_bonus, atk_bonus, vard_hp) {
- maxhit <- floor((str_level * (str_bonus + 64) + 320)/640)
- atk_roll_max <- atk_level * (atk_bonus + 64)
- # fang max hit mechanics
- minhit <- floor(0.15 * maxhit)
- maxhit <- maxhit - minhit
- hit <- attack(atk_roll_max, vard_hp, "fang")
- damage <- 0
- if (hit) {
- damage <- sample(minhit:maxhit, 1)
- }
- return (damage)
- }
- attack_with_scythe <- function(str_bonus, atk_bonus, vard_hp) {
- maxhit <- floor((str_level * (str_bonus + 64) + 320)/640)
- minhit <- 0
- atk_roll_max <- atk_level * (atk_bonus + 64)
- # against a single 2x2 enemy, scythe hits twice with both hits rolling accuracy independently and the second hit capped at 1/2 the max hit of the first
- hit <- attack(atk_roll_max, vard_hp, "")
- damage <- 0
- if (hit) {
- damage <- damage + sample(minhit:maxhit, 1)
- }
- hit <- attack(atk_roll_max, vard_hp, "")
- if (hit) {
- damage <- damage + sample(minhit:floor(maxhit/2), 1)
- }
- return (damage)
- }
- attack_with_axe <- function(str_bonus, atk_bonus, vard_hp) {
- # axe passive boosts strength additively with prayer
- str_level <- floor(118 * (1.23 + 0.06 * axe_stacks)) + 3 + 8
- maxhit <- floor((str_level * (str_bonus + 64) + 320)/640)
- minhit <- 0
- atk_roll_max <- atk_level * (atk_bonus + 64)
- hit <- attack(atk_roll_max, vard_hp, "")
- damage <- 0
- if (hit) {
- damage <- sample(minhit:maxhit, 1)
- }
- if (axe_stacks < 5) {
- axe_stacks <<- axe_stacks + 1
- }
- return (damage)
- }
- ```
- ```{r special attacks}
- spec_with_vw <- function(str_bonus, atk_bonus, vard_hp) {
- # voidwaker spec guarantees a hit between 50-150% of its max hit
- maxhit <- floor((str_level * (str_bonus + 64) + 320)/640)
- minhit <- floor(maxhit * 0.5)
- maxhit <- maxhit + minhit
- damage <- sample(minhit:maxhit, 1)
- return (damage)
- }
- spec_with_claws <- function(str_bonus, atk_bonus, vard_hp) {
- maxhit <- floor((str_level * (str_bonus + 64) + 320)/640)
- minhit <- 0
- atk_roll_max <- atk_level * (atk_bonus + 64)
- # Claws roll accuracy up to four times depending on how many hitsplats miss
- # The following is a DPS approximation from the wiki
- # With this implementation it appears to outperform VW which should not be the case
- # but I cba to fix it since we don't know the exact mechanics
- hit <- attack(atk_roll_max, vard_hp, "")
- if (hit) {
- minhit <- maxhit
- maxhit <- 2 * maxhit
- } else {
- hit <- attack(atk_roll_max, vard_hp, "")
- if (hit) {
- minhit <- floor(0.75 * maxhit)
- maxhit <- floor(1.75 * maxhit)
- } else {
- hit <- attack(atk_roll_max, vard_hp, "")
- if (hit) {
- minhit <- floor(0.5 * maxhit)
- maxhit <- floor(1.5 * maxhit)
- } else {
- hit <- attack(atk_roll_max, vard_hp, "")
- if (hit) {
- minhit <- floor(0.25 * maxhit)
- maxhit <- floor(1.25 * maxhit)
- }
- }
- }
- }
- damage <- sample(minhit:maxhit, 1)
- return (damage)
- }
- spec_with_bgs <- function(str_bonus, atk_bonus, vard_hp) {
- maxhit <- floor((str_level * (str_bonus + 64) + 320)/640)
- minhit <- 0
- atk_roll_max <- atk_level * (atk_bonus + 64)
- # BGS spec does 21% more damage and doubles the maximum attack roll
- maxhit <- floor(maxhit * 1.21)
- atk_roll_max <- atk_roll_max * 2
- hit <- attack(atk_roll_max, vard_hp, "")
- damage <- 0
- if (hit) {
- damage <- sample(minhit:maxhit, 1)
- }
- vard_lowered_def <<- vard_def - damage
- return (damage)
- }
- spec_with_dds <- function(str_bonus, atk_bonus, vard_hp) {
- maxhit <- floor((str_level * (str_bonus + 64) + 320)/640)
- minhit <- 0
- atk_roll_max <- atk_level * (atk_bonus + 64)
- # DDS spec does 15% more damage with a 15% higher maximum attack roll
- maxhit <- floor(maxhit * 1.15)
- atk_roll_max <- atk_roll_max * 1.15
- hit <- attack(atk_roll_max, vard_hp, "")
- damage <- 0
- if (hit) {
- damage <- damage + sample(minhit:maxhit, 1)
- }
- hit <- attack(atk_roll_max, vard_hp, "")
- if (hit) {
- damage <- damage + sample(minhit:maxhit, 1)
- }
- return (damage)
- }
- spec_with_axe <- function(str_bonus, atk_bonus, vard_hp) {
- # axe spec boosts strength additively with prayer
- str_level <- floor(118 * (1.23 + 0.06 * axe_stacks)) + 3 + 8
- maxhit <- floor((str_level * (str_bonus + 64) + 320)/640)
- minhit <- 0
- atk_roll_max <- atk_level * (atk_bonus + 64)
- # axe spec increases the maximum attack roll by 6% per stack
- atk_roll_max <- atk_roll_max * (1 + 0.06 * axe_stacks)
- hit <- attack(atk_roll_max, vard_hp, "")
- damage <- 0
- if (hit) {
- damage <- sample(minhit:maxhit, 1)
- }
- axe_stacks <<- 0
- return (damage)
- }
- ```
- ```{r farming Vardorvis}
- # given one of the kill_vard functions below,
- # a gear setup of weapon, armor, ring, and optional spec weapon,
- # and a total N number of kills to be done,
- # returns the average time (in seconds) to kill Vard with that setup
- farm_vard <- function(FUN, gear, N) {
- TTK <- 0
- for(i in 1:N) {
- TTK <- TTK + FUN(gear)
- }
- return(TTK / N)
- }
- # given a gear setup, kills vard once
- kill_vard <- function(gear) {
- time <- 0
- hp <- vard_max_hp
- vard_lowered_def <- vard_base_def
- axe_stacks <<- 0
- while (hp > 0) {
- hp <- hp - attack_with(gear, hp)
- time <- time + 5
- }
- # the last hit kills vard instantly, we do not need to wait for its cooldown
- time <- time - 4
- return (time*0.6)
- }
- # given a gear setup and either vw or claws as gear[5], kills vard once by speccing immediately
- kill_vard_spec_start <- function(gear) {
- time <- 0
- hp <- vard_max_hp
- vard_lowered_def <<- vard_base_def
- axe_stacks <<- 0
- hp <- hp - attack_with_spec(gear[c(5, 2, 3, 4)], hp)
- time <- time + 4
- if(gear[5] == "bgs") {
- time <- time + 2
- }
- while (hp > 0) {
- hp <- hp - attack_with(gear[-5], hp)
- time <- time + 5
- }
- time <- time - 4
- return (time*0.6)
- }
- # given a gear setup and either vw or claws as gear[5], kills vard once by speccing once vard is < 200 HP
- kill_vard_spec_enrage <- function(gear) {
- time <- 0
- hp <- vard_max_hp
- vard_lowered_def <<- vard_base_def
- axe_stacks <<- 0
- has_specced <- FALSE
- while (hp > 0) {
- hp <- hp - attack_with(gear[-5], hp)
- time <- time + 5
- if (hp < 200 && !has_specced) {
- hp <- hp - attack_with_spec(gear[c(5, 2, 3, 4)], hp)
- time <- time + 4
- has_specced <- TRUE
- }
- }
- time <- time - 4
- return (time*0.6)
- }
- # axe spec into spec weapon into scythe switch, supposedly "optimal"
- kill_vard_optimal <- function(gear) {
- time <- 0
- hp <- vard_max_hp
- vard_lowered_def <<- vard_base_def
- axe_stacks <<- 0
- while (hp > 150) {
- hp <- hp - attack_with(gear[-5], hp)
- time <- time + 5
- }
- # axe spec (maxes 77)
- hp <- hp - attack_with_spec(gear[c(1, 2, 3, 4)], hp)
- time <- time + 5
- if(hp <= 0) {
- time <- time - 4
- return (time*0.6)
- }
- # vw spec (maxes 76)
- hp <- hp - attack_with_spec(gear[c(5, 2, 3, 4)], hp)
- time <- time + 4
- if(hp <= 0) {
- time <- time - 3
- return (time*0.6)
- }
- #finish with scythe
- gear <- c("scythe", "torva", "bellator", "fury")
- while (hp > 0) {
- hp <- hp - attack_with(gear, hp)
- time <- time + 5
- }
- time <- time - 4
- return (time*0.6)
- }
- # Kills vard switching the main weapon to switchwep at a certain HP threshold. Tests every threshold from 100-200 in multiples of 10
- # and returns the fastest TTK as well as the optimal threshold to switch weapons
- farm_vard_switch_wep <- function(gear, N, switchwep) {
- HPs <- seq(160, 160, 10)
- fastest_TTK <- 69420
- fastest_threshold <- 0
- for(index in 1:length(HPs)) {
- TTK <- 0
- for(i in 1:N) {
- TTK <- TTK + kill_vard_switch_wep(gear, HPs[index], switchwep)
- }
- if(TTK / N < fastest_TTK) {
- fastest_TTK <- TTK / N
- fastest_threshold <- HPs[index]
- }
- }
- return(c(fastest_TTK, fastest_threshold))
- }
- kill_vard_switch_wep <- function(gear, threshold, switchwep) {
- time <- 0
- hp <- vard_max_hp
- vard_lowered_def <<- vard_base_def
- axe_stacks <<- 0
- while (hp > threshold) {
- hp <- hp - attack_with(gear, hp)
- time <- time + 5
- }
- gear <- c(switchwep, "torva", "bellator", "fury")
- while (hp > 0) {
- hp <- hp - attack_with(gear, hp)
- time <- time + 5
- }
- time <- time - 4
- return (time*0.6)
- }
- ```
- ```{r use cases}
- N <- 50000
- sets <- data.frame(
- Weapon = rep(c("fang", "scythe", "axe"), each=6),
- Armor = rep(rep(c("torva", "bandos"), each=3), 3),
- Ring = rep(c("bellator", "ultor", "berserker"), 6),
- stringsAsFactors=FALSE
- )
- # This test compares all 18 combinations of weapon, armor, and ring in the dataframe 'sets' and runs N Vardorvis kills each, storing the results in 'sets'
- # TTK: The average time to kill Vardorvis, in seconds
- # DPS: The average damage per second
- TTK <- numeric(nrow(sets))
- DPS <- numeric(nrow(sets))
- for (i in 1:nrow(sets)) {
- gear <- c(t(sets[i,]), "fury")
- time <- farm_vard(kill_vard, gear, N)
- TTK[i] <- time
- DPS[i] <- vard_max_hp / time
- cat(sprintf("Setup %s, %s, %s takes %#.2f seconds\n", gear[1], gear[2], gear[3], time))
- }
- sets2 <- cbind(sets, TTK, DPS)
- # This test assumes torva + bellator, and tests using 1 dragon claws or 1 voidwaker spec along with the fang, scythe, or axe
- # For each combination, it tests the average TTK if you spec at the start of the fight, or if you spec when Vard falls below 200 HP (roughly when he enrages)
- sets_spec <- data.frame(
- Weapon = rep(c("fang", "scythe", "axe"), each=3),
- Spec = rep(c("vw", "claws", "bgs"), 3),
- stringsAsFactors=FALSE
- )
- TTK_spec_start <- numeric(nrow(sets_spec))
- DPS_spec_start <- numeric(nrow(sets_spec))
- TTK_spec_enrage <- numeric(nrow(sets_spec))
- DPS_spec_enrage <- numeric(nrow(sets_spec))
- for (i in 1:nrow(sets_spec)) {
- gear <- c(sets_spec[i,1], "torva", "bellator", "fury", sets_spec[i,2])
- time <- farm_vard(kill_vard_spec_start, gear, N)
- TTK_spec_start[i] <- time
- DPS_spec_start[i] <- vard_max_hp / time
- cat(sprintf("Setup %s, %s (spec start), takes %#.2f seconds\n", gear[1], gear[5], time))
- if(gear[5] == "bgs")
- next
- time <- farm_vard(kill_vard_spec_enrage, gear, N)
- TTK_spec_enrage[i] <- time
- DPS_spec_enrage[i] <- vard_max_hp / time
- cat(sprintf("Setup %s, %s (spec enrage), takes %#.2f seconds\n", gear[1], gear[5], time))
- }
- sets_spec <- cbind(sets_spec, TTK_spec_start, TTK_spec_enrage, old_TTK=sets$TTK[rep(c(1, 7, 13), each=3)])
- sets_spec <- sets_spec %>% mutate(timesave = old_TTK - TTK_spec_start)
- gear <- c("axe", "torva", "bellator", "fury", "vw")
- time <- farm_vard(kill_vard_spec_enrage, gear, N)
- cat(sprintf("Setup %s, %s (spec enrage, axe spec), takes %#.2f seconds\n", gear[1], gear[5], time))
- gear <- c("axe", "torva", "bellator", "fury")
- time <- farm_vard(kill_vard, gear, N) # manually change starting axe_stacks to 3
- cat(sprintf("Setup %s (start with 3 axe stacks), takes %#.2f seconds\n", gear[1], time))
- # Axe spec maxes 77 and VW maxes 76. send both specs at 150 HP and finish with scythe
- gear <- c("axe", "torva", "bellator", "fury", "vw")
- time <- farm_vard(kill_vard_optimal, gear, N)
- cat(sprintf("Setup %s (at 150 HP, axe spec into VW spec into scythe), takes %#.2f seconds\n", gear[1], time))
- gear <- c("fang", "bandos", "berserker", "fury", "bgs")
- time <- farm_vard(kill_vard_spec_start, gear, N)
- cat(sprintf("Setup %s, %s (spec start), takes %#.2f seconds\n", gear[1], gear[5], time))
- # This test finds the optimal threshold at which to switch from fang to scythe and returns the average kill time with this strat
- gear <- c("fang", "torva", "bellator", "fury")
- ret <- farm_vard_switch_wep(gear, 50000, "scythe")
- switch_scythe_ttk <- ret[1]
- switch_scythe_threshold <- ret[2]
- cat(sprintf("The optimal HP to switch from fang to scythe is at %d HP. The average time to kill is %f\n", ret[2], ret[1]))
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement