Skip to content

Commit

Permalink
Core/Scripts: Remove some unnecessary creature/player casts in script…
Browse files Browse the repository at this point in the history
…s and do some safer casting in a silithus script
  • Loading branch information
kaelima committed Apr 9, 2012
1 parent 3988e8e commit 4c961ff
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 48 deletions.
11 changes: 5 additions & 6 deletions src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,11 @@ class npc_scarlet_ghoul : public CreatureScript
{
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());
}
}
}
Expand All @@ -826,10 +826,11 @@ class npc_scarlet_ghoul : public CreatureScript
{
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/scripts/EasternKingdoms/eversong_woods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,14 @@ class npc_apprentice_mirveda : public CreatureScript
{
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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/server/scripts/EasternKingdoms/isle_of_queldanas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class npc_greengill_slave : public CreatureScript
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);
Expand Down
72 changes: 40 additions & 32 deletions src/server/scripts/Kalimdor/silithus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,16 +979,14 @@ class npc_anachronos_quest_trigger : public CreatureScript
//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;
Expand All @@ -998,9 +996,11 @@ class npc_anachronos_quest_trigger : public CreatureScript

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;
}
}
}
}
Expand All @@ -1017,27 +1017,27 @@ class npc_anachronos_quest_trigger : public CreatureScript

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;
}

Expand Down Expand Up @@ -1081,8 +1081,13 @@ class npc_anachronos_quest_trigger : public CreatureScript
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();

};

Expand All @@ -1099,15 +1104,13 @@ class go_crystalline_tear : public GameObjectScript
{
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)
{
Expand Down Expand Up @@ -1135,11 +1138,16 @@ class go_crystalline_tear : public GameObjectScript

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;
}
}
}
}
Expand Down

0 comments on commit 4c961ff

Please sign in to comment.