修复徽章镶嵌
This commit is contained in:
205
src/dispatch.cpp
205
src/dispatch.cpp
@@ -23,7 +23,6 @@ ENUM_PACK_RET_TYPE CDispatch::UseEquipmentMoveItem(CUser* user, PacketBuf* pBuf)
|
||||
|
||||
if (user->get_state() != 3)
|
||||
{
|
||||
LOG(u8"玩家状态不正常!");
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
@@ -34,10 +33,19 @@ ENUM_PACK_RET_TYPE CDispatch::UseEquipmentMoveItem(CUser* user, PacketBuf* pBuf)
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
LOG(u8"UseEquipmentMoveItem :%s ", Util::ToHexString((const unsigned char*)pBuf->get_buf_ptr(0), 40).c_str());
|
||||
int equipment_pos = pBuf->get_short(); //装备位置
|
||||
int equipment_id = pBuf->get_int(); //装备代码
|
||||
int item_pos = pBuf->get_short(); //物品位置
|
||||
LOG(u8"UseEquipmentMoveItem :%s ", Utils::ToHexString((const unsigned char*)pBuf->get_buf_ptr(0), 40).c_str());
|
||||
|
||||
short equipment_pos = 0;
|
||||
int equipment_id = 0;
|
||||
short item_pos = 0;
|
||||
|
||||
if ((unsigned __int8)pBuf->get_short(&equipment_pos) != 1
|
||||
|| (unsigned __int8)pBuf->get_int(&equipment_id) != 1
|
||||
|| (unsigned __int8)pBuf->get_short(&item_pos) != 1)
|
||||
{
|
||||
user->SendCmdErrorPacket(84, -1);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
//1 物品栏 2 时装
|
||||
if (user->CheckItemLock(1, equipment_pos))
|
||||
@@ -94,8 +102,8 @@ ENUM_PACK_RET_TYPE CDispatch::UseEquipmentMoveItem(CUser* user, PacketBuf* pBuf)
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
CItem* equipment_citem = DataManager->find_item(equipment_id);
|
||||
CItem* item_citem = DataManager->find_item(item_id);
|
||||
CEquipItem* equipment_citem = (CEquipItem*)DataManager->find_item(equipment_id);
|
||||
CStackableItem* item_citem = (CStackableItem*)DataManager->find_item(item_id);
|
||||
LOG(u8"equipment_citem +12: %p"
|
||||
, *(int*)equipment_citem + 12
|
||||
);
|
||||
@@ -227,9 +235,17 @@ ENUM_PACK_RET_TYPE CDispatch::Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_Mod
|
||||
user->SendCmdErrorPacket(84, 0xD1u);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
int equipment_pos = pBuf->get_short();
|
||||
int equipment_id = pBuf->get_int();
|
||||
int item_pos = pBuf->get_short();
|
||||
short equipment_pos = 0;
|
||||
int equipment_id = 0;
|
||||
short item_pos = 0;
|
||||
|
||||
if ((unsigned __int8)pBuf->get_short(&equipment_pos) != 1
|
||||
|| (unsigned __int8)pBuf->get_int(&equipment_id) != 1
|
||||
|| (unsigned __int8)pBuf->get_short(&item_pos) != 1)
|
||||
{
|
||||
user->SendCmdErrorPacket(84, -1);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
auto CurCharacInvenW = (CInventory*)user->getCurCharacInvenW();
|
||||
Inven_Item equipment_inven = {};
|
||||
@@ -301,9 +317,176 @@ ENUM_PACK_RET_TYPE CDispatch::Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_Mod
|
||||
CInventory::INVENTORY_TYPE_ITEM,
|
||||
equipment_pos,
|
||||
equipment_inven);
|
||||
|
||||
|
||||
dis_mod->_SendResult(user, 1, item_pos, equipment_pos);
|
||||
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
ENUM_PACK_RET_TYPE CDispatch::UseJewel_dispatch_sig(void* pDispatcher_UseJewel, CUser* user, PacketBuf* pBuf)
|
||||
{
|
||||
printf("getCurCharacName :%s \n", user->getCurCharacName().c_str());
|
||||
printf("getCurCharacNo :%d \n", user->getCurCharacNo());
|
||||
printf("get_buf_ptr :%p %p \n", pBuf->get_buf_ptr(0));
|
||||
printf("get_len :%d \n", pBuf->get_len());
|
||||
|
||||
// printf("pBuf :%s \n", Util::ToHexString((const unsigned char*)pBuf->get_buf_ptr(0),40).c_str());
|
||||
int state = user->get_state();
|
||||
LOG("state :%d \n", state);
|
||||
//校验角色状态是否允许镶嵌
|
||||
if (state != 3)
|
||||
return PAK_IGNORE;
|
||||
|
||||
int isEnableAvatarSocketAction = user->isEnableAvatarSocketAction();
|
||||
if (isEnableAvatarSocketAction)
|
||||
user->SendCmdErrorPacket(205, (unsigned char)isEnableAvatarSocketAction);
|
||||
//解析packet_buf
|
||||
|
||||
short avartar_inven_slot = 0; //时装所在的背包槽
|
||||
int avartar_item_id = 0; //时装item_id
|
||||
char emblem_cnt = 0; //本次镶嵌徽章数量
|
||||
|
||||
if ((unsigned __int8)pBuf->get_short(&avartar_inven_slot) != 1
|
||||
|| (unsigned __int8)pBuf->get_int(&avartar_item_id) != 1
|
||||
|| (unsigned __int8)pBuf->get_byte(&emblem_cnt) != 1)
|
||||
{
|
||||
user->SendCmdErrorPacket(205, -1);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
if (user->CheckItemLock(2, avartar_inven_slot))
|
||||
{
|
||||
user->SendCmdErrorPacket(205, 213);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
//获取时装道具
|
||||
CInventory* inven = user->getCurCharacInvenW();
|
||||
if (!inven)
|
||||
{
|
||||
LOG("pUser->getCurCharacInvenW : error \n");
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
Inven_Item* avartar = inven->GetInvenRef(CInventory::INVENTORY_TYPE_AVARTAR, avartar_inven_slot);
|
||||
if (!avartar)
|
||||
{
|
||||
LOG("inven->GetInvenRef : error \n");
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
//校验时装 数据是否合法
|
||||
if (avartar->isEmpty() || (avartar->getKey() != avartar_item_id) || user->CheckItemLock(2, avartar_inven_slot))
|
||||
{
|
||||
|
||||
LOG("avartar->isEmpty() || avartar->getKey() || pUser->CheckItemLock() : error \n");
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
//获取时装插槽数据
|
||||
WongWork::CAvatarItemMgr* avartar_add_info = (WongWork::CAvatarItemMgr*)avartar->get_add_info();
|
||||
WongWork::CAvatarItemMgr* inven_avartar_mgr = inven->GetAvatarItemMgrR();
|
||||
int jewel_socket_data = inven_avartar_mgr->getJewelSocketData(avartar_add_info);
|
||||
if (!jewel_socket_data)
|
||||
{
|
||||
LOG("jewel_socket_data : error \n");
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
LOG("jewel_socket_data :%s \n", Utils::ToHexString((const unsigned char*)jewel_socket_data, 40).c_str());
|
||||
if (emblem_cnt <= 3)
|
||||
{
|
||||
std::map<int, std::pair<int, int>> emblems;
|
||||
for (int i = 0; i < emblem_cnt; i++)
|
||||
{
|
||||
//徽章所在的背包槽
|
||||
short emblem_inven_slot = 0;
|
||||
pBuf->get_short(&emblem_inven_slot);
|
||||
//徽章item_id
|
||||
int emblem_item_id = 0;
|
||||
pBuf->get_int(&emblem_item_id);
|
||||
//该徽章镶嵌的时装插槽id
|
||||
char avartar_socket_slot = 0;
|
||||
pBuf->get_byte(&avartar_socket_slot);
|
||||
|
||||
//获取徽章道具
|
||||
Inven_Item* emblem = inven->GetInvenRef(CInventory::INVENTORY_TYPE_ITEM, emblem_inven_slot);
|
||||
//校验徽章及插槽数据是否合法
|
||||
if (emblem->isEmpty() || (emblem->getKey() != emblem_item_id) || (avartar_socket_slot >= 3))
|
||||
{
|
||||
LOG("emblem->isEmpty() || (emblem->getKey() : error \n");
|
||||
user->SendCmdErrorPacket(205, 209);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
//校验徽章是否满足时装插槽颜色要求
|
||||
|
||||
//获取徽章pvf数据
|
||||
CDataManager* DataManager = CDataManager::G_CDataManager();
|
||||
if (!DataManager)
|
||||
{
|
||||
LOG("CDataManager::G_CDataManager() : error \n");
|
||||
user->SendCmdErrorPacket(205, 209);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
CStackableItem* citem = (CStackableItem*)DataManager->find_item(emblem_item_id);
|
||||
if (!citem)
|
||||
{
|
||||
LOG("DataManager->find_item() : error \n");
|
||||
user->SendCmdErrorPacket(205, 209);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
//校验徽章类型
|
||||
if (!citem->is_stackable() || (citem->GetItemType() != 20))
|
||||
{
|
||||
LOG("citem->is_stackable() || (citem->GetItemType() : error \n");
|
||||
user->SendCmdErrorPacket(205, 209);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
//获取徽章支持的插槽
|
||||
int emblem_socket_type = citem->getJewelTargetSocket();
|
||||
|
||||
//获取要镶嵌的时装插槽类型
|
||||
int avartar_socket_type = *(short*)(jewel_socket_data + avartar_socket_slot * 6);
|
||||
if (!(emblem_socket_type & avartar_socket_type))
|
||||
{
|
||||
//插槽类型不匹配
|
||||
LOG("emblem_socket_type & avartar_socket_type\n");
|
||||
user->SendCmdErrorPacket(205, 209);
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
LOG("avartar_socket_slot:%d emblem_inven_slot:%d emblem_item_id:%d\n", avartar_socket_slot, emblem_inven_slot, emblem_item_id);
|
||||
emblems[avartar_socket_slot] = std::make_pair(emblem_inven_slot, emblem_item_id);
|
||||
}
|
||||
LOG("数据已读取!!!\n");
|
||||
|
||||
for (auto& avartar_socket_slot : emblems)
|
||||
{
|
||||
//删除徽章
|
||||
int emblem_inven_slot = avartar_socket_slot.second.first;
|
||||
inven->delete_item(CInventory::INVENTORY_TYPE_ITEM, emblem_inven_slot, 1, 8, 1);
|
||||
|
||||
//设置时装插槽数据
|
||||
int emblem_item_id = avartar_socket_slot.second.second;
|
||||
*(int*)(jewel_socket_data + avartar_socket_slot.first * 6 + 2) = emblem_item_id;
|
||||
LOG("徽章item_id=%d 已成功镶嵌进avartar_socket_slot=%d 的槽内!\n", emblem_item_id, avartar_socket_slot);
|
||||
}
|
||||
|
||||
//时装插槽数据存档
|
||||
DB_UpdateAvatarJewelSlot::makeRequest(user->getCurCharacNo(), avartar->get_ui_id(), (void*)jewel_socket_data);
|
||||
|
||||
//通知客户端时装数据已更新
|
||||
user->SendUpdateItemList(1, 1, avartar_inven_slot);
|
||||
LOG("徽章镶嵌完毕!!!");
|
||||
//回包给客户端
|
||||
InterfacePacketBuf* packet_guard = (InterfacePacketBuf*)PacketGuard::NewPacketGuard();
|
||||
|
||||
packet_guard->put_header(1, 204);
|
||||
packet_guard->put_int(1);
|
||||
packet_guard->finalize(1);
|
||||
user->Send((PacketGuard*)packet_guard);
|
||||
PacketGuard::DelPacketGuard((PacketGuard*)packet_guard);
|
||||
return PAK_OK;
|
||||
}
|
||||
return PAK_IGNORE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user