Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bastion-siege-logic

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bastion-siege-logic - npm Package Compare versions

Comparing version 2.5.0 to 2.5.1

10

dist/source/battle.d.ts

@@ -5,9 +5,9 @@ import { ConstructionResources } from './resources';

interface BattleOdds {
solo: BattleBuildingOdds;
alliance: BattleBuildingOdds;
readonly solo: BattleBuildingOdds;
readonly alliance: BattleBuildingOdds;
}
interface BattleBuildingOdds {
barracks: number;
trebuchet: number;
wall: number;
readonly barracks: number;
readonly trebuchet: number;
readonly wall: number;
}

@@ -14,0 +14,0 @@ export declare const BATTLE_ODDS: BattleOdds;

import { Mystic } from './gamescreen/mystics';
export declare type BattlereportResource = 'gold' | 'gems' | 'karma' | 'terra';
export interface Battlereport extends BattlereportRaw {
time: number;
export interface Battlereport extends Readonly<BattlereportRaw> {
readonly time: number;
}
export interface BattlereportRaw {
attack: boolean;
won: boolean;
me: string;
friends: string[];
enemies: string[];
enemyAlliance?: string;
enemyMystic?: Mystic;
soldiersAlive: number;
soldiersTotal: number;
gold: number;
gems?: number;
karma?: number;
terra?: number;
readonly attack: boolean;
readonly won: boolean;
readonly me: string;
readonly friends: readonly string[];
readonly enemies: readonly string[];
readonly enemyAlliance?: string;
readonly enemyMystic?: Mystic;
readonly soldiersAlive: number;
readonly soldiersTotal: number;
readonly gold: number;
readonly gems?: number;
readonly karma?: number;
readonly terra?: number;
}
export declare function uniqueBattlereportIdentifier(report: Battlereport): string;
export declare function sameBattleResourceAssumption(reports: Battlereport[], resource?: BattlereportResource): number;
export declare function sameBattleResourceAssumption(reports: readonly Battlereport[], resource?: BattlereportResource): number;
export interface Buildings {
townhall: number;
storage: number;
houses: number;
farm: number;
sawmill: number;
mine: number;
barracks: number;
wall: number;
readonly townhall: number;
readonly storage: number;
readonly houses: number;
readonly farm: number;
readonly sawmill: number;
readonly mine: number;
readonly barracks: number;
readonly wall: number;
}
export interface Workshop {
trebuchet: number;
ballista: number;
readonly trebuchet: number;
readonly ballista: number;
}

@@ -20,7 +20,7 @@ export interface Constructions extends Buildings, Workshop {

export declare type ConstructionName = keyof Constructions;
export declare const BUILDINGS: BuildingName[];
export declare const WORKSHOP: WorkshopName[];
export declare const CONSTRUCTIONS: ConstructionName[];
export declare const BUILDING_COST_FACTORS: {
[key: string]: [number, number, number];
};
export declare const BUILDINGS: readonly BuildingName[];
export declare const WORKSHOP: readonly WorkshopName[];
export declare const CONSTRUCTIONS: readonly ConstructionName[];
export declare const BUILDING_COST_FACTORS: Readonly<{
[key: string]: Readonly<[number, number, number]>;
}>;

@@ -8,2 +8,3 @@ "use strict";

const resourceLimitNeeded = maxResourceFactor * wantedBuildingLevel * (wantedBuildingLevel + 1);
/* eslint-disable unicorn/prevent-abbreviations */
const tmp1 = Math.sqrt(2);

@@ -13,2 +14,3 @@ const tmp2 = Math.sqrt(resourceLimitNeeded + 5000);

const tmp4 = tmp3 / 10;
/* eslint-enable */
const levelRequired = Math.ceil(tmp4);

@@ -21,4 +23,3 @@ return levelRequired;

const resourceLimitNeeded = goldFactor * wantedBuildingLevel * (wantedBuildingLevel + 1);
const tmp1 = resourceLimitNeeded / 500000;
const levelRequired = Math.ceil(tmp1);
const levelRequired = Math.ceil(resourceLimitNeeded / 500000);
return levelRequired;

@@ -46,2 +47,3 @@ }

function calcMaxBuildingLevelWithFactorAndCapacity(factor, capacity) {
/* eslint-disable unicorn/prevent-abbreviations */
const tmp11 = factor ** 2;

@@ -52,2 +54,3 @@ const tmp12 = -4 * factor * capacity;

const tmp = (tmp1 / tmp2) - 0.5;
/* eslint-enable */
const result = Math.floor(tmp);

@@ -54,0 +57,0 @@ return result;

export declare type Castle = 'diamond' | 'ruby' | 'sapphire';
export declare const CASTLES: Castle[];
export declare const CASTLES: readonly Castle[];
export declare const CASTLE_SIEGE_SECONDS: number;
export declare const CASTLE_HOLD_SECONDS: number;
export declare const CASTLE_BONUS: Record<Castle, number>;
export declare const CASTLE_BONUS: Readonly<Record<Castle, number>>;
export declare const EMOJI: {
[key: string]: string;
gold: string;
wood: string;
stone: string;
food: string;
gem: string;
karma: string;
wins: string;
terra: string;
people: string;
army: string;
archer: string;
serverStatistics: string;
conqueror: string;
listLeader: string;
listNormal: string;
listYou: string;
buildings: string;
workshop: string;
townhall: string;
storage: string;
houses: string;
farm: string;
sawmill: string;
mine: string;
barracks: string;
wall: string;
repair: string;
trebuchet: string;
ballista: string;
war: string;
search: string;
alliancebattle: string;
attack: string;
defence: string;
trade: string;
castle: string;
dragon: string;
undead: string;
};

@@ -7,82 +7,82 @@ import { BattlereportRaw } from '../battlereport';

export interface AllianceBattleStart {
attack: boolean;
ally: Player;
enemy: Player;
readonly attack: boolean;
readonly ally: Player;
readonly enemy: Player;
}
export interface Attackscout {
player: Player;
terra: number;
karma: number;
readonly player: Player;
readonly terra: number;
readonly karma: number;
}
export interface BattleSolo {
enemy: Player;
readonly enemy: Player;
}
export interface BattleAlliance {
attack: string[];
defence: string[];
readonly attack: string[];
readonly defence: string[];
}
export interface CastleSiegeAllianceJoined {
alliance: string;
readonly alliance: string;
}
export interface CastleSiegeParticipant {
alliance: string;
name: string;
players: string[];
readonly alliance: string;
readonly name: string;
readonly players: string[];
}
export interface CastleSiegeEnds {
oldAlliance?: string;
newAlliance?: string;
readonly oldAlliance?: string;
readonly newAlliance?: string;
}
export interface Chat {
sender: string;
text: string;
readonly sender: string;
readonly text: string;
}
export interface DomainStats {
wins: number;
karma: number;
terra: number;
readonly wins: number;
readonly karma: number;
readonly terra: number;
}
export interface Effect {
emoji: string;
name: string;
timestamp?: number;
minutesRemaining?: number;
readonly emoji: string;
readonly name: string;
readonly timestamp?: number;
readonly minutesRemaining?: number;
}
export interface ListEntry {
type: string;
name: string;
value: string;
meta?: string;
readonly type: string;
readonly name: string;
readonly value: string;
readonly meta?: string;
}
export declare type GamescreenType = ConstructionName | 'allianceBattleYourArmyJoined' | 'allianceMembers' | 'castleSiegeAvailable' | 'castleSiegePlayerJoined' | 'castleSiegeStarts' | 'castleSiegeYouJoined' | 'dig' | 'main' | 'nextCastleSiege' | 'patrolreport' | 'personalAllianceOverview' | 'rankingGold' | 'rankingKarma' | 'rankingSearch' | 'rankingTerra' | 'rankingWins' | 'resources' | 'siegeStarted' | 'war';
export interface GamescreenContent {
type?: GamescreenType;
allianceBattleStart?: AllianceBattleStart;
allianceBattleSupport?: Player;
allianceJoinRequest?: Player;
allianceLeader?: Player;
alreadyInFight?: Player;
attackIncoming?: Player;
attackscout?: Attackscout;
battle?: BattleAlliance | BattleSolo;
battlereport?: BattlereportRaw;
buildings?: Buildings;
castle?: Castle;
castleSiegeAllianceJoined?: CastleSiegeAllianceJoined;
castleSiegeEnds?: CastleSiegeEnds;
castleSiegeParticipants?: CastleSiegeParticipant[];
castleSiegePlayerJoined?: Player;
chat?: Chat;
conqueror?: Player;
domainStats?: DomainStats;
effects?: Effect[];
list?: ListEntry[];
notRecoveredFromFight?: Player;
player?: Player;
resources?: Resources;
workshop?: Workshop;
readonly type?: GamescreenType;
readonly allianceBattleStart?: AllianceBattleStart;
readonly allianceBattleSupport?: Player;
readonly allianceJoinRequest?: Player;
readonly allianceLeader?: Player;
readonly alreadyInFight?: Player;
readonly attackIncoming?: Player;
readonly attackscout?: Attackscout;
readonly battle?: BattleAlliance | BattleSolo;
readonly battlereport?: BattlereportRaw;
readonly buildings?: Buildings;
readonly castle?: Castle;
readonly castleSiegeAllianceJoined?: CastleSiegeAllianceJoined;
readonly castleSiegeEnds?: CastleSiegeEnds;
readonly castleSiegeParticipants?: CastleSiegeParticipant[];
readonly castleSiegePlayerJoined?: Player;
readonly chat?: Chat;
readonly conqueror?: Player;
readonly domainStats?: DomainStats;
readonly effects?: Effect[];
readonly list?: ListEntry[];
readonly notRecoveredFromFight?: Player;
readonly player?: Player;
readonly resources?: Resources;
readonly workshop?: Workshop;
}
export interface Gamescreen extends GamescreenContent {
timestamp: number;
ingameTimestamp: number;
readonly timestamp: number;
readonly ingameTimestamp: number;
}

@@ -36,3 +36,3 @@ "use strict";

const { name: enemy, alliance: enemyAlliance } = regexHelper.getPlayer(content, /Битва с (?:альянсом )?([\s\S]+) окончена/);
const winnersLosers = getWinnersLosersFromAllianceAttack(content, 'Победители', 'Проигравшие', 'Для');
const winnersLosers = getWinnersLosersFromAllianceAttack(content, 'Победители', 'Проигравшие', '\nДля');
const soldiers = getSoldiers(content, {

@@ -56,3 +56,3 @@ normal: `(\\d+)${REGEX_ARMY} из (\\d+)${REGEX_ARMY}`,

const { name: enemy, alliance: enemyAlliance } = regexHelper.getPlayer(content, /battle with (?:alliance )?([\s\S]+) complete/);
const winnersLosers = getWinnersLosersFromAllianceAttack(content, 'Winners', 'Losers', 'For');
const winnersLosers = getWinnersLosersFromAllianceAttack(content, 'Winners', 'Losers', '\nFor');
const soldiers = getSoldiers(content, {

@@ -75,7 +75,7 @@ normal: `(\\d+)${REGEX_ARMY} of (\\d+)${REGEX_ARMY}`,

const losersStartIndex = content.indexOf(losersString + ': ');
const loserAbortIndex = content.includes(losersAbortString) ? content.indexOf(losersAbortString) : content.length + 1;
const loserAbortIndex = content.includes(losersAbortString) ? content.indexOf(losersAbortString) : content.length;
const winnersSubstring = content.slice(winnersStartIndex + winnersString.length + 2, losersStartIndex - 1);
const winners = winnersSubstring.split(', ')
.map(o => o.trim());
const losersSubstring = content.slice(losersStartIndex + losersString.length + 2, loserAbortIndex - 1);
const losersSubstring = content.slice(losersStartIndex + losersString.length + 2, loserAbortIndex);
const losers = losersSubstring.split(', ')

@@ -82,0 +82,0 @@ .map(o => o.trim());

@@ -151,3 +151,3 @@ "use strict";

if (line.startsWith('[')) {
const { alliance, name } = regexHelper.getPlayer(line, /^(\[[^\]]+\][^(]+)(?: \(\d+\))?$/);
const { alliance, name } = regexHelper.getPlayer(line, /^(\[[^\]]+][^(]+)(?: \(\d+\))?$/);
if (!alliance) {

@@ -154,0 +154,0 @@ throw new Error('failed to parse castle participants');

@@ -18,3 +18,4 @@ "use strict";

.map(o => Object.values(o))
.reduce((arr, add) => arr.concat(add), []);
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
.reduce((collector, add) => collector.concat(add), []);
function parseGamescreenContent(content) {

@@ -21,0 +22,0 @@ for (const parser of availableParser) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const emoji_1 = require("./emoji");
const regex_1 = require("./helpers/regex");
const contentFilter = require("./helpers/content-filter");

@@ -56,15 +57,14 @@ const LIST_SIMPLE_REGEX = /^(👑|🔅|⚜)(.+)\s+(\S+)$/;

.map(o => {
const match = regex.exec(o);
const match = regex_1.generateRegex(regex).exec(o);
if (!match) {
return undefined;
}
const entry = {
type: match[1],
name: match[2].trim(),
value: match[3]
};
if (match[4]) {
entry.meta = match[4];
const type = match[1];
const name = match[2].trim();
const value = match[3];
const meta = match[4];
if (meta) {
return { type, name, value, meta };
}
return entry;
return { type, name, value };
})

@@ -71,0 +71,0 @@ .filter(o => o);

@@ -14,16 +14,15 @@ "use strict";

const effects = lines
.map(line => {
const effect = {
emoji: regexHelper.getStrict(line, EFFECTS_REGEX, 1),
name: regexHelper.getStrict(line, EFFECTS_REGEX, 2)
};
.map((line) => {
const emoji = regexHelper.getStrict(line, EFFECTS_REGEX, 1);
const name = regexHelper.getStrict(line, EFFECTS_REGEX, 2);
const minutesRemaining = regexHelper.getOptionalNumber(line, /: (\d+) [^.]+\./);
const timestampString = regexHelper.getOptional(line, /(\d[\d-: ]+ \+0000 UTC)/);
const timestampString = regexHelper.getOptional(line, /(\d[\d-: ]+ \+0{4} UTC)/);
if (timestampString) {
effect.timestamp = Date.parse(timestampString) / 1000;
const timestamp = Date.parse(timestampString) / 1000;
return { emoji, name, timestamp };
}
else if (minutesRemaining) {
effect.minutesRemaining = minutesRemaining;
if (minutesRemaining) {
return { emoji, name, minutesRemaining };
}
return effect;
return { emoji, name };
});

@@ -49,12 +48,10 @@ return { effects };

}
const result = {
type: 'war',
domainStats: getWarMenuDomainStats(content)
};
const type = 'war';
const domainStats = getWarMenuDomainStats(content);
const warRegex = isEnglish ? WAR_REGEX_ENGLISH : WAR_REGEX_RUSSIAN;
const battle = getWarBattle(content, warRegex);
if (battle) {
result.battle = battle;
return { type, domainStats, battle };
}
return result;
return { type, domainStats };
}

@@ -61,0 +58,0 @@ exports.war = war;

interface LangEntry {
en: string;
ru: string;
readonly en: string;
readonly ru: string;
}
export declare const GAMETEXT: Record<string, LangEntry>;
export declare const GAMETEXT: Readonly<Record<string, LangEntry>>;
export {};
export declare function starts(content: string, expected: string): boolean;
export declare function includes(content: string, expected: string): boolean;
export declare function ends(content: string, expected: string): boolean;
export declare function startsAll(content: string, first: string, second: string, ...more: string[]): boolean;
export declare function includesAll(content: string, first: string, second: string, ...more: string[]): boolean;
export declare function endsAll(content: string, first: string, second: string, ...more: string[]): boolean;
export declare function startsAny(content: string, first: string, second: string, ...more: string[]): boolean;
export declare function includesAny(content: string, first: string, second: string, ...more: string[]): boolean;
export declare function endsAny(content: string, first: string, second: string, ...more: string[]): boolean;
export declare function startsAll(content: string, first: string, second: string, ...more: readonly string[]): boolean;
export declare function includesAll(content: string, first: string, second: string, ...more: readonly string[]): boolean;
export declare function endsAll(content: string, first: string, second: string, ...more: readonly string[]): boolean;
export declare function startsAny(content: string, first: string, second: string, ...more: readonly string[]): boolean;
export declare function includesAny(content: string, first: string, second: string, ...more: readonly string[]): boolean;
export declare function endsAny(content: string, first: string, second: string, ...more: readonly string[]): boolean;
export declare function startsWithGametext(content: string, emojiSelector: string, gametextSelector: string, spaceSeperated: boolean): boolean;
import { Player } from '../player';
export declare function getOptional(text: string, pattern: RegExp | string, group?: number): string | undefined;
export declare function getOptionalNumber(text: string, pattern: RegExp | string, group?: number): number | undefined;
export declare function getStrict(text: string, pattern: RegExp | string, group?: number): string;
export declare function getNumberStrict(text: string, pattern: RegExp | string, group?: number): number;
export declare function getPlayer(text: string, pattern: RegExp | string, group?: number): Player;
export interface RegExpLike {
readonly source: string;
readonly flags: string;
}
export declare function generateRegex(pattern: RegExpLike | string): RegExp;
export declare function getOptional(text: string, pattern: RegExpLike | string, group?: number): string | undefined;
export declare function getOptionalNumber(text: string, pattern: RegExpLike | string, group?: number): number | undefined;
export declare function getStrict(text: string, pattern: RegExpLike | string, group?: number): string;
export declare function getNumberStrict(text: string, pattern: RegExpLike | string, group?: number): number;
export declare function getPlayer(text: string, pattern: RegExpLike | string, group?: number): Player;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const player_1 = require("../player");
function generateRegex(pattern) {
if (typeof pattern === 'string') {
return new RegExp(pattern);
}
return new RegExp(pattern.source, pattern.flags);
}
exports.generateRegex = generateRegex;
function getOptional(text, pattern, group = 1) {
const regex = new RegExp(pattern);
const regex = generateRegex(pattern);
const match = regex.exec(text);

@@ -7,0 +14,0 @@ if (!match) {

export interface MysticsText {
dragon: string;
undead: string;
readonly dragon: string;
readonly undead: string;
}
export declare type Mystic = keyof MysticsText;
export declare const MYSTICS: Mystic[];
export declare const MYSTICS_TEXT_EN: {
dragon: string;
undead: string;
};
export declare const MYSTICS_TEXT_RU: {
dragon: string;
undead: string;
};
export declare const MYSTICS: readonly Mystic[];
export declare const MYSTICS_TEXT_EN: MysticsText;
export declare const MYSTICS_TEXT_RU: MysticsText;
export declare function isMystic(input: string): Mystic | false;
import { Mystic } from './mystics';
export interface Player {
name: string;
mystic?: Mystic;
alliance?: string;
bonus?: string;
achievements?: string;
readonly name: string;
readonly mystic?: Mystic;
readonly alliance?: string;
readonly bonus?: string;
readonly achievements?: string;
}
export declare function parsePlayer(input: string): Player;

@@ -10,10 +10,10 @@ "use strict";

function createNameRegex() {
const e = emojiRegex.source;
const emojiSource = emojiRegex.source;
const concatedNamePart = [
// First part (negative karma, conquerer, halloween, …)
`(${e}+)?`,
`(${emojiSource}+)?`,
// Achievements
/(?:{([^}]+)})?/,
// Alliance
/(?:\[([^\]]+)\])?/,
/(?:\[([^\]]+)])?/,
// Name

@@ -20,0 +20,0 @@ /(.+)/

@@ -1,3 +0,3 @@

export declare const NOT_ALLOWED_CHARS: string[];
export declare const ALTERNATIVE_SPACES: string[];
export declare function inputTextCleanup(text: Readonly<string>): string;
export declare const NOT_ALLOWED_CHARS: readonly string[];
export declare const ALTERNATIVE_SPACES: readonly string[];
export declare function inputTextCleanup(text: string): string;

@@ -24,3 +24,2 @@ "use strict";

}
text = '42';
return output;

@@ -27,0 +26,0 @@ }

import { Buildings } from './buildings';
export interface ConstructionResources {
gold: number;
wood: number;
stone: number;
readonly gold: number;
readonly wood: number;
readonly stone: number;
}
export interface Resources {
gold: number;
wood: number;
stone: number;
food: number;
readonly gold: number;
readonly wood: number;
readonly stone: number;
readonly food: number;
}
export declare type ConstructionResourceName = keyof ConstructionResources;
export declare type ResourceName = keyof Resources;
export declare const CONSTRUCTION_RESOURCES: ConstructionResourceName[];
export declare const RESOURCES: ResourceName[];
export declare const CONSTRUCTION_RESOURCES: readonly ConstructionResourceName[];
export declare const RESOURCES: readonly ResourceName[];
export declare function calcGoldCapacity(townhallLevel: number): number;

@@ -18,0 +18,0 @@ export declare function calcStorageCapacity(storageLevel: number): number;

{
"name": "bastion-siege-logic",
"version": "2.5.0",
"version": "2.5.1",
"description": "",

@@ -13,3 +13,3 @@ "license": "MIT",

"engines": {
"node": ">=8.3"
"node": ">=12"
},

@@ -42,3 +42,3 @@ "scripts": {

"typescript": "^3.7.4",
"xo": "^0.27.2"
"xo": "^0.29.1"
},

@@ -62,10 +62,6 @@ "nyc": {

"xo": {
"extends": "xo-typescript",
"semicolon": false,
"extensions": [
"ts"
],
"rules": {
"ava/no-ignored-test-files": "off",
"import/named": "warn",
"ava/no-ignored-test-files": "off",
"@typescript-eslint/no-unnecessary-condition": [

@@ -76,9 +72,16 @@ "error",

}
],
"@typescript-eslint/semi": [
"error",
"never"
]
}
},
"overrides": [
{
"files": [
"test/**/*",
"**/*.test.*"
],
"rules": {
"@typescript-eslint/prefer-readonly-parameter-types": "off"
}
}
]
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc