Merge branch 'DarkflameUniverse:main' into property-fixes

This commit is contained in:
David Markowitz
2022-03-30 18:38:07 -07:00
committed by GitHub
21 changed files with 416 additions and 230 deletions

View File

@@ -6,6 +6,7 @@
#include "Database.h"
#include "Game.h"
#include "dLogger.h"
#include "User.h"
#include <WorldPackets.h>
#include "Character.h"
@@ -68,16 +69,6 @@ void UserManager::Initialize() {
StripCR(line);
m_PreapprovedNames.push_back(line);
}
//Load custom ones from MySQL too:
/*sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT name FROM approvedNames;");
sql::ResultSet* res = stmt->executeQuery();
while (res->next()) {
m_PreapprovedNames.push_back(res->getString(1));
}
delete res;
delete stmt;*/
}
UserManager::~UserManager() {
@@ -566,122 +557,38 @@ void UserManager::LoginCharacter(const SystemAddress& sysAddr, uint32_t playerID
}
}
uint32_t GetShirtColorId(uint32_t color) {
// get the index of the color in shirtColorVector
auto colorId = std::find(shirtColorVector.begin(), shirtColorVector.end(), color);
return color = std::distance(shirtColorVector.begin(), colorId);
}
uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
shirtStyle--; // to start at 0 instead of 1
uint32_t stylesCount = 34;
uint32_t colorId = GetShirtColorId(shirtColor);
uint32_t startID = 4049; // item ID of the shirt with color 0 (red) and style 0 (plain)
// For some reason, if the shirt style is 34 - 39,
// The ID is different than the original... Was this because
// these shirts were added later?
if (shirtStyle >= 34) {
startID = 5730; // item ID of the shirt with color 0 (red) and style 34 (butterflies)
shirtStyle -= stylesCount; //change style from range 35-40 to range 0-5
stylesCount = 6;
try {
std::string shirtQuery = "select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == \"character create shirt\" AND icc.color1 == ";
shirtQuery += std::to_string(shirtColor);
shirtQuery += " AND icc.decal == ";
shirtQuery = shirtQuery + std::to_string(shirtStyle);
auto tableData = CDClientDatabase::ExecuteQuery(shirtQuery);
auto shirtLOT = tableData.getIntField(0, -1);
tableData.finalize();
return shirtLOT;
}
catch (const std::exception&){
Game::logger->Log("Character Create", "Failed to execute query! Using backup...");
// in case of no shirt found in CDServer, return problematic red vest.
return 4069;
}
// Get the final ID of the shirt
uint32_t shirtID = startID + (colorId * stylesCount) + shirtStyle;
return shirtID;
}
uint32_t FindCharPantsID(uint32_t pantsColor) {
uint32_t pantsID = 2508;
switch (pantsColor) {
case 0: {
pantsID = PANTS_BRIGHT_RED;
break;
try {
std::string pantsQuery = "select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == \"cc pants\" AND icc.color1 == ";
pantsQuery += std::to_string(pantsColor);
auto tableData = CDClientDatabase::ExecuteQuery(pantsQuery);
auto pantsLOT = tableData.getIntField(0, -1);
tableData.finalize();
return pantsLOT;
}
case 1: {
pantsID = PANTS_BRIGHT_BLUE;
break;
catch (const std::exception&){
Game::logger->Log("Character Create", "Failed to execute query! Using backup...");
// in case of no pants color found in CDServer, return red pants.
return 2508;
}
case 3: {
pantsID = PANTS_DARK_GREEN;
break;
}
case 5: {
pantsID = PANTS_BRIGHT_ORANGE;
break;
}
case 6: {
pantsID = PANTS_BLACK;
break;
}
case 7: {
pantsID = PANTS_DARK_STONE_GRAY;
break;
}
case 8: {
pantsID = PANTS_MEDIUM_STONE_GRAY;
break;
}
case 9: {
pantsID = PANTS_REDDISH_BROWN;
break;
}
case 10: {
pantsID = PANTS_WHITE;
break;
}
case 11: {
pantsID = PANTS_MEDIUM_BLUE;
break;
}
case 13: {
pantsID = PANTS_DARK_RED;
break;
}
case 14: {
pantsID = PANTS_EARTH_BLUE;
break;
}
case 15: {
pantsID = PANTS_EARTH_GREEN;
break;
}
case 16: {
pantsID = PANTS_BRICK_YELLOW;
break;
}
case 84: {
pantsID = PANTS_SAND_BLUE;
break;
}
case 96: {
pantsID = PANTS_SAND_GREEN;
break;
}
}
return pantsID;
}
void UserManager::SaveAllActiveCharacters() {

View File

@@ -44,7 +44,6 @@ public:
private:
static UserManager* m_Address; //Singleton
//std::vector<User*> m_Users;
std::map<SystemAddress, User*> m_Users;
std::vector<User*> m_UsersToDelete;
@@ -54,43 +53,4 @@ private:
std::vector<std::string> m_PreapprovedNames;
};
enum CharCreatePantsColor : uint32_t {
PANTS_BRIGHT_RED = 2508,
PANTS_BRIGHT_ORANGE = 2509,
PANTS_BRICK_YELLOW = 2511,
PANTS_MEDIUM_BLUE = 2513,
PANTS_SAND_GREEN = 2514,
PANTS_DARK_GREEN = 2515,
PANTS_EARTH_GREEN = 2516,
PANTS_EARTH_BLUE = 2517,
PANTS_BRIGHT_BLUE = 2519,
PANTS_SAND_BLUE = 2520,
PANTS_DARK_STONE_GRAY = 2521,
PANTS_MEDIUM_STONE_GRAY = 2522,
PANTS_WHITE = 2523,
PANTS_BLACK = 2524,
PANTS_REDDISH_BROWN = 2526,
PANTS_DARK_RED = 2527
};
const std::vector<uint32_t> shirtColorVector {
0, // BRIGHT_RED
1, // BRIGHT_BLUE
2, // BRIGHT_YELLOW
3, // DARK_GREEN
5, // BRIGHT_ORANGE
6, // BLACK
7, // DARK_STONE_GRAY
8, // MEDIUM_STONE_GRAY
9, // REDDISH_BROWN
10, // WHITE
11, // MEDIUM_BLUE
13, // DARK_RED
14, // EARTH_BLUE
15, // EARTH_GREEN
16, // BRICK_YELLOW
84, // SAND_BLUE
96 // SAND_GREEN
};
#endif // USERMANAGER_H

View File

@@ -1043,7 +1043,7 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks)
UpdateSlot(item->GetInfo().equipLocation, { item->GetId(), item->GetLot(), item->GetCount(), item->GetSlot() });
if (item->GetParent() == LWOOBJID_EMPTY) ApplyBuff(item->GetLot());
ApplyBuff(item);
AddItemSkills(item->GetLot());
@@ -1071,7 +1071,7 @@ void InventoryComponent::UnEquipItem(Item* item)
set->OnUnEquip(lot);
}
if (item->GetParent() == LWOOBJID_EMPTY) RemoveBuff(item->GetLot());
RemoveBuff(item);
RemoveItemSkills(item->GetLot());
@@ -1089,9 +1089,9 @@ void InventoryComponent::UnEquipItem(Item* item)
}
}
void InventoryComponent::ApplyBuff(const LOT lot) const
void InventoryComponent::ApplyBuff(Item* item) const
{
const auto buffs = FindBuffs(lot, true);
const auto buffs = FindBuffs(item, true);
for (const auto buff : buffs)
{
@@ -1099,9 +1099,9 @@ void InventoryComponent::ApplyBuff(const LOT lot) const
}
}
void InventoryComponent::RemoveBuff(const LOT lot) const
void InventoryComponent::RemoveBuff(Item* item) const
{
const auto buffs = FindBuffs(lot, false);
const auto buffs = FindBuffs(item, false);
for (const auto buff : buffs)
{
@@ -1418,18 +1418,18 @@ uint32_t InventoryComponent::FindSkill(const LOT lot)
return 0;
}
std::vector<uint32_t> InventoryComponent::FindBuffs(const LOT lot, bool castOnEquip) const
std::vector<uint32_t> InventoryComponent::FindBuffs(Item* item, bool castOnEquip) const
{
std::vector<uint32_t> buffs;
if (item == nullptr) return buffs;
auto* table = CDClientManager::Instance()->GetTable<CDObjectSkillsTable>("ObjectSkills");
auto* behaviors = CDClientManager::Instance()->GetTable<CDSkillBehaviorTable>("SkillBehavior");
const auto results = table->Query([=](const CDObjectSkills& entry)
{
return entry.objectTemplate == static_cast<unsigned int>(lot);
return entry.objectTemplate == static_cast<unsigned int>(item->GetLot());
});
std::vector<uint32_t> buffs;
auto* missions = static_cast<MissionComponent*>(m_Parent->GetComponent(COMPONENT_TYPE_MISSION));
for (const auto& result : results)
@@ -1449,8 +1449,8 @@ std::vector<uint32_t> InventoryComponent::FindBuffs(const LOT lot, bool castOnEq
{
missions->Progress(MissionTaskType::MISSION_TASK_TYPE_SKILL, result.skillID);
}
buffs.push_back(static_cast<uint32_t>(entry.behaviorID));
// If item is not a proxy, add its buff to the added buffs.
if (item->GetParent() == LWOOBJID_EMPTY) buffs.push_back(static_cast<uint32_t>(entry.behaviorID));
}
}
@@ -1531,7 +1531,7 @@ std::vector<Item*> InventoryComponent::GenerateProxies(Item* parent)
auto* inventory = GetInventory(ITEM_SETS);
auto* proxy = new Item(lot, inventory, inventory->FindEmptySlot(), 1, {}, parent->GetId(), false, parent->GetId());
auto* proxy = new Item(lot, inventory, inventory->FindEmptySlot(), 1, {}, parent->GetId(), false);
EquipItem(proxy);

View File

@@ -193,15 +193,15 @@ public:
/**
* Adds a buff related to equipping a lot to the entity
* @param lot the lot to find buffs for
* @param item the item to find buffs for
*/
void ApplyBuff(LOT lot) const;
void ApplyBuff(Item* item) const;
/**
* Removes buffs related to equipping a lot from the entity
* @param lot the lot to find buffs for
* @param item the item to find buffs for
*/
void RemoveBuff(LOT lot) const;
void RemoveBuff(Item* item) const;
/**
* Saves the equipped items into a temp state
@@ -240,11 +240,11 @@ public:
/**
* Finds all the buffs related to a lot
* @param lot the lot to get the buffs for
* @param item the item to get the buffs for
* @param castOnEquip if true, the skill missions for these buffs will be progressed
* @return the buffs related to the specified lot
*/
std::vector<uint32_t> FindBuffs(LOT lot, bool castOnEquip) const;
std::vector<uint32_t> FindBuffs(Item* item, bool castOnEquip) const;
/**
* Initializes the equipped items with a list of items

View File

@@ -416,6 +416,7 @@ void MissionTask::Progress(int32_t value, LWOOBJID associate, const std::string&
case MissionTaskType::MISSION_TASK_TYPE_RACING:
{
// The meaning of associate can be found in RacingTaskParam.h
if (parameters.empty()) break;
if (!InAllTargets(dZoneManager::Instance()->GetZone()->GetWorldID()) && !(parameters[0] == 4 || parameters[0] == 5) && !InAllTargets(value)) break;
@@ -440,6 +441,11 @@ void MissionTask::Progress(int32_t value, LWOOBJID associate, const std::string&
if (!InAllTargets(value)) break;
AddProgress(count);
}
else if (associate == 17)
{
if (!InAllTargets(value)) break;
AddProgress(count);
}
else
{
AddProgress(count);

View File

@@ -16,5 +16,5 @@ enum class RacingTaskParam : int32_t {
RACING_TASK_PARAM_WIN_RACE_IN_WORLD = 14, //<! A task param for winning a race in a specific world.
RACING_TASK_PARAM_FIRST_PLACE_MULTIPLE_TRACKS = 15, //<! A task param for finishing in first place on multiple tracks.
RACING_TASK_PARAM_LAST_PLACE_FINISH = 16, //<! A task param for finishing in last place.
RACING_TASK_PARAM_SMASH_DRAGON_EGGS = 17 //<! A task param for smashing dragon eggs during a race.
RACING_TASK_PARAM_SMASH_SPECIFIC_SMASHABLE = 17 //<! A task param for smashing dragon eggs during a race.
};

View File

@@ -363,11 +363,6 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
if (user->GetMaxGMLevel() == 0 || entity->GetGMLevel() >= 0) {
if ((chatCommand == "playanimation" || chatCommand == "playanim") && args.size() == 1) {
std::u16string anim = GeneralUtils::ASCIIToUTF16(args[0], args[0].size());
GameMessages::SendPlayAnimation(entity, anim);
}
if (chatCommand == "die") {
entity->Smash(entity->GetObjectID());
}
@@ -446,6 +441,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); // need to retoggle because it gets reenabled on creation of new character
}
if ((chatCommand == "playanimation" || chatCommand == "playanim") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
std::u16string anim = GeneralUtils::ASCIIToUTF16(args[0], args[0].size());
GameMessages::SendPlayAnimation(entity, anim);
}
if (chatCommand == "list-spawns" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
for (const auto& pair : EntityManager::Instance()->GetSpawnPointEntities()) {