Merge pull request #291 from EmosewaMC/EmosewaMC

Implemented sourceType for SendSetCurrency
This commit is contained in:
Xiphoseer 2022-01-04 12:01:32 +01:00 committed by GitHub
commit 4d19459015
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 50 additions and 29 deletions

View File

@ -469,6 +469,31 @@ enum eRebuildState : uint32_t {
REBUILD_INCOMPLETE
};
enum eLootSourceType : int32_t {
LOOT_SOURCE_NONE = 0,
LOOT_SOURCE_CHEST,
LOOT_SOURCE_MISSION,
LOOT_SOURCE_MAIL,
LOOT_SOURCE_CURRENCY,
LOOT_SOURCE_ACHIEVEMENT,
LOOT_SOURCE_TRADE,
LOOT_SOURCE_QUICKBUILD,
LOOT_SOURCE_DELETION,
LOOT_SOURCE_VENDOR,
LOOT_SOURCE_ACTIVITY,
LOOT_SOURCE_PICKUP,
LOOT_SOURCE_BRICK,
LOOT_SOURCE_PROPERTY,
LOOT_SOURCE_MODERATION,
LOOT_SOURCE_EXHIBIT,
LOOT_SOURCE_INVENTORY,
LOOT_SOURCE_CLAIMCODE,
LOOT_SOURCE_CONSUMPTION,
LOOT_SOURCE_CRAFTING,
LOOT_SOURCE_LEVELREWARD,
LOOT_SOURCE_RELOCATE
};
enum eGameActivities : uint32_t {
ACTIVITY_NONE,
ACTIVITY_QUICKBUILDING,

View File

@ -527,7 +527,7 @@ void Character::OnZoneLoad()
*/
if (HasPermission(PermissionMap::Old)) {
if (GetCoins() > 1000000) {
SetCoins(1000000);
SetCoins(1000000, LOOT_SOURCE_NONE);
}
}
@ -567,7 +567,7 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const
return pair->second;
}
void Character::SetCoins(int64_t newCoins, const bool message) {
void Character::SetCoins(int64_t newCoins, eLootSourceType lootSource) {
if (newCoins < 0)
{
newCoins = 0;
@ -575,10 +575,7 @@ void Character::SetCoins(int64_t newCoins, const bool message) {
m_Coins = newCoins;
if (message)
{
GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true);
}
GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootSource);
}
bool Character::HasBeenToWorld(LWOMAPID mapID) const

View File

@ -309,12 +309,11 @@ public:
const int64_t GetCoins() const { return m_Coins; }
/**
* Updates the current amount of coins of the character by a specified amount, for achievements this is not sent
* as it's tracked by the client
* Updates the current amount of coins of the character by a specified amount
* @param newCoins the amount of coins to update by
* @param message whether to notify the client of the change
* @param coinSource The source of the loot
*/
void SetCoins(int64_t newCoins, bool message = true);
void SetCoins(int64_t newCoins, eLootSourceType coinSource);
/**
* Get the entity this character belongs to

View File

@ -151,8 +151,8 @@ void Trade::Complete()
if (inventoryA == nullptr || inventoryB == nullptr || characterA == nullptr || characterB == nullptr || missionsA == nullptr || missionsB == nullptr) return;
characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB);
characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA);
characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB, LOOT_SOURCE_TRADE);
characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, LOOT_SOURCE_TRADE);
for (const auto& tradeItem : m_ItemsA)
{

View File

@ -825,7 +825,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose);
}
character->SetCoins(coinsTotal);
character->SetCoins(coinsTotal, LOOT_SOURCE_PICKUP);
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {

View File

@ -706,7 +706,7 @@ void GameMessages::SendBroadcastTextToChatbox(Entity* entity, const SystemAddres
SEND_PACKET_BROADCAST
}
void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent) {
void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, eLootSourceType sourceType) {
CBITSTREAM
CMSGHEADER
@ -729,7 +729,6 @@ void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootTyp
bitStream.Write(sourceTradeID != LWOOBJID_EMPTY);
if (sourceTradeID != LWOOBJID_EMPTY) bitStream.Write(sourceTradeID);
int sourceType = 0; //For now.
bitStream.Write(sourceType != LOOTTYPE_NONE);
if (sourceType != LOOTTYPE_NONE) bitStream.Write(sourceType);
@ -4685,7 +4684,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti
inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost);
}
character->SetCoins(character->GetCoins() - (coinCost));
character->SetCoins(character->GetCoins() - (coinCost), LOOT_SOURCE_VENDOR);
inv->AddItem(item, count);
}
@ -4734,7 +4733,7 @@ void GameMessages::HandleSellToVendor(RakNet::BitStream* inStream, Entity* entit
//inv->RemoveItem(count, -1, iObjID);
inv->MoveItemToInventory(item, VENDOR_BUYBACK, count, true, false, true);
character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count)));
character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count)), LOOT_SOURCE_VENDOR);
//EntityManager::Instance()->SerializeEntity(player); // so inventory updates
GameMessages::SendVendorTransactionResult(entity, sysAddr);
}
@ -4796,7 +4795,7 @@ void GameMessages::HandleBuybackFromVendor(RakNet::BitStream* inStream, Entity*
//inv->RemoveItem(count, -1, iObjID);
inv->MoveItemToInventory(item, Inventory::FindInventoryTypeForLot(item->GetLot()), count, true, false);
character->SetCoins(character->GetCoins() - cost);
character->SetCoins(character->GetCoins() - cost, LOOT_SOURCE_VENDOR);
//EntityManager::Instance()->SerializeEntity(player); // so inventory updates
GameMessages::SendVendorTransactionResult(entity, sysAddr);
}
@ -5240,7 +5239,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent
auto* ch = entity->GetCharacter();
if (entity->CanPickupCoins(currency)) {
ch->SetCoins(ch->GetCoins() + currency);
ch->SetCoins(ch->GetCoins() + currency, LOOT_SOURCE_PICKUP);
}
}

View File

@ -78,7 +78,7 @@ namespace GameMessages {
void SendPlayFXEffect(const LWOOBJID& entity, int32_t effectID, const std::u16string& effectType, const std::string& name, LWOOBJID secondary = LWOOBJID_EMPTY, float priority = 1, float scale = 1, bool serialize = true);
void SendStopFXEffect(Entity* entity, bool killImmediate, std::string name);
void SendBroadcastTextToChatbox(Entity* entity, const SystemAddress& sysAddr, const std::u16string& attrs, const std::u16string& wsText);
void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent);
void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, eLootSourceType sourceType);
void SendRebuildNotifyState(Entity* entity, int prevState, int state, const LWOOBJID& playerID);
void SendEnableRebuild(Entity* entity, bool enable, bool fail, bool success, int failReason, float duration, const LWOOBJID& playerID);

View File

@ -444,7 +444,7 @@ void Mission::YieldRewards() {
auto count = pair.second > 0 ? pair.second : 1;
// Sanitfy check, 6 is the max any mission yields
// Sanity check, 6 is the max any mission yields
if (count > 6) {
count = 0;
}
@ -453,7 +453,7 @@ void Mission::YieldRewards() {
}
if (info->reward_currency_repeatable > 0) {
character->SetCoins(character->GetCoins() + info->reward_currency_repeatable);
character->SetCoins(character->GetCoins() + info->reward_currency_repeatable, LOOT_SOURCE_MISSION);
}
return;
@ -473,7 +473,7 @@ void Mission::YieldRewards() {
auto count = pair.second > 0 ? pair.second : 1;
// Sanitfy check, 6 is the max any mission yields
// Sanity check, 6 is the max any mission yields
if (count > 6) {
count = 0;
}
@ -482,7 +482,8 @@ void Mission::YieldRewards() {
}
if (info->reward_currency > 0) {
character->SetCoins(character->GetCoins() + info->reward_currency, info->isMission);
eLootSourceType lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT;
character->SetCoins(character->GetCoins() + info->reward_currency, lootSource);
}
if (info->reward_maxinventory > 0) {

View File

@ -320,7 +320,7 @@ void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t ac
auto* character = player->GetCharacter();
character->SetCoins(character->GetCoins() + coins);
character->SetCoins(character->GetCoins() + coins, LOOT_SOURCE_ACTIVITY);
}
void LootGenerator::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, 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);
entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, 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);

View File

@ -1334,7 +1334,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
auto* ch = entity->GetCharacter();
ch->SetCoins(ch->GetCoins() + money);
ch->SetCoins(ch->GetCoins() + money, LOOT_SOURCE_MODERATION);
}
if ((chatCommand == "setcurrency") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
@ -1347,7 +1347,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
auto* ch = entity->GetCharacter();
ch->SetCoins(money);
ch->SetCoins(money, LOOT_SOURCE_MODERATION);
}
// Allow for this on even while not a GM, as it sometimes toggles incorrrectly.