Show
Ignore:
Timestamp:
11/19/08 13:22:12 (17 years ago)
Author:
yumileroy
Message:

[svn] * Added ACE for Linux and Windows (Thanks Derex for Linux part and partial Windows part)
* Updated to 6721 and 676
* Fixed TrinityScript? logo
* Version updated to 0.2.6721.676

Original author: Neo2003
Date: 2008-10-04 06:17:19-05:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/Creature.cpp

    r2 r6  
    4747#include "Policies/SingletonImp.h" 
    4848 
     49void TrainerSpellData::Clear() 
     50{ 
     51    for (TrainerSpellList::iterator itr = spellList.begin(); itr != spellList.end(); ++itr) 
     52        delete (*itr); 
     53    spellList.empty(); 
     54} 
     55 
     56TrainerSpell 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 
    4965Creature::Creature() : 
    5066Unit(), i_AI(NULL), 
    5167lootForPickPocketed(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), 
     68m_itemsLoaded(false), m_lootMoney(0), m_lootRecipient(0), 
    5369m_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), 
     70m_gossipOptionLoaded(false),m_emoteState(0), m_isPet(false), m_isTotem(false), 
    5571m_regenTimer(2000), m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0), 
    5672m_AlreadyCallAssistence(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), 
     
    7288    CleanupsBeforeDelete(); 
    7389 
    74     m_trainer_spells.clear(); 
    7590    m_vendor_items.clear(); 
    7691 
     
    91106    if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); 
    92107    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     do 
    110     { 
    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; 
    145108} 
    146109 
     
    551514        return false; 
    552515 
    553     if(m_trainer_spells.empty()) 
     516    TrainerSpellData const* trainer_spells = GetTrainerSpells(); 
     517 
     518 
     519    if(!trainer_spells || trainer_spells->spellList.empty()) 
    554520    { 
    555521        sLog.outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_TRAINER but have empty trainer spell list.", 
     
    719685                        break; 
    720686                    case GOSSIP_OPTION_TRAINER: 
    721                         // Lazy loading at first access 
    722                         LoadTrainerSpells(); 
    723  
    724687                        if(!isCanTrainingOf(pPlayer,false)) 
    725688                            cantalking=false; 
     
    757720            if(!gso->Option.empty() && cantalking ) 
    758721            {                                               //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); 
    760723                ingso=gso; 
    761724            } 
     
    764727 
    765728    ///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()) 
    767730    { 
    768731        if(HasFlag(UNIT_NPC_FLAGS,UNIT_NPC_FLAG_TRAINER)) 
    769732        { 
    770             LoadTrainerSpells();                            // Lazy loading at first access 
    771733            isCanTrainingOf(pPlayer,true);                  // output error message if need 
    772734        } 
     
    783745        return; 
    784746 
    785     GossipMenu* gossipmenu = player->PlayerTalkClass->GetGossipMenu(); 
     747    GossipMenu& gossipmenu = player->PlayerTalkClass->GetGossipMenu(); 
    786748 
    787749    // in case empty gossip menu open quest menu if any 
    788     if (gossipmenu->MenuItemCount() == 0 && GetNpcTextId() == 0) 
     750    if (gossipmenu.Empty() && GetNpcTextId() == 0) 
    789751    { 
    790752        player->SendPreparedQuest(GetGUID()); 
     
    799761void Creature::OnGossipSelect(Player* player, uint32 option) 
    800762{ 
    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; 
    803769    uint32 zoneid=GetZoneId(); 
    804770    uint64 guid=GetGUID(); 
     
    969935uint32 Creature::GetNpcTextId() 
    970936{ 
    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; 
    986941} 
    987942 
     
    14001355    m_vendor_items.clear(); 
    14011356 
    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) 
    14051359        return; 
    14061360 
    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); 
    14331363 
    14341364    m_itemsLoaded = true; 
     
    19921922    return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptName; 
    19931923} 
     1924 
     1925TrainerSpellData const* Creature::GetTrainerSpells() const 
     1926{ 
     1927    return objmgr.GetNpcTrainerSpells(GetEntry()); 
     1928}