From 6938c74014618867e613ae6fe10053c58d88133d Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 21 Apr 2022 02:28:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Global/GetDiplomacy=20=EC=A4=91?= =?UTF-8?q?=EC=9B=90=20=EC=A0=95=EB=B3=B4=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/API/Global/GetDiplomacy.php | 107 ++++++++++++++++++++++++++ hwe/ts/SammoAPI.ts | 3 +- hwe/ts/defs/API/Global.ts | 11 ++- 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 hwe/sammo/API/Global/GetDiplomacy.php diff --git a/hwe/sammo/API/Global/GetDiplomacy.php b/hwe/sammo/API/Global/GetDiplomacy.php new file mode 100644 index 00000000..be8061e1 --- /dev/null +++ b/hwe/sammo/API/Global/GetDiplomacy.php @@ -0,0 +1,107 @@ +userID; + increaseRefresh("중원정보", 1); + + $db = DB::db(); + $gameStor = KVStorage::getStorage($db, 'game_env'); + + $myNationID = $db->queryFirstField('SELECT nation FROM general WHERE owner=%i', $userID); + + + $nations = array_filter(getAllNationStaticInfo(), function (array $nation) { + return $nation['level']; + }); + uasort($nations, function (array $lhs, array $rhs) { + return - ($lhs['power'] <=> $rhs['power']); + }); + foreach(array_keys($nations) as $nationID){ + $nations[$nationID]['cities'] = []; + } + + $realConflict = []; + foreach ($db->queryAllLists('SELECT nation, city, conflict FROM city') as [ + $nationID, + $cityID, + $rawConflict + ]) { + if($nationID != 0){ + $nations[$nationID]['cities'][] = $cityID; + } + + if($rawConflict == '{}'){ + continue; + } + $rawConflict = Json::decode($rawConflict); + if (count($rawConflict) < 2) { + continue; + } + + $sum = array_sum($rawConflict); + + $conflict = []; + foreach ($rawConflict as $nationID => $killnum) { + $conflict[$nationID] = [ + 'killnum' => $killnum, + 'percent' => round(100 * $killnum / $sum, 1), + ]; + } + + $realConflict[] = [$cityID, $conflict]; + }; + + $neutralDiplomacyMap = [ + 3 => 2, + 4 => 2, + 5 => 2, + 6 => 2, + 7 => 2, + ]; + + $diplomacyList = []; + foreach ($db->queryAllLists('SELECT me, you, state FROM diplomacy') as [$me, $you, $state]) { + if (!key_exists($me, $diplomacyList)) { + $diplomacyList[$me] = []; + } + + if ($me != $myNationID && $you != $myNationID) { + $diplomacyList[$me][$you] = $neutralDiplomacyMap[$state] ?? $state; + } else { + $diplomacyList[$me][$you] = $state; + } + } + + return [ + 'result' => true, + 'nations' => $nations, + 'conflict' => $realConflict, + 'diplomacyList' => $diplomacyList, + 'myNationID' => $myNationID, + ]; + } +} diff --git a/hwe/ts/SammoAPI.ts b/hwe/ts/SammoAPI.ts index 44a99a1b..5f5f3d39 100644 --- a/hwe/ts/SammoAPI.ts +++ b/hwe/ts/SammoAPI.ts @@ -12,7 +12,7 @@ import type { inheritBuffType } from "./defs/API/InheritAction"; import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse } from "./defs/API/Nation"; import type { UploadImageResponse } from "./defs/API/Misc"; import type { JoinArgs } from "./defs/API/General"; -import type { GetConstResponse, GetCurrentHistoryResponse, GetHistoryResponse } from "./defs/API/Global"; +import type { GetConstResponse, GetCurrentHistoryResponse, GetDiplomacyResponse, GetHistoryResponse } from "./defs/API/Global"; import type { CachedMapResult, GeneralListResponse, MapResult } from "./defs"; const apiRealPath = { @@ -60,6 +60,7 @@ const apiRealPath = { GetCurrentHistory: GET as APICallT, GetMap: GET as APICallT, GetCachedMap: GET as APICallT, + GetDiplomacy: GET as APICallT, }, InheritAction: { BuyHiddenBuff: PUT as APICallT<{ diff --git a/hwe/ts/defs/API/Global.ts b/hwe/ts/defs/API/Global.ts index b2f332fd..681567b0 100644 --- a/hwe/ts/defs/API/Global.ts +++ b/hwe/ts/defs/API/Global.ts @@ -1,5 +1,5 @@ import type { CityID, CrewTypeID, GameCityDefault, GameConstType, GameUnitType, GameIActionKey, GameIActionCategory, GameIActionInfo } from "@/defs/GameObj"; -import type { MapResult } from "@/defs"; +import type { diplomacyState, MapResult, SimpleNationObj } from "@/defs"; export interface GetConstResponse { result: true; @@ -67,4 +67,13 @@ export type GetHistoryResponse = { export type GetCurrentHistoryResponse = { result: true; data: HistoryObj; +} + + +export type GetDiplomacyResponse = { + result: true; + nations: SimpleNationObj[]; + conflict: [number, Record][]; + diplomacyList: Record>; + myNationID: number; } \ No newline at end of file