AVA2 unlock P8: new rings client (mt_rings, ring slots, item import)

ITEM_TYPE_RINGS / c_Equipment_Rings1/2, mt_rings adds the two slots beside
the shoes, the accessory tooltip and the drill / jewel / switcher / adder drop
targets; make_items imports the four +0..+9 ring chains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-16 14:40:40 +09:00
co-authored by Claude Opus 5.5
parent b9af78ef64
commit 8d01a7a754
7 changed files with 165 additions and 6 deletions
+2
View File
@@ -1020,6 +1020,7 @@ namespace PythonBoot
#include "MountScript.inc"
#include "CostumeAttrScript.inc"
#include "PendantScript.inc"
#include "RingsScript.inc"
static void install_script_module(const char* c_szModule, const char* c_szScript)
{
@@ -1108,6 +1109,7 @@ bool RunMainScript(const char* lpCmdLine, std::string* error)
install_script_module("mt_mount", c_szMountScript);
install_script_module("mt_costume_attr", c_szCostumeAttrScript);
install_script_module("mt_pendant", c_szPendantScript);
install_script_module("mt_rings", c_szRingsScript);
if (g_touch_input)
install_script_module("mt_mobile_hud", c_szMobileHUDScript);
}
+139
View File
@@ -0,0 +1,139 @@
// PORT: AVA2 new rings (ENABLE_NEW_RINGS), as module mt_rings. Rings are ITEM_TYPE_RINGS (36) worn in
// c_Equipment_Rings1/2 (server WEAR_RINGS_1/2, metin2-server port_rings.cpp). They are socket accessories with
// their own attribute pool, reached through the 40250 switchers / adders. This script adds the two slots to the
// inventory's equipment panel (the free spots beside the shoes on equipment_base, where AVA2 has them too), gives
// rings the accessory tooltip of AVA2 uitooltip.py (limits, applies, attributes, jewel sockets) and marks them as
// drop targets of the drill / jewel / switcher / adder items the server accepts.
static const char c_szRingsScript[] = R"PY(# -*- coding: utf-8 -*-
import item
import player
import uiInventory
import uiToolTip
import ui
# EquipmentSlot coordinates (the shoes are at 39,145).
SLOTS=((item.EQUIPMENT_RINGS1,(2,145)),(item.EQUIPMENT_RINGS2,(75,145)))
# AVA2 CItem::CanPutInto: ring family (vnum / 10 * 10) -> jewel.
JEWEL={19220:50634,19500:50635,19520:50636,19540:50637,19560:50638}
ACCESSORY_SOCKET_MAX_SIZE=3
def IsRing(vnum):
if not vnum:return False
item.SelectItem(vnum)
return item.GetItemType()==item.ITEM_TYPE_RINGS
def MaterialVnum(vnum):
return JEWEL.get(vnum/10*10,0)
def FindChild(node,name):
if node.get("name")==name:return node
for child in node.get("children",()):
found=FindChild(child,name)
if found:return found
return None
def PatchInventoryWindow(window):
base=FindChild(window,"Equipment_Base");slot=FindChild(window,"EquipmentSlot")
if not base or not slot:return
frames=[];cells=[]
for i,(index,(x,y)) in enumerate(SLOTS):
frames.append({"name":"RingSlotBase%d"%i,"type":"image","x":slot["x"]+x,"y":slot["y"]+y,"image":"d:/ymir work/ui/public/Slot_Base.sub"})
cells.append({"index":index,"x":x,"y":y,"width":32,"height":32})
base["children"]=tuple(frames)+tuple(base.get("children",()))
slot["slot"]=tuple(slot["slot"])+tuple(cells)
_execfile=ui.execfile
def ExecFile(fileName,dict):
_execfile(fileName,dict)
name=fileName.replace("\\","/").split("/")[-1].lower()
if name=="inventorywindow.py" and "window" in dict:PatchInventoryWindow(dict["window"])
ui.execfile=ExecFile
_refreshEquip=uiInventory.InventoryWindow.RefreshEquipSlotWindow
def RefreshEquipSlotWindow(self):
_refreshEquip(self)
for index,_ in SLOTS:self.wndEquip.SetItemSlot(index,player.GetItemIndex(index),0)
self.wndEquip.RefreshSlot()
uiInventory.InventoryWindow.RefreshEquipSlotWindow=RefreshEquipSlotWindow
def AttrCount(slot):
return len([1 for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM) if player.GetItemAttribute(slot,i)[0]])
# 40250's __CanPutAccessorySocket / __CanAddAccessorySocket / __CanChangeItemAttrList / __CanAddItemAttr only take
# weapons, armor and the armor accessories; everything else (refine scrolls, ...) keeps the 40250 checks.
RING_USE_TYPES=("USE_ADD_ACCESSORY_SOCKET","USE_PUT_INTO_ACCESSORY_SOCKET","USE_CHANGE_ATTRIBUTE","USE_ADD_ATTRIBUTE","USE_ADD_ATTRIBUTE2")
def CanUseOnRing(srcItemVNum,dstSlotPos,useType):
dstItemVNum=player.GetItemIndex(dstSlotPos)
# the server refuses these items on a worn item ("Fix" in CHARACTER::UseItemEx)
if player.IsEquipmentSlot(dstSlotPos):return False
cur=player.GetItemMetinSocket(dstSlotPos,0);end=player.GetItemMetinSocket(dstSlotPos,1)
if useType=="USE_ADD_ACCESSORY_SOCKET":return end<ACCESSORY_SOCKET_MAX_SIZE
if useType=="USE_PUT_INTO_ACCESSORY_SOCKET":return srcItemVNum==MaterialVnum(dstItemVNum) and cur<end
# 71151 / 76023 / 71152 / 76024 are for weapons / armor
if srcItemVNum in (71151,76023,71152,76024):return False
count=AttrCount(dstSlotPos)
if useType=="USE_CHANGE_ATTRIBUTE":return count>0
if useType=="USE_ADD_ATTRIBUTE":return count<4
if useType=="USE_ADD_ATTRIBUTE2":return count==4
return False
_canUse=uiInventory.InventoryWindow._InventoryWindow__CanUseSrcItemToDstItem
def CanUseSrcItemToDstItem(self,srcItemVNum,srcSlotPos,dstSlotPos):
useType=item.GetUseType(srcItemVNum)
if srcSlotPos!=dstSlotPos and useType in RING_USE_TYPES and IsRing(player.GetItemIndex(dstSlotPos)):
return CanUseOnRing(srcItemVNum,dstSlotPos,useType)
return _canUse(self,srcItemVNum,srcSlotPos,dstSlotPos)
uiInventory.InventoryWindow._InventoryWindow__CanUseSrcItemToDstItem=CanUseSrcItemToDstItem
# --- tooltip (AVA2 uitooltip.py ITEM_TYPE_RINGS branch, without rarity) ---------------------------------------
# A ring falls into the generic branch of ItemToolTip.AddItemData, which only appends the limits; the rest of the
# accessory tooltip follows them.
Tip=uiToolTip.ItemToolTip
_addItemData=Tip.AddItemData
_appendLimit=Tip._ItemToolTip__AppendLimitInformation
def AddItemData(self,itemVnum,metinSlot,attrSlot=0,flags=0,unbindTime=0):
self.mtRing=(itemVnum,metinSlot,attrSlot) if IsRing(itemVnum) else None
try:
return _addItemData(self,itemVnum,metinSlot,attrSlot,flags,unbindTime)
finally:
self.mtRing=None
def AppendLimitInformation(self):
_appendLimit(self)
state=getattr(self,'mtRing',None)
if not state:return
self.mtRing=None
itemVnum,metinSlot,attrSlot=state
item.SelectItem(itemVnum)
self._ItemToolTip__AppendAffectInformation()
self._ItemToolTip__AppendAttributeInformation(attrSlot)
item.SelectItem(itemVnum)
self.AppendWearableInformation()
if metinSlot:
item.SelectItem(itemVnum)
self._ItemToolTip__AppendAccessoryMetinSlotInfo(metinSlot,MaterialVnum(itemVnum))
item.SelectItem(itemVnum)
Tip.AddItemData=AddItemData
Tip._ItemToolTip__AppendLimitInformation=AppendLimitInformation
)PY";