Changeset 18 for trunk/src/game/ObjectMgr.cpp
- Timestamp:
- 11/19/08 13:23:29 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/ObjectMgr.cpp
r6 r18 71 71 } 72 72 73 LanguageDesc 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 96 LanguageDesc 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 73 107 ObjectMgr::ObjectMgr() 74 108 { … … 135 169 136 170 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(); 139 172 140 173 for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr) … … 2698 2731 mExclusiveQuestGroups.clear(); 2699 2732 2700 // 0 1 2 3 4 5 6 72701 QueryResult *result = WorldDatabase.Query("SELECT entry, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue,"2702 // 8 9 10 11 12 13 14 152733 // 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 2703 2736 "RepObjectiveFaction, RepObjectiveValue, RequiredMinRepFaction, RequiredMinRepValue, RequiredMaxRepFaction, RequiredMaxRepValue, SuggestedPlayers, LimitTime," 2704 // 1 6 17 18 19 20 21 22 23 24 252737 // 17 18 19 20 21 22 23 24 25 26 2705 2738 "QuestFlags, SpecialFlags, CharTitleId, PrevQuestId, NextQuestId, ExclusiveGroup, NextQuestInChain, SrcItemId, SrcItemCount, SrcSpell," 2706 // 2 6 27 28 29 30 31 32 33 34 352739 // 27 28 29 30 31 32 33 34 35 36 2707 2740 "Title, Details, Objectives, OfferRewardText, RequestItemsText, EndText, ObjectiveText1, ObjectiveText2, ObjectiveText3, ObjectiveText4," 2708 // 3 6 37 38 39 40 41 42 432741 // 37 38 39 40 41 42 43 44 2709 2742 "ReqItemId1, ReqItemId2, ReqItemId3, ReqItemId4, ReqItemCount1, ReqItemCount2, ReqItemCount3, ReqItemCount4," 2710 // 4 4 45 46 47 48 49 50 51 52 5354 552743 // 45 46 47 48 49 50 51 52 53 54 54 55 2711 2744 "ReqSourceId1, ReqSourceId2, ReqSourceId3, ReqSourceId4, ReqSourceCount1, ReqSourceCount2, ReqSourceCount3, ReqSourceCount4, ReqSourceRef1, ReqSourceRef2, ReqSourceRef3, ReqSourceRef4," 2712 // 5 6 57 58 59 60 61 62 632745 // 57 58 59 60 61 62 63 64 2713 2746 "ReqCreatureOrGOId1, ReqCreatureOrGOId2, ReqCreatureOrGOId3, ReqCreatureOrGOId4, ReqCreatureOrGOCount1, ReqCreatureOrGOCount2, ReqCreatureOrGOCount3, ReqCreatureOrGOCount4," 2714 // 6 4 65 66 672747 // 65 66 67 68 2715 2748 "ReqSpellCast1, ReqSpellCast2, ReqSpellCast3, ReqSpellCast4," 2716 // 6 8 69 70 71 72 732749 // 69 70 71 72 73 74 2717 2750 "RewChoiceItemId1, RewChoiceItemId2, RewChoiceItemId3, RewChoiceItemId4, RewChoiceItemId5, RewChoiceItemId6," 2718 // 7 4 75 76 77 78 792751 // 75 76 77 78 79 80 2719 2752 "RewChoiceItemCount1, RewChoiceItemCount2, RewChoiceItemCount3, RewChoiceItemCount4, RewChoiceItemCount5, RewChoiceItemCount6," 2720 // 8 0 81 82 83 84 85 86 872753 // 81 82 83 84 85 86 87 88 2721 2754 "RewItemId1, RewItemId2, RewItemId3, RewItemId4, RewItemCount1, RewItemCount2, RewItemCount3, RewItemCount4," 2722 // 8 8 89 90 91 92 93 94 95 96 972755 // 89 90 91 92 93 94 95 96 97 98 2723 2756 "RewRepFaction1, RewRepFaction2, RewRepFaction3, RewRepFaction4, RewRepFaction5, RewRepValue1, RewRepValue2, RewRepValue3, RewRepValue4, RewRepValue5," 2724 // 9 8 99 100 101 102 103 104 105 106 1072757 // 99 100 101 102 103 104 105 106 107 108 2725 2758 "RewOrReqMoney, RewMoneyMaxLevel, RewSpell, RewSpellCast, RewMailTemplateId, RewMailDelaySecs, PointMapId, PointX, PointY, PointOpt," 2726 // 10 8 109 110 111 112 113 114 115 116 1172759 // 109 110 111 112 113 114 115 116 117 118 2727 2760 "DetailsEmote1, DetailsEmote2, DetailsEmote3, DetailsEmote4,IncompleteEmote, CompleteEmote, OfferRewardEmote1, OfferRewardEmote2, OfferRewardEmote3, OfferRewardEmote4," 2728 // 11 8 1192761 // 119 120 2729 2762 "StartScript, CompleteScript" 2730 2763 " FROM quest_template"); … … 2761 2794 2762 2795 // 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 } 2763 2801 2764 2802 if (qinfo->QuestFlags & ~QUEST_MANGOS_FLAGS_DB_ALLOWED) … … 6149 6187 if(entry==0) 6150 6188 { 6151 sLog.out String("Table `%s` contain reserved entry 0, ignored.",table);6189 sLog.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table); 6152 6190 continue; 6153 6191 } … … 6156 6194 int32 start = min_value > 0 ? min_value : max_value; 6157 6195 int32 end = min_value > 0 ? max_value : min_value; 6158 sLog.out String("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); 6159 6197 continue; 6160 6198 } … … 6164 6202 if(data.Content.size() > 0) 6165 6203 { 6166 sLog.out String("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); 6167 6205 continue; 6168 6206 } … … 6657 6695 barGoLink bar( result->GetRowCount() ); 6658 6696 6659 uint32 count = 0 ,entry,spell;6697 uint32 count = 0; 6660 6698 do 6661 6699 { … … 6664 6702 Field* fields = result->Fetch(); 6665 6703 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) 6670 6710 { 6671 6711 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); 6672 6718 continue; 6673 6719 } … … 6716 6762 // For reload case 6717 6763 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(); 6722 6765 m_mCacheVendorItemMap.clear(); 6723 6766 … … 6737 6780 6738 6781 uint32 count = 0; 6739 uint32 entry, item_id, ExtendedCost;6740 6782 do 6741 6783 { … … 6743 6785 Field* fields = result->Fetch(); 6744 6786 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)) 6749 6794 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); 6781 6799 ++count; 6782 6800 … … 6839 6857 } 6840 6858 6859 void 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 6867 bool 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 6881 bool 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 6841 6962 // Functions for scripting access 6842 6963 const char* GetAreaTriggerScriptNameById(uint32 id) … … 6849 6970 if(start_value >= 0 || start_value <= end_value) // start/end reversed for negative values 6850 6971 { 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()); 6852 6973 start_value = -1; 6853 6974 end_value = std::numeric_limits<int32>::min();