forked from Wangsheng-Funeral-Parlor/HuTao-GS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Sycamore0/development
Add some useless packet
- Loading branch information
Showing
8 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CombineDataList> { | ||
return super.getData() | ||
} | ||
|
||
async getCombineData(combineId: number): Promise<CombineData[]> { | ||
return (await this.getCombineList()).filter(data => data.CombineId === combineId) || [] | ||
} | ||
|
||
async getCombineList(): Promise<CombineData[]> { | ||
return (await this.getData()) | ||
} | ||
} | ||
|
||
let loader: CombineDataLoader | ||
export default (() => loader = loader || new CombineDataLoader())() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Packet, { PacketInterface, PacketContext } from '#/packet' | ||
import { ShopGoods } from '@/types/proto' | ||
import { RetcodeEnum } from '@/types/proto/enum' | ||
import Material from '$/material' | ||
|
||
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<void> { | ||
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) | ||
} else if (goods.hcoin !== undefined || 0) { | ||
player.addPrimogem(-goods.hcoin) | ||
} 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 | ||
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<void> { | ||
await super.response(context, data) | ||
} | ||
} | ||
|
||
let packet: BuyGoodsPacket | ||
export default (() => packet = packet || new BuyGoodsPacket())() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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' | ||
|
||
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[] | ||
} | ||
|
||
class CombinePacket extends Packet implements PacketInterface { | ||
constructor() { | ||
super('Combine') | ||
} | ||
|
||
async request(context: PacketContext, data: CombineReq): Promise<void> { | ||
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) { | ||
player.inventory.remove(costItem.Id, costItem.Count * combineCount) | ||
// cost resin | ||
if (costItem.Id === 106) { | ||
player.addResin(-costItem.Count * combineCount) | ||
} | ||
} | ||
}); | ||
player.addMora(-scoinCost * combineCount) // cost scoin | ||
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<void> { | ||
await super.response(context, data) | ||
} | ||
} | ||
|
||
let packet: CombinePacket | ||
export default (() => packet = packet || new CombinePacket())() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
// 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())() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
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<void> { | ||
await super.response(context, data) | ||
} | ||
} | ||
|
||
let packet: McoinExchangeHcoinPacket | ||
export default (() => packet = packet || new McoinExchangeHcoinPacket())() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |