forked from mirror/openmw-tes3mp
Send attributes and skills to server whenever they change
This commit is contained in:
parent
ce5553cda6
commit
03d6e0cb62
2 changed files with 47 additions and 15 deletions
|
@ -169,9 +169,19 @@ void Networking::Update(RakNet::Packet *packet)
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ID_GAME_UPDATE_SKILLS:
|
case ID_GAME_ATTRIBUTE:
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!player->CreatureStats()->mDead)
|
||||||
|
{
|
||||||
|
myPacket->Read(player);
|
||||||
|
myPacket->Send(player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ID_GAME_SKILL:
|
||||||
{
|
{
|
||||||
DEBUG_PRINTF("ID_GAME_UPDATE_SKILLS\n");
|
|
||||||
|
|
||||||
if (!player->CreatureStats()->mDead)
|
if (!player->CreatureStats()->mDead)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,6 +50,7 @@ void LocalPlayer::Update()
|
||||||
updateDeadState();
|
updateDeadState();
|
||||||
updateInventory();
|
updateInventory();
|
||||||
updateBaseStats();
|
updateBaseStats();
|
||||||
|
updateAttributesAndSkills();
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::Ptr LocalPlayer::GetPlayerPtr()
|
MWWorld::Ptr LocalPlayer::GetPlayerPtr()
|
||||||
|
@ -89,6 +90,40 @@ void LocalPlayer::updateBaseStats(bool forceUpdate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalPlayer::updateAttributesAndSkills(bool forceUpdate)
|
||||||
|
{
|
||||||
|
MWWorld::Ptr player = GetPlayerPtr();
|
||||||
|
|
||||||
|
const MWMechanics::NpcStats &_npcStats = player.getClass().getNpcStats(player);
|
||||||
|
|
||||||
|
bool isUpdatingSkills = false;
|
||||||
|
bool isUpdatingAttributes = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < 27; ++i) {
|
||||||
|
|
||||||
|
if (_npcStats.getSkill(i).getBase() != NpcStats()->mSkills[i].mBase) {
|
||||||
|
_npcStats.getSkill(i).writeState(NpcStats()->mSkills[i]);
|
||||||
|
isUpdatingSkills = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; ++i) {
|
||||||
|
|
||||||
|
if (_npcStats.getAttribute(i).getBase() != CreatureStats()->mAttributes[i].mBase) {
|
||||||
|
_npcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]);
|
||||||
|
isUpdatingAttributes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isUpdatingSkills) {
|
||||||
|
GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isUpdatingAttributes) {
|
||||||
|
GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LocalPlayer::updatePosition(bool forceUpdate)
|
void LocalPlayer::updatePosition(bool forceUpdate)
|
||||||
{
|
{
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
@ -276,19 +311,6 @@ void LocalPlayer::updateDeadState(bool forceUpdate)
|
||||||
isDead = false;
|
isDead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::updateAttributesAndSkills(bool forceUpdate)
|
|
||||||
{
|
|
||||||
MWWorld::Ptr player = GetPlayerPtr();
|
|
||||||
|
|
||||||
const MWMechanics::NpcStats &_npcStats = player.getClass().getNpcStats(player);
|
|
||||||
|
|
||||||
for (int i = 0; i < PacketAttributesAndStats::StatsCount; ++i)
|
|
||||||
_npcStats.getSkill(i).writeState( NpcStats()->mSkills[i]);
|
|
||||||
|
|
||||||
for (int i = 0; i < PacketAttributesAndStats::AttributesCount; ++i)
|
|
||||||
_npcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Networking *LocalPlayer::GetNetworking()
|
Networking *LocalPlayer::GetNetworking()
|
||||||
{
|
{
|
||||||
return mwmp::Main::get().getNetworking();
|
return mwmp::Main::get().getNetworking();
|
||||||
|
|
Loading…
Reference in a new issue