1.4.3 • Published 8 months ago

@dicelette/core v1.4.3

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
8 months ago

@Core

The core module for Dicelette, contains :

  • The dice function (that parse the string into a Dice Parser and send the result in a good message) ;
  • The verification of the template

The two are used in the bot and documentation.

Type alias

  • Sign: "+" | "-" | "*" | "/" | "%" | "^" | "**";
  • Statistic : { [name: string]: { combinaison?: string; max?: number; min?: number; } } :
    • name: string : The name of the statistic
    • combinaison: string : A combinaison between multiple/other statistic, formula... (ex: constitution+2). Can't coexist with min & max.
    • max: number : The maximum value of the statistic
    • min: number : The minimum value of the statistic

Interface (index.d.ts)

Compare

  • sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "=="
  • value: number

Critical

  • Optional failure: number
  • Optional success: number

Modifier

  • sign: Sign
  • value: number

Resultat

  • Optional comment: string
  • Optional compare: Compare
  • dice: string
  • Optional modifier: Modifier
  • result: string

Statistical Template

Example

diceType: "1d20+{{$}}>=20"

The dice throw will be 1d20 + statistique that must be less than 20

diceType: "1d20<=$"

The dice throw will be 1d20 that must be less than the statistic

Properties

  • Optional charName: boolean Allow to force the user to choose a name for them characters

  • Optional critical: Critical How the success/echec will be done

  • Optional damage: { [name: string]: string } Special dice for damage

  • Optional diceType: string A die type in the notation supported by the bot. See documentation for syntaxe.

  • Optional statistics: Statistic

  • Optional total: number A total can be set, it allows to calculate the total value of a future register member If the sum of the value > total, the bot will send a message to the user to inform him that the total is exceeded and an error will be thrown Note: Statistic that have a formula will be ignored from the total

Modules

Dice

Variables

  • const COMMENT_REGEX: RegExp

Functions

calculator(sign, value, total): number

Evaluate a formula and replace "^" by "**" if any

NameType
signSign
valuenumber
totalnumber

roll(dice): Resultat | undefined

Parse the string provided and turn it as a readable dice for dice parser

NameTypeDescription
dicestring{string}

Utils

cleanedDice(dice): string

Replace the ++ +- -- by their proper value:

  • ++ = +
  • +- = -
  • -- = +
NameTypeDescription
dicestring{string}

escapeRegex(string): string

Escape regex string

NameTypeDescription
stringstring{string}

generateStatsDice(originalDice, stats?): string

Replace the stat name by their value using stat and after evaluate any formula using replaceFormulaInDice

NameTypeDescription
originalDicestring{dice}
stats?Object{name: string: number}

replaceFormulaInDice(dice, stats): string

Replace the {{}} in the dice string and evaluate the interior if any

NameTypeDescription
dicestring{string}

Verify Template

diceRandomParse(value, template): string

Generate a random dice and remove the formula (+ evaluate it) Used for diceDamage only

NameTypeDescription
valuestring{string}
templateStatisticalTemplate{StatisticalTemplate}

diceTypeRandomParse(dice, template): string

NameTypeDescription
dicestring{string}
templateStatisticalTemplate{StatisticalTemplate}

evalCombinaison(combinaison, stats): Object

Random the combinaison and evaluate it to check if everything is valid

NameTypeDescription
combinaisonObject{name: string: string}
statsObject{name: string: string|number}

evalOneCombinaison(combinaison, stats): any

Evaluate one selected combinaison

NameTypeDescription
combinaisonstring{string}
statsObject{name: string: string|number}

evalStatsDice(testDice, stats?): string

Verify if the provided dice work with random value

NameTypeDescription
testDicestring{string}
stats?Object{name: string: number}

generateRandomStat(total?, max?, min?): number

NameTypeDefault value
totalundefined | number100
max?numberundefined
min?numberundefined

testCombinaison(template): void

Test all combinaison with generated random value

NameType
templateStatisticalTemplate

testDamageRoll(template): void

Test each damage roll from the template.damage

NameType
templateStatisticalTemplate

verifyTemplateValue(template): StatisticalTemplate

Parse the provided JSON and verify each field to check if everything could work when rolling

NameType
templateany
1.4.3

8 months ago

1.4.2

8 months ago

1.4.1

8 months ago

1.3.0

8 months ago

1.2.2

8 months ago

1.2.0

1 year ago

1.1.4

1 year ago

1.2.1

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago