Add safe AVA2 lock material selection and tooltip query
This commit is contained in:
@@ -137,3 +137,6 @@ $(OBJDIR)/ava2_track.o $(OBJDIR)/questlua_dungeon.o $(OBJDIR)/input_db.o $(OBJDI
|
||||
$(OBJDIR)/ava2_ticket_shop.o $(OBJDIR)/shop_manager.o $(OBJDIR)/cmd_general.o: ava2_ticket_shop.h
|
||||
|
||||
$(OBJDIR)/cmd_general.o $(OBJDIR)/ava2_track.o: port_dungeon_settings.h
|
||||
|
||||
$(OBJDIR)/cmd_general.o: ava2_attr_lock_commands.h port_attr_lock.h
|
||||
$(OBJDIR)/questlua_item.o: port_attr_lock.h
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Read-only presentation bridge: this port keeps AVA2 lock indices in an independent table.
|
||||
#include "port_attr_lock.h"
|
||||
#include <sstream>
|
||||
ACMD(do_attr_lock_info) {
|
||||
if (!ch || !ch->IsPC()) return;
|
||||
unsigned token=0,window=0,cell=0;std::string extra;std::istringstream args(argument);
|
||||
if (!(args>>token>>window>>cell) || (args>>extra) || token>2147483647 || window>255 || cell>65535 ||
|
||||
(window!=INVENTORY && window!=EQUIPMENT && window!=SWITCHBOT)) return;
|
||||
quest::PC* pc=quest::CQuestManager::instance().GetPCForce(ch->GetPlayerID());
|
||||
if (!pc || !pc->IsLoaded()) return;
|
||||
const int now=get_global_time();
|
||||
if (ch->GetProtectTime("attr_lock_query")>now) return;
|
||||
ch->SetProtectTime("attr_lock_query",now+1);
|
||||
const TItemPos pos{BYTE(window),WORD(cell)};
|
||||
if (window==SWITCHBOT ? cell>=SWITCHBOT_SLOT_COUNT : cell>=INVENTORY_AND_EQUIP_SLOT_MAX) return;
|
||||
LPITEM target=ch->GetItem(pos);int mask=0;
|
||||
if (target && PortAttrFilled(target)) {
|
||||
mask=PortAttrLockEffective(PortAttrLockGet(target),PortAttrFilled(target),target->GetProto() && target->GetProto()->sAddonType);
|
||||
if (!target->m_portAttrLockLoaded) mask=-1; // SQL failure is not an unlocked item.
|
||||
}
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"AttrLockInfo %u %u %u %u %d",token,window,cell,target?target->GetVnum():0,mask);
|
||||
}
|
||||
@@ -4560,10 +4560,26 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
|
||||
case USE_ADD_ATTRIBUTE:
|
||||
case USE_ADD_ATTRIBUTE2:
|
||||
{
|
||||
// AVA2: using a lock material without a destination selects its 1-based index in a quest.
|
||||
if ((item->GetVnum()==50348 || item->GetVnum()==50349) &&
|
||||
(!IsValidItemPosition(DestCell) || !GetItem(DestCell))) {
|
||||
quest::CQuestManager::instance().RegisterNPCVnum(item->GetVnum());
|
||||
quest::CQuestManager::instance().UseItem(GetPlayerID(),item,false);
|
||||
return true;
|
||||
}
|
||||
LPITEM item2;
|
||||
if (!IsValidItemPosition(DestCell) || !(item2 = GetItem(DestCell)))
|
||||
return false;
|
||||
|
||||
// AVA2 lock materials carry the selected 1-based attribute in socket 0.
|
||||
if (item->GetVnum() == 50348 || item->GetVnum() == 50349)
|
||||
{
|
||||
const long index = item->GetSocket(0);
|
||||
const char* error = index < 1 || index > 5 ? "slot" :
|
||||
PortAttrLockUse(this, item2, unsigned(index - 1), item);
|
||||
ChatPacket(CHAT_TYPE_COMMAND,"AttrLockResult %s",error?error:"ok");
|
||||
return error == NULL;
|
||||
}
|
||||
if (item->IsCostumeEnchant())
|
||||
return CostumeEnchantUse(item, item2);
|
||||
|
||||
@@ -4633,15 +4649,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
|
||||
break;
|
||||
|
||||
case USE_CHANGE_ATTRIBUTE :
|
||||
// AVA2 lock materials carry the selected 1-based attribute in socket 0.
|
||||
if (item->GetVnum() == 50348 || item->GetVnum() == 50349)
|
||||
{
|
||||
const long index = item->GetSocket(0);
|
||||
const char* error = index < 1 || index > 5 ? "slot" :
|
||||
PortAttrLockUse(this, item2, unsigned(index - 1), item);
|
||||
if (error) ChatPacket(CHAT_TYPE_INFO, "Attribute lock: %s", error);
|
||||
return error == NULL;
|
||||
}
|
||||
|
||||
if (item2->GetAttributeSetIndex() == -1 && !item2->IsNewRing())
|
||||
{
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("속성을 변경할 수 없는 아이템입니다."));
|
||||
|
||||
@@ -13,6 +13,7 @@ ACMD(do_port_features);
|
||||
ACMD(do_port_pickup);
|
||||
ACMD(do_setpickupmode);
|
||||
ACMD(do_track_window);
|
||||
ACMD(do_attr_lock_info);
|
||||
ACMD(do_open_shop);
|
||||
ACMD(do_port_chest);
|
||||
ACMD(do_chest_drop);
|
||||
@@ -610,6 +611,7 @@ struct command_info cmd_info[] =
|
||||
{ "mt_features", do_port_features, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "open_shop",do_open_shop,0,POS_DEAD,GM_PLAYER },
|
||||
{ "track_window",do_track_window,0,POS_DEAD,GM_PLAYER },
|
||||
{ "attr_lock_info",do_attr_lock_info,0,POS_DEAD,GM_PLAYER },
|
||||
{ "setpickupmode",do_setpickupmode,0,POS_DEAD,GM_PLAYER },
|
||||
{ "mt_pickup", do_port_pickup, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "chest_drop", do_chest_drop, 0, POS_DEAD, GM_PLAYER },
|
||||
|
||||
@@ -2724,3 +2724,5 @@ ACMD(do_open_shop)
|
||||
if (!(in>>shop) || (in>>extra) || shop!=12) return;
|
||||
if (!Ava2OpenTicketShop(ch)) ch->ChatPacket(CHAT_TYPE_COMMAND,"TrackError busy");
|
||||
}
|
||||
|
||||
#include "ava2_attr_lock_commands.h"
|
||||
|
||||
@@ -42,7 +42,9 @@ const char* PortAttrLockUse(CHARACTER* ch,CItem* item,unsigned slot,CItem* mater
|
||||
if(!material || material==item || material->GetOwner()!=ch || material->IsExchanging() || material->isLocked() ||
|
||||
material->IsEquipped() || material->GetCount()<1)return "material";
|
||||
const bool addon=item->GetProto() && item->GetProto()->sAddonType;
|
||||
const unsigned old=PortAttrLockEffective(PortAttrLockGet(item),PortAttrFilled(item),addon);
|
||||
const unsigned stored=PortAttrLockGet(item);
|
||||
if (!item->m_portAttrLockLoaded)return "db";
|
||||
const unsigned old=PortAttrLockEffective(stored,PortAttrFilled(item),addon);
|
||||
const bool removing=slot<5 && (old>>slot&1);
|
||||
if(material->GetVnum()!=(removing?50349u:50348u))return "material";
|
||||
unsigned mask=0;
|
||||
@@ -51,3 +53,12 @@ const char* PortAttrLockUse(CHARACTER* ch,CItem* item,unsigned slot,CItem* mater
|
||||
material->SetCount(material->GetCount()-1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Quest selection changes only the material's index; dragging it remains the sole lock mutation path.
|
||||
bool PortAttrLockSelect(CHARACTER* ch,CItem* material,unsigned index) {
|
||||
if (!ch || !material || material->GetOwner()!=ch || material->GetWindow()!=INVENTORY ||
|
||||
(material->GetVnum()!=50348 && material->GetVnum()!=50349) || index<1 || index>5 ||
|
||||
material->GetCount()<1 || material->IsEquipped() || material->IsExchanging() || material->isLocked() ||
|
||||
ch->IsDead() || ch->IsStun() || !ch->CanHandleItem() || ch->GetShop() || ch->GetExchange() || ch->IsOpenSafebox()) return false;
|
||||
material->SetSocket(0,index);material->Save();return true;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ inline const char* PortAttrLockToggle(unsigned mask,unsigned slot,unsigned fille
|
||||
class CItem;
|
||||
class CHARACTER;
|
||||
void PortAttrLockBoot();
|
||||
bool PortAttrLockSelect(CHARACTER* ch,CItem* material,unsigned index);
|
||||
// Cached on the item after the first lookup. A failed lookup returns 0 and is retried next time.
|
||||
unsigned PortAttrLockGet(CItem* item);
|
||||
// Writes synchronously (a following warp loads the new value on the next core); false on SQL error.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "item_manager.h"
|
||||
#include "over9refine.h"
|
||||
#include "log.h"
|
||||
#include "port_attr_lock.h"
|
||||
|
||||
#undef sys_err
|
||||
#ifndef __WIN32__
|
||||
@@ -467,6 +468,15 @@ namespace quest
|
||||
return 1;
|
||||
}
|
||||
|
||||
int item_select_attr_lock(lua_State* L) {
|
||||
// The quest can yield while the original item moves or is destroyed. Resolve its ID again.
|
||||
const double index=lua_tonumber(L,1),id=lua_tonumber(L,2);
|
||||
if (!lua_isnumber(L,1) || !lua_isnumber(L,2) || !(index>=1 && index<=5) || index!=int(index) ||
|
||||
!(id>0 && id<=4294967295.0) || id!=DWORD(id)) {lua_pushboolean(L,0);return 1;}
|
||||
LPITEM material=ITEM_MANAGER::instance().Find(DWORD(id));
|
||||
lua_pushboolean(L,PortAttrLockSelect(CQuestManager::instance().GetCurrentCharacterPtr(),material,unsigned(index)));return 1;
|
||||
}
|
||||
|
||||
void RegisterITEMFunctionTable()
|
||||
{
|
||||
|
||||
@@ -479,6 +489,7 @@ namespace quest
|
||||
{ "remove", item_remove },
|
||||
{ "get_socket", item_get_socket },
|
||||
{ "set_socket", item_set_socket },
|
||||
{ "select_attr_lock",item_select_attr_lock },
|
||||
{ "set_attribute", item_set_attribute },
|
||||
{ "get_vnum", item_get_vnum },
|
||||
{ "has_flag", item_has_flag },
|
||||
|
||||
Reference in New Issue
Block a user