npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

leviathan-war-functions

v1.2.5

Published

functions for leviathan

Readme

Leviathan Formulas

This library contains various formulas used in the game Leviathan War.

User related Formulas

getLevel(userExp: number, round?: boolean)

This function takes the amount of experience (userExp) as input and returns the user's level. If the optional second parameter, round, is set to true, the function will return the level rounded down to the nearest integer. If round is omitted or false, the function will return the level as a floating-point number.

Example:

getLevel(1000); // returns 2
getLevel(1500, true); // returns 3
getLevel(2000); // returns 3.464

getExp(userLvl: number)

This function takes the user's level (userLvl) as input and returns the experience required for that level.

Example:

getExp(2); // returns 1000
getExp(3); // returns 2000

getExpLeft(userExp: number)

This function takes the user's experience (userExp) as input and returns the amount of experience needed to reach the next level.

Example:

getExpLeft(1000); // returns 1000
getExpLeft(1500); // returns 500

reductionProductivity(coordination: number, pro: boolean, happiness: number)

This function calculates the reduction in productivity based on coordination, whether the user is a professional (pro), and happiness. It returns a float value representing the reduction in productivity.

Example:

reductionProductivity(10000, true, 50); // returns 0.045
reductionProductivity(10000, false, 50); // returns 0.065

reductionFatigue(coordination: number, pro: boolean, healthSystem: number)

This function calculates the reduction in fatigue based on coordination, whether the user is a professional (pro), and the health system level. It returns a float value representing the reduction in fatigue.

Example:

reductionFatigue(10000, true, 50); // returns 0.045
reductionFatigue(10000, false, 50); // returns 0.065

expPerWork(level: number, education: number, regionHigherEducation: number)

This function calculates the experience gained per work action, considering the user's level, education, and region higher education level. It returns an integer value representing the experience gained per work action.

Example:

expPerWork(10, 50, 100); // returns 5
expPerWork(15, 65, 150); // returns 7

levelStatSecs(strength: number, education: number, stateEducation: number)

This function calculates the level stat in seconds based on the user's strength, education, and state education level. It returns a float value representing the level stat in seconds.

Example:

levelStatSecs(200, 50, 100); // returns 7800
levelStatSecs(150, 40, 50); // returns 4050

War related Functions

Consider the following object that maps the bonus for different types of troops depending on the terrain type of the region wher ethey are attacking or defending.

const terrainBonusTable = {
  forest: {
    tanks: -15,
    planes: -10,
    infantry: 20,
    missiles: -5
  },
  desert: {
    tanks: 3,
    planes: 3,
    infantry: 5,
    missiles: 2
  },
  hills: {
    tanks: 10,
    planes:15,
    infantry: 10,
    missiles: 15
  },
  jungle: {
    tanks: -10,
    planes: -20,
    infantry: 5,
    missiles: -20
  },
  marsh: {
    tanks: -15,
    planes: 10,
    infantry: -5,
    missiles: 10
  },
  mountains: {
    tanks: 20,
    planes: 20,
    infantry: -15,
    missiles: 5
  },
  plains: {
    tanks: 20,
    planes: 20,
    infantry: 10,
    missiles: 20
  },
  urban: {
    tanks: 15,
    planes: -15,
    infantry: 15,
    missiles: -20
  },
}

qtyTroops(coordination: number)

Calculates the number of troops based on the coordination value.

Arguments:

  • coordination (number) - The coordination value used to determine the number of troops.

Returns:

  • (number) - The calculated number of troops.

getDamage(terrainType: string, troopsType: string, level: number, strength: number, troops: number, ``partyBonusType: string, partyBonus: number, militaryBonus: number, warType: string, opponentStateSecurity?: number)

Calculates the damage dealt by a troop based on various factors.

Arguments:

  • terrainType - THE terrain type where the battle occurs.
  • troopsType (string) - The type of troops involved in the battle.
  • level (number) - The level of the troops.
  • strength (number) - The strength of the troops.
  • troops (number) - The number of troops.
  • partyBonusType (string) - The type of party bonus (e.g., "damage").
  • partyBonus (number) - The party bonus value.
  • militaryBonus (number) - The military bonus value.
  • warType (string) - The type of war (e.g., "coupDeEtat", "revolution", "statesWar").
  • opponentStateSecurity? (number, optional) - The opponent's state security value (only required for "coupDeEtat" and "revolution" war types).

Returns:

  • (number) - The calculated damage dealt by the troops

