Core/Entities: bg vehicle will also have charmer's faction (save faction before charm and restore old faction after charm)

This commit is contained in:
joschiwald
2014-01-17 01:07:37 +01:00
parent 45dc95c8dc
commit 940e52236b
7 changed files with 109 additions and 126 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright (C) 2005-2013 Trinity <http://www.trinitycore.org/>
# Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
+19 -41
View File
@@ -23,6 +23,10 @@
#include "ObjectAccessor.h"
#include "Player.h"
/////////////////
// AggressorAI
/////////////////
int AggressorAI::Permissible(const Creature* creature)
{
// have some hostile factions, it will be selected by IsHostileTo check at MoveInLineOfSight
@@ -40,26 +44,9 @@ void AggressorAI::UpdateAI(uint32 /*diff*/)
DoMeleeAttackIfReady();
}
// some day we will delete these useless things
int CombatAI::Permissible(const Creature* /*creature*/)
{
return PERMIT_BASE_NO;
}
int ArcherAI::Permissible(const Creature* /*creature*/)
{
return PERMIT_BASE_NO;
}
int TurretAI::Permissible(const Creature* /*creature*/)
{
return PERMIT_BASE_NO;
}
int VehicleAI::Permissible(const Creature* /*creature*/)
{
return PERMIT_BASE_NO;
}
/////////////////
// CombatAI
/////////////////
void CombatAI::InitializeAI()
{
@@ -118,7 +105,7 @@ void CombatAI::SpellInterrupted(uint32 spellId, uint32 unTimeMs)
}
/////////////////
//CasterAI
// CasterAI
/////////////////
void CasterAI::InitializeAI()
@@ -182,7 +169,7 @@ void CasterAI::UpdateAI(uint32 diff)
}
//////////////
//ArcherAI
// ArcherAI
//////////////
ArcherAI::ArcherAI(Creature* c) : CreatureAI(c)
@@ -231,7 +218,7 @@ void ArcherAI::UpdateAI(uint32 /*diff*/)
}
//////////////
//TurretAI
// TurretAI
//////////////
TurretAI::TurretAI(Creature* c) : CreatureAI(c)
@@ -269,17 +256,17 @@ void TurretAI::UpdateAI(uint32 /*diff*/)
}
//////////////
//VehicleAI
// VehicleAI
//////////////
VehicleAI::VehicleAI(Creature* c) : CreatureAI(c), m_IsVehicleInUse(false), m_ConditionsTimer(VEHICLE_CONDITION_CHECK_TIME)
VehicleAI::VehicleAI(Creature* creature) : CreatureAI(creature), m_ConditionsTimer(VEHICLE_CONDITION_CHECK_TIME)
{
LoadConditions();
m_DoDismiss = false;
m_DismissTimer = VEHICLE_DISMISS_TIME;
}
//NOTE: VehicleAI::UpdateAI runs even while the vehicle is mounted
// NOTE: VehicleAI::UpdateAI runs even while the vehicle is mounted
void VehicleAI::UpdateAI(uint32 diff)
{
CheckConditions(diff);
@@ -289,7 +276,6 @@ void VehicleAI::UpdateAI(uint32 diff)
if (m_DismissTimer < diff)
{
m_DoDismiss = false;
me->SetVisible(false);
me->DespawnOrUnsummon();
}
else
@@ -297,24 +283,16 @@ void VehicleAI::UpdateAI(uint32 diff)
}
}
void VehicleAI::Reset()
{
me->SetVisible(true);
}
void VehicleAI::OnCharmed(bool apply)
{
if (m_IsVehicleInUse && !apply && !conditions.empty())//was used and has conditions
if (!me->GetVehicleKit()->IsVehicleInUse() && !apply && !conditions.empty()) // was used and has conditions
{
m_DoDismiss = true;//needs reset
me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PLAYER_VEHICLE);
me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
m_DoDismiss = true; // needs reset
}
else if (apply)
m_DoDismiss = false;//in use again
m_DoDismiss = false; // in use again
m_DismissTimer = VEHICLE_DISMISS_TIME;//reset timer
m_IsVehicleInUse = apply;
m_DismissTimer = VEHICLE_DISMISS_TIME; // reset timer
}
void VehicleAI::LoadConditions()
@@ -324,7 +302,7 @@ void VehicleAI::LoadConditions()
TC_LOG_DEBUG("condition", "VehicleAI::LoadConditions: loaded %u conditions", uint32(conditions.size()));
}
void VehicleAI::CheckConditions(const uint32 diff)
void VehicleAI::CheckConditions(uint32 diff)
{
if (m_ConditionsTimer < diff)
{
@@ -339,7 +317,7 @@ void VehicleAI::CheckConditions(const uint32 diff)
if (!sConditionMgr->IsObjectMeetToConditions(player, me, conditions))
{
player->ExitVehicle();
return;//check other pessanger in next tick
return; // check other pessanger in next tick
}
}
}
+12 -8
View File
@@ -47,7 +47,9 @@ class CombatAI : public CreatureAI
void JustDied(Unit* killer);
void UpdateAI(uint32 diff);
void SpellInterrupted(uint32 spellId, uint32 unTimeMs);
static int Permissible(const Creature*);
static int Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
protected:
EventMap events;
SpellVct spells;
@@ -72,7 +74,8 @@ struct ArcherAI : public CreatureAI
void AttackStart(Unit* who);
void UpdateAI(uint32 diff);
static int Permissible(Creature const*);
static int Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
protected:
float m_minRange;
};
@@ -85,29 +88,30 @@ struct TurretAI : public CreatureAI
void AttackStart(Unit* who);
void UpdateAI(uint32 diff);
static int Permissible(Creature const*);
static int Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
protected:
float m_minRange;
};
#define VEHICLE_CONDITION_CHECK_TIME 1000
#define VEHICLE_DISMISS_TIME 5000
struct VehicleAI : public CreatureAI
{
public:
explicit VehicleAI(Creature* c);
explicit VehicleAI(Creature* creature);
void UpdateAI(uint32 diff);
static int Permissible(Creature const*);
void Reset();
void MoveInLineOfSight(Unit*) { }
void AttackStart(Unit*) { }
void OnCharmed(bool apply);
static int Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
private:
bool m_IsVehicleInUse;
void LoadConditions();
void CheckConditions(const uint32 diff);
void CheckConditions(uint32 diff);
ConditionList conditions;
uint32 m_ConditionsTimer;
bool m_DoDismiss;
+8 -5
View File
@@ -759,7 +759,6 @@ Player::Player(WorldSession* session): Unit(true)
m_ArmorProficiency = 0;
m_canParry = false;
m_canBlock = false;
m_canDualWield = false;
m_canTitanGrip = false;
m_ammoDPS = 0.0f;
@@ -23769,14 +23768,18 @@ void Player::ResurectUsingRequestData()
SpawnCorpseBones();
}
void Player::SetClientControl(Unit* target, uint8 allowMove)
void Player::SetClientControl(Unit* target, bool allowMove)
{
WorldPacket data(SMSG_CLIENT_CONTROL_UPDATE, target->GetPackGUID().size()+1);
data.append(target->GetPackGUID());
data << uint8(allowMove);
data << uint8(allowMove ? 1 : 0);
GetSession()->SendPacket(&data);
if (target == this)
SetMover(this);
if (this != target)
SetViewpoint(target, allowMove);
if (allowMove)
SetMover(target);
}
void Player::SetMover(Unit* target)
+1 -1
View File
@@ -2088,7 +2088,7 @@ class Player : public Unit, public GridObject<Player>
bool IsKnowHowFlyIn(uint32 mapid, uint32 zone) const;
void SetClientControl(Unit* target, uint8 allowMove);
void SetClientControl(Unit* target, bool allowMove);
void SetMover(Unit* target);
+55 -58
View File
@@ -258,6 +258,8 @@ Unit::Unit(bool isWorldObject) :
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
_lastLiquid = NULL;
_oldFactionId = 0;
_isWalkingBeforeCharm = false;
}
@@ -4830,7 +4832,7 @@ GameObject* Unit::GetGameObject(uint32 spellId) const
void Unit::AddGameObject(GameObject* gameObj)
{
if (!gameObj || !gameObj->GetOwnerGUID() == 0)
if (!gameObj || gameObj->GetOwnerGUID() != 0)
return;
m_gameObj.push_back(gameObj);
@@ -9219,17 +9221,17 @@ void Unit::SetOwnerGUID(uint64 owner)
Unit* Unit::GetOwner() const
{
if (uint64 ownerid = GetOwnerGUID())
{
return ObjectAccessor::GetUnit(*this, ownerid);
}
if (uint64 ownerGUID = GetOwnerGUID())
return ObjectAccessor::GetUnit(*this, ownerGUID);
return NULL;
}
Unit* Unit::GetCharmer() const
{
if (uint64 charmerid = GetCharmerGUID())
return ObjectAccessor::GetUnit(*this, charmerid);
if (uint64 charmerGUID = GetCharmerGUID())
return ObjectAccessor::GetUnit(*this, charmerGUID);
return NULL;
}
@@ -9565,8 +9567,8 @@ void Unit::SetCharm(Unit* charm, bool apply)
}
if (charm->GetTypeId() == TYPEID_PLAYER
|| !charm->ToCreature()->HasUnitTypeMask(UNIT_MASK_MINION)
|| charm->GetOwnerGUID() != GetGUID())
|| !charm->ToCreature()->HasUnitTypeMask(UNIT_MASK_MINION)
|| charm->GetOwnerGUID() != GetGUID())
{
m_Controlled.erase(charm);
}
@@ -13577,9 +13579,8 @@ CharmInfo::~CharmInfo() { }
void CharmInfo::RestoreState()
{
if (_unit->GetTypeId() == TYPEID_UNIT)
if (Creature* creature = _unit->ToCreature())
creature->SetReactState(_oldReactState);
if (Creature* creature = _unit->ToCreature())
creature->SetReactState(_oldReactState);
}
void CharmInfo::InitPetActionBar()
@@ -15633,8 +15634,8 @@ void Unit::SetFeared(bool apply)
}
}
if (GetTypeId() == TYPEID_PLAYER)
ToPlayer()->SetClientControl(this, !apply);
if (Player* player = ToPlayer())
player->SetClientControl(this, !apply);
}
void Unit::SetConfused(bool apply)
@@ -15655,8 +15656,8 @@ void Unit::SetConfused(bool apply)
}
}
if (GetTypeId() == TYPEID_PLAYER)
ToPlayer()->SetClientControl(this, !apply);
if (Player* player = ToPlayer())
player->SetClientControl(this, !apply);
}
bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* aurApp)
@@ -15702,11 +15703,13 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
CombatStop(); /// @todo CombatStop(true) may cause crash (interrupt spells)
DeleteThreatList();
Player* playerCharmer = charmer->ToPlayer();
// Charmer stop charming
if (charmer->GetTypeId() == TYPEID_PLAYER)
if (playerCharmer)
{
charmer->ToPlayer()->StopCastingCharm();
charmer->ToPlayer()->StopCastingBindSight();
playerCharmer->StopCastingCharm();
playerCharmer->StopCastingBindSight();
}
// Charmed stop charming
@@ -15728,11 +15731,10 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
if (aurApp && aurApp->GetRemoveMode())
return false;
// Set charmed
Map* map = GetMap();
if (!IsVehicle() || (IsVehicle() && map && !map->IsBattleground()))
setFaction(charmer->getFaction());
_oldFactionId = getFaction();
setFaction(charmer->getFaction());
// Set charmed
charmer->SetCharm(this, true);
if (GetTypeId() == TYPEID_UNIT)
@@ -15745,7 +15747,7 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
Player* player = ToPlayer();
if (player->isAFK())
player->ToggleAFK();
player->SetClientControl(this, 0);
player->SetClientControl(this, false);
}
// charm is set by aura, and aura effect remove handler was called during apply handler execution
@@ -15763,25 +15765,21 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
GetCharmInfo()->InitCharmCreateSpells();
}
if (charmer->GetTypeId() == TYPEID_PLAYER)
if (playerCharmer)
{
switch (type)
{
case CHARM_TYPE_VEHICLE:
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
charmer->ToPlayer()->SetClientControl(this, 1);
charmer->ToPlayer()->SetMover(this);
charmer->ToPlayer()->SetViewpoint(this, true);
charmer->ToPlayer()->VehicleSpellInitialize();
playerCharmer->SetClientControl(this, true);
playerCharmer->VehicleSpellInitialize();
break;
case CHARM_TYPE_POSSESS:
AddUnitState(UNIT_STATE_POSSESSED);
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
charmer->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE);
charmer->ToPlayer()->SetClientControl(this, 1);
charmer->ToPlayer()->SetMover(this);
charmer->ToPlayer()->SetViewpoint(this, true);
charmer->ToPlayer()->PossessSpellInitialize();
playerCharmer->SetClientControl(this, true);
playerCharmer->PossessSpellInitialize();
break;
case CHARM_TYPE_CHARM:
if (GetTypeId() == TYPEID_UNIT && charmer->getClass() == CLASS_WARLOCK)
@@ -15800,7 +15798,7 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped
}
}
charmer->ToPlayer()->CharmSpellInitialize();
playerCharmer->CharmSpellInitialize();
break;
default:
case CHARM_TYPE_CONVERT:
@@ -15837,16 +15835,16 @@ void Unit::RemoveCharmedBy(Unit* charmer)
CombatStop(); /// @todo CombatStop(true) may cause crash (interrupt spells)
getHostileRefManager().deleteReferences();
DeleteThreatList();
Map* map = GetMap();
if (!IsVehicle() || (IsVehicle() && map && !map->IsBattleground()))
RestoreFaction();
GetMotionMaster()->InitDefault();
if (type == CHARM_TYPE_POSSESS)
if (_oldFactionId)
{
ClearUnitState(UNIT_STATE_POSSESSED);
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
setFaction(_oldFactionId);
_oldFactionId = 0;
}
else
RestoreFaction();
GetMotionMaster()->InitDefault();
if (Creature* creature = ToCreature())
{
@@ -15858,8 +15856,6 @@ void Unit::RemoveCharmedBy(Unit* charmer)
if (type != CHARM_TYPE_VEHICLE)
LastCharmerGUID = charmer->GetGUID();
}
else
ToPlayer()->SetClientControl(this, 1);
// If charmer still exists
if (!charmer)
@@ -15870,24 +15866,23 @@ void Unit::RemoveCharmedBy(Unit* charmer)
charmer->SetCharm(this, false);
if (charmer->GetTypeId() == TYPEID_PLAYER)
Player* playerCharmer = charmer->ToPlayer();
if (playerCharmer)
{
switch (type)
{
case CHARM_TYPE_VEHICLE:
charmer->ToPlayer()->SetClientControl(charmer, 1);
charmer->ToPlayer()->SetViewpoint(this, false);
charmer->ToPlayer()->SetClientControl(this, 0);
if (GetTypeId() == TYPEID_PLAYER)
ToPlayer()->SetMover(this);
playerCharmer->SetClientControl(this, false);
playerCharmer->SetClientControl(charmer, true);
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
break;
case CHARM_TYPE_POSSESS:
charmer->ToPlayer()->SetClientControl(charmer, 1);
charmer->ToPlayer()->SetViewpoint(this, false);
charmer->ToPlayer()->SetClientControl(this, 0);
playerCharmer->SetClientControl(this, false);
playerCharmer->SetClientControl(charmer, true);
charmer->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE);
if (GetTypeId() == TYPEID_PLAYER)
ToPlayer()->SetMover(this);
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
ClearUnitState(UNIT_STATE_POSSESSED);
break;
case CHARM_TYPE_CHARM:
if (GetTypeId() == TYPEID_UNIT && charmer->getClass() == CLASS_WARLOCK)
@@ -15908,9 +15903,12 @@ void Unit::RemoveCharmedBy(Unit* charmer)
}
}
if (Player* player = ToPlayer())
player->SetClientControl(this, true);
// a guardian should always have charminfo
if (charmer->GetTypeId() == TYPEID_PLAYER && this != charmer->GetFirstControlled())
charmer->ToPlayer()->SendRemoveControlBar();
if (playerCharmer && this != charmer->GetFirstControlled())
playerCharmer->SendRemoveControlBar();
else if (GetTypeId() == TYPEID_PLAYER || (GetTypeId() == TYPEID_UNIT && !ToCreature()->IsGuardian()))
DeleteCharmInfo();
}
@@ -15967,8 +15965,7 @@ void Unit::RemoveVehicleKit()
m_updateFlag &= ~UPDATEFLAG_VEHICLE;
m_unitTypeMask &= ~UNIT_MASK_VEHICLE;
RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PLAYER_VEHICLE);
RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK | UNIT_NPC_FLAG_PLAYER_VEHICLE);
}
bool Unit::IsOnVehicle(const Unit* vehicle) const
+13 -12
View File
@@ -2247,7 +2247,8 @@ class Unit : public WorldObject
bool m_cleanupDone; // lock made to not add stuff after cleanup before delete
bool m_duringRemoveFromWorld; // lock made to not add stuff after begining removing from world
bool _isWalkingBeforeCharm; // Are we walking before we were charmed?
uint32 _oldFactionId; ///< faction before charm
bool _isWalkingBeforeCharm; ///< Are we walking before we were charmed?
time_t _lastDamagedTime; // Part of Evade mechanics
};
@@ -2258,31 +2259,31 @@ namespace Trinity
class PowerPctOrderPred
{
public:
PowerPctOrderPred(Powers power, bool ascending = true) : m_power(power), m_ascending(ascending) { }
bool operator() (const Unit* a, const Unit* b) const
PowerPctOrderPred(Powers power, bool ascending = true) : _power(power), _ascending(ascending) { }
bool operator() (Unit const* a, Unit const* b) const
{
float rA = a->GetMaxPower(m_power) ? float(a->GetPower(m_power)) / float(a->GetMaxPower(m_power)) : 0.0f;
float rB = b->GetMaxPower(m_power) ? float(b->GetPower(m_power)) / float(b->GetMaxPower(m_power)) : 0.0f;
return m_ascending ? rA < rB : rA > rB;
float rA = a->GetMaxPower(_power) ? float(a->GetPower(_power)) / float(a->GetMaxPower(_power)) : 0.0f;
float rB = b->GetMaxPower(_power) ? float(b->GetPower(_power)) / float(b->GetMaxPower(_power)) : 0.0f;
return _ascending ? rA < rB : rA > rB;
}
private:
const Powers m_power;
const bool m_ascending;
Powers const _power;
bool const _ascending;
};
// Binary predicate for sorting Units based on percent value of health
class HealthPctOrderPred
{
public:
HealthPctOrderPred(bool ascending = true) : m_ascending(ascending) { }
bool operator() (const Unit* a, const Unit* b) const
HealthPctOrderPred(bool ascending = true) : _ascending(ascending) { }
bool operator() (Unit const* a, Unit const* b) const
{
float rA = a->GetMaxHealth() ? float(a->GetHealth()) / float(a->GetMaxHealth()) : 0.0f;
float rB = b->GetMaxHealth() ? float(b->GetHealth()) / float(b->GetMaxHealth()) : 0.0f;
return m_ascending ? rA < rB : rA > rB;
return _ascending ? rA < rB : rA > rB;
}
private:
const bool m_ascending;
bool const _ascending;
};
}
#endif