AVA2 unlock P6: costume enchants (client)

Keep 54001-54078 (body/hair) and 54124-54174 (mount skin) enchants as
USE_CHANGE_ATTRIBUTE; mt_costume_attr marks matching costumes as drop
targets, shows the attribute in the tooltip and renders MTCATTR; the
switchbot no longer lists enchants as scrolls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-16 14:07:07 +09:00
co-authored by Claude Opus 5.5
parent 1412806ee9
commit a1b63c0afb
5 changed files with 103 additions and 8 deletions
@@ -0,0 +1,83 @@
// PORT: AVA2 costume enchants (ENABLE_SPECIAL_COSTUME_ATTR), as module mt_costume_attr. Items 54001-54267 are
// USE_CHANGE_ATTRIBUTE rows with value0 = apply, value1 = value, value2 = target mask (1 << bonus flag); the server
// (metin2-server port_costume_attr.cpp) adds that attribute to a body / hair / mount-skin costume. The 40250
// inventory already sends every USE_CHANGE_ATTRIBUTE drop to the server; this script only marks the matching
// costumes as usable targets, shows the attribute in the enchant's tooltip and renders the "MTCATTR <code>" server
// messages that replace AVA2's locale strings 1056 / 1057 / 1061 / 1062 / 1063.
static const char c_szCostumeAttrScript[] = R"PY(# -*- coding: utf-8 -*-
import chat
import game
import item
import player
import uiInventory
import uiToolTip
L=player.AutoHuntLocalize
VNUMS=(54001,54267)
MAX_ATTR=3
# AVA2 CItem::GetBonusFlag of the costume kinds the server maps -> (mask bit, target name).
TARGETS={item.COSTUME_TYPE_BODY:(1,'时装'),item.COSTUME_TYPE_HAIR:(2,'发型'),item.COSTUME_TYPE_MOUNT_SKIN:(4,'坐骑外观')}
MESSAGES={'target':'该强化石不能用于这件物品。','none':'该强化石没有可附加的属性。','equipped':'请先卸下时装再附加属性。',
'full':'这件时装的附加属性已满(最多 3 条)。','has':'这件时装已有该属性。','done':'附加属性成功。'}
def Enchant(vnum):
"""(apply, value, mask) of a costume enchant, else None (selects vnum)."""
if not VNUMS[0]<=vnum<=VNUMS[1]:return None
item.SelectItem(vnum)
if item.GetItemType()!=item.ITEM_TYPE_USE or item.GetUseType(vnum)!="USE_CHANGE_ATTRIBUTE" or not item.GetValue(2):return None
return (item.GetValue(0),item.GetValue(1),item.GetValue(2))
def CanEnchant(enchant,dstSlot):
dstVnum=player.GetItemIndex(dstSlot)
if not dstVnum or player.IsEquipmentSlot(dstSlot):return False
item.SelectItem(dstVnum)
if item.GetItemType()!=item.ITEM_TYPE_COSTUME:return False
target=TARGETS.get(item.GetItemSubType())
if not target or not enchant[2]&(1<<target[0]):return False
attrs=[player.GetItemAttribute(dstSlot,i) for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM)]
used=[a for a in attrs if a[0]]
return len(used)<MAX_ATTR and enchant[0] not in [a[0] for a in used]
_canUse=uiInventory.InventoryWindow._InventoryWindow__CanUseSrcItemToDstItem
def CanUseSrcItemToDstItem(self,srcItemVNum,srcSlotPos,dstSlotPos):
enchant=Enchant(srcItemVNum)
if enchant is None:return _canUse(self,srcItemVNum,srcSlotPos,dstSlotPos)
return srcSlotPos!=dstSlotPos and CanEnchant(enchant,dstSlotPos)
uiInventory.InventoryWindow._InventoryWindow__CanUseSrcItemToDstItem=CanUseSrcItemToDstItem
Tip=uiToolTip.ItemToolTip
_addItemData=Tip.AddItemData
def AddItemData(self,itemVnum,metinSlot,attrSlot=0,flags=0,unbindTime=0):
result=_addItemData(self,itemVnum,metinSlot,attrSlot,flags,unbindTime)
enchant=Enchant(itemVnum)
if enchant:
self.AppendSpace(5)
affect=self._ItemToolTip__GetAffectString(enchant[0],enchant[1])
if affect:self.AppendTextLine(affect,self.POSITIVE_COLOR)
names=[name for bit,name in sorted(TARGETS.values()) if enchant[2]&(1<<bit)]
if names:self.AppendTextLine(L('适用:'+'、'.join(names)),self.CONDITION_COLOR)
self.ResizeToolTip()
return result
Tip.AddItemData=AddItemData
_command=game.GameWindow.BINARY_ServerCommand_Run
def Command(self,line):
if line.startswith('MTCATTR '):
words=line.split()
text=MESSAGES.get(words[1] if len(words)>1 else '')
if text:chat.AppendChat(chat.CHAT_TYPE_INFO,L(text))
return 1
return _command(self,line)
game.GameWindow.BINARY_ServerCommand_Run=Command
)PY";
+2
View File
@@ -1018,6 +1018,7 @@ namespace PythonBoot
#include "ArmorShapesScript.inc"
#include "SashScript.inc"
#include "MountScript.inc"
#include "CostumeAttrScript.inc"
static void install_script_module(const char* c_szModule, const char* c_szScript)
{
@@ -1104,6 +1105,7 @@ bool RunMainScript(const char* lpCmdLine, std::string* error)
install_script_module("mt_shapes", c_szArmorShapesScript);
install_script_module("mt_sash", c_szSashScript);
install_script_module("mt_mount", c_szMountScript);
install_script_module("mt_costume_attr", c_szCostumeAttrScript);
if (g_touch_input)
install_script_module("mt_mobile_hud", c_szMobileHUDScript);
}
+2 -1
View File
@@ -188,7 +188,8 @@ class SwitchbotWindow(ui.Window):
vnum=player.GetItemIndex(player.INVENTORY,cell)
if not vnum:continue
item.SelectItem(vnum);kind=item.GetItemType()
if kind==item.ITEM_TYPE_USE and item.GetItemSubType()==USE_CHANGE_ATTRIBUTE:
# 54001-54267 with a value2 mask are AVA2 costume enchants (mt_costume_attr), not switchers.
if kind==item.ITEM_TYPE_USE and item.GetItemSubType()==USE_CHANGE_ATTRIBUTE and not (54001<=vnum<=54267 and item.GetValue(2)):
scrolls[vnum]=scrolls.get(vnum,0)+player.GetItemCount(player.INVENTORY,cell)
elif kind in (item.ITEM_TYPE_WEAPON,item.ITEM_TYPE_ARMOR) and any(player.GetItemAttribute(player.INVENTORY,cell,i)[0] for i in range(5)):
items.append((cell,vnum))