mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
Fixed crashes related to hardcore mode
This commit is contained in:
@@ -666,46 +666,46 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
|
||||
return;
|
||||
}
|
||||
Smash(source, eKillType::VIOLENT, u"", skillID);
|
||||
|
||||
//check if hardcore mode is enabled
|
||||
if (Game::config->GetValue("hardcore_mode") == "1") {
|
||||
//check if this is a player:
|
||||
if (m_Parent->GetLOT() == 1) {
|
||||
//get hardcore_lose_uscore_on_death_percent from dconfig:
|
||||
auto hardcore_lose_uscore_on_death_percent = std::stoi(Game::config->GetValue("hardcore_lose_uscore_on_death_percent"));
|
||||
auto hardcoreLoseUscoreOnDeathPercent = std::stoi(Game::config->GetValue("hardcore_lose_uscore_on_death_percent"));
|
||||
|
||||
//remove hardcore_lose_uscore_on_death_percent from the player's uscore:
|
||||
auto* character = m_Parent->GetComponent<CharacterComponent>();
|
||||
auto uscore = character->GetUScore();
|
||||
|
||||
auto uscore_to_lose = uscore * hardcore_lose_uscore_on_death_percent / 100;
|
||||
character->SetUScore(uscore - uscore_to_lose);
|
||||
auto uscoreToLose = uscore * hardcoreLoseUscoreOnDeathPercent / 100;
|
||||
character->SetUScore(uscore - uscoreToLose);
|
||||
|
||||
//get hardcore_dropinventory on death from dconfig:
|
||||
auto hardcore_dropinventory_on_death = (bool)std::stoi(Game::config->GetValue("hardcore_dropinventory_on_death"));
|
||||
GameMessages::SendModifyLEGOScore(m_Parent, m_Parent->GetSystemAddress(), -uscoreToLose, eLootSourceType::LOOT_SOURCE_MISSION);
|
||||
|
||||
if (hardcore_dropinventory_on_death == false) return;
|
||||
// Reload the player
|
||||
EntityManager::Instance()->DestructEntity(m_Parent);
|
||||
EntityManager::Instance()->ConstructEntity(m_Parent);
|
||||
|
||||
auto hardcoreDropinventoryOnDeath = (bool)std::stoi(Game::config->GetValue("hardcore_dropinventory_on_death"));
|
||||
|
||||
if (hardcoreDropinventoryOnDeath == false) return;
|
||||
|
||||
//drop all items from inventory:
|
||||
auto* inventory = m_Parent->GetComponent<InventoryComponent>();
|
||||
|
||||
//get the items inventory:
|
||||
auto items = inventory->GetInventory(eInventoryType::ITEMS);
|
||||
for (auto item : items->GetItems()) {
|
||||
//check if this is an equipped item:
|
||||
if (item.second->IsEquipped()) {
|
||||
//unequip the item:
|
||||
inventory->UnEquipItem(item.second);
|
||||
}
|
||||
|
||||
auto itemMap = items->GetItems();
|
||||
for (const auto& item : itemMap) {
|
||||
//drop the item:
|
||||
GameMessages::SendDropClientLoot(m_Parent, source, item.second->GetLot(), 0, m_Parent->GetPosition(), item.second->GetCount());
|
||||
|
||||
//remove from inventory:
|
||||
inventory->RemoveItem(item.second->GetLot(), item.second->GetCount());
|
||||
item.second->SetCount(0, false, false);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
|
||||
//get character:
|
||||
auto* chars = m_Parent->GetCharacter();
|
||||
if (chars) {
|
||||
@@ -727,15 +727,19 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
auto maxHealth = GetMaxHealth();
|
||||
|
||||
//get the u-score to award from dconfig:
|
||||
auto hardcore_uscore_enemies_multiplier = std::stoi(Game::config->GetValue("hardcore_uscore_enemies_multiplier"));
|
||||
int uscore = maxHealth * hardcore_uscore_enemies_multiplier;
|
||||
auto hardcoreUscoreEnemiesMultiplier = std::stoi(Game::config->GetValue("hardcore_uscore_enemies_multiplier"));
|
||||
int uscore = maxHealth * hardcoreUscoreEnemiesMultiplier;
|
||||
|
||||
playerStats->SetUScore(playerStats->GetUScore() + uscore);
|
||||
GameMessages::SendModifyLEGOScore(player, player->GetSystemAddress(), uscore, eLootSourceType::LOOT_SOURCE_NONE);
|
||||
GameMessages::SendModifyLEGOScore(player, player->GetSystemAddress(), uscore, eLootSourceType::LOOT_SOURCE_MISSION);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Smash(source, eKillType::VIOLENT, u"", skillID);
|
||||
}
|
||||
|
||||
void DestroyableComponent::Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd) {
|
||||
|
Reference in New Issue
Block a user