njlyon0 / dndR

Dungeons & Dragons Functions for Players and Dungeon Masters
https://njlyon0.github.io/dndR/
Other
17 stars 2 forks source link

Level calculator function #11

Closed HumbertoNappo closed 1 year ago

HumbertoNappo commented 1 year ago

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.

njlyon0 commented 1 year ago

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)

HumbertoNappo commented 1 year ago

For some reason I couldn't add the code to the comment, but here it is.

Em qui., 23 de mar. de 2023 às 21:12, Nick J Lyon @.***> escreveu:

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 https://github.com/njlyon0/dndR/blob/main/DESCRIPTION for how I added someone else who added a function)

— Reply to this email directly, view it on GitHub https://github.com/njlyon0/dndR/issues/11#issuecomment-1482075168, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQEPWQWM5VJLAGBMP52JTNDW5TRHLANCNFSM6AAAAAAWF4DJRE . You are receiving this because you authored the thread.Message ID: @.***>

-- Humberto C. Nappo Graduado em Ciências Biológicas e mestrando em Ecologia pela Universidade de Brasília

ORCID ID: https://orcid.org/0000-0001-7810-1635 Lattes CV: http://lattes.cnpq.br/8150109942426326

njlyon0 commented 1 year ago

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?

HumbertoNappo commented 1 year ago

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")

} }

HumbertoNappo commented 1 year ago

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.

njlyon0 commented 1 year ago

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?
HumbertoNappo commented 1 year ago

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

I do not have a website that is worth adding.

njlyon0 commented 1 year ago

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)?

HumbertoNappo commented 1 year ago

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).

njlyon0 commented 1 year ago

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!