From 4f60afa9d97bba7685e6a948dc44556baec1232f Mon Sep 17 00:00:00 2001 From: GanyusLeftHorn <1244229+GanyusLeftHorn@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:03:39 +0200 Subject: [PATCH] Handle GetShopListCsReq and make NPCs interactable. (#6) * Handle GetShopListCsReq and make NPCs interactable. * Add utils for shop excels. --- .gitignore | 3 ++ src/server/packets/GetFirstTalkNpcCsReq.ts | 20 +++++++-- src/server/packets/GetNpcTakenRewardCsReq.ts | 13 ++++++ src/server/packets/GetShopListCsReq.ts | 41 +++++++++++++++++ src/util/excel/ShopConfigExcel.ts | 39 +++++++++++++++++ src/util/excel/ShopGoodsConfigExcel.ts | 46 ++++++++++++++++++++ 6 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 src/server/packets/GetNpcTakenRewardCsReq.ts create mode 100644 src/server/packets/GetShopListCsReq.ts create mode 100644 src/util/excel/ShopConfigExcel.ts create mode 100644 src/util/excel/ShopGoodsConfigExcel.ts diff --git a/.gitignore b/.gitignore index d8c7cab..b842dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -104,6 +104,9 @@ dist # TernJS port file .tern-port +# VS Code +.vscode/ + # CrepeSR config.json src/data/* \ No newline at end of file diff --git a/src/server/packets/GetFirstTalkNpcCsReq.ts b/src/server/packets/GetFirstTalkNpcCsReq.ts index efa2624..488e638 100644 --- a/src/server/packets/GetFirstTalkNpcCsReq.ts +++ b/src/server/packets/GetFirstTalkNpcCsReq.ts @@ -1,9 +1,23 @@ -import { GetFirstTalkNpcScRsp } from "../../data/proto/StarRail"; +import { GetFirstTalkNpcCsReq, GetFirstTalkNpcScRsp, NpcMeetStatus } from "../../data/proto/StarRail"; import Packet from "../kcp/Packet"; import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { - session.send("GetFirstTalkNpcScRsp", { + const body = packet.body as GetFirstTalkNpcCsReq; + + const dataObj = { retcode: 0, - } as GetFirstTalkNpcScRsp); + npcMeetStatusList: [] + } as GetFirstTalkNpcScRsp; + + body.seriesIdList.forEach(series => { + const meetStatusObj = { + seriesId: series, + isMeet: false + } as NpcMeetStatus; + + dataObj.npcMeetStatusList.push(meetStatusObj); + }); + + session.send("GetFirstTalkNpcScRsp", dataObj); } \ No newline at end of file diff --git a/src/server/packets/GetNpcTakenRewardCsReq.ts b/src/server/packets/GetNpcTakenRewardCsReq.ts new file mode 100644 index 0000000..55bf8ac --- /dev/null +++ b/src/server/packets/GetNpcTakenRewardCsReq.ts @@ -0,0 +1,13 @@ +import { GetNpcTakenRewardCsReq, GetNpcTakenRewardScRsp } from "../../data/proto/StarRail"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetNpcTakenRewardCsReq; + + session.send("GetNpcTakenRewardScRsp", { + retcode: 0, + npcId: body.npcId, + talkEventList: [] + } as GetNpcTakenRewardScRsp); +} \ No newline at end of file diff --git a/src/server/packets/GetShopListCsReq.ts b/src/server/packets/GetShopListCsReq.ts new file mode 100644 index 0000000..ee78be2 --- /dev/null +++ b/src/server/packets/GetShopListCsReq.ts @@ -0,0 +1,41 @@ +import { GetShopListScRsp, GetShopListCsReq, Shop, Goods } from "../../data/proto/StarRail"; +import ShopConfigExcel from "../../util/excel/ShopConfigExcel"; +import ShopGoodsConfigExcel from "../../util/excel/ShopGoodsConfigExcel"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as GetShopListCsReq; + + const dataObj = { + retcode: 0, + shopType: body.shopType, + shopList: [] + } as GetShopListScRsp; + + // Get all shops from the excels. + ShopConfigExcel.all().forEach(shop => { + const shopObj = { + shopId: shop.ShopID, + beginTime: 0, + endTime: Date.now() * 2, + goodsList: [] + } as Shop; + + // Add goods for this shop. + ShopGoodsConfigExcel.fromShopId(shop.ShopID).forEach(goods => { + const goodsObj = { + goodsId: goods.GoodsID, + buyTimes: 0, + beginTime: 0, + endTime: Date.now() * 2, + } as Goods; + + shopObj.goodsList.push(goodsObj); + }); + + dataObj.shopList.push(shopObj); + }); + + session.send("GetShopListScRsp", dataObj); +} \ No newline at end of file diff --git a/src/util/excel/ShopConfigExcel.ts b/src/util/excel/ShopConfigExcel.ts new file mode 100644 index 0000000..5bb7f33 --- /dev/null +++ b/src/util/excel/ShopConfigExcel.ts @@ -0,0 +1,39 @@ +import _ShopConfigExcelTable from "../../data/excel/ShopConfigExcelTable.json"; +const ShopConfigExcelTable = _ShopConfigExcelTable as { [key: string]: ShopConfigExcelTableEntry }; + +export default class ShopConfigExcel { + private constructor() { + } + + public static all() : ShopConfigExcelTableEntry[] { + return Object.values(ShopConfigExcelTable); + } + + public static fromId(id: number) : ShopConfigExcelTableEntry { + return ShopConfigExcelTable[id]; + } + + public static fromIds(ids: number[]): ShopConfigExcelTableEntry[] { + return ids.map(id => ShopConfigExcel.fromId(id)); + } +} + +interface TextMap { + hash: number; +} + +export interface ShopConfigExcelTableEntry { + ShopID: number, + ShopMainType: string, + ShopType: number, + ShopName: TextMap, + ShopDesc: TextMap, + ShopIconPath: string, + LimitType1: string, + LimitValue1List: number[], + LimitType2: string, + LimitValue2List: number[], + IsOpen: boolean, + ServerVerification: boolean, + ScheduleDataID: number +} \ No newline at end of file diff --git a/src/util/excel/ShopGoodsConfigExcel.ts b/src/util/excel/ShopGoodsConfigExcel.ts new file mode 100644 index 0000000..6bb8519 --- /dev/null +++ b/src/util/excel/ShopGoodsConfigExcel.ts @@ -0,0 +1,46 @@ +import _ShopGoodsConfigExcelTable from "../../data/excel/ShopGoodsConfigExcelTable.json"; +const ShopGoodsConfigExcelTable = _ShopGoodsConfigExcelTable as { [key: string]: ShopGoodsConfigExcelTableEntry }; + +export default class ShopGoodsConfigExcel { + private constructor() { + } + + public static fromId(id: number) : ShopGoodsConfigExcelTableEntry { + return ShopGoodsConfigExcelTable[id]; + } + + public static fromIds(ids: number[]): ShopGoodsConfigExcelTableEntry[] { + return ids.map(id => ShopGoodsConfigExcel.fromId(id)); + } + + public static fromShopId(id: number): ShopGoodsConfigExcelTableEntry[] { + return Object.values(ShopGoodsConfigExcelTable).filter(entry => entry.ShopID == id); + } +} + +interface TextMap { + hash: number; +} + +export interface ShopGoodsConfigExcelTableEntry { + GoodsID: number, + ItemID: number, + ShopGoodsIconPath: string, + ItemCount: number, + Level: number, + Rank: number, + CurrencyList: number[], + CurrencyCostList: number[], + GoodsSortID: number, + LimitType1: string, + LimitValue1List: number[], + LimitType2: string, + LimitValue2List: number[], + OnShelfType1: string, + OnShelfValue1List: number[], + LimitTimes: number, + CanBeRefresh: boolean, + RefreshType: number, + ShopID: number, + ScheduleDataID: number +} \ No newline at end of file