Port the AVA2 switchbot window and switchbot module
PythonSwitchbot + PythonNetworkStreamPhaseGameSwitchbot from AVA2 (CG/GC 171, SWITCHBOT window 7, SLOT_TYPE_SWITCHBOT), uiswitchbot.py verbatim in SwitchbotScript.inc plus its ENABLE_SWITCHBOT glue (tooltip, mouse/inventory drag-back, interface/game hooks, zh strings, server switchbot_* messages). Entry is the minimap 洗练 button; F9 stays with auto-hunt. The client version timestamp is now "mt20261016" so the server enables the switchbot. 50348/50349 no longer open the window. Adds docs/AVA2-PARITY-PLAN.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e70a6abf7a
commit
fc98e6e2b4
@@ -93,10 +93,6 @@ def UseItemSlot(self,slot):
|
||||
import mt_battlepass
|
||||
if mt_battlepass.g_window:mt_battlepass.g_window.OfferTicket(cell,vnum)
|
||||
return
|
||||
if vnum in (50348,50349):
|
||||
import mt_switchbot
|
||||
if mt_switchbot.g_window:mt_switchbot.g_window.Open()
|
||||
return
|
||||
return _use(self,slot)
|
||||
|
||||
uiInventory.InventoryWindow.UseItemSlot=UseItemSlot
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "UserInterface/PythonMessenger.h"
|
||||
#include "UserInterface/PythonSafeBox.h"
|
||||
#include "UserInterface/PythonSash.h"
|
||||
#include "UserInterface/PythonSwitchbot.h"
|
||||
#include "UserInterface/PythonGuild.h"
|
||||
#include "UserInterface/MarkManager.h"
|
||||
#include "UserInterface/GuildMarkDownloader.h"
|
||||
@@ -158,6 +159,7 @@ struct GameSingletons
|
||||
CPythonMessenger pyManager;
|
||||
CPythonSafeBox pySafeBox;
|
||||
CPythonSash pySash; // PORT: AVA2 sash
|
||||
CPythonSwitchbot pySwitchbot; // PORT: AVA2 switchbot
|
||||
CPythonGuild pyGuild;
|
||||
CGuildMarkManager kGuildMarkManager;
|
||||
CGuildMarkDownloader kGuildMarkDownloader;
|
||||
@@ -924,6 +926,7 @@ bool run_main_script_body(const char* lpCmdLine, std::string* error)
|
||||
initMessenger();
|
||||
initsafebox();
|
||||
initSash();
|
||||
initSwitchbot();
|
||||
initguild();
|
||||
initServerStateChecker();
|
||||
initRenderTarget(); // PORT: AVA2 model preview
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -157,6 +157,7 @@ enum ESlotType
|
||||
SLOT_TYPE_PRIVATE_SHOP,
|
||||
SLOT_TYPE_MALL,
|
||||
SLOT_TYPE_DRAGON_SOUL_INVENTORY,
|
||||
SLOT_TYPE_SWITCHBOT, // PORT: AVA2 switchbot
|
||||
SLOT_TYPE_MAX,
|
||||
};
|
||||
|
||||
@@ -169,10 +170,12 @@ enum EWindows
|
||||
MALL,
|
||||
DRAGON_SOUL_INVENTORY,
|
||||
GROUND, // NOTE: 2013년 2월5일 현재까지 unused.. 왜 있는거지???
|
||||
SWITCHBOT, // PORT: AVA2 switchbot; 7 on the wire = metin2-server EWindows SWITCHBOT
|
||||
BELT_INVENTORY, // NOTE: W2.1 버전에 새로 추가되는 벨트 슬롯 아이템이 제공하는 벨트 인벤토리
|
||||
|
||||
WINDOW_TYPE_MAX,
|
||||
};
|
||||
static_assert(SWITCHBOT == 7, "SWITCHBOT window must match the server");
|
||||
|
||||
enum EDSInventoryMaxNum
|
||||
{
|
||||
@@ -180,6 +183,32 @@ enum EDSInventoryMaxNum
|
||||
DS_REFINE_WINDOW_MAX_NUM = 15,
|
||||
};
|
||||
|
||||
// PORT: AVA2 switchbot (GameType.h ENABLE_SWITCHBOT). Attribute sets as the server numbers them: the 40250
|
||||
// item_attr sets, then the pseudo sets for new rings and talismans (metin2-server port_switchbot.cpp).
|
||||
enum ESwitchbotValues
|
||||
{
|
||||
SWITCHBOT_SLOT_COUNT = 6,
|
||||
SWITCHBOT_SLOT_COUNT_REAL = 5,
|
||||
|
||||
SWITCHBOT_ALTERNATIVE_COUNT = 2,
|
||||
MAX_NORM_ATTR_NUM = 5,
|
||||
};
|
||||
|
||||
enum EAttributeSet
|
||||
{
|
||||
ATTRIBUTE_SET_WEAPON,
|
||||
ATTRIBUTE_SET_BODY,
|
||||
ATTRIBUTE_SET_WRIST,
|
||||
ATTRIBUTE_SET_FOOTS,
|
||||
ATTRIBUTE_SET_NECK,
|
||||
ATTRIBUTE_SET_HEAD,
|
||||
ATTRIBUTE_SET_SHIELD,
|
||||
ATTRIBUTE_SET_EAR,
|
||||
ATTRIBUTE_SET_NEW_RINGS,
|
||||
ATTRIBUTE_SET_PENDANT,
|
||||
ATTRIBUTE_SET_MAX_NUM,
|
||||
};
|
||||
|
||||
#pragma pack (push, 1)
|
||||
#define WORD_MAX 0xffff
|
||||
|
||||
@@ -220,6 +249,9 @@ typedef struct SItemPos
|
||||
case DRAGON_SOUL_INVENTORY:
|
||||
return cell < (DS_INVENTORY_MAX_NUM);
|
||||
break;
|
||||
case SWITCHBOT:
|
||||
return cell < SWITCHBOT_SLOT_COUNT;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -155,6 +155,7 @@ enum
|
||||
HEADER_CG_DRAGON_SOUL_REFINE = 205,
|
||||
HEADER_CG_STATE_CHECKER = 206,
|
||||
HEADER_CG_SASH = 211, // PORT: AVA2 sash (metin2-server FEATURE-AVA2-UNLOCK P4)
|
||||
HEADER_CG_SWITCHBOT = 171, // PORT: AVA2 switchbot (metin2-server FEATURE-SWITCHBOT)
|
||||
|
||||
#ifdef __AUCTION__
|
||||
HEADER_CG_AUCTION_CMD = 205,
|
||||
@@ -360,6 +361,7 @@ enum
|
||||
HEADER_GC_DRAGON_SOUL_REFINE = 209,
|
||||
HEADER_GC_RESPOND_CHANNELSTATUS = 210,
|
||||
HEADER_GC_SASH = 215, // PORT: AVA2 sash
|
||||
HEADER_GC_SWITCHBOT = 171, // PORT: AVA2 switchbot, DYNAMIC_SIZE_PACKET
|
||||
|
||||
HEADER_GC_KEY_AGREEMENT_COMPLETED = 0xfa, // _IMPROVED_PACKET_ENCRYPTION_
|
||||
HEADER_GC_KEY_AGREEMENT = 0xfb, // _IMPROVED_PACKET_ENCRYPTION_
|
||||
@@ -2865,4 +2867,47 @@ typedef struct SSashResult
|
||||
DWORD dwMaxAbs;
|
||||
} TSashResult;
|
||||
|
||||
// PORT: AVA2 switchbot (ENABLE_SWITCHBOT), AVA2 Packet.h order. CG/GC: header, size, subheader, slot, then the
|
||||
// subheader's payload; the item update carries our 3 sockets and 7 attributes like TPacketGCItemSet.
|
||||
enum ECGSwitchbotSubheader
|
||||
{
|
||||
SUBHEADER_CG_SWITCHBOT_START,
|
||||
SUBHEADER_CG_SWITCHBOT_STOP,
|
||||
};
|
||||
|
||||
struct TPacketCGSwitchbot
|
||||
{
|
||||
BYTE header;
|
||||
int size;
|
||||
BYTE subheader;
|
||||
BYTE slot;
|
||||
};
|
||||
|
||||
enum EGCSwitchbotSubheader
|
||||
{
|
||||
SUBHEADER_GC_SWITCHBOT_UPDATE,
|
||||
SUBHEADER_GC_SWITCHBOT_UPDATE_ITEM,
|
||||
SUBHEADER_GC_SWITCHBOT_SEND_ATTRIBUTE_INFORMATION,
|
||||
};
|
||||
|
||||
struct TPacketGCSwitchbot
|
||||
{
|
||||
BYTE header;
|
||||
int size;
|
||||
BYTE subheader;
|
||||
BYTE slot;
|
||||
};
|
||||
|
||||
struct TSwitchbotUpdateItem
|
||||
{
|
||||
BYTE slot;
|
||||
DWORD vnum;
|
||||
WORD count;
|
||||
LONG alSockets[ITEM_SOCKET_SLOT_MAX_NUM]; // PORT: LONG, the 32-bit Win32 long
|
||||
TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_SLOT_MAX_NUM];
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
static_assert(sizeof(TPacketCGSwitchbot) == 7 && sizeof(TPacketGCSwitchbot) == 7, "switchbot packet header");
|
||||
static_assert(sizeof(TSwitchbotUpdateItem) == 40, "TSwitchbotUpdateItem");
|
||||
|
||||
@@ -185,6 +185,7 @@ class CMainPacketHeaderMap : public CNetworkPacketHeaderMap
|
||||
Set(HEADER_GC_SPECIFIC_EFFECT, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCSpecificEffect), STATIC_SIZE_PACKET));
|
||||
Set(HEADER_GC_DRAGON_SOUL_REFINE, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCDragonSoulRefine), STATIC_SIZE_PACKET));
|
||||
Set(HEADER_GC_SASH, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketSash), STATIC_SIZE_PACKET)); // PORT: AVA2 sash
|
||||
Set(HEADER_GC_SWITCHBOT, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCSwitchbot), DYNAMIC_SIZE_PACKET)); // PORT: AVA2 switchbot
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "InsultChecker.h"
|
||||
|
||||
#include "Packet.h"
|
||||
#include "PythonSwitchbot.h" // PORT: AVA2 switchbot
|
||||
|
||||
class CInstanceBase;
|
||||
class CNetworkActorManager;
|
||||
@@ -273,6 +274,10 @@ class CPythonNetworkStream : public CNetworkStream, public CSingleton<CPythonNet
|
||||
bool SendSashRemovePacket(BYTE bPos);
|
||||
bool SendSashRefinePacket();
|
||||
|
||||
// PORT: AVA2 switchbot
|
||||
bool SendSwitchbotStartPacket(BYTE slot, std::vector<CPythonSwitchbot::TSwitchbotAttributeAlternativeTable> alternatives);
|
||||
bool SendSwitchbotStopPacket(BYTE slot);
|
||||
|
||||
// Handshake
|
||||
bool RecvHandshakePacket();
|
||||
bool RecvHandshakeOKPacket();
|
||||
@@ -552,6 +557,7 @@ class CPythonNetworkStream : public CNetworkStream, public CSingleton<CPythonNet
|
||||
// 용혼석 관련
|
||||
bool RecvDragonSoulRefine();
|
||||
bool RecvSashPacket(bool bReturn = false); // PORT: AVA2 sash
|
||||
bool RecvSwitchbotPacket(); // PORT: AVA2 switchbot
|
||||
|
||||
// MiniMap Info
|
||||
bool RecvNPCList();
|
||||
|
||||
@@ -634,6 +634,10 @@ void CPythonNetworkStream::GamePhase()
|
||||
ret = RecvSashPacket();
|
||||
break;
|
||||
|
||||
case HEADER_GC_SWITCHBOT: // PORT: AVA2 switchbot
|
||||
ret = RecvSwitchbotPacket();
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = RecvDefaultPacket(header);
|
||||
break;
|
||||
@@ -4184,7 +4188,9 @@ bool CPythonNetworkStream::SendClientVersionPacket()
|
||||
TPacketCGClientVersion kVersionPacket;
|
||||
kVersionPacket.header = HEADER_CG_CLIENT_VERSION;
|
||||
strncpy(kVersionPacket.filename, filename.c_str(), sizeof(kVersionPacket.filename)-1);
|
||||
strncpy(kVersionPacket.timestamp, __TIMESTAMP__, sizeof(kVersionPacket.timestamp)-1);
|
||||
// PORT: protocol date instead of __TIMESTAMP__; the server sends the AVA2 switchbot packets only from
|
||||
// "mt20261016" on (metin2-server port_switchbot.h PORT_SWITCHBOT_CLIENT_VERSION).
|
||||
strncpy(kVersionPacket.timestamp, "mt20261016", sizeof(kVersionPacket.timestamp)-1);
|
||||
|
||||
if (!Send(sizeof(kVersionPacket), &kVersionPacket))
|
||||
Tracef("SendClientReportPacket Error");
|
||||
|
||||
@@ -231,6 +231,13 @@ bool CPythonNetworkStream::RecvItemSetPacket()
|
||||
|
||||
rkPlayer.SetItemData(packet_item_set.Cell, kItemData);
|
||||
|
||||
// PORT: AVA2 switchbot: the switchbot window refreshes itself, the inventory does not change.
|
||||
if (packet_item_set.Cell.window_type == SWITCHBOT)
|
||||
{
|
||||
PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "RefreshSwitchbotWindow", Py_BuildValue("()"));
|
||||
return true;
|
||||
}
|
||||
|
||||
__RefreshInventoryWindow();
|
||||
return true;
|
||||
}
|
||||
@@ -256,6 +263,13 @@ bool CPythonNetworkStream::RecvItemSetPacket2()
|
||||
IAbstractPlayer& rkPlayer=IAbstractPlayer::GetSingleton();
|
||||
rkPlayer.SetItemData(packet_item_set.Cell, kItemData);
|
||||
|
||||
// PORT: AVA2 switchbot: the switchbot window refreshes itself, the inventory does not change.
|
||||
if (packet_item_set.Cell.window_type == SWITCHBOT)
|
||||
{
|
||||
PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "RefreshSwitchbotWindow", Py_BuildValue("()"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (packet_item_set.highlight)
|
||||
PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "BINARY_Highlight_Item", Py_BuildValue("(ii)", packet_item_set.Cell.window_type, packet_item_set.Cell.cell));
|
||||
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
#include "StdAfx.h"
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "PythonSwitchbot.h"
|
||||
#include "AbstractPlayer.h"
|
||||
#include "Packet.h"
|
||||
|
||||
// PORT: AVA2 PythonNetworkStreamPhaseGame.cpp switchbot packets (ENABLE_SWITCHBOT) verbatim.
|
||||
bool CPythonNetworkStream::RecvSwitchbotPacket()
|
||||
{
|
||||
TPacketGCSwitchbot pack;
|
||||
if (!Recv(sizeof(pack), &pack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t packet_size = int(pack.size) - sizeof(TPacketGCSwitchbot);
|
||||
if (pack.subheader == SUBHEADER_GC_SWITCHBOT_UPDATE)
|
||||
{
|
||||
if (packet_size != sizeof(CPythonSwitchbot::TSwitchbotTable))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CPythonSwitchbot::TSwitchbotTable table;
|
||||
if (!Recv(sizeof(table), &table))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CPythonSwitchbot::Instance().Update(table);
|
||||
PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "RefreshSwitchbotWindow", Py_BuildValue("()"));
|
||||
}
|
||||
else if (pack.subheader == SUBHEADER_GC_SWITCHBOT_UPDATE_ITEM)
|
||||
{
|
||||
if (packet_size != sizeof(TSwitchbotUpdateItem))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TSwitchbotUpdateItem update;
|
||||
if (!Recv(sizeof(update), &update))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TItemPos pos(SWITCHBOT, update.slot);
|
||||
|
||||
IAbstractPlayer& rkPlayer = IAbstractPlayer::GetSingleton();
|
||||
rkPlayer.SetItemCount(pos, update.count);
|
||||
|
||||
for (int i = 0; i < ITEM_SOCKET_SLOT_MAX_NUM; ++i)
|
||||
{
|
||||
rkPlayer.SetItemMetinSocket(pos, i, update.alSockets[i]);
|
||||
|
||||
}
|
||||
|
||||
for (int j = 0; j < ITEM_ATTRIBUTE_SLOT_MAX_NUM; ++j)
|
||||
{
|
||||
rkPlayer.SetItemAttribute(pos, j, update.aAttr[j].bType, update.aAttr[j].sValue);
|
||||
}
|
||||
|
||||
PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "RefreshSwitchbotItem", Py_BuildValue("(i)", update.slot));
|
||||
return true;
|
||||
}
|
||||
else if (pack.subheader == SUBHEADER_GC_SWITCHBOT_SEND_ATTRIBUTE_INFORMATION)
|
||||
{
|
||||
CPythonSwitchbot::Instance().ClearAttributeMap();
|
||||
|
||||
size_t table_size = sizeof(CPythonSwitchbot::TSwitchbottAttributeTable);
|
||||
while (packet_size >= table_size)
|
||||
{
|
||||
CPythonSwitchbot::TSwitchbottAttributeTable table;
|
||||
if (!Recv(table_size, &table))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CPythonSwitchbot::Instance().AddAttributeToMap(table);
|
||||
packet_size -= table_size;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPythonNetworkStream::SendSwitchbotStartPacket(BYTE slot, std::vector<CPythonSwitchbot::TSwitchbotAttributeAlternativeTable> alternatives)
|
||||
{
|
||||
TPacketCGSwitchbot pack;
|
||||
pack.header = HEADER_CG_SWITCHBOT;
|
||||
pack.subheader = SUBHEADER_CG_SWITCHBOT_START;
|
||||
pack.size = sizeof(TPacketCGSwitchbot) + sizeof(CPythonSwitchbot::TSwitchbotAttributeAlternativeTable) * SWITCHBOT_ALTERNATIVE_COUNT;
|
||||
pack.slot = slot;
|
||||
|
||||
if (!Send(sizeof(pack), &pack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& it : alternatives)
|
||||
{
|
||||
if (!Send(sizeof(it), &it))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return SendSequence();
|
||||
}
|
||||
|
||||
bool CPythonNetworkStream::SendSwitchbotStopPacket(BYTE slot)
|
||||
{
|
||||
TPacketCGSwitchbot pack;
|
||||
pack.header = HEADER_CG_SWITCHBOT;
|
||||
pack.subheader = SUBHEADER_CG_SWITCHBOT_STOP;
|
||||
pack.size = sizeof(TPacketCGSwitchbot);
|
||||
pack.slot = slot;
|
||||
|
||||
if (!Send(sizeof(pack), &pack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return SendSequence();
|
||||
}
|
||||
@@ -587,6 +587,8 @@ const TItemData * CPythonPlayer::GetItemData(TItemPos Cell) const
|
||||
return &m_playerStatus.aItem[Cell.cell];
|
||||
case DRAGON_SOUL_INVENTORY:
|
||||
return &m_playerStatus.aDSItem[Cell.cell];
|
||||
case SWITCHBOT: // PORT: AVA2 switchbot
|
||||
return &m_playerStatus.aSwitchbotItem[Cell.cell];
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@@ -616,6 +618,9 @@ void CPythonPlayer::SetItemData(TItemPos Cell, const TItemData & c_rkItemInst)
|
||||
case DRAGON_SOUL_INVENTORY:
|
||||
m_playerStatus.aDSItem[Cell.cell] = c_rkItemInst;
|
||||
break;
|
||||
case SWITCHBOT: // PORT: AVA2 switchbot
|
||||
m_playerStatus.aSwitchbotItem[Cell.cell] = c_rkItemInst;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ class CPythonPlayer : public CSingleton<CPythonPlayer>, public IAbstractPlayer
|
||||
{
|
||||
TItemData aItem[c_Inventory_Count];
|
||||
TItemData aDSItem[c_DragonSoul_Inventory_Count];
|
||||
TItemData aSwitchbotItem[SWITCHBOT_SLOT_COUNT]; // PORT: AVA2 switchbot window
|
||||
TQuickSlot aQuickSlot[QUICKSLOT_MAX_NUM];
|
||||
TSkillInstance aSkill[SKILL_MAX_NUM];
|
||||
long m_alPoint[POINT_MAX_NUM];
|
||||
|
||||
@@ -2586,6 +2586,7 @@ void initPlayer()
|
||||
PyModule_AddIntConstant(poModule, "SLOT_TYPE_MALL", SLOT_TYPE_MALL);
|
||||
PyModule_AddIntConstant(poModule, "SLOT_TYPE_EMOTION", SLOT_TYPE_EMOTION);
|
||||
PyModule_AddIntConstant(poModule, "SLOT_TYPE_DRAGON_SOUL_INVENTORY", SLOT_TYPE_DRAGON_SOUL_INVENTORY);
|
||||
PyModule_AddIntConstant(poModule, "SLOT_TYPE_SWITCHBOT", SLOT_TYPE_SWITCHBOT); // PORT: AVA2 switchbot
|
||||
|
||||
PyModule_AddIntConstant(poModule, "RESERVED_WINDOW", RESERVED_WINDOW);
|
||||
PyModule_AddIntConstant(poModule, "INVENTORY", INVENTORY);
|
||||
@@ -2594,6 +2595,7 @@ void initPlayer()
|
||||
PyModule_AddIntConstant(poModule, "MALL", MALL);
|
||||
PyModule_AddIntConstant(poModule, "DRAGON_SOUL_INVENTORY", DRAGON_SOUL_INVENTORY);
|
||||
PyModule_AddIntConstant(poModule, "GROUND", GROUND);
|
||||
PyModule_AddIntConstant(poModule, "SWITCHBOT", SWITCHBOT); // PORT: AVA2 switchbot
|
||||
|
||||
PyModule_AddIntConstant(poModule, "ITEM_MONEY", -1);
|
||||
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
// PORT: AVA2 PythonSwitchbot.cpp (ENABLE_SWITCHBOT) verbatim except memcpy for memcpy_s and the two PORT notes;
|
||||
// the switchbot module is driven by mt_switchbot (ScriptLib/SwitchbotScript.inc).
|
||||
|
||||
#include "PythonSwitchbot.h"
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "PythonPlayer.h"
|
||||
#include "../GameLib/ItemManager.h"
|
||||
|
||||
CPythonSwitchbot::CPythonSwitchbot()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
CPythonSwitchbot::~CPythonSwitchbot()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void CPythonSwitchbot::Initialize()
|
||||
{
|
||||
m_SwitchbotTable = {};
|
||||
m_map_AttributesBySet.clear();
|
||||
}
|
||||
|
||||
void CPythonSwitchbot::Update(const TSwitchbotTable& table)
|
||||
{
|
||||
memcpy(m_SwitchbotTable.active, table.active, sizeof(table.active));
|
||||
memcpy(m_SwitchbotTable.finished, table.finished, sizeof(table.finished));
|
||||
memcpy(m_SwitchbotTable.alternatives, table.alternatives, sizeof(table.alternatives));
|
||||
memcpy(m_SwitchbotTable.items, table.items, sizeof(table.items));
|
||||
m_SwitchbotTable.player_id = table.player_id;
|
||||
}
|
||||
|
||||
void CPythonSwitchbot::SetAttribute(BYTE slot, BYTE alternative, BYTE attrIdx, BYTE attrType, int attrValue)
|
||||
{
|
||||
if (slot >= SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (alternative >= SWITCHBOT_ALTERNATIVE_COUNT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_SwitchbotTable.alternatives[slot][alternative].attributes[attrIdx].bType = attrType;
|
||||
m_SwitchbotTable.alternatives[slot][alternative].attributes[attrIdx].sValue = attrValue;
|
||||
}
|
||||
|
||||
TPlayerItemAttribute CPythonSwitchbot::GetAttribute(BYTE slot, BYTE alternative, BYTE attrIdx)
|
||||
{
|
||||
TPlayerItemAttribute attr = {};
|
||||
|
||||
if (slot >= SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return attr;
|
||||
}
|
||||
|
||||
if (alternative >= SWITCHBOT_ALTERNATIVE_COUNT)
|
||||
{
|
||||
return attr;
|
||||
}
|
||||
|
||||
attr.bType = m_SwitchbotTable.alternatives[slot][alternative].attributes[attrIdx].bType;
|
||||
attr.sValue = m_SwitchbotTable.alternatives[slot][alternative].attributes[attrIdx].sValue;
|
||||
|
||||
return attr;
|
||||
}
|
||||
|
||||
void CPythonSwitchbot::GetAlternatives(BYTE slot, std::vector<TSwitchbotAttributeAlternativeTable>& vec_alternatives)
|
||||
{
|
||||
if (slot >= SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& it : m_SwitchbotTable.alternatives[slot])
|
||||
{
|
||||
vec_alternatives.emplace_back(it);
|
||||
}
|
||||
}
|
||||
|
||||
int CPythonSwitchbot::GetAttibuteSet(BYTE slot)
|
||||
{
|
||||
if (slot >= SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
TItemPos pos(SWITCHBOT, slot);
|
||||
|
||||
CItemData* pItemDataPtr = NULL;
|
||||
BYTE item_type = 0, item_subtype = 0; // PORT: AVA2 left item_type uninitialised
|
||||
|
||||
if (CItemManager::Instance().GetItemDataPointer(CPythonPlayer::Instance().GetItemIndex(pos), &pItemDataPtr))
|
||||
{
|
||||
item_type = pItemDataPtr->GetType();
|
||||
item_subtype = pItemDataPtr->GetSubType();
|
||||
}
|
||||
|
||||
if (item_type == 0 && item_subtype == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (item_type == CItemData::ITEM_TYPE_WEAPON)
|
||||
{
|
||||
if (item_subtype == CItemData::WEAPON_ARROW)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ATTRIBUTE_SET_WEAPON;
|
||||
}
|
||||
|
||||
if(item_type == CItemData::ITEM_TYPE_RINGS)
|
||||
{
|
||||
return ATTRIBUTE_SET_NEW_RINGS;
|
||||
}
|
||||
|
||||
if (item_type == CItemData::ITEM_TYPE_ARMOR || item_type == CItemData::ITEM_TYPE_COSTUME)
|
||||
{
|
||||
switch (item_subtype)
|
||||
{
|
||||
case CItemData::ARMOR_BODY:
|
||||
return ATTRIBUTE_SET_BODY;
|
||||
|
||||
case CItemData::ARMOR_WRIST:
|
||||
return ATTRIBUTE_SET_WRIST;
|
||||
|
||||
case CItemData::ARMOR_FOOTS:
|
||||
return ATTRIBUTE_SET_FOOTS;
|
||||
|
||||
case CItemData::ARMOR_NECK:
|
||||
return ATTRIBUTE_SET_NECK;
|
||||
|
||||
case CItemData::ARMOR_HEAD:
|
||||
return ATTRIBUTE_SET_HEAD;
|
||||
|
||||
case CItemData::ARMOR_SHIELD:
|
||||
return ATTRIBUTE_SET_SHIELD;
|
||||
|
||||
case CItemData::ARMOR_EAR:
|
||||
return ATTRIBUTE_SET_EAR;
|
||||
|
||||
case CItemData::ARMOR_PENDANT:
|
||||
return ATTRIBUTE_SET_PENDANT;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool CPythonSwitchbot::IsActive(BYTE slot)
|
||||
{
|
||||
if (slot >= SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_SwitchbotTable.active[slot];
|
||||
}
|
||||
|
||||
bool CPythonSwitchbot::IsFinished(BYTE slot)
|
||||
{
|
||||
if (slot >= SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_SwitchbotTable.finished[slot];
|
||||
}
|
||||
|
||||
void CPythonSwitchbot::ClearSlot(BYTE slot)
|
||||
{
|
||||
if (slot >= SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_SwitchbotTable.active[slot] = false;
|
||||
m_SwitchbotTable.items[slot] = 0;
|
||||
memset(&m_SwitchbotTable.alternatives[slot], 0, sizeof(m_SwitchbotTable.alternatives[slot]));
|
||||
}
|
||||
|
||||
void CPythonSwitchbot::ClearAttributeMap()
|
||||
{
|
||||
m_map_AttributesBySet.clear();
|
||||
}
|
||||
|
||||
void CPythonSwitchbot::AddAttributeToMap(const TSwitchbottAttributeTable& table)
|
||||
{
|
||||
const auto& it = m_map_AttributesBySet.find(table.attribute_set);
|
||||
if (it == m_map_AttributesBySet.end())
|
||||
{
|
||||
std::map<BYTE, long> attribute_map;
|
||||
attribute_map.insert(std::make_pair(table.apply_num, table.max_value));
|
||||
|
||||
m_map_AttributesBySet.insert(std::make_pair(table.attribute_set, attribute_map));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::map<unsigned char, long>::iterator it2 = it->second.find(table.apply_num);
|
||||
if (it2 == it->second.end())
|
||||
{
|
||||
it->second.insert(std::make_pair(table.apply_num, table.max_value));
|
||||
}
|
||||
else
|
||||
{
|
||||
it2->second = table.max_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CPythonSwitchbot::GetAttributesBySet(int iAttributeSet, std::vector<TPlayerItemAttribute>& vec_attributes)
|
||||
{
|
||||
if (iAttributeSet == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& it = m_map_AttributesBySet.find(iAttributeSet);
|
||||
if (it == m_map_AttributesBySet.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& it2 : it->second)
|
||||
{
|
||||
TPlayerItemAttribute attr;
|
||||
attr.bType = it2.first;
|
||||
attr.sValue = it2.second;
|
||||
|
||||
vec_attributes.emplace_back(attr);
|
||||
}
|
||||
}
|
||||
|
||||
long CPythonSwitchbot::GetAttributeMaxValue(int iAttributeSet, BYTE attrType)
|
||||
{
|
||||
if (iAttributeSet == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto& it = m_map_AttributesBySet.find(iAttributeSet);
|
||||
if (it == m_map_AttributesBySet.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto& it2 = it->second.find(attrType);
|
||||
if (it2 == it->second.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return it2->second;
|
||||
}
|
||||
|
||||
PyObject* switchbotIsActive(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
return Py_BuildValue("i", CPythonSwitchbot::Instance().IsActive(bSlot));
|
||||
}
|
||||
|
||||
PyObject* switchbotIsFinished(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
return Py_BuildValue("i", CPythonSwitchbot::Instance().IsFinished(bSlot));
|
||||
}
|
||||
|
||||
PyObject* switchbotGetAttribute(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
BYTE bAlternative;
|
||||
if (!PyTuple_GetByte(poArgs, 1, &bAlternative))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
BYTE bAttrIndex;
|
||||
if (!PyTuple_GetByte(poArgs, 2, &bAttrIndex))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
TPlayerItemAttribute attr = CPythonSwitchbot::Instance().GetAttribute(bSlot, bAlternative, bAttrIndex);
|
||||
return Py_BuildValue("ii", attr.bType, attr.sValue);
|
||||
}
|
||||
|
||||
PyObject* switchbotSetAttribute(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
BYTE bAlternative;
|
||||
if (!PyTuple_GetByte(poArgs, 1, &bAlternative))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
BYTE bAttrIndex;
|
||||
if (!PyTuple_GetByte(poArgs, 2, &bAttrIndex))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
BYTE bType;
|
||||
if (!PyTuple_GetByte(poArgs, 3, &bType))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
int iValue;
|
||||
if (!PyTuple_GetInteger(poArgs, 4, &iValue))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
CPythonSwitchbot::Instance().SetAttribute(bSlot, bAlternative, bAttrIndex, bType, iValue);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* switchbotClearSlot(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
CPythonSwitchbot::Instance().ClearSlot(bSlot);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* switchbotGetAttributesForSet(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
PyObject* list = PyList_New(0);
|
||||
|
||||
int iAttributeSet = CPythonSwitchbot::Instance().GetAttibuteSet(bSlot);
|
||||
if (iAttributeSet == -1)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
std::vector<TPlayerItemAttribute> vec_attributes;
|
||||
CPythonSwitchbot::Instance().GetAttributesBySet(iAttributeSet, vec_attributes);
|
||||
|
||||
struct
|
||||
{
|
||||
bool operator()(TPlayerItemAttribute a, TPlayerItemAttribute b) const
|
||||
{
|
||||
return a.bType < b.bType;
|
||||
}
|
||||
} SortAttributes;
|
||||
|
||||
std::sort(vec_attributes.begin(), vec_attributes.end(), SortAttributes);
|
||||
|
||||
for (TPlayerItemAttribute attr : vec_attributes)
|
||||
{
|
||||
PyList_Append(list, Py_BuildValue("(ii)", attr.bType, attr.sValue));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
PyObject* switchbotGetAttributeMaxValue(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
BYTE bAttrType;
|
||||
if (!PyTuple_GetByte(poArgs, 1, &bAttrType))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
int iAttributeSet = CPythonSwitchbot::Instance().GetAttibuteSet(bSlot);
|
||||
if (iAttributeSet == -1)
|
||||
{
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
long maxValue = CPythonSwitchbot::Instance().GetAttributeMaxValue(iAttributeSet, bAttrType);
|
||||
return Py_BuildValue("i", int(maxValue)); // PORT: "i" takes an int; long is 64-bit here
|
||||
}
|
||||
|
||||
PyObject* switchbotStart(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
if (bSlot > SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
std::vector<CPythonSwitchbot::TSwitchbotAttributeAlternativeTable> vec_alternatives;
|
||||
CPythonSwitchbot::Instance().GetAlternatives(bSlot, vec_alternatives);
|
||||
|
||||
CPythonNetworkStream::Instance().SendSwitchbotStartPacket(bSlot, vec_alternatives);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* switchbotStop(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
BYTE bSlot;
|
||||
if (!PyTuple_GetByte(poArgs, 0, &bSlot))
|
||||
{
|
||||
return Py_BuildException();
|
||||
}
|
||||
|
||||
if (bSlot > SWITCHBOT_SLOT_COUNT)
|
||||
{
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
CPythonNetworkStream::Instance().SendSwitchbotStopPacket(bSlot);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
void initSwitchbot()
|
||||
{
|
||||
static PyMethodDef s_methods[] =
|
||||
{
|
||||
{ "IsActive", switchbotIsActive, METH_VARARGS },
|
||||
{ "IsFinished", switchbotIsFinished, METH_VARARGS },
|
||||
{ "GetAttribute", switchbotGetAttribute, METH_VARARGS },
|
||||
{ "SetAttribute", switchbotSetAttribute, METH_VARARGS },
|
||||
{ "GetAttributesForSet", switchbotGetAttributesForSet, METH_VARARGS },
|
||||
{ "GetAttributeMaxValue", switchbotGetAttributeMaxValue, METH_VARARGS },
|
||||
{ "ClearSlot", switchbotClearSlot, METH_VARARGS },
|
||||
{ "Start", switchbotStart, METH_VARARGS },
|
||||
{ "Stop", switchbotStop, METH_VARARGS },
|
||||
|
||||
{ NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
PyObject * poModule = Py_InitModule("switchbot", s_methods);
|
||||
PyModule_AddIntConstant(poModule, "SLOT_COUNT", SWITCHBOT_SLOT_COUNT_REAL);
|
||||
PyModule_AddIntConstant(poModule, "ALTERNATIVE_COUNT", SWITCHBOT_ALTERNATIVE_COUNT);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
// PORT: AVA2 PythonSwitchbot.h (ENABLE_SWITCHBOT). The tables are the server's wire layout
|
||||
// (metin2-server common/tables.h); max_value is LONG, the 32-bit Win32 long.
|
||||
#include "Packet.h"
|
||||
|
||||
class CPythonSwitchbot : public CSingleton <CPythonSwitchbot>
|
||||
{
|
||||
public:
|
||||
#pragma pack(1)
|
||||
struct TSwitchbotAttributeAlternativeTable
|
||||
{
|
||||
TPlayerItemAttribute attributes[MAX_NORM_ATTR_NUM];
|
||||
|
||||
bool IsConfigured() const
|
||||
{
|
||||
for (const auto& it : attributes)
|
||||
{
|
||||
if (it.bType && it.sValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct TSwitchbotTable
|
||||
{
|
||||
DWORD player_id;
|
||||
bool active[SWITCHBOT_SLOT_COUNT];
|
||||
bool finished[SWITCHBOT_SLOT_COUNT];
|
||||
DWORD items[SWITCHBOT_SLOT_COUNT];
|
||||
TSwitchbotAttributeAlternativeTable alternatives[SWITCHBOT_SLOT_COUNT][SWITCHBOT_ALTERNATIVE_COUNT];
|
||||
|
||||
TSwitchbotTable() : player_id(0)
|
||||
{
|
||||
memset(&items, 0, sizeof(items));
|
||||
memset(&alternatives, 0, sizeof(alternatives));
|
||||
memset(&active, false, sizeof(active));
|
||||
memset(&finished, false, sizeof(finished));
|
||||
}
|
||||
};
|
||||
|
||||
struct TSwitchbottAttributeTable
|
||||
{
|
||||
BYTE attribute_set;
|
||||
int apply_num;
|
||||
LONG max_value;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
CPythonSwitchbot();
|
||||
virtual ~CPythonSwitchbot();
|
||||
|
||||
void Initialize();
|
||||
void Update(const TSwitchbotTable& table);
|
||||
|
||||
void SetAttribute(BYTE slot, BYTE alternative, BYTE attrIdx, BYTE attrType, int attrValue);
|
||||
TPlayerItemAttribute GetAttribute(BYTE slot, BYTE alternative, BYTE attrIdx);
|
||||
void GetAlternatives(BYTE slot, std::vector<TSwitchbotAttributeAlternativeTable>& attributes);
|
||||
int GetAttibuteSet(BYTE slot);
|
||||
bool IsActive(BYTE slot);
|
||||
bool IsFinished(BYTE slot);
|
||||
|
||||
void ClearSlot(BYTE slot);
|
||||
void ClearAttributeMap();
|
||||
|
||||
void AddAttributeToMap(const TSwitchbottAttributeTable& table);
|
||||
void GetAttributesBySet(int iAttributeSet, std::vector<TPlayerItemAttribute>& vec_attributes);
|
||||
long GetAttributeMaxValue(int iAttributeSet, BYTE attrType);
|
||||
|
||||
protected:
|
||||
TSwitchbotTable m_SwitchbotTable;
|
||||
std::map<BYTE, std::map<BYTE, long>> m_map_AttributesBySet;
|
||||
};
|
||||
|
||||
static_assert(sizeof(CPythonSwitchbot::TSwitchbotTable) == 220, "TSwitchbotTable");
|
||||
static_assert(sizeof(CPythonSwitchbot::TSwitchbotAttributeAlternativeTable) == 15, "TSwitchbotAttributeAlternativeTable");
|
||||
static_assert(sizeof(CPythonSwitchbot::TSwitchbottAttributeTable) == 9, "TSwitchbottAttributeTable");
|
||||
@@ -69,6 +69,7 @@ void initBackground();
|
||||
void initMessenger();
|
||||
void initsafebox();
|
||||
void initSash(); // PORT: AVA2 sash
|
||||
void initSwitchbot(); // PORT: AVA2 switchbot
|
||||
void initguild();
|
||||
void initServerStateChecker();
|
||||
void initRenderTarget(); // PORT: AVA2 CPythonRenderTargetModule
|
||||
|
||||
Reference in New Issue
Block a user