Port AVA2 native tracker and item-currency ticket shop
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
// Baseline item records followed by AVA2 item-currency pairs. This envelope keeps legacy NPC/PC shops compatible.
|
||||
template<class Item,class Price,std::size_t Count>
|
||||
inline bool DecodeAva2ShopStart(const char* data,std::size_t size,std::uint32_t& owner,Item (&items)[Count],Price (&prices)[Count])
|
||||
{
|
||||
if (!data || size!=sizeof(owner)+sizeof(items)+sizeof(prices)) return false;
|
||||
Item decodedItems[Count];Price decodedPrices[Count];
|
||||
std::memcpy(decodedItems,data+sizeof(owner),sizeof(decodedItems));
|
||||
std::memcpy(decodedPrices,data+sizeof(owner)+sizeof(decodedItems),sizeof(decodedPrices));
|
||||
for (std::size_t i=0;i<Count;++i)
|
||||
if ((decodedPrices[i].vnum==0)!=(decodedPrices[i].count==0) || (decodedPrices[i].vnum && !decodedItems[i].vnum)) return false;
|
||||
std::memcpy(&owner,data,sizeof(owner));
|
||||
std::memcpy(items,decodedItems,sizeof(items));std::memcpy(prices,decodedPrices,sizeof(prices));
|
||||
return true;
|
||||
}
|
||||
@@ -373,6 +373,9 @@ typedef struct packet_shop_item
|
||||
TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_SLOT_MAX_NUM];
|
||||
} TShopItemData;
|
||||
|
||||
struct TAva2ShopPrice { DWORD vnum, count; };
|
||||
static_assert(sizeof(TAva2ShopPrice)==8,"AVA2 shop currency layout");
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
// PORT: wire sizes of the 32-bit client (SHOP_SUBHEADER_GC_START/_EX send 40 of these back to back).
|
||||
|
||||
@@ -1882,6 +1882,8 @@ enum EPacketShopSubHeaders
|
||||
SHOP_SUBHEADER_GC_SOLD_OUT,
|
||||
SHOP_SUBHEADER_GC_START_EX,
|
||||
SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY_EX,
|
||||
SHOP_SUBHEADER_GC_START_ITEM_CURRENCY,
|
||||
SHOP_SUBHEADER_GC_NOT_ENOUGH_ITEM,
|
||||
};
|
||||
|
||||
typedef struct packet_shop
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "Ava2ShopWire.h"
|
||||
#include "StdAfx.h"
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "Packet.h"
|
||||
@@ -1713,6 +1714,24 @@ bool CPythonNetworkStream::RecvShopPacket()
|
||||
|
||||
switch (packet_shop.subheader)
|
||||
{
|
||||
case SHOP_SUBHEADER_GC_START_ITEM_CURRENCY:
|
||||
{
|
||||
TShopItemData items[SHOP_HOST_ITEM_MAX_NUM];
|
||||
TAva2ShopPrice prices[SHOP_HOST_ITEM_MAX_NUM];
|
||||
DWORD owner=0;
|
||||
if (iSize<0 || !DecodeAva2ShopStart(vecBuffer.data(),size_t(iSize),owner,items,prices)) return false;
|
||||
CPythonShop::Instance().Clear();
|
||||
CPythonShop::Instance().SetTabCoinType(0,SHOP_COIN_TYPE_GOLD);
|
||||
for (unsigned i=0;i<SHOP_HOST_ITEM_MAX_NUM;++i) {
|
||||
CPythonShop::Instance().SetItemData(i,items[i]);
|
||||
CPythonShop::Instance().SetItemCurrency(i,prices[i].vnum,prices[i].count);
|
||||
}
|
||||
PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME],"StartShop",Py_BuildValue("(i)",owner));
|
||||
}
|
||||
break;
|
||||
case SHOP_SUBHEADER_GC_NOT_ENOUGH_ITEM:
|
||||
PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME],"OnShopError",Py_BuildValue("(s)","NOT_ENOUGH_COUNT"));
|
||||
break;
|
||||
case SHOP_SUBHEADER_GC_START:
|
||||
{
|
||||
CPythonShop::Instance().Clear();
|
||||
|
||||
@@ -13,6 +13,16 @@
|
||||
// *pdwItemID=itemData->vnum;
|
||||
// return TRUE;
|
||||
//}
|
||||
// AVA2 GetVnumBuy/GetCountBuy, isolated from the baseline shop packet.
|
||||
void CPythonShop::SetItemCurrency(DWORD index,DWORD vnum,DWORD count) {
|
||||
if(index<SHOP_TAB_COUNT_MAX*SHOP_HOST_ITEM_MAX_NUM) m_itemCurrency[index]={vnum,count};
|
||||
}
|
||||
DWORD CPythonShop::GetItemCurrencyVnum(DWORD index) const {
|
||||
return index<SHOP_TAB_COUNT_MAX*SHOP_HOST_ITEM_MAX_NUM?m_itemCurrency[index].vnum:0;
|
||||
}
|
||||
DWORD CPythonShop::GetItemCurrencyCount(DWORD index) const {
|
||||
return index<SHOP_TAB_COUNT_MAX*SHOP_HOST_ITEM_MAX_NUM?m_itemCurrency[index].count:0;
|
||||
}
|
||||
void CPythonShop::SetTabCoinType(BYTE tabIdx, BYTE coinType)
|
||||
{
|
||||
if (tabIdx >= m_bTabCount)
|
||||
@@ -167,6 +177,7 @@ void CPythonShop::Open(BOOL isPrivateShop, BOOL isMainPrivateShop)
|
||||
|
||||
void CPythonShop::Close()
|
||||
{
|
||||
memset(m_itemCurrency,0,sizeof(m_itemCurrency));
|
||||
m_isShoping = FALSE;
|
||||
m_isPrivateShop = FALSE;
|
||||
m_isMainPlayerPrivateShop = FALSE;
|
||||
@@ -189,6 +200,7 @@ BOOL CPythonShop::IsMainPlayerPrivateShop()
|
||||
|
||||
void CPythonShop::Clear()
|
||||
{
|
||||
memset(m_itemCurrency,0,sizeof(m_itemCurrency));
|
||||
m_isShoping = FALSE;
|
||||
m_isPrivateShop = FALSE;
|
||||
m_isMainPlayerPrivateShop = FALSE;
|
||||
@@ -399,6 +411,14 @@ PyObject * shopGetTabCoinType(PyObject * poSelf, PyObject * poArgs)
|
||||
return Py_BuildValue("i", CPythonShop::instance().GetTabCoinType(bTabIdx));
|
||||
}
|
||||
|
||||
PyObject* shopGetVnumBuy(PyObject*,PyObject* args) {
|
||||
int index;if(!PyTuple_GetInteger(args,0,&index))return Py_BuildException();
|
||||
return Py_BuildValue("I",CPythonShop::Instance().GetItemCurrencyVnum(index));
|
||||
}
|
||||
PyObject* shopGetCountBuy(PyObject*,PyObject* args) {
|
||||
int index;if(!PyTuple_GetInteger(args,0,&index))return Py_BuildException();
|
||||
return Py_BuildValue("I",CPythonShop::Instance().GetItemCurrencyCount(index));
|
||||
}
|
||||
void initshop()
|
||||
{
|
||||
static PyMethodDef s_methods[] =
|
||||
@@ -411,6 +431,8 @@ void initshop()
|
||||
{ "IsMainPlayerPrivateShop", shopIsMainPlayerPrivateShop, METH_VARARGS },
|
||||
{ "GetItemID", shopGetItemID, METH_VARARGS },
|
||||
{ "GetItemCount", shopGetItemCount, METH_VARARGS },
|
||||
{ "GetVnumBuy",shopGetVnumBuy,METH_VARARGS },
|
||||
{ "GetCountBuy",shopGetCountBuy,METH_VARARGS },
|
||||
{ "GetItemPrice", shopGetItemPrice, METH_VARARGS },
|
||||
{ "GetItemMetinSocket", shopGetItemMetinSocket, METH_VARARGS },
|
||||
{ "GetItemAttribute", shopGetItemAttribute, METH_VARARGS },
|
||||
|
||||
@@ -24,6 +24,9 @@ class CPythonShop : public CSingleton<CPythonShop>
|
||||
virtual ~CPythonShop(void);
|
||||
|
||||
void Clear();
|
||||
void SetItemCurrency(DWORD index,DWORD vnum,DWORD count);
|
||||
DWORD GetItemCurrencyVnum(DWORD index) const;
|
||||
DWORD GetItemCurrencyCount(DWORD index) const;
|
||||
|
||||
void SetItemData(DWORD dwIndex, const TShopItemData & c_rShopItemData);
|
||||
BOOL GetItemData(DWORD dwIndex, const TShopItemData ** c_ppItemData);
|
||||
@@ -74,6 +77,7 @@ class CPythonShop : public CSingleton<CPythonShop>
|
||||
TShopItemData items[SHOP_HOST_ITEM_MAX_NUM];
|
||||
};
|
||||
|
||||
TAva2ShopPrice m_itemCurrency[SHOP_TAB_COUNT_MAX*SHOP_HOST_ITEM_MAX_NUM];
|
||||
BYTE m_bTabCount;
|
||||
ShopTab m_aShoptabs[SHOP_TAB_COUNT_MAX];
|
||||
|
||||
|
||||
@@ -309,6 +309,8 @@ void CPythonSystem::SetDefaultConfig()
|
||||
m_Config.iShadowLevel = 3;
|
||||
m_Config.bViewChat = true;
|
||||
m_Config.bAlwaysShowName = DEFAULT_VALUE_ALWAYS_SHOW_NAME;
|
||||
m_Config.dungeonTrack = false;
|
||||
m_Config.bossTrack = false;
|
||||
m_Config.bShowDamage = true;
|
||||
m_Config.bShowSalesText = true;
|
||||
}
|
||||
@@ -448,6 +450,8 @@ bool CPythonSystem::LoadConfig()
|
||||
m_Config.bDecompressDDS = atoi(value) == 1 ? true : false;
|
||||
else if (!stricmp(command, "NO_SOUND_CARD"))
|
||||
m_Config.bNoSoundCard = atoi(value) == 1 ? true : false;
|
||||
else if (!stricmp(command,"DUNGEON_TRACK")) m_Config.dungeonTrack = atoi(value)==1;
|
||||
else if (!stricmp(command,"BOSS_TRACK")) m_Config.bossTrack = atoi(value)==1;
|
||||
else if (!stricmp(command, "VIEW_CHAT"))
|
||||
m_Config.bViewChat = atoi(value) == 1 ? true : false;
|
||||
else if (!stricmp(command, "ALWAYS_VIEW_NAME"))
|
||||
@@ -546,8 +550,9 @@ bool CPythonSystem::SaveConfig()
|
||||
fprintf(fp, "USE_DEFAULT_IME %d\n", m_Config.bUseDefaultIME);
|
||||
fprintf(fp, "SOFTWARE_TILING %d\n", m_Config.bSoftwareTiling);
|
||||
fprintf(fp, "SHADOW_LEVEL %d\n", m_Config.iShadowLevel);
|
||||
// The classic loader stops at the first blank line; extensions must precede it.
|
||||
fprintf(fp,"DUNGEON_TRACK\t%d\nBOSS_TRACK\t%d\n",m_Config.dungeonTrack,m_Config.bossTrack);
|
||||
fprintf(fp, "\n");
|
||||
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ class CPythonSystem : public CSingleton<CPythonSystem>
|
||||
bool bAlwaysShowName;
|
||||
bool bShowDamage;
|
||||
bool bShowSalesText;
|
||||
bool dungeonTrack;
|
||||
bool bossTrack;
|
||||
} TConfig;
|
||||
|
||||
public:
|
||||
|
||||
@@ -411,6 +411,19 @@ PyObject * systemSetShadowLevel(PyObject * poSelf, PyObject * poArgs)
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
// AVA2 tracker notification preferences.
|
||||
PyObject* systemGetDungeonTrack(PyObject*,PyObject*) { return Py_BuildValue("i",CPythonSystem::Instance().GetConfig()->dungeonTrack); }
|
||||
PyObject* systemSetDungeonTrack(PyObject*,PyObject* args) {
|
||||
int flag; if (!PyTuple_GetInteger(args,0,&flag)) return Py_BuildException();
|
||||
CPythonSystem::Instance().GetConfig()->dungeonTrack=flag!=0;
|
||||
CPythonSystem::Instance().SaveConfig(); return Py_BuildNone();
|
||||
}
|
||||
PyObject* systemGetBossTrack(PyObject*,PyObject*) { return Py_BuildValue("i",CPythonSystem::Instance().GetConfig()->bossTrack); }
|
||||
PyObject* systemSetBossTrack(PyObject*,PyObject* args) {
|
||||
int flag; if (!PyTuple_GetInteger(args,0,&flag)) return Py_BuildException();
|
||||
CPythonSystem::Instance().GetConfig()->bossTrack=flag!=0;
|
||||
CPythonSystem::Instance().SaveConfig(); return Py_BuildNone();
|
||||
}
|
||||
void initsystem()
|
||||
{
|
||||
static PyMethodDef s_methods[] =
|
||||
@@ -450,6 +463,10 @@ void initsystem()
|
||||
{ "SetSoundVolumef", systemSetSoundVolumef, METH_VARARGS },
|
||||
{ "IsSoftwareCursor", systemIsSoftwareCursor, METH_VARARGS },
|
||||
|
||||
{ "GetDungeonTrack",systemGetDungeonTrack,METH_VARARGS },
|
||||
{ "SetDungeonTrack",systemSetDungeonTrack,METH_VARARGS },
|
||||
{ "GetBossTrack",systemGetBossTrack,METH_VARARGS },
|
||||
{ "SetBossTrack",systemSetBossTrack,METH_VARARGS },
|
||||
{ "SetViewChatFlag", systemSetViewChatFlag, METH_VARARGS },
|
||||
{ "IsViewChat", systemIsViewChat, METH_VARARGS },
|
||||
|
||||
|
||||
Reference in New Issue
Block a user