costGun(factoryLvl: number, pMissiles: number)

Calculates the cost of a gun based on the factory level and the number of missiles.

Arguments:

  • factoryLvl (number) - The level of the factory.
  • pMissiles (number) - The number of missiles.

Returns:

-(number) - The calculated cost of the gun

Travel Functions

GetDistance(origin: Origin, destination: Destination)

Calculates the distance between two geographical points.

Arguments:

  • origin (Origin): The origin point.
  • destination (Destination): The destination point.

Returns:

  • (number) - The distance between the origin and destination points in kilometers.

GetTime(user: User, origin: Origin, destination: Destination)

Calculates the time it takes for a user to travel between two geographical points based on their attributes.

Arguments:

  • user (User): The user with attributes such as strength, education, and level.
  • origin (Origin): The origin point.
  • destination (Destination): The destination point.

Returns:

  • (number) - The time it takes for the user to travel between the origin and destination points in minutes.

Parties

README.md

partyCurrentLevel(partyTotalDamage: number, round?: boolean)

Calculates the current party level based on the total damage dealt by the party.

Arguments:

  • partyTotalDamage (number) - The total damage dealt by the party.
  • round? (boolean, optional) - Whether to round the result or not. Default is false.

Returns:

  • (number) - The calculated party level.

getPartyLvlToExp(partyLvl: number)

Calculates the experience required to reach the given party level.

Arguments:

  • partyLvl (number) - The target party level.

Returns:

  • (number) - The experience required to reach the target party level.

getPartyExpLeft(partyTotalDamage: number)

Calculates the experience left to reach the next party level.

Arguments:

  • partyTotalDamage (number) - The total damage dealt by the party.

Returns:

  • (number) - The experience left to reach the next party level.

maxPartyMembers(partyTotalDamage: number)

Calculates the maximum number of members allowed in the party based on the party's total damage.

Arguments:

  • partyTotalDamage (number) - The total damage dealt by the party.

Returns:

  • (number) - The maximum number of members allowed in the party.

partyBonus(partyTotalDamage: number)

Calculates the party bonus based on the party's total damage.

Arguments:

  • partyTotalDamage (number) - The total damage dealt by the party.

Returns:

  • (number) - The calculated party bonus.

productionResources(resourceType: string, level: number, education: number, factoryLvl: number, partyBonusType: string, partyBonus: number, regionBasicEducation: number)

Calculates the production of resources based on various factors.

Arguments:

  • resourceType (string) - The type of resource being produced.
  • level (number) - The level of the worker.
  • education (number) - The education level of the worker.
  • factoryLvl (number) - The level of the factory.
  • partyBonusType (string) - The type of party bonus (e.g., 'production').
  • partyBonus (number) - The party bonus value.
  • regionBasicEducation (number) - The basic education level of the region.

Returns:

  • (number) - The calculated production of the specified resource.

getFactoryLevel(factoryExp: number, round?: boolean)

Calculates the factory level based on the factory experience.

Arguments:

  • factoryExp (number) - The experience of the factory.
  • round? (boolean, optional) - Whether to round the result or not. Default is false.

Returns:

  • (number) - The calculated factory level.

getFactoryExp(factoryLevel: number)

Calculates the experience required to reach the given factory level.

Arguments:

  • factoryLevel (number) - The target factory level.

Returns:

  • (number) - The experience required to reach the target factory level.

getFactoryExpLeft(factoryExp: number)

Calculates the experience left to reach the next factory level.

Arguments:

  • factoryExp (number) - The experience of the factory.

Returns:

  • (number) - The experience left to reach the next factory level.

Buildings

README.md

Overview

This module provides a utility function for calculating the resources required to upgrade a building in a game. The function takes the building type, initial level, and desired level as input and returns an object containing the resources needed for the upgrade.

Function

buildingResources(buildingType: string, initialLevel: number, desiredLevel: number)

Calculates the resources needed to upgrade a building from its initial level to the desired level.

Arguments:

  • buildingType (string) - The type of the building (e.g., 'schools', 'sportCenters', 'universities', 'recreativeCenters', 'policeStations', 'militaryBases', 'healthCenters').
  • initialLevel (number) - The initial level of the building.
  • desiredLevel (number) - The desired level of the building.

Returns:

  • (object) - An object containing the necessary resources to upgrade the building. The object keys represent the resource type (e.g., 'water', 'iron', 'oil'), and the values represent the required amount of each resource.