Add attribute lock (AVA2 ENABLE_LOCK_ATTR port)
Up to two normal attribute slots (addon pair = one group) keep their type and value through CItem::ChangeAttribute, so scroll rerolls, the switchbot and GM rerolls all respect it. The mask lives in the new player.mt_item_attr_lock table (created at boot), cached per CItem and written synchronously; CopyAttributeTo carries it to refined items. No item struct, db cache or client packet change. Toggled with /mt_switchbot 1 lock CELL SLOT; MTSB1 lock line follows attrs_end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
400e44fae4
commit
dc7159338e
@@ -61,7 +61,7 @@ CPPFILE = BattleArena.cpp FSM.cpp MarkConvert.cpp MarkImage.cpp MarkManager.cpp
|
||||
desc_client.cpp desc_manager.cpp desc_p2p.cpp dev_log.cpp dungeon.cpp empire_text_convert.cpp entity.cpp\
|
||||
entity_view.cpp event.cpp event_queue.cpp exchange.cpp file_loader.cpp fishing.cpp gm.cpp guild.cpp\
|
||||
guild_manager.cpp guild_war.cpp horse_rider.cpp horsename_manager.cpp input.cpp input_auth.cpp input_db.cpp\
|
||||
input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\
|
||||
input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp port_attr_lock.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\
|
||||
item.cpp item_addon.cpp item_attribute.cpp item_manager.cpp item_manager_idrange.cpp locale.cpp\
|
||||
locale_service.cpp log.cpp login_data.cpp lzo_manager.cpp marriage.cpp matrix_card.cpp\
|
||||
messenger_manager.cpp mining.cpp mob_manager.cpp monarch.cpp motion.cpp over9refine.cpp p2p.cpp packet_info.cpp\
|
||||
|
||||
@@ -51,6 +51,8 @@ void CItem::Initialize()
|
||||
m_bExchanging = false;
|
||||
memset(&m_alSockets, 0, sizeof(m_alSockets));
|
||||
memset(&m_aAttr, 0, sizeof(m_aAttr));
|
||||
m_portAttrLock = 0;
|
||||
m_portAttrLockLoaded = false;
|
||||
|
||||
m_pkDestroyEvent = NULL;
|
||||
m_pkOwnershipEvent = NULL;
|
||||
|
||||
@@ -171,6 +171,9 @@ class CItem : public CEntity
|
||||
int GetAttributeCount();
|
||||
void ClearAttribute();
|
||||
void ChangeAttribute(const int* aiChangeProb=NULL);
|
||||
// PORT: attribute lock cache, see port_attr_lock.h.
|
||||
BYTE m_portAttrLock;
|
||||
bool m_portAttrLockLoaded;
|
||||
void AddAttribute();
|
||||
void AddAttribute(BYTE bType, short sValue);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "char.h"
|
||||
#include "desc.h"
|
||||
#include "item_manager.h"
|
||||
#include "port_attr_lock.h"
|
||||
|
||||
const int MAX_NORM_ATTR_NUM = ITEM_MANAGER::MAX_NORM_ATTR_NUM;
|
||||
const int MAX_RARE_ATTR_NUM = ITEM_MANAGER::MAX_RARE_ATTR_NUM;
|
||||
@@ -189,24 +190,40 @@ void CItem::ChangeAttribute(const int* aiChangeProb)
|
||||
{
|
||||
int iAttributeCount = GetAttributeCount();
|
||||
|
||||
// PORT: locked slots (port_attr_lock.h) keep their type and value; the rest are rerolled into the gaps.
|
||||
TItemTable const * pProto = GetProto();
|
||||
const bool bAddon = pProto && pProto->sAddonType;
|
||||
const unsigned lock = iAttributeCount ? PortAttrLockEffective(PortAttrLockGet(this), PortAttrFilled(this), bAddon) : 0;
|
||||
TPlayerItemAttribute aLocked[MAX_NORM_ATTR_NUM];
|
||||
memcpy(aLocked, m_aAttr, sizeof(aLocked));
|
||||
|
||||
ClearAttribute();
|
||||
|
||||
if (iAttributeCount == 0)
|
||||
return;
|
||||
|
||||
TItemTable const * pProto = GetProto();
|
||||
|
||||
if (pProto && pProto->sAddonType)
|
||||
if (bAddon && !(lock & kPortAttrLockAddonPair))
|
||||
{
|
||||
ApplyAddon(pProto->sAddonType);
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_NORM_ATTR_NUM; ++i)
|
||||
if (lock >> i & 1)
|
||||
m_aAttr[i] = aLocked[i];
|
||||
|
||||
int iFilled = 0;
|
||||
|
||||
for (int i = 0; i < MAX_NORM_ATTR_NUM; ++i)
|
||||
if (m_aAttr[i].bType)
|
||||
++iFilled;
|
||||
|
||||
static const int tmpChangeProb[ITEM_ATTRIBUTE_MAX_LEVEL] =
|
||||
{
|
||||
0, 10, 40, 35, 15,
|
||||
};
|
||||
|
||||
for (int i = GetAttributeCount(); i < iAttributeCount; ++i)
|
||||
// PutAttribute fills the first empty slot, so the gaps between locked slots fill in order.
|
||||
for (int i = iFilled; i < iAttributeCount; ++i)
|
||||
{
|
||||
if (aiChangeProb == NULL)
|
||||
{
|
||||
@@ -333,6 +350,10 @@ void CItem::SetForceAttribute(int i, BYTE bType, short sValue)
|
||||
void CItem::CopyAttributeTo(LPITEM pItem)
|
||||
{
|
||||
pItem->SetAttributes(m_aAttr);
|
||||
|
||||
// PORT: the lock follows the attributes to the refined / replaced item.
|
||||
if (const unsigned lock = PortAttrLockGet(this))
|
||||
PortAttrLockSet(GetOwner(), pItem, lock);
|
||||
}
|
||||
|
||||
int CItem::GetRareAttrCount()
|
||||
|
||||
@@ -238,6 +238,7 @@ extern std::vector<TPlayerTable> g_vec_save;
|
||||
unsigned int save_idx = 0;
|
||||
|
||||
void PortBossTick();
|
||||
void PortAttrLockBoot();
|
||||
|
||||
void heartbeat(LPHEART ht, int pulse)
|
||||
{
|
||||
@@ -792,6 +793,9 @@ int start(int argc, char **argv)
|
||||
config_init(st_localeServiceName);
|
||||
// END_OF_LOCALE_SERVICE
|
||||
|
||||
if (!g_bAuthServer)
|
||||
PortAttrLockBoot();
|
||||
|
||||
#ifdef __WIN32__
|
||||
// In Windows dev mode, "verbose" option is [on] by default.
|
||||
bVerbose = true;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "stdafx.h"
|
||||
#include "utils.h"
|
||||
#include "char.h"
|
||||
#include "db.h"
|
||||
#include "item.h"
|
||||
#include "log.h"
|
||||
#include "port_attr_lock.h"
|
||||
|
||||
void PortAttrLockBoot() {
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(
|
||||
"CREATE TABLE IF NOT EXISTS mt_item_attr_lock (item_id INT UNSIGNED NOT NULL PRIMARY KEY,"
|
||||
" mask TINYINT UNSIGNED NOT NULL) ENGINE=MyISAM"));
|
||||
if(msg->uiSQLErrno)sys_err("PortAttrLockBoot: cannot create mt_item_attr_lock (errno %u)",msg->uiSQLErrno);
|
||||
}
|
||||
|
||||
unsigned PortAttrLockGet(CItem* item) {
|
||||
if(item->m_portAttrLockLoaded)return item->m_portAttrLock;
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("SELECT mask FROM mt_item_attr_lock WHERE item_id=%u",item->GetID()));
|
||||
if(msg->uiSQLErrno){sys_err("PortAttrLockGet: item %u lookup failed",item->GetID());return 0;}
|
||||
unsigned mask=0;
|
||||
if(msg->Get()->uiNumRows) {
|
||||
MYSQL_ROW row=mysql_fetch_row(msg->Get()->pSQLResult);
|
||||
str_to_number(mask,row[0]);
|
||||
}
|
||||
item->m_portAttrLock=BYTE(mask);item->m_portAttrLockLoaded=true;
|
||||
return mask;
|
||||
}
|
||||
|
||||
bool PortAttrLockSet(CHARACTER* ch,CItem* item,unsigned mask) {
|
||||
std::unique_ptr<SQLMsg> msg(mask?
|
||||
DBManager::instance().DirectQuery("REPLACE INTO mt_item_attr_lock (item_id,mask) VALUES(%u,%u)",item->GetID(),mask):
|
||||
DBManager::instance().DirectQuery("DELETE FROM mt_item_attr_lock WHERE item_id=%u",item->GetID()));
|
||||
if(msg->uiSQLErrno){sys_err("PortAttrLockSet: item %u mask %u failed",item->GetID(),mask);return false;}
|
||||
item->m_portAttrLock=BYTE(mask);item->m_portAttrLockLoaded=true;
|
||||
char hint[16];snprintf(hint,sizeof(hint),"%u",mask);
|
||||
if(ch)LogManager::instance().ItemLog(ch,item,"ATTR_LOCK",hint);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef METIN2_PORT_ATTR_LOCK_H
|
||||
#define METIN2_PORT_ATTR_LOCK_H
|
||||
// PORT: attribute lock (AVA2 ENABLE_LOCK_ATTR). Up to two of the five normal attribute slots keep their type and
|
||||
// value through CItem::ChangeAttribute, so manual scrolls, the switchbot and GM rerolls all respect it.
|
||||
// AVA2 keeps the lock indices in attribute slots 7/8; this server has no spare attribute or socket slot, so the
|
||||
// mask lives in player.mt_item_attr_lock keyed by item ID (port_attr_lock.cpp) and no client packet changes.
|
||||
// Bit i = normal slot i. On items with an addon type, slots 0 and 1 (skill / normal hit bonus) are one group.
|
||||
|
||||
static const unsigned kPortAttrLockSlots=5,kPortAttrLockGroups=2,kPortAttrLockAddonPair=3;
|
||||
|
||||
// Mask of the normal slots that hold an attribute.
|
||||
template<class Item> unsigned PortAttrFilled(Item* item) {
|
||||
unsigned filled=0;
|
||||
for(unsigned i=0;i<kPortAttrLockSlots;++i)if(item->GetAttributeType(i))filled|=1u<<i;
|
||||
return filled;
|
||||
}
|
||||
|
||||
inline unsigned PortAttrLockGroupCount(unsigned mask,bool addon) {
|
||||
unsigned groups=0;
|
||||
for(unsigned i=0;i<kPortAttrLockSlots;++i)if(mask>>i&1)++groups;
|
||||
if(addon && (mask&kPortAttrLockAddonPair)==kPortAttrLockAddonPair)--groups;
|
||||
return groups;
|
||||
}
|
||||
|
||||
// The stored mask as ChangeAttribute applies it: only filled slots, the addon pair kept whole.
|
||||
inline unsigned PortAttrLockEffective(unsigned mask,unsigned filled,bool addon) {
|
||||
mask&=(1u<<kPortAttrLockSlots)-1;
|
||||
if(addon && (mask&kPortAttrLockAddonPair))mask|=kPortAttrLockAddonPair;
|
||||
return mask&filled;
|
||||
}
|
||||
|
||||
// Toggle the lock on SLOT. Returns NULL and sets OUT, or an MTSB1 error code:
|
||||
// slot (out of range or empty), max (a third group, or every filled slot would be locked).
|
||||
inline const char* PortAttrLockToggle(unsigned mask,unsigned slot,unsigned filled,bool addon,unsigned& out) {
|
||||
if(slot>=kPortAttrLockSlots || !(filled>>slot&1))return "slot";
|
||||
mask=PortAttrLockEffective(mask,filled,addon);
|
||||
const unsigned bit=addon && slot<2?kPortAttrLockAddonPair&filled:1u<<slot;
|
||||
if(mask&bit){out=mask&~bit;return 0;}
|
||||
const unsigned next=mask|bit;
|
||||
if(PortAttrLockGroupCount(next,addon)>kPortAttrLockGroups || next==filled)return "max";
|
||||
out=next;return 0;
|
||||
}
|
||||
|
||||
class CItem;
|
||||
class CHARACTER;
|
||||
void PortAttrLockBoot();
|
||||
// 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.
|
||||
bool PortAttrLockSet(CHARACTER* ch,CItem* item,unsigned mask);
|
||||
#endif
|
||||
@@ -3,11 +3,13 @@
|
||||
// PORT: AVA2-style automatic attribute change. Every roll goes through the original
|
||||
// CHARACTER::UseItem change-attribute path, so its checks, probabilities, log and consumption apply unchanged.
|
||||
// One bound item per character; not persisted; stops on logout, warp, busy windows or any rejected roll.
|
||||
// The lock verb toggles the attribute lock (port_attr_lock.h) that ChangeAttribute applies to every reroll.
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "port_attr_lock.h"
|
||||
|
||||
static const unsigned kPortSwitchAlternatives=2, kPortSwitchTargets=5, kPortSwitchLimit=1000;
|
||||
static const unsigned kPortSwitchAddonSkillMax=30, kPortSwitchAddonNormalMax=65; // CItemAddonManager::ApplyAddonTo bounds.
|
||||
@@ -141,6 +143,29 @@ static void PortSwitchStop(LPCHARACTER ch,const char* reason) {
|
||||
g_portSwitchbots.erase(it);
|
||||
}
|
||||
|
||||
static void PortSwitchLockLine(LPCHARACTER ch,LPITEM item) {
|
||||
const bool addon=item->GetProto() && item->GetProto()->sAddonType;
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 lock %u %u %u",unsigned(item->GetCell()),unsigned(item->GetVnum()),
|
||||
PortAttrLockEffective(PortAttrLockGet(item),PortAttrFilled(item),addon));
|
||||
}
|
||||
|
||||
// lock CELL SLOT: toggle the lock on one normal slot; not while the bot rolls this item.
|
||||
static const char* PortSwitchLock(LPCHARACTER ch,unsigned cell,unsigned slot) {
|
||||
if(PortSwitchBusy(ch))return "busy";
|
||||
LPITEM item=cell<INVENTORY_MAX_NUM?ch->GetItem(TItemPos(INVENTORY,cell)):NULL;
|
||||
if(!item)return "item";
|
||||
if(item->IsEquipped() || item->IsExchanging())return "equipped";
|
||||
if(item->GetType()==ITEM_COSTUME || item->GetAttributeSetIndex()<0)return "no_attr";
|
||||
auto it=g_portSwitchbots.find(ch->GetPlayerID());
|
||||
if(it!=g_portSwitchbots.end() && it->second.item==item->GetID())return "running";
|
||||
const bool addon=item->GetProto() && item->GetProto()->sAddonType;
|
||||
unsigned mask=0;
|
||||
if(const char* error=PortAttrLockToggle(PortAttrLockGet(item),slot,PortAttrFilled(item),addon,mask))return error;
|
||||
if(!PortAttrLockSet(ch,item,mask))return "db";
|
||||
PortSwitchLockLine(ch,item);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void PortSwitchAttrs(LPCHARACTER ch,unsigned cell) {
|
||||
LPITEM item=cell<INVENTORY_MAX_NUM?ch->GetItem(TItemPos(INVENTORY,cell)):NULL;
|
||||
if(!item){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 error attrs item");return;}
|
||||
@@ -150,6 +175,7 @@ static void PortSwitchAttrs(LPCHARACTER ch,unsigned cell) {
|
||||
for(unsigned i=0;i<allowed.size();++i)
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 attr %u %u %d",i,allowed[i].first,allowed[i].second);
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 attrs_end %u %u",cell,unsigned(allowed.size()));
|
||||
PortSwitchLockLine(ch,item);
|
||||
}
|
||||
|
||||
// start CELL SCROLL LIMIT N1 (APPLY VALUE)*N1 [N2 (APPLY VALUE)*N2]
|
||||
@@ -199,8 +225,12 @@ ACMD(do_port_switchbot) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 error %s rate",verb.c_str());return;
|
||||
}
|
||||
ch->m_portSwitchbotLastCommand=get_dword_time();
|
||||
unsigned cell=0;
|
||||
unsigned cell=0,slot=0;
|
||||
if(verb=="attrs" && args.size()==3 && PortSwitchNumber(args[2],cell)) PortSwitchAttrs(ch,cell);
|
||||
else if(verb=="lock" && args.size()==4 && PortSwitchNumber(args[2],cell) && PortSwitchNumber(args[3],slot)) {
|
||||
const char* error=PortSwitchLock(ch,cell,slot);
|
||||
if(error)ch->ChatPacket(CHAT_TYPE_COMMAND,"MTSB1 error lock %s",error);
|
||||
}
|
||||
else if(verb=="stop" && args.size()==2) PortSwitchStop(ch,"stopped");
|
||||
else if(verb=="status" && args.size()==2) {
|
||||
auto it=g_portSwitchbots.find(ch->GetPlayerID());
|
||||
|
||||
Reference in New Issue
Block a user