HostileReference* ThreatContainer::selectNextVictim(Creature* pAttacker, HostileReference* pCurrentVictim)
{
HostileReference* currentRef = NULL;
bool found = false;
bool noPriorityTargetFound = false;
ThreatList::const_iterator lastRef = iThreatList.end();
lastRef--;
for(ThreatList::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;)
{
currentRef = (*iter);
Unit* target = currentRef->getTarget();
MANGOS_ASSERT(target); // if the ref has status online the target must be there !
// some units are prefered in comparison to others
if(!noPriorityTargetFound && (target->IsImmunedToDamage(pAttacker->GetMeleeDamageSchoolMask()) || target->hasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_DAMAGE)) )
{
if(iter != lastRef)
{
// current victim is a second choice target, so don't compare threat with it below
if(currentRef == pCurrentVictim)
pCurrentVictim = NULL;
++iter;
continue;
}
else
{
// if we reached to this point, everyone in the threatlist is a second choice target. In such a situation the target with the highest threat should be attacked.
noPriorityTargetFound = true;
iter = iThreatList.begin();
continue;
}
}
if (!pAttacker->IsOutOfThreatArea(target)) // skip non attackable currently targets
{
if (pCurrentVictim) // select 1.3/1.1 better target in comparison current target
{
// list sorted and and we check current target, then this is best case
if(pCurrentVictim == currentRef || currentRef->getThreat() <= 1.1f * pCurrentVictim->getThreat() )
{
currentRef = pCurrentVictim; // for second case
found = true;
break;
}
if (currentRef->getThreat() > 1.3f * pCurrentVictim->getThreat() ||
(currentRef->getThreat() > 1.1f * pCurrentVictim->getThreat() &&
pAttacker->CanReachWithMeleeAttack(target)) )
{ //implement 110% threat rule for targets in melee range
found = true; //and 130% rule for targets in ranged distances
break; //for selecting alive targets
}
}
else // select any
{
found = true;
break;
}
}
++iter;
}
if(!found)
currentRef = NULL;
return currentRef;
}
void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
{
if (!i_path || i_path->empty())
return;
m_lastReachedWaypoint = i_currentNode;
if (m_isArrivalDone)
return;
creature.clearUnitState(UNIT_STAT_ROAMING_MOVE);
m_isArrivalDone = true;
WaypointPath::const_iterator currPoint = i_path->find(i_currentNode);
MANGOS_ASSERT(currPoint != i_path->end());
WaypointNode const& node = currPoint->second;
if (node.script_id)
{
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature movement start script %u at point %u for %s.", node.script_id, i_currentNode, creature.GetGuidStr().c_str());
creature.GetMap()->ScriptsStart(sCreatureMovementScripts, node.script_id, &creature, &creature);
}
// We have reached the destination and can process behavior
if (WaypointBehavior* behavior = node.behavior)
{
if (behavior->emote != 0)
creature.HandleEmote(behavior->emote);
if (behavior->spell != 0)
creature.CastSpell(&creature, behavior->spell, false);
if (behavior->model1 != 0)
creature.SetDisplayId(behavior->model1);
if (behavior->textid[0])
{
int32 textId = behavior->textid[0];
// Not only one text is set
if (behavior->textid[1])
{
// Select one from max 5 texts (0 and 1 already checked)
int i = 2;
for (; i < MAX_WAYPOINT_TEXT; ++i)
{
if (!behavior->textid[i])
break;
}
textId = behavior->textid[urand(0, i - 1)];
}
if (MangosStringLocale const* textData = sObjectMgr.GetMangosStringLocale(textId))
creature.MonsterText(textData, nullptr);
else
sLog.outErrorDb("%s reached waypoint %u, attempted to do text %i, but required text-data could not be found", creature.GetGuidStr().c_str(), i_currentNode, textId);
}
}
// Inform script
if (creature.AI())
{
uint32 type = WAYPOINT_MOTION_TYPE;
if (m_PathOrigin == PATH_FROM_EXTERNAL && m_pathId > 0)
type = EXTERNAL_WAYPOINT_MOVE + m_pathId;
creature.AI()->MovementInform(type, i_currentNode);
}
// Wait delay ms
Stop(node.delay);
}
HostileReference* ThreatContainer::selectNextVictim(Creature* pAttacker, HostileReference* pCurrentVictim)
{
HostileReference* pCurrentRef = NULL;
bool found = false;
bool onlySecondChoiceTargetsFound = false;
bool checkedCurrentVictim = false;
ThreatList::const_iterator lastRef = iThreatList.end();
--lastRef;
for (ThreatList::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;)
{
pCurrentRef = (*iter);
Unit* pTarget = pCurrentRef->getTarget();
// MANGOS_ASSERT(pTarget); // if the ref has status online the target must be there!
if (!pTarget)
continue;
MAPLOCK_READ(pTarget, MAP_LOCK_TYPE_THREAT);
// some units are prefered in comparison to others
// if (checkThreatArea) consider IsOutOfThreatArea - expected to be only set for pCurrentVictim
// This prevents dropping valid targets due to 1.1 or 1.3 threat rule vs invalid current target
if (!onlySecondChoiceTargetsFound && pAttacker->IsSecondChoiceTarget(pTarget, pCurrentRef == pCurrentVictim))
{
if (iter != lastRef)
++iter;
else
{
// if we reached to this point, everyone in the threatlist is a second choice target. In such a situation the target with the highest threat should be attacked.
onlySecondChoiceTargetsFound = true;
iter = iThreatList.begin();
}
// current victim is a second choice target, so don't compare threat with it below
if (pCurrentRef == pCurrentVictim)
pCurrentVictim = NULL;
// second choice targets are only handled threat dependend if we have only have second choice targets
continue;
}
if (!pAttacker->IsOutOfThreatArea(pTarget)) // skip non attackable currently targets
{
if (pCurrentVictim) // select 1.3/1.1 better target in comparison current target
{
// normal case: pCurrentRef is still valid and most hated
if (pCurrentVictim == pCurrentRef)
{
found = true;
break;
}
// we found a valid target, but only compare its threat if the currect victim is also a valid target
// Additional check to prevent unneeded comparision in case of valid current victim
if (!checkedCurrentVictim)
{
Unit* pCurrentTarget = pCurrentVictim->getTarget();
MANGOS_ASSERT(pCurrentTarget);
if (pAttacker->IsSecondChoiceTarget(pCurrentTarget, true))
{
// CurrentVictim is invalid, so return CurrentRef
found = true;
break;
}
checkedCurrentVictim = true;
}
// list sorted and and we check current target, then this is best case
if (pCurrentRef->getThreat() <= 1.1f * pCurrentVictim->getThreat())
{
pCurrentRef = pCurrentVictim;
found = true;
break;
}
if (pCurrentRef->getThreat() > 1.3f * pCurrentVictim->getThreat() ||
(pCurrentRef->getThreat() > 1.1f * pCurrentVictim->getThreat() && pAttacker->CanReachWithMeleeAttack(pTarget)))
{ // implement 110% threat rule for targets in melee range
found = true; // and 130% rule for targets in ranged distances
break; // for selecting alive targets
}
}
else // select any
{
found = true;
break;
}
}
++iter;
}
if (!found)
pCurrentRef = NULL;
return pCurrentRef;
}
void BattleGroundAV::HandleQuestComplete(uint32 questid, Player* player)
{
if (GetStatus() != STATUS_IN_PROGRESS)
return;
BattleGroundAVTeamIndex teamIdx = GetAVTeamIndexByTeamId(player->GetBGTeam());
MANGOS_ASSERT(teamIdx != BG_AV_TEAM_NEUTRAL);
uint32 reputation = 0; // reputation for the whole team (other reputation must be done in db)
// TODO add events (including quest not available anymore, next quest availabe, go/npc de/spawning)
sLog.outError("BattleGroundAV: Quest %i completed", questid);
switch (questid)
{
case BG_AV_QUEST_A_SCRAPS1:
case BG_AV_QUEST_A_SCRAPS2:
case BG_AV_QUEST_H_SCRAPS1:
case BG_AV_QUEST_H_SCRAPS2:
m_Team_QuestStatus[teamIdx][0] += 20;
reputation = 1;
if (m_Team_QuestStatus[teamIdx][0] == 500 || m_Team_QuestStatus[teamIdx][0] == 1000 || m_Team_QuestStatus[teamIdx][0] == 1500) //25,50,75 turn ins
{
DEBUG_LOG("BattleGroundAV: Quest %i completed starting with unit upgrading..", questid);
for (BG_AV_Nodes i = BG_AV_NODES_FIRSTAID_STATION; i <= BG_AV_NODES_FROSTWOLF_HUT; ++i)
if (m_Nodes[i].Owner == teamIdx && m_Nodes[i].State == POINT_CONTROLLED)
PopulateNode(i);
}
break;
case BG_AV_QUEST_A_COMMANDER1:
case BG_AV_QUEST_H_COMMANDER1:
m_Team_QuestStatus[teamIdx][1]++;
reputation = 1;
if (m_Team_QuestStatus[teamIdx][1] == 120)
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here", questid);
break;
case BG_AV_QUEST_A_COMMANDER2:
case BG_AV_QUEST_H_COMMANDER2:
m_Team_QuestStatus[teamIdx][2]++;
reputation = 2;
if (m_Team_QuestStatus[teamIdx][2] == 60)
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here", questid);
break;
case BG_AV_QUEST_A_COMMANDER3:
case BG_AV_QUEST_H_COMMANDER3:
m_Team_QuestStatus[teamIdx][3]++;
reputation = 5;
if (m_Team_QuestStatus[teamIdx][1] == 30)
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here", questid);
break;
case BG_AV_QUEST_A_BOSS1:
case BG_AV_QUEST_H_BOSS1:
m_Team_QuestStatus[teamIdx][4] += 4; // there are 2 quests where you can turn in 5 or 1 item.. ( + 4 cause +1 will be done some lines below)
reputation = 4;
case BG_AV_QUEST_A_BOSS2:
case BG_AV_QUEST_H_BOSS2:
m_Team_QuestStatus[teamIdx][4]++;
reputation += 1;
if (m_Team_QuestStatus[teamIdx][4] >= 200)
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here", questid);
break;
case BG_AV_QUEST_A_NEAR_MINE:
case BG_AV_QUEST_H_NEAR_MINE:
m_Team_QuestStatus[teamIdx][5]++;
reputation = 2;
if (m_Team_QuestStatus[teamIdx][5] == 28)
{
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here", questid);
if (m_Team_QuestStatus[teamIdx][6] == 7)
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here - ground assault ready", questid);
}
break;
case BG_AV_QUEST_A_OTHER_MINE:
case BG_AV_QUEST_H_OTHER_MINE:
m_Team_QuestStatus[teamIdx][6]++;
reputation = 3;
if (m_Team_QuestStatus[teamIdx][6] == 7)
{
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here", questid);
if (m_Team_QuestStatus[teamIdx][5] == 20)
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here - ground assault ready", questid);
}
break;
case BG_AV_QUEST_A_RIDER_HIDE:
case BG_AV_QUEST_H_RIDER_HIDE:
m_Team_QuestStatus[teamIdx][7]++;
reputation = 1;
if (m_Team_QuestStatus[teamIdx][7] == 25)
{
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here", questid);
if (m_Team_QuestStatus[teamIdx][8] == 25)
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here - rider assault ready", questid);
}
break;
case BG_AV_QUEST_A_RIDER_TAME:
case BG_AV_QUEST_H_RIDER_TAME:
m_Team_QuestStatus[teamIdx][8]++;
reputation = 1;
if (m_Team_QuestStatus[teamIdx][8] == 25)
{
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here", questid);
if (m_Team_QuestStatus[teamIdx][7] == 25)
DEBUG_LOG("BattleGroundAV: Quest %i completed (need to implement some events here - rider assault ready", questid);
//.........这里部分代码省略.........
/**
* This function will board a passenger onto a vehicle
*
* @param passenger MUST be provided. This Unit will be boarded onto the vehicles (if it checks out)
* @param seat Seat to which the passenger will be boarded (if can, elsewise an alternative will be selected if possible)
*/
void VehicleInfo::Board(Unit* passenger, uint8 seat)
{
MANGOS_ASSERT(passenger);
DEBUG_LOG("VehicleInfo(of %s)::Board: Try to board passenger %s to seat %u", m_owner->GetGuidStr().c_str(), passenger->GetGuidStr().c_str(), seat);
// This check is also called in Spell::CheckCast()
if (!CanBoard(passenger))
return;
// Use the planned seat only if the seat is valid, possible to choose and empty
if (!IsSeatAvailableFor(passenger, seat))
if (!GetUsableSeatFor(passenger, seat))
return;
VehicleSeatEntry const* seatEntry = GetSeatEntry(seat);
MANGOS_ASSERT(seatEntry);
// ToDo: Unboard passenger from a MOTransport when they are properly implemented
/*if (TransportInfo* transportInfo = passenger->GetTransportInfo())
{
WorldObject* transporter = transportInfo->GetTransport();
// Must be a MO transporter
MANGOS_ASSERT(transporter->GetObjectGuid().IsMOTransport());
((Transport*)transporter)->UnBoardPassenger(passenger);
}*/
DEBUG_LOG("VehicleInfo::Board: Board passenger: %s to seat %u", passenger->GetGuidStr().c_str(), seat);
// Calculate passengers local position
float lx, ly, lz, lo;
CalculateBoardingPositionOf(passenger->GetPositionX(), passenger->GetPositionY(), passenger->GetPositionZ(), passenger->GetOrientation(), lx, ly, lz, lo);
BoardPassenger(passenger, lx, ly, lz, lo, seat); // Use TransportBase to store the passenger
// Set data for createobject packets
passenger->m_movementInfo.AddMovementFlag(MOVEFLAG_ONTRANSPORT);
passenger->m_movementInfo.SetTransportData(m_owner->GetObjectGuid(), lx, ly, lz, lo, 0, seat);
if (passenger->GetTypeId() == TYPEID_PLAYER)
{
Player* pPlayer = (Player*)passenger;
pPlayer->RemovePet(PET_SAVE_AS_CURRENT);
WorldPacket data(SMSG_ON_CANCEL_EXPECTED_RIDE_VEHICLE_AURA);
pPlayer->GetSession()->SendPacket(&data);
// SMSG_BREAK_TARGET (?)
}
if (!passenger->IsRooted())
passenger->SetRoot(true);
Movement::MoveSplineInit init(*passenger);
init.MoveTo(0.0f, 0.0f, 0.0f); // ToDo: Set correct local coords
init.SetFacing(0.0f); // local orientation ? ToDo: Set proper orientation!
init.SetBoardVehicle();
init.Launch();
// Apply passenger modifications
ApplySeatMods(passenger, seatEntry->m_flags);
}
请发表评论