forked from mirror/openmw-tes3mp
Add and use SendInventory() method in LocalPlayer, and clarify some code
This commit is contained in:
parent
c5c72a3b17
commit
eedd40328a
2 changed files with 45 additions and 24 deletions
|
@ -202,6 +202,10 @@ void LocalPlayer::updateSkills(bool forceUpdate)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr player = getPlayerPtr();
|
MWWorld::Ptr player = getPlayerPtr();
|
||||||
const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
|
const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
|
||||||
|
|
||||||
|
// Track whether skills have changed their values, but not whether
|
||||||
|
// progress towards skill increases has changed (to not spam server
|
||||||
|
// with packets every time tiny progress is made)
|
||||||
bool skillsChanged = false;
|
bool skillsChanged = false;
|
||||||
|
|
||||||
for (int i = 0; i < 27; ++i)
|
for (int i = 0; i < 27; ++i)
|
||||||
|
@ -211,8 +215,8 @@ void LocalPlayer::updateSkills(bool forceUpdate)
|
||||||
ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]);
|
ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]);
|
||||||
skillsChanged = true;
|
skillsChanged = true;
|
||||||
}
|
}
|
||||||
// If we only have skill progress, update the state for relevant skills
|
// If we only have skill progress, remember it for future packets,
|
||||||
// but don't send a packet just because of this (to avoid spam)
|
// but don't send a packet just because of this
|
||||||
else if (ptrNpcStats.getSkill(i).getProgress() != NpcStats()->mSkills[i].mProgress)
|
else if (ptrNpcStats.getSkill(i).getProgress() != NpcStats()->mSkills[i].mProgress)
|
||||||
{
|
{
|
||||||
ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]);
|
ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]);
|
||||||
|
@ -415,18 +419,20 @@ void LocalPlayer::updateEquipped(bool forceUpdate)
|
||||||
void LocalPlayer::updateInventory(bool forceUpdate)
|
void LocalPlayer::updateInventory(bool forceUpdate)
|
||||||
{
|
{
|
||||||
static bool invChanged = false;
|
static bool invChanged = false;
|
||||||
|
|
||||||
if (forceUpdate)
|
if (forceUpdate)
|
||||||
invChanged = true;
|
invChanged = true;
|
||||||
|
|
||||||
MWWorld::Ptr player = getPlayerPtr();
|
MWWorld::Ptr ptrPlayer = getPlayerPtr();
|
||||||
MWWorld::InventoryStore &invStore = player.getClass().getInventoryStore(player);
|
MWWorld::InventoryStore &ptrInventory = ptrPlayer.getClass().getInventoryStore(ptrPlayer);
|
||||||
mwmp::Item item;
|
mwmp::Item item;
|
||||||
|
|
||||||
if (!invChanged)
|
if (!invChanged)
|
||||||
|
{
|
||||||
for (vector<Item>::iterator iter = inventory.items.begin(); iter != inventory.items.end(); ++iter)
|
for (vector<Item>::iterator iter = inventory.items.begin(); iter != inventory.items.end(); ++iter)
|
||||||
{
|
{
|
||||||
MWWorld::ContainerStoreIterator result(invStore.begin());
|
MWWorld::ContainerStoreIterator result(ptrInventory.begin());
|
||||||
for (; result != invStore.end(); ++result)
|
for (; result != ptrInventory.end(); ++result)
|
||||||
{
|
{
|
||||||
item.refid = result->getCellRef().getRefId();
|
item.refid = result->getCellRef().getRefId();
|
||||||
if (item.refid.find("$dynamic") != string::npos) // skip generated items (self enchanted for e.g.)
|
if (item.refid.find("$dynamic") != string::npos) // skip generated items (self enchanted for e.g.)
|
||||||
|
@ -438,14 +444,17 @@ void LocalPlayer::updateInventory(bool forceUpdate)
|
||||||
if (item == (*iter))
|
if (item == (*iter))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result == invStore.end())
|
if (result == ptrInventory.end())
|
||||||
{
|
{
|
||||||
invChanged = true;
|
invChanged = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!invChanged)
|
if (!invChanged)
|
||||||
for (MWWorld::ContainerStoreIterator iter(invStore.begin()); iter != invStore.end(); ++iter)
|
{
|
||||||
|
for (MWWorld::ContainerStoreIterator iter(ptrInventory.begin()); iter != ptrInventory.end(); ++iter)
|
||||||
{
|
{
|
||||||
item.refid = iter->getCellRef().getRefId();
|
item.refid = iter->getCellRef().getRefId();
|
||||||
if (item.refid.find("$dynamic") != string::npos) // skip generated items (self enchanted for e.g.)
|
if (item.refid.find("$dynamic") != string::npos) // skip generated items (self enchanted for e.g.)
|
||||||
|
@ -468,28 +477,14 @@ void LocalPlayer::updateInventory(bool forceUpdate)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!invChanged)
|
if (!invChanged)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
invChanged = false;
|
invChanged = false;
|
||||||
|
|
||||||
inventory.items.clear();
|
sendInventory();
|
||||||
for (MWWorld::ContainerStoreIterator iter(invStore.begin()); iter != invStore.end(); ++iter)
|
|
||||||
{
|
|
||||||
item.refid = iter->getCellRef().getRefId();
|
|
||||||
if (item.refid.find("$dynamic") != string::npos) // skip generated items (self enchanted for e.g.)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
item.count = iter->getRefData().getCount();
|
|
||||||
item.health = iter->getCellRef().getCharge();
|
|
||||||
|
|
||||||
inventory.items.push_back(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
inventory.count = (unsigned int) inventory.items.size();
|
|
||||||
inventory.action = Inventory::UPDATE;
|
|
||||||
Main::get().getNetworking()->getPlayerPacket(ID_GAME_INVENTORY)->Send(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::updateAttackState(bool forceUpdate)
|
void LocalPlayer::updateAttackState(bool forceUpdate)
|
||||||
|
@ -813,6 +808,31 @@ void LocalPlayer::sendClass()
|
||||||
getNetworking()->getPlayerPacket(ID_GAME_CHARCLASS)->Send(this);
|
getNetworking()->getPlayerPacket(ID_GAME_CHARCLASS)->Send(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalPlayer::sendInventory()
|
||||||
|
{
|
||||||
|
MWWorld::Ptr ptrPlayer = getPlayerPtr();
|
||||||
|
MWWorld::InventoryStore &ptrInventory = ptrPlayer.getClass().getInventoryStore(ptrPlayer);
|
||||||
|
mwmp::Item item;
|
||||||
|
|
||||||
|
inventory.items.clear();
|
||||||
|
|
||||||
|
for (MWWorld::ContainerStoreIterator iter(ptrInventory.begin()); iter != ptrInventory.end(); ++iter)
|
||||||
|
{
|
||||||
|
item.refid = iter->getCellRef().getRefId();
|
||||||
|
if (item.refid.find("$dynamic") != string::npos) // skip generated items (self enchanted for e.g.)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
item.count = iter->getRefData().getCount();
|
||||||
|
item.health = iter->getCellRef().getCharge();
|
||||||
|
|
||||||
|
inventory.items.push_back(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.count = (unsigned int)inventory.items.size();
|
||||||
|
inventory.action = Inventory::UPDATE;
|
||||||
|
Main::get().getNetworking()->getPlayerPacket(ID_GAME_INVENTORY)->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();
|
||||||
|
|
|
@ -46,6 +46,7 @@ namespace mwmp
|
||||||
void setInventory();
|
void setInventory();
|
||||||
|
|
||||||
void sendClass();
|
void sendClass();
|
||||||
|
void sendInventory();
|
||||||
void sendAttack(Attack::TYPE type);
|
void sendAttack(Attack::TYPE type);
|
||||||
|
|
||||||
void prepareAttack(Attack::TYPE type, bool state);
|
void prepareAttack(Attack::TYPE type, bool state);
|
||||||
|
|
Loading…
Reference in a new issue