aboutsummaryrefslogtreecommitdiff
path: root/src/game/CombatAI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/CombatAI.cpp')
-rw-r--r--src/game/CombatAI.cpp64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/game/CombatAI.cpp b/src/game/CombatAI.cpp
index 56d1e6d6a3d..0d0ff17ffd7 100644
--- a/src/game/CombatAI.cpp
+++ b/src/game/CombatAI.cpp
@@ -292,17 +292,79 @@ void AOEAI::UpdateAI(const uint32 /*diff*/)
//VehicleAI
//////////////
+VehicleAI::VehicleAI(Creature *c) : CreatureAI(c), m_vehicle(c->GetVehicleKit()), m_IsVehicleInUse(false), 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
-void VehicleAI::UpdateAI(const uint32 /*diff*/)
+void VehicleAI::UpdateAI(const uint32 diff)
{
+ CheckConditions(diff);
+
+ if (m_DoDismiss)
+ {
+ if (m_DismissTimer < diff)
+ {
+ m_DoDismiss = false;
+ me->SetVisibility(VISIBILITY_OFF);
+ me->ForcedDespawn();
+ }else m_DismissTimer -= diff;
+ }
}
void VehicleAI::Reset()
{
+ me->SetVisibility(VISIBILITY_ON);
+
m_vehicle->Reset();
}
void VehicleAI::OnCharmed(bool apply)
{
+ if (m_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);
+ }
+ else if (apply)
+ m_DoDismiss = false;//in use again
+ m_DismissTimer = VEHICLE_DISMISS_TIME;//reset timer
m_IsVehicleInUse = apply;
+}
+
+void VehicleAI::LoadConditions()
+{
+ conditions = sConditionMgr.GetConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, me->GetEntry());
+ if (!conditions.empty())
+ {
+ sLog.outDebug("VehicleAI::LoadConditions: loaded %u conditions", uint32(conditions.size()));
+ }
+}
+
+void VehicleAI::CheckConditions(const uint32 diff)
+{
+ if(m_ConditionsTimer < diff)
+ {
+ if (!conditions.empty())
+ {
+ for (SeatMap::iterator itr = m_vehicle->m_Seats.begin(); itr != m_vehicle->m_Seats.end(); ++itr)
+ if (Unit *passenger = itr->second.passenger)
+ {
+ if (Player* plr = passenger->ToPlayer())
+ {
+ if (!sConditionMgr.IsPlayerMeetToConditions(plr, conditions))
+ {
+ plr->ExitVehicle();
+ return;//check other pessanger in next tick
+ }
+ }
+ }
+ }
+ m_ConditionsTimer = VEHICLE_CONDITION_CHECK_TIME;
+ } else m_ConditionsTimer -= diff;
} \ No newline at end of file