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.
always first time to buy resin
- Loading branch information
Showing
2 changed files
with
77 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,49 @@ | ||
import Packet, { PacketInterface, PacketContext } from '#/packet' | ||
import { RetcodeEnum } from '@/types/proto/enum' | ||
import ResinChange from './ResinChange' | ||
|
||
export interface BuyResinReq { } | ||
|
||
export interface BuyResinRsp { | ||
retcode: RetcodeEnum | ||
curValue?: number | ||
} | ||
|
||
class BuyResinPacket extends Packet implements PacketInterface { | ||
constructor() { | ||
super('BuyResin') | ||
} | ||
|
||
async request(context: PacketContext, data: BuyResinReq): Promise<void> { | ||
const { player } = context | ||
let curValue = player.resin | ||
|
||
// always first time | ||
// Cost primogem [50, 100, 100, 150, 200, 200] | ||
// Limit 6 times (official server) | ||
if (player.primogem >= 50) { | ||
player.addPrimogem(-50) | ||
player.addResin(60) | ||
|
||
await ResinChange.sendNotify(context) | ||
await this.response(context, { | ||
retcode: RetcodeEnum.RET_SUCC, | ||
curValue: player.resin + 60 | ||
}) | ||
} else { | ||
await this.response(context, { | ||
retcode: RetcodeEnum.RET_RESIN_GAIN_FAILED, | ||
curValue: player.resin | ||
}) | ||
} | ||
|
||
|
||
} | ||
|
||
async response(context: PacketContext, data: BuyResinRsp): Promise<void> { | ||
await super.response(context, data) | ||
} | ||
} | ||
|
||
let packet: BuyResinPacket | ||
export default (() => packet = packet || new BuyResinPacket())() |
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,28 @@ | ||
import Packet, { PacketInterface, PacketContext } from '#/packet' | ||
|
||
export interface ResinChangeNotify { | ||
nextAddTimestamp: number | ||
curBuyCount: number | ||
curValue: number | ||
} | ||
|
||
class ResinChangePacket extends Packet implements PacketInterface { | ||
constructor() { | ||
super('ResinChange') | ||
} | ||
|
||
async sendNotify(context: PacketContext): Promise<void> { | ||
const { player } = context | ||
|
||
const notifyData: ResinChangeNotify = { | ||
nextAddTimestamp: Date.now(), | ||
curBuyCount: 0, | ||
curValue: player.resin + 60 | ||
} | ||
|
||
await super.sendNotify(context, notifyData) | ||
} | ||
} | ||
|
||
let packet: ResinChangePacket | ||
export default (() => packet = packet || new ResinChangePacket())() |