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

[svn] *** Source Mangos ***
*Load npc_options at server startup, use cached data at creature gossip menu init.
* Also new .reload table command added
*Implement npc_option localization support, also store in DB BoxText/BoxMoney/Coded?
* Use characters.guid instead low guid value from characters.data in charcter enum data prepering for client.
* Fixed crash at .pinfo command use from console.
* Fixed windows ad.exe build
*Creature related code and DB cleanups.
* Rename 2 creature_template fields to more clean names and related code update also.
* Use enum values instead raw values for type_flags, use halper functions instead code repeating.
* Move tamed pet creating code to new function.

** Small code changes to make things compliant with above changes.
** Another rev with big changes so test away.

Original author: KingPin?
Date: 2008-11-05 09:22:56-06:00

Files:
1 modified

Legend:

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

    r149 r168  
    623623    sLog.outString(); 
    624624    sLog.outString( ">> Loaded %u creature locale strings", mCreatureLocaleMap.size() ); 
     625} 
     626 
     627void ObjectMgr::LoadNpcOptionLocales() 
     628{ 
     629    mNpcOptionLocaleMap.clear();                              // need for reload case 
     630 
     631    QueryResult *result = WorldDatabase.Query("SELECT entry," 
     632        "option_text_loc1,box_text_loc1,option_text_loc2,box_text_loc2," 
     633        "option_text_loc3,box_text_loc3,option_text_loc4,box_text_loc4," 
     634        "option_text_loc5,box_text_loc5,option_text_loc6,box_text_loc6," 
     635        "option_text_loc7,box_text_loc7,option_text_loc8,box_text_loc8 " 
     636        "FROM locales_npc_option"); 
     637 
     638    if(!result) 
     639    { 
     640        barGoLink bar(1); 
     641 
     642        bar.step(); 
     643 
     644        sLog.outString(""); 
     645        sLog.outString(">> Loaded 0 npc_option locale strings. DB table `locales_npc_option` is empty."); 
     646        return; 
     647    } 
     648 
     649    barGoLink bar(result->GetRowCount()); 
     650 
     651    do 
     652    { 
     653        Field *fields = result->Fetch(); 
     654        bar.step(); 
     655 
     656        uint32 entry = fields[0].GetUInt32(); 
     657 
     658        NpcOptionLocale& data = mNpcOptionLocaleMap[entry]; 
     659 
     660        for(int i = 1; i < MAX_LOCALE; ++i) 
     661        { 
     662            std::string str = fields[1+2*(i-1)].GetCppString(); 
     663            if(!str.empty()) 
     664            { 
     665                int idx = GetOrNewIndexForLocale(LocaleConstant(i)); 
     666                if(idx >= 0) 
     667                { 
     668                    if(data.OptionText.size() <= idx) 
     669                        data.OptionText.resize(idx+1); 
     670 
     671                    data.OptionText[idx] = str; 
     672                } 
     673            } 
     674            str = fields[1+2*(i-1)+1].GetCppString(); 
     675            if(!str.empty()) 
     676            { 
     677                int idx = GetOrNewIndexForLocale(LocaleConstant(i)); 
     678                if(idx >= 0) 
     679                { 
     680                    if(data.BoxText.size() <= idx) 
     681                        data.BoxText.resize(idx+1); 
     682 
     683                    data.BoxText[idx] = str; 
     684                } 
     685            } 
     686        } 
     687    } while (result->NextRow()); 
     688 
     689    delete result; 
     690 
     691    sLog.outString(); 
     692    sLog.outString( ">> Loaded %u npc_option locale strings", mNpcOptionLocaleMap.size() ); 
    625693} 
    626694 
     
    70777145} 
    70787146 
     7147void ObjectMgr::LoadNpcOptions() 
     7148{ 
     7149    m_mCacheNpcOptionList.clear();                          // For reload case 
     7150 
     7151    QueryResult *result = WorldDatabase.Query( 
     7152        //      0  1         2       3    4      5         6     7           8 
     7153        "SELECT id,gossip_id,npcflag,icon,action,box_money,coded,option_text,box_text " 
     7154        "FROM npc_option"); 
     7155    if( !result ) 
     7156    { 
     7157        barGoLink bar( 1 ); 
     7158 
     7159        bar.step(); 
     7160 
     7161        sLog.outString(); 
     7162        sLog.outErrorDb(">> Loaded `npc_option`, table is empty!"); 
     7163        return; 
     7164    } 
     7165 
     7166    barGoLink bar( result->GetRowCount() ); 
     7167 
     7168    uint32 count = 0; 
     7169 
     7170    do 
     7171    { 
     7172        bar.step(); 
     7173 
     7174        Field* fields = result->Fetch(); 
     7175 
     7176        GossipOption go; 
     7177        go.Id               = fields[0].GetUInt32(); 
     7178        go.GossipId         = fields[1].GetUInt32(); 
     7179        go.NpcFlag          = fields[2].GetUInt32(); 
     7180        go.Icon             = fields[3].GetUInt32(); 
     7181        go.Action           = fields[4].GetUInt32(); 
     7182        go.BoxMoney         = fields[5].GetUInt32(); 
     7183        go.Coded            = fields[6].GetUInt8()!=0; 
     7184        go.OptionText       = fields[7].GetCppString(); 
     7185        go.BoxText          = fields[8].GetCppString(); 
     7186 
     7187        m_mCacheNpcOptionList.push_back(go); 
     7188 
     7189        ++count; 
     7190 
     7191    } while (result->NextRow()); 
     7192    delete result; 
     7193 
     7194    sLog.outString(); 
     7195    sLog.outString( ">> Loaded %d npc_option entries", count ); 
     7196} 
     7197 
    70797198void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 extendedcost, bool savetodb) 
    70807199{