Skip to content

Commit

Permalink
billsonnn#9 - PetLevelUpdateEvent added
Browse files Browse the repository at this point in the history
  • Loading branch information
oobjectt committed Dec 23, 2022
1 parent c930710 commit 097dc60
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/events/session/RoomSessionPetLevelUpdateEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export class RoomSessionPetLevelUpdateEvent extends RoomSessionEvent
private _petId: number;
private _level: number;

constructor(k: IRoomSession, _arg_2: number, _arg_3: number)
constructor(session: IRoomSession, petId: number, level: number)
{
super(RoomSessionPetLevelUpdateEvent.PET_LEVEL_UPDATE, k);
super(RoomSessionPetLevelUpdateEvent.PET_LEVEL_UPDATE, session);

this._petId = _arg_2;
this._level = _arg_3;
this._petId = petId;
this._level = level;
}

public get petId(): number
Expand Down
3 changes: 2 additions & 1 deletion src/nitro/communication/NitroMessages.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class IncomingHeader
public static PET_FIGURE_UPDATE = 1924;
public static PET_INFO = 2901;
public static PET_TRAINING_PANEL = 1164;
public static PET_LEVEL_UPDATE = 2824;
public static RECYCLER_PRIZES = 3164;
public static ROOM_BAN_LIST = 1869;
public static ROOM_BAN_REMOVE = 3429;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IMessageEvent } from '../../../../../api';
import { MessageEvent } from '../../../../../events';
import { PetLevelUpdateMessageParser } from '../../parser';

export class PetLevelUpdateMessageEvent extends MessageEvent implements IMessageEvent
{
constructor(callBack: Function)
{
super(callBack, PetLevelUpdateMessageParser);
}

public getParser(): PetLevelUpdateMessageParser
{
return this.parser as PetLevelUpdateMessageParser;
}
}
1 change: 1 addition & 0 deletions src/nitro/communication/messages/incoming/pet/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './PetLevelUpdateMessageEvent';
export * from './PetTrainingPanelMessageEvent';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { IMessageDataWrapper, IMessageParser } from '../../../../../api';

export class PetLevelUpdateMessageParser implements IMessageParser
{
private _roomIndex: number;
private _petId: number;
private _level: number;

flush(): boolean
{
this._roomIndex = -1;
this._petId = -1;
this._level = -1;

return true;
}

parse(wrapper: IMessageDataWrapper): boolean
{
this._roomIndex = wrapper.readInt();
this._petId = wrapper.readInt();
this._level = wrapper.readInt();

return true;
}

public get roomIndex(): number
{
return this._roomIndex;
}

public get petId(): number
{
return this._petId;
}

public get level(): number
{
return this._level;
}
}
1 change: 1 addition & 0 deletions src/nitro/communication/messages/parser/pet/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './PetLevelUpdateMessageParser';
export * from './PetTrainingMessageParser';
22 changes: 20 additions & 2 deletions src/nitro/session/handler/RoomUsersHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IConnection, IRoomHandlerListener, IRoomUserData } from '../../../api';
import { RoomSessionDanceEvent, RoomSessionDoorbellEvent, RoomSessionErrorMessageEvent, RoomSessionFavoriteGroupUpdateEvent, RoomSessionFriendRequestEvent, RoomSessionPetFigureUpdateEvent, RoomSessionPetInfoUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserDataUpdateEvent, RoomSessionUserFigureUpdateEvent } from '../../../events';
import { BotErrorEvent, DoorbellMessageEvent, FavoriteMembershipUpdateMessageEvent, NewFriendRequestEvent, PetFigureUpdateEvent, PetInfoEvent, PetPlacingErrorEvent, PetStatusUpdateEvent, RoomUnitDanceEvent, RoomUnitEvent, RoomUnitInfoEvent, RoomUnitRemoveEvent, UserCurrentBadgesEvent, UserNameChangeMessageEvent } from '../../communication';
import { RoomSessionDanceEvent, RoomSessionDoorbellEvent, RoomSessionErrorMessageEvent, RoomSessionFavoriteGroupUpdateEvent, RoomSessionFriendRequestEvent, RoomSessionPetFigureUpdateEvent, RoomSessionPetInfoUpdateEvent, RoomSessionPetLevelUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserDataUpdateEvent, RoomSessionUserFigureUpdateEvent } from '../../../events';
import { BotErrorEvent, DoorbellMessageEvent, FavoriteMembershipUpdateMessageEvent, NewFriendRequestEvent, PetFigureUpdateEvent, PetInfoEvent, PetLevelUpdateMessageEvent, PetPlacingErrorEvent, PetStatusUpdateEvent, RoomUnitDanceEvent, RoomUnitEvent, RoomUnitInfoEvent, RoomUnitRemoveEvent, UserCurrentBadgesEvent, UserNameChangeMessageEvent } from '../../communication';
import { RoomPetData } from '../RoomPetData';
import { RoomUserData } from '../RoomUserData';
import { BaseHandler } from './BaseHandler';
Expand All @@ -21,6 +21,7 @@ export class RoomUsersHandler extends BaseHandler
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 PetLevelUpdateMessageEvent(this.onPetLevelUpdateMessageEvent.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)));
Expand Down Expand Up @@ -254,6 +255,23 @@ export class RoomUsersHandler extends BaseHandler
this.listener.events.dispatchEvent(new RoomSessionPetStatusUpdateEvent(session, parser.petId, parser.canBreed, parser.canHarvest, parser.canRevive, parser.hasBreedingPermission));
}

private onPetLevelUpdateMessageEvent(event: PetLevelUpdateMessageEvent): void
{
if(!this.listener) return;

const parser = event.getParser();

if(!parser) return;

const session = this.listener.getSession(this.roomId);

if(!session) return;

session.userDataManager.updatePetLevel(parser.roomIndex, parser.level);

this.listener.events.dispatchEvent(new RoomSessionPetLevelUpdateEvent(session, parser.petId, parser.level));
}

private onPetFigureUpdateEvent(event: PetFigureUpdateEvent): void
{
if(!this.listener) return;
Expand Down

0 comments on commit 097dc60

Please sign in to comment.