Skip to content

Commit

Permalink
Added marriage description into char inspection.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed May 27, 2024
1 parent 628eca8 commit be5dfc8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 42 deletions.
9 changes: 9 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,8 @@ class Player final : public Creature, public Cylinder, public Bankable {
int32_t magicShieldCapacityFlat = 0;
int32_t magicShieldCapacityPercent = 0;

int32_t marriageSpouse = -1;

void updateItemsLight(bool internal = false);
uint16_t getStepSpeed() const override {
return std::max<uint16_t>(PLAYER_MIN_SPEED, std::min<uint16_t>(PLAYER_MAX_SPEED, getSpeed()));
Expand Down Expand Up @@ -3058,4 +3060,11 @@ class Player final : public Creature, public Cylinder, public Bankable {
bool hasOtherRewardContainerOpen(const std::shared_ptr<Container> container) const;

void checkAndShowBlessingMessage();

void setMarriageSpouse(const int32_t spouseId) {
marriageSpouse = spouseId;
}
int32_t getMarriageSpouse() const {
return marriageSpouse;
}
};
2 changes: 2 additions & 0 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr<Player> player, DBResult_p

player->setManaShield(result->getNumber<uint32_t>("manashield"));
player->setMaxManaShield(result->getNumber<uint32_t>("max_manashield"));

player->setMarriageSpouse(result->getNumber<int32_t>("marriage_spouse"));
return true;
}

Expand Down
91 changes: 49 additions & 42 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3457,7 +3457,7 @@ void ProtocolGame::sendCyclopediaCharacterGeneralStats() {
msg.add<uint16_t>(player->getOfflineTrainingTime() / 60 / 1000);
msg.add<uint16_t>(player->getSpeed());
msg.add<uint16_t>(player->getBaseSpeed());
msg.add<uint32_t>(player->getBonusCapacity());
msg.add<uint32_t>(player->getCapacity());
msg.add<uint32_t>(player->getBaseCapacity());
msg.add<uint32_t>(player->hasFlag(PlayerFlags_t::HasInfiniteCapacity) ? 1000000 : player->getFreeCapacity());
msg.addByte(8);
Expand Down Expand Up @@ -4072,63 +4072,70 @@ void ProtocolGame::sendCyclopediaCharacterInspection() {
auto playerDescriptionPosition = msg.getBufferPosition();
msg.skipBytes(1);

// Player title
if (player->title()->getCurrentTitle() != 0) {
playerDescriptionSize++;
msg.addString("Character Title", "ProtocolGame::sendCyclopediaCharacterInspection - Title");
msg.addString(player->title()->getCurrentTitleName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->title()->getCurrentTitleName()");
}

// Level description
playerDescriptionSize++;
msg.addString("Level", "ProtocolGame::sendCyclopediaCharacterInspection - Level");
msg.addString(std::to_string(player->getLevel()), "ProtocolGame::sendCyclopediaCharacterInspection - std::to_string(player->getLevel())");

// Vocation description
playerDescriptionSize++;
msg.addString(std::to_string(player->getLevel()), "ProtocolGame::sendCyclopediaCharacterInspection - std::to_string(player->getLevel())");
msg.addString("Vocation", "ProtocolGame::sendCyclopediaCharacterInspection - Vocation");
msg.addString(player->getVocation()->getVocName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->getVocation()->getVocName()");

// Player title
if (player->title()->getCurrentTitle() != 0) {
playerDescriptionSize++;
msg.addString("Title", "ProtocolGame::sendCyclopediaCharacterInspection - Title");
msg.addString(player->title()->getCurrentTitleName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->title()->getCurrentTitleName()");
}

// Loyalty title
if (!player->getLoyaltyTitle().empty()) {
playerDescriptionSize++;
msg.addString("Loyalty Title", "ProtocolGame::sendCyclopediaCharacterInspection - Loyalty Title");
msg.addString(player->getLoyaltyTitle(), "ProtocolGame::sendCyclopediaCharacterInspection - player->getLoyaltyTitle()");
}

// todo: Prey description
// for (uint8_t slotId = PreySlot_First; slotId <= PreySlot_Last; slotId++) {
// PreySlot* slot = player->getPreySlotById(static_cast<PreySlot_t>(slotId));
// if (slot && slot->isOccupied()) {
// playerDescriptionSize++;
// std::ostringstream ss;
// ss << "Active Prey " << (slotId + 1);
// msg.addString(ss.str(), "ProtocolGame::sendCyclopediaCharacterInspection - active prey");
// ss.str("");
// ss.clear();
//
// if (auto mtype = g_monsters().getMonsterTypeByRaceId(slot->selectedRaceId)) {
// ss << mtype->name;
// } else {
// ss << "Unknown creature";
// }
//
// if (slot->bonus == PreyBonus_Damage) {
// ss << " (Improved Damage +";
// } else if (slot->bonus == PreyBonus_Defense) {
// ss << " (Improved Defense +";
// } else if (slot->bonus == PreyBonus_Experience) {
// ss << " (Improved Experience +";
// } else if (slot->bonus == PreyBonus_Loot) {
// ss << " (Improved Loot +";
// }
// ss << slot->bonusPercentage << "%, remaining ";
// uint8_t hours = slot->bonusTimeLeft / 3600;
// uint8_t minutes = (slot->bonusTimeLeft - (hours * 3600)) / 60;
// ss << std::to_string(hours) << ":" << (minutes < 10 ? "0" : "") << std::to_string(minutes) << "h)";
// msg.addString(ss.str(), "ProtocolGame::sendCyclopediaCharacterInspection - prey description");
// }
// }
// Marriage description
if (const auto spouseId = player->getMarriageSpouse(); spouseId > 0) {
if (const auto &spouse = g_game().getPlayerByID(spouseId, true); spouse) {
playerDescriptionSize++;
msg.addString("Married to", "ProtocolGame::sendCyclopediaCharacterInspection - Married to");
msg.addString(spouse->getName(), "ProtocolGame::sendCyclopediaCharacterInspection - spouse->getName()");
}
}

// Prey description
for (uint8_t slotId = PreySlot_First; slotId <= PreySlot_Last; slotId++) {
if (const auto &slot = player->getPreySlotById(static_cast<PreySlot_t>(slotId));
slot && slot->isOccupied()) {
playerDescriptionSize++;
std::string desc = fmt::format("Active Prey {}", slotId + 1);
msg.addString(desc, "ProtocolGame::sendCyclopediaCharacterInspection - active prey");

std::ostringstream ss;
if (auto mtype = g_monsters().getMonsterTypeByRaceId(slot->selectedRaceId)) {
ss << mtype->name;
} else {
ss << "Unknown creature";
}

if (slot->bonus == PreyBonus_Damage) {
ss << " (Improved Damage +";
} else if (slot->bonus == PreyBonus_Defense) {
ss << " (Improved Defense +";
} else if (slot->bonus == PreyBonus_Experience) {
ss << " (Improved Experience +";
} else if (slot->bonus == PreyBonus_Loot) {
ss << " (Improved Loot +";
}
ss << slot->bonusPercentage << "%, remaining ";
uint8_t hours = slot->bonusTimeLeft / 3600;
uint8_t minutes = (slot->bonusTimeLeft - (hours * 3600)) / 60;
ss << std::to_string(hours) << ":" << (minutes < 10 ? "0" : "") << std::to_string(minutes) << "h)";
msg.addString(ss.str(), "ProtocolGame::sendCyclopediaCharacterInspection - prey description");
}
}

// Outfit description
playerDescriptionSize++;
Expand Down

0 comments on commit be5dfc8

Please sign in to comment.