[General] Add and use PlayerBounty packet and matching script functions

0.6.1
David Cernat 8 years ago
parent 6658531713
commit 7b07d6651f

@ -113,14 +113,14 @@ source_group(tes3mp-server\\processors\\actor FILES ${PROCESSORS_ACTOR})
set(PROCESSORS_PLAYER
processors/player/ProcessorChatMsg.hpp processors/player/ProcessorGUIMessageBox.hpp
processors/player/ProcessorPlayerAnimFlags.hpp processors/player/ProcessorPlayerAttack.hpp
processors/player/ProcessorPlayerAttribute.hpp processors/player/ProcessorPlayerCellChange.hpp
processors/player/ProcessorPlayerCellState.hpp processors/player/ProcessorPlayerCharClass.hpp
processors/player/ProcessorPlayerCharGen.hpp processors/player/ProcessorPlayerDeath.hpp
processors/player/ProcessorPlayerEquipment.hpp processors/player/ProcessorPlayerInventory.hpp
processors/player/ProcessorPlayerJournal.hpp processors/player/ProcessorPlayerLevel.hpp
processors/player/ProcessorPlayerPos.hpp processors/player/ProcessorPlayerResurrect.hpp
processors/player/ProcessorPlayerSkill.hpp processors/player/ProcessorPlayerSpellbook.hpp
processors/player/ProcessorPlayerStatsDynamic.hpp
processors/player/ProcessorPlayerAttribute.hpp processors/player/ProcessorPlayerBounty.hpp
processors/player/ProcessorPlayerCellChange.hpp processors/player/ProcessorPlayerCellState.hpp
processors/player/ProcessorPlayerCharClass.hpp processors/player/ProcessorPlayerCharGen.hpp
processors/player/ProcessorPlayerDeath.hpp processors/player/ProcessorPlayerEquipment.hpp
processors/player/ProcessorPlayerInventory.hpp processors/player/ProcessorPlayerJournal.hpp
processors/player/ProcessorPlayerLevel.hpp processors/player/ProcessorPlayerPos.hpp
processors/player/ProcessorPlayerResurrect.hpp processors/player/ProcessorPlayerSkill.hpp
processors/player/ProcessorPlayerSpellbook.hpp processors/player/ProcessorPlayerStatsDynamic.hpp
)
source_group(tes3mp-server\\processors\\player FILES ${PROCESSORS_PLAYER})

@ -11,6 +11,7 @@
#include "processors/player/ProcessorPlayerAttribute.hpp"
#include "processors/player/ProcessorPlayerSkill.hpp"
#include "processors/player/ProcessorPlayerLevel.hpp"
#include "processors/player/ProcessorPlayerBounty.hpp"
#include "processors/player/ProcessorPlayerEquipment.hpp"
#include "processors/player/ProcessorPlayerInventory.hpp"
#include "processors/player/ProcessorPlayerSpellbook.hpp"
@ -64,6 +65,7 @@ void ProcessorInitializer()
PlayerProcessor::AddProcessor(new ProcessorPlayerAttribute());
PlayerProcessor::AddProcessor(new ProcessorPlayerSkill());
PlayerProcessor::AddProcessor(new ProcessorPlayerLevel());
PlayerProcessor::AddProcessor(new ProcessorPlayerBounty());
PlayerProcessor::AddProcessor(new ProcessorPlayerEquipment());
PlayerProcessor::AddProcessor(new ProcessorPlayerInventory());
PlayerProcessor::AddProcessor(new ProcessorPlayerSpellbook());

@ -134,7 +134,7 @@ void StatsFunctions::SetIsMale(unsigned short pid, int value) noexcept
int StatsFunctions::GetLevel(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0.0f);
GET_PLAYER(pid, player, 0);
return player->creatureStats.mLevel;
}
@ -150,7 +150,7 @@ void StatsFunctions::SetLevel(unsigned short pid, int value) noexcept
int StatsFunctions::GetLevelProgress(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0.0f);
GET_PLAYER(pid, player, 0);
return player->npcStats.mLevelProgress;
}
@ -432,7 +432,7 @@ int StatsFunctions::GetSkillIncrease(unsigned short pid, unsigned int attribute)
return player->npcStats.mSkillIncrease[attribute];
}
void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute, int value) noexcept // TODO: need packet for transmit it
void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute, int value) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
@ -443,6 +443,22 @@ void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute
player->npcStats.mSkillIncrease[attribute] = value;
}
int StatsFunctions::GetBounty(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->npcStats.mBounty;
}
void StatsFunctions::SetBounty(unsigned short pid, int value) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
player->npcStats.mBounty = value;
}
void StatsFunctions::SetCharGenStage(unsigned short pid, int start, int end) noexcept
{
Player *player;
@ -511,3 +527,13 @@ void StatsFunctions::SendLevel(unsigned short pid) noexcept
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_LEVEL)->Send(false);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_LEVEL)->Send(true);
}
void StatsFunctions::SendBounty(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOUNTY)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOUNTY)->Send(false);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOUNTY)->Send(true);
}

