파일 위치 이동

This commit is contained in:
2023-09-23 14:21:21 +00:00
parent 438df6cd3c
commit 4e629e0b1e
42 changed files with 206 additions and 781 deletions
+23
View File
@@ -0,0 +1,23 @@
{
"name": "@sammo/game_logic",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"build": "tsc --build"
},
"author": "",
"type": "module",
"license": "MIT",
"dependencies": {
"@sammo/api_def": "workspace:^",
"@sammo/server_util": "workspace:^",
"@sammo/util": "workspace:^",
"@strpc/express": "workspace:^",
"dotenv": "^16.3.1",
"mongoose": "^7.4.3"
},
"devDependencies": {
"@types/node": "^20.6.3"
}
}
+140
View File
@@ -0,0 +1,140 @@
interface Stats { min: number, max: number, total: number };
export function abilityRand(stats: Stats): [number, number, number] {
let leadership = Math.random() * 65 + 10;
let strength = Math.random() * 65 + 10;
let intel = Math.random() * 65 + 10;
const rate = leadership + strength + intel;
leadership = Math.floor((leadership / rate) * stats.total);
strength = Math.floor((strength / rate) * stats.total);
intel = Math.floor((intel / rate) * stats.total);
while (leadership + strength + intel < stats.total) {
leadership += 1;
}
if (
leadership > stats.max ||
strength > stats.max ||
intel > stats.max ||
leadership < stats.min ||
strength < stats.min ||
intel < stats.min
) {
return abilityRand(stats);
}
return [leadership, strength, intel];
}
export function abilityLeadpow(stats: Stats): [number, number, number] {
let leadership = Math.random() * 6;
let strength = Math.random() * 6;
let intel = Math.random() * 1;
const rate = leadership + strength + intel;
leadership = Math.floor((leadership / rate) * stats.total);
strength = Math.floor((strength / rate) * stats.total);
intel = Math.floor((intel / rate) * stats.total);
while (leadership + strength + intel < stats.total) {
strength += 1;
}
if (intel < stats.min) {
leadership -= stats.min - intel;
intel = stats.min;
}
if (leadership > stats.max) {
strength += leadership - stats.max;
leadership = stats.max;
}
if (strength > stats.max) {
leadership += strength - stats.max;
strength = stats.max;
}
if (leadership > stats.max) {
intel += leadership - stats.max;
leadership = stats.max;
}
return [leadership, strength, intel];
}
export function abilityLeadint(stats: Stats): [number, number, number] {
let leadership = Math.random() * 6;
let strength = Math.random() * 1;
let intel = Math.random() * 6;
const rate = leadership + strength + intel;
leadership = Math.floor((leadership / rate) * stats.total);
strength = Math.floor((strength / rate) * stats.total);
intel = Math.floor((intel / rate) * stats.total);
while (leadership + strength + intel < stats.total) {
intel += 1;
}
if (strength < stats.min) {
leadership -= stats.min - strength;
strength = stats.min;
}
if (leadership > stats.max) {
intel += leadership - stats.max;
leadership = stats.max;
}
if (intel > stats.max) {
leadership += intel - stats.max;
intel = stats.max;
}
if (leadership > stats.max) {
strength += leadership - stats.max;
leadership = stats.max;
}
return [leadership, strength, intel];
}
export function abilityPowint(stats: Stats): [number, number, number] {
let leadership = Math.random() * 1;
let strength = Math.random() * 6;
let intel = Math.random() * 6;
const rate = leadership + strength + intel;
leadership = Math.floor((leadership / rate) * stats.total);
strength = Math.floor((strength / rate) * stats.total);
intel = Math.floor((intel / rate) * stats.total);
while (leadership + strength + intel < stats.total) {
intel += 1;
}
if (leadership < stats.min) {
strength -= stats.min - leadership;
leadership = stats.min;
}
if (strength > stats.max) {
intel += strength - stats.max;
strength = stats.max;
}
if (intel > stats.max) {
strength += intel - stats.max;
intel = stats.max;
}
if (strength > stats.max) {
leadership += strength - stats.max;
strength = stats.max;
}
return [leadership, strength, intel];
}
+1
View File
@@ -0,0 +1 @@
export * from "./generalStats.js";
+21
View File
@@ -0,0 +1,21 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
},
"references": [
{
"path": "../../@strpc/express"
},
{
"path": "../util"
},
{
"path": "../crypto"
},
{
"path": "../server_util"
},
]
}