Remove player health, use playermap
This commit is contained in:
1 parent
b932a07cba
commit
be8ee31f03
14 files changed
+25
-37
No files matched your search
@@ -17,7 +17,6 @@
|
|||||||
],
|
],
|
||||||
"currentLocationId": "",
|
"currentLocationId": "",
|
||||||
"globalFloats": {
|
"globalFloats": {
|
||||||
"player_hp": 200.0
|
|
||||||
},
|
},
|
||||||
"globalInts": {},
|
"globalInts": {},
|
||||||
"inventory": {
|
"inventory": {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
],
|
],
|
||||||
"currentLocationId": "",
|
"currentLocationId": "",
|
||||||
"globalFloats": {
|
"globalFloats": {
|
||||||
"player_hp": 200.0
|
|
||||||
},
|
},
|
||||||
"globalInts": {},
|
"globalInts": {},
|
||||||
"inventory": {
|
"inventory": {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
],
|
],
|
||||||
"currentLocationId": "",
|
"currentLocationId": "",
|
||||||
"globalFloats": {
|
"globalFloats": {
|
||||||
"player_hp": 200.0
|
|
||||||
},
|
},
|
||||||
"globalInts": {},
|
"globalInts": {},
|
||||||
"inventory": {
|
"inventory": {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ function on_bed_sleep()
|
|||||||
else
|
else
|
||||||
game_api.start_cutscene("sleep_cutscene001")
|
game_api.start_cutscene("sleep_cutscene001")
|
||||||
game_api.setIntValue("need_sleep", 0)
|
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
|
--game_api.set_day() - done in cutscene
|
||||||
local day = game_api.getIntValue("day")
|
local day = game_api.getIntValue("day")
|
||||||
game_api.setIntValue("day", day + 1)
|
game_api.setIntValue("day", day + 1)
|
||||||
@@ -338,8 +338,6 @@ end
|
|||||||
|
|
||||||
function callback_enter_location()
|
function callback_enter_location()
|
||||||
print("Enter location dorm")
|
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)
|
game_api.set_teleport_active("tp_dorm_to_loc2", false)
|
||||||
if (game_api.is_night()) then
|
if (game_api.is_night()) then
|
||||||
closeAlikDoor()
|
closeAlikDoor()
|
||||||
@@ -348,8 +346,6 @@ end
|
|||||||
|
|
||||||
function callback_exit_location()
|
function callback_exit_location()
|
||||||
print("Exit location dorm")
|
print("Exit location dorm")
|
||||||
local hp = game_api.get_player_hp()
|
|
||||||
game_api.setFloatValue("player_hp", hp)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
game_api.set_location_callbacks(
|
game_api.set_location_callbacks(
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ end
|
|||||||
|
|
||||||
function callback_enter_location()
|
function callback_enter_location()
|
||||||
print("Enter location uni exterior")
|
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)
|
game_api.set_teleport_active("tp_loc2_to_dorm", false)
|
||||||
if (game_api.is_night()) then
|
if (game_api.is_night()) then
|
||||||
game_api.deactivate_interactive_object("car001")
|
game_api.deactivate_interactive_object("car001")
|
||||||
@@ -87,8 +85,6 @@ end
|
|||||||
|
|
||||||
function callback_exit_location()
|
function callback_exit_location()
|
||||||
print("Exit location uni exterior")
|
print("Exit location uni exterior")
|
||||||
local hp = game_api.get_player_hp()
|
|
||||||
game_api.setFloatValue("player_hp", hp)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
game_api.set_location_callbacks(
|
game_api.set_location_callbacks(
|
||||||
|
|||||||
@@ -275,7 +275,6 @@ function on_quest_over()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function on_darklands_over()
|
function on_darklands_over()
|
||||||
game_api.set_player_hp(10)
|
|
||||||
game_api.resetPlayerAfterDeath()
|
game_api.resetPlayerAfterDeath()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1346,9 +1345,6 @@ end
|
|||||||
|
|
||||||
function callback_enter_location()
|
function callback_enter_location()
|
||||||
print("Enter location uni interior-")
|
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")
|
local day = game_api.getIntValue("day")
|
||||||
|
|
||||||
print("day is:")
|
print("day is:")
|
||||||
@@ -1402,11 +1398,6 @@ end
|
|||||||
|
|
||||||
function callback_exit_location()
|
function callback_exit_location()
|
||||||
print("Exit location uni interior")
|
print("Exit location uni interior")
|
||||||
--player_left_darklands = false
|
|
||||||
local hp = game_api.get_player_hp()
|
|
||||||
game_api.setFloatValue("player_hp", hp)
|
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
0 - day0
|
0 - day0
|
||||||
1 - darklands
|
1 - darklands
|
||||||
|
|||||||
+2
-2
@@ -52,7 +52,7 @@ void GameState::save(nlohmann::json& out) const
|
|||||||
out["isDawn"] = isDawn;
|
out["isDawn"] = isDawn;
|
||||||
|
|
||||||
// --- Player resources ---
|
// --- Player resources ---
|
||||||
out["playerHp"] = playerHp;
|
//out["playerHp"] = playerHp;
|
||||||
out["playerMaxHp"] = playerMaxHp;
|
out["playerMaxHp"] = playerMaxHp;
|
||||||
out["money"] = money;
|
out["money"] = money;
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ void GameState::load(const nlohmann::json& in)
|
|||||||
|
|
||||||
|
|
||||||
// --- Player resources ---
|
// --- Player resources ---
|
||||||
playerHp = in.value("playerHp", playerHp);
|
//playerHp = in.value("playerHp", playerHp);
|
||||||
playerMaxHp = in.value("playerMaxHp", playerMaxHp);
|
playerMaxHp = in.value("playerMaxHp", playerMaxHp);
|
||||||
money = in.value("money", money);
|
money = in.value("money", money);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ struct GameState : public ISaveable {
|
|||||||
|
|
||||||
// --- Player resources ---
|
// --- Player resources ---
|
||||||
Inventory inventory;
|
Inventory inventory;
|
||||||
float playerHp = 200.f;
|
//float playerHp = 200.f;
|
||||||
float playerMaxHp = 200.f;
|
float playerMaxHp = 200.f;
|
||||||
int money = 5500;
|
int money = 5500;
|
||||||
|
|
||||||
|
|||||||
@@ -178,6 +178,18 @@ namespace FRG
|
|||||||
std::string());
|
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(
|
||||||
|
state->hp,
|
||||||
|
state->initialHp,
|
||||||
|
std::string());
|
||||||
|
}
|
||||||
|
|
||||||
bool Location::hasInventoryItem(const std::string& itemId) const
|
bool Location::hasInventoryItem(const std::string& itemId) const
|
||||||
{
|
{
|
||||||
auto snapshot = gameServer_.snapshot();
|
auto snapshot = gameServer_.snapshot();
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ namespace FRG
|
|||||||
void resetCharacterAfterDeath(Character& character);
|
void resetCharacterAfterDeath(Character& character);
|
||||||
void tryCharacterAttackCombo(Character& character);
|
void tryCharacterAttackCombo(Character& character);
|
||||||
void setCharacterHp(Character& character, float hp);
|
void setCharacterHp(Character& character, float hp);
|
||||||
|
void refillCharacterHp(Character& character);
|
||||||
bool hasInventoryItem(const std::string& itemId) const;
|
bool hasInventoryItem(const std::string& itemId) const;
|
||||||
std::size_t inventoryItemCount() const;
|
std::size_t inventoryItemCount() const;
|
||||||
void addInventoryItem(std::string itemId);
|
void addInventoryItem(std::string itemId);
|
||||||
|
|||||||
+1
-1
@@ -2206,7 +2206,7 @@ namespace FRG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MenuManager::updateHealthBar(float hp, float maxHp) {
|
void MenuManager::updateHealthBar(float hp, float maxHp) {
|
||||||
server_.submit(SetPlayerHealthCommand{hp, maxHp});
|
//server_.submit(SetPlayerHealthCommand{hp, maxHp});
|
||||||
applyCurrentHealthBar();
|
applyCurrentHealthBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -431,15 +431,15 @@ namespace FRG {
|
|||||||
return state ? state->position.z() : 0.0f;
|
return state ? state->position.z() : 0.0f;
|
||||||
});
|
});
|
||||||
|
|
||||||
// set_player_hp(value) — sets the player's current HP directly.
|
api.set_function("refill_current_player_hp",
|
||||||
api.set_function("set_player_hp",
|
[loc]() {
|
||||||
[loc](float value) {
|
|
||||||
if (loc->player)
|
if (loc->player)
|
||||||
{
|
{
|
||||||
loc->setCharacterHp(*loc->player, value);
|
loc->refillCharacterHp(*loc->player);
|
||||||
loc->resetCharacterAfterDeath(*loc->player);
|
loc->resetCharacterAfterDeath(*loc->player);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// get_player_hp() → float (0 if no player)
|
// get_player_hp() → float (0 if no player)
|
||||||
api.set_function("get_player_hp",
|
api.set_function("get_player_hp",
|
||||||
[loc]() -> float {
|
[loc]() -> float {
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ struct GameSnapshot {
|
|||||||
|
|
||||||
struct SetWorldModeCommand { bool darklands; bool night; bool dawn; };
|
struct SetWorldModeCommand { bool darklands; bool night; bool dawn; };
|
||||||
struct SetCurrentLocationCommand { std::string locationId; };
|
struct SetCurrentLocationCommand { std::string locationId; };
|
||||||
struct SetPlayerHealthCommand { float hp; float maxHp; };
|
|
||||||
struct SetMoneyCommand { int amount; };
|
struct SetMoneyCommand { int amount; };
|
||||||
struct SpendMoneyCommand { int amount; };
|
struct SpendMoneyCommand { int amount; };
|
||||||
struct CompleteTutorialStepCommand { TutorialStep step; };
|
struct CompleteTutorialStepCommand { TutorialStep step; };
|
||||||
@@ -230,7 +229,6 @@ struct ReloadQuestDefinitionsCommand { std::string path; std::string zipFile; };
|
|||||||
using GameCommand = std::variant<
|
using GameCommand = std::variant<
|
||||||
SetWorldModeCommand,
|
SetWorldModeCommand,
|
||||||
SetCurrentLocationCommand,
|
SetCurrentLocationCommand,
|
||||||
SetPlayerHealthCommand,
|
|
||||||
SetMoneyCommand,
|
SetMoneyCommand,
|
||||||
SpendMoneyCommand,
|
SpendMoneyCommand,
|
||||||
CompleteTutorialStepCommand,
|
CompleteTutorialStepCommand,
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void InternalGameServer::startCampaign(
|
|||||||
state_.locations.clear();
|
state_.locations.clear();
|
||||||
state_.players.clear();
|
state_.players.clear();
|
||||||
state_.questJournal.loadFromFile(campaign.questsPath, zipFile);
|
state_.questJournal.loadFromFile(campaign.questsPath, zipFile);
|
||||||
state_.globalFloats["player_hp"] = 200.f;
|
//state_.globalFloats["player_hp"] = 200.f;
|
||||||
|
|
||||||
if (createLocalPlayer) {
|
if (createLocalPlayer) {
|
||||||
auto player = std::make_shared<CharacterState>();
|
auto player = std::make_shared<CharacterState>();
|
||||||
@@ -142,12 +142,12 @@ void InternalGameServer::resetCampaign(
|
|||||||
state_.isDarklands = false;
|
state_.isDarklands = false;
|
||||||
state_.isNight = false;
|
state_.isNight = false;
|
||||||
state_.isDawn = false;
|
state_.isDawn = false;
|
||||||
state_.playerHp = 200.f;
|
//state_.playerHp = 200.f;
|
||||||
state_.playerMaxHp = 200.f;
|
state_.playerMaxHp = 200.f;
|
||||||
state_.money = 5500;
|
state_.money = 5500;
|
||||||
state_.globalInts.clear();
|
state_.globalInts.clear();
|
||||||
state_.globalFloats.clear();
|
state_.globalFloats.clear();
|
||||||
state_.globalFloats["player_hp"] = 200.f;
|
//state_.globalFloats["player_hp"] = 200.f;
|
||||||
state_.tutorialStep = TutorialStep::AdvanceDialogue;
|
state_.tutorialStep = TutorialStep::AdvanceDialogue;
|
||||||
state_.tutorialPhoneChatScreenOpened = false;
|
state_.tutorialPhoneChatScreenOpened = false;
|
||||||
state_.tutorialJournalScreenOpened = false;
|
state_.tutorialJournalScreenOpened = false;
|
||||||
@@ -271,9 +271,6 @@ void InternalGameServer::submit(const GameCommand& command)
|
|||||||
state_.isDawn = value.dawn;
|
state_.isDawn = value.dawn;
|
||||||
} else if constexpr (std::is_same_v<T, SetCurrentLocationCommand>) {
|
} else if constexpr (std::is_same_v<T, SetCurrentLocationCommand>) {
|
||||||
state_.currentLocationName = value.locationId;
|
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>) {
|
} else if constexpr (std::is_same_v<T, SetMoneyCommand>) {
|
||||||
state_.money = value.amount;
|
state_.money = value.amount;
|
||||||
} else if constexpr (std::is_same_v<T, SpendMoneyCommand>) {
|
} else if constexpr (std::is_same_v<T, SpendMoneyCommand>) {
|
||||||
|
|||||||
Reference in new issue
Block a user