From f09dc2b65b8b6d9db959a782a7ba5768ec4ec767 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sun, 16 Apr 2017 15:00:25 +0800 Subject: [PATCH] [Client] Add player processors --- .../player/ProcessorChatMessage.hpp | 30 +++++++ .../player/ProcessorGUIMessageBox.hpp | 44 ++++++++++ .../player/ProcessorGameConsole.hpp | 30 +++++++ .../processors/player/ProcessorGameTime.hpp | 39 ++++++++ .../processors/player/ProcessorHandshake.hpp | 28 ++++++ .../player/ProcessorPlayerAttack.hpp | 88 +++++++++++++++++++ .../player/ProcessorPlayerAttribute.hpp | 49 +++++++++++ .../player/ProcessorPlayerBaseInfo.hpp | 58 ++++++++++++ .../player/ProcessorPlayerCellChange.hpp | 37 ++++++++ .../player/ProcessorPlayerCellState.hpp | 31 +++++++ .../player/ProcessorPlayerCharClass.hpp | 35 ++++++++ .../player/ProcessorPlayerCharGen.hpp | 29 ++++++ .../player/ProcessorPlayerDeath.hpp | 53 +++++++++++ .../player/ProcessorPlayerDrawState.hpp | 35 ++++++++ .../player/ProcessorPlayerDynamicStats.hpp | 47 ++++++++++ .../player/ProcessorPlayerEquipment.hpp | 36 ++++++++ .../player/ProcessorPlayerInventory.hpp | 43 +++++++++ .../player/ProcessorPlayerJournal.hpp | 36 ++++++++ .../player/ProcessorPlayerLevel.hpp | 42 +++++++++ .../processors/player/ProcessorPlayerPos.hpp | 41 +++++++++ .../player/ProcessorPlayerResurrect.hpp | 67 ++++++++++++++ .../player/ProcessorPlayerSkill.hpp | 47 ++++++++++ .../player/ProcessorPlayerSpellbook.hpp | 44 ++++++++++ .../player/ProcessorUserDisconnected.hpp | 33 +++++++ .../processors/player/ProcessorUserMyID.hpp | 31 +++++++ 25 files changed, 1053 insertions(+) create mode 100644 apps/openmw/mwmp/processors/player/ProcessorChatMessage.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorGUIMessageBox.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorGameConsole.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorGameTime.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerAttack.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerAttribute.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerBaseInfo.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerCellChange.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerCellState.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerCharClass.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerCharGen.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerDeath.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerDrawState.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerDynamicStats.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerEquipment.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerJournal.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerLevel.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerPos.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerSkill.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorUserDisconnected.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorUserMyID.hpp diff --git a/apps/openmw/mwmp/processors/player/ProcessorChatMessage.hpp b/apps/openmw/mwmp/processors/player/ProcessorChatMessage.hpp new file mode 100644 index 000000000..399d5d057 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorChatMessage.hpp @@ -0,0 +1,30 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORCHATMESSAGE_HPP +#define OPENMW_PROCESSORCHATMESSAGE_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" +#include "apps/openmw/mwmp/Main.hpp" +#include "apps/openmw/mwmp/GUIController.hpp" + +namespace mwmp +{ + class ProcessorChatMessage : public PlayerProcessor + { + public: + ProcessorChatMessage() + { + BPP_INIT(ID_CHAT_MESSAGE) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + Main::get().getGUIController()->printChatMessage(player->chatMessage); + } + }; +} + +#endif //OPENMW_PROCESSORCHATMESSAGE_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorGUIMessageBox.hpp b/apps/openmw/mwmp/processors/player/ProcessorGUIMessageBox.hpp new file mode 100644 index 000000000..790be60e1 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorGUIMessageBox.hpp @@ -0,0 +1,44 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORGUIMESSAGEBOX_HPP +#define OPENMW_PROCESSORGUIMESSAGEBOX_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorGUIMessageBox : public PlayerProcessor + { + public: + ProcessorGUIMessageBox() + { + BPP_INIT(ID_GUI_MESSAGEBOX) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_GUI_MESSAGEBOX, Type %d, MSG %s", player->guiMessageBox.type, + player->guiMessageBox.label.c_str()); + + int messageBoxType = player->guiMessageBox.type; + + if (messageBoxType == BasePlayer::GUIMessageBox::MessageBox) + Main::get().getGUIController()->showMessageBox(player->guiMessageBox); + else if (messageBoxType == BasePlayer::GUIMessageBox::CustomMessageBox) + Main::get().getGUIController()->showCustomMessageBox(player->guiMessageBox); + else if (messageBoxType == BasePlayer::GUIMessageBox::InputDialog) + Main::get().getGUIController()->showInputBox(player->guiMessageBox); + else if (messageBoxType == BasePlayer::GUIMessageBox::ListBox) + Main::get().getGUIController()->showDialogList(player->guiMessageBox); + } + } + }; +} + + +#endif //OPENMW_PROCESSORGUIMESSAGEBOX_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameConsole.hpp b/apps/openmw/mwmp/processors/player/ProcessorGameConsole.hpp new file mode 100644 index 000000000..92b648e73 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorGameConsole.hpp @@ -0,0 +1,30 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORGAMECONSOLE_HPP +#define OPENMW_PROCESSORGAMECONSOLE_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorGameConsole : public PlayerProcessor + { + public: + ProcessorGameConsole() + { + BPP_INIT(ID_GAME_CONSOLE) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + + } + }; +} + + + +#endif //OPENMW_PROCESSORGAMECONSOLE_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameTime.hpp b/apps/openmw/mwmp/processors/player/ProcessorGameTime.hpp new file mode 100644 index 000000000..cc7a1adbc --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorGameTime.hpp @@ -0,0 +1,39 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORGAMETIME_HPP +#define OPENMW_PROCESSORGAMETIME_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorGameTime : public PlayerProcessor + { + public: + ProcessorGameTime() + { + BPP_INIT(ID_PLAYER_CHARCLASS) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + if (player->hour != -1) + world->setHour(player->hour); + else if (player->day != -1) + world->setDay(player->day); + else if (player->month != -1) + world->setMonth(player->month); + } + } + }; +} + + + +#endif //OPENMW_PROCESSORGAMETIME_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp b/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp new file mode 100644 index 000000000..8390fedcd --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp @@ -0,0 +1,28 @@ +// +// Created by koncord on 04.04.17. +// + +#ifndef OPENMW_PROCESSORHANDSHAKE_HPP +#define OPENMW_PROCESSORHANDSHAKE_HPP + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorHandshake : public PlayerProcessor + { + public: + ProcessorHandshake() + { + BPP_INIT(ID_HANDSHAKE) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + packet.setPlayer(getLocalPlayer()); // player is 0 because myGuid will be setted after ProcessUserMyID + packet.Send(serverAddr); + } + }; +} + +#endif //OPENMW_PROCESSORHANDSHAKE_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerAttack.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerAttack.hpp new file mode 100644 index 000000000..437b98b3e --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerAttack.hpp @@ -0,0 +1,88 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERATTACK_HPP +#define OPENMW_PROCESSORPLAYERATTACK_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" +#include "apps/openmw/mwbase/world.hpp" +#include "apps/openmw/mwworld/containerstore.hpp" +#include "apps/openmw/mwworld/inventorystore.hpp" +#include "apps/openmw/mwmechanics/combat.hpp" + +#include "apps/openmw/mwbase/environment.hpp" + +namespace mwmp +{ + class ProcessorPlayerAttack : public PlayerProcessor + { + public: + ProcessorPlayerAttack() + { + BPP_INIT(ID_PLAYER_ATTACK) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + DedicatedPlayer &dedicatedPlayer = static_cast(*player); + //cout << "Player: " << dedicatedPlayer.Npc()->mName << " pressed: " << (dedicatedPlayer.getAttack()->pressed == 1) << endl; + if (dedicatedPlayer.attack.pressed == 0) + { + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", dedicatedPlayer.attack.success ? "true" : "false"); + + if (dedicatedPlayer.attack.success == 1) + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f",dedicatedPlayer.attack.damage); + } + + MWMechanics::CreatureStats &stats = dedicatedPlayer.getPtr().getClass().getNpcStats(dedicatedPlayer.getPtr()); + stats.getSpells().setSelectedSpell(dedicatedPlayer.attack.refid); + + MWWorld::Ptr victim; + if (dedicatedPlayer.attack.target == getLocalPlayer()->guid) + victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); + else if (Players::getPlayer(dedicatedPlayer.attack.target) != 0) + victim = Players::getPlayer(dedicatedPlayer.attack.target)->getPtr(); + + MWWorld::Ptr attacker; + attacker = dedicatedPlayer.getPtr(); + + // Get the weapon used (if hand-to-hand, weapon = inv.end()) + if (dedicatedPlayer.drawState == 1) + { + MWWorld::InventoryStore &inv = attacker.getClass().getInventoryStore(attacker); + MWWorld::ContainerStoreIterator weaponslot = inv.getSlot( + MWWorld::InventoryStore::Slot_CarriedRight); + MWWorld::Ptr weapon = ((weaponslot != inv.end()) ? *weaponslot : MWWorld::Ptr()); + if (!weapon.isEmpty() && weapon.getTypeName() != typeid(ESM::Weapon).name()) + weapon = MWWorld::Ptr(); + + if (victim.mRef != 0) + { + bool healthdmg; + if (!weapon.isEmpty()) + healthdmg = true; + else + { + MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim); + healthdmg = otherstats.isParalyzed() || otherstats.getKnockedDown(); + } + + if (!weapon.isEmpty()) + MWMechanics::blockMeleeAttack(attacker, victim, weapon, dedicatedPlayer.attack.damage, 1); + dedicatedPlayer.getPtr().getClass().onHit(victim, dedicatedPlayer.attack.damage, healthdmg, weapon, attacker, osg::Vec3f(), + dedicatedPlayer.attack.success); + } + } + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", dedicatedPlayer.attack.refid.c_str()); + LOG_APPEND(Log::LOG_VERBOSE, " - success: %d", dedicatedPlayer.attack.success); + } + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERATTACK_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerAttribute.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerAttribute.hpp new file mode 100644 index 000000000..0a649b5be --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerAttribute.hpp @@ -0,0 +1,49 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERATTRIBUTE_HPP +#define OPENMW_PROCESSORPLAYERATTRIBUTE_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" +#include "apps/openmw/mwmechanics/npcstats.hpp" +#include "apps/openmw/mwclass/npc.hpp" + +namespace mwmp +{ + class ProcessorPlayerAttribute : public PlayerProcessor + { + public: + ProcessorPlayerAttribute() + { + BPP_INIT(ID_PLAYER_ATTRIBUTE) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if(isRequest()) + static_cast(player)->updateAttributes(true); + else + static_cast(player)->setAttributes(); + } + else + { + MWWorld::Ptr ptrPlayer = static_cast(player)->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); + MWMechanics::AttributeValue attributeValue; + + for (int i = 0; i < 8; ++i) + { + attributeValue.readState(player->creatureStats.mAttributes[i]); + ptrCreatureStats->setAttribute(i, attributeValue); + } + } + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERATTRIBUTE_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerBaseInfo.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerBaseInfo.hpp new file mode 100644 index 000000000..4504c80ee --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerBaseInfo.hpp @@ -0,0 +1,58 @@ +// +// Created by koncord on 04.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERBASEINFO_HPP +#define OPENMW_PROCESSORPLAYERBASEINFO_HPP + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerBaseInfo : public PlayerProcessor + { + public: + ProcessorPlayerBaseInfo() + { + BPP_INIT(ID_PLAYER_BASEINFO) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_BASEINFO from server"); + + if(isLocal()) + { + LOG_APPEND(Log::LOG_INFO, "- Packet was about my id"); + + if(isRequest()) + { + LOG_APPEND(Log::LOG_INFO, "- Requesting info"); + packet.Send(serverAddr); + } + else + { + LOG_APPEND(Log::LOG_INFO, "- Updating LocalPlayer"); + static_cast(player)->updateChar(); + } + } + else + { + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", player == 0 ? "new player" : player->npc.mName.c_str()); + + if (player == 0) + { + LOG_APPEND(Log::LOG_INFO, "- Exchanging data with new player"); + player = Players::newPlayer(guid); + + packet.setPlayer(player); + packet.Read(); + } + + Players::createPlayer(guid); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERBASEINFO_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerCellChange.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerCellChange.hpp new file mode 100644 index 000000000..405046135 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerCellChange.hpp @@ -0,0 +1,37 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCELLCHANGE_HPP +#define OPENMW_PROCESSORPLAYERCELLCHANGE_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerCellChange : public PlayerProcessor + { + public: + ProcessorPlayerCellChange() + { + BPP_INIT(ID_PLAYER_CELL_CHANGE) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if (isRequest()) + static_cast(player)->updateCell(true); + else + static_cast(player)->setCell(); + } + else + static_cast(player)->updateCell(); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERCELLCHANGE_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerCellState.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerCellState.hpp new file mode 100644 index 000000000..b7c124fed --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerCellState.hpp @@ -0,0 +1,31 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCELLSTATE_HPP +#define OPENMW_PROCESSORPLAYERCELLSTATE_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerCellState : public PlayerProcessor + { + public: + ProcessorPlayerCellState() + { + BPP_INIT(ID_PLAYER_CELL_STATE) + avoidReading = true; + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal() && isRequest()) + static_cast(player)->sendCellStates(); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERCELLSTATE_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerCharClass.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerCharClass.hpp new file mode 100644 index 000000000..4019e79c9 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerCharClass.hpp @@ -0,0 +1,35 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCHARCLASS_HPP +#define OPENMW_PROCESSORPLAYERCHARCLASS_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerCharClass : public PlayerProcessor + { + public: + ProcessorPlayerCharClass() + { + BPP_INIT(ID_PLAYER_CHARCLASS) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if(isRequest()) + static_cast(player)->sendClass(); + else + static_cast(player)->setClass(); + } + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERCHARCLASS_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerCharGen.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerCharGen.hpp new file mode 100644 index 000000000..ff1b8a65a --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerCharGen.hpp @@ -0,0 +1,29 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCHARGEN_HPP +#define OPENMW_PROCESSORPLAYERCHARGEN_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerCharGen : public PlayerProcessor + { + public: + ProcessorPlayerCharGen() + { + BPP_INIT(ID_PLAYER_CHARGEN) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERCHARGEN_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerDeath.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerDeath.hpp new file mode 100644 index 000000000..7386ec0f7 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerDeath.hpp @@ -0,0 +1,53 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERDEATH_HPP +#define OPENMW_PROCESSORPLAYERDEATH_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerDeath : public PlayerProcessor + { + public: + ProcessorPlayerDeath() + { + BPP_INIT(ID_PLAYER_DEATH) + avoidReading = true; + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_DEATH from server"); + if (isLocal()) + { + LOG_APPEND(Log::LOG_INFO, "- Packet was about me"); + + MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWMechanics::DynamicStat health = playerPtr.getClass().getCreatureStats(playerPtr).getHealth(); + health.setCurrent(0); + playerPtr.getClass().getCreatureStats(playerPtr).setHealth(health); + packet.setPlayer(player); + packet.Send(serverAddr); + } + else + { + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", player->npc.mName.c_str()); + + MWMechanics::DynamicStat health; + player->creatureStats.mDead = true; + health.readState(player->creatureStats.mDynamic[0]); + health.setCurrent(0); + health.writeState(player->creatureStats.mDynamic[0]); + + MWWorld::Ptr ptr = static_cast(player)->getPtr(); + ptr.getClass().getCreatureStats(ptr).setHealth(health); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERDEATH_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerDrawState.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerDrawState.hpp new file mode 100644 index 000000000..aeba23b50 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerDrawState.hpp @@ -0,0 +1,35 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERDRAWSTATE_HPP +#define OPENMW_PROCESSORPLAYERDRAWSTATE_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerDrawState : public PlayerProcessor + { + public: + ProcessorPlayerDrawState() + { + BPP_INIT(ID_PLAYER_DRAWSTATE) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if(isRequest()) + static_cast(player)->updateDrawStateAndFlags(true); + } + else + static_cast(player)->updateDrawState(); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERDRAWSTATE_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerDynamicStats.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerDynamicStats.hpp new file mode 100644 index 000000000..7dd33eadb --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerDynamicStats.hpp @@ -0,0 +1,47 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERDYNAMICSTATS_HPP +#define OPENMW_PROCESSORPLAYERDYNAMICSTATS_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerDynamicStats : public PlayerProcessor + { + public: + ProcessorPlayerDynamicStats() + { + BPP_INIT(ID_PLAYER_DYNAMICSTATS) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if (isRequest()) + static_cast(player)->updateDynamicStats(true); + else + static_cast(player)->setDynamicStats(); + } + else + { + MWWorld::Ptr ptrPlayer = static_cast(player)->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); + MWMechanics::DynamicStat value; + + for (int i = 0; i < 3; ++i) + { + value.readState(player->creatureStats.mDynamic[i]); + ptrCreatureStats->setDynamic(i, value); + } + } + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERDYNAMICSTATS_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerEquipment.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerEquipment.hpp new file mode 100644 index 000000000..c6cbf1ee8 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerEquipment.hpp @@ -0,0 +1,36 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYEREQUIPMENT_HPP +#define OPENMW_PROCESSORPLAYEREQUIPMENT_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerEquipment : public PlayerProcessor + { + public: + ProcessorPlayerEquipment() + { + BPP_INIT(ID_PLAYER_EQUIPMENT) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if (isRequest()) + static_cast(player)->updateEquipment(true); + else + static_cast(player)->setEquipment(); + } + else + static_cast(player)->updateEquipment(); + } + }; +} + +#endif //OPENMW_PROCESSORPLAYEREQUIPMENT_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp new file mode 100644 index 000000000..150d7100d --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp @@ -0,0 +1,43 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP +#define OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerInventory : public PlayerProcessor + { + public: + ProcessorPlayerInventory() + { + BPP_INIT(ID_PLAYER_INVENTORY) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (!isLocal()) return; + + if (isRequest()) + static_cast(player)->updateInventory(true); + else + { + LocalPlayer &localPlayer = static_cast(*player); + int inventoryAction = localPlayer.inventoryChanges.action; + + if (inventoryAction == InventoryChanges::ADD) + localPlayer.addItems(); + else if (inventoryAction == InventoryChanges::REMOVE) + localPlayer.removeItems(); + else // InventoryChanges::SET + localPlayer.setInventory(); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerJournal.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerJournal.hpp new file mode 100644 index 000000000..c1b8b5f2e --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerJournal.hpp @@ -0,0 +1,36 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERJOURNAL_HPP +#define OPENMW_PROCESSORPLAYERJOURNAL_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerJournal : public PlayerProcessor + { + public: + ProcessorPlayerJournal() + { + BPP_INIT(ID_PLAYER_JOURNAL) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (!isLocal()) return; + + if (isRequest()) + { + // Entire journal cannot currently be requested from players + } + else + static_cast(player)->addJournalItems(); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERJOURNAL_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerLevel.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerLevel.hpp new file mode 100644 index 000000000..d86acdd7d --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerLevel.hpp @@ -0,0 +1,42 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERLEVEL_HPP +#define OPENMW_PROCESSORPLAYERLEVEL_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerLevel : public PlayerProcessor + { + public: + ProcessorPlayerLevel() + { + BPP_INIT(ID_PLAYER_LEVEL) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if(isRequest()) + static_cast(player)->updateLevel(true); + else + static_cast(player)->setLevel(); + } + else + { + MWWorld::Ptr ptrPlayer = static_cast(player)->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); + + ptrCreatureStats->setLevel(player->creatureStats.mLevel); + } + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERLEVEL_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerPos.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerPos.hpp new file mode 100644 index 000000000..2fbaeb503 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerPos.hpp @@ -0,0 +1,41 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERPOS_HPP +#define OPENMW_PROCESSORPLAYERPOS_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerPos : public PlayerProcessor + { + public: + ProcessorPlayerPos() + { + BPP_INIT(ID_PLAYER_POS) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if (!isRequest()) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_PLAYER_POS changed by server"); + + static_cast(player)->setPosition(); + } + else + static_cast(player)->updatePosition(true); + } + else // dedicated player + static_cast(player)->updateMarker(); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERPOS_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp new file mode 100644 index 000000000..4122bed58 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp @@ -0,0 +1,67 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERRESURRECT_HPP +#define OPENMW_PROCESSORPLAYERRESURRECT_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" +#include "apps/openmw/mwmp/Main.hpp" +#include "apps/openmw/mwmp/Networking.hpp" + +namespace mwmp +{ + class ProcessorPlayerResurrect : public PlayerProcessor + { + public: + ProcessorPlayerResurrect() + { + BPP_INIT(ID_PLAYER_RESURRECT) + avoidReading = true; + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_RESURRECT from server"); + + if (isLocal()) + { + LOG_APPEND(Log::LOG_INFO, "- Packet was about me"); + + MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); + playerPtr.getClass().getCreatureStats(playerPtr).resurrect(); + + // If this player had a weapon or spell readied when dying, they will + // still have it readied but be unable to use it unless we clear it here + playerPtr.getClass().getNpcStats(playerPtr).setDrawState(MWMechanics::DrawState_Nothing); + + packet.setPlayer(player); + packet.Send(serverAddr); + + static_cast(player)->updateDynamicStats(true); + Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_DYNAMICSTATS)->setPlayer(player); + Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_DYNAMICSTATS)->Send(serverAddr); + } + else + { + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", player->npc.mName.c_str()); + + player->creatureStats.mDead = false; + if (player->creatureStats.mDynamic[0].mMod < 1) + player->creatureStats.mDynamic[0].mMod = 1; + player->creatureStats.mDynamic[0].mCurrent = player->creatureStats.mDynamic[0].mMod; + + MWWorld::Ptr ptr = static_cast(player)->getPtr(); + + ptr.getClass().getCreatureStats(ptr).resurrect(); + + MWMechanics::DynamicStat health; + health.readState(player->creatureStats.mDynamic[0]); + ptr.getClass().getCreatureStats(ptr).setHealth(health); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERRESURRECT_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerSkill.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerSkill.hpp new file mode 100644 index 000000000..ccfe2d2b4 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerSkill.hpp @@ -0,0 +1,47 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERSKILL_HPP +#define OPENMW_PROCESSORPLAYERSKILL_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerSkill : public PlayerProcessor + { + public: + ProcessorPlayerSkill() + { + BPP_INIT(ID_PLAYER_SKILL) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + if(isRequest()) + static_cast(player)->updateSkills(true); + else + static_cast(player)->setSkills(); + } + else + { + MWWorld::Ptr ptrPlayer = static_cast(player)->getPtr(); + MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); + MWMechanics::SkillValue skillValue; + + for (int i = 0; i < 27; ++i) + { + skillValue.readState(player->npcStats.mSkills[i]); + ptrNpcStats->setSkill(i, skillValue); + } + } + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERSKILL_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp new file mode 100644 index 000000000..d446b6099 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp @@ -0,0 +1,44 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERSPELLBOOK_HPP +#define OPENMW_PROCESSORPLAYERSPELLBOOK_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerSpellbook : public PlayerProcessor + { + public: + ProcessorPlayerSpellbook() + { + BPP_INIT(ID_PLAYER_SPELLBOOK) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (!isLocal()) return; + + if (isRequest()) + static_cast(player)->sendSpellbook(); + else + { + LocalPlayer &localPlayer = static_cast(*player); + + int spellbookAction = localPlayer.spellbookChanges.action; + + if (spellbookAction == SpellbookChanges::ADD) + localPlayer.addSpells(); + else if (spellbookAction == SpellbookChanges::REMOVE) + localPlayer.removeSpells(); + else // SpellbookChanges::SET + localPlayer.setSpellbook(); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERSPELLBOOK_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorUserDisconnected.hpp b/apps/openmw/mwmp/processors/player/ProcessorUserDisconnected.hpp new file mode 100644 index 000000000..bccb1eb20 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorUserDisconnected.hpp @@ -0,0 +1,33 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORUSERDISCONNECTED_HPP +#define OPENMW_PROCESSORUSERDISCONNECTED_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" +#include "apps/openmw/mwstate/statemanagerimp.hpp" + +namespace mwmp +{ + class ProcessorUserDisconnected : public PlayerProcessor + { + public: + ProcessorUserDisconnected() + { + BPP_INIT(ID_USER_DISCONNECTED) + avoidReading = true; + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + MWBase::Environment::get().getStateManager()->requestQuit(); + else + Players::disconnectPlayer(guid); + } + }; +} + +#endif //OPENMW_PROCESSORUSERDISCONNECTED_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorUserMyID.hpp b/apps/openmw/mwmp/processors/player/ProcessorUserMyID.hpp new file mode 100644 index 000000000..bdd0a8b94 --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorUserMyID.hpp @@ -0,0 +1,31 @@ +// +// Created by koncord on 16.04.17. +// + +#ifndef OPENMW_PROCESSORUSERMYID_HPP +#define OPENMW_PROCESSORUSERMYID_HPP + + +#include "apps/openmw/mwmp/PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorUserMyID : public PlayerProcessor + { + public: + ProcessorUserMyID() + { + BPP_INIT(ID_USER_MYID) + avoidReading = true; + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_USER_MYID from server"); + myGuid = guid; + getLocalPlayer()->guid = guid; + } + }; +} + +#endif //OPENMW_PROCESSORUSERMYID_HPP