Files
metin2-server/tests/features/test_dragonsoul_alchemy.py
T
shenandshen a7152750fb feat: complete Stage 6 item shop, durable point queue, Gaya market, and alchemy parity
- Implement durable point drop intent journal on disk with fsync before network send
- Fix DB point settlement day by fixing CURDATE() on initial account row lock within transaction
- Implement Gaya market subsystem (port_gaya.cpp/h, 27 slots, 55 items, filesystem persistence, /gem command)
- Add POINT_GEM (248) to CHARACTER and support 39063 / 39064 right-click usage
- Fix treasure key (77921~77923) and box (77918~77920) stack decrement in char_item.cpp
- Verify Dragon Soul recharge items 100001 / 100002 and holly bean 100500 DoRefineStrength
- Add 8 verified products (144, 145, 149, 233, 234, 240, 241, 242) to verified-products.json (count: 57)
- Add comprehensive test suites for durable queue, Gaya market, key stacks, and dragon soul alchemy
2026-10-20 04:53:49 -07:00

168 lines
8.0 KiB
Python

#!/usr/bin/env python3
"""Verify Dragon Soul / Alchemy mechanics for items 100001, 100002, 100500."""
from pathlib import Path
import re
import unittest
ROOT = Path(__file__).resolve().parents[2]
class DragonSoulAlchemyTest(unittest.TestCase):
def test_item_proto_definitions(self):
"""Verify item types, sub-types, and values from item_proto sources."""
proto_file = (
ROOT / '..' / 'AVA2' / '3. Source BIN' / 'Tools' / 'DumpProto' / 'Release' / 'item_proto.txt'
)
if not proto_file.exists():
proto_file = ROOT / '..' / 'metin2-client' / 'build' / 'wiki-source' / 'item_proto.txt'
self.assertTrue(proto_file.exists(), "item_proto.txt must exist")
lines = proto_file.read_text(encoding='latin1').splitlines()
protos = {}
for line in lines:
parts = line.split('\t')
if len(parts) >= 4 and parts[0] in ('100001', '100002', '100500'):
protos[parts[0]] = parts
# 100001: USE_TIME_CHARGE_PER, Value0 = 50 (%)
self.assertIn('100001', protos)
p100001 = protos['100001']
self.assertEqual(p100001[2], 'ITEM_USE')
self.assertEqual(p100001[3], 'USE_TIME_CHARGE_PER')
# Value0 index in TSV is typically 24
self.assertIn('50', p100001)
# 100002: USE_TIME_CHARGE_FIX, Value0 = 86400 (24h)
if '100002' in protos:
p100002 = protos['100002']
self.assertEqual(p100002[2], 'ITEM_USE')
self.assertEqual(p100002[3], 'USE_TIME_CHARGE_FIX')
self.assertIn('86400', p100002)
# 100500: MATERIAL_DS_REFINE_HOLLY
if '100500' in protos:
p100500 = protos['100500']
self.assertEqual(p100500[2], 'ITEM_MATERIAL')
self.assertEqual(p100500[3], 'MATERIAL_DS_REFINE_HOLLY')
def test_dragonsoul_time_charge_logic_char_item(self):
"""Verify char_item.cpp correctly handles USE_TIME_CHARGE_PER and USE_TIME_CHARGE_FIX."""
source = (ROOT / 'src/server/game/src/char_item.cpp').read_text(encoding='latin1')
# USE_TIME_CHARGE_PER block
self.assertIn('case USE_TIME_CHARGE_PER:', source)
per_block = source.split('case USE_TIME_CHARGE_PER:', 1)[1].split('break;', 1)[0]
self.assertIn('pDestItem->IsDragonSoul()', per_block)
self.assertIn('pDestItem->GiveMoreTime_Per', per_block)
self.assertIn('item->SetCount(item->GetCount() - 1);', per_block)
# USE_TIME_CHARGE_FIX block
self.assertIn('case USE_TIME_CHARGE_FIX:', source)
fix_block = source.split('case USE_TIME_CHARGE_FIX:', 1)[1].split('break;', 1)[0]
self.assertIn('pDestItem->IsDragonSoul()', fix_block)
self.assertIn('pDestItem->GiveMoreTime_Fix', fix_block)
self.assertIn('item->SetCount(item->GetCount() - 1);', fix_block)
def test_item_give_more_time_implementation(self):
"""Verify CItem::GiveMoreTime_Per and CItem::GiveMoreTime_Fix logic in item.cpp."""
source = (ROOT / 'src/server/game/src/item.cpp').read_text(encoding='latin1')
# Verify GiveMoreTime_Per
self.assertIn('int CItem::GiveMoreTime_Per(float fPercent)', source)
per_code = source.split('int CItem::GiveMoreTime_Per(float fPercent)', 1)[1].split('int CItem::GiveMoreTime_Fix', 1)[0]
self.assertIn('DWORD duration = DSManager::instance().GetDuration(this);', per_code)
self.assertIn('int remain_sec = GetSocket(ITEM_SOCKET_REMAIN_SEC);', per_code)
self.assertIn('int given_time = fPercent * duration / 100;', per_code)
self.assertIn('if (remain_sec == duration)', per_code)
self.assertIn('SetSocket(ITEM_SOCKET_REMAIN_SEC, duration);', per_code)
# Verify GiveMoreTime_Fix
self.assertIn('int CItem::GiveMoreTime_Fix(DWORD dwTime)', source)
fix_code = source.split('int CItem::GiveMoreTime_Fix(DWORD dwTime)', 1)[1].split('int\tCItem::GetDuration()', 1)[0]
self.assertIn('if (remain_sec == duration)', fix_code)
self.assertIn('SetSocket(ITEM_SOCKET_REMAIN_SEC, duration);', fix_code)
def test_time_charge_simulation(self):
"""Simulate GiveMoreTime_Per and GiveMoreTime_Fix numerical bounds."""
duration = 86400 # 24 hours
# Simulated GiveMoreTime_Per (50%)
def give_more_time_per(remain_sec, percent=50.0):
given = int(percent * duration / 100)
if remain_sec == duration:
return 0, remain_sec
if given + remain_sec >= duration:
return duration - remain_sec, duration
return given, remain_sec + given
# 1. 50% charge when remaining is 0: gives 43200s, total 43200s
added, new_remain = give_more_time_per(0, 50.0)
self.assertEqual(added, 43200)
self.assertEqual(new_remain, 43200)
# 2. 50% charge when remaining is 60000s: capped at 86400, gives 26400s
added, new_remain = give_more_time_per(60000, 50.0)
self.assertEqual(added, 26400)
self.assertEqual(new_remain, 86400)
# 3. Charge when already full: gives 0
added, new_remain = give_more_time_per(86400, 50.0)
self.assertEqual(added, 0)
self.assertEqual(new_remain, 86400)
# Simulated GiveMoreTime_Fix (86400s)
def give_more_time_fix(remain_sec, fix_time=86400):
if remain_sec == duration:
return 0, remain_sec
if fix_time + remain_sec >= duration:
return duration - remain_sec, duration
return fix_time, remain_sec + fix_time
# 1. Fixed charge 86400s when remaining is 1000s: capped at 86400, gives 85400s
added, new_remain = give_more_time_fix(1000, 86400)
self.assertEqual(added, 85400)
self.assertEqual(new_remain, 86400)
def test_dragon_bean_100500_refine_strength_mechanics(self):
"""Verify 100500 MATERIAL_DS_REFINE_HOLLY in DSManager::DoRefineStrength."""
source = (ROOT / 'src/server/game/src/DragonSoul.cpp').read_text(encoding='latin1')
# Check IsDragonSoulRefineMaterial recognizes MATERIAL_DS_REFINE_HOLLY
mat_check = source.split('bool IsDragonSoulRefineMaterial(LPITEM pItem)', 1)[1].split('bool DSManager::DoRefineStrength', 1)[0]
self.assertIn('MATERIAL_DS_REFINE_HOLLY', mat_check)
# Check DoRefineStrength handling of refine stone and fee
refine_func = source.split('bool DSManager::DoRefineStrength', 1)[1].split('SendRefineResultPacket(ch, bSubHeader,', 1)[0]
# Fee deduction before roll
self.assertIn('if (ch->GetGold() < fee)', refine_func)
self.assertIn('ch->PointChange(POINT_GOLD, -fee);', refine_func)
# Material stack decrement in both branches
success_branch = refine_func.split('if (fnumber(0.f, 100.f) <= fProb)', 1)[1].split('else', 1)[0]
fail_branch = refine_func.split('else', 1)[1]
self.assertIn('pRefineStone->SetCount(pRefineStone->GetCount() - 1);', success_branch)
self.assertIn('pRefineStone->SetCount(pRefineStone->GetCount() - 1);', fail_branch)
def test_dragon_soul_table_holly_values(self):
"""Verify RefineStrengthTables configures MATERIAL_DS_REFINE_HOLLY fee and probs."""
table_path = ROOT / '..' / '40250' / 'Server Client TMP4' / 'Server' / 'metin2' / 'server' / 'share' / 'locale' / 'english' / 'dragon_soul_table.txt'
self.assertTrue(table_path.exists(), "dragon_soul_table.txt must exist")
content = table_path.read_text(encoding='latin1')
match = re.search(r'MATERIAL_DS_REFINE_HOLLY\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)', content)
self.assertIsNotNone(match, "MATERIAL_DS_REFINE_HOLLY table line must exist")
fee = int(match.group(1))
probs = [int(match.group(i)) for i in range(2, 8)]
# Holly bean fee = 30000 gold
self.assertEqual(fee, 30000)
# Probabilities for strength 0 to 5: 100%, 90%, 80%, 60%, 40%, 30%
self.assertEqual(probs, [100, 90, 80, 60, 40, 30])
if __name__ == '__main__':
unittest.main()