feat: add read-only attr lock views for exchange, shop, safebox and inspect

This commit is contained in:
shen
2026-10-18 18:21:59 -07:00
parent bce34954d9
commit 5b8cc3069f
5 changed files with 153 additions and 5 deletions
+31 -5
View File
@@ -1,19 +1,45 @@
// Read-only presentation bridge: this port keeps AVA2 lock indices in an independent table.
#include "port_attr_lock.h"
#include <sstream>
#include "exchange.h"
#include "shop.h"
#include "safebox.h"
// Context IDs are presentation-only, never item window IDs or arbitrary owner IDs.
static LPITEM Ava2AttrLockView(LPCHARACTER ch,unsigned view,unsigned cell,unsigned vid) {
if (view==101 || view==102) {
CExchange* own=ch->GetExchange();
if (!own || own->GetOwner()!=ch || !own->GetCompany() || own->GetCompany()->GetCompany()!=own) return NULL;
CExchange* side=view==101?own:own->GetCompany();
LPITEM item=side->GetDisplayItem(cell);
return item && item->GetOwner()==side->GetOwner() && item->IsExchanging()?item:NULL;
}
if (view==103) return ch->GetShop()?ch->GetShop()->GetGuestItem(ch,cell):NULL;
if (view==104 || view==105) {
CSafebox* box=view==104?ch->GetSafebox():ch->GetMall();
return box && cell<SAFEBOX_MAX_NUM && box->IsValidPosition(cell)?box->Get(cell):NULL;
}
// do_view_equip is GM-only in the baseline. Never grant this to ordinary players.
if (view==106 && ch->GetGMLevel()>GM_PLAYER && cell<WEAR_MAX_NUM) {
LPCHARACTER owner=CHARACTER_MANAGER::instance().Find(vid);
return owner && owner->IsPC()?owner->GetWear(cell):NULL;
}
return NULL;
}
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;
unsigned token=0,window=0,cell=0,vid=0;std::string extra;std::istringstream args(argument);
if (!(args>>token>>window>>cell) || token>2147483647 || window>255 || cell>65535) return;
const bool view=window>=101 && window<=106;
if (view ? !(args>>vid) : (window!=INVENTORY && window!=EQUIPMENT && window!=SWITCHBOT)) return;
if ((args>>extra) || (window!=106 && vid)) 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 (!view && (window==SWITCHBOT ? cell>=SWITCHBOT_SLOT_COUNT : cell>=INVENTORY_AND_EQUIP_SLOT_MAX)) return;
LPITEM target=view?Ava2AttrLockView(ch,window,cell,vid):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.
+9
View File
@@ -22,6 +22,15 @@ class CExchange
bool AddItem(TItemPos item_pos, BYTE display_pos);
bool RemoveItem(BYTE pos);
// Tooltip cells are display positions, not m_apItems array indices.
LPITEM GetDisplayItem(unsigned cell) const {
if (cell >= EXCHANGE_ITEM_MAX_NUM) return NULL;
for (unsigned i=0;i<EXCHANGE_ITEM_MAX_NUM;++i)
if (m_apItems[i] && m_abItemDisplayPos[i]==cell) return m_apItems[i];
return NULL;
}
LPCHARACTER GetOwner() { return m_pOwner; }
CExchange * GetCompany() { return m_pCompany; }
+14
View File
@@ -462,6 +462,20 @@ int CShop::Buy(LPCHARACTER ch, BYTE pos)
return (SHOP_SUBHEADER_GC_OK);
}
LPITEM CShop::GetGuestItem(LPCHARACTER guest, unsigned cell)
{
if (!guest || guest->GetShop()!=this || m_map_guest.find(guest)==m_map_guest.end() ||
!m_pkPC || cell>=m_itemVector.size()) return NULL;
const SHOP_ITEM& row=m_itemVector[cell];
// Match AddGuest's hidden high-value stock rule as well as its membership check.
if (quest::CQuestManager::instance().GetEventFlag("hivalue_item_sell")==0 &&
(row.vnum==70024 || row.vnum==70035)) return NULL;
LPITEM item=row.pkItem;
if (!item || item->GetOwner()!=m_pkPC || item->GetID()!=DWORD(row.itemid) ||
item->GetVnum()!=row.vnum || !item->GetCount()) return NULL;
return item;
}
bool CShop::AddGuest(LPCHARACTER ch, DWORD owner_vid, bool bOtherEmpire)
{
if (!ch)
+1
View File
@@ -55,6 +55,7 @@ class CShop
// 아이템이 상점에 등록되어 있는지 알려준다.
virtual bool IsSellingItem(DWORD itemID);
LPITEM GetGuestItem(LPCHARACTER guest, unsigned cell);
DWORD GetVnum() { return m_dwVnum; }
DWORD GetNPCVnum() { return m_dwNPCVnum; }