# leviathan-war-functions

> functions for leviathan

Latest version **1.2.5** (published 2023-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install leviathan-war-functions
pnpm add leviathan-war-functions
yarn add leviathan-war-functions
bun add leviathan-war-functions
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.5 |
| Published | 2023-03-29 |
| First published | 2023-03-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 28.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | sakaloner |
| Maintainers | sakaloner |

## Links

- npm: https://www.npmjs.com/package/leviathan-war-functions
- Repository: git@github.com:Leviathan-War/leviathanformulas
- npm.io page: https://npm.io/package/leviathan-war-functions

## Dependencies (1)

- [ts-node](https://npm.io/package/ts-node.md) ^10.9.1

## Recent versions

- 1.2.5 (latest) — 2023-03-29
- 1.2.4 — 2023-03-29
- 1.2.3 — 2023-03-29
- 1.2.2 — 2023-03-23
- 1.2.0 — 2023-03-22

## 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:

```javascript
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:

```javascript
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:

``` javascript
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:

``` javascript
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:

``` javascript
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:

``` javascript
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:

```javascript
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.

``` javascript
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.

---
_Source: https://npm.io/package/leviathan-war-functions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
