Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
dnd-combat-simulator
Advanced tools
A combat simulator for simple DnD encounters to calculate expected win probabilities.
This package provides an API to simulate simple DnD combat encounters and determine win ratios for the participating parties.
Install using npm
npm i dnd-combat-simulator
The API provides the following interfaces:
const dnd = require('dnd-combat-simulator');
let roll = dnd.dice(dice_type, modifier);
let combatant = new dnd.Combatant(id, hp, ac, initiative, attack_bonus, damage, dmg_dice, dmg_bonus);
let attack = new dnd.Attack(dice_type, dice_number, dmg_bonus);
let party = new dnd.Party();
let combat = new dnd.Combat();
This is a dice rolling utility function, which takes two parameters and an optional options object:
In order to simulate rolling a d8+2 we call the function as follows:
let roll = dnd.dice(8, 2);
This parser can be used to quickly create combatants from data in a csv format. This function takes a single parameter:
This is a constructor for creating combatant objects. It takes eight parameters:
The following three parameters are for the combatants first attack. All attacks are stored in combatant.attacks
.
Adds a new attack to the combatant. Details of the attack object.
Adds a new temporary buff to the combatant. Details of the buff object.
Checks for expired buffs and removes them from the combatant. Is called by combat at the end of a combatants turn and is internally called by combatant before returning an isHit call.
Decrements the remaining time remaining for all active buffs. Is called at the beginning of a combatants turn each round.
Adds a reaction that can trigger once per round on being attacked. Details of the reaction object.
Rolls for initiative and returns the result.
Rolls an attack roll and returns the result.
Checks whether the passed in attack roll hits or not.
Deals the damage passed in to the combatant.
Checks whether the combatant is dead or not.
Resets the combatant to the pre-combat state.
Returns the combatants current hit points taking any active buffs into consideration.
Returns the combatants current armour class taking any active buffs into consideration.
Returns the combatants current initiative taking any active buffs into consideration.
Returns the combatants current attack bonus taking any active buffs into consideration.
The attack constructor takes three parameters:
Rolls for damage and returns the amount of damage dealt.
The buff constructor takes three parameters:
The Reaction constructor takes a trigger function as a parameter. This trigger function is called when checking if reaction is triggered before a hit is applied. The signature of this function must be as follows: triggerFunction(self, atkRoll) : boolean
. It should contain the effect of the reaction (a buff maybe) and the return value should reflect whether or not the reaction was triggered.
The reactions object contains the following prepared trigger functions, which can be used to create reactions:
The party object serves to group multiple combatants together, they will fight together and follow a common party strategy. The members of a party can be accessed through party.members
.
Adds a new combatant to the party, combatants are not required to be unique.
According to party.combatStrategy
a target is selected from the list of combatants. Any function that is a valid compare method taking two combatant objects can be used as a combat strategy. The party object has several pre-built available in party.combatStrategies
.
The combat object is the core of the fight simulation.
Adds a party with a string identifier to the combat. All parties are accessible in combat.parties
.
Rolls initiative for all combatants and sorts them into list accessible in combat.turnList
. The logger parameter must be a function that takes a string, a typical candidate would be console.log
.
Goes through all alive combatants and lets them make attacks. The logger parameter must be a function that takes a string, a typical candidate would be console.log
.
Runs a whole fight and returns a list of the surviving combatants. The objects in the list have the following structure {party_id: string, combatant: combatant, roll: number}
. The logger parameter must be a function that takes a string, a typical candidate would be console.log
.
Checks whether the fight is still ongoing by checking whether there are still valid opponents left.
Returns all survivors after a fight. The same as the output of combat.runFight(logger)
. Could also be used in between rounds.
Resets to the pre-combat state and allows the fight to be simulated from the beginning.
FAQs
A combat simulator for simple DnD encounters to calculate expected win probabilities.
The npm package dnd-combat-simulator receives a total of 1 weekly downloads. As such, dnd-combat-simulator popularity was classified as not popular.
We found that dnd-combat-simulator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.