Fix items after "obtained" because RemoveItem can be called making the Item Ptr dead.
This commit is contained in:
parent
f4eb56e978
commit
ac15c6b9f7
@ -2964,6 +2964,15 @@ void LuaInterface::SetLuaUserDataStale(void* ptr) {
|
||||
}
|
||||
}
|
||||
|
||||
bool LuaInterface::IsLuaUserDataValid(void* ptr) {
|
||||
std::shared_lock lock(MLUAUserData);
|
||||
std::map<void*, LUAUserData*>::iterator itr = user_data_ptr.find(ptr);
|
||||
if(itr != user_data_ptr.end()) {
|
||||
return itr->second->correctly_initialized;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
LUAUserData::LUAUserData(){
|
||||
correctly_initialized = false;
|
||||
quest = 0;
|
||||
|
@ -355,6 +355,7 @@ public:
|
||||
int32 GetFreeCustomSpellID();
|
||||
|
||||
void SetLuaUserDataStale(void* ptr);
|
||||
bool IsLuaUserDataValid(void* ptr);
|
||||
|
||||
private:
|
||||
bool shutting_down;
|
||||
|
@ -2967,12 +2967,12 @@ bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overr
|
||||
guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
|
||||
guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
|
||||
}
|
||||
|
||||
|
||||
lootingClient->CheckPlayerQuestsItemUpdate(item);
|
||||
|
||||
if (item->GetItemScript() && lua_interface)
|
||||
lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
|
||||
|
||||
lootingClient->CheckPlayerQuestsItemUpdate(item);
|
||||
|
||||
if (GetVersion() <= 561) {
|
||||
EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
|
||||
if (outapp)
|
||||
@ -8079,6 +8079,9 @@ bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
|
||||
CheckPlayerQuestsItemUpdate(item);
|
||||
if (item->GetItemScript() && lua_interface)
|
||||
lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
|
||||
|
||||
if(!lua_interface->IsLuaUserDataValid(item) && item_deleted)
|
||||
*item_deleted = true;
|
||||
}
|
||||
else {
|
||||
lua_interface->SetLuaUserDataStale(item);
|
||||
@ -8537,7 +8540,6 @@ void Client::BuyItem(int32 item_id, int16 quantity) {
|
||||
bool itemDeleted = false;
|
||||
AddItem(item, &itemDeleted);
|
||||
if (!itemDeleted) {
|
||||
CheckPlayerQuestsItemUpdate(item);
|
||||
if (item && total_available < 0xFF) {
|
||||
world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
|
||||
SendBuyMerchantList();
|
||||
@ -8634,7 +8636,6 @@ void Client::BuyItem(int32 item_id, int16 quantity) {
|
||||
bool itemDeleted = false;
|
||||
AddItem(item, &itemDeleted);
|
||||
if (!itemDeleted) {
|
||||
CheckPlayerQuestsItemUpdate(item);
|
||||
if (item && total_available < 0xFF) {
|
||||
world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
|
||||
SendBuyMerchantList();
|
||||
|
Loading…
x
Reference in New Issue
Block a user