forked from teamnwah/openmw-tes3coop
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;
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ void LocalPlayer::Update()
|
|||
updateDeadState();
|
||||
updateInventory();
|
||||
updateBaseStats();
|
||||
updateAttributesAndSkills();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
@ -276,19 +311,6 @@ void LocalPlayer::updateDeadState(bool forceUpdate)
|
|||
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()
|
||||
{
|
||||
return mwmp::Main::get().getNetworking();
|
||||
|
|
Loading…
Reference in a new issue