@ -58,14 +58,17 @@
{"GetMagickaCurrent", StatsFunctions::GetMagickaCurrent},\
{"SetMagickaCurrent", StatsFunctions::SetMagickaCurrent},\
\
{"SetFatigueBase", StatsFunctions::SetFatigueBase},\
{"GetFatigueBase", StatsFunctions::GetFatigueBase},\
{"SetFatigueCurrent", StatsFunctions::SetFatigueCurrent},\
{"SetFatigueBase", StatsFunctions::SetFatigueBase},\
{"GetFatigueCurrent", StatsFunctions::GetFatigueCurrent},\
{"SetFatigueCurrent", StatsFunctions::SetFatigueCurrent},\
\
{"GetSkillIncrease", StatsFunctions::GetSkillIncrease},\
{"SetSkillIncrease", StatsFunctions::SetSkillIncrease},\
\
{"GetBounty", StatsFunctions::GetBounty},\
{"SetBounty", StatsFunctions::SetBounty},\
\
{"SetCharGenStage", StatsFunctions::SetCharGenStage},\
{"Resurrect", StatsFunctions::Resurrect},\
{"SendBaseInfo", StatsFunctions::SendBaseInfo},\
@ -73,7 +76,8 @@
{"SendStatsDynamic", StatsFunctions::SendStatsDynamic},\
{"SendAttributes", StatsFunctions::SendAttributes},\
{"SendSkills", StatsFunctions::SendSkills},\
{"SendLevel", StatsFunctions::SendLevel}
{"SendLevel", StatsFunctions::SendLevel},\
{"SendBounty", StatsFunctions::SendBounty}
class StatsFunctions
{
@ -138,6 +142,9 @@ public:
static int GetSkillIncrease(unsigned short pid, unsigned int pos) noexcept;
static void SetSkillIncrease(unsigned short pid, unsigned int pos, int value) noexcept;
static int GetBounty(unsigned short pid) noexcept;
static void SetBounty(unsigned short pid, int value) noexcept;
static void Resurrect(unsigned short pid);
static void SetCharGenStage(unsigned short pid, int start, int end) noexcept;
static void SendBaseInfo(unsigned short pid) noexcept;
@ -146,6 +153,7 @@ public:
static void SendAttributes(unsigned short pid) noexcept;
static void SendSkills(unsigned short pid) noexcept;
static void SendLevel(unsigned short pid) noexcept;
static void SendBounty(unsigned short pid) noexcept;
};
#endif //OPENMW_STATAPI_HPP

@ -119,6 +119,7 @@ public:
{"OnPlayerAttributesChange", Function<void, unsigned short>()},
{"OnPlayerSkillsChange", Function<void, unsigned short>()},
{"OnPlayerLevelChange", Function<void, unsigned short>()},
{"OnPlayerBountyChange", Function<void, unsigned short>()},
{"OnPlayerEquipmentChange", Function<void, unsigned short>()},
{"OnPlayerInventoryChange", Function<void, unsigned short>()},
{"OnPlayerSpellbookChange", Function<void, unsigned short>()},

