56 lines
3.4 KiB
C++
56 lines
3.4 KiB
C++
// AVA2 UserInterface/PythonPrivateShopSearch.cpp (active Windows feature set).
|
|
#include "shop_search_state.h"
|
|
#include "python_native_modules.h"
|
|
#include "shared/common/PythonUtils.h"
|
|
#include <bit>
|
|
#include <cstring>
|
|
namespace ava2 {
|
|
std::vector<TOfflineShopItemData>& GetShopSearchItems() { static std::vector<TOfflineShopItemData> items;return items; }
|
|
namespace {
|
|
TOfflineShopItemData* lookup(int index) {
|
|
auto& items=GetShopSearchItems();
|
|
if(uint32_t(index)>=items.size()) { PyErr_Format(PyExc_RuntimeError,"Shop search index out of range: %d",index);return nullptr; }
|
|
return &items[index];
|
|
}
|
|
template<int field> PyObject* scalar(PyObject*,PyObject* args) {
|
|
int index;if(!PyTuple_GetInteger(args,0,&index))return Py_BadArgument();
|
|
auto* item=lookup(index);if(!item)return nullptr;
|
|
if constexpr(field==0)return PyInt_FromLong(item->count);
|
|
if constexpr(field==1)return PyLong_FromLongLong(item->price);
|
|
if constexpr(field==2)return PyInt_FromLong(std::bit_cast<int32_t>(item->vnum));
|
|
if constexpr(field==3)return PyInt_FromLong(std::bit_cast<int32_t>(item->owner_id));
|
|
if constexpr(field==4)return PyInt_FromLong(item->display_pos);
|
|
if constexpr(field==5)return PyInt_FromLong(std::bit_cast<int32_t>(item->id));
|
|
if constexpr(field==6)return PyString_FromStringAndSize(item->szBuyerName,strnlen(item->szBuyerName,sizeof(item->szBuyerName)));
|
|
}
|
|
PyObject* count(PyObject*,PyObject*) { return PyInt_FromLong(GetShopSearchItems().size()); }
|
|
PyObject* clear(PyObject*,PyObject*) { GetShopSearchItems().clear();Py_RETURN_NONE; }
|
|
PyObject* socket(PyObject*,PyObject* args) {
|
|
int index,slot;if(!PyTuple_GetInteger(args,0,&index)||!PyTuple_GetInteger(args,1,&slot))return Py_BadArgument();
|
|
if(slot>=int(ITEM_SOCKET_SLOT_MAX_NUM))return Py_BuildException();
|
|
if(slot<0) { PyErr_SetString(PyExc_RuntimeError,"Shop search socket out of range");return nullptr; }
|
|
auto* item=lookup(index);return item?PyInt_FromLong(item->alSockets[slot]):nullptr;
|
|
}
|
|
PyObject* attr(PyObject*,PyObject* args) {
|
|
int index,slot;if(!PyTuple_GetInteger(args,0,&index)||!PyTuple_GetInteger(args,1,&slot))return Py_BuildException();
|
|
if(slot<0||slot>=int(ITEM_ATTRIBUTE_SLOT_MAX_NUM))return Py_BuildValue("(ii)",0,0);
|
|
auto* item=lookup(index);return item?Py_BuildValue("(ii)",int(item->aAttr[slot].bType),int(item->aAttr[slot].sValue)):nullptr;
|
|
}
|
|
PyObject* new_name(PyObject*,PyObject* args) {
|
|
int index;if(!PyTuple_GetInteger(args,0,&index))return Py_BadArgument();
|
|
return PyString_FromString("^"); // Original explicitly ignores the result record's name.
|
|
}
|
|
}
|
|
void initprivateShopSearch() {
|
|
static PyMethodDef methods[]={
|
|
{"GetItemCount",count,METH_VARARGS,nullptr},{"GetSearchItemCount",scalar<0>,METH_VARARGS,nullptr},
|
|
{"GetSearchItemPrice",scalar<1>,METH_VARARGS,nullptr},{"GetSearchItemVnum",scalar<2>,METH_VARARGS,nullptr},
|
|
{"GetSearchItemShopVID",scalar<3>,METH_VARARGS,nullptr},{"ClearSearchItems",clear,METH_VARARGS,nullptr},
|
|
{"GetSearchItemMetinSocket",socket,METH_VARARGS,nullptr},{"GetSearchItemAttribute",attr,METH_VARARGS,nullptr},
|
|
{"GetSearchItemNewName",new_name,METH_VARARGS,nullptr},{"GetSearchItemPos",scalar<4>,METH_VARARGS,nullptr},
|
|
{"GetSearchItemSeller",scalar<6>,METH_VARARGS,nullptr},{"GetSearchItemID",scalar<5>,METH_VARARGS,nullptr},
|
|
{nullptr,nullptr,0,nullptr}};
|
|
Py_InitModule("privateShopSearch",methods);
|
|
}
|
|
}
|