void OnLoad() { if (_unit->IsSummon()) { Summon* s = TO< Summon* >(_unit); Unit* owner = s->GetOwner(); owner->CastSpell(_unit, 45204, true); // clone me owner->CastSpell(_unit, 58838, true); // inherit threat list // Mage mirror image spell if (_unit->GetCreatedBySpell() == 58833) { _unit->SetMaxHealth(2500); _unit->SetHealth(2500); _unit->SetMaxPower(POWER_TYPE_MANA, owner->GetMaxPower(POWER_TYPE_MANA)); _unit->SetPower(POWER_TYPE_MANA, owner->GetPower(POWER_TYPE_MANA)); SpellRange* range = NULL; AI_Spell sp1; sp1.entryId = 59638; sp1.spell = dbcSpell.LookupEntryForced(sp1.entryId); sp1.spellType = STYPE_DAMAGE; sp1.agent = AGENT_SPELL; sp1.spelltargetType = TTYPE_SINGLETARGET; sp1.cooldown = 0; sp1.cooldowntime = 0; sp1.Misc2 = 0; sp1.procCount = 0; sp1.procChance = 100; range = dbcSpellRange.LookupEntry(sp1.spell->rangeIndex); sp1.minrange = GetMinRange(range); sp1.maxrange = GetMaxRange(range); _unit->GetAIInterface()->addSpellToList(&sp1); AI_Spell sp2; sp2.entryId = 59637; sp2.spell = dbcSpell.LookupEntryForced(sp2.entryId); sp2.spellType = STYPE_DAMAGE; sp2.agent = AGENT_SPELL; sp2.spelltargetType = TTYPE_SINGLETARGET; sp2.cooldown = 0; sp2.cooldowntime = 0; sp2.Misc2 = 0; sp2.procCount = 0; sp2.procChance = 100; range = dbcSpellRange.LookupEntry(sp2.spell->rangeIndex); sp2.minrange = GetMinRange(range); sp2.maxrange = GetMaxRange(range); _unit->GetAIInterface()->addSpellToList(&sp2); } } }
SpellDesc* ArcScriptCreatureAI::AddSpell(uint32 pSpellId, TargetType pTargetType, float pChance, float pCastTime, int32 pCooldown, float pMinRange, float pMaxRange, bool pStrictRange, char* pText, TextType pTextType, uint32 pSoundId) { //Cannot add twice same spell id SpellDesc* NewSpell = FindSpellById(pSpellId); if( NewSpell ) return NewSpell; //Find spell info from spell id SpellEntry* Info = dbcSpell.LookupEntry(pSpellId); #ifdef USE_DBC_SPELL_INFO float CastTime = ( Info->CastingTimeIndex ) ? GetCastTime(dbcSpellCastTime.LookupEntry(Info->CastingTimeIndex)) : pCastTime; int32 Cooldown = Info->RecoveryTime; float MinRange = ( Info->rangeIndex ) ? GetMinRange(dbcSpellRange.LookupEntry(Info->rangeIndex)) : pMinRange; float MaxRange = ( Info->rangeIndex ) ? GetMaxRange(dbcSpellRange.LookupEntry(Info->rangeIndex)) : pMaxRange; sLog.outColor(TYELLOW, "ArcScriptCreatureAI::AddSpell(%u) : casttime=%.1f cooldown=%d minrange=%.1f maxrange=%.1f\n", pSpellId, CastTime, Cooldown, MinRange, MaxRange); #else float CastTime = pCastTime; int32 Cooldown = pCooldown; float MinRange = pMinRange; float MaxRange = pMaxRange; #endif //Create new spell NewSpell = new SpellDesc(Info, NULL, pTargetType, pChance, CastTime, Cooldown, MinRange, MaxRange, pStrictRange, pText, pTextType, pSoundId); mSpells.push_back(NewSpell); return NewSpell; }
void Pet::CreateAISpell(SpellEntry * info) { // Create an AI_Spell AI_Spell *sp = new AI_Spell; sp->agent = AGENT_SPELL; sp->entryId = GetEntry(); sp->floatMisc1 = 0; sp->maxrange = GetMaxRange(sSpellRange.LookupEntry(info->rangeIndex)); sp->minrange = GetMinRange(sSpellRange.LookupEntry(info->rangeIndex)); sp->Misc2 = 0; sp->procChance = 0; sp->procCount = 0; sp->procCounter = 0; sp->procEvent = 0; sp->spellCooldown = 0; sp->spellCooldownTimer = 0; sp->spellId = info->Id; sp->spellType = STYPE_DAMAGE; sp->spelltargetType = TTYPE_SINGLETARGET; if(info->Effect[0] == SPELL_EFFECT_APPLY_AURA) sp->agent = STYPE_BUFF; if(info->EffectImplicitTargetA[0] == 24) { float radius = ::GetRadius(sSpellRadius.LookupEntry(info->EffectRadiusIndex[0])); sp->maxrange = radius; sp->spelltargetType = TTYPE_SOURCE; } m_AISpellStore[info->Id] = sp; }
SpellEntry const *Creature::reachWithSpellAttack(Unit *pVictim) { if(!pVictim) return NULL; for(uint32 i=0; i < CREATURE_MAX_SPELLS; i++) { if(!m_spells[i]) continue; SpellEntry const *spellInfo = sSpellStore.LookupEntry(m_spells[i] ); if(!spellInfo) { sLog.outError("WORLD: unknown spell id %i\n", m_spells[i]); continue; } bool bcontinue = true; for(uint32 j=0;j<3;j++) { if( (spellInfo->Effect[j] == SPELL_EFFECT_SCHOOL_DAMAGE ) || (spellInfo->Effect[j] == SPELL_EFFECT_INSTAKILL) || (spellInfo->Effect[j] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE) || (spellInfo->Effect[j] == SPELL_EFFECT_HEALTH_LEECH ) ) { bcontinue = false; break; } } if(bcontinue) continue; if(spellInfo->manaCost > GetPower(POWER_MANA)) continue; SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(spellInfo->rangeIndex); float range = GetMaxRange(srange); float minrange = GetMinRange(srange); float dist = GetDistanceSq(pVictim); //if(!isInFront( pVictim, range ) && spellInfo->AttributesEx ) // continue; if( dist > range * range || dist < minrange * minrange ) continue; if(m_silenced) continue; return spellInfo; } return NULL; }
bool ChatHandler::HandleAddAIAgentCommand(const char* args, WorldSession *m_session) { char* agent = strtok((char*)args, " "); if(!agent) return false; char* procEvent = strtok(NULL, " "); if(!procEvent) return false; char* procChance = strtok(NULL, " "); if(!procChance) return false; char* procCount = strtok(NULL, " "); if(!procCount) return false; char* spellId = strtok(NULL, " "); if(!spellId) return false; char* spellType = strtok(NULL, " "); if(!spellType) return false; char* spelltargetType = strtok(NULL, " "); if(!spelltargetType) return false; char* spellCooldown = strtok(NULL, " "); if(!spellCooldown) return false; char* floatMisc1 = strtok(NULL, " "); if(!floatMisc1) return false; char* Misc2 = strtok(NULL, " "); if(!Misc2) return false; Creature* target = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(m_session->GetPlayer()->GetSelection())); if(!target) { RedSystemMessage(m_session, "You have to select a Creature!"); return false; } std::stringstream qry; qry << "INSERT INTO ai_agents SET entry = '" << target->GetUInt32Value(OBJECT_FIELD_ENTRY) << "', type = '" << atoi(agent) << "', event = '" << atoi(procEvent)<< "', chance = '" << atoi(procChance)<< "', maxcount = '" << atoi(procCount)<< "', spell = '" << atoi(spellId)<< "', spelltype = '" << atoi(spellType)<< "', targettype_overwrite = '" << atoi(spelltargetType)<< "', cooldown_overwrite = '" << atoi(spellCooldown)<< "', floatMisc1 = '" << atof(floatMisc1)<< "', Misc2 ='" << atoi(Misc2)<< "'"; WorldDatabase.Execute( qry.str().c_str( ) ); AI_Spell * sp = new AI_Spell; sp->agent = atoi(agent); sp->procChance = atoi(procChance); /* sp->procCount = atoi(procCount);*/ sp->spell = dbcSpell.LookupEntry(atoi(spellId)); sp->spellType = atoi(spellType); // sp->spelltargetType = atoi(spelltargetType); sp->floatMisc1 = (float)atof(floatMisc1); sp->Misc2 = (uint32)atof(Misc2); sp->cooldown = (uint32)atoi(spellCooldown); sp->procCount=0; sp->procCounter=0; sp->cooldowntime=0; sp->minrange = GetMinRange(dbcSpellRange.LookupEntry(dbcSpell.LookupEntry(atoi(spellId))->rangeIndex)); sp->maxrange = GetMaxRange(dbcSpellRange.LookupEntry(dbcSpell.LookupEntry(atoi(spellId))->rangeIndex)); target->GetProto()->spells.push_back(sp); if(sp->agent == AGENT_CALLFORHELP) target->GetAIInterface()->m_canCallForHelp = true; else if(sp->agent == AGENT_FLEE) target->GetAIInterface()->m_canFlee = true; else if(sp->agent == AGENT_RANGED) target->GetAIInterface()->m_canRangedAttack = true; else target->GetAIInterface()->addSpellToList(sp); return true; }
BlueDragonAI(Creature* pCreature) : MoonScriptCreatureAI( pCreature ) { AI_Spell* NewSpell = new AI_Spell; NewSpell->spell = dbcSpell.LookupEntry( 45848 ); NewSpell->agent = AGENT_SPELL; NewSpell->entryId = _unit->GetEntry(); NewSpell->maxrange = GetMaxRange( dbcSpellRange.LookupEntry( NewSpell->spell->rangeIndex ) ); NewSpell->minrange = GetMinRange( dbcSpellRange.LookupEntry( NewSpell->spell->rangeIndex ) ); NewSpell->spelltargetType = TTYPE_SINGLETARGET; NewSpell->spellType = STYPE_DAMAGE; NewSpell->cooldown = objmgr.GetPetSpellCooldown( NewSpell->spell->Id ); NewSpell->cooldowntime = 0; NewSpell->autocast_type = AUTOCAST_EVENT_NONE; NewSpell->floatMisc1 = 0; NewSpell->Misc2 = 0; NewSpell->procChance = 0; NewSpell->procCount=0; _unit->GetAIInterface()->addSpellToList( NewSpell ); NewSpell = new AI_Spell; NewSpell->spell = dbcSpell.LookupEntry( 45856 ); NewSpell->agent = AGENT_SPELL; NewSpell->entryId = _unit->GetEntry(); NewSpell->maxrange = GetMaxRange( dbcSpellRange.LookupEntry( NewSpell->spell->rangeIndex ) ); NewSpell->minrange = GetMinRange( dbcSpellRange.LookupEntry( NewSpell->spell->rangeIndex ) ); NewSpell->spelltargetType = TTYPE_CASTER; NewSpell->spellType = STYPE_BUFF; NewSpell->cooldown = objmgr.GetPetSpellCooldown( NewSpell->spell->Id ); NewSpell->cooldowntime = 0; NewSpell->autocast_type = AUTOCAST_EVENT_NONE; NewSpell->floatMisc1 = 0; NewSpell->Misc2 = 0; NewSpell->procChance = 0; NewSpell->procCount=0; _unit->GetAIInterface()->addSpellToList( NewSpell ); NewSpell = new AI_Spell; NewSpell->spell = dbcSpell.LookupEntry( 45860 ); NewSpell->agent = AGENT_SPELL; NewSpell->entryId = _unit->GetEntry(); NewSpell->maxrange = GetMaxRange( dbcSpellRange.LookupEntry( NewSpell->spell->rangeIndex ) ); NewSpell->minrange = GetMinRange( dbcSpellRange.LookupEntry( NewSpell->spell->rangeIndex ) ); NewSpell->spelltargetType = TTYPE_SINGLETARGET; NewSpell->spellType = STYPE_BUFF; NewSpell->cooldown = objmgr.GetPetSpellCooldown( NewSpell->spell->Id ); NewSpell->cooldowntime = 0; NewSpell->autocast_type = AUTOCAST_EVENT_NONE; NewSpell->floatMisc1 = 0; NewSpell->Misc2 = 0; NewSpell->procChance = 0; NewSpell->procCount=0; _unit->GetAIInterface()->addSpellToList( NewSpell ); NewSpell = new AI_Spell; NewSpell->spell = dbcSpell.LookupEntry( 45862 ); NewSpell->agent = AGENT_SPELL; NewSpell->entryId = _unit->GetEntry(); NewSpell->maxrange = GetMaxRange( dbcSpellRange.LookupEntry( NewSpell->spell->rangeIndex ) ); NewSpell->minrange = GetMinRange( dbcSpellRange.LookupEntry( NewSpell->spell->rangeIndex ) ); NewSpell->spelltargetType = TTYPE_SINGLETARGET; NewSpell->spellType = STYPE_BUFF; NewSpell->cooldown = objmgr.GetPetSpellCooldown( NewSpell->spell->Id ); NewSpell->cooldowntime = 0; NewSpell->autocast_type = AUTOCAST_EVENT_NONE; NewSpell->floatMisc1 = 0; NewSpell->Misc2 = 0; NewSpell->procChance = 0; NewSpell->procCount=0; _unit->GetAIInterface()->addSpellToList( NewSpell ); RegisterAIUpdateEvent( 500 ); };
void ObjectMgr::LoadExtraCreatureProtoStuff() { { StorageContainerIterator<CreatureProto> * itr = CreatureProtoStorage.MakeIterator(); CreatureProto * cn; while(!itr->AtEnd()) { cn = itr->Get(); if(itr->Get()->aura_string) { string auras = string(itr->Get()->aura_string); vector<string> aurs = StrSplit(auras, " "); for(vector<string>::iterator it = aurs.begin(); it != aurs.end(); ++it) { uint32 id = atol((*it).c_str()); if(id) itr->Get()->start_auras.insert( id ); } } if(!itr->Get()->MinHealth) itr->Get()->MinHealth = 1; if(!itr->Get()->MaxHealth) itr->Get()->MaxHealth = 1; if (itr->Get()->AttackType > SCHOOL_ARCANE) itr->Get()->AttackType = SCHOOL_NORMAL; cn->m_canFlee = cn->m_canRangedAttack = cn->m_canCallForHelp = false; cn->m_fleeHealth = 0.0f; // please.... m_fleeDuration is a uint32... //cn->m_fleeDuration = 0.0f; cn->m_fleeDuration = 0; if(!itr->Inc()) break; } itr->Destruct(); } { StorageContainerIterator<CreatureInfo> * itr = CreatureNameStorage.MakeIterator(); CreatureInfo * ci; while(!itr->AtEnd()) { ci = itr->Get(); ci->lowercase_name = string(ci->Name); for(uint32 j = 0; j < ci->lowercase_name.length(); ++j) ci->lowercase_name[j] = tolower(ci->lowercase_name[j]); // Darvaleo 2008/08/15 - Copied lowercase conversion logic from ItemPrototype task ci->gossip_script = sScriptMgr.GetDefaultGossipScript(); if(!itr->Inc()) break; } itr->Destruct(); } { StorageContainerIterator<Quest> * itr = QuestStorage.MakeIterator(); Quest * qst; while(!itr->AtEnd()) { qst = itr->Get(); qst->pQuestScript = NULL; if( !itr->Inc() ) break; } itr->Destruct(); } // Load AI Agents QueryResult * result = WorldDatabase.Query( "SELECT * FROM ai_agents" ); CreatureProto * cn; if( result != NULL ) { AI_Spell *sp; SpellEntry * spe; uint32 entry; if(Config.OptionsConfig.GetBoolDefault("Server", "LoadAIAgents", true)) { do { Field *fields = result->Fetch(); entry = fields[0].GetUInt32(); cn = CreatureProtoStorage.LookupEntry(entry); spe = dbcSpell.LookupEntryForced(fields[5].GetUInt32()); if( spe == NULL ) { Log.Warning("AIAgent", "For %u has nonexistant spell %u.", fields[0].GetUInt32(), fields[5].GetUInt32()); } if(!cn) continue; sp = new AI_Spell; sp->entryId = fields[0].GetUInt32(); sp->agent = fields[1].GetUInt16(); sp->procChance = fields[3].GetUInt32(); sp->procCount = fields[4].GetUInt32(); sp->spell = spe; sp->spellType = fields[6].GetUInt32(); sp->spelltargetType = fields[7].GetUInt32(); sp->cooldown = fields[8].GetUInt32(); sp->floatMisc1 = fields[9].GetFloat(); sp->autocast_type=(uint32)-1; sp->custom_pointer=false; sp->cooldowntime=getMSTime(); sp->procCounter=0; /* if (!sp->procCountDB) sp->procCount = uint32(-1); else sp->procCount = sp->procCountDB;*/ sp->Misc2 = fields[10].GetUInt32(); if(sp->agent == AGENT_SPELL) { if(!sp->spell) { //printf("SpellId %u in ai_agent for %u is invalid.\n", (unsigned int)fields[5].GetUInt32(), (unsigned int)sp->entryId); delete sp; continue; } if(sp->spell->Effect[0] == SPELL_EFFECT_LEARN_SPELL || sp->spell->Effect[1] == SPELL_EFFECT_LEARN_SPELL || sp->spell->Effect[2] == SPELL_EFFECT_LEARN_SPELL) { //printf("Teaching spell %u in ai_agent for %u\n", (unsigned int)fields[5].GetUInt32(), (unsigned int)sp->entryId); delete sp; continue; } sp->minrange = GetMinRange(dbcSpellRange.LookupEntry(sp->spell->rangeIndex)); sp->maxrange = GetMaxRange(dbcSpellRange.LookupEntry(sp->spell->rangeIndex)); //omg the poor darling has no clue about making ai_agents if(sp->cooldown==0xffffffff) { //now this will not be exact cooldown but maybe a bigger one to not make him spam spells to often int cooldown; SpellDuration *sd=dbcSpellDuration.LookupEntry(sp->spell->DurationIndex); int Dur=0; int Casttime=0;//most of the time 0 int RecoveryTime=sp->spell->RecoveryTime; if(sp->spell->DurationIndex) Dur =::GetDuration(sd); Casttime=GetCastTime(dbcSpellCastTime.LookupEntry(sp->spell->CastingTimeIndex)); cooldown=Dur+Casttime+RecoveryTime; if(cooldown<0) sp->cooldown=0;//huge value that should not loop while adding some timestamp to it else sp->cooldown=cooldown; } /* //now apply the morron filter if(sp->procChance==0) { //printf("SpellId %u in ai_agent for %u is invalid.\n", (unsigned int)fields[5].GetUInt32(), (unsigned int)sp->entryId); delete sp; continue; } if(sp->spellType==0) { //right now only these 2 are used if(IsBeneficSpell(sp->spell)) sp->spellType==STYPE_HEAL; else sp->spellType==STYPE_BUFF; } if(sp->spelltargetType==0) sp->spelltargetType = RecommandAISpellTargetType(sp->spell); */ } if(sp->agent == AGENT_RANGED) { cn->m_canRangedAttack = true; delete sp; } else if(sp->agent == AGENT_FLEE) { cn->m_canFlee = true; if(sp->floatMisc1) cn->m_canFlee = (sp->floatMisc1>0.0f ? true : false); else cn->m_fleeHealth = 0.2f; if(sp->Misc2) cn->m_fleeDuration = sp->Misc2; else cn->m_fleeDuration = 10000; delete sp; } else if(sp->agent == AGENT_CALLFORHELP) { cn->m_canCallForHelp = true; if(sp->floatMisc1) cn->m_callForHelpHealth = 0.2f; delete sp; } else { cn->spells.push_back(sp); } } while( result->NextRow() ); } delete result; } }
void ObjectMgr::LoadExtraCreatureProtoStuff() { { StorageContainerIterator<CreatureProto> * itr = CreatureProtoStorage.MakeIterator(); CreatureProto* cn; while(!itr->AtEnd()) { cn = itr->Get(); // Process spell fields for( uint32 i = 0; i < MAX_CREATURE_PROTO_SPELLS; i++ ){ if( cn->AISpells[ i ] == 0 ) continue; SpellEntry *sp = dbcSpell.LookupEntryForced( cn->AISpells[ i ] ); if( sp == NULL ) continue; if( ( sp->Attributes & ATTRIBUTES_PASSIVE ) == 0 ) cn->castable_spells.push_back( sp->Id ); else cn->start_auras.insert( sp->Id ); } // process creature spells from creaturespelldata.dbc if( cn->spelldataid != 0 ){ CreatureSpellDataEntry* spe = dbcCreatureSpellData.LookupEntry( cn->spelldataid ); for( uint32 i = 0; i < 3; i++ ){ if( spe->Spells[ i ] == 0 ) continue; SpellEntry *sp = dbcSpell.LookupEntryForced( spe->Spells[ i ] ); if( sp == NULL ) continue; if( ( sp->Attributes & ATTRIBUTES_PASSIVE ) == 0 ) cn->castable_spells.push_back( sp->Id ); else cn->start_auras.insert( sp->Id ); } } if(cn->aura_string) { string auras = string(cn->aura_string); vector<string> aurs = StrSplit(auras, " "); for(vector<string>::iterator it = aurs.begin(); it != aurs.end(); ++it) { uint32 id = atol((*it).c_str()); if(id) cn->start_auras.insert(id); } } if(!cn->MinHealth) cn->MinHealth = 1; if(!cn->MaxHealth) cn->MaxHealth = 1; if(cn->AttackType > SCHOOL_ARCANE) cn->AttackType = SCHOOL_NORMAL; cn->m_canFlee = cn->m_canRangedAttack = cn->m_canCallForHelp = false; cn->m_fleeHealth = 0.0f; // please.... m_fleeDuration is a uint32... //cn->m_fleeDuration = 0.0f; cn->m_fleeDuration = 0; if(!itr->Inc()) break; } itr->Destruct(); } { StorageContainerIterator<CreatureInfo> * itr = CreatureNameStorage.MakeIterator(); CreatureInfo* ci; while(!itr->AtEnd()) { ci = itr->Get(); ci->lowercase_name = string(ci->Name); for(uint32 j = 0; j < ci->lowercase_name.length(); ++j) ci->lowercase_name[j] = static_cast<char>(tolower(ci->lowercase_name[j])); // Darvaleo 2008/08/15 - Copied lowercase conversion logic from ItemPrototype task for(int i = 0; i < NUM_MONSTER_SAY_EVENTS; i++) ci->MonsterSay[i] = objmgr.HasMonsterSay(ci->Id, MONSTER_SAY_EVENTS(i)); if(!itr->Inc()) break; } itr->Destruct(); } // Load AI Agents if(Config.MainConfig.GetBoolDefault("Server", "LoadAIAgents", true)) { QueryResult* result = WorldDatabase.Query("SELECT * FROM ai_agents"); CreatureProto* cn; if(result != NULL) { AI_Spell* sp; SpellEntry* spe; uint32 entry; do { Field* fields = result->Fetch(); entry = fields[0].GetUInt32(); cn = CreatureProtoStorage.LookupEntry(entry); spe = dbcSpell.LookupEntryForced(fields[6].GetUInt32()); if(spe == NULL) { Log.Error("AIAgent", "For %u has nonexistent spell %u.", fields[0].GetUInt32(), fields[6].GetUInt32()); continue; } if(!cn) continue; sp = new AI_Spell; sp->entryId = fields[0].GetUInt32(); sp->instance_mode = fields[1].GetUInt32(); sp->agent = fields[2].GetUInt16(); sp->procChance = fields[4].GetUInt32(); sp->procCount = fields[5].GetUInt32(); sp->spell = spe; sp->spellType = static_cast<uint8>(fields[7].GetUInt32()); int32 targettype = fields[8].GetInt32(); if(targettype == -1) sp->spelltargetType = static_cast<uint8>(GetAiTargetType(spe)); else sp->spelltargetType = static_cast<uint8>(targettype); sp->cooldown = fields[9].GetInt32(); sp->floatMisc1 = fields[10].GetFloat(); sp->autocast_type = (uint32) - 1; sp->cooldowntime = getMSTime(); sp->procCounter = 0; sp->Misc2 = fields[11].GetUInt32(); if(sp->agent == AGENT_SPELL) { if(!sp->spell) { LOG_DEBUG("SpellId %u in ai_agent for %u is invalid.", (unsigned int)fields[6].GetUInt32(), (unsigned int)sp->entryId); delete sp; sp = NULL; continue; } if(sp->spell->Effect[0] == SPELL_EFFECT_LEARN_SPELL || sp->spell->Effect[1] == SPELL_EFFECT_LEARN_SPELL || sp->spell->Effect[2] == SPELL_EFFECT_LEARN_SPELL) { LOG_DEBUG("Teaching spell %u in ai_agent for %u", (unsigned int)fields[6].GetUInt32(), (unsigned int)sp->entryId); delete sp; sp = NULL; continue; } sp->minrange = GetMinRange(dbcSpellRange.LookupEntry(sp->spell->rangeIndex)); sp->maxrange = GetMaxRange(dbcSpellRange.LookupEntry(sp->spell->rangeIndex)); //omg the poor darling has no clue about making ai_agents if(sp->cooldown == (uint32) - 1) { //now this will not be exact cooldown but maybe a bigger one to not make him spam spells to often int cooldown; SpellDuration* sd = dbcSpellDuration.LookupEntry(sp->spell->DurationIndex); int Dur = 0; int Casttime = 0; //most of the time 0 int RecoveryTime = sp->spell->RecoveryTime; if(sp->spell->DurationIndex) Dur =::GetDuration(sd); Casttime = GetCastTime(dbcSpellCastTime.LookupEntry(sp->spell->CastingTimeIndex)); cooldown = Dur + Casttime + RecoveryTime; if(cooldown < 0) sp->cooldown = 2000; //huge value that should not loop while adding some timestamp to it else sp->cooldown = cooldown; } /* //now apply the moron filter if(sp->procChance== 0) { //printf("SpellId %u in ai_agent for %u is invalid.\n", (unsigned int)fields[5].GetUInt32(), (unsigned int)sp->entryId); delete sp; sp = NULL; continue; } if(sp->spellType== 0) { //right now only these 2 are used if(IsBeneficSpell(sp->spell)) sp->spellType==STYPE_HEAL; else sp->spellType==STYPE_BUFF; } if(sp->spelltargetType== 0) sp->spelltargetType = RecommandAISpellTargetType(sp->spell); */ } if(sp->agent == AGENT_RANGED) { cn->m_canRangedAttack = true; delete sp; sp = NULL; } else if(sp->agent == AGENT_FLEE) { cn->m_canFlee = true; if(sp->floatMisc1) cn->m_canFlee = (sp->floatMisc1 > 0.0f ? true : false); else cn->m_fleeHealth = 0.2f; if(sp->Misc2) cn->m_fleeDuration = sp->Misc2; else cn->m_fleeDuration = 10000; delete sp; sp = NULL; } else if(sp->agent == AGENT_CALLFORHELP) { cn->m_canCallForHelp = true; if(sp->floatMisc1) cn->m_callForHelpHealth = 0.2f; delete sp; sp = NULL; } else { cn->spells.push_back(sp); } } while(result->NextRow()); delete result; } } }
vtkDataSet * avtLineoutFilter::NoSampling(vtkDataSet *in_ds, int domain) { bool rgrid = in_ds->GetDataObjectType() == VTK_RECTILINEAR_GRID; vtkDataSet *rv = NULL; // // Use interval tree to find intersected cells // int ncells = in_ds->GetNumberOfCells(); avtIntervalTree itree(ncells, ndims, false); double bounds[6]; double tol = 1e38; for (int i = 0; i < ncells; i++) { in_ds->GetCellBounds(i, bounds); itree.AddElement(i, bounds); double min = GetMinRange(bounds, ndims); if (min < tol) tol = min; } tol = tol/2.; itree.Calculate(); intVector isectedCells; doubleVector isectedPts; intVector lineCells; doubleVector linePts; itree.GetElementsListFromLine(point1, point2, lineCells, linePts, &tol); if (lineCells.size() == 0) { debug5 << "avtIntervalTree returned NO intersected cells for domain " << domain << "." << endl; return NULL; } vtkUnsignedCharArray *ghosts = (vtkUnsignedCharArray *)in_ds->GetCellData()->GetArray("avtGhostZones"); vtkCellIntersections *cellIntersections = NULL; vtkGenericCell *cell; double isect[3], p1[3], t; bool endPointInCell = false; if (!rgrid) { cellIntersections = vtkCellIntersections::New(); cellIntersections->SetTestCoPlanar(true); cell = vtkGenericCell::New(); } for (int i = 0; i < lineCells.size(); i++) { // // Want to skip ghost zones!! // if (ghosts && ghosts->GetComponent(lineCells[i], 0)) { continue; } bool doMore = true; if (!rgrid) { // // do a bit more checking if not a rectlinearGrid, as the interval // tree only calculated intersections with a cell's bounding box. // in_ds->GetCell(lineCells[i], cell); double isect2[3]; // Check both directions of the line, because we don't want // to intersect only a node. if (cellIntersections->CellIntersectWithLine(cell, point1, point2, t, isect) && cellIntersections->CellIntersectWithLine(cell, point2, point1, t, isect2)) { if (vtkVisItUtility::PointsEqual(isect, isect2, &tol)) { // Discard single-point intersections that are equivalent // to an endpoint. doMore = false; if (vtkVisItUtility::CellContainsPoint(cell, point1)) { if (!vtkVisItUtility::PointsEqual(point1, isect, &tol)) { p1[0] = point1[0]; p1[1] = point1[1]; p1[2] = point1[2]; doMore = true; } } else if (vtkVisItUtility::CellContainsPoint(cell, point2)) { if (!vtkVisItUtility::PointsEqual(point2, isect, &tol)) { p1[0] = point2[0]; p1[1] = point2[1]; p1[2] = point2[2]; doMore = true; } } } // points equal else { p1[0] = isect[0]; p1[1] = isect[1]; p1[2] = isect[2]; doMore = true; } } // isects both directions else { doMore = false; } } // rgrid else { p1[0] = linePts[i*3]; p1[1] = linePts[i*3+1]; p1[2] = linePts[i*3+2]; } if (doMore) { bool dupFound = false; for (int j = 0; j < isectedCells.size() && !dupFound; j++) { double p2[3]; p2[0] = isectedPts[j*3]; p2[1] = isectedPts[j*3+1]; p2[2] = isectedPts[j*3+2]; if (vtkVisItUtility::PointsEqual(p1, p2, &tol)) { dupFound = true; if (lineCells[i] < isectedCells[j]) isectedCells[j] = lineCells[i]; } } if (!dupFound) { isectedCells.push_back(lineCells[i]); isectedPts.push_back(p1[0]); isectedPts.push_back(p1[1]); isectedPts.push_back(p1[2]); } } } vtkIdList *cells = vtkIdList::New(); vtkPoints *pts = vtkVisItUtility::NewPoints(in_ds); double cpt[3]; for (int i = 0; i < isectedCells.size(); i++) { cpt[0] = isectedPts[i*3]; cpt[1] = isectedPts[i*3+1]; cpt[2] = isectedPts[i*3+2]; pts->InsertNextPoint(cpt); cells->InsertNextId(isectedCells[i]); } if (!useOriginalCells) { rv = CreateRGrid(in_ds, point1, point2, pts, cells); } else { rv = CreateRGridFromOrigCells(in_ds, point1, point2, pts, cells); } if (rv->GetNumberOfCells() == 0 || rv->GetNumberOfPoints() == 0) { debug5 << "avtIntervalTree returned empty DS for domain " << domain << "." << endl; rv = NULL; } cells->Delete(); pts->Delete(); if (!rgrid) { cellIntersections->Delete(); cell->Delete(); } ManageMemory(rv); if (rv != NULL) rv->Delete(); return rv; }