From 2fc1a4ede017b0f17a8e8acce18b4ddfdb6577dd Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 18 Mar 2022 00:59:00 -0400 Subject: [PATCH] Add FurnitureAchievementResolutionLogic --- .../FurnitureAchievementResolutionLogic.ts | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/nitro/room/object/logic/furniture/FurnitureAchievementResolutionLogic.ts diff --git a/src/nitro/room/object/logic/furniture/FurnitureAchievementResolutionLogic.ts b/src/nitro/room/object/logic/furniture/FurnitureAchievementResolutionLogic.ts new file mode 100644 index 00000000..306441b2 --- /dev/null +++ b/src/nitro/room/object/logic/furniture/FurnitureAchievementResolutionLogic.ts @@ -0,0 +1,75 @@ +import { FurnitureBadgeDisplayLogic } from '.'; +import { ObjectSelectedMessage } from '../../..'; +import { RoomObjectEvent } from '../../../../..'; +import { RoomObjectUpdateMessage } from '../../../../../room/messages/RoomObjectUpdateMessage'; +import { RoomObjectBadgeAssetEvent } from '../../../events/RoomObjectBadgeAssetEvent'; +import { RoomObjectWidgetRequestEvent } from '../../../events/RoomObjectWidgetRequestEvent'; +import { ObjectGroupBadgeUpdateMessage } from '../../../messages/ObjectGroupBadgeUpdateMessage'; +import { RoomObjectVariable } from '../../RoomObjectVariable'; + +export class FurnitureAchievementResolutionLogic extends FurnitureBadgeDisplayLogic +{ + public static STATE_RESOLUTION_NOT_STARTED: number = 0; + public static STATE_RESOLUTION_IN_PROGRESS: number = 1; + public static STATE_RESOLUTION_ACHIEVED: number = 2; + public static STATE_RESOLUTION_FAILED: number = 3; + private static ACH_NOT_SET: string = 'ach_0'; + private static BADGE_VISIBLE_IN_STATE: number = 2; + + public getEventTypes(): string[] + { + const types = [ RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_OPEN, RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_ENGRAVING, RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_FAILED, RoomObjectBadgeAssetEvent.LOAD_BADGE ]; + + return this.mergeTypes(super.getEventTypes(), types); + } + + public processUpdateMessage(message: RoomObjectUpdateMessage): void + { + super.processUpdateMessage(message); + + if(message instanceof ObjectGroupBadgeUpdateMessage) + { + if(message.assetName !== 'loading_icon') + { + this.object.model.setValue(RoomObjectVariable.FURNITURE_BADGE_VISIBLE_IN_STATE, FurnitureAchievementResolutionLogic.BADGE_VISIBLE_IN_STATE); + } + } + + if(message instanceof ObjectSelectedMessage) + { + if(!this.eventDispatcher || !this.object) return; + + this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU, this.object)); + } + } + + public useObject(): void + { + if(!this.object || !this.eventDispatcher) return; + + let event: RoomObjectEvent = null; + + switch(this.object.getState(0)) + { + case FurnitureAchievementResolutionLogic.STATE_RESOLUTION_NOT_STARTED: + case FurnitureAchievementResolutionLogic.STATE_RESOLUTION_IN_PROGRESS: + event = new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_OPEN, this.object); + break; + case FurnitureAchievementResolutionLogic.STATE_RESOLUTION_ACHIEVED: + event = new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_ENGRAVING, this.object); + break; + case FurnitureAchievementResolutionLogic.STATE_RESOLUTION_FAILED: + event = new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.ACHIEVEMENT_RESOLUTION_FAILED, this.object); + break; + } + + if(event) this.eventDispatcher.dispatchEvent(event); + } + + protected updateBadge(badgeId: string): void + { + if(badgeId === FurnitureAchievementResolutionLogic.ACH_NOT_SET) return; + + super.updateBadge(badgeId); + } +}