Changeset 6 for trunk/src/game/Creature.cpp
- Timestamp:
- 11/19/08 13:22:12 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/Creature.cpp
r2 r6 47 47 #include "Policies/SingletonImp.h" 48 48 49 void TrainerSpellData::Clear() 50 { 51 for (TrainerSpellList::iterator itr = spellList.begin(); itr != spellList.end(); ++itr) 52 delete (*itr); 53 spellList.empty(); 54 } 55 56 TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const 57 { 58 for(TrainerSpellList::const_iterator itr = spellList.begin(); itr != spellList.end(); ++itr) 59 if((*itr)->spell == spell_id) 60 return *itr; 61 62 return NULL; 63 } 64 49 65 Creature::Creature() : 50 66 Unit(), i_AI(NULL), 51 67 lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0), 52 m_itemsLoaded(false), m_ trainerSpellsLoaded(false), m_trainer_type(0), m_lootMoney(0), m_lootRecipient(0),68 m_itemsLoaded(false), m_lootMoney(0), m_lootRecipient(0), 53 69 m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f), 54 m_gossipOptionLoaded(false),m_ NPCTextId(0), m_emoteState(0), m_isPet(false), m_isTotem(false),70 m_gossipOptionLoaded(false),m_emoteState(0), m_isPet(false), m_isTotem(false), 55 71 m_regenTimer(2000), m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0), 56 72 m_AlreadyCallAssistence(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), … … 72 88 CleanupsBeforeDelete(); 73 89 74 m_trainer_spells.clear();75 90 m_vendor_items.clear(); 76 91 … … 91 106 if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); 92 107 Unit::RemoveFromWorld(); 93 }94 95 void Creature::LoadTrainerSpells()96 {97 if(m_trainerSpellsLoaded)98 return;99 100 m_trainer_spells.clear();101 m_trainer_type = 0;102 103 Field *fields;104 QueryResult *result = WorldDatabase.PQuery("SELECT spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer WHERE entry = '%u'", GetEntry());105 106 if(!result)107 return;108 109 do110 {111 fields = result->Fetch();112 113 uint32 spellid = fields[0].GetUInt32();114 SpellEntry const *spellinfo = sSpellStore.LookupEntry(spellid);115 116 if(!spellinfo)117 {118 sLog.outErrorDb("Trainer (Entry: %u ) has non existing spell %u",GetEntry(),spellid);119 continue;120 }121 122 if(!SpellMgr::IsSpellValid(spellinfo))123 {124 sLog.outErrorDb("LoadTrainerSpells: Trainer (Entry: %u) has broken learning spell %u.", GetEntry(), spellid);125 continue;126 }127 128 if(SpellMgr::IsProfessionSpell(spellinfo->Id))129 m_trainer_type = 2;130 131 TrainerSpell tspell;132 tspell.spell = spellinfo;133 tspell.spellcost = fields[1].GetUInt32();134 tspell.reqskill = fields[2].GetUInt32();135 tspell.reqskillvalue= fields[3].GetUInt32();136 tspell.reqlevel = fields[4].GetUInt32();137 138 m_trainer_spells.push_back(tspell);139 140 } while( result->NextRow() );141 142 delete result;143 144 m_trainerSpellsLoaded = true;145 108 } 146 109 … … 551 514 return false; 552 515 553 if(m_trainer_spells.empty()) 516 TrainerSpellData const* trainer_spells = GetTrainerSpells(); 517 518 519 if(!trainer_spells || trainer_spells->spellList.empty()) 554 520 { 555 521 sLog.outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_TRAINER but have empty trainer spell list.", … … 719 685 break; 720 686 case GOSSIP_OPTION_TRAINER: 721 // Lazy loading at first access722 LoadTrainerSpells();723 724 687 if(!isCanTrainingOf(pPlayer,false)) 725 688 cantalking=false; … … 757 720 if(!gso->Option.empty() && cantalking ) 758 721 { //note for future dev: should have database fields for BoxMessage & BoxMoney 759 pm->GetGossipMenu() ->AddMenuItem((uint8)gso->Icon,gso->Option, gossipid,gso->Action,"",0,false);722 pm->GetGossipMenu().AddMenuItem((uint8)gso->Icon,gso->Option, gossipid,gso->Action,"",0,false); 760 723 ingso=gso; 761 724 } … … 764 727 765 728 ///some gossips aren't handled in normal way ... so we need to do it this way .. TODO: handle it in normal way ;-) 766 if(pm-> GetGossipMenu()->MenuItemCount()==0 && !pm->GetQuestMenu()->MenuItemCount())729 if(pm->Empty()) 767 730 { 768 731 if(HasFlag(UNIT_NPC_FLAGS,UNIT_NPC_FLAG_TRAINER)) 769 732 { 770 LoadTrainerSpells(); // Lazy loading at first access771 733 isCanTrainingOf(pPlayer,true); // output error message if need 772 734 } … … 783 745 return; 784 746 785 GossipMenu *gossipmenu = player->PlayerTalkClass->GetGossipMenu();747 GossipMenu& gossipmenu = player->PlayerTalkClass->GetGossipMenu(); 786 748 787 749 // in case empty gossip menu open quest menu if any 788 if (gossipmenu ->MenuItemCount() == 0&& GetNpcTextId() == 0)750 if (gossipmenu.Empty() && GetNpcTextId() == 0) 789 751 { 790 752 player->SendPreparedQuest(GetGUID()); … … 799 761 void Creature::OnGossipSelect(Player* player, uint32 option) 800 762 { 801 GossipMenu* gossipmenu = player->PlayerTalkClass->GetGossipMenu(); 802 uint32 action=gossipmenu->GetItem(option).m_gAction; 763 GossipMenu& gossipmenu = player->PlayerTalkClass->GetGossipMenu(); 764 765 if(option >= gossipmenu.MenuItemCount()) 766 return; 767 768 uint32 action=gossipmenu.GetItem(option).m_gAction; 803 769 uint32 zoneid=GetZoneId(); 804 770 uint64 guid=GetGUID(); … … 969 935 uint32 Creature::GetNpcTextId() 970 936 { 971 // already loaded and cached 972 if(m_NPCTextId) 973 return m_NPCTextId; 974 975 QueryResult* result = WorldDatabase.PQuery("SELECT textid FROM npc_gossip WHERE npc_guid= '%u'", m_DBTableGuid); 976 if(result) 977 { 978 Field *fields = result->Fetch(); 979 m_NPCTextId = fields[0].GetUInt32(); 980 delete result; 981 } 982 else 983 m_NPCTextId = DEFAULT_GOSSIP_MESSAGE; 984 985 return m_NPCTextId; 937 if(uint32 pos = objmgr.GetNpcGossip(m_DBTableGuid)) 938 return pos; 939 940 return DEFAULT_GOSSIP_MESSAGE; 986 941 } 987 942 … … 1400 1355 m_vendor_items.clear(); 1401 1356 1402 QueryResult *result = WorldDatabase.PQuery("SELECT item, maxcount, incrtime, ExtendedCost FROM npc_vendor WHERE entry = '%u'", GetEntry()); 1403 1404 if(!result) 1357 VendorItemList const* vList = objmgr.GetNpcVendorItemList(GetEntry()); 1358 if(!vList) 1405 1359 return; 1406 1360 1407 do 1408 { 1409 Field *fields = result->Fetch(); 1410 1411 if (GetItemCount() >= MAX_VENDOR_ITEMS) 1412 { 1413 sLog.outErrorDb( "Vendor %u has too many items (%u >= %i). Check the DB!", GetEntry(), GetItemCount(), MAX_VENDOR_ITEMS ); 1414 break; 1415 } 1416 1417 uint32 item_id = fields[0].GetUInt32(); 1418 if(!sItemStorage.LookupEntry<ItemPrototype>(item_id)) 1419 { 1420 sLog.outErrorDb("Vendor %u have in item list non-existed item %u",GetEntry(),item_id); 1421 continue; 1422 } 1423 1424 uint32 ExtendedCost = fields[3].GetUInt32(); 1425 if(ExtendedCost && !sItemExtendedCostStore.LookupEntry(ExtendedCost)) 1426 sLog.outErrorDb("Item (Entry: %u) has wrong ExtendedCost (%u) for vendor (%u)",item_id,ExtendedCost,GetEntry()); 1427 1428 AddItem( item_id, fields[1].GetUInt32(), fields[2].GetUInt32(), ExtendedCost); 1429 } 1430 while( result->NextRow() ); 1431 1432 delete result; 1361 for (VendorItemList::const_iterator _item_iter = vList->begin(); _item_iter != vList->end(); ++_item_iter) 1362 AddItem( (*_item_iter)->item, (*_item_iter)->maxcount, (*_item_iter)->incrtime, (*_item_iter)->ExtendedCost); 1433 1363 1434 1364 m_itemsLoaded = true; … … 1992 1922 return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptName; 1993 1923 } 1924 1925 TrainerSpellData const* Creature::GetTrainerSpells() const 1926 { 1927 return objmgr.GetNpcTrainerSpells(GetEntry()); 1928 }