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

[svn] * Little fix in RandomMovementGenerator?
* Updated to 6731 and 680

Original author: Neo2003
Date: 2008-10-06 04:48:59-05:00

Files:
1 modified

Legend:

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

    r6 r18  
    7171} 
    7272 
     73LanguageDesc lang_description[LANGUAGES_COUNT] = 
     74{ 
     75    { LANG_ADDON,           0, 0                       }, 
     76    { LANG_UNIVERSAL,       0, 0                       }, 
     77    { LANG_ORCISH,        669, SKILL_LANG_ORCISH       }, 
     78    { LANG_DARNASSIAN,    671, SKILL_LANG_DARNASSIAN   }, 
     79    { LANG_TAURAHE,       670, SKILL_LANG_TAURAHE      }, 
     80    { LANG_DWARVISH,      672, SKILL_LANG_DWARVEN      }, 
     81    { LANG_COMMON,        668, SKILL_LANG_COMMON       }, 
     82    { LANG_DEMONIC,       815, SKILL_LANG_DEMON_TONGUE }, 
     83    { LANG_TITAN,         816, SKILL_LANG_TITAN        }, 
     84    { LANG_THALASSIAN,    813, SKILL_LANG_THALASSIAN   }, 
     85    { LANG_DRACONIC,      814, SKILL_LANG_DRACONIC     }, 
     86    { LANG_KALIMAG,       817, SKILL_LANG_OLD_TONGUE   }, 
     87    { LANG_GNOMISH,      7340, SKILL_LANG_GNOMISH      }, 
     88    { LANG_TROLL,        7341, SKILL_LANG_TROLL        }, 
     89    { LANG_GUTTERSPEAK, 17737, SKILL_LANG_GUTTERSPEAK  }, 
     90    { LANG_DRAENEI,     29932, SKILL_LANG_DRAENEI      }, 
     91    { LANG_ZOMBIE,          0, 0                       }, 
     92    { LANG_GNOMISH_BINARY,  0, 0                       }, 
     93    { LANG_GOBLIN_BINARY,   0, 0                       } 
     94}; 
     95 
     96LanguageDesc const* GetLanguageDescByID(uint32 lang) 
     97{ 
     98    for(int i = 0; i < LANGUAGES_COUNT; ++i) 
     99    { 
     100        if(uint32(lang_description[i].lang_id) == lang) 
     101            return &lang_description[i]; 
     102    } 
     103 
     104    return NULL; 
     105} 
     106 
    73107ObjectMgr::ObjectMgr() 
    74108{ 
     
    135169 
    136170    for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr) 
    137         for (VendorItemList::iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2) 
    138             delete (*itr2); 
     171        itr->second.Clear(); 
    139172 
    140173    for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr) 
     
    26982731    mExclusiveQuestGroups.clear(); 
    26992732 
    2700     //                                                0      1           2             3         4           5     6              7 
    2701     QueryResult *result = WorldDatabase.Query("SELECT entry, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue," 
    2702     //   8                    9                  10                     11                   12                     13                   14                15 
     2733    //                                                0      1       2           3             4         5           6     7              8 
     2734    QueryResult *result = WorldDatabase.Query("SELECT entry, Method, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue," 
     2735    //   9                    10                 11                     12                   13                     14                   15                16 
    27032736        "RepObjectiveFaction, RepObjectiveValue, RequiredMinRepFaction, RequiredMinRepValue, RequiredMaxRepFaction, RequiredMaxRepValue, SuggestedPlayers, LimitTime," 
    2704     //   16          17            18           19           20           21              22                23         24            25 
     2737    //   17          18            19           20           21           22              23                24         25            26 
    27052738        "QuestFlags, SpecialFlags, CharTitleId, PrevQuestId, NextQuestId, ExclusiveGroup, NextQuestInChain, SrcItemId, SrcItemCount, SrcSpell," 
    2706     //   26     27       28          29               30                31       32              33              34              35 
     2739    //   27     28       29          30               31                32       33              34              35              36 
    27072740        "Title, Details, Objectives, OfferRewardText, RequestItemsText, EndText, ObjectiveText1, ObjectiveText2, ObjectiveText3, ObjectiveText4," 
    2708     //   36          37          38          39          40             41             42             43 
     2741    //   37          38          39          40          41             42             43             44 
    27092742        "ReqItemId1, ReqItemId2, ReqItemId3, ReqItemId4, ReqItemCount1, ReqItemCount2, ReqItemCount3, ReqItemCount4," 
    2710     //   44            45            46            47            48               49               50               51               52             53             54             55 
     2743    //   45            46            47            48            49               50               51               52               53             54             54             55 
    27112744        "ReqSourceId1, ReqSourceId2, ReqSourceId3, ReqSourceId4, ReqSourceCount1, ReqSourceCount2, ReqSourceCount3, ReqSourceCount4, ReqSourceRef1, ReqSourceRef2, ReqSourceRef3, ReqSourceRef4," 
    2712     //   56                  57                  58                  59                  60                     61                     62                     63 
     2745    //   57                  58                  59                  60                  61                     62                     63                     64 
    27132746        "ReqCreatureOrGOId1, ReqCreatureOrGOId2, ReqCreatureOrGOId3, ReqCreatureOrGOId4, ReqCreatureOrGOCount1, ReqCreatureOrGOCount2, ReqCreatureOrGOCount3, ReqCreatureOrGOCount4," 
    2714     //   64             65             66             67 
     2747    //   65             66             67             68 
    27152748        "ReqSpellCast1, ReqSpellCast2, ReqSpellCast3, ReqSpellCast4," 
    2716     //   68                69                70                71                72                73 
     2749    //   69                70                71                72                73                74 
    27172750        "RewChoiceItemId1, RewChoiceItemId2, RewChoiceItemId3, RewChoiceItemId4, RewChoiceItemId5, RewChoiceItemId6," 
    2718     //   74                   75                   76                   77                   78                   79 
     2751    //   75                   76                   77                   78                   79                   80 
    27192752        "RewChoiceItemCount1, RewChoiceItemCount2, RewChoiceItemCount3, RewChoiceItemCount4, RewChoiceItemCount5, RewChoiceItemCount6," 
    2720     //   80          81          82          83          84             85             86             87 
     2753    //   81          82          83          84          85             86             87             88 
    27212754        "RewItemId1, RewItemId2, RewItemId3, RewItemId4, RewItemCount1, RewItemCount2, RewItemCount3, RewItemCount4," 
    2722     //   88              89              90              91              92              93            94            95            96            97 
     2755    //   89              90              91              92              93              94            95            96            97            98 
    27232756        "RewRepFaction1, RewRepFaction2, RewRepFaction3, RewRepFaction4, RewRepFaction5, RewRepValue1, RewRepValue2, RewRepValue3, RewRepValue4, RewRepValue5," 
    2724     //   98             99                100       101           102                103               104         105     106     107 
     2757    //   99             100               101       102           103                104               105         106     107     108 
    27252758        "RewOrReqMoney, RewMoneyMaxLevel, RewSpell, RewSpellCast, RewMailTemplateId, RewMailDelaySecs, PointMapId, PointX, PointY, PointOpt," 
    2726     //   108            109            110            111           112              113            114                115                116                117 
     2759    //   109            110            111            112           113              114            115                116                117                118 
    27272760        "DetailsEmote1, DetailsEmote2, DetailsEmote3, DetailsEmote4,IncompleteEmote, CompleteEmote, OfferRewardEmote1, OfferRewardEmote2, OfferRewardEmote3, OfferRewardEmote4," 
    2728     //   118          119 
     2761    //   119          120 
    27292762        "StartScript, CompleteScript" 
    27302763        " FROM quest_template"); 
     
    27612794 
    27622795        // additional quest integrity checks (GO, creature_template and item_template must be loaded already) 
     2796 
     2797        if( qinfo->GetQuestMethod() >= 3 ) 
     2798        { 
     2799            sLog.outErrorDb("Quest %u has `Method` = %u, expected values are 0, 1 or 2.",qinfo->GetQuestId(),qinfo->GetQuestMethod()); 
     2800        } 
    27632801 
    27642802        if (qinfo->QuestFlags & ~QUEST_MANGOS_FLAGS_DB_ALLOWED) 
     
    61496187        if(entry==0) 
    61506188        { 
    6151             sLog.outString("Table `%s` contain reserved entry 0, ignored.",table); 
     6189            sLog.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table); 
    61526190            continue; 
    61536191        } 
     
    61566194            int32 start = min_value > 0 ? min_value : max_value; 
    61576195            int32 end   = min_value > 0 ? max_value : min_value; 
    6158             sLog.outString("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,start,end); 
     6196            sLog.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,start,end); 
    61596197            continue; 
    61606198        } 
     
    61646202        if(data.Content.size() > 0) 
    61656203        { 
    6166             sLog.outString("Table `%s` contain data for already loaded entry  %i (from another table?), ignored.",table,entry); 
     6204            sLog.outErrorDb("Table `%s` contain data for already loaded entry  %i (from another table?), ignored.",table,entry); 
    61676205            continue; 
    61686206        } 
     
    66576695    barGoLink bar( result->GetRowCount() ); 
    66586696 
    6659     uint32 count = 0,entry,spell; 
     6697    uint32 count = 0; 
    66606698    do 
    66616699    { 
     
    66646702        Field* fields = result->Fetch(); 
    66656703 
    6666         entry  = fields[0].GetUInt32(); 
    6667         spell  = fields[1].GetUInt32(); 
    6668  
    6669         if(!GetCreatureTemplate(entry)) 
     6704        uint32 entry  = fields[0].GetUInt32(); 
     6705        uint32 spell  = fields[1].GetUInt32(); 
     6706 
     6707        CreatureInfo const* cInfo = GetCreatureTemplate(entry); 
     6708 
     6709        if(!cInfo) 
    66706710        { 
    66716711            sLog.outErrorDb("Table `npc_trainer` have entry for not existed creature template (Entry: %u), ignore", entry); 
     6712            continue; 
     6713        } 
     6714 
     6715        if(!(cInfo->npcflag & UNIT_NPC_FLAG_TRAINER)) 
     6716        { 
     6717            sLog.outErrorDb("Table `npc_trainer` have data for not creature template (Entry: %u) without trainer flag, ignore", entry); 
    66726718            continue; 
    66736719        } 
     
    67166762    // For reload case  
    67176763    for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr) 
    6718     { 
    6719         for (VendorItemList::iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2) 
    6720             delete (*itr2); 
    6721     } 
     6764        itr->second.Clear(); 
    67226765    m_mCacheVendorItemMap.clear(); 
    67236766 
     
    67376780 
    67386781    uint32 count = 0; 
    6739     uint32 entry, item_id, ExtendedCost; 
    67406782    do 
    67416783    { 
     
    67436785        Field* fields = result->Fetch(); 
    67446786 
    6745         entry = fields[0].GetUInt32(); 
    6746         if(!GetCreatureTemplate(entry)) 
    6747         { 
    6748             sLog.outErrorDb("Table `npc_vendor` have data for not existed creature template (Entry: %u), ignore", entry); 
     6787        uint32 entry        = fields[0].GetUInt32(); 
     6788        uint32 item_id      = fields[1].GetUInt32(); 
     6789        uint32 maxcount     = fields[2].GetUInt32(); 
     6790        uint32 incrtime     = fields[3].GetUInt32(); 
     6791        uint32 ExtendedCost = fields[4].GetUInt32(); 
     6792 
     6793        if(!IsVendorItemValid(entry,item_id,maxcount,incrtime,ExtendedCost)) 
    67496794            continue; 
    6750         } 
    6751  
    6752         item_id  = fields[1].GetUInt32(); 
    6753         if(!GetItemPrototype(item_id)) 
    6754         { 
    6755             sLog.outErrorDb("Table `npc_vendor` for Vendor (Entry: %u) have in item list non-existed item (%u), ignore",entry,item_id); 
    6756             continue; 
    6757         } 
    6758  
    6759         ExtendedCost = fields[4].GetUInt32(); 
    6760         if(ExtendedCost && !sItemExtendedCostStore.LookupEntry(ExtendedCost)) 
    6761         { 
    6762             sLog.outErrorDb("Table `npc_vendor` have Item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignore",item_id,ExtendedCost,entry); 
    6763             continue; 
    6764         } 
    6765  
    6766         VendorItemList& vList = m_mCacheVendorItemMap[entry]; 
    6767  
    6768         if(vList.size() >= MAX_VENDOR_ITEMS) 
    6769         { 
    6770             sLog.outErrorDb( "Table `npc_vendor` has too many items (%u >= %i) for vendor (Entry: %u), ignore", vList.size(), MAX_VENDOR_ITEMS, entry); 
    6771             continue; 
    6772         } 
    6773  
    6774         VendorItem* pVendorItem = new VendorItem(); 
    6775         pVendorItem->item         = item_id; 
    6776         pVendorItem->maxcount     = fields[2].GetUInt32(); 
    6777         pVendorItem->incrtime     = fields[3].GetUInt32(); 
    6778         pVendorItem->ExtendedCost = ExtendedCost; 
    6779  
    6780         vList.push_back(pVendorItem); 
     6795 
     6796        VendorItemData& vList = m_mCacheVendorItemMap[entry]; 
     6797 
     6798        vList.AddItem(item_id,maxcount,incrtime,ExtendedCost); 
    67816799        ++count; 
    67826800 
     
    68396857} 
    68406858 
     6859void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 extendedcost ) 
     6860{ 
     6861    VendorItemData& vList = m_mCacheVendorItemMap[entry]; 
     6862    vList.AddItem(item,maxcount,incrtime,extendedcost); 
     6863 
     6864    WorldDatabase.PExecuteLog("INSERT INTO npc_vendor (entry,item,maxcount,incrtime,extendedcost) VALUES('%u','%u','%u','%u','%u')",entry, item, maxcount,incrtime,extendedcost); 
     6865} 
     6866 
     6867bool ObjectMgr::RemoveVendorItem( uint32 entry,uint32 item ) 
     6868{ 
     6869    CacheVendorItemMap::iterator  iter = m_mCacheVendorItemMap.find(entry); 
     6870    if(iter == m_mCacheVendorItemMap.end()) 
     6871        return false; 
     6872 
     6873    if(!iter->second.FindItem(item)) 
     6874        return false; 
     6875 
     6876    iter->second.RemoveItem(item); 
     6877    WorldDatabase.PExecuteLog("DELETE FROM npc_vendor WHERE entry='%u' AND item='%u'",entry, item); 
     6878    return true; 
     6879} 
     6880 
     6881bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost, Player* pl ) const 
     6882{ 
     6883    CreatureInfo const* cInfo = GetCreatureTemplate(vendor_entry); 
     6884    if(!cInfo) 
     6885    { 
     6886        if(pl) 
     6887            ChatHandler(pl).SendSysMessage(LANG_COMMAND_VENDORSELECTION); 
     6888        else 
     6889            sLog.outErrorDb("Table `npc_vendor` have data for not existed creature template (Entry: %u), ignore", vendor_entry); 
     6890        return false; 
     6891    } 
     6892 
     6893    if(!(cInfo->npcflag & UNIT_NPC_FLAG_VENDOR)) 
     6894    { 
     6895        if(pl) 
     6896            ChatHandler(pl).SendSysMessage(LANG_COMMAND_VENDORSELECTION); 
     6897        else 
     6898            sLog.outErrorDb("Table `npc_vendor` have data for not creature template (Entry: %u) without vendor flag, ignore", vendor_entry); 
     6899        return false; 
     6900    } 
     6901 
     6902    if(!GetItemPrototype(item_id)) 
     6903    { 
     6904        if(pl) 
     6905            ChatHandler(pl).PSendSysMessage(LANG_ITEM_NOT_FOUND, item_id); 
     6906        else 
     6907            sLog.outErrorDb("Table `npc_vendor` for Vendor (Entry: %u) have in item list non-existed item (%u), ignore",vendor_entry,item_id); 
     6908        return false; 
     6909    } 
     6910 
     6911    if(ExtendedCost && !sItemExtendedCostStore.LookupEntry(ExtendedCost)) 
     6912    { 
     6913        if(pl) 
     6914            ChatHandler(pl).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST,ExtendedCost); 
     6915        else 
     6916            sLog.outErrorDb("Table `npc_vendor` have Item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignore",item_id,ExtendedCost,vendor_entry); 
     6917        return false; 
     6918    } 
     6919 
     6920    if(maxcount > 0 && incrtime == 0) 
     6921    { 
     6922        if(pl) 
     6923            ChatHandler(pl).PSendSysMessage("MaxCount!=0 (%u) but IncrTime==0", maxcount); 
     6924        else 
     6925            sLog.outErrorDb( "Table `npc_vendor` has `maxcount` (%u) for item %u of vendor (Entry: %u) but `incrtime`=0, ignore", maxcount, item_id, vendor_entry); 
     6926        return false; 
     6927    } 
     6928    else if(maxcount==0 && incrtime > 0) 
     6929    { 
     6930        if(pl) 
     6931            ChatHandler(pl).PSendSysMessage("MaxCount==0 but IncrTime<>=0"); 
     6932        else 
     6933            sLog.outErrorDb( "Table `npc_vendor` has `maxcount`=0 for item %u of vendor (Entry: %u) but `incrtime`<>0, ignore", item_id, vendor_entry); 
     6934        return false; 
     6935    } 
     6936 
     6937    VendorItemData const* vItems = GetNpcVendorItemList(vendor_entry); 
     6938    if(!vItems) 
     6939        return true;                                        // later checks for non-empty lists 
     6940 
     6941    if(vItems->FindItem(item_id)) 
     6942    { 
     6943        if(pl) 
     6944            ChatHandler(pl).PSendSysMessage(LANG_ITEM_ALREADY_IN_LIST,item_id); 
     6945        else 
     6946            sLog.outErrorDb( "Table `npc_vendor` has duplicate items %u for vendor (Entry: %u), ignore", item_id, vendor_entry); 
     6947        return false; 
     6948    } 
     6949 
     6950    if(vItems->GetItemCount() >= MAX_VENDOR_ITEMS) 
     6951    { 
     6952        if(pl) 
     6953            ChatHandler(pl).SendSysMessage(LANG_COMMAND_ADDVENDORITEMITEMS); 
     6954        else 
     6955            sLog.outErrorDb( "Table `npc_vendor` has too many items (%u >= %i) for vendor (Entry: %u), ignore", vItems->GetItemCount(), MAX_VENDOR_ITEMS, vendor_entry); 
     6956        return false; 
     6957    } 
     6958 
     6959    return true; 
     6960} 
     6961 
    68416962// Functions for scripting access 
    68426963const char* GetAreaTriggerScriptNameById(uint32 id) 
     
    68496970    if(start_value >= 0 || start_value <= end_value)        // start/end reversed for negative values 
    68506971    { 
    6851         sLog.outError("Table '%s' attempt loaded with invalid range (%d - %d), use (%d - %d) instead.",table,start_value,end_value,-1,std::numeric_limits<int32>::min()); 
     6972        sLog.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), use (%d - %d) instead.",table,start_value,end_value,-1,std::numeric_limits<int32>::min()); 
    68526973        start_value = -1; 
    68536974        end_value = std::numeric_limits<int32>::min();