mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
Implement sending of ID_GAME_SPELLBOOK from client
This commit is contained in:
parent
6ea5f08e9c
commit
95efb77e53
8 changed files with 91 additions and 0 deletions
|
@ -236,6 +236,8 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
|
||||||
DEBUG_PRINTF("ID_GAME_SPELLBOOK\n");
|
DEBUG_PRINTF("ID_GAME_SPELLBOOK\n");
|
||||||
myPacket->Read(player);
|
myPacket->Read(player);
|
||||||
|
|
||||||
|
Script::Call<Script::CallbackIdentity("OnPlayerChangeSpellbook")>(player->getId());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ public:
|
||||||
{"OnPlayerChangeLevel", Function<void, unsigned short>()},
|
{"OnPlayerChangeLevel", Function<void, unsigned short>()},
|
||||||
{"OnPlayerChangeEquipment", Function<void, unsigned short>()},
|
{"OnPlayerChangeEquipment", Function<void, unsigned short>()},
|
||||||
{"OnPlayerChangeInventory", Function<void, unsigned short>()},
|
{"OnPlayerChangeInventory", Function<void, unsigned short>()},
|
||||||
|
{"OnPlayerChangeSpellbook", Function<void, unsigned short>()},
|
||||||
{"OnPlayerSendMessage", Function<bool, unsigned short, const char*>()},
|
{"OnPlayerSendMessage", Function<bool, unsigned short, const char*>()},
|
||||||
{"OnPlayerEndCharGen", Function<void, unsigned short>()},
|
{"OnPlayerEndCharGen", Function<void, unsigned short>()},
|
||||||
{"OnGUIAction", Function<void, unsigned short, int, const char*>()}
|
{"OnGUIAction", Function<void, unsigned short, int, const char*>()}
|
||||||
|
|
|
@ -845,6 +845,30 @@ void LocalPlayer::sendInventory()
|
||||||
Main::get().getNetworking()->getPlayerPacket(ID_GAME_INVENTORY)->Send(this);
|
Main::get().getNetworking()->getPlayerPacket(ID_GAME_INVENTORY)->Send(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalPlayer::sendSpellAddition(std::string id)
|
||||||
|
{
|
||||||
|
spellbook.spells.clear();
|
||||||
|
|
||||||
|
mwmp::Spell spell;
|
||||||
|
spell.id = id;
|
||||||
|
spellbook.spells.push_back(spell);
|
||||||
|
|
||||||
|
spellbook.action = Spellbook::ADD;
|
||||||
|
Main::get().getNetworking()->getPlayerPacket(ID_GAME_SPELLBOOK)->Send(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPlayer::sendSpellRemoval(std::string id)
|
||||||
|
{
|
||||||
|
spellbook.spells.clear();
|
||||||
|
|
||||||
|
mwmp::Spell spell;
|
||||||
|
spell.id = id;
|
||||||
|
spellbook.spells.push_back(spell);
|
||||||
|
|
||||||
|
spellbook.action = Spellbook::REMOVE;
|
||||||
|
Main::get().getNetworking()->getPlayerPacket(ID_GAME_SPELLBOOK)->Send(this);
|
||||||
|
}
|
||||||
|
|
||||||
void LocalPlayer::sendAttack(Attack::TYPE type)
|
void LocalPlayer::sendAttack(Attack::TYPE type)
|
||||||
{
|
{
|
||||||
MWMechanics::DrawState_ state = getPlayerPtr().getClass().getNpcStats(getPlayerPtr()).getDrawState();
|
MWMechanics::DrawState_ state = getPlayerPtr().getClass().getNpcStats(getPlayerPtr()).getDrawState();
|
||||||
|
|
|
@ -47,6 +47,8 @@ namespace mwmp
|
||||||
|
|
||||||
void sendClass();
|
void sendClass();
|
||||||
void sendInventory();
|
void sendInventory();
|
||||||
|
void sendSpellAddition(std::string id);
|
||||||
|
void sendSpellRemoval(std::string id);
|
||||||
void sendAttack(Attack::TYPE type);
|
void sendAttack(Attack::TYPE type);
|
||||||
|
|
||||||
void prepareAttack(Attack::TYPE type, bool state);
|
void prepareAttack(Attack::TYPE type, bool state);
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "../mwmp/Main.hpp"
|
||||||
|
|
||||||
#include <components/esm/loadnpc.hpp>
|
#include <components/esm/loadnpc.hpp>
|
||||||
|
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
@ -442,6 +444,11 @@ namespace MWScript
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (id);
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (id);
|
||||||
|
|
||||||
ptr.getClass().getCreatureStats (ptr).getSpells().add (id);
|
ptr.getClass().getCreatureStats (ptr).getSpells().add (id);
|
||||||
|
|
||||||
|
// Added by tes3mp
|
||||||
|
//
|
||||||
|
// LocalPlayer has gained a spell, so send a packet with it
|
||||||
|
mwmp::Main::get().getLocalPlayer()->sendSpellAddition(id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -466,6 +473,11 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
wm->unsetSelectedSpell();
|
wm->unsetSelectedSpell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Added by tes3mp
|
||||||
|
//
|
||||||
|
// LocalPlayer has lost a spell, so send a packet with it
|
||||||
|
mwmp::Main::get().getLocalPlayer()->sendSpellRemoval(id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,24 @@ namespace mwmp
|
||||||
int action; //0 - FullUpdate, 1 - AddItem, 2 - RemoveItem
|
int action; //0 - FullUpdate, 1 - AddItem, 2 - RemoveItem
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Spell
|
||||||
|
{
|
||||||
|
std::string id;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Spellbook
|
||||||
|
{
|
||||||
|
std::vector<Spell> spells;
|
||||||
|
unsigned int count;
|
||||||
|
enum ACTION_TYPE
|
||||||
|
{
|
||||||
|
UPDATE = 0,
|
||||||
|
ADD,
|
||||||
|
REMOVE
|
||||||
|
};
|
||||||
|
int action; //0 - Update, 1 - Add, 2 - Remove
|
||||||
|
};
|
||||||
|
|
||||||
class BasePlayer
|
class BasePlayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -89,6 +107,7 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
inventory.action = 0;
|
inventory.action = 0;
|
||||||
inventory.count = 0;
|
inventory.count = 0;
|
||||||
|
spellbook.action = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BasePlayer()
|
BasePlayer()
|
||||||
|
@ -174,6 +193,7 @@ namespace mwmp
|
||||||
int day;
|
int day;
|
||||||
double hour;
|
double hour;
|
||||||
Inventory inventory;
|
Inventory inventory;
|
||||||
|
Spellbook spellbook;
|
||||||
bool consoleAllowed;
|
bool consoleAllowed;
|
||||||
bool ignorePosPacket;
|
bool ignorePosPacket;
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,18 @@ void PacketInventory::Packet(RakNet::BitStream *bs, BasePlayer *player, bool sen
|
||||||
PlayerPacket::Packet(bs, player, send);
|
PlayerPacket::Packet(bs, player, send);
|
||||||
|
|
||||||
RW(player->inventory.action, send);
|
RW(player->inventory.action, send);
|
||||||
|
|
||||||
if (!send)
|
if (!send)
|
||||||
player->inventory.items.clear();
|
player->inventory.items.clear();
|
||||||
else
|
else
|
||||||
player->inventory.count = (unsigned int) (player->inventory.items.size());
|
player->inventory.count = (unsigned int) (player->inventory.items.size());
|
||||||
|
|
||||||
RW(player->inventory.count, send);
|
RW(player->inventory.count, send);
|
||||||
|
|
||||||
for (int i = 0; i < player->inventory.count; i++)
|
for (int i = 0; i < player->inventory.count; i++)
|
||||||
{
|
{
|
||||||
Item item;
|
Item item;
|
||||||
|
|
||||||
if (send)
|
if (send)
|
||||||
{
|
{
|
||||||
item = player->inventory.items[i];
|
item = player->inventory.items[i];
|
||||||
|
|
|
@ -12,4 +12,30 @@ PacketSpellbook::PacketSpellbook(RakNet::RakPeerInterface *peer) : PlayerPacket(
|
||||||
void PacketSpellbook::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
void PacketSpellbook::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
||||||
{
|
{
|
||||||
PlayerPacket::Packet(bs, player, send);
|
PlayerPacket::Packet(bs, player, send);
|
||||||
|
|
||||||
|
RW(player->spellbook.action, send);
|
||||||
|
|
||||||
|
if (!send)
|
||||||
|
player->spellbook.spells.clear();
|
||||||
|
else
|
||||||
|
player->spellbook.count = (unsigned int) (player->spellbook.spells.size());
|
||||||
|
|
||||||
|
RW(player->spellbook.count, send);
|
||||||
|
|
||||||
|
for (int i = 0; i < player->spellbook.count; i++)
|
||||||
|
{
|
||||||
|
Spell spell;
|
||||||
|
|
||||||
|
if (send)
|
||||||
|
{
|
||||||
|
spell = player->spellbook.spells[i];
|
||||||
|
RW(spell.id, send);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RW(spell.id, send);
|
||||||
|
player->spellbook.spells.push_back(spell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue