/* Actual Spell Code */ bool HandleDummySpell(uint32 uSpellId, uint32 i, Spell *pSpell) { script_debuglog("Dummy spell call for spell %u = Life Tap, dmg: %u", uSpellId, pSpell->damage); // obtain our target Unit *target = pSpell->GetUnitTarget(); if(target == NULL) { script_errorlog("Dummy spell %u (Life Tap) called with null unittarget!", uSpellId); return false; } // take the health from the player (20, etc) target->DealDamage(target, pSpell->damage, 0, 0, 0); // add the mana to the players mana (but check if we're bigger than max mana) // UNIT_FIELD_POWER1 == Mana uint32 new_val = target->GetUInt32Value(UNIT_FIELD_POWER1); uint32 max_val = target->GetUInt32Value(UNIT_FIELD_MAXPOWER1); new_val += pSpell->damage; // (new_val > max_val ? max_val : new_val) // means: if(new_val > max_val) use max_val as mana value // else use new_val as the mana val target->SetUInt32Value(UNIT_FIELD_POWER1, (new_val > max_val ? max_val : new_val)); // success. return true; }
bool GOQuestAccept_GO_crystalline_tear(Player* plr, GameObject* go, Quest const* quest) { if (quest->GetQuestId() == QUEST_A_PAWN_ON_THE_ETERNAL_BOARD) { if (Unit* Anachronos_Quest_Trigger = go->FindNearestCreature(15454, 100, plr)) { Unit *Merithra = Anachronos_Quest_Trigger->SummonCreature(15378,-8034.535,1535.14,2.61,0,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,220000); Unit *Caelestrasz = Anachronos_Quest_Trigger->SummonCreature(15379,-8032.767, 1533.148,2.61, 1.5,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,220000); Unit *Arygos = Anachronos_Quest_Trigger->SummonCreature(15380,-8034.52, 1537.843, 2.61, 5.7,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,220000); /* Unit *Fandral = */ Anachronos_Quest_Trigger->SummonCreature(15382,-8028.462, 1535.843, 2.61, 3.141592,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,220000); Creature *Anachronos = Anachronos_Quest_Trigger->SummonCreature(15381,-8028.75, 1538.795, 2.61, 4,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,220000); if (Merithra) { Merithra->SetUInt32Value(UNIT_NPC_FLAGS, 0); Merithra->SetUInt32Value(UNIT_FIELD_BYTES_1,0); Merithra->SetUInt32Value(UNIT_FIELD_DISPLAYID,15420); Merithra->setFaction(35); } if (Caelestrasz) { Caelestrasz->SetUInt32Value(UNIT_NPC_FLAGS, 0); Caelestrasz->SetUInt32Value(UNIT_FIELD_BYTES_1,0); Caelestrasz->SetUInt32Value(UNIT_FIELD_DISPLAYID,15419); Caelestrasz->setFaction(35); } if (Arygos) { Arygos->SetUInt32Value(UNIT_NPC_FLAGS, 0); Arygos->SetUInt32Value(UNIT_FIELD_BYTES_1,0); Arygos->SetUInt32Value(UNIT_FIELD_DISPLAYID,15418); Arygos->setFaction(35); } if (Anachronos) { CAST_AI(npc_anachronos_the_ancientAI, Anachronos->AI())->PlayerGUID = plr->GetGUID(); CAST_AI(npc_anachronos_quest_triggerAI, CAST_CRE(Anachronos_Quest_Trigger)->AI())->Failed=false; CAST_AI(npc_anachronos_quest_triggerAI, CAST_CRE(Anachronos_Quest_Trigger)->AI())->PlayerGUID = plr->GetGUID(); CAST_AI(npc_anachronos_quest_triggerAI, CAST_CRE(Anachronos_Quest_Trigger)->AI())->EventStarted=true; CAST_AI(npc_anachronos_quest_triggerAI, CAST_CRE(Anachronos_Quest_Trigger)->AI())->Announced=true; } } } return true; }
bool ChatHandler::HandleEmoteCommand(const char* args, WorldSession *m_session) { uint32 emote = atoi((char*)args); Unit* target = this->getSelectedCreature(m_session); if (!target) return false; if (target) target->SetUInt32Value(UNIT_NPC_EMOTESTATE, emote); return true; }
void Pet::UpdateSpellPower() { Unit* owner = GetOwner(); if(!owner || owner->GetTypeId()!=TYPEID_PLAYER) return; // Only for displaying in client! owner->SetUInt32Value(PLAYER_PET_SPELL_POWER, SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_SPELL)); }
void Pet::UpdateSpellPower() { Unit* owner = GetOwner(); if(!owner ||owner->GetTypeId()!=TYPEID_PLAYER || !owner->IsInWorld()) return; MAPLOCK_READ(owner,MAP_LOCK_TYPE_AURAS); // Only for displaying in client! owner->SetUInt32Value(PLAYER_PET_SPELL_POWER, SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_SPELL)); }
bool ChatHandler::HandleEmoteCommand(const char* args) { uint32 emote = atoi((char*)args); Player* chr = m_session->GetPlayer(); if(chr->GetSelection() == 0) return false; Unit* target = ObjectAccessor::Instance().GetCreature(*chr, chr->GetSelection()); target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote); return true; }
uint32 NextStep(uint32 Step) { Player* player = Unit::GetPlayer(*me, PlayerGUID); switch (Step) { case 0: { me->SetInFront(player); Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20); if (Creepjack) Creepjack->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20); if (Malone) Malone->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); return 2000; } case 1: DoScriptText(SAY_1, me, player); return 3000; case 2: DoScriptText(SAY_2, me, player); return 5000; case 3: DoScriptText(SAY_3, me, player); return 2000; case 4: DoScriptText(SAY_4, me, player); return 2000; case 5: DoScriptText(SAY_5, me, player); return 2000; case 6: Attack = true; return 2000; default: return 0; } }
void Mana() { /* Attempt to get a Fel Crystal and move to it if not in range. Once in range we get the FelCrystal to cast Mana Rage on Selin */ Unit *FelCrystal = NULL; PreventActions(false); FelCrystal = FindFelCrystal(); if(!FelCrystal || !FelCrystal->isAlive()) { PreventActions(true); FelCrystal = NULL; return; } // Not in range if(_unit->GetDistance2dSq(FelCrystal) > 50) { MoveTo(FelCrystal->GetPositionX(), FelCrystal->GetPositionY(), FelCrystal->GetPositionZ()); FelCrystal = NULL; return; } _unit->GetAIInterface()->StopMovement(0); if(!FelCrystal->GetCurrentSpell()) FelCrystal->CastSpell(_unit, ManaRage, false); //nastavim attackable FelCrystal->SetUInt32Value(UNIT_FIELD_FLAGS, 0); // Mana Rage giving of mana doesnt work so we give 10%(3231) / AIUpdate() Event. CastSpellNowNoScheduling(ManaRageTrigger); uint32 mana = _unit->GetUInt32Value(UNIT_FIELD_POWER1)+3231; if(mana >= _unit->GetUInt32Value(UNIT_FIELD_MAXPOWER1)) mana = _unit->GetUInt32Value(UNIT_FIELD_MAXPOWER1); _unit->SetUInt32Value(UNIT_FIELD_POWER1, mana); // Re-Enable FelExplosion if(GetManaPercent() >= 100) PreventActions(true); FelCrystal = NULL; }
void DamageTaken(Unit *done_by, uint32 &damage) { Unit *pOtherBoss = GetOtherBoss(); if (pOtherBoss) { float dPercent = ((float)damage) / ((float)m_creature->GetMaxHealth()); int odmg = (int)(dPercent * ((float)pOtherBoss->GetMaxHealth())); int ohealth = pOtherBoss->GetHealth()-odmg; pOtherBoss->SetHealth(ohealth > 0 ? ohealth : 0); if (ohealth <= 0) { pOtherBoss->setDeathState(JUST_DIED); pOtherBoss->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); } } }
void UpdateAI(const uint32 diff) { if (!UpdateVictim()) return; //Check_Timer for the death of LorKhan and Zath. if (!WasDead && Check_Timer <= diff) { if (m_pInstance) { if (m_pInstance->GetData(TYPE_LORKHAN) == SPECIAL) { //Resurrect LorKhan if (Unit *pLorKhan = Unit::GetUnit((*me), m_pInstance->GetData64(DATA_LORKHAN))) { pLorKhan->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); pLorKhan->setFaction(14); pLorKhan->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); pLorKhan->SetFullHealth(); m_pInstance->SetData(TYPE_LORKHAN, DONE); } } if (m_pInstance->GetData(TYPE_ZATH) == SPECIAL) { //Resurrect Zath Unit *pZath = Unit::GetUnit((*me), m_pInstance->GetData64(DATA_ZATH)); if (pZath) { pZath->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); pZath->setFaction(14); pZath->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); pZath->SetFullHealth(); m_pInstance->SetData(TYPE_ZATH, DONE); } } } Check_Timer = 5000; } else Check_Timer -= diff; if (!PhaseTwo && MortalCleave_Timer <= diff) { DoCast(me->getVictim(), SPELL_MORTALCLEAVE); MortalCleave_Timer = 15000 + rand()%5000; } else MortalCleave_Timer -= diff; if (!PhaseTwo && Silence_Timer <= diff) { DoCast(me->getVictim(), SPELL_SILENCE); Silence_Timer = 20000 + rand()%5000; } else Silence_Timer -= diff; if (!PhaseTwo && !WasDead && !HealthAbovePct(5)) { me->RemoveAurasByType(SPELL_AURA_PERIODIC_DAMAGE_PERCENT); me->RemoveAurasByType(SPELL_AURA_PERIODIC_DAMAGE); me->RemoveAurasByType(SPELL_AURA_PERIODIC_LEECH); me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); me->SetStandState(UNIT_STAND_STATE_SLEEP); me->AttackStop(); if (m_pInstance) m_pInstance->SetData(TYPE_THEKAL, SPECIAL); WasDead=true; } //Thekal will transform to Tiger if he died and was not resurrected after 10 seconds. if (!PhaseTwo && WasDead) { if (Resurrect_Timer <= diff) { DoCast(me, SPELL_TIGER_FORM); me->SetFloatValue(OBJECT_FIELD_SCALE_X, 2.00f); me->SetStandState(UNIT_STAND_STATE_STAND); me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); me->SetFullHealth(); const CreatureInfo *cinfo = me->GetCreatureInfo(); me->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 40))); me->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 40))); me->UpdateDamagePhysical(BASE_ATTACK); DoResetThreat(); PhaseTwo = true; } else Resurrect_Timer -= diff; } if (me->IsFullHealth() && WasDead) { WasDead = false; } if (PhaseTwo) { if (Charge_Timer <= diff) { if (Unit *pTarget = SelectTarget(SELECT_TARGET_RANDOM,0)) { DoCast(pTarget, SPELL_CHARGE); DoResetThreat(); AttackStart(pTarget); } Charge_Timer = 15000 + rand()%7000; } else Charge_Timer -= diff; if (Frenzy_Timer <= diff) { DoCast(me, SPELL_FRENZY); Frenzy_Timer = 30000; } else Frenzy_Timer -= diff; if (ForcePunch_Timer <= diff) { DoCast(me->getVictim(), SPELL_SILENCE); ForcePunch_Timer = 16000 + rand()%5000; } else ForcePunch_Timer -= diff; if (SummonTigers_Timer <= diff) { DoCast(me->getVictim(), SPELL_SUMMONTIGERS); SummonTigers_Timer = 10000 + rand()%4000; } else SummonTigers_Timer -= diff; if (HealthBelowPct(11) && !Enraged) { DoCast(me, SPELL_ENRAGE); Enraged = true; } } DoMeleeAttackIfReady(); }
void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 rnd, uint32 eventId, Unit* actionInvoker) { switch (action.type) { case ACTION_T_TEXT: { if (!action.text.TextId1) return; int32 temp = action.text.TextId1; if (action.text.TextId2 && action.text.TextId3) temp = RAND(action.text.TextId1, action.text.TextId2, action.text.TextId3); else if (action.text.TextId2 && urand(0, 1)) temp = action.text.TextId2; if (temp) { Unit* target = NULL; if (actionInvoker) { if (actionInvoker->GetTypeId() == TYPEID_PLAYER) target = actionInvoker; else if (Unit* owner = actionInvoker->GetOwner()) { if (owner->GetTypeId() == TYPEID_PLAYER) target = owner; } } else { target = me->getVictim(); if (target && target->GetTypeId() != TYPEID_PLAYER) if (Unit* owner = target->GetOwner()) if (owner->GetTypeId() == TYPEID_PLAYER) target = owner; } DoScriptText(temp, me, target); } break; } case ACTION_T_SET_FACTION: { if (action.set_faction.factionId) me->setFaction(action.set_faction.factionId); else { if (CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(me->GetEntry())) { //if no id provided, assume reset and then use default if (me->getFaction() != ci->faction_A) me->setFaction(ci->faction_A); } } break; } case ACTION_T_MORPH_TO_ENTRY_OR_MODEL: { if (action.morph.creatureId || action.morph.modelId) { //set model based on entry from creature_template if (action.morph.creatureId) { if (CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(action.morph.creatureId)) { uint32 display_id = sObjectMgr->ChooseDisplayId(0, ci); me->SetDisplayId(display_id); } } //if no param1, then use value from param2 (modelId) else me->SetDisplayId(action.morph.modelId); } else me->DeMorph(); break; } case ACTION_T_SOUND: me->PlayDirectSound(action.sound.soundId); break; case ACTION_T_EMOTE: me->HandleEmoteCommand(action.emote.emoteId); break; case ACTION_T_RANDOM_SOUND: { int32 temp = GetRandActionParam(rnd, action.random_sound.soundId1, action.random_sound.soundId2, action.random_sound.soundId3); if (temp >= 0) me->PlayDirectSound(temp); break; } case ACTION_T_RANDOM_EMOTE: { int32 temp = GetRandActionParam(rnd, action.random_emote.emoteId1, action.random_emote.emoteId2, action.random_emote.emoteId3); if (temp >= 0) me->HandleEmoteCommand(temp); break; } case ACTION_T_CAST: { Unit* target = GetTargetByType(action.cast.target, actionInvoker); Unit* caster = me; if (!target) return; if (action.cast.castFlags & CAST_FORCE_TARGET_SELF) caster = target; //Allowed to cast only if not casting (unless we interrupt ourself) or if spell is triggered bool canCast = !caster->IsNonMeleeSpellCasted(false) || (action.cast.castFlags & (CAST_TRIGGERED | CAST_INTERRUPT_PREVIOUS)); // If cast flag CAST_AURA_NOT_PRESENT is active, check if target already has aura on them if (action.cast.castFlags & CAST_AURA_NOT_PRESENT) { if (target->HasAura(action.cast.spellId)) return; } if (canCast) { const SpellInfo* tSpell = sSpellMgr->GetSpellInfo(action.cast.spellId); //Verify that spell exists if (tSpell) { //Check if cannot cast spell if (!(action.cast.castFlags & (CAST_FORCE_TARGET_SELF | CAST_FORCE_CAST)) && !CanCast(target, tSpell, (action.cast.castFlags & CAST_TRIGGERED))) { //Melee current victim if flag not set if (!(action.cast.castFlags & CAST_NO_MELEE_IF_OOM)) { if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE) { m_AttackDistance = 0.0f; m_AttackAngle = 0.0f; me->GetMotionMaster()->MoveChase(me->getVictim(), m_AttackDistance, m_AttackAngle); } } } else { //Interrupt any previous spell if (caster->IsNonMeleeSpellCasted(false) && action.cast.castFlags & CAST_INTERRUPT_PREVIOUS) caster->InterruptNonMeleeSpells(false); caster->CastSpell(target, action.cast.spellId, (action.cast.castFlags & CAST_TRIGGERED)); } } else sLog->outErrorDb("CreatureEventAI: event %d creature %d attempt to cast spell that doesn't exist %d", eventId, me->GetEntry(), action.cast.spellId); } break; } case ACTION_T_SUMMON: { Unit* target = GetTargetByType(action.summon.target, actionInvoker); Creature* creature = NULL; if (action.summon.duration) creature = me->SummonCreature(action.summon.creatureId, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, action.summon.duration); else creature = me->SummonCreature(action.summon.creatureId, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 0); if (!creature) sLog->outErrorDb("CreatureEventAI: failed to spawn creature %u. Spawn event %d is on creature %d", action.summon.creatureId, eventId, me->GetEntry()); else if (action.summon.target != TARGET_T_SELF && target) creature->AI()->AttackStart(target); break; } case ACTION_T_THREAT_SINGLE_PCT: if (Unit* target = GetTargetByType(action.threat_single_pct.target, actionInvoker)) me->getThreatManager().modifyThreatPercent(target, action.threat_single_pct.percent); break; case ACTION_T_THREAT_ALL_PCT: { std::list<HostileReference*>& threatList = me->getThreatManager().getThreatList(); for (std::list<HostileReference*>::iterator i = threatList.begin(); i != threatList.end(); ++i) if (Unit* Temp = Unit::GetUnit(*me, (*i)->getUnitGuid())) me->getThreatManager().modifyThreatPercent(Temp, action.threat_all_pct.percent); break; } case ACTION_T_QUEST_EVENT: if (Unit* target = GetTargetByType(action.quest_event.target, actionInvoker)) if (target->GetTypeId() == TYPEID_PLAYER) target->ToPlayer()->AreaExploredOrEventHappens(action.quest_event.questId); break; case ACTION_T_CAST_EVENT: if (Unit* target = GetTargetByType(action.cast_event.target, actionInvoker)) if (target->GetTypeId() == TYPEID_PLAYER) target->ToPlayer()->CastedCreatureOrGO(action.cast_event.creatureId, me->GetGUID(), action.cast_event.spellId); break; case ACTION_T_SET_UNIT_FIELD: { Unit* target = GetTargetByType(action.set_unit_field.target, actionInvoker); // not allow modify important for integrity object fields if (action.set_unit_field.field < OBJECT_END || action.set_unit_field.field >= UNIT_END) return; if (target) target->SetUInt32Value(action.set_unit_field.field, action.set_unit_field.value); break; } case ACTION_T_SET_UNIT_FLAG: if (Unit* target = GetTargetByType(action.unit_flag.target, actionInvoker)) target->SetFlag(UNIT_FIELD_FLAGS, action.unit_flag.value); break; case ACTION_T_REMOVE_UNIT_FLAG: if (Unit* target = GetTargetByType(action.unit_flag.target, actionInvoker)) target->RemoveFlag(UNIT_FIELD_FLAGS, action.unit_flag.value); break; case ACTION_T_AUTO_ATTACK: m_MeleeEnabled = action.auto_attack.state != 0; break; case ACTION_T_COMBAT_MOVEMENT: // ignore no affect case if (m_CombatMovementEnabled == (action.combat_movement.state != 0)) return; m_CombatMovementEnabled = action.combat_movement.state != 0; //Allow movement (create new targeted movement gen only if idle) if (m_CombatMovementEnabled) { Unit* victim = me->getVictim(); if (me->isInCombat() && victim) { if (action.combat_movement.melee) { me->AddUnitState(UNIT_STATE_MELEE_ATTACKING); me->SendMeleeAttackStart(victim); } if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE) me->GetMotionMaster()->MoveChase(victim, m_AttackDistance, m_AttackAngle); // Targeted movement generator will start melee automatically, no need to send it explicitly } } else { if (me->isInCombat()) { Unit* victim = me->getVictim(); if (action.combat_movement.melee && victim) { me->ClearUnitState(UNIT_STATE_MELEE_ATTACKING); me->SendMeleeAttackStop(victim); } if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE) me->GetMotionMaster()->MoveIdle(); } } break; case ACTION_T_SET_PHASE: m_Phase = action.set_phase.phase; break; case ACTION_T_INC_PHASE: { int32 new_phase = int32(m_Phase)+action.set_inc_phase.step; if (new_phase < 0) { sLog->outErrorDb("CreatureEventAI: Event %d decrease m_Phase under 0. CreatureEntry = %d", eventId, me->GetEntry()); m_Phase = 0; } else if (new_phase >= MAX_PHASE) { sLog->outErrorDb("CreatureEventAI: Event %d incremented m_Phase above %u. m_Phase mask cannot be used with phases past %u. CreatureEntry = %d", eventId, MAX_PHASE-1, MAX_PHASE-1, me->GetEntry()); m_Phase = MAX_PHASE-1; } else m_Phase = new_phase; break; } case ACTION_T_EVADE: EnterEvadeMode(); break; case ACTION_T_FLEE_FOR_ASSIST: me->DoFleeToGetAssistance(); break; case ACTION_T_QUEST_EVENT_ALL: if (actionInvoker && actionInvoker->GetTypeId() == TYPEID_PLAYER) { if (Unit* Temp = Unit::GetUnit(*me, actionInvoker->GetGUID())) if (Temp->GetTypeId() == TYPEID_PLAYER) Temp->ToPlayer()->GroupEventHappens(action.quest_event_all.questId, me); } break; case ACTION_T_CAST_EVENT_ALL: { std::list<HostileReference*>& threatList = me->getThreatManager().getThreatList(); for (std::list<HostileReference*>::iterator i = threatList.begin(); i != threatList.end(); ++i) if (Unit* Temp = Unit::GetUnit(*me, (*i)->getUnitGuid())) if (Temp->GetTypeId() == TYPEID_PLAYER) Temp->ToPlayer()->CastedCreatureOrGO(action.cast_event_all.creatureId, me->GetGUID(), action.cast_event_all.spellId); break; } case ACTION_T_REMOVEAURASFROMSPELL: if (Unit* target = GetTargetByType(action.remove_aura.target, actionInvoker)) target->RemoveAurasDueToSpell(action.remove_aura.spellId); break; case ACTION_T_RANGED_MOVEMENT: m_AttackDistance = (float)action.ranged_movement.distance; m_AttackAngle = action.ranged_movement.angle/180.0f*M_PI; if (m_CombatMovementEnabled) { me->GetMotionMaster()->MoveChase(me->getVictim(), m_AttackDistance, m_AttackAngle); } break; case ACTION_T_RANDOM_PHASE: m_Phase = GetRandActionParam(rnd, action.random_phase.phase1, action.random_phase.phase2, action.random_phase.phase3); break; case ACTION_T_RANDOM_PHASE_RANGE: if (action.random_phase_range.phaseMin <= action.random_phase_range.phaseMax) m_Phase = urand(action.random_phase_range.phaseMin, action.random_phase_range.phaseMax); else sLog->outErrorDb("CreatureEventAI: ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 < Param1. Event = %d. CreatureEntry = %d", eventId, me->GetEntry()); break; case ACTION_T_SUMMON_ID: { Unit* target = GetTargetByType(action.summon_id.target, actionInvoker); CreatureEventAI_Summon_Map::const_iterator i = sEventAIMgr->GetCreatureEventAISummonMap().find(action.summon_id.spawnId); if (i == sEventAIMgr->GetCreatureEventAISummonMap().end()) { sLog->outErrorDb("CreatureEventAI: failed to spawn creature %u. Summon map index %u does not exist. EventID %d. CreatureID %d", action.summon_id.creatureId, action.summon_id.spawnId, eventId, me->GetEntry()); return; } Creature* creature = NULL; if ((*i).second.SpawnTimeSecs) creature = me->SummonCreature(action.summon_id.creatureId, (*i).second.position_x, (*i).second.position_y, (*i).second.position_z, (*i).second.orientation, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, (*i).second.SpawnTimeSecs); else creature = me->SummonCreature(action.summon_id.creatureId, (*i).second.position_x, (*i).second.position_y, (*i).second.position_z, (*i).second.orientation, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 0); if (!creature) sLog->outErrorDb("CreatureEventAI: failed to spawn creature %u. EventId %d.Creature %d", action.summon_id.creatureId, eventId, me->GetEntry()); else if (action.summon_id.target != TARGET_T_SELF && target) creature->AI()->AttackStart(target); break; } case ACTION_T_KILLED_MONSTER: //first attempt player who tapped creature if (Player* player = me->GetLootRecipient()) player->RewardPlayerAndGroupAtEvent(action.killed_monster.creatureId, player); // player as param is a hacky solution not to use GUID else { //if not available, use actionInvoker if (Unit* target = GetTargetByType(action.killed_monster.target, actionInvoker)) if (Player* player2 = target->GetCharmerOrOwnerPlayerOrPlayerItself()) player2->RewardPlayerAndGroupAtEvent(action.killed_monster.creatureId, player2); } break; case ACTION_T_SET_INST_DATA: { InstanceScript* instance = (InstanceScript*)me->GetInstanceScript(); if (!instance) { sLog->outErrorDb("CreatureEventAI: Event %d attempt to set instance data without instance script. Creature %d", eventId, me->GetEntry()); return; } instance->SetData(action.set_inst_data.field, action.set_inst_data.value); break; } case ACTION_T_SET_INST_DATA64: { Unit* target = GetTargetByType(action.set_inst_data64.target, actionInvoker); if (!target) { sLog->outErrorDb("CreatureEventAI: Event %d attempt to set instance data64 but Target == NULL. Creature %d", eventId, me->GetEntry()); return; } InstanceScript* instance = (InstanceScript*)me->GetInstanceScript(); if (!instance) { sLog->outErrorDb("CreatureEventAI: Event %d attempt to set instance data64 without instance script. Creature %d", eventId, me->GetEntry()); return; } instance->SetData64(action.set_inst_data64.field, target->GetGUID()); break; } case ACTION_T_UPDATE_TEMPLATE: if (me->GetEntry() == action.update_template.creatureId) { sLog->outErrorDb("CreatureEventAI: Event %d ACTION_T_UPDATE_TEMPLATE call with param1 == current entry. Creature %d", eventId, me->GetEntry()); return; } me->UpdateEntry(action.update_template.creatureId, action.update_template.team ? HORDE : ALLIANCE); break; case ACTION_T_DIE: if (me->isDead()) { sLog->outErrorDb("CreatureEventAI: Event %d ACTION_T_DIE on dead creature. Creature %d", eventId, me->GetEntry()); return; } me->Kill(me); break; case ACTION_T_ZONE_COMBAT_PULSE: { me->SetInCombatWithZone(); break; } case ACTION_T_CALL_FOR_HELP: { me->CallForHelp((float)action.call_for_help.radius); break; } break; // TRINITY ONLY case ACTION_T_MOVE_RANDOM_POINT: //dosen't work in combat { float x, y, z; me->GetClosePoint(x, y, z, me->GetObjectSize() / 3, (float)action.raw.param1); me->GetMotionMaster()->MovePoint(0, x, y, z); break; } case ACTION_T_SET_STAND_STATE: me->SetStandState(UnitStandStateType(action.raw.param1)); break; case ACTION_T_SET_PHASE_MASK: me->SetPhaseMask(action.raw.param1, true); break; case ACTION_T_SET_VISIBILITY: me->SetVisible(bool(action.raw.param1)); break; case ACTION_T_SET_ACTIVE: me->setActive(action.raw.param1 ? true : false); break; case ACTION_T_SET_AGGRESSIVE: me->SetReactState(ReactStates(action.raw.param1)); break; case ACTION_T_ATTACK_START_PULSE: AttackStart(me->SelectNearestTarget((float)action.raw.param1)); break; case ACTION_T_SUMMON_GO: { GameObject* object = NULL; float x, y, z; me->GetPosition(x, y, z); object = me->SummonGameObject(action.raw.param1, x, y, z, 0, 0, 0, 0, 0, action.raw.param2); if (!object) { sLog->outErrorDb("TSCR: EventAI failed to spawn object %u. Spawn event %d is on creature %d", action.raw.param1, eventId, me->GetEntry()); } break; } case ACTION_T_SET_SHEATH: { me->SetSheath(SheathState(action.set_sheath.sheath)); break; } case ACTION_T_FORCE_DESPAWN: { me->DespawnOrUnsummon(action.forced_despawn.msDelay); break; } case ACTION_T_SET_INVINCIBILITY_HP_LEVEL: { if (action.invincibility_hp_level.is_percent) m_InvincibilityHpLevel = me->CountPctFromMaxHealth(action.invincibility_hp_level.hp_level); else m_InvincibilityHpLevel = action.invincibility_hp_level.hp_level; break; } case ACTION_T_MOUNT_TO_ENTRY_OR_MODEL: { if (action.mount.creatureId || action.mount.modelId) { // set model based on entry from creature_template if (action.mount.creatureId) { if (CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(action.mount.creatureId)) { uint32 display_id = sObjectMgr->ChooseDisplayId(0, cInfo); me->Mount(display_id); } } //if no param1, then use value from param2 (modelId) else me->Mount(action.mount.modelId); } else me->Dismount(); break; } } }
void UpdateAI(const uint32 diff) { if (!UpdateVictim()) return; //Check_Timer for the death of LorKhan and Zath. if(!WasDead && Check_Timer < diff) { if(pInstance) { if(pInstance->GetData(DATA_LORKHANISDEAD)) { //Resurrect LorKhan Unit *pLorKhan = Unit::GetUnit((*m_creature), pInstance->GetData64(DATA_LORKHAN)); if(pLorKhan) { pLorKhan->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); pLorKhan->setFaction(14); pLorKhan->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); pLorKhan->SetHealth(int(pLorKhan->GetMaxHealth()*1.0)); } } if(pInstance->GetData(DATA_ZATHISDEAD)) { //Resurrect Zath Unit *pZath = Unit::GetUnit((*m_creature), pInstance->GetData64(DATA_ZATH)); if(pZath) { pZath->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); pZath->setFaction(14); pZath->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); pZath->SetHealth(int(pZath->GetMaxHealth()*1.0)); } } } Check_Timer = 5000; }else Check_Timer -= diff; if (!PhaseTwo && MortalCleave_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_MORTALCLEAVE); MortalCleave_Timer = 15000 + rand()%5000; }else MortalCleave_Timer -= diff; if (!PhaseTwo && Silence_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_SILENCE); Silence_Timer = 20000 + rand()%5000; }else Silence_Timer -= diff; if (!PhaseTwo && !WasDead && m_creature->GetHealth() <= m_creature->GetMaxHealth() * 0.05) { m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 3); m_creature->AttackStop(); if(pInstance) pInstance->SetData(DATA_THEKALFAKE_DEATH, 0); WasDead=true; } //Thekal will transform to Tiger if he died and was not resurrected after 10 seconds. if(!PhaseTwo && WasDead) { if (Resurrect_Timer < diff) { DoCast(m_creature,SPELL_TIGER_FORM); m_creature->SetFloatValue(OBJECT_FIELD_SCALE_X, 2.00f); m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); m_creature->SetHealth(int(m_creature->GetMaxHealth()*1.0)); const CreatureInfo *cinfo = m_creature->GetCreatureInfo(); m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 40))); m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 40))); m_creature->UpdateDamagePhysical(BASE_ATTACK); DoResetThreat(); PhaseTwo = true; }else Resurrect_Timer -= diff; } if ((m_creature->GetHealth()*100 / m_creature->GetMaxHealth() == 100) && WasDead) { WasDead = false; } if (PhaseTwo) { if (Charge_Timer < diff) { if (Unit* target = SelectUnit(SELECT_TARGET_RANDOM,0)) { DoCast(target,SPELL_CHARGE); DoResetThreat(); AttackStart(target); } Charge_Timer = 15000 + rand()%7000; }else Charge_Timer -= diff; if (Frenzy_Timer < diff) { DoCast(m_creature,SPELL_FRENZY); Frenzy_Timer = 30000; }else Frenzy_Timer -= diff; if (ForcePunch_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_SILENCE); ForcePunch_Timer = 16000 + rand()%5000; }else ForcePunch_Timer -= diff; if (SummonTigers_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_SUMMONTIGERS); SummonTigers_Timer = 10000 + rand()%4000; }else SummonTigers_Timer -= diff; if ((m_creature->GetHealth()*100 / m_creature->GetMaxHealth() < 11) && !Enraged) { DoCast(m_creature, SPELL_ENRAGE); Enraged = true; } } DoMeleeAttackIfReady(); }
bool ChatHandler::HandleModifyFactionCommand(const char* args) { uint32 factionid; uint32 flag; uint32 npcflag; uint32 dyflag; char* pfactionid = strtok((char*)args, " "); Unit* chr = getSelectedCreature(); if(!chr) { SendSysMessage(LANG_SELECT_CREATURE); return true; } if(!pfactionid) { if(chr) { factionid = chr->getFaction(); flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS); npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS); dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS); PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag); } return true; } if (chr == NULL) { SendSysMessage(LANG_NO_CHAR_SELECTED); return true; } factionid = atoi(pfactionid); char* pflag = strtok(NULL, " "); if (!pflag) flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS); else flag = atoi(pflag); char* pnpcflag = strtok(NULL, " "); if(!pnpcflag) npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS); else npcflag = atoi(pnpcflag); char* pdyflag = strtok(NULL, " "); if(!pdyflag) dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS); else dyflag = atoi(pdyflag); if(!sFactionTemplateStore.LookupEntry(factionid)) { PSendSysMessage(LANG_WRONG_FACTION, factionid); return true; } PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag); //sprintf((char*)buf,"%s changed your Faction to %i.", m_session->GetPlayer()->GetName(), factionid); //FillSystemMessageData(&data, m_session, buf); //chr->GetSession()->SendPacket(&data); chr->setFaction(factionid); chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag); chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag); chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag); return true; }
bool NetherBeam(int beamerID) { if(beamerID < 0 || beamerID > 2) return false; Map *map = m_creature->GetMap(); if(!map->IsDungeon()) return false; Unit* uBeamer = Unit::GetUnit(*m_creature, BeamerGUID[beamerID]); if(!uBeamer) return false; Unit* uBeamerHelp = Unit::GetUnit(*m_creature, BeamerhelpGUID[beamerID]); if(!uBeamerHelp) return false; CandidatesGUID[beamerID] = m_creature->GetGUID(); Unit* uCandidate = Unit::GetUnit(*m_creature, CandidatesGUID[beamerID]); if(!uCandidate) return false; int spell_exhaustion = -1; Unit* uLastCandidate = NULL; int creature_portal = -1; int spell_plr = -1; int spell_creature = -1; int spell_beam = -1; // switch beam specific settings/variables uLastCandidate = Unit::GetUnit(*m_creature, LastCandidatesGUID[beamerID]); switch(beamerID) { case 0: // blue spell_exhaustion = SPELL_EXHAUSTION_DOM; //uLastCandidate = lastDOMcandidate; creature_portal = CREATURE_BLUEPORTAL; spell_plr = SPELL_DOMINANCE_PLR; spell_creature = SPELL_DOMINANCE_NS; spell_beam = SPELL_BEAM_DOM; break; case 1: // green spell_exhaustion = SPELL_EXHAUSTION_SER; //uLastCandidate = lastSERcandidate; creature_portal = CREATURE_GREENPORTAL; spell_plr = SPELL_SERENITY_PLR; spell_creature = SPELL_SERENITY_NS; spell_beam = SPELL_BEAM_SER; break; case 2: // red spell_exhaustion = SPELL_EXHAUSTION_PER; //uLastCandidate = lastPERcandidate; creature_portal = CREATURE_REDPORTAL; spell_plr = SPELL_PERSEVERENCE_PLR; spell_creature = SPELL_PERSEVERENCE_NS; spell_beam = SPELL_BEAM_PER; break; default: return false; // oO? something got wrong... } // step throught each player in the list and check, if he is in the beam Map::PlayerList const &PlayerList = map->GetPlayers(); for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) { if(i->getSource() && i->getSource()->isAlive()) { plr = Unit::GetUnit(*m_creature, i->getSource()->GetGUID()); BossDist = m_creature->GetDistance2d(uBeamer); BossAngle = m_creature->GetAngle(uBeamer); PlrDist = plr->GetDistance2d(uBeamer); PlrAngle = plr->GetAngle(uBeamer); if((BossAngle - degrad10) < PlrAngle // is in range? && PlrAngle < (BossAngle + degrad10) // is in range? && PlrDist < BossDist // is in range? && !plr->HasAura(spell_exhaustion,0) // hasn't yet the spell? && plr->isAlive()) { // is alive? uCandidate = plr; // ok, take him as candidate if(beamerID==2) // red beam PLRonRedBeam = true; } } } if(uCandidate == m_creature) { if(uCandidate != uLastCandidate) { if(uBeamer) { uBeamer->DealDamage(uBeamerHelp, uBeamerHelp->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); if(uBeamerHelp) { BeamerhelpGUID[beamerID] = 0; uBeamerHelp = NULL; uBeamerHelp = uBeamer->SummonCreature(creature_portal,RandomedCoords[beamerID][0],RandomedCoords[beamerID][1],RandomedCoords[beamerID][2],0,TEMPSUMMON_CORPSE_DESPAWN,0); BeamerhelpGUID[beamerID] = uBeamerHelp->GetGUID(); uBeamerHelp->SetUInt32Value(UNIT_FIELD_DISPLAYID, 11686); uBeamerHelp->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); uBeamerHelp->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); } } uLastCandidate = uCandidate; } uBeamerHelp = Unit::GetUnit(*m_creature, BeamerhelpGUID[beamerID]); if(uBeamer) uBeamer->CastSpell(m_creature,spell_creature,true); if(uBeamerHelp) uBeamerHelp->CastSpell(uCandidate,spell_beam,true); } else { if(uCandidate != uLastCandidate) { if(uBeamer) { uBeamer->DealDamage(uBeamerHelp, uBeamerHelp->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); if(uBeamerHelp) { BeamerhelpGUID[beamerID] = 0; uBeamerHelp = NULL; uBeamerHelp = uBeamer->SummonCreature(creature_portal,RandomedCoords[beamerID][0],RandomedCoords[beamerID][1],RandomedCoords[beamerID][2],0,TEMPSUMMON_CORPSE_DESPAWN,0); BeamerhelpGUID[beamerID] = uBeamerHelp->GetGUID(); uBeamerHelp->SetUInt32Value(UNIT_FIELD_DISPLAYID, 11686); uBeamerHelp->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); uBeamerHelp->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); } } uLastCandidate = uCandidate; ExhaustHandler(uCandidate,beamerID); } uBeamerHelp = Unit::GetUnit(*m_creature, BeamerhelpGUID[beamerID]); if(uBeamer) uBeamer->CastSpell(uCandidate,spell_plr,true); if(uBeamerHelp) uBeamerHelp->CastSpell(uCandidate,spell_beam,true); } LastCandidatesGUID[beamerID] = uLastCandidate->GetGUID(); CandidatesGUID[beamerID] = uCandidate->GetGUID(); return true; }