All pastes #987096 Raw Edit

Untitled

public cpp v1 · immutable
·published 2008-04-16 06:26 UTC
rendered paste body
void ObjectMgr::LoadTrainers(){	QueryResult * result = WorldDatabase.Query("SELECT * FROM trainer_defs");	QueryResult * result2;	Field * fields2;	const char * temp;	size_t len;	LoadDisabledSpells();	if(!result)		return;	if(result->GetFieldCount() != 10)	{		Log.LargeErrorMessage(LARGERRORMESSAGE_WARNING, "Trainers table format is invalid. Please update your database.");		return;	}	do 	{		Field * fields = result->Fetch();		uint32 entry = fields[0].GetUInt32();		Trainer * tr = new Trainer;		tr->RequiredSkill = fields[1].GetUInt32();		tr->RequiredSkillLine = fields[2].GetUInt32();		tr->RequiredClass = fields[3].GetUInt32();		tr->TrainerType = fields[4].GetUInt32();		tr->Can_Train_Gossip_TextId = fields[6].GetUInt32();		tr->Cannot_Train_GossipTextId = fields[7].GetUInt32();		tr->UIMessage = (char*)NormalTalkMessage;		if(!tr->Can_Train_Gossip_TextId)			tr->Can_Train_Gossip_TextId=1;		if(!tr->Cannot_Train_GossipTextId)			tr->Cannot_Train_GossipTextId=1;		temp = fields[5].GetString();		len=strlen(temp);		if(len)		{			tr->UIMessage = new char[len+1];			strcpy(tr->UIMessage, temp);			tr->UIMessage[len] = 0;		}		//now load the spells		result2 = WorldDatabase.Query("SELECT * FROM trainer_spells where entry='%u'",entry);		if(!result2)		{			Log.Error("LoadTrainers", "Trainer with no spells, entry %u.", entry);			delete [] tr->UIMessage;			delete tr;			continue;		}		else		{			do			{				fields2 = result2->Fetch();				TrainerSpell ts;				bool abrt=false;				uint32 CastSpellID=fields2[1].GetUInt32();				uint32 LearnSpellID=fields2[2].GetUInt32();				ts.pCastSpell = NULL;				ts.pLearnSpell = NULL;				ts.pCastRealSpell = NULL;				if( CastSpellID != 0 )				{					ts.pCastSpell = dbcSpell.LookupEntryForced( CastSpellID );					if( ts.pCastSpell )					{						for(int k=0;k<3;k++)						{							if(ts.pCastSpell->Effect[k]==SPELL_EFFECT_LEARN_SPELL)							{								ts.pCastRealSpell = dbcSpell.LookupEntryForced(ts.pCastSpell->EffectTriggerSpell[k]);								if( ts.pCastRealSpell == NULL )								{									Log.Warning("Trainers", "Trainer %u contains cast spell %u that is non-teaching\n", entry, CastSpellID);									abrt=true;								}								break;							}						}					}					if(abrt)						continue;				}				if( LearnSpellID != 0 )				{					ts.pLearnSpell = dbcSpell.LookupEntryForced( LearnSpellID );				}				if( ts.pCastSpell == NULL && ts.pLearnSpell == NULL )				{					Log.Warning("LoadTrainers", "Trainer %u with no invalid spells (%u/%u).", entry, CastSpellID, LearnSpellID);					continue; //omg a bad spell !				}				if( ts.pCastSpell && !ts.pCastRealSpell)					continue;				ts.Cost = fields2[3].GetUInt32();				ts.RequiredSpell = fields2[4].GetUInt32();				ts.RequiredSkillLine = fields2[5].GetUInt32();				ts.RequiredSkillLineValue = fields2[6].GetUInt32();				ts.RequiredLevel = fields2[7].GetUInt32();				ts.DeleteSpell = fields2[8].GetUInt32();				ts.IsProfession = (fields2[9].GetUInt32() != 0) ? true : false;				tr->Spells.push_back(ts);			}			while(result2->NextRow());			delete result2;			tr->SpellCount = (uint32)tr->Spells.size();			//and now we insert it to our lookup table			if(!tr->SpellCount)			{				delete [] tr->UIMessage;				delete tr;				continue;			}			mTrainers.insert( TrainerMap::value_type( entry, tr ) );		}			} while(result->NextRow());	delete result;	Log.Notice("ObjectMgr", "%u trainers loaded.", mTrainers.size());}Trainer* ObjectMgr::GetTrainer(uint32 Entry){	TrainerMap::iterator iter = mTrainers.find(Entry);	if(iter == mTrainers.end())		return NULL;	return iter->second;}