diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 97c193a57..723c49f59 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -606,7 +606,7 @@ namespace MWClass if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) { mwmp::Main::get().getLocalPlayer()->GetAttack()->success = false; - mwmp::Main::get().getLocalPlayer()->sendAttack(0); + mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); } othercls.onHit(victim, 0.0f, false, weapon, ptr, osg::Vec3f(), false); @@ -850,7 +850,7 @@ namespace MWClass _atk->attacker = mwmp::Main::get().getLocalPlayer()->guid; _atk->target = mwmp::Players::GetPlayer(ptr)->guid; _atk->knockdown = getCreatureStats(ptr).getKnockedDown(); - mwmp::Main::get().getLocalPlayer()->sendAttack(0); // todo: make this sensitive to different weapon types + mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types } if (ptr == MWMechanics::getPlayer()) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 5eb9adf87..f07c8ebcc 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1035,12 +1035,15 @@ namespace MWMechanics if (iter->first == player) { bool state = MWBase::Environment::get().getWorld()->getPlayer().getAttackingOrSpell(); + DrawState_ dstate = player.getClass().getNpcStats(player).getDrawState(); iter->second->getCharacterController()->setAttackingOrSpell(state); - mwmp::Main::get().getLocalPlayer()->prepareAttack(2, state); + if (dstate == DrawState_Weapon) + mwmp::Main::get().getLocalPlayer()->prepareAttack(mwmp::Attack::MELEE, state); } - if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(iter->first)) - iter->second->getCharacterController()->setAttackingOrSpell(mwmp::Main::get().getNetworking()->Attack(iter->first)); + mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::Players::GetPlayer(iter->first); + if (dedicatedPlayer != nullptr) + dedicatedPlayer->updateActor(iter->second); if (!iter->first.getClass().getCreatureStats(iter->first).isDead()) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 88681384c..a84e2ae57 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "../mwrender/animation.hpp" @@ -1233,6 +1234,9 @@ bool CharacterController::updateWeaponState() if(!spellid.empty() && MWBase::Environment::get().getWorld()->startSpellCast(mPtr)) { + if (mPtr == getPlayer()) + mwmp::Main::get().getLocalPlayer()->prepareAttack(mwmp::Attack::MAGIC, true); + MWMechanics::CastSpell cast(mPtr, NULL); cast.playSpellCastingEffects(spellid); diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index a5c4176eb..e87598b19 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -799,35 +799,19 @@ namespace MWMechanics bool isDedicated = mwmp::Main::get().getNetworking()->isDedicatedPlayer(mCaster); - if (mCaster == getPlayer()) - { - mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true; - mwmp::Main::get().getLocalPlayer()->GetAttack()->pressed = true; - } - if (isDedicated) - { mwmp::Players::GetPlayer(mCaster)->GetAttack()->pressed = false; - } - if ((!isDedicated && Misc::Rng::roll0to99() >= successChance) || + if ((!isDedicated && !mwmp::Main::get().getLocalPlayer()->GetAttack()->success) || (isDedicated && mwmp::Players::GetPlayer(mCaster)->GetAttack()->success == 0)) { if (mCaster == getPlayer()) { - mwmp::Main::get().getLocalPlayer()->GetAttack()->success = false; MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicSkillFail}"); } fail = true; } - if (mCaster == getPlayer()) - { - mwmp::Main::get().getLocalPlayer()->sendAttack(1); - mwmp::Main::get().getLocalPlayer()->GetAttack()->pressed = false; - mwmp::Main::get().getLocalPlayer()->sendAttack(1); - } - if (fail) { // Failure sound diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 7e844b9c7..c41010e39 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -12,6 +12,7 @@ #include "../mwworld/player.hpp" #include "../mwworld/customdata.hpp" #include "../mwclass/npc.hpp" +#include "../mwmechanics/actor.hpp" #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/mechanicsmanagerimp.hpp" @@ -500,3 +501,8 @@ void DedicatedPlayer::setMarkerState(bool state) else removeMarker(); } + +void DedicatedPlayer::updateActor(MWMechanics::Actor *actor) +{ + actor->getCharacterController()->setAttackingOrSpell(GetAttack()->pressed); +} diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index 00c200542..46664f275 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -14,6 +14,10 @@ #include #include +namespace MWMechanics +{ + class Actor; +} namespace mwmp { @@ -50,6 +54,7 @@ namespace mwmp void updateMarker(); void removeMarker(); void setMarkerState(bool state); + void updateActor(MWMechanics::Actor *actor); private: DedicatedPlayer(RakNet::RakNetGUID guid); virtual ~DedicatedPlayer(); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 24dedc79d..6cbd76df1 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "LocalPlayer.hpp" #include "Main.hpp" @@ -510,7 +511,7 @@ void LocalPlayer::updateAttackState(bool forceUpdate) const string &spell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); GetAttack()->attacker = guid; - GetAttack()->type = 1; + GetAttack()->type = Attack::MAGIC; GetAttack()->pressed = true; GetAttack()->refid = spell; @@ -793,18 +794,11 @@ void LocalPlayer::sendClass() GetNetworking()->GetPlayerPacket(ID_GAME_CHARCLASS)->Send(this); } -void LocalPlayer::sendAttack(char type) +void LocalPlayer::sendAttack(Attack::TYPE type) { MWMechanics::DrawState_ state = GetPlayerPtr().getClass().getNpcStats(GetPlayerPtr()).getDrawState(); - if (state == MWMechanics::DrawState_Spell) - { - - } - else - { - } GetAttack()->type = type; GetAttack()->pressed = false; RakNet::BitStream bs; @@ -812,9 +806,9 @@ void LocalPlayer::sendAttack(char type) GetNetworking()->SendData(&bs); } -void LocalPlayer::prepareAttack(char type, bool state) +void LocalPlayer::prepareAttack(Attack::TYPE type, bool state) { - if (GetAttack()->pressed == state) + if (GetAttack()->pressed == state && type != Attack::MAGIC) return; MWMechanics::DrawState_ dstate = GetPlayerPtr().getClass().getNpcStats(GetPlayerPtr()).getDrawState(); @@ -822,18 +816,18 @@ void LocalPlayer::prepareAttack(char type, bool state) if (dstate == MWMechanics::DrawState_Spell) { const string &spell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); - + GetAttack()->success = Misc::Rng::roll0to99() >=MWMechanics::getSpellSuccessChance(spell, GetPlayerPtr()); + state = true; GetAttack()->refid = spell; } else { - + GetAttack()->success = false; } GetAttack()->pressed = state; GetAttack()->type = type; GetAttack()->knockdown = false; - GetAttack()->success = false; GetAttack()->block = false; GetAttack()->target = RakNet::RakNetGUID(); GetAttack()->attacker = guid; diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index d0d084165..ef046f97a 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -46,9 +46,9 @@ namespace mwmp void setInventory(); void sendClass(); - void sendAttack(char type); + void sendAttack(Attack::TYPE type); - void prepareAttack(char type, bool state); + void prepareAttack(Attack::TYPE type, bool state); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index da07a43db..3702723b9 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -397,6 +397,7 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) { LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", pl->GetAttack()->refid.c_str()); + LOG_APPEND(Log::LOG_VERBOSE, " - success: %d", pl->GetAttack()->success); } } break; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index f20d8699d..994b61bf9 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -20,6 +20,12 @@ namespace mwmp RakNet::RakNetGUID target; RakNet::RakNetGUID attacker; char type; // 0 - melee, 1 - magic, 2 - throwable + enum TYPE + { + MELEE = 0, + MAGIC, + THROWABLE + }; std::string refid; // id of spell (e.g. "fireball") char success; char block;