Files
metin2-client/tests/port/port_python_ui_modules_test.cpp
T
shenandshen 18d9c89af8 feat: implement offline shop and private shop search client subsystems (Stage 5 Part 2)
- Enable ENABLE_OFFLINESHOP_SYSTEM and ENABLE_SHOP_SEARCH_SYSTEM in Locale_inc.h
- Add CG57, CG58, CG143, GC47, GC48, GC156 packets and subheaders in Packet.h
- Implement PythonShop offline shop item/stock/money methods and Python bindings
- Implement PythonNetworkStream offline shop packet sending and receiving handlers
- Port PythonPrivateShopSearch and export privateShopSearch Python module
- Add PythonUtils PyTuple_GetLongLong for 64-bit yang input parsing
- Add Python UI module test assertions covering offline shop and search APIs
2026-10-20 03:38:34 -07:00

155 lines
5.9 KiB
C++

#include "EterPythonLib/StdAfx.h"
#include "EterPythonLib/PythonWindowManager.h"
#include "ScriptLib/PythonLauncher.h"
#include "UserInterface/StdAfx.h"
extern void initapp();
extern void initPlayer();
extern void initItem();
extern void initchrmgr();
extern void initnet();
extern void initshop();
extern void initprivateShopSearch();
#include "UserInterface/PythonPlayer.h"
#include "UserInterface/PythonShop.h"
#include "UserInterface/PythonPrivateShopSearch.h"
#include <cassert>
#include "../../src/platform/ScriptLib/PythonHost.h"
#include <cstdio>
#include <string>
int main(int argc, char** argv)
{
const std::string stdlib = argc > 1 ? argv[1] : PythonHost::DefaultStdLibPath();
PythonHost::Configure();
CPythonLauncher launcher;
if (!launcher.Create())
return 1;
std::string error;
if (!PythonHost::InstallStdLib(stdlib.c_str(), &error))
{
std::fprintf(stderr, "InstallStdLib: %s\n", error.c_str());
return 1;
}
{
UI::CWindowManager manager;
initgrp();
initgrpImage();
initgrpText();
initgrpThing();
initwndMgr();
initapp();
initItem();
initchrmgr();
initnet();
CPythonPlayer player;
initPlayer();
CPythonShop shop;
initshop();
CPythonPrivateShopSearch privateShopSearch;
initprivateShopSearch();
CPythonPlayer::Instance().SetGold64(123456789012345LL);
assert(CPythonPlayer::Instance().GetGold64() == 123456789012345LL);
assert(CPythonPlayer::Instance().GetStatus(POINT_GOLD) == 2000000000);
if (!launcher.RunLine(
"import player, item, chrmgr, app\n"
"gold = player.GetElk()\n"
"assert gold == 123456789012345L, 'GetElk mismatch: %r' % gold\n"
"assert player.GetGold64() == 123456789012345L\n"
"def _fmt(v):\n"
" if v >= 1000000000000: return '%.2f T' % (float(v)/1000000000000.0)\n"
" elif v >= 1000000000: return '%.2f B' % (float(v)/1000000000.0)\n"
" return format(int(v), ',')\n"
"assert _fmt(gold) == '123.46 T'\n"
"assert _fmt(5200000000L) == '5.20 B'\n"
"assert _fmt(1234567) == '1,234,567'\n"
"assert item.COSTUME_SLOT_WEAPON == player.COSTUME_SLOT_WEAPON\n"
"assert item.COSTUME_SLOT_NEW_SASH == player.COSTUME_SLOT_NEW_SASH\n"
"assert item.SHINING_SLOT_WEAPON == player.SHINING_SLOT_WEAPON\n"
"assert item.SHINING_SLOT_ARMOR == player.SHINING_SLOT_ARMOR\n"
"assert item.SHINING_SLOT_SPECIAL == player.SHINING_SLOT_SPECIAL\n"
"assert player.IsCostumeSlot(player.COSTUME_SLOT_WEAPON) == 1\n"
"assert player.IsCostumeSlot(player.COSTUME_SLOT_NEW_SASH) == 1\n"
"assert player.IsCostumeSlot(player.SHINING_SLOT_WEAPON) == 1\n"
"assert player.IsCostumeSlot(player.SHINING_SLOT_ARMOR) == 1\n"
"assert player.IsCostumeSlot(player.SHINING_SLOT_SPECIAL) == 1\n"
"assert item.COSTUME_TYPE_WEAPON == 5\n"
"assert item.COSTUME_TYPE_NEW_SASH == 6\n"
"assert item.ITEM_TYPE_SHINING == 35\n"
"assert item.SHINING_WEAPON == 0\n"
"assert chrmgr.EFFECT_SHINING_WEAPON >= 0\n"
"assert app.ENABLE_NEW_PET_SYSTEM == 1\n"
"assert item.ITEM_TYPE_PET == 37\n"
"assert item.EQUIPMENT_OLDPET == item.COSTUME_SLOT_PET\n"
"assert item.EQUIPMENT_PET == item.PET_SLOT\n"
"assert item.PET_LEVELABLE == 0\n"
"assert item.PET_EGG == 1\n"
"assert item.PET_PROTEIN == 3\n"
"assert item.PET_DEW == 5\n"
"assert item.PET_SKILL == 6\n"
"assert item.PET_SKILL_DEL_BOOK == 11\n"
"assert item.PET_SKILL_ALL_DEL_BOOK == 12\n"
"assert app.ENABLE_ATTR_6TH_7TH == 1\n"
"assert app.BL_67_ATTR == 1\n"
"assert player.ON_TOP_WND_ATTR_67 == 7\n"
"assert player.ON_TOP_WND_NONE == 0\n"
"assert app.ENABLE_SPECIAL_STORAGE == 1\n"
"assert player.SWITCHBOT == 7\n"
"assert player.UPGRADE_INVENTORY == 8\n"
"assert player.BOOK_INVENTORY == 9\n"
"assert player.STONE_INVENTORY == 10\n"
"assert player.CHANGE_INVENTORY == 11\n"
"assert player.COSTUME_INVENTORY == 12\n"
"assert player.SLOT_TYPE_UPGRADE_INVENTORY > 0\n"
"assert player.SLOT_TYPE_BOOK_INVENTORY > 0\n"
"assert player.SLOT_TYPE_STONE_INVENTORY > 0\n"
"assert player.SLOT_TYPE_CHANGE_INVENTORY > 0\n"
"assert player.SLOT_TYPE_COSTUME_INVENTORY > 0\n"
"assert player.SPECIAL_PAGE_SIZE == 45\n"
"assert player.SPECIAL_PAGE_COUNT == 4\n"
"assert player.SPECIAL_SLOT_COUNT == 180\n"
"assert hasattr(player, 'GetItemCountByTT')\n"
"import net\n"
"assert hasattr(net, 'Send67AttrPacket')\n"
"assert hasattr(net, 'Send67AttrClosePacket')\n"
"assert app.ENABLE_OFFLINESHOP_SYSTEM == 1\n"
"assert app.ENABLE_SHOP_SEARCH_SYSTEM == 1\n"
"import shop\n"
"assert shop.OFFLINE_SHOP_SLOT_COUNT == 80\n"
"assert hasattr(shop, 'IsOfflineShop')\n"
"assert hasattr(shop, 'GetOfflineShopItemID')\n"
"assert hasattr(shop, 'GetOfflineShopItemCount')\n"
"assert hasattr(shop, 'GetOfflineShopItemPrice')\n"
"assert hasattr(shop, 'GetCurrentOfflineShopMoney')\n"
"assert hasattr(shop, 'HasOfflineShop')\n"
"assert hasattr(shop, 'GetShopFlag')\n"
"import privateShopSearch\n"
"assert hasattr(privateShopSearch, 'GetItemCount')\n"
"assert hasattr(privateShopSearch, 'GetSearchItemPrice')\n"
"assert hasattr(privateShopSearch, 'ClearSearchItems')\n"
"assert privateShopSearch.GetItemCount() == 0\n"
"assert hasattr(net, 'SendOfflineShopEndPacket')\n"
"assert hasattr(net, 'SendOfflineShopBuyPacket')\n"
"assert hasattr(net, 'SendAddOfflineShopItem')\n"
"assert hasattr(net, 'SendRemoveOfflineShopItem')\n"
"assert hasattr(net, 'SendOpenShopSlot')\n"
"assert hasattr(net, 'SendPrivateShopSearchInfo')\n"
))
return 1;
if (!launcher.RunLine("import wndMgr, grp, grpImage, grpText, grpThing, app"))
return 1;
if (!launcher.RunLine(
"class Handler: pass\n"
"window = wndMgr.Register(Handler(), 'UI')\n"
"assert window > 0\n"
"wndMgr.SetName(window, 'roundtrip')\n"
"wndMgr.SetWindowSize(window, 100, 50)\n"
"assert wndMgr.GetWindowWidth(window) == 100\n"
"wndMgr.Destroy(window)\n"))
return 1;
manager.Update();
}
launcher.Clear();
return 0;
}