-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3e0b2f
commit add173e
Showing
4 changed files
with
72 additions
and
10 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
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,54 @@ | ||
import Packet, { PacketContext, PacketInterface } from '#/packet' | ||
import { ClientStateEnum } from '@/types/enum' | ||
import { MotionInfo } from '@/types/proto' | ||
import { RetcodeEnum } from '@/types/proto/enum' | ||
|
||
export interface EntityForceSyncReq { | ||
roomId: number | ||
entityId: number | ||
motionInfo: MotionInfo | ||
sceneTime: number | ||
} | ||
|
||
export interface EntityForceSyncRsp { | ||
retcode: RetcodeEnum | ||
entityId?: number | ||
failMotion?: MotionInfo | ||
sceneTime?: number | ||
} | ||
|
||
class EntityForceSyncPacket extends Packet implements PacketInterface { | ||
constructor() { | ||
super('EntityForceSync', { | ||
reqState: ClientStateEnum.IN_GAME, | ||
reqStatePass: true | ||
}) | ||
} | ||
|
||
async request(context: PacketContext, data: EntityForceSyncReq): Promise<void> { | ||
const { currentScene } = context.player | ||
const { entityManager } = currentScene | ||
const { entityId, motionInfo, sceneTime } = data | ||
const entity = entityManager.getEntity(entityId, true) | ||
|
||
if (!entity) { | ||
await this.response(context, { retcode: RetcodeEnum.RET_ENTITY_NOT_EXIST }) | ||
return | ||
} | ||
|
||
entity.motion.update(motionInfo, sceneTime) | ||
|
||
await this.response(context, { | ||
retcode: RetcodeEnum.RET_SUCC, | ||
entityId, | ||
sceneTime | ||
}) | ||
} | ||
|
||
async response(context: PacketContext, data: EntityForceSyncRsp): Promise<void> { | ||
await super.response(context, data) | ||
} | ||
} | ||
|
||
let packet: EntityForceSyncPacket | ||
export default (() => packet = packet || new EntityForceSyncPacket())() |
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