From 75184dd396bb072afa3402796106c598e481ecd1 Mon Sep 17 00:00:00 2001 From: Syca <64587684+Sycamore0@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:30:27 +0800 Subject: [PATCH 1/4] Create McoinExchangeHcoin.ts --- src/kcpServer/packets/McoinExchangeHcoin.ts | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/kcpServer/packets/McoinExchangeHcoin.ts diff --git a/src/kcpServer/packets/McoinExchangeHcoin.ts b/src/kcpServer/packets/McoinExchangeHcoin.ts new file mode 100644 index 0000000..9533509 --- /dev/null +++ b/src/kcpServer/packets/McoinExchangeHcoin.ts @@ -0,0 +1,42 @@ +import Packet, { PacketInterface, PacketContext } from '#/packet' +import { RetcodeEnum } from '@/types/proto/enum' + +export interface McoinExchangeHcoinReq { + hcoin: number + mcoinCost: number +} + +export interface McoinExchangeHcoinRsp { + retcode: RetcodeEnum + hcoin: number + mcoinCost: number +} + +export interface McoinExchangeHcoinNotify { } + +class McoinExchangeHcoinPacket extends Packet implements PacketInterface { + constructor() { + super('McoinExchangeHcoin') + } + + async request(context: PacketContext, data: McoinExchangeHcoinReq): Promise { + const { player } = context + const { hcoin, mcoinCost } = data + + player.addGenesisCrystal(-mcoinCost) + player.addPrimogem(hcoin) + + await this.response(context, { + retcode: RetcodeEnum.RET_SUCC, + hcoin: hcoin, + mcoinCost: mcoinCost + }) + } + + async response(context: PacketContext, data: McoinExchangeHcoinRsp): Promise { + await super.response(context, data) + } +} + +let packet: McoinExchangeHcoinPacket +export default (() => packet = packet || new McoinExchangeHcoinPacket())() \ No newline at end of file From 03e73dd3e27c4dfc217697ffb3748e0018662568 Mon Sep 17 00:00:00 2001 From: Syca <64587684+Sycamore0@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:25:19 +0800 Subject: [PATCH 2/4] Support Combine --- .../game/gameData/data/CombineData.ts | 25 ++++++ src/kcpServer/game/index.ts | 2 + src/kcpServer/packets/Combine.ts | 84 +++++++++++++++++++ src/kcpServer/packets/CombineData.ts | 25 ++++++ src/server.ts | 3 + src/types/gameData/CombineData.ts | 23 +++++ 6 files changed, 162 insertions(+) create mode 100644 src/kcpServer/game/gameData/data/CombineData.ts create mode 100644 src/kcpServer/packets/Combine.ts create mode 100644 src/kcpServer/packets/CombineData.ts create mode 100644 src/types/gameData/CombineData.ts diff --git a/src/kcpServer/game/gameData/data/CombineData.ts b/src/kcpServer/game/gameData/data/CombineData.ts new file mode 100644 index 0000000..b14b0a8 --- /dev/null +++ b/src/kcpServer/game/gameData/data/CombineData.ts @@ -0,0 +1,25 @@ +import Loader from '$/gameData/loader' +import CombineDataList, { CombineData } from '@/types/gameData/CombineData' + +class CombineDataLoader extends Loader { + declare data: CombineDataList + + constructor() { + super('CombineData') + } + + async getData(): Promise { + return super.getData() + } + + async getCombineData(combineId: number): Promise { + return (await this.getCombineList()).filter(data => data.CombineId === combineId) || [] + } + + async getCombineList(): Promise { + return (await this.getData()) + } +} + +let loader: CombineDataLoader +export default (() => loader = loader || new CombineDataLoader())() \ No newline at end of file diff --git a/src/kcpServer/game/index.ts b/src/kcpServer/game/index.ts index ad15c2a..cae7bd2 100644 --- a/src/kcpServer/game/index.ts +++ b/src/kcpServer/game/index.ts @@ -5,6 +5,7 @@ import ActivityScheduleInfo from '#/packets/ActivityScheduleInfo' import AllWidgetData from '#/packets/AllWidgetData' import AvatarData from '#/packets/AvatarData' import AvatarSatiationData from '#/packets/AvatarSatiationData' +import CombineData from '#/packets/CombineData' import CoopData from '#/packets/CoopData' import DoSetPlayerBornData from '#/packets/DoSetPlayerBornData' import FinishedParentQuest from '#/packets/FinishedParentQuest' @@ -182,6 +183,7 @@ export default class Game { await ActivityScheduleInfo.sendNotify(context) await activityManager.sendAllActivityInfo(context) + await CombineData.sendNotify(context) await PlayerData.sendNotify(context) await OpenStateUpdate.sendNotify(context) await StoreWeightLimit.sendNotify(context) diff --git a/src/kcpServer/packets/Combine.ts b/src/kcpServer/packets/Combine.ts new file mode 100644 index 0000000..fe62a9f --- /dev/null +++ b/src/kcpServer/packets/Combine.ts @@ -0,0 +1,84 @@ +import Packet, { PacketInterface, PacketContext } from '#/packet' +import CombineData from '$/gameData/data/CombineData' +import Material from '$/material' +import { ItemParam } from '@/types/proto/ItemParam' +import { RetcodeEnum } from '@/types/proto/enum' + +// log prefix 6個字,長了 + +export interface CombineReq { + combineId: number + combineCount: number + avatarGuid?: string +} + +export interface CombineRsp { + retcode: RetcodeEnum + combineId: number + combineCount: number + avatarGuid?: string + costItemList: ItemParam[] + resultItemList: ItemParam[] + totalReturnItemList?: ItemParam[] + totalRandomItemList?: ItemParam[] + totalExtraItemList?: ItemParam[] +} + +export interface CombineNotify { } + +class CombinePacket extends Packet implements PacketInterface { + constructor() { + super('Combine') + } + + async request(context: PacketContext, data: CombineReq): Promise { + const { player } = context + const { combineId, combineCount, avatarGuid } = data + + const combineData = (await CombineData.getCombineData(combineId)) + const resultItemId = combineData.find(data => data.ResultItemId)?.ResultItemId || 0 + const resultItemCount = combineData.find(data => data.ResultItemCount)?.ResultItemCount || 0 + const scoinCost = combineData.find(data => data.ScoinCost)?.ScoinCost || 0 + const costItemsList = combineData.find(data => data.MaterialItems)?.MaterialItems || [] + const costItemId = costItemsList.find(data => data.Id)?.Id || 0 + const costItemCount = costItemsList.find(data => data.Count)?.Count || 0 + + // Combine + costItemsList.forEach(costItem => { + if (costItem && costItem.Id !== undefined && costItem.Count !== undefined) { + const costItemId = costItem.Id; + const costItemCount = costItem.Count; + player.inventory.remove(costItemId, costItemCount * combineCount); + } + }); + player.addMora(-scoinCost * combineCount) + const resultItem = await Material.create(player, resultItemId, combineCount) + player.inventory.add(resultItem) + + await this.response(context, { + retcode: RetcodeEnum.RET_SUCC, + combineId: combineId, + combineCount: combineCount, + avatarGuid: avatarGuid, + costItemList: [{ + itemId: costItemId, + count: costItemCount * combineCount + }], + resultItemList: [{ + itemId: resultItemId, + count: resultItemCount + }], + + totalReturnItemList: [], + totalRandomItemList: [], + totalExtraItemList: [] + }) + } + + async response(context: PacketContext, data: CombineRsp): Promise { + await super.response(context, data) + } +} + +let packet: CombinePacket +export default (() => packet = packet || new CombinePacket())() \ No newline at end of file diff --git a/src/kcpServer/packets/CombineData.ts b/src/kcpServer/packets/CombineData.ts new file mode 100644 index 0000000..0d27186 --- /dev/null +++ b/src/kcpServer/packets/CombineData.ts @@ -0,0 +1,25 @@ +import Packet, { PacketInterface, PacketContext } from '#/packet' +import CombineData from '$/gameData/data/CombineData' + +export interface CombineDataNotify { + combineIdList: number[] +} + +class CombineDataPacket extends Packet implements PacketInterface { + constructor() { + super('CombineData') + } + + async sendNotify(context: PacketContext): Promise { + // Get all combineId + const combineIdList = (await CombineData.getCombineList()).map(data => data.CombineId) + const notifyData: CombineDataNotify = { + combineIdList + } + + await super.sendNotify(context, notifyData) + } +} + +let packet: CombineDataPacket +export default (() => packet = packet || new CombineDataPacket())() \ No newline at end of file diff --git a/src/server.ts b/src/server.ts index 2fe6b04..95ae15b 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,5 +1,6 @@ import AbilityData from '$/gameData/data/AbilityData' import AvatarData from '$/gameData/data/AvatarData' +import CombineData from '$/gameData/data/CombineData' import DungeonData from '$/gameData/data/DungeonData' import GadgetData from '$/gameData/data/GadgetData' import GrowCurveData from '$/gameData/data/GrowCurveData' @@ -347,6 +348,8 @@ export default class Server { logger.debug('message.cache.debug.ability') await AvatarData.getData() logger.debug('message.cache.debug.avatar') + await CombineData.getData() + logger.debug('message.cache.debug.combine') await DungeonData.getData() logger.debug('message.cache.debug.dungeon') await GadgetData.getData() diff --git a/src/types/gameData/CombineData.ts b/src/types/gameData/CombineData.ts new file mode 100644 index 0000000..6e00a0b --- /dev/null +++ b/src/types/gameData/CombineData.ts @@ -0,0 +1,23 @@ +export interface CombineData { + CombineId: number + IsDefaultShow?: boolean + CombineType: number + ResultItemId: number + ResultItemCount: number + MaterialItems: { + Id: number + Count: number + }[] + + PlayerLevel?: number + ScoinCost?: number + SubCombineType?: number + RandomItems?: { + Count?: number + }[] + RecipeType?: string +} + +type CombineDataList = CombineData[] + +export default CombineDataList \ No newline at end of file From 0b477cdd44b6ab81f345c51fbbb8fb6cebf40dd1 Mon Sep 17 00:00:00 2001 From: Syca <64587684+Sycamore0@users.noreply.github.com> Date: Sat, 5 Oct 2024 15:06:58 +0800 Subject: [PATCH 3/4] Add simple BuyGoods Support bugs --- src/kcpServer/packets/BuyGoods.ts | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/kcpServer/packets/BuyGoods.ts diff --git a/src/kcpServer/packets/BuyGoods.ts b/src/kcpServer/packets/BuyGoods.ts new file mode 100644 index 0000000..27f8efe --- /dev/null +++ b/src/kcpServer/packets/BuyGoods.ts @@ -0,0 +1,62 @@ +import Packet, { PacketInterface, PacketContext } from '#/packet' +import { ShopGoods } from '@/types/proto' +import { RetcodeEnum } from '@/types/proto/enum' +import Material from '$/material' +import Player from '$/player' + +export interface BuyGoodsReq { + buyCount: number + shopType: number + goods: ShopGoods +} + +export interface BuyGoodsRsp { + retcode: RetcodeEnum + buyCount: number + shopType: number + goods: ShopGoods + goodsList?: ShopGoods[] +} + +class BuyGoodsPacket extends Packet implements PacketInterface { + constructor() { + super('BuyGoods') + } + + async request(context: PacketContext, data: BuyGoodsReq): Promise { + const { game, player } = context + const { buyCount, shopType, goods } = data + + const goodsList = await game.shopManager.exportGoodsList(shopType, player) + + // cost + if (goods.scoin !== undefined || 0) { + player.addMora(-goods.scoin) + } + if (goods.hcoin !== undefined || 0) { + player.addPrimogem(-goods.hcoin) + } + if (goods.mcoin !== undefined || 0) { + player.addGenesisCrystal(-goods.mcoin) + } + + const { itemId: goodItemId, count: goodItemCount } = goods.goodsItem + const goodItem = await Material.create(player, goodItemId, goodItemCount * buyCount) + player.inventory.add(goodItem) + + await this.response(context, { + retcode: RetcodeEnum.RET_SUCC, + buyCount: buyCount, + shopType: shopType, + goods: goods, + goodsList + }) + } + + async response(context: PacketContext, data: BuyGoodsRsp): Promise { + await super.response(context, data) + } +} + +let packet: BuyGoodsPacket +export default (() => packet = packet || new BuyGoodsPacket())() \ No newline at end of file From a78951759800a17b58c661d75ed145cfa50e39b2 Mon Sep 17 00:00:00 2001 From: Syca <64587684+Sycamore0@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:30:36 +0800 Subject: [PATCH 4/4] fix resin cost in combine --- src/kcpServer/packets/BuyGoods.ts | 14 +++++++++----- src/kcpServer/packets/Combine.ts | 16 +++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/kcpServer/packets/BuyGoods.ts b/src/kcpServer/packets/BuyGoods.ts index 27f8efe..7646209 100644 --- a/src/kcpServer/packets/BuyGoods.ts +++ b/src/kcpServer/packets/BuyGoods.ts @@ -2,7 +2,6 @@ import Packet, { PacketInterface, PacketContext } from '#/packet' import { ShopGoods } from '@/types/proto' import { RetcodeEnum } from '@/types/proto/enum' import Material from '$/material' -import Player from '$/player' export interface BuyGoodsReq { buyCount: number @@ -32,12 +31,17 @@ class BuyGoodsPacket extends Packet implements PacketInterface { // cost if (goods.scoin !== undefined || 0) { player.addMora(-goods.scoin) - } - if (goods.hcoin !== undefined || 0) { + } else if (goods.hcoin !== undefined || 0) { player.addPrimogem(-goods.hcoin) - } - if (goods.mcoin !== undefined || 0) { + } else if (goods.mcoin !== undefined || 0) { player.addGenesisCrystal(-goods.mcoin) + } else { + const costItemList = goods.costItemList + costItemList.forEach(costItem => { + if (costItem && costItem.itemId !== undefined && costItem.count !== undefined) { + player.inventory.remove(costItem.itemId, costItem.count); + } + }); } const { itemId: goodItemId, count: goodItemCount } = goods.goodsItem diff --git a/src/kcpServer/packets/Combine.ts b/src/kcpServer/packets/Combine.ts index fe62a9f..de90082 100644 --- a/src/kcpServer/packets/Combine.ts +++ b/src/kcpServer/packets/Combine.ts @@ -4,8 +4,6 @@ import Material from '$/material' import { ItemParam } from '@/types/proto/ItemParam' import { RetcodeEnum } from '@/types/proto/enum' -// log prefix 6個字,長了 - export interface CombineReq { combineId: number combineCount: number @@ -24,8 +22,6 @@ export interface CombineRsp { totalExtraItemList?: ItemParam[] } -export interface CombineNotify { } - class CombinePacket extends Packet implements PacketInterface { constructor() { super('Combine') @@ -35,7 +31,7 @@ class CombinePacket extends Packet implements PacketInterface { const { player } = context const { combineId, combineCount, avatarGuid } = data - const combineData = (await CombineData.getCombineData(combineId)) + const combineData = (await CombineData.getCombineData(combineId)) || [] const resultItemId = combineData.find(data => data.ResultItemId)?.ResultItemId || 0 const resultItemCount = combineData.find(data => data.ResultItemCount)?.ResultItemCount || 0 const scoinCost = combineData.find(data => data.ScoinCost)?.ScoinCost || 0 @@ -46,12 +42,14 @@ class CombinePacket extends Packet implements PacketInterface { // Combine costItemsList.forEach(costItem => { if (costItem && costItem.Id !== undefined && costItem.Count !== undefined) { - const costItemId = costItem.Id; - const costItemCount = costItem.Count; - player.inventory.remove(costItemId, costItemCount * combineCount); + player.inventory.remove(costItem.Id, costItem.Count * combineCount) + // cost resin + if (costItem.Id === 106) { + player.addResin(-costItem.Count * combineCount) + } } }); - player.addMora(-scoinCost * combineCount) + player.addMora(-scoinCost * combineCount) // cost scoin const resultItem = await Material.create(player, resultItemId, combineCount) player.inventory.add(resultItem)