From ad89dd0ffb93f47cfddb07d04c22b13b49268144 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Tue, 5 Apr 2022 01:20:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20func=5Fconverter=20=EC=9D=BC=EB=B6=80?= =?UTF-8?q?=20=ED=95=AD=EB=AA=A9=20=EC=9D=B4=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/ts/defs/index.ts | 2 +- hwe/ts/utilGame/formatConnectScore.ts | 21 ++++++ hwe/ts/utilGame/formatDefenceTrain.ts | 17 +++++ hwe/ts/utilGame/formatDexLevel.ts | 50 ++++++++++++ hwe/ts/utilGame/formatHonor.ts | 25 ++++++ hwe/ts/utilGame/formatOfficerLevelText.ts | 92 +++++++++++++++++++++++ package-lock.json | 11 +++ package.json | 1 + 8 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 hwe/ts/utilGame/formatConnectScore.ts create mode 100644 hwe/ts/utilGame/formatDefenceTrain.ts create mode 100644 hwe/ts/utilGame/formatDexLevel.ts create mode 100644 hwe/ts/utilGame/formatHonor.ts create mode 100644 hwe/ts/utilGame/formatOfficerLevelText.ts diff --git a/hwe/ts/defs/index.ts b/hwe/ts/defs/index.ts index d7b8b0bf..5140102e 100644 --- a/hwe/ts/defs/index.ts +++ b/hwe/ts/defs/index.ts @@ -228,4 +228,4 @@ export const diplomacyStateInfo: Record = { 1: { name: '선포중', color: 'magenta' }, 2: { name: '통상' }, 7: { name: '불가침', color: 'green' }, -} +} \ No newline at end of file diff --git a/hwe/ts/utilGame/formatConnectScore.ts b/hwe/ts/utilGame/formatConnectScore.ts new file mode 100644 index 00000000..c027787f --- /dev/null +++ b/hwe/ts/utilGame/formatConnectScore.ts @@ -0,0 +1,21 @@ +import bs from 'binary-search'; + +const connectMap: [number, string][] = [ + [50, '안함'], + [100, '무관심'], + [400, '보통'], + [200, '가끔'], + [800, '자주'], + [1600, '열심'], + [3200, '중독'], + [6400, '폐인'], + [12800, '경고'], +] + +export function formatConnectScore(connect: number) { + const idx = bs(connectMap, connect, ([key], needle) => key - needle); + if(idx >= 0){ + return connectMap[idx][1]??'?'; + } + return connectMap[-(idx + 1)][1]??'?'; +} \ No newline at end of file diff --git a/hwe/ts/utilGame/formatDefenceTrain.ts b/hwe/ts/utilGame/formatDefenceTrain.ts new file mode 100644 index 00000000..cdbafe67 --- /dev/null +++ b/hwe/ts/utilGame/formatDefenceTrain.ts @@ -0,0 +1,17 @@ +import bs from 'binary-search'; + +const defenceMap: [number,string][] = [ + [0, "△"], + [60, "○"], + [80, "◎"], + [90, "☆"], + [999, "×"], +] + +export function formatDefenceTrain(defenceTrain: number): string { + const idx = bs(defenceMap, defenceTrain, ([defenceKey], needle) => defenceKey - needle); + if(idx >= 0){ + return defenceMap[idx][1]??'?'; + } + return defenceMap[-(idx + 1)][1]??'?'; +} \ No newline at end of file diff --git a/hwe/ts/utilGame/formatDexLevel.ts b/hwe/ts/utilGame/formatDexLevel.ts new file mode 100644 index 00000000..6a608044 --- /dev/null +++ b/hwe/ts/utilGame/formatDexLevel.ts @@ -0,0 +1,50 @@ +import bs from 'binary-search'; + +export const DexLevelMap: [number, string, string][] = [ + [0, 'navy', 'F-'], + [350, 'navy', 'F'], + [1375, 'navy', 'F+'], + [3500, 'skyblue', 'E-'], + [7125, 'skyblue', 'E'], + [12650, 'skyblue', 'E+'], + [20475, 'seagreen', 'D-'], + [31000, 'seagreen', 'D'], + [44625, 'seagreen', 'D+'], + [61750, 'teal', 'C-'], + [82775, 'teal', 'C'], + [108100, 'teal', 'C+'], + [138125, 'limegreen', 'B-'], + [173250, 'limegreen', 'B'], + [213875, 'limegreen', 'B+'], + [260400, 'darkorange', 'A-'], + [313225, 'darkorange', 'A'], + [372750, 'darkorange', 'A+'], + [439375, 'tomato', 'S-'], + [513500, 'tomato', 'S'], + [595525, 'tomato', 'S+'], + [685850, 'darkviolet', 'Z-'], + [784875, 'darkviolet', 'Z'], + [893000, 'darkviolet', 'Z+'], + [1010625, 'gold', 'EX-'], + [1138150, 'gold', 'EX'], + [1275975, 'white', 'EX+'], +]; + +export type DexInfo = { + level: number, + name: string, + color: string, +} + +export function formatDexLevel(dex: number): DexInfo { + const rawIdx = bs(DexLevelMap, dex, ([dexKey], needle) => dexKey - needle); + const level = rawIdx >= 0 ? rawIdx : -(rawIdx + 1); + + const [, color, name] = DexLevelMap[level]; + + return { + level, + name, + color + }; +} \ No newline at end of file diff --git a/hwe/ts/utilGame/formatHonor.ts b/hwe/ts/utilGame/formatHonor.ts new file mode 100644 index 00000000..3ea9399c --- /dev/null +++ b/hwe/ts/utilGame/formatHonor.ts @@ -0,0 +1,25 @@ +import bs from 'binary-search'; + +const hornorMap: [number, string][] = [ + [640, '전무'], + [2560, '무명'], + [5760, '신동'], + [10240, '약간'], + [16000, '평범'], + [23040, '지역적'], + [31360, '전국적'], + [40960, '세계적'], + [45000, '유명'], + [51840, '명사'], + [55000, '호걸'], + [64000, '효웅'], + [77440, '영웅'], +] + +export function formatHonor(experience: number): string { + const idx = bs(hornorMap, experience, ([experienceKey], needle) => experienceKey - needle); + if (idx >= 0) { + return hornorMap[idx][1] ?? '?'; + } + return hornorMap[-(idx + 1)][1] ?? '?'; +} \ No newline at end of file diff --git a/hwe/ts/utilGame/formatOfficerLevelText.ts b/hwe/ts/utilGame/formatOfficerLevelText.ts new file mode 100644 index 00000000..406a7776 --- /dev/null +++ b/hwe/ts/utilGame/formatOfficerLevelText.ts @@ -0,0 +1,92 @@ +export const OfficerLevelMapDefault: Record = { + 12: '군주', + 11: '참모', + 10: '제1장군', + 9: '제1모사', + 8: '제2장군', + 7: '제2모사', + 6: '제3장군', + 5: '제3모사', + 4: '태수', + 3: '군사', + 2: '종사', + 1: '일반', + 0: '재야', +} + +export const OfficerLevelMapByNationLevel: Record> = { + 7: { + 12: '황제', + 11: '승상', + 10: '표기장군', + 9: '사공', + 8: '거기장군', + 7: '태위', + 6: '위장군', + 5: '사도' + }, + + 6: { + 12: '왕', + 11: '광록훈', + 10: '좌장군', + 9: '상서령', + 8: '우장군', + 7: '중서령', + 6: '전장군', + 5: '비서령' + }, + + 5: { + 12: '공', + 11: '광록대부', + 10: '안국장군', + 9: '집금오', + 8: '파로장군', + 7: '소부' + }, + + 4: { + 12: '주목', + 11: '태사령', + 10: '아문장군', + 9: '낭중', + 8: '호군', + 7: '종사중랑' + }, + + 3: { + 12: '주자사', + 11: '주부', + 10: '편장군', + 9: '간의대부' + }, + + 2: { + 12: '군벌', + 11: '참모', + 10: '비장군', + 9: '부참모' + }, + + 1: { + 12: '영주', + 11: '참모' + }, + + 0: { + 12: '두목', + 11: '부두목' + }, +} +export function formatOfficerLevelText(officerLevel: number, nationLevel?: number) { + if (officerLevel < 5) { + return OfficerLevelMapDefault[officerLevel] ?? '???'; + } + + const nationMap = nationLevel === undefined + ? OfficerLevelMapDefault + : (OfficerLevelMapByNationLevel[nationLevel] ?? OfficerLevelMapDefault); + + return nationMap[officerLevel] ?? (OfficerLevelMapDefault[officerLevel] ?? '???'); +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3b81b866..a519dc2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,6 +44,7 @@ "axios": "^0.26.1", "babel-plugin-lodash": "^3.3.4", "babel-preset-modern-browsers": "^15.0.2", + "binary-search": "^1.3.6", "bootstrap": "^5.1.3", "bootstrap-vue-3": "=0.1.8", "bootswatch": "^5.1.3", @@ -3453,6 +3454,11 @@ "node": "*" } }, + "node_modules/binary-search": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/binary-search/-/binary-search-1.3.6.tgz", + "integrity": "sha512-nbE1WxOTTrUWIfsfZ4aHGYu5DOuNkbxGokjV6Z2kxfJK3uaAb8zNK1muzOeipoLHZjInT4Br88BHpzevc681xA==" + }, "node_modules/boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", @@ -13092,6 +13098,11 @@ "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==" }, + "binary-search": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/binary-search/-/binary-search-1.3.6.tgz", + "integrity": "sha512-nbE1WxOTTrUWIfsfZ4aHGYu5DOuNkbxGokjV6Z2kxfJK3uaAb8zNK1muzOeipoLHZjInT4Br88BHpzevc681xA==" + }, "boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", diff --git a/package.json b/package.json index c355febb..4bfd6640 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "axios": "^0.26.1", "babel-plugin-lodash": "^3.3.4", "babel-preset-modern-browsers": "^15.0.2", + "binary-search": "^1.3.6", "bootstrap": "^5.1.3", "bootstrap-vue-3": "=0.1.8", "bootswatch": "^5.1.3",