njlyon0/dndR

Level calculator function

Closed this issue · 10 comments

Some time ago I wrote a function for calculating player level from the XP gained. I think it could be a nice addition to your package.

Sounds like it could be a great fit! If you'd like to send me what you have I'd gladly add you as a contributor and link your professional website / profile (see the DESCRIPTION file for how I added someone else who added a function)

Hmm, I'm not seeing the file in that comment. If it is a short function you could just paste the code in the script into the Issue comment and I can port it from there back to a .R file on my end?

library(dplyr)

Create Character Advancement Table

XP_table <- data.frame(matrix(ncol = 3, nrow = 20)) %>%
rename(XP = 1, Level = 2, Proficiency = 3) %>%
mutate(XP = c(0, 300, 900, 2700, 6500, 14000, 23000, 34000,
48000, 64000, 85000, 100000, 120000, 140000,
165000, 195000, 225000, 265000, 305000, 355000),
Level = seq(1:20),
Proficiency = rep(c("+2", "+3", "+4", "+5", "+6"), each = 4))

Create Level Calculator function

level.calc <- function(XP){

if(is.numeric(XP) == TRUE){

for (i in 1:length(XP_table$XP)) {
  
  if (XP <= XP_table$XP[i]){
    
    print(paste("Level", max(XP_table$Level[XP_table$XP <= XP]), sep = " "))
    
    break
    
  }else{
    
    if (XP > XP_table$XP[20]){
      
      print("Level 20")
      
      break
    }
  }
}

}else{

stop("XP must be numeric")

}
}

I don't know exactly how to fix the formatting, but since it is not a long function, I think it is not a big problem.

Looks great, I'll get to integrating it right away! Two quick follow-up questions for you:

  1. How do you want your name listed in the DESCRIPTION?
  2. Do you have a website and/or ORCID that you want listed in the DESCRIPTION next to your name?

person(given = "Humberto",
family = "Nappo",
role = "ctb",
comment = c(ORCID = "0000-0001-7810-1635"))

I do not have a website that is worth adding.

Great! What is the URL to your website?

Also, what are the digits of your ORCID (should be sixteen numbers in four groups of four)?

Just edited the previous message. I could sware I had pasted the ORCID code but apparently I did not (or the machines are just messing with me these days). And I actually forgot the "not" in the last phrase (my english is not the sharpest, you see).

Looks good to me! Your function (now named pc_level_calc to better fit the naming convention of the other functions) is fully integrated into dndR and you are credited by name in the DESCRIPTION and README.

I'll close this issue now but thanks so much for contributing your function!