mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-21 21:20:04 +00:00
Items Implementation (#11)
* Item Manager (Initial Implementation) * Item Manager (Second Phase) * Item Manager (Phase Three) * Not Working Code * Inventory Implementation (Complete?) * Items Implementation -Fixed Indentations -Final touches to make it all work * Update Makefile * Added small comments -- needs to be fixed
This commit is contained in:
parent
e044b4251a
commit
aa2adcd9e2
2
Makefile
2
Makefile
@ -21,6 +21,7 @@ SRC=\
|
||||
src/CNStructs.cpp\
|
||||
src/main.cpp\
|
||||
src/NanoManager.cpp\
|
||||
src/ItemManager.cpp\
|
||||
src/NPCManager.cpp\
|
||||
src/Player.cpp\
|
||||
src/PlayerManager.cpp\
|
||||
@ -36,6 +37,7 @@ HDR=\
|
||||
src/CNStructs.hpp\
|
||||
src/INIReader.hpp\
|
||||
src/NanoManager.hpp\
|
||||
src/ItemManager.hpp\
|
||||
src/NPCManager.hpp\
|
||||
src/Player.hpp\
|
||||
src/PlayerManager.hpp\
|
||||
|
@ -93,13 +93,20 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
loginSessions[sock].characters[UID].PCStyle2 = charInfo->sPC_Style2;
|
||||
|
||||
for (int i = 0; i < AEQUIP_COUNT; i++) {
|
||||
// setup item
|
||||
// setup equips
|
||||
charInfo->aEquip[i].iID = 0;
|
||||
charInfo->aEquip[i].iType = i;
|
||||
charInfo->aEquip[i].iOpt = 0;
|
||||
loginSessions[sock].characters[UID].Equip[i] = charInfo->aEquip[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < AINVEN_COUNT; i++) {
|
||||
// setup inventories
|
||||
loginSessions[sock].characters[UID].Inven[i].iID = 0;
|
||||
loginSessions[sock].characters[UID].Inven[i].iType = 0;
|
||||
loginSessions[sock].characters[UID].Inven[i].iOpt = 0;
|
||||
}
|
||||
|
||||
// set default to the first character
|
||||
if (i == 0)
|
||||
loginSessions[sock].selectedChar = UID;
|
||||
|
@ -23,6 +23,7 @@ enum SHARDPACKETID {
|
||||
P_CL2FE_GM_REQ_PC_SET_VALUE = 318767211,
|
||||
P_CL2FE_REQ_SEND_FREECHAT_MESSAGE = 318767111,
|
||||
P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT = 318767184,
|
||||
P_CL2FE_REQ_ITEM_MOVE = 318767114,
|
||||
P_CL2FE_REQ_PC_EXIT = 318767106,
|
||||
|
||||
// shard 2 client
|
||||
@ -47,6 +48,8 @@ enum SHARDPACKETID {
|
||||
P_FE2CL_GM_REP_PC_SET_VALUE = 822083781,
|
||||
P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602,
|
||||
P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT = 822083730,
|
||||
P_FE2CL_PC_ITEM_MOVE_SUCC = 822083610,
|
||||
P_FE2CL_PC_EQUIP_CHANGE = 822083611,
|
||||
P_FE2CL_REP_PC_EXIT_SUCC = 822083589,
|
||||
P_FE2CL_PC_MOTD_LOGIN = 822083793
|
||||
};
|
||||
|
63
src/ItemManager.cpp
Normal file
63
src/ItemManager.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "CNShardServer.hpp"
|
||||
#include "CNStructs.hpp"
|
||||
#include "ItemManager.hpp"
|
||||
#include "PlayerManager.hpp"
|
||||
#include "Player.hpp"
|
||||
|
||||
void ItemManager::init() {
|
||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_ITEM_MOVE, itemMoveHandler);
|
||||
REGISTER_SHARD_PACKET(P_FE2CL_PC_EQUIP_CHANGE, itemMoveHandler);
|
||||
}
|
||||
|
||||
void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2FE_REQ_ITEM_MOVE))
|
||||
return; // ignore the malformed packet
|
||||
|
||||
sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf;
|
||||
sP_FE2CL_PC_ITEM_MOVE_SUCC* resp = (sP_FE2CL_PC_ITEM_MOVE_SUCC*)xmalloc(sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC));
|
||||
|
||||
PlayerView plr = PlayerManager::players[sock];
|
||||
|
||||
//weird flip flop but it makes things happen
|
||||
resp->eFrom = itemmove->eTo;
|
||||
resp->iFromSlotNum = itemmove->iToSlotNum;
|
||||
resp->eTo = itemmove->eFrom;
|
||||
resp->iToSlotNum = itemmove->iFromSlotNum;
|
||||
|
||||
//eFrom 0 means from equip, 1 means from inventory
|
||||
if (itemmove->eFrom == 0) {
|
||||
resp->FromSlotItem = plr.plr.Equip[itemmove->iFromSlotNum];
|
||||
} else {
|
||||
resp->FromSlotItem = plr.plr.Inven[itemmove->iFromSlotNum];
|
||||
}
|
||||
|
||||
//eTo 0 means to equip, 1 means to inventory
|
||||
if (itemmove->eTo == 0) {
|
||||
resp->ToSlotItem = plr.plr.Equip[itemmove->iToSlotNum];
|
||||
plr.plr.Equip[itemmove->iToSlotNum] = resp->FromSlotItem;
|
||||
} else {
|
||||
resp->ToSlotItem = plr.plr.Inven[itemmove->iToSlotNum];
|
||||
plr.plr.Inven[itemmove->iToSlotNum] = resp->FromSlotItem;
|
||||
}
|
||||
|
||||
if (itemmove->eFrom == 0) {
|
||||
plr.plr.Equip[itemmove->iFromSlotNum] = resp->ToSlotItem;
|
||||
|
||||
sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
|
||||
|
||||
resp2->iPC_ID = plr.plr.iID;
|
||||
resp2->iEquipSlotNum = resp->iToSlotNum;
|
||||
resp2->EquipSlotItem = resp->ToSlotItem;
|
||||
|
||||
for (CNSocket* otherSock : plr.viewable) {
|
||||
otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey()));
|
||||
}
|
||||
|
||||
} else {
|
||||
plr.plr.Inven[itemmove->iFromSlotNum] = resp->ToSlotItem;
|
||||
}
|
||||
|
||||
PlayerManager::players[sock] = plr;
|
||||
|
||||
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC), sock->getFEKey()));
|
||||
}
|
11
src/ItemManager.hpp
Normal file
11
src/ItemManager.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef _IM_HPP
|
||||
#define _IM_HPP
|
||||
|
||||
#include "CNShardServer.hpp"
|
||||
|
||||
namespace ItemManager {
|
||||
void init();
|
||||
void itemMoveHandler(CNSocket* sock, CNPacketData* data);
|
||||
}
|
||||
|
||||
#endif
|
@ -20,6 +20,7 @@ struct Player {
|
||||
|
||||
int x, y, z, angle;
|
||||
sItemBase Equip[AEQUIP_COUNT];
|
||||
sItemBase Inven[AINVEN_COUNT];
|
||||
};
|
||||
|
||||
#endif
|
@ -2,6 +2,7 @@
|
||||
#include "CNShardServer.hpp"
|
||||
#include "PlayerManager.hpp"
|
||||
#include "ChatManager.hpp"
|
||||
#include "ItemManager.hpp"
|
||||
#include "NanoManager.hpp"
|
||||
#include "NPCManager.hpp"
|
||||
|
||||
@ -30,6 +31,7 @@ int main() {
|
||||
std::cout << "[INFO] Intializing Packet Managers..." << std::endl;
|
||||
PlayerManager::init();
|
||||
ChatManager::init();
|
||||
ItemManager::init();
|
||||
NanoManager::init();
|
||||
NPCManager::init();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* genstructs.py */
|
||||
|
||||
#define AEQUIP_COUNT 9
|
||||
#define AINVEN_COUNT 50
|
||||
|
||||
#pragma pack(push)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user