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(){
|
LUAUserData::LUAUserData(){
|
||||||
correctly_initialized = false;
|
correctly_initialized = false;
|
||||||
quest = 0;
|
quest = 0;
|
||||||
|
@ -355,6 +355,7 @@ public:
|
|||||||
int32 GetFreeCustomSpellID();
|
int32 GetFreeCustomSpellID();
|
||||||
|
|
||||||
void SetLuaUserDataStale(void* ptr);
|
void SetLuaUserDataStale(void* ptr);
|
||||||
|
bool IsLuaUserDataValid(void* ptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool shutting_down;
|
bool shutting_down;
|
||||||
|
@ -2968,11 +2968,11 @@ bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overr
|
|||||||
guild->SendMessageToGuild(type, "%s has looted the %s %s", 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)
|
if (item->GetItemScript() && lua_interface)
|
||||||
lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
|
lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
|
||||||
|
|
||||||
lootingClient->CheckPlayerQuestsItemUpdate(item);
|
|
||||||
|
|
||||||
if (GetVersion() <= 561) {
|
if (GetVersion() <= 561) {
|
||||||
EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
|
EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
|
||||||
if (outapp)
|
if (outapp)
|
||||||
@ -8079,6 +8079,9 @@ bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
|
|||||||
CheckPlayerQuestsItemUpdate(item);
|
CheckPlayerQuestsItemUpdate(item);
|
||||||
if (item->GetItemScript() && lua_interface)
|
if (item->GetItemScript() && lua_interface)
|
||||||
lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
|
lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
|
||||||
|
|
||||||
|
if(!lua_interface->IsLuaUserDataValid(item) && item_deleted)
|
||||||
|
*item_deleted = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lua_interface->SetLuaUserDataStale(item);
|
lua_interface->SetLuaUserDataStale(item);
|
||||||
@ -8537,7 +8540,6 @@ void Client::BuyItem(int32 item_id, int16 quantity) {
|
|||||||
bool itemDeleted = false;
|
bool itemDeleted = false;
|
||||||
AddItem(item, &itemDeleted);
|
AddItem(item, &itemDeleted);
|
||||||
if (!itemDeleted) {
|
if (!itemDeleted) {
|
||||||
CheckPlayerQuestsItemUpdate(item);
|
|
||||||
if (item && total_available < 0xFF) {
|
if (item && total_available < 0xFF) {
|
||||||
world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
|
world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
|
||||||
SendBuyMerchantList();
|
SendBuyMerchantList();
|
||||||
@ -8634,7 +8636,6 @@ void Client::BuyItem(int32 item_id, int16 quantity) {
|
|||||||
bool itemDeleted = false;
|
bool itemDeleted = false;
|
||||||
AddItem(item, &itemDeleted);
|
AddItem(item, &itemDeleted);
|
||||||
if (!itemDeleted) {
|
if (!itemDeleted) {
|
||||||
CheckPlayerQuestsItemUpdate(item);
|
|
||||||
if (item && total_available < 0xFF) {
|
if (item && total_available < 0xFF) {
|
||||||
world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
|
world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
|
||||||
SendBuyMerchantList();
|
SendBuyMerchantList();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user