Remove player health, use playermap
This commit is contained in:
1 parent
b932a07cba
commit
be8ee31f03
14 files changed
+27
-39
No files matched your search
+2
-2
@@ -52,7 +52,7 @@ void GameState::save(nlohmann::json& out) const
|
||||
out["isDawn"] = isDawn;
|
||||
|
||||
// --- Player resources ---
|
||||
out["playerHp"] = playerHp;
|
||||
//out["playerHp"] = playerHp;
|
||||
out["playerMaxHp"] = playerMaxHp;
|
||||
out["money"] = money;
|
||||
|
||||
@@ -137,7 +137,7 @@ void GameState::load(const nlohmann::json& in)
|
||||
|
||||
|
||||
// --- Player resources ---
|
||||
playerHp = in.value("playerHp", playerHp);
|
||||
//playerHp = in.value("playerHp", playerHp);
|
||||
playerMaxHp = in.value("playerMaxHp", playerMaxHp);
|
||||
money = in.value("money", money);
|
||||
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ struct GameState : public ISaveable {
|
||||
|
||||
// --- Player resources ---
|
||||
Inventory inventory;
|
||||
float playerHp = 200.f;
|
||||
//float playerHp = 200.f;
|
||||
float playerMaxHp = 200.f;
|
||||
int money = 5500;
|
||||
|
||||
|
||||
+14
-2
@@ -165,11 +165,23 @@ namespace FRG
|
||||
gameServer_.submit(
|
||||
TryCharacterAttackComboCommand{locationId_, character.entityId()});
|
||||
}
|
||||
|
||||
|
||||
void Location::setCharacterHp(Character& character, float hp)
|
||||
{
|
||||
gameServer_.submit(
|
||||
SetCharacterHealthCommand{locationId_, character.entityId(), hp});
|
||||
SetCharacterHealthCommand{ locationId_, character.entityId(), hp });
|
||||
auto state = character.stateSnapshot();
|
||||
if (character.onHpChanged && state)
|
||||
character.onHpChanged(
|
||||
state->hp,
|
||||
state->initialHp,
|
||||
std::string());
|
||||
}
|
||||
|
||||
void Location::refillCharacterHp(Character& character)
|
||||
{
|
||||
gameServer_.submit(
|
||||
SetCharacterHealthCommand{locationId_, character.entityId(), character.stateSnapshot()->initialHp});
|
||||
auto state = character.stateSnapshot();
|
||||
if (character.onHpChanged && state)
|
||||
character.onHpChanged(
|
||||
|
||||
@@ -183,6 +183,7 @@ namespace FRG
|
||||
void resetCharacterAfterDeath(Character& character);
|
||||
void tryCharacterAttackCombo(Character& character);
|
||||
void setCharacterHp(Character& character, float hp);
|
||||
void refillCharacterHp(Character& character);
|
||||
bool hasInventoryItem(const std::string& itemId) const;
|
||||
std::size_t inventoryItemCount() const;
|
||||
void addInventoryItem(std::string itemId);
|
||||
|
||||
+1
-1
@@ -2206,7 +2206,7 @@ namespace FRG {
|
||||
}
|
||||
|
||||
void MenuManager::updateHealthBar(float hp, float maxHp) {
|
||||
server_.submit(SetPlayerHealthCommand{hp, maxHp});
|
||||
//server_.submit(SetPlayerHealthCommand{hp, maxHp});
|
||||
applyCurrentHealthBar();
|
||||
}
|
||||
|
||||
|
||||
@@ -431,15 +431,15 @@ namespace FRG {
|
||||
return state ? state->position.z() : 0.0f;
|
||||
});
|
||||
|
||||
// set_player_hp(value) — sets the player's current HP directly.
|
||||
api.set_function("set_player_hp",
|
||||
[loc](float value) {
|
||||
api.set_function("refill_current_player_hp",
|
||||
[loc]() {
|
||||
if (loc->player)
|
||||
{
|
||||
loc->setCharacterHp(*loc->player, value);
|
||||
loc->refillCharacterHp(*loc->player);
|
||||
loc->resetCharacterAfterDeath(*loc->player);
|
||||
}
|
||||
});
|
||||
|
||||
// get_player_hp() → float (0 if no player)
|
||||
api.set_function("get_player_hp",
|
||||
[loc]() -> float {
|
||||
|
||||
@@ -69,7 +69,6 @@ struct GameSnapshot {
|
||||
|
||||
struct SetWorldModeCommand { bool darklands; bool night; bool dawn; };
|
||||
struct SetCurrentLocationCommand { std::string locationId; };
|
||||
struct SetPlayerHealthCommand { float hp; float maxHp; };
|
||||
struct SetMoneyCommand { int amount; };
|
||||
struct SpendMoneyCommand { int amount; };
|
||||
struct CompleteTutorialStepCommand { TutorialStep step; };
|
||||
@@ -230,7 +229,6 @@ struct ReloadQuestDefinitionsCommand { std::string path; std::string zipFile; };
|
||||
using GameCommand = std::variant<
|
||||
SetWorldModeCommand,
|
||||
SetCurrentLocationCommand,
|
||||
SetPlayerHealthCommand,
|
||||
SetMoneyCommand,
|
||||
SpendMoneyCommand,
|
||||
CompleteTutorialStepCommand,
|
||||
|
||||
@@ -101,7 +101,7 @@ void InternalGameServer::startCampaign(
|
||||
state_.locations.clear();
|
||||
state_.players.clear();
|
||||
state_.questJournal.loadFromFile(campaign.questsPath, zipFile);
|
||||
state_.globalFloats["player_hp"] = 200.f;
|
||||
//state_.globalFloats["player_hp"] = 200.f;
|
||||
|
||||
if (createLocalPlayer) {
|
||||
auto player = std::make_shared<CharacterState>();
|
||||
@@ -142,12 +142,12 @@ void InternalGameServer::resetCampaign(
|
||||
state_.isDarklands = false;
|
||||
state_.isNight = false;
|
||||
state_.isDawn = false;
|
||||
state_.playerHp = 200.f;
|
||||
//state_.playerHp = 200.f;
|
||||
state_.playerMaxHp = 200.f;
|
||||
state_.money = 5500;
|
||||
state_.globalInts.clear();
|
||||
state_.globalFloats.clear();
|
||||
state_.globalFloats["player_hp"] = 200.f;
|
||||
//state_.globalFloats["player_hp"] = 200.f;
|
||||
state_.tutorialStep = TutorialStep::AdvanceDialogue;
|
||||
state_.tutorialPhoneChatScreenOpened = false;
|
||||
state_.tutorialJournalScreenOpened = false;
|
||||
@@ -271,9 +271,6 @@ void InternalGameServer::submit(const GameCommand& command)
|
||||
state_.isDawn = value.dawn;
|
||||
} else if constexpr (std::is_same_v<T, SetCurrentLocationCommand>) {
|
||||
state_.currentLocationName = value.locationId;
|
||||
} else if constexpr (std::is_same_v<T, SetPlayerHealthCommand>) {
|
||||
state_.playerHp = value.hp;
|
||||
state_.playerMaxHp = value.maxHp;
|
||||
} else if constexpr (std::is_same_v<T, SetMoneyCommand>) {
|
||||
state_.money = value.amount;
|
||||
} else if constexpr (std::is_same_v<T, SpendMoneyCommand>) {
|
||||
|
||||
Reference in new issue
Block a user