// Oleg Petruny proprietary.


#include "FishingManager.h"

#include "EnhancedInputComponent.h"
#include "InputMappingContext.h"

#include "MainGameModeBase.h"
#include "PlayerBase.h"

AFishingManager::AFishingManager()
{
    static ConstructorHelpers::FObjectFinder<UInputMappingContext> asset{ TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/Minigame/IMC_Minigame_Fishing.IMC_Minigame_Fishing'") };
    input = asset.Object;
}

void AFishingManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate)
{
    if(!playerPawn)
        return;

    AMinigame::Start(playerPawn, delegate);

    player->LockPlayer(FPlayerLock::All());

    auto& mapping = input.LoadSynchronous()->GetMapping(0);
    handler1 = player->inputComponent->BindAction(mapping.Action, ETriggerEvent::Started, this, &AFishingManager::OnInputHold).GetHandle();
    handler2 = player->inputComponent->BindAction(mapping.Action, ETriggerEvent::Completed, this, &AFishingManager::OnInputUnhold).GetHandle();
}

void AFishingManager::End()
{
    player->inputComponent->RemoveBindingByHandle(handler1);
    player->inputComponent->RemoveBindingByHandle(handler2);

    player->UnlockPlayer(FPlayerLock::All());

    AMinigame::End();
}
