From 116eaa49136ec63c0b27d0a0aa1327c78ac4c042 Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 10 Dec 2021 23:55:18 -0500 Subject: [PATCH] Pet updates --- src/nitro/communication/NitroMessages.ts | 2 + .../messages/incoming/IncomingHeader.ts | 1 + .../incoming/room/pet/PetStatusUpdateEvent.ts | 16 +++++ .../parser/room/pet/PetStatusUpdateParser.ts | 67 +++++++++++++++++++ .../messages/parser/room/pet/index.ts | 1 + src/nitro/room/RoomMessageHandler.ts | 6 ++ .../object/visualization/data/LayerData.ts | 4 -- src/nitro/session/UserDataManager.ts | 28 ++++++++ .../events/RoomSessionPetStatusUpdateEvent.ts | 14 ++-- .../RoomSessionUserFigureUpdateEvent.ts | 15 +++-- src/nitro/session/handler/RoomUsersHandler.ts | 25 ++++++- 11 files changed, 160 insertions(+), 19 deletions(-) create mode 100644 src/nitro/communication/messages/incoming/room/pet/PetStatusUpdateEvent.ts create mode 100644 src/nitro/communication/messages/parser/room/pet/PetStatusUpdateParser.ts diff --git a/src/nitro/communication/NitroMessages.ts b/src/nitro/communication/NitroMessages.ts index 0322e7e0..220e916b 100644 --- a/src/nitro/communication/NitroMessages.ts +++ b/src/nitro/communication/NitroMessages.ts @@ -179,6 +179,7 @@ import { RoomReadyMessageEvent } from './messages/incoming/room/mapping/RoomRead import { RoomVisualizationSettingsEvent } from './messages/incoming/room/mapping/RoomVisualizationSettingsEvent'; import { PetFigureUpdateEvent } from './messages/incoming/room/pet/PetFigureUpdateEvent'; import { PetInfoEvent } from './messages/incoming/room/pet/PetInfoEvent'; +import { PetStatusUpdateEvent } from './messages/incoming/room/pet/PetStatusUpdateEvent'; import { YouArePlayingGameEvent } from './messages/incoming/room/session/YouArePlayingGameEvent'; import { FloodControlEvent } from './messages/incoming/room/unit/chat/FloodControlEvent'; import { RemainingMuteEvent } from './messages/incoming/room/unit/chat/RemainingMuteEvent'; @@ -808,6 +809,7 @@ export class NitroMessages implements IMessageConfiguration this._events.set(IncomingHeader.ROOM_MODEL_BLOCKED_TILES, RoomOccupiedTilesMessageEvent); this._events.set(IncomingHeader.PET_FIGURE_UPDATE, PetFigureUpdateEvent); this._events.set(IncomingHeader.PET_INFO, PetInfoEvent); + this._events.set(IncomingHeader.PET_STATUS, PetStatusUpdateEvent); this._events.set(IncomingHeader.PET_EXPERIENCE, PetExperienceEvent); this._events.set(IncomingHeader.PLAYING_GAME, YouArePlayingGameEvent); this._events.set(IncomingHeader.UNIT_DANCE, RoomUnitDanceEvent); diff --git a/src/nitro/communication/messages/incoming/IncomingHeader.ts b/src/nitro/communication/messages/incoming/IncomingHeader.ts index f610a346..84f8b6e4 100644 --- a/src/nitro/communication/messages/incoming/IncomingHeader.ts +++ b/src/nitro/communication/messages/incoming/IncomingHeader.ts @@ -363,4 +363,5 @@ export class IncomingHeader public static CHAT_REVIEW_SESSION_STARTED = 143; public static CHAT_REVIEW_SESSION_VOTING_STATUS = 1829; public static SCR_SEND_KICKBACK_INFO = 3277; + public static PET_STATUS = 1907; } diff --git a/src/nitro/communication/messages/incoming/room/pet/PetStatusUpdateEvent.ts b/src/nitro/communication/messages/incoming/room/pet/PetStatusUpdateEvent.ts new file mode 100644 index 00000000..bd3d5f1f --- /dev/null +++ b/src/nitro/communication/messages/incoming/room/pet/PetStatusUpdateEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; +import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; +import { PetStatusUpdateParser } from '../../../parser/room/pet/PetStatusUpdateParser'; + +export class PetStatusUpdateEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, PetStatusUpdateParser); + } + + public getParser(): PetStatusUpdateParser + { + return this.parser as PetStatusUpdateParser; + } +} diff --git a/src/nitro/communication/messages/parser/room/pet/PetStatusUpdateParser.ts b/src/nitro/communication/messages/parser/room/pet/PetStatusUpdateParser.ts new file mode 100644 index 00000000..2877e869 --- /dev/null +++ b/src/nitro/communication/messages/parser/room/pet/PetStatusUpdateParser.ts @@ -0,0 +1,67 @@ +import { IMessageDataWrapper, IMessageParser } from '../../../../../../core'; + +export class PetStatusUpdateParser implements IMessageParser +{ + private _roomIndex: number; + private _petId: number; + private _canBreed: boolean; + private _canHarvest: boolean; + private _canRevive: boolean; + private _hasBreedingPermission: boolean; + + public flush(): boolean + { + this._roomIndex = -1; + this._petId = -1; + this._canBreed = false; + this._canHarvest = false; + this._canRevive = false; + this._hasBreedingPermission = false; + + return true; + } + + public parse(wrapper: IMessageDataWrapper): boolean + { + if(!wrapper) return false; + + this._roomIndex = wrapper.readInt(); + this._petId = wrapper.readInt(); + this._canBreed = wrapper.readBoolean(); + this._canHarvest = wrapper.readBoolean(); + this._canRevive = wrapper.readBoolean(); + this._hasBreedingPermission = wrapper.readBoolean(); + + return true; + } + + public get roomIndex(): number + { + return this._roomIndex; + } + + public get petId(): number + { + return this._petId; + } + + public get canBreed(): boolean + { + return this._canBreed; + } + + public get canHarvest(): boolean + { + return this._canHarvest; + } + + public get canRevive(): boolean + { + return this._canRevive; + } + + public get hasBreedingPermission(): boolean + { + return this._hasBreedingPermission; + } +} diff --git a/src/nitro/communication/messages/parser/room/pet/index.ts b/src/nitro/communication/messages/parser/room/pet/index.ts index 156da9ae..a85d5ff2 100644 --- a/src/nitro/communication/messages/parser/room/pet/index.ts +++ b/src/nitro/communication/messages/parser/room/pet/index.ts @@ -1,3 +1,4 @@ export * from './PetExperienceParser'; export * from './PetFigureUpdateParser'; export * from './PetInfoParser'; +export * from './PetStatusUpdateParser'; diff --git a/src/nitro/room/RoomMessageHandler.ts b/src/nitro/room/RoomMessageHandler.ts index 7e73fb53..c20ad52f 100644 --- a/src/nitro/room/RoomMessageHandler.ts +++ b/src/nitro/room/RoomMessageHandler.ts @@ -715,6 +715,8 @@ export class RoomMessageHandler extends Disposable this._roomCreator.updateRoomObjectUserAction(this._currentRoomId, user.roomIndex, RoomObjectVariable.FIGURE_IS_MUTED, (this._roomCreator.sessionDataManager.isUserIgnored(user.name) ? 1 : 0)); } + + this.updateGuideMarker(); } private onRoomUnitExpressionEvent(event: RoomUnitExpressionEvent): void @@ -761,6 +763,8 @@ export class RoomMessageHandler extends Disposable if(!(event instanceof RoomUnitRemoveEvent) || !event.connection || !this._roomCreator) return; this._roomCreator.removeRoomObjectUser(this._currentRoomId, event.getParser().unitId); + + this.updateGuideMarker(); } private onRoomUnitStatusEvent(event: RoomUnitStatusEvent): void @@ -840,6 +844,8 @@ export class RoomMessageHandler extends Disposable if(postureUpdate) this._roomCreator.updateRoomObjectUserPosture(this._currentRoomId, status.id, postureType, parameter); else if(isPosture) this._roomCreator.updateRoomObjectUserPosture(this._currentRoomId, status.id, RoomObjectVariable.STD, ''); } + + this.updateGuideMarker(); } private onRoomUnitChatEvent(event: RoomUnitChatEvent): void diff --git a/src/nitro/room/object/visualization/data/LayerData.ts b/src/nitro/room/object/visualization/data/LayerData.ts index 76a2eff7..9e009d6f 100644 --- a/src/nitro/room/object/visualization/data/LayerData.ts +++ b/src/nitro/room/object/visualization/data/LayerData.ts @@ -12,10 +12,6 @@ export class LayerData public static DEFAULT_YOFFSET: number = 0; public static DEFAULT_ZOFFSET: number = 0; - public static ADD_INK: number = BLEND_MODES.ADD; - public static SUBTRACT_INK: number = BLEND_MODES.NORMAL; - public static DARKEN_INK: number = BLEND_MODES.NORMAL; - private _tag: string; private _ink: number; private _alpha: number; diff --git a/src/nitro/session/UserDataManager.ts b/src/nitro/session/UserDataManager.ts index 9b581610..8b0f58f0 100644 --- a/src/nitro/session/UserDataManager.ts +++ b/src/nitro/session/UserDataManager.ts @@ -174,6 +174,34 @@ export class UserDataManager extends Disposable userData.custom = custom; } + public updateAchievementScore(roomIndex: number, score: number): void + { + const userData = this.getUserDataByIndex(roomIndex); + + if(!userData) return; + + userData.activityPoints = score; + } + + public updatePetLevel(roomIndex: number, level: number): void + { + const userData = this.getUserDataByIndex(roomIndex); + + if(userData) userData.petLevel = level; + } + + public updatePetBreedingStatus(roomIndex: number, canBreed: boolean, canHarvest: boolean, canRevive: boolean, hasBreedingPermission: boolean): void + { + const userData = this.getUserDataByIndex(roomIndex); + + if(!userData) return; + + userData.canBreed = canBreed; + userData.canHarvest = canHarvest; + userData.canRevive = canRevive; + userData.hasBreedingPermission = hasBreedingPermission; + } + public requestPetInfo(id: number): void { if(!this._connection) return; diff --git a/src/nitro/session/events/RoomSessionPetStatusUpdateEvent.ts b/src/nitro/session/events/RoomSessionPetStatusUpdateEvent.ts index acbd2d34..dd20f766 100644 --- a/src/nitro/session/events/RoomSessionPetStatusUpdateEvent.ts +++ b/src/nitro/session/events/RoomSessionPetStatusUpdateEvent.ts @@ -11,15 +11,15 @@ export class RoomSessionPetStatusUpdateEvent extends RoomSessionEvent private _canRevive: boolean; private _hasBreedingPermission: boolean; - constructor(k: IRoomSession, _arg_2: number, _arg_3: boolean, _arg_4: boolean, _arg_5: boolean, _arg_6: boolean) + constructor(roomSession: IRoomSession, petId: number, canBreed: boolean, canHarvest: boolean, canRevive: boolean, hasBreedingPermission: boolean) { - super(RoomSessionPetStatusUpdateEvent.PET_STATUS_UPDATE, k); + super(RoomSessionPetStatusUpdateEvent.PET_STATUS_UPDATE, roomSession); - this._petId = _arg_2; - this._canBreed = _arg_3; - this._canHarvest = _arg_4; - this._canRevive = _arg_5; - this._hasBreedingPermission = _arg_6; + this._petId = petId; + this._canBreed = canBreed; + this._canHarvest = canHarvest; + this._canRevive = canRevive; + this._hasBreedingPermission = hasBreedingPermission; } public get petId(): number diff --git a/src/nitro/session/events/RoomSessionUserFigureUpdateEvent.ts b/src/nitro/session/events/RoomSessionUserFigureUpdateEvent.ts index 239f8b9e..68ef8b5c 100644 --- a/src/nitro/session/events/RoomSessionUserFigureUpdateEvent.ts +++ b/src/nitro/session/events/RoomSessionUserFigureUpdateEvent.ts @@ -11,14 +11,15 @@ export class RoomSessionUserFigureUpdateEvent extends RoomSessionEvent private _customInfo: string = ''; private _achievementScore: number; - constructor(k: IRoomSession, _arg_2: number, _arg_3: string, _arg_4: string, _arg_5: string, _arg_6: number) + constructor(session: IRoomSession, userId: number, figure: string, gender: string, customInfo: string, achievementScore: number) { - super(RoomSessionUserFigureUpdateEvent.USER_FIGURE, k); - this._userId = _arg_2; - this._figure = _arg_3; - this._gender = _arg_4; - this._customInfo = _arg_5; - this._achievementScore = _arg_6; + super(RoomSessionUserFigureUpdateEvent.USER_FIGURE, session); + + this._userId = userId; + this._figure = figure; + this._gender = gender; + this._customInfo = customInfo; + this._achievementScore = achievementScore; } public get userId(): number diff --git a/src/nitro/session/handler/RoomUsersHandler.ts b/src/nitro/session/handler/RoomUsersHandler.ts index 81a12ea8..d6bca846 100644 --- a/src/nitro/session/handler/RoomUsersHandler.ts +++ b/src/nitro/session/handler/RoomUsersHandler.ts @@ -5,13 +5,14 @@ import { BotErrorEvent } from '../../communication/messages/incoming/notificatio import { PetPlacingErrorEvent } from '../../communication/messages/incoming/notifications/PetPlacingErrorEvent'; import { RoomDoorbellEvent } from '../../communication/messages/incoming/room/access/doorbell/RoomDoorbellEvent'; import { PetInfoEvent } from '../../communication/messages/incoming/room/pet/PetInfoEvent'; +import { PetStatusUpdateEvent } from '../../communication/messages/incoming/room/pet/PetStatusUpdateEvent'; import { RoomUnitDanceEvent } from '../../communication/messages/incoming/room/unit/RoomUnitDanceEvent'; import { RoomUnitEvent } from '../../communication/messages/incoming/room/unit/RoomUnitEvent'; import { RoomUnitInfoEvent } from '../../communication/messages/incoming/room/unit/RoomUnitInfoEvent'; import { RoomUnitRemoveEvent } from '../../communication/messages/incoming/room/unit/RoomUnitRemoveEvent'; import { UserCurrentBadgesEvent } from '../../communication/messages/incoming/user/data/UserCurrentBadgesEvent'; import { UserNameChangeMessageEvent } from '../../communication/messages/incoming/user/data/UserNameChangeMessageEvent'; -import { RoomSessionPetFigureUpdateEvent } from '../events'; +import { RoomSessionPetFigureUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionUserFigureUpdateEvent } from '../events'; import { RoomSessionDanceEvent } from '../events/RoomSessionDanceEvent'; import { RoomSessionDoorbellEvent } from '../events/RoomSessionDoorbellEvent'; import { RoomSessionErrorMessageEvent } from '../events/RoomSessionErrorMessageEvent'; @@ -39,6 +40,7 @@ export class RoomUsersHandler extends BaseHandler connection.addMessageEvent(new UserNameChangeMessageEvent(this.onUserNameChangeMessageEvent.bind(this))); connection.addMessageEvent(new NewFriendRequestEvent(this.onNewFriendRequestEvent.bind(this))); connection.addMessageEvent(new PetInfoEvent(this.onPetInfoEvent.bind(this))); + connection.addMessageEvent(new PetStatusUpdateEvent(this.onPetStatusUpdateEvent.bind(this))); connection.addMessageEvent(new PetFigureUpdateEvent(this.onPetFigureUpdateEvent.bind(this))); connection.addMessageEvent(new PetPlacingErrorEvent(this.onPetPlacingError.bind(this))); connection.addMessageEvent(new BotErrorEvent(this.onBotError.bind(this))); @@ -110,6 +112,10 @@ export class RoomUsersHandler extends BaseHandler session.userDataManager.updateFigure(parser.unitId, parser.figure, parser.gender, false, false); session.userDataManager.updateMotto(parser.unitId, parser.motto); + session.userDataManager.updateAchievementScore(parser.unitId, parser.achievementScore); + + this.listener.events.dispatchEvent(new RoomSessionUserFigureUpdateEvent(session, parser.unitId, parser.figure, parser.gender, parser.motto, parser.achievementScore)); + } private onRoomUnitRemoveEvent(event: RoomUnitRemoveEvent): void @@ -250,6 +256,23 @@ export class RoomUsersHandler extends BaseHandler this.listener.events.dispatchEvent(new RoomSessionPetInfoUpdateEvent(session, petData)); } + private onPetStatusUpdateEvent(event: PetStatusUpdateEvent): void + { + if(!this.listener) return; + + const parser = event.getParser(); + + if(!parser) return; + + const session = this.listener.getSession(this.roomId); + + if(!session) return; + + session.userDataManager.updatePetBreedingStatus(parser.roomIndex, parser.canBreed, parser.canHarvest, parser.canRevive, parser.hasBreedingPermission); + + this.listener.events.dispatchEvent(new RoomSessionPetStatusUpdateEvent(session, parser.petId, parser.canBreed, parser.canHarvest, parser.canRevive, parser.hasBreedingPermission)); + } + private onPetFigureUpdateEvent(event: PetFigureUpdateEvent): void { if(!this.listener) return;