Handle GetShopListCsReq and make NPCs interactable. (#6)

* Handle GetShopListCsReq and make NPCs interactable.

* Add utils for shop excels.
This commit is contained in:
GanyusLeftHorn 2022-08-01 18:03:39 +02:00 committed by GitHub
parent 3d7b575425
commit 4f60afa9d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 159 additions and 3 deletions

3
.gitignore vendored
View File

@ -104,6 +104,9 @@ dist
# TernJS port file
.tern-port
# VS Code
.vscode/
# CrepeSR
config.json
src/data/*

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -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
}