diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-11-02 04:40:58 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-11-02 04:41:47 +0300 |
commit | b90214b9878246ec45e68c0c6c309337d8e15ef2 (patch) | |
tree | ea977f4aaf1bc2ab8cd86f77103d1bc9cee9e1d9 /src/localplayer.cpp | |
parent | 17631dacf2cb8ebc3acc1dae9df0729a80a150d9 (diff) | |
download | manaplus-b90214b9878246ec45e68c0c6c309337d8e15ef2.tar.gz manaplus-b90214b9878246ec45e68c0c6c309337d8e15ef2.tar.bz2 manaplus-b90214b9878246ec45e68c0c6c309337d8e15ef2.tar.xz manaplus-b90214b9878246ec45e68c0c6c309337d8e15ef2.zip |
Add option to yellow bar to change player attack in pvp mode.
Modes: attack all, attack not friends, attack bad relations,
dont attack players.
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r-- | src/localplayer.cpp | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index ea3209229..2c7227a2d 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -36,6 +36,7 @@ #include "party.h" #include "particle.h" #include "playerinfo.h" +#include "playerrelations.h" #include "simpleanimation.h" #include "sound.h" #include "statuseffect.h" @@ -159,6 +160,7 @@ LocalPlayer::LocalPlayer(int id, int subtype): mDisableCrazyMove = false; mPickUpType = config.getIntValue("pickUpType"); mMagicAttackType = config.getIntValue("magicAttackType"); + mPvpAttackType = config.getIntValue("pvpAttackType"); mMoveToTargetType = config.getIntValue("moveToTargetType"); mDisableGameModifiers = config.getBoolValue("disableGameModifiers"); mTargetDeadPlayers = config.getBoolValue("targetDeadPlayers"); @@ -1356,26 +1358,30 @@ void LocalPlayer::attack(Being *target, bool keep, bool dontChangeEquipment) mTargetTime = tick_time; } - setAction(ATTACK); - - if (mEquippedWeapon) + if (target->getType() != Being::PLAYER || checAttackPermissions(target)) { - std::string soundFile = mEquippedWeapon->getSound(EQUIP_EVENT_STRIKE); - if (!soundFile.empty()) - sound.playSfx(soundFile); - } - else - { - sound.playSfx(paths.getValue("attackSfxFile", "fist-swish.ogg")); - } + setAction(ATTACK); - if (!Client::limitPackets(PACKET_ATTACK)) - return; + if (mEquippedWeapon) + { + std::string soundFile = mEquippedWeapon->getSound(EQUIP_EVENT_STRIKE); + if (!soundFile.empty()) + sound.playSfx(soundFile); + } + else + { + sound.playSfx(paths.getValue("attackSfxFile", "fist-swish.ogg")); + } - if (!dontChangeEquipment && target) - changeEquipmentBeforeAttack(target); + if (!Client::limitPackets(PACKET_ATTACK)) + return; + + if (!dontChangeEquipment && target) + changeEquipmentBeforeAttack(target); + + Net::getPlayerHandler()->attack(target->getId(), mServerAttack); + } - Net::getPlayerHandler()->attack(target->getId(), mServerAttack); #ifdef MANASERV_SUPPORT if ((Net::getNetworkType() != ServerInfo::MANASERV) && !keep) #else @@ -2890,6 +2896,17 @@ void LocalPlayer::switchMagicAttack() miniStatusWindow->updateStatus(); } +void LocalPlayer::switchPvpAttack() +{ + mPvpAttackType++; + if (mPvpAttackType > 3) + mPvpAttackType = 0; + + config.setValue("pvpAttackType", mPvpAttackType); + if (miniStatusWindow) + miniStatusWindow->updateStatus(); +} + void LocalPlayer::magicAttack() { if (!chatWindow || !isAlive() @@ -3897,6 +3914,7 @@ void LocalPlayer::resetYellowBar() mAttackWeaponType = config.resetIntValue("attackWeaponType"); mAttackType = config.resetIntValue("attackType"); mMagicAttackType = config.resetIntValue("magicAttackType"); + mPvpAttackType = config.resetIntValue("pvpAttackType"); mQuickDropCounter = config.resetIntValue("quickDropCounter"); mPickUpType = config.resetIntValue("pickUpType"); if (viewport) @@ -3937,6 +3955,26 @@ void LocalPlayer::stopAdvert() mBlockAdvert = true; } +bool LocalPlayer::checAttackPermissions(Being *target) +{ + if (!target) + return false; + + switch (mPvpAttackType) + { + case 0: + return true; + case 1: + return !(player_relations.getRelation(target->getName()) + == PlayerRelation::FRIEND); + case 2: + return player_relations.checkBadRelation(target->getName()); + default: + case 3: + return false; + } +} + void AwayListener::action(const gcn::ActionEvent &event) { if (event.getId() == "ok" && player_node && player_node->getAway()) |