|
|
@ -1476,22 +1476,24 @@ namespace MWMechanics
|
|
|
|
|
|
|
|
|
|
|
|
bool MechanicsManager::actorAttacked(const MWWorld::Ptr &target, const MWWorld::Ptr &attacker)
|
|
|
|
bool MechanicsManager::actorAttacked(const MWWorld::Ptr &target, const MWWorld::Ptr &attacker)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (target == getPlayer() || !attacker.getClass().isActor())
|
|
|
|
const MWWorld::Ptr& player = getPlayer();
|
|
|
|
|
|
|
|
if (target == player || !attacker.getClass().isActor())
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
std::set<MWWorld::Ptr> followersAttacker;
|
|
|
|
|
|
|
|
getActorsSidingWith(attacker, followersAttacker);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWMechanics::CreatureStats& statsTarget = target.getClass().getCreatureStats(target);
|
|
|
|
MWMechanics::CreatureStats& statsTarget = target.getClass().getCreatureStats(target);
|
|
|
|
|
|
|
|
if (attacker == player)
|
|
|
|
if (followersAttacker.find(target) != followersAttacker.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
statsTarget.friendlyHit();
|
|
|
|
std::set<MWWorld::Ptr> followersAttacker;
|
|
|
|
|
|
|
|
getActorsSidingWith(attacker, followersAttacker);
|
|
|
|
if (statsTarget.getFriendlyHits() < 4)
|
|
|
|
if (followersAttacker.find(target) != followersAttacker.end())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getDialogueManager()->say(target, "hit");
|
|
|
|
statsTarget.friendlyHit();
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (statsTarget.getFriendlyHits() < 4)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MWBase::Environment::get().getDialogueManager()->say(target, "hit");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1500,9 +1502,9 @@ namespace MWMechanics
|
|
|
|
|
|
|
|
|
|
|
|
AiSequence& seq = statsTarget.getAiSequence();
|
|
|
|
AiSequence& seq = statsTarget.getAiSequence();
|
|
|
|
|
|
|
|
|
|
|
|
if (!attacker.isEmpty() && (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(target)
|
|
|
|
if (!attacker.isEmpty()
|
|
|
|
|| attacker == getPlayer())
|
|
|
|
&& (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(target) || attacker == player)
|
|
|
|
&& !seq.isInCombat(attacker))
|
|
|
|
&& !seq.isInCombat(attacker))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back.
|
|
|
|
// Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back.
|
|
|
|
// Note: accidental or collateral damage attacks are ignored.
|
|
|
|
// Note: accidental or collateral damage attacks are ignored.
|
|
|
@ -1512,7 +1514,7 @@ namespace MWMechanics
|
|
|
|
// he will attack the player only if we will force him (e.g. via StartCombat console command)
|
|
|
|
// he will attack the player only if we will force him (e.g. via StartCombat console command)
|
|
|
|
bool peaceful = false;
|
|
|
|
bool peaceful = false;
|
|
|
|
std::string script = target.getClass().getScript(target);
|
|
|
|
std::string script = target.getClass().getScript(target);
|
|
|
|
if (!script.empty() && target.getRefData().getLocals().hasVar(script, "onpchitme") && attacker == getPlayer())
|
|
|
|
if (!script.empty() && target.getRefData().getLocals().hasVar(script, "onpchitme") && attacker == player)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int fight = std::max(0, target.getClass().getCreatureStats(target).getAiSetting(CreatureStats::AI_Fight).getModified());
|
|
|
|
int fight = std::max(0, target.getClass().getCreatureStats(target).getAiSetting(CreatureStats::AI_Fight).getModified());
|
|
|
|
peaceful = (fight == 0);
|
|
|
|
peaceful = (fight == 0);
|
|
|
|