@ -0,0 +1,24 @@
#ifndef OPENMW_PROCESSORPLAYERBOUNTY_HPP
#define OPENMW_PROCESSORPLAYERBOUNTY_HPP
#include "apps/openmw-mp/PlayerProcessor.hpp"
namespace mwmp
{
class ProcessorPlayerBounty : public PlayerProcessor
{
public:
ProcessorPlayerBounty()
{
BPP_INIT(ID_PLAYER_BOUNTY)
}
void Do(PlayerPacket &packet, Player &player) override
{
Script::Call<Script::CallbackIdentity("OnPlayerBountyChange")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYERBOUNTY_HPP

@ -106,11 +106,11 @@ add_openmw_dir (mwmp\\processors\\actor ProcessorActorAnimFlags ProcessorActorAn
)
add_openmw_dir (mwmp\\processors\\player ProcessorChatMessage ProcessorGameConsole ProcessorGameTime ProcessorGUIMessageBox
ProcessorHandshake ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerCellChange
ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerAnimFlags
ProcessorPlayerStatsDynamic ProcessorPlayerEquipment ProcessorPlayerInventory ProcessorPlayerJournal
ProcessorPlayerLevel ProcessorPlayerPos ProcessorPlayerResurrect ProcessorPlayerSkill ProcessorPlayerSpellbook
ProcessorUserDisconnected ProcessorUserMyID
ProcessorHandshake ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerBounty
ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath
ProcessorPlayerAnimFlags ProcessorPlayerStatsDynamic ProcessorPlayerEquipment ProcessorPlayerInventory
ProcessorPlayerJournal ProcessorPlayerLevel ProcessorPlayerPos ProcessorPlayerResurrect ProcessorPlayerSkill
ProcessorPlayerSpellbook ProcessorUserDisconnected ProcessorUserMyID
)
add_openmw_dir (mwmp\\processors\\world BaseObjectProcessor ProcessorContainer ProcessorDoorState ProcessorMusicPlay

@ -79,6 +79,7 @@ void LocalPlayer::update()
updateAttributes();
updateSkills();
updateLevel();
updateBounty();
}
void LocalPlayer::charGen(int stageFirst, int stageEnd)
@ -267,11 +268,11 @@ void LocalPlayer::updateSkills(bool forceUpdate)
void LocalPlayer::updateLevel(bool forceUpdate)
{
MWWorld::Ptr player = getPlayerPtr();
const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
const MWMechanics::CreatureStats &ptrCreatureStats = player.getClass().getCreatureStats(player);
if (ptrNpcStats.getLevel() != creatureStats.mLevel || forceUpdate)
if (ptrCreatureStats.getLevel() != creatureStats.mLevel || forceUpdate)
{
creatureStats.mLevel = ptrNpcStats.getLevel();
creatureStats.mLevel = ptrCreatureStats.getLevel();
getNetworking()->getPlayerPacket(ID_PLAYER_LEVEL)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_LEVEL)->Send();
@ -281,6 +282,19 @@ void LocalPlayer::updateLevel(bool forceUpdate)
}
}
void LocalPlayer::updateBounty(bool forceUpdate)
{
MWWorld::Ptr player = getPlayerPtr();
const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
if (ptrNpcStats.getBounty() != npcStats.mBounty || forceUpdate)
{
npcStats.mBounty = ptrNpcStats.getBounty();
getNetworking()->getPlayerPacket(ID_PLAYER_BOUNTY)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_BOUNTY)->Send();
}
}
void LocalPlayer::updatePosition(bool forceUpdate)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
@ -742,6 +756,15 @@ void LocalPlayer::setLevel()
ptrCreatureStats->setLevel(creatureStats.mLevel);
}
void LocalPlayer::setBounty()
{
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr();
MWMechanics::NpcStats *ptrNpcStats = &player.getClass().getNpcStats(player);
ptrNpcStats->setBounty(npcStats.mBounty);
}
void LocalPlayer::setPosition()
{
MWBase::World *world = MWBase::Environment::get().getWorld();

@ -29,6 +29,7 @@ namespace mwmp
void updateAttributes(bool forceUpdate = false);
void updateSkills(bool forceUpdate = false);
void updateLevel(bool forceUpdate = false);
void updateBounty(bool forceUpdate = false);
void updatePosition(bool forceUpdate = false);
void updateCell(bool forceUpdate = false);
void updateChar();
@ -49,6 +50,7 @@ namespace mwmp
void setAttributes();
void setSkills();
void setLevel();
void setBounty();
void setPosition();
void setCell();
void setClass();

@ -11,6 +11,7 @@
#include "processors/player/ProcessorPlayerAttribute.hpp"
#include "processors/player/ProcessorPlayerSkill.hpp"
#include "processors/player/ProcessorPlayerLevel.hpp"
#include "processors/player/ProcessorPlayerBounty.hpp"
#include "processors/player/ProcessorPlayerEquipment.hpp"
#include "processors/player/ProcessorPlayerInventory.hpp"
#include "processors/player/ProcessorPlayerSpellbook.hpp"
@ -68,6 +69,7 @@ void ProcessorInitializer()
PlayerProcessor::AddProcessor(new ProcessorPlayerAttribute());
PlayerProcessor::AddProcessor(new ProcessorPlayerSkill());
PlayerProcessor::AddProcessor(new ProcessorPlayerLevel());
PlayerProcessor::AddProcessor(new ProcessorPlayerBounty());
PlayerProcessor::AddProcessor(new ProcessorPlayerEquipment());
PlayerProcessor::AddProcessor(new ProcessorPlayerInventory());
PlayerProcessor::AddProcessor(new ProcessorPlayerSpellbook());

@ -0,0 +1,38 @@
#ifndef OPENMW_PROCESSORPLAYERBOUNTY_HPP
#define OPENMW_PROCESSORPLAYERBOUNTY_HPP
#include "apps/openmw/mwmp/PlayerProcessor.hpp"
namespace mwmp
{
class ProcessorPlayerBounty : public PlayerProcessor
{
public:
ProcessorPlayerBounty()
{
BPP_INIT(ID_PLAYER_BOUNTY)
}
virtual void Do(PlayerPacket &packet, BasePlayer *player)
{
if (isLocal())
{
if(isRequest())
static_cast<LocalPlayer *>(player)->updateBounty(true);
else
static_cast<LocalPlayer *>(player)->setBounty();
}
else if (player != 0)
{
MWWorld::Ptr ptrPlayer = static_cast<DedicatedPlayer *>(player)->getPtr();
MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer);
ptrNpcStats->setBounty(player->npcStats.mBounty);
}
}
};
}
#endif //OPENMW_PROCESSORPLAYERBOUNTY_HPP

@ -177,9 +177,9 @@ add_component_dir (openmw-mp\\Packets\\Player
PlayerPacket
PacketHandshake PacketChatMessage PacketPlayerBaseInfo PacketPlayerPosition PacketPlayerEquipment
PacketPlayerAttack PacketPlayerStatsDynamic PacketPlayerAnimFlags PacketPlayerCharGen PacketPlayerAttribute
PacketPlayerSkill PacketPlayerLevel PacketPlayerClass PacketPlayerInventory PacketPlayerSpellbook
PacketPlayerJournal PacketPlayerActiveSkills PacketPlayerCellChange PacketPlayerCellState PacketPlayerDeath
PacketPlayerResurrect PacketGUIBoxes PacketTime
PacketPlayerSkill PacketPlayerLevel PacketPlayerBounty PacketPlayerClass PacketPlayerInventory
PacketPlayerSpellbook PacketPlayerJournal PacketPlayerActiveSkills PacketPlayerCellChange PacketPlayerCellState
PacketPlayerDeath PacketPlayerResurrect PacketGUIBoxes PacketTime
)
add_component_dir (openmw-mp\\Packets\\World

@ -20,6 +20,7 @@
#include "../Packets/Player/PacketPlayerAttribute.hpp"
#include "../Packets/Player/PacketPlayerSkill.hpp"
#include "../Packets/Player/PacketPlayerLevel.hpp"
#include "../Packets/Player/PacketPlayerBounty.hpp"
#include "../Packets/Player/PacketHandshake.hpp"
#include "../Packets/Player/PacketGUIBoxes.hpp"
#include "../Packets/Player/PacketTime.hpp"
@ -63,6 +64,7 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p
AddPacket<PacketPlayerAttribute>(&packets, peer);
AddPacket<PacketPlayerSkill>(&packets, peer);
AddPacket<PacketPlayerLevel>(&packets, peer);
AddPacket<PacketPlayerBounty>(&packets, peer);
AddPacket<PacketHandshake>(&packets, peer);
AddPacket<PacketGUIBoxes>(&packets, peer);

@ -26,6 +26,7 @@ enum GameMessages
ID_PLAYER_ATTRIBUTE,
ID_PLAYER_SKILL,
ID_PLAYER_LEVEL,
ID_PLAYER_BOUNTY,
ID_PLAYER_CHARCLASS,
ID_HANDSHAKE,
ID_LOADED,

@ -0,0 +1,16 @@
#include "PacketPlayerBounty.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
PacketPlayerBounty::PacketPlayerBounty(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
{
packetID = ID_PLAYER_BOUNTY;
}
void PacketPlayerBounty::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->npcStats.mBounty, send);
}

@ -0,0 +1,17 @@
#ifndef OPENMW_PACKETPLAYERBOUNTY_HPP
#define OPENMW_PACKETPLAYERBOUNTY_HPP
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
namespace mwmp
{
class PacketPlayerBounty : public PlayerPacket
{
public:
PacketPlayerBounty(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
};
}
#endif //OPENMW_PACKETPLAYERBOUNTY_HPP
Loading…
Cancel
Save