Merge branch 'main' into main

This commit is contained in:
Aaron Kimbrell
2022-05-24 19:00:52 -05:00
committed by GitHub
169 changed files with 3164 additions and 1954 deletions

View File

@@ -268,15 +268,15 @@ std::unordered_map<LOT, int32_t> LootGenerator::RollLootMatrix(uint32_t matrixIn
return drops;
}
void LootGenerator::GiveLoot(Entity* player, uint32_t matrixIndex) {
void LootGenerator::GiveLoot(Entity* player, uint32_t matrixIndex, eLootSourceType lootSourceType) {
player = player->GetOwner(); // If the owner is overwritten, we collect that here
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
GiveLoot(player, result);
GiveLoot(player, result, lootSourceType);
}
void LootGenerator::GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result) {
void LootGenerator::GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result, eLootSourceType lootSourceType) {
player = player->GetOwner(); // if the owner is overwritten, we collect that here
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
@@ -285,7 +285,7 @@ void LootGenerator::GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& r
return;
for (const auto& pair : result) {
inventoryComponent->AddItem(pair.first, pair.second);
inventoryComponent->AddItem(pair.first, pair.second, lootSourceType);
}
}
@@ -314,13 +314,13 @@ void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t ac
maxCoins = currencyTable[0].maxvalue;
}
GiveLoot(player, selectedReward->LootMatrixIndex);
GiveLoot(player, selectedReward->LootMatrixIndex, eLootSourceType::LOOT_SOURCE_ACTIVITY);
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
auto* character = player->GetCharacter();
character->SetCoins(character->GetCoins() + coins, LOOT_SOURCE_ACTIVITY);
character->SetCoins(character->GetCoins() + coins, eLootSourceType::LOOT_SOURCE_ACTIVITY);
}
void LootGenerator::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) {

View File

@@ -47,8 +47,8 @@ class LootGenerator : public Singleton<LootGenerator> {
std::unordered_map<LOT, int32_t> RollLootMatrix(Entity* player, uint32_t matrixIndex);
std::unordered_map<LOT, int32_t> RollLootMatrix(uint32_t matrixIndex);
void GiveLoot(Entity* player, uint32_t matrixIndex);
void GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result);
void GiveLoot(Entity* player, uint32_t matrixIndex, eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE);
void GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result, eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE);
void GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating = 0);
void DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins);
void DropLoot(Entity* player, Entity* killedObject, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins);

View File

@@ -262,7 +262,7 @@ void Mail::HandleSendMail(RakNet::BitStream* packet, const SystemAddress& sysAdd
}
Mail::SendSendResponse(sysAddr, Mail::MailSendResponse::Success);
entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, LOOT_SOURCE_MAIL);
entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, eLootSourceType::LOOT_SOURCE_MAIL);
Game::logger->Log("Mail", "Seeing if we need to remove item with ID/count/LOT: %i %i %i\n", itemID, attachmentCount, itemLOT);
@@ -363,7 +363,7 @@ void Mail::HandleAttachmentCollect(RakNet::BitStream* packet, const SystemAddres
auto inv = static_cast<InventoryComponent*>(player->GetComponent(COMPONENT_TYPE_INVENTORY));
if (!inv) return;
inv->AddItem(attachmentLOT, attachmentCount);
inv->AddItem(attachmentLOT, attachmentCount, eLootSourceType::LOOT_SOURCE_MAIL);
Mail::SendAttachmentRemoveConfirm(sysAddr, mailID);

View File

@@ -131,6 +131,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
bool success = user->GetMaxGMLevel() >= level;
if (success) {
if (entity->GetGMLevel() > GAME_MASTER_LEVEL_CIVILIAN && level == GAME_MASTER_LEVEL_CIVILIAN)
{
GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS);
@@ -140,12 +141,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS);
}
WorldPackets::SendGMLevelChange(sysAddr, success, user->GetMaxGMLevel(), entity->GetGMLevel(), level);
GameMessages::SendChatModeUpdate(entity->GetObjectID(), level);
entity->SetGMLevel(level);
Game::logger->Log("SlashCommandHandler", "User %s (%i) has changed their GM level to %i for charID %llu\n", user->GetUsername().c_str(), user->GetAccountID(), level, entity->GetObjectID());
}
}
WorldPackets::SendGMLevelChange(sysAddr, success, user->GetMaxGMLevel(), entity->GetGMLevel(), level);
GameMessages::SendChatModeUpdate(entity->GetObjectID(), level);
entity->SetGMLevel(level);
Game::logger->Log("SlashCommandHandler", "User %s (%i) has changed their GM level to %i for charID %llu\n", user->GetUsername().c_str(), user->GetAccountID(), level, entity->GetObjectID());
}
}
#ifndef DEVELOPER_SERVER
if ((entity->GetGMLevel() > user->GetMaxGMLevel()) || (entity->GetGMLevel() > GAME_MASTER_LEVEL_CIVILIAN && user->GetMaxGMLevel() == GAME_MASTER_LEVEL_JUNIOR_DEVELOPER))
@@ -304,27 +305,15 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (chatCommand == "leave-zone") {
const auto currentZone = dZoneManager::Instance()->GetZone()->GetZoneID().GetMapID();
auto newZone = 1100;
switch (currentZone)
{
case 1101:
newZone = 1100;
break;
case 1204:
newZone = 1200;
break;
default:
newZone = 1100;
break;
}
if (currentZone == newZone)
{
auto newZone = 0;
if (currentZone % 100 == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"You are not in an instanced zone.");
return;
} else {
newZone = (currentZone / 100) * 100;
}
// If new zone would be inaccessible, then default to Avant Gardens.
if (!CheckIfAccessibleZone(newZone)) newZone = 1100;
ChatPackets::SendSystemMessage(sysAddr, u"Leaving zone...");
@@ -374,12 +363,7 @@ 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 (user->GetMaxGMLevel() == 0 || entity->GetGMLevel() >= 0) {
if (chatCommand == "die") {
entity->Smash(entity->GetObjectID());
}
@@ -406,11 +390,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
if (entity->GetGMLevel() == 0) return;
}
}
// Log command to database
auto stmt = Database::CreatePreppedStmt("INSERT INTO command_log (character_id, command) VALUES (?, ?);");
stmt->setInt(1, entity->GetCharacter()->GetID());
auto stmt = Database::CreatePreppedStmt("INSERT INTO command_log (character_id, command) VALUES (?, ?);");
stmt->setInt(1, entity->GetCharacter()->GetID());
stmt->setString(2, GeneralUtils::UTF16ToWTF8(command).c_str());
stmt->execute();
delete stmt;
@@ -459,6 +443,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()) {
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(pair.first));
@@ -672,7 +661,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
return;
}
entity->GetCharacter()->SetPlayerFlag(flagId, true);
entity->GetCharacter()->SetPlayerFlag(flagId, true);
}
if (chatCommand == "setflag" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 2)
@@ -688,7 +677,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
ChatPackets::SendSystemMessage(sysAddr, u"Invalid flag type.");
return;
}
entity->GetCharacter()->SetPlayerFlag(flagId, onOffFlag == "on");
entity->GetCharacter()->SetPlayerFlag(flagId, onOffFlag == "on");
}
if (chatCommand == "clearflag" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1)
{
@@ -700,7 +689,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
return;
}
entity->GetCharacter()->SetPlayerFlag(flagId, false);
entity->GetCharacter()->SetPlayerFlag(flagId, false);
}
if (chatCommand == "resetmission" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
@@ -798,8 +787,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
ChatPackets::SendSystemMessage(sysAddr, msg);
}
if (chatCommand == "gmadditem" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
if (args.size() == 1) {
if (chatCommand == "gmadditem" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
if (args.size() == 1) {
uint32_t itemLOT;
if (!GeneralUtils::TryParse(args[0], itemLOT))
@@ -810,8 +799,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
InventoryComponent * inventory = static_cast<InventoryComponent*>(entity->GetComponent(COMPONENT_TYPE_INVENTORY));
inventory->AddItem(itemLOT, 1);
} else if(args.size() == 2) {
inventory->AddItem(itemLOT, 1, eLootSourceType::LOOT_SOURCE_MODERATION);
} else if(args.size() == 2) {
uint32_t itemLOT;
if (!GeneralUtils::TryParse(args[0], itemLOT))
@@ -830,12 +819,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
InventoryComponent* inventory = static_cast<InventoryComponent*>(entity->GetComponent(COMPONENT_TYPE_INVENTORY));
inventory->AddItem(itemLOT, count);
inventory->AddItem(itemLOT, count, eLootSourceType::LOOT_SOURCE_MODERATION);
}
else {
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /gmadditem <lot>");
}
}
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /gmadditem <lot>");
}
}
if (chatCommand == "mailitem" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_MODERATOR && args.size() >= 2) {
const auto& playerName = args[0];
@@ -912,9 +901,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::ASCIIToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS);
}
if ((chatCommand == "teleport" || chatCommand == "tele") && entity->GetGMLevel() >= GAME_MASTER_LEVEL_JUNIOR_MODERATOR) {
NiPoint3 pos {};
if (args.size() == 3) {
if ((chatCommand == "teleport" || chatCommand == "tele") && entity->GetGMLevel() >= GAME_MASTER_LEVEL_JUNIOR_MODERATOR) {
NiPoint3 pos {};
if (args.size() == 3) {
float x, y, z;
@@ -943,6 +932,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
Game::logger->Log("SlashCommandHandler", "Teleporting objectID: %llu to %f, %f, %f\n", entity->GetObjectID(), pos.x, pos.y, pos.z);
GameMessages::SendTeleport(entity->GetObjectID(), pos, NiQuaternion(), sysAddr);
} else if (args.size() == 2) {
float x, z;
if (!GeneralUtils::TryParse(args[0], x))
@@ -961,7 +951,6 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
pos.SetY(0.0f);
pos.SetZ(z);
Game::logger->Log("SlashCommandHandler", "Teleporting objectID: %llu to X: %f, Z: %f\n", entity->GetObjectID(), pos.x, pos.z);
GameMessages::SendTeleport(entity->GetObjectID(), pos, NiQuaternion(), sysAddr);
} else {
@@ -988,7 +977,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
}
}
}
}
if (chatCommand == "tpall" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER)
{
@@ -1216,7 +1205,6 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
dest->SetImagination(999);
dest->SetMaxImagination(999.0f);
}
EntityManager::Instance()->SerializeEntity(entity);
}
@@ -1242,11 +1230,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
dest->SetImagination(9);
dest->SetMaxImagination(9.0f);
}
EntityManager::Instance()->SerializeEntity(entity);
}
if (chatCommand == "refillstats" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
auto dest = static_cast<DestroyableComponent*>(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE));
if (dest) {
dest->SetHealth((int)dest->GetMaxHealth());
@@ -1285,23 +1273,23 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
return;
}
EntityInfo info;
info.lot = lot;
info.pos = comp->GetPosition();
info.rot = comp->GetRotation();
EntityInfo info;
info.lot = lot;
info.pos = comp->GetPosition();
info.rot = comp->GetRotation();
info.spawner = nullptr;
info.spawnerID = entity->GetObjectID();
info.spawnerNodeID = 0;
Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr);
Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr);
if (newEntity == nullptr) {
if (newEntity == nullptr) {
ChatPackets::SendSystemMessage(sysAddr, u"Failed to spawn entity.");
return;
}
}
EntityManager::Instance()->ConstructEntity(newEntity);
}
EntityManager::Instance()->ConstructEntity(newEntity);
}
if ((chatCommand == "giveuscore") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
int32_t uscore;
@@ -1314,8 +1302,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
CharacterComponent* character = entity->GetComponent<CharacterComponent>();
if (character) character->SetUScore(character->GetUScore() + uscore);
GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), uscore, LOOTTYPE_NONE);
// LOOT_SOURCE_MODERATION should work but it doesn't. Relog to see uscore changes
GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), uscore, eLootSourceType::LOOT_SOURCE_MODERATION);
}
if (chatCommand == "pos" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
@@ -1345,9 +1333,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
GameMessages::SendPlayFXEffect(entity, 7074, u"create", "7074", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
}
if (chatCommand == "playrebuildfx" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
GameMessages::SendPlayFXEffect(entity, 230, u"rebuild", "230", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
}
if (chatCommand == "playrebuildfx" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
GameMessages::SendPlayFXEffect(entity, 230, u"rebuild", "230", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
}
if ((chatCommand == "freemoney" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) && args.size() == 1) {
int32_t money;
@@ -1359,7 +1347,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
auto* ch = entity->GetCharacter();
ch->SetCoins(ch->GetCoins() + money, LOOT_SOURCE_MODERATION);
ch->SetCoins(ch->GetCoins() + money, eLootSourceType::LOOT_SOURCE_MODERATION);
}
if ((chatCommand == "setcurrency") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
@@ -1372,7 +1360,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
auto* ch = entity->GetCharacter();
ch->SetCoins(money, LOOT_SOURCE_MODERATION);
ch->SetCoins(money, eLootSourceType::LOOT_SOURCE_MODERATION);
}
// Allow for this on even while not a GM, as it sometimes toggles incorrrectly.
@@ -1430,8 +1418,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
return;
}
if ((chatCommand == "testmap" && args.size() >= 1) && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) {
ChatPackets::SendSystemMessage(sysAddr, u"Requesting map change...");
if ((chatCommand == "testmap" && args.size() >= 1) && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) {
ChatPackets::SendSystemMessage(sysAddr, u"Requesting map change...");
uint32_t reqZone;
LWOCLONEID cloneId = 0;
bool force = false;
@@ -1482,12 +1470,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
);
}
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, reqZone, cloneId, false, [objid, darwin](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, reqZone, cloneId, false, [objid, darwin](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
auto* entity = EntityManager::Instance()->GetEntity(objid);
if (entity == nullptr) {
return;
}
if (entity == nullptr) {
return;
}
float transferTime = 3.32999992370605f;
if (darwin) transferTime = 0.0f;
@@ -1509,7 +1497,6 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
});
return;
});
} else {
@@ -1648,7 +1635,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
std::vector<LDFBaseData*> data {};
data.push_back(new LDFData<int32_t>(u"reforgedLOT", reforgedItem));
inventoryComponent->AddItem(baseItem, 1, INVALID, data);
inventoryComponent->AddItem(baseItem, 1, eLootSourceType::LOOT_SOURCE_MODERATION, eInventoryType::INVALID, data);
}
if (chatCommand == "crash" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_OPERATOR)
@@ -1953,54 +1940,17 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
bool SlashCommandHandler::CheckIfAccessibleZone(const unsigned int zoneID) {
switch (zoneID) {
case 98:
case 1000:
case 1001:
case 1100:
case 1101:
case 1150:
case 1151:
case 1152:
case 1200:
case 1201:
case 1250:
case 1251:
case 1260:
case 1300:
case 1350:
case 1351:
case 1400:
case 1401:
case 1450:
case 1451:
case 1600:
case 1601:
case 1602:
case 1603:
case 1604:
case 1700:
case 1800:
case 1900:
case 2000:
case 58004:
case 58005:
case 58006:
return true;
default:
return false;
//We're gonna go ahead and presume we've got the db loaded already:
CDZoneTableTable * zoneTable = CDClientManager::Instance()->GetTable<CDZoneTableTable>("ZoneTable");
const CDZoneTable* zone = zoneTable->Query(zoneID);
if (zone != nullptr) {
std::string zonePath = "./res/maps/" + zone->zoneName;
std::transform(zonePath.begin(), zonePath.end(), zonePath.begin(), ::tolower);
std::ifstream f(zonePath.c_str());
return f.good();
} else {
return false;
}
return false;
}
void SlashCommandHandler::SendAnnouncement(const std::string& title, const std::string& message) {