mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-02-09 03:18:57 +01:00
Core/Scripts: Remove some unnecessary creature/player casts in scripts and do some safer casting in a silithus script
This commit is contained in:
@@ -297,14 +297,13 @@ void ScriptedAI::DoTeleportTo(const float position[4])
|
||||
|
||||
void ScriptedAI::DoTeleportPlayer(Unit* unit, float x, float y, float z, float o)
|
||||
{
|
||||
if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
|
||||
{
|
||||
if (unit)
|
||||
sLog->outError("TSCR: Creature " UI64FMTD " (Entry: %u) Tried to teleport non-player unit (Type: %u GUID: " UI64FMTD ") to x: %f y:%f z: %f o: %f. Aborted.", me->GetGUID(), me->GetEntry(), unit->GetTypeId(), unit->GetGUID(), x, y, z, o);
|
||||
if (!unit)
|
||||
return;
|
||||
}
|
||||
|
||||
CAST_PLR(unit)->TeleportTo(unit->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT);
|
||||
if (Player* player = unit->ToPlayer())
|
||||
player->TeleportTo(unit->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT);
|
||||
else
|
||||
sLog->outError("TSCR: Creature " UI64FMTD " (Entry: %u) Tried to teleport non-player unit (Type: %u GUID: " UI64FMTD ") to x: %f y:%f z: %f o: %f. Aborted.", me->GetGUID(), me->GetEntry(), unit->GetTypeId(), unit->GetGUID(), x, y, z, o);
|
||||
}
|
||||
|
||||
void ScriptedAI::DoTeleportAll(float x, float y, float z, float o)
|
||||
|
||||
@@ -809,11 +809,11 @@ public:
|
||||
{
|
||||
for (std::list<Creature*>::const_iterator itr = MinionList.begin(); itr != MinionList.end(); ++itr)
|
||||
{
|
||||
if (CAST_CRE(*itr)->GetOwner()->GetGUID() == me->GetOwner()->GetGUID())
|
||||
if ((*itr)->GetOwner()->GetGUID() == me->GetOwner()->GetGUID())
|
||||
{
|
||||
if (CAST_CRE(*itr)->isInCombat() && CAST_CRE(*itr)->getAttackerForHelper())
|
||||
if ((*itr)->isInCombat() && (*itr)->getAttackerForHelper())
|
||||
{
|
||||
AttackStart(CAST_CRE(*itr)->getAttackerForHelper());
|
||||
AttackStart((*itr)->getAttackerForHelper());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -826,10 +826,11 @@ public:
|
||||
{
|
||||
if (Unit* owner = me->GetOwner())
|
||||
{
|
||||
if (owner->GetTypeId() == TYPEID_PLAYER && CAST_PLR(owner)->isInCombat())
|
||||
Player* plrOwner = owner->ToPlayer();
|
||||
if (plrOwner && plrOwner->isInCombat())
|
||||
{
|
||||
if (CAST_PLR(owner)->getAttackerForHelper() && CAST_PLR(owner)->getAttackerForHelper()->GetEntry() == GHOSTS)
|
||||
AttackStart(CAST_PLR(owner)->getAttackerForHelper());
|
||||
if (plrOwner->getAttackerForHelper() && plrOwner->getAttackerForHelper()->GetEntry() == GHOSTS)
|
||||
AttackStart(plrOwner->getAttackerForHelper());
|
||||
else
|
||||
FindMinions(owner);
|
||||
}
|
||||
|
||||
@@ -490,14 +490,14 @@ public:
|
||||
{
|
||||
if (PlayerGUID)
|
||||
if (Player* player = Unit::GetPlayer(*me, PlayerGUID))
|
||||
CAST_PLR(player)->FailQuest(QUEST_UNEXPECTED_RESULT);
|
||||
player->FailQuest(QUEST_UNEXPECTED_RESULT);
|
||||
}
|
||||
|
||||
void UpdateAI(const uint32 /*diff*/)
|
||||
{
|
||||
if (KillCount >= 3 && PlayerGUID)
|
||||
if (Player* player = Unit::GetPlayer(*me, PlayerGUID))
|
||||
CAST_PLR(player)->CompleteQuest(QUEST_UNEXPECTED_RESULT);
|
||||
player->CompleteQuest(QUEST_UNEXPECTED_RESULT);
|
||||
|
||||
if (Summon)
|
||||
{
|
||||
|
||||
@@ -129,8 +129,8 @@ public:
|
||||
PlayerGUID = caster->GetGUID();
|
||||
if (PlayerGUID)
|
||||
{
|
||||
Unit* player = Unit::GetUnit(*me, PlayerGUID);
|
||||
if (player && CAST_PLR(player)->GetQuestStatus(QUESTG) == QUEST_STATUS_INCOMPLETE)
|
||||
Player* player = Unit::GetPlayer(*me, PlayerGUID);
|
||||
if (player && player->GetQuestStatus(QUESTG) == QUEST_STATUS_INCOMPLETE)
|
||||
DoCast(player, 45110, true);
|
||||
}
|
||||
DoCast(me, ENRAGE);
|
||||
|
||||
@@ -979,16 +979,14 @@ public:
|
||||
//uint8 QirajiWaspCount = 0;
|
||||
for (uint8 i = 0; i < 67; ++i)
|
||||
{
|
||||
float X = SpawnLocation[locIndex + i].x;
|
||||
float Y = SpawnLocation[locIndex + i].y;
|
||||
float Z = SpawnLocation[locIndex + i].z;
|
||||
float O = SpawnLocation[locIndex + i].o;
|
||||
float x = SpawnLocation[locIndex + i].x;
|
||||
float y = SpawnLocation[locIndex + i].y;
|
||||
float z = SpawnLocation[locIndex + i].z;
|
||||
float o = SpawnLocation[locIndex + i].o;
|
||||
uint32 desptimer = WavesInfo[WaveCount].DespTimer;
|
||||
Creature* spawn = me->SummonCreature(WavesInfo[WaveCount].CreatureId, X, Y, Z, O, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, desptimer);
|
||||
|
||||
if (spawn)
|
||||
if (Creature* spawn = me->SummonCreature(WavesInfo[WaveCount].CreatureId, x, y, z, o, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, desptimer))
|
||||
{
|
||||
spawn->LoadCreaturesAddon();
|
||||
if (spawn->GetEntry() == 15423)
|
||||
spawn->SetUInt32Value(UNIT_FIELD_DISPLAYID, 15427+rand()%4);
|
||||
if (i >= 30) WaveCount = 1;
|
||||
@@ -998,9 +996,11 @@ public:
|
||||
|
||||
if (WaveCount < 5) //1-4 Wave
|
||||
{
|
||||
mob_qiraj_war_spawn::mob_qiraj_war_spawnAI* spawnAI = CAST_AI(mob_qiraj_war_spawn::mob_qiraj_war_spawnAI, spawn->AI());
|
||||
spawnAI->MobGUID = me->GetGUID();
|
||||
spawnAI->PlayerGUID = PlayerGUID;
|
||||
if (mob_qiraj_war_spawn::mob_qiraj_war_spawnAI* spawnAI = CAST_AI(mob_qiraj_war_spawn::mob_qiraj_war_spawnAI, spawn->AI()))
|
||||
{
|
||||
spawnAI->MobGUID = me->GetGUID();
|
||||
spawnAI->PlayerGUID = PlayerGUID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1017,27 +1017,27 @@ public:
|
||||
|
||||
if (Group* EventGroup = player->GetGroup())
|
||||
{
|
||||
Player* GroupMember;
|
||||
Player* groupMember;
|
||||
|
||||
uint8 GroupMemberCount = 0;
|
||||
uint8 DeadMemberCount = 0;
|
||||
uint8 FailedMemberCount = 0;
|
||||
|
||||
const Group::MemberSlotList members = EventGroup->GetMemberSlots();
|
||||
Group::MemberSlotList const members = EventGroup->GetMemberSlots();
|
||||
|
||||
for (Group::member_citerator itr = members.begin(); itr!= members.end(); ++itr)
|
||||
{
|
||||
GroupMember = (Unit::GetPlayer(*me, itr->guid));
|
||||
if (!GroupMember)
|
||||
groupMember = (Unit::GetPlayer(*me, itr->guid));
|
||||
if (!groupMember)
|
||||
continue;
|
||||
if (!GroupMember->IsWithinDistInMap(me, EVENT_AREA_RADIUS) && GroupMember->GetQuestStatus(QUEST_A_PAWN_ON_THE_ETERNAL_BOARD) == QUEST_STATUS_INCOMPLETE)
|
||||
if (!groupMember->IsWithinDistInMap(me, EVENT_AREA_RADIUS) && groupMember->GetQuestStatus(QUEST_A_PAWN_ON_THE_ETERNAL_BOARD) == QUEST_STATUS_INCOMPLETE)
|
||||
{
|
||||
GroupMember->FailQuest(QUEST_A_PAWN_ON_THE_ETERNAL_BOARD);
|
||||
groupMember->FailQuest(QUEST_A_PAWN_ON_THE_ETERNAL_BOARD);
|
||||
++FailedMemberCount;
|
||||
}
|
||||
++GroupMemberCount;
|
||||
|
||||
if (GroupMember->isDead())
|
||||
if (groupMember->isDead())
|
||||
++DeadMemberCount;
|
||||
}
|
||||
|
||||
@@ -1081,8 +1081,13 @@ public:
|
||||
void mob_qiraj_war_spawn::mob_qiraj_war_spawnAI::JustDied(Unit* /*slayer*/)
|
||||
{
|
||||
me->RemoveCorpse();
|
||||
if (Creature* Mob = (Unit::GetCreature(*me, MobGUID)))
|
||||
CAST_AI(npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI, Mob->AI())->LiveCounter();
|
||||
|
||||
if (!MobGUID)
|
||||
return;
|
||||
|
||||
if (Creature* mob = Unit::GetCreature(*me, MobGUID))
|
||||
if (npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI* triggerAI = CAST_AI(npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI, mob->AI()))
|
||||
triggerAI->LiveCounter();
|
||||
|
||||
};
|
||||
|
||||
@@ -1099,15 +1104,13 @@ public:
|
||||
{
|
||||
if (quest->GetQuestId() == QUEST_A_PAWN_ON_THE_ETERNAL_BOARD)
|
||||
{
|
||||
|
||||
if (Unit* Anachronos_Quest_Trigger = go->FindNearestCreature(15454, 100, player))
|
||||
if (Creature* trigger = go->FindNearestCreature(15454, 100, player))
|
||||
{
|
||||
|
||||
Unit* Merithra = Anachronos_Quest_Trigger->SummonCreature(15378, -8034.535f, 1535.14f, 2.61f, 0, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
Unit* Caelestrasz = Anachronos_Quest_Trigger->SummonCreature(15379, -8032.767f, 1533.148f, 2.61f, 1.5f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
Unit* Arygos = Anachronos_Quest_Trigger->SummonCreature(15380, -8034.52f, 1537.843f, 2.61f, 5.7f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
/* Unit* Fandral = */ Anachronos_Quest_Trigger->SummonCreature(15382, -8028.462f, 1535.843f, 2.61f, 3.141592f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
Creature* Anachronos = Anachronos_Quest_Trigger->SummonCreature(15381, -8028.75f, 1538.795f, 2.61f, 4, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
Unit* Merithra = trigger->SummonCreature(15378, -8034.535f, 1535.14f, 2.61f, 0, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
Unit* Caelestrasz = trigger->SummonCreature(15379, -8032.767f, 1533.148f, 2.61f, 1.5f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
Unit* Arygos = trigger->SummonCreature(15380, -8034.52f, 1537.843f, 2.61f, 5.7f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
/* Unit* Fandral = */ trigger->SummonCreature(15382, -8028.462f, 1535.843f, 2.61f, 3.141592f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
Creature* Anachronos = trigger->SummonCreature(15381, -8028.75f, 1538.795f, 2.61f, 4, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 220000);
|
||||
|
||||
if (Merithra)
|
||||
{
|
||||
@@ -1135,11 +1138,16 @@ public:
|
||||
|
||||
if (Anachronos)
|
||||
{
|
||||
CAST_AI(npc_anachronos_the_ancient::npc_anachronos_the_ancientAI, Anachronos->AI())->PlayerGUID = player->GetGUID();
|
||||
CAST_AI(npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI, CAST_CRE(Anachronos_Quest_Trigger)->AI())->Failed=false;
|
||||
CAST_AI(npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI, CAST_CRE(Anachronos_Quest_Trigger)->AI())->PlayerGUID = player->GetGUID();
|
||||
CAST_AI(npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI, CAST_CRE(Anachronos_Quest_Trigger)->AI())->EventStarted=true;
|
||||
CAST_AI(npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI, CAST_CRE(Anachronos_Quest_Trigger)->AI())->Announced=true;
|
||||
if (npc_anachronos_the_ancient::npc_anachronos_the_ancientAI* anachronosAI = CAST_AI(npc_anachronos_the_ancient::npc_anachronos_the_ancientAI, Anachronos->AI()))
|
||||
anachronosAI->PlayerGUID = player->GetGUID();
|
||||
|
||||
if (npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI* triggerAI = CAST_AI(npc_anachronos_quest_trigger::npc_anachronos_quest_triggerAI, trigger->AI()))
|
||||
{
|
||||
triggerAI->Failed = false;
|
||||
triggerAI->PlayerGUID = player->GetGUID();
|
||||
triggerAI->EventStarted = true;
|
||||
triggerAI->Announced = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user