Skip to content

Commit

Permalink
Issue #66 Implement pit interactable (#201)
Browse files Browse the repository at this point in the history
Implements the dialog part, the actual pit navigation will be done later
when I have implemented collision detection/movement.
  • Loading branch information
xavieran authored Jul 22, 2024
1 parent 0b1df69 commit dbadee9
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bak/dialogSources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class DialogSources
static constexpr auto mTrappedAnimal = KeyTarget{0xab};
static constexpr auto mWell = KeyTarget{0xbc};
static constexpr auto mDoorTooClose = KeyTarget{0x9d};
static constexpr auto mPitHaveRope = KeyTarget{0xc5};
static constexpr auto mPitNoRope = KeyTarget{0xc6};

static constexpr auto mCharacterIsNotASpellcaster = KeyTarget{0xd8};

Expand Down
1 change: 1 addition & 0 deletions bak/itemNumbers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static constexpr auto sStandardArmor = BAK::ItemIndex{48};

static constexpr auto sSovereigns = BAK::ItemIndex{53};
static constexpr auto sRoyals = BAK::ItemIndex{54};
static constexpr auto sRope = BAK::ItemIndex{82};
static constexpr auto sShovel = BAK::ItemIndex{83};
static constexpr auto sScroll = BAK::ItemIndex{133};
static constexpr auto sDayRations = BAK::ItemIndex{134};
Expand Down
6 changes: 5 additions & 1 deletion game/interactable/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include "game/interactable/door.hpp"
#include "game/interactable/generic.hpp"
#include "game/interactable/ladder.hpp"
#include "game/interactable/pit.hpp"
#include "game/interactable/tomb.hpp"

#include "gui/IGuiManager.hpp"

#include "bak/gameState.hpp"
#include "bak/worldFactory.hpp"

#include <memory>

Expand Down Expand Up @@ -114,6 +114,10 @@ class InteractableFactory
return std::make_unique<Door>(
mGuiManager,
mGameState);
case InteractableType::Pit:
return std::make_unique<Pit>(
mGuiManager,
mGameState);
case InteractableType::Corn:
return MakeGeneric(BAK::DialogSources::mCorn);
case InteractableType::CrystalTree:
Expand Down
81 changes: 81 additions & 0 deletions game/interactable/pit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#pragma once

#include "game/interactable/IInteractable.hpp"

#include "bak/IContainer.hpp"
#include "bak/container.hpp"
#include "bak/dialog.hpp"
#include "bak/dialogSources.hpp"
#include "bak/entityType.hpp"
#include "bak/dialog.hpp"
#include "bak/gameState.hpp"
#include "bak/itemNumbers.hpp"

#include "gui/IDialogScene.hpp"
#include "gui/IGuiManager.hpp"

namespace Game::Interactable {

class Pit : public IInteractable
{
public:
Pit(
Gui::IGuiManager& guiManager,
BAK::GameState& gameState)
:
mGuiManager{guiManager},
mGameState{gameState},
mDialogScene{
[]{},
[]{},
[&](const auto& choice){ DialogFinished(choice); }},
mCurrentPit{nullptr}
{}

void BeginInteraction(BAK::GenericContainer& pit, BAK::EntityType) override
{
mCurrentPit = &pit;
if (mGameState.GetParty().HaveItem(BAK::sRope))
{
StartDialog(BAK::DialogSources::mPitHaveRope);
}
else
{
StartDialog(BAK::DialogSources::mPitNoRope);
}
}

void DialogFinished(const std::optional<BAK::ChoiceIndex>& choice)
{
ASSERT(mCurrentPit);
if (choice && choice->mValue == BAK::Keywords::sYesIndex)
{
Logging::LogDebug(__FUNCTION__) << "Swing across pit...\n";
}
else
{
Logging::LogDebug(__FUNCTION__) << "Not crossing pit\n";
}
}

void StartDialog(BAK::Target target)
{
mGuiManager.StartDialog(
target,
false,
false,
&mDialogScene);
}

void EncounterFinished() override
{
}

private:
Gui::IGuiManager& mGuiManager;
BAK::GameState& mGameState;
Gui::DynamicDialogScene mDialogScene;
BAK::GenericContainer* mCurrentPit;
};

}
2 changes: 1 addition & 1 deletion shaders/shaders.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "shaders/shaders.hpp"

#include <array>
#include <functional>
#include <algorithm>

namespace Shaders {

Expand Down

0 comments on commit dbadee9

Please sign in to comment.