1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 18:19:55 +00:00

Send spellbook in LocalPlayer CharGen & change UPDATE action name to SET

This commit is contained in:
David Cernat 2017-01-20 09:07:07 +02:00
parent 0f7748d9d2
commit 83277a1512
7 changed files with 39 additions and 25 deletions

View file

@ -75,7 +75,7 @@ void ItemFunctions::ClearInventory(unsigned short pid) noexcept
GET_PLAYER(pid, player, );
player->packetItemsBuffer.items.clear();
player->packetItemsBuffer.action = PacketItems::UPDATE;
player->packetItemsBuffer.action = PacketItems::SET;
}
bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* itemId)

View file

@ -44,7 +44,7 @@ void SpellFunctions::ClearSpellbook(unsigned short pid) noexcept
GET_PLAYER(pid, player, );
player->packetSpellsBuffer.spells.clear();
player->packetSpellsBuffer.action = PacketSpells::UPDATE;
player->packetSpellsBuffer.action = PacketSpells::SET;
}
const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexcept

View file

@ -27,9 +27,6 @@
#include "actorutil.hpp"
#include "combat.hpp"
#include "../mwmp/Main.hpp"
#include "../mwmp/LocalPlayer.hpp"
namespace
{
@ -216,15 +213,8 @@ namespace MWMechanics
std::vector<std::string> selectedSpells = autoCalcPlayerSpells(skills, attributes, race);
for (std::vector<std::string>::iterator it = selectedSpells.begin(); it != selectedSpells.end(); ++it)
{
creatureStats.getSpells().add(*it);
// Added by tes3mp
//
// LocalPlayer has gained a spell, so send a packet with it
mwmp::Main::get().getLocalPlayer()->sendSpellAddition(*it);
}
// forced update and current value adjustments
mActors.updateActor (ptr, 0);

View file

@ -133,6 +133,7 @@ bool LocalPlayer::charGenThread()
updateSkills(true);
updateLevel(true);
sendClass();
sendSpellbook();
getNetworking()->getPlayerPacket(ID_GAME_CHARGEN)->Send(this);
}
@ -620,7 +621,7 @@ void LocalPlayer::updateDrawStateAndFlags(bool forceUpdate)
void LocalPlayer::addItems()
{
MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
for (unsigned int i = 0; i < packetItems.count; i++)
@ -634,7 +635,7 @@ void LocalPlayer::addItems()
void LocalPlayer::addSpells()
{
MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells();
for (vector<ESM::Spell>::const_iterator spell = packetSpells.spells.begin(); spell != packetSpells.spells.end(); spell++)
@ -644,7 +645,7 @@ void LocalPlayer::addSpells()
void LocalPlayer::removeItems()
{
MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
for (unsigned int i = 0; i < packetItems.count; i++)
@ -656,7 +657,7 @@ void LocalPlayer::removeItems()
void LocalPlayer::removeSpells()
{
MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells();
for (vector<ESM::Spell>::const_iterator spell = packetSpells.spells.begin(); spell != packetSpells.spells.end(); spell++)
@ -855,7 +856,7 @@ void LocalPlayer::setEquipment()
void LocalPlayer::setInventory()
{
MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
// Clear items in inventory
@ -873,7 +874,7 @@ void LocalPlayer::setInventory()
void LocalPlayer::setSpellbook()
{
MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells();
// Clear spells in spellbook, while ignoring abilities, powers, etc.
@ -931,10 +932,32 @@ void LocalPlayer::sendInventory()
}
packetItems.count = (unsigned int) packetItems.items.size();
packetItems.action = PacketItems::UPDATE;
packetItems.action = PacketItems::SET;
Main::get().getNetworking()->getPlayerPacket(ID_GAME_INVENTORY)->Send(this);
}
void LocalPlayer::sendSpellbook()
{
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells();
packetSpells.spells.clear();
// Send spells in spellbook, while ignoring abilities, powers, etc.
for (MWMechanics::Spells::TIterator iter = ptrSpells.begin(); iter != ptrSpells.end(); ++iter)
{
const ESM::Spell *spell = iter->first;
if (spell->mData.mType == ESM::Spell::ST_Spell)
{
packetSpells.spells.push_back(*spell);
}
}
packetSpells.action = PacketSpells::SET;
Main::get().getNetworking()->getPlayerPacket(ID_GAME_SPELLBOOK)->Send(this);
}
void LocalPlayer::sendSpellAddition(std::string id)
{
if (id.find("$dynamic") != string::npos) // skip custom spells

View file

@ -55,6 +55,7 @@ namespace mwmp
void sendClass();
void sendInventory();
void sendSpellbook();
void sendSpellAddition(std::string id);
void sendSpellAddition(const ESM::Spell &spell);
void sendSpellRemoval(std::string id);

View file

@ -309,7 +309,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
{
getLocalPlayer()->removeItems();
}
else // PacketItems::UPDATE
else // PacketItems::SET
{
getLocalPlayer()->setInventory();
}
@ -338,7 +338,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
{
getLocalPlayer()->removeSpells();
}
else // PacketSpells::UPDATE
else // PacketSpells::SET
{
getLocalPlayer()->setSpellbook();
}

View file

@ -52,11 +52,11 @@ namespace mwmp
unsigned int count;
enum ACTION_TYPE
{
UPDATE = 0,
SET = 0,
ADD,
REMOVE
};
int action; //0 - Full update, 1 - Add item, 2 - Remove item
int action; //0 - Clear and set in entirety, 1 - Add item, 2 - Remove item
};
struct PacketSpells
@ -65,11 +65,11 @@ namespace mwmp
unsigned int count;
enum ACTION_TYPE
{
UPDATE = 0,
SET = 0,
ADD,
REMOVE
};
int action; //0 - Full update, 1 - Add spell, 2 - Remove spell
int action; //0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell
};
class BasePlayer