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
@@ -17,7 +17,6 @@
|
||||
],
|
||||
"currentLocationId": "",
|
||||
"globalFloats": {
|
||||
"player_hp": 200.0
|
||||
},
|
||||
"globalInts": {},
|
||||
"inventory": {
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
],
|
||||
"currentLocationId": "",
|
||||
"globalFloats": {
|
||||
"player_hp": 200.0
|
||||
},
|
||||
"globalInts": {},
|
||||
"inventory": {
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
],
|
||||
"currentLocationId": "",
|
||||
"globalFloats": {
|
||||
"player_hp": 200.0
|
||||
},
|
||||
"globalInts": {},
|
||||
"inventory": {
|
||||
|
||||
@@ -63,7 +63,7 @@ function on_bed_sleep()
|
||||
else
|
||||
game_api.start_cutscene("sleep_cutscene001")
|
||||
game_api.setIntValue("need_sleep", 0)
|
||||
game_api.set_player_hp(200)
|
||||
game_api.refill_current_player_hp()
|
||||
--game_api.set_day() - done in cutscene
|
||||
local day = game_api.getIntValue("day")
|
||||
game_api.setIntValue("day", day + 1)
|
||||
@@ -338,8 +338,6 @@ end
|
||||
|
||||
function callback_enter_location()
|
||||
print("Enter location dorm")
|
||||
local hp = game_api.getFloatValue("player_hp")
|
||||
game_api.set_player_hp(hp)
|
||||
game_api.set_teleport_active("tp_dorm_to_loc2", false)
|
||||
if (game_api.is_night()) then
|
||||
closeAlikDoor()
|
||||
@@ -348,8 +346,6 @@ end
|
||||
|
||||
function callback_exit_location()
|
||||
print("Exit location dorm")
|
||||
local hp = game_api.get_player_hp()
|
||||
game_api.setFloatValue("player_hp", hp)
|
||||
end
|
||||
|
||||
game_api.set_location_callbacks(
|
||||
|
||||
@@ -71,8 +71,6 @@ end
|
||||
|
||||
function callback_enter_location()
|
||||
print("Enter location uni exterior")
|
||||
local hp = game_api.getFloatValue("player_hp")
|
||||
game_api.set_player_hp(hp)
|
||||
game_api.set_teleport_active("tp_loc2_to_dorm", false)
|
||||
if (game_api.is_night()) then
|
||||
game_api.deactivate_interactive_object("car001")
|
||||
@@ -87,8 +85,6 @@ end
|
||||
|
||||
function callback_exit_location()
|
||||
print("Exit location uni exterior")
|
||||
local hp = game_api.get_player_hp()
|
||||
game_api.setFloatValue("player_hp", hp)
|
||||
end
|
||||
|
||||
game_api.set_location_callbacks(
|
||||
|
||||
@@ -275,7 +275,6 @@ function on_quest_over()
|
||||
end
|
||||
|
||||
function on_darklands_over()
|
||||
game_api.set_player_hp(10)
|
||||
game_api.resetPlayerAfterDeath()
|
||||
end
|
||||
|
||||
@@ -1346,9 +1345,6 @@ end
|
||||
|
||||
function callback_enter_location()
|
||||
print("Enter location uni interior-")
|
||||
--player_left_darklands = false
|
||||
local hp = game_api.getFloatValue("player_hp")
|
||||
game_api.set_player_hp(hp)
|
||||
local day = game_api.getIntValue("day")
|
||||
|
||||
print("day is:")
|
||||
@@ -1402,11 +1398,6 @@ end
|
||||
|
||||
function callback_exit_location()
|
||||
print("Exit location uni interior")
|
||||
--player_left_darklands = false
|
||||
local hp = game_api.get_player_hp()
|
||||
game_api.setFloatValue("player_hp", hp)
|
||||
|
||||
|
||||
--[[
|
||||
0 - day0
|
||||
1 - darklands
|
||||
|
||||
+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