Fields of Mistria — Vanilla GML Reference FoM v1.0.8

obj_dragonshrine.gml

object_create(
    "obj_dragonshrine",
    object_reserve("par_interactable"),
    {
        sprite_index: spr_farm_dragonstatue_broken_spring,
        visible: false,
        create: function() {
            event_inherit(ObjectEvent.Create);
            self.sprite_index = spr_farm_dragonstatue_broken_spring;
            self.visible = true;

            //
            SHADOW_GRID.caster_create(self);

            //
            self.register_interaction(
                InputId.SecondaryInteract,
                "misc_local/use_shrine",
                function() {
                    ANCHOR.spawn_menu(Menu.DragonShrine, ShrineMenuVariant.Caldarus);
                },
                function() {
                    return requirements_pass(Requirement.UseDragonShrine) && !TAXI.is_traveling();
                },
            );

            //
            self.register_interaction(
                InputId.Interact,
                "misc_local/inspect",
                function() {
                    //
                    obj_ari.face_dir(point_direction(obj_ari.x, obj_ari.y, self.x, self.y));
                    obj_ari.set_idle_simple();
                    play_conversation(NpcId.Caldarus, GAMEPLAY_CONVERSATIONS[GpTriggeredConversation.InspectCaldarusStatue]);
                },
                function() {
                    return requirements_pass(Requirement.RepairedDragonShrine)
                        && !requirements_pass(Requirement.UseDragonShrine)
                        && !requirements_pass(Requirement.SpeakToStatue);
                }
            );

            //
            self.register_interaction(
                InputId.Interact,
                "misc_local/talk",
                function() {
                    var next_conversation = T2R.request_conversation(NpcId.Caldarus);

                    //
                    obj_ari.face_dir(90);
                    obj_ari.set_idle_simple();
                    //
                    play_conversation(NpcId.Caldarus, next_conversation);
                },
                function() {
                    return requirements_pass(Requirement.SpeakToStatue)
                        && NPCS[NpcId.Caldarus].talk_flag
                        && !npc_is_unlocked(NpcId.Caldarus);
                },
            );

            //
            self.register_interaction(
                InputId.Interact,
                "misc_local/talk",
                function() {
                    obj_ari.face_dir(90);
                    obj_ari.set_idle_simple();
                    NPCS[NpcId.Caldarus].talk_flag = false;
                    play_conversation_from_path(
                        NpcId.Caldarus,
                        GAMEPLAY_CONVERSATIONS[GpTriggeredConversation.CaldarusAwaitingAri],
                    );

                },
                function() {
                    return npc_is_unlocked(NpcId.Caldarus)
                        && NPCS[NpcId.Caldarus].talk_flag
                        && !MIST.scene_history.contains("caldarus_recovery");
                }
            )

            self.register_interaction(
                InputId.Interact,
                "misc_local/teleport",
                function() {
                    if ARI.get_essence() >= 10  {
                        var initial_outfit = NPCS[NpcId.Caldarus].wardrobe.outfit_name;
                        NPCS[NpcId.Caldarus].wardrobe.set_outfit("dragon_statue");
                        play_conversation_from_path(NpcId.Caldarus, GAMEPLAY_CONVERSATIONS[GpTriggeredConversation.CaldarusTeleport], function(driver, initial_outfit) {
                            if driver.prompt_index_selected == 0 {
                                TANGO.play("SoundEffects/Inventory/SpendEssence");
                                ARI.modify_essence(-10);
                                var point = trellis_point("caldarus_house/teleport_target");
                                ari_teleport_to_room(LocationId.CaldarusHouse, point.x, point.y);
                            }
                            NPCS[NpcId.Caldarus].wardrobe.set_outfit(initial_outfit);
                        }, [initial_outfit]);
                    } else {
                        play_conversation_from_path(NpcId.Caldarus, GAMEPLAY_CONVERSATIONS[GpTriggeredConversation.CaldarusTeleportFail]);
                    }
                },
                function() {
                    return npc_is_unlocked(NpcId.Caldarus)
                        && !TAXI.is_traveling()
                        && MIST.scene_history.contains("caldarus_recovery");
                }
            )

            depth = get_instance_depth(y);
            mask_index = spr_farm_dragonstatue_broken_spring;

            var fiddle_data = fiddle_get("interaction/dragon_shrine_offset");
            self.bounce_x_offset = fiddle_data[0];
            self.bounce_y_offset = fiddle_data[1];
            self.use_interact_bubble(spr_ui_bark_icon_essence, spr_ui_bark_icon_essence_small);

            self.interact_bubble_info = self.bubble_info;
            self.speech_bubble_info = clone_value(self.bubble_info);
            self.speech_bubble_info.bubble = spr_ui_dialogue_speech_bubble_big;
            self.speech_bubble_info.bubble_small = spr_ui_dialogue_speech_bubble_small;
            self.speech_bubble_info.has_icon = false;
            self.speech_bubble_info.y = self.bounce_y_offset + 6;
            self.speech_bubble_info.y_small = 0;

            function has_talk_interaction() {
                return requirements_pass(Requirement.SpeakToStatue)
                    && NPCS[NpcId.Caldarus].talk_flag
                    && !npc_is_unlocked(NpcId.Caldarus);
            }

            function bubble_should_update() {
                if menu_or_cutscene_pause() {
                    return;
                }

                var talking = self.has_talk_interaction();
                if talking == false && requirements_pass(Requirement.UseDragonShrine) == false {
                    return;
                }

                self.bubble_info = talking ? self.speech_bubble_info : self.interact_bubble_info;
                self.bouncer.status = InteractBounceStatus.Distant;
                self.bouncer.alpha = approach(self.bouncer.alpha, BARK_MIN_ALPHA, BARK_FADE_SPEED);
            }
        },
        step: function() {
            self.sprite_index = requirements_pass(Requirement.RepairedDragonShrine)
                ? spr_farm_dragonstatue_restored_spring
                : spr_farm_dragonstatue_broken_spring;
        },
    }
);