Index: trunk/src/trinityrealm/TrinityRealm.rc
===================================================================
--- trunk/src/trinityrealm/TrinityRealm.rc (revision 6)
+++ trunk/src/trinityrealm/TrinityRealm.rc (revision 18)
@@ -53,6 +53,6 @@
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,2,6721,676
- PRODUCTVERSION 0,2,6721,676
+ FILEVERSION 0,3,6731,680
+ PRODUCTVERSION 0,3,6731,680
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
@@ -70,10 +70,10 @@
         BEGIN
             VALUE "FileDescription", "TrinityRealm"
-            VALUE "FileVersion", "0, 2, 6721, 676"
+            VALUE "FileVersion", "0, 3, 6731, 680"
             VALUE "InternalName", "TrinityRealm"
             VALUE "LegalCopyright", "Copyright (C) 2008"
             VALUE "OriginalFilename", "TrinityRealm.exe"
             VALUE "ProductName", "TrinityRealm"
-            VALUE "ProductVersion", "0, 2, 6721, 676"
+            VALUE "ProductVersion", "0, 3, 6731, 680"
         END
     END
Index: trunk/src/game/Creature.h
===================================================================
--- trunk/src/game/Creature.h (revision 14)
+++ trunk/src/game/Creature.h (revision 18)
@@ -111,17 +111,4 @@
     uint32 Action;
     std::string Option;
-};
-
-struct CreatureItem
-{
-    CreatureItem(uint32 _item, uint32 _maxcount, uint32 _incrtime, uint32 _ExtendedCost)
-        : id(_item), count(_maxcount), maxcount(_maxcount), incrtime(_incrtime), ExtendedCost(_ExtendedCost), lastincr((uint32)time(NULL)) {}
-
-    uint32 id;
-    uint32 count;
-    uint32 maxcount;
-    uint32 incrtime;
-    uint32 lastincr;
-    uint32 ExtendedCost;
 };
 
@@ -292,4 +279,54 @@
 #endif
 
+// Vendors
+struct VendorItem
+{
+    VendorItem(uint32 _item, uint32 _maxcount, uint32 _incrtime, uint32 _ExtendedCost)
+        : item(_item), maxcount(_maxcount), incrtime(_incrtime), ExtendedCost(_ExtendedCost) {}
+
+    uint32 item;
+    uint32 maxcount;                                        // 0 for infinity item amount
+    uint32 incrtime;                                        // time for restore items amount if maxcount != 0
+    uint32 ExtendedCost;
+};
+typedef std::vector<VendorItem*> VendorItemList;
+
+struct VendorItemData
+{
+    VendorItemList m_items;
+
+    VendorItem* GetItem(uint32 slot) const
+    {
+        if(slot>=m_items.size()) return NULL;
+        return m_items[slot];
+    }
+    bool Empty() const { return m_items.empty(); }
+    uint8 GetItemCount() const { return m_items.size(); }
+    void AddItem( uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost)
+    {
+        m_items.push_back(new VendorItem(item, maxcount, ptime, ExtendedCost));
+    }
+    bool RemoveItem( uint32 item_id );
+    VendorItem const* FindItem(uint32 item_id) const;
+
+    void Clear()
+    {
+        for (VendorItemList::iterator itr = m_items.begin(); itr != m_items.end(); ++itr)
+            delete (*itr);
+    }
+};
+
+struct VendorItemCount
+{
+    explicit VendorItemCount(uint32 _item, uint32 _count)
+        : itemId(_item), count(_count), lastIncrementTime(time(NULL)) {}
+
+    uint32 itemId;
+    uint32 count;
+    time_t lastIncrementTime;
+};
+
+typedef std::list<VendorItemCount> VendorItemCounts;
+
 struct TrainerSpell
 {
@@ -419,39 +456,7 @@
         float GetSpellDamageMod(int32 Rank);
 
-        /*********************************************************/
-        /***                    VENDOR SYSTEM                  ***/
-        /*********************************************************/
-        void LoadGoods();                                   // must be called before access to vendor items, lazy loading at first call
-        void ReloadGoods() { m_itemsLoaded = false; LoadGoods(); }
-
-        CreatureItem* GetItem(uint32 slot)
-        {
-            if(slot>=m_vendor_items.size()) return NULL;
-            return &m_vendor_items[slot];
-        }
-        uint8 GetItemCount() const { return m_vendor_items.size(); }
-        void AddItem( uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost)
-        {
-            m_vendor_items.push_back(CreatureItem(item, maxcount, ptime, ExtendedCost));
-        }
-        bool RemoveItem( uint32 item_id )
-        {
-            for(CreatureItems::iterator i = m_vendor_items.begin(); i != m_vendor_items.end(); ++i )
-            {
-                if(i->id==item_id)
-                {
-                    m_vendor_items.erase(i);
-                    return true;
-                }
-            }
-            return false;
-        }
-        CreatureItem* FindItem(uint32 item_id)
-        {
-            for(CreatureItems::iterator i = m_vendor_items.begin(); i != m_vendor_items.end(); ++i )
-                if(i->id==item_id)
-                    return &*i;
-            return NULL;
-        }
+        VendorItemData const* GetVendorItems() const;
+        uint32 GetVendorItemCurrentCount(VendorItem const* vItem);
+        uint32 UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 used_count);
 
         TrainerSpellData const* GetTrainerSpells() const;
@@ -563,7 +568,5 @@
 
         // vendor items
-        typedef std::vector<CreatureItem> CreatureItems;
-        CreatureItems m_vendor_items;
-        bool m_itemsLoaded;                                 // vendor items loading state
+        VendorItemCounts m_vendorItemCounts;
 
         void _RealtimeSetCreatureInfo();
@@ -593,5 +596,5 @@
         MovementGeneratorType m_defaultMovementType;
         Cell m_currentCell;                                 // store current cell where creature listed
-        uint32 m_DBTableGuid;
+        uint32 m_DBTableGuid;                               ///< For new or temporary creatures is 0 for saved it is lowguid
         uint32 m_equipmentId;
 
Index: trunk/src/game/SpellEffects.cpp
===================================================================
--- trunk/src/game/SpellEffects.cpp (revision 9)
+++ trunk/src/game/SpellEffects.cpp (revision 18)
@@ -53,4 +53,6 @@
 #include "SocialMgr.h"
 #include "Util.h"
+#include "TemporarySummon.h"
+
 
 pEffect SpellEffects[TOTAL_SPELL_EFFECTS]=
@@ -1007,8 +1009,76 @@
                     return;
                 }
+                case 37573:                                 //Temporal Phase Modulator
+                {
+                    if(!unitTarget)
+                        return;
+
+                    TemporarySummon* tempSummon = dynamic_cast<TemporarySummon*>(unitTarget);
+                    if(!tempSummon)
+                        return;
+
+                    uint32 health = tempSummon->GetHealth();
+                    const uint32 entry_list[6] = {21821, 21820, 21817};
+
+                    float x = tempSummon->GetPositionX();
+                    float y = tempSummon->GetPositionY();
+                    float z = tempSummon->GetPositionZ();
+                    float o = tempSummon->GetOrientation();
+
+                    tempSummon->UnSummon();
+
+                    Creature* pCreature = m_caster->SummonCreature(entry_list[urand(0, 2)], x, y, z, o,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,180000);
+                    if (!pCreature)
+                        return;
+
+                    pCreature->SetHealth(health);
+
+                    if(pCreature->AI())
+                        pCreature->AI()->AttackStart(m_caster);
+
+                    return;
+                }
+                case 34665:                                 //Administer Antidote
+                {
+                    if(!unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER )
+                        return;
+
+                    if(!unitTarget)
+                        return;
+
+                    TemporarySummon* tempSummon = dynamic_cast<TemporarySummon*>(unitTarget);
+                    if(!tempSummon)
+                        return;
+
+                    uint32 health = tempSummon->GetHealth();
+
+                    float x = tempSummon->GetPositionX();
+                    float y = tempSummon->GetPositionY();
+                    float z = tempSummon->GetPositionZ();
+                    float o = tempSummon->GetOrientation();
+                    tempSummon->UnSummon();
+
+                    Creature* pCreature = m_caster->SummonCreature(16992, x, y, z, o,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,180000);
+                    if (!pCreature)
+                        return;
+
+                    pCreature->SetHealth(health);
+                    ((Player*)m_caster)->KilledMonster(16992,pCreature->GetGUID());
+
+                    if (pCreature->AI())
+                        pCreature->AI()->AttackStart(m_caster);
+
+                    return;
+                }
+                case 44997:                                 // Converting Sentry
+                {
+                    //Converted Sentry Credit
+                    m_caster->CastSpell(m_caster, 45009, true);
+                    return;
+                }                
                 case 45030:                                 // Impale Emissary
                 {
                     // Emissary of Hate Credit
-                    m_caster->CastSpell(m_caster,45088,true);
+                    m_caster->CastSpell(m_caster, 45088, true);
                     return;
                 }
@@ -1100,4 +1170,14 @@
                             ((Player*)m_caster)->GetSession()->SendPacket(&data);
                         }
+                    }
+                    return;
+                }
+                case 32826:
+                {
+                    if ( unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT )
+                    {
+                        //Polymorph Cast Visual Rank 1
+                        const uint32 spell_list[6] = {32813, 32816, 32817, 32818, 32819, 32820};
+                        unitTarget->CastSpell( unitTarget, spell_list[urand(0, 5)], true); 
                     }
                     return;
@@ -2761,25 +2841,24 @@
             goInfo->type == GAMEOBJECT_TYPE_GOOBER && goInfo->goober.losOK )
         {
-            if(BattleGround *bg = player->GetBattleGround())// in battleground
-            {
-                if( !player->IsMounted() &&                 // not mounted
-                    !player->HasStealthAura() &&            // not stealthed
-                    !player->HasInvisibilityAura() &&       // not invisible
-                    player->isAlive() )                     // live player
-                {
-                    // check if it's correct bg
-                    if(bg && bg->GetTypeID() == BATTLEGROUND_AB)
-                        bg->EventPlayerClickedOnFlag(player, gameObjTarget);
-
-                    return;
-                }
+            //isAllowUseBattleGroundObject() already called in CanCast()
+            // in battleground check
+            if(BattleGround *bg = player->GetBattleGround())
+            {
+                // check if it's correct bg
+                if(bg && bg->GetTypeID() == BATTLEGROUND_AB)
+                    bg->EventPlayerClickedOnFlag(player, gameObjTarget);
+                return;
             }
         }
         else if (goInfo->type == GAMEOBJECT_TYPE_FLAGSTAND)
         {
+            //isAllowUseBattleGroundObject() already called in CanCast()
+            // in battleground check
             if(BattleGround *bg = player->GetBattleGround())
+            {
                 if(bg->GetTypeID() == BATTLEGROUND_EY)
                     bg->EventPlayerClickedOnFlag(player, gameObjTarget);
-            return;
+                return;
+            }
         }
         lockId = gameObjTarget->GetLockId();
@@ -4752,4 +4831,14 @@
             break;
         }
+        //5,000 Gold
+        case 46642:
+        {
+            if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
+                return;
+
+            ((Player*)unitTarget)->ModifyMoney(50000000);
+
+            break;
+        }
     }
 
Index: trunk/src/game/Chat.h
===================================================================
--- trunk/src/game/Chat.h (revision 9)
+++ trunk/src/game/Chat.h (revision 18)
@@ -28,17 +28,4 @@
 class Unit;
 struct GameTele;
-
-struct LanguageDesc
-{
-    Language lang_id;
-    uint32   spell_id;
-    uint32   skill_id;
-};
-
-extern LanguageDesc lang_description[LANGUAGES_COUNT];
-
-LanguageDesc const* GetLanguageDescByID(uint32 lang);
-LanguageDesc const* GetLanguageDescBySpell(uint32 spell_id);
-LanguageDesc const* GetLanguageDescBySkill(uint32 skill_id);
 
 class ChatCommand
Index: trunk/src/game/QuestDef.h
===================================================================
--- trunk/src/game/QuestDef.h (revision 2)
+++ trunk/src/game/QuestDef.h (revision 18)
@@ -115,5 +115,5 @@
     // Flags used at server and sended to client
     QUEST_FLAGS_STAY_ALIVE     = 1,                         // Not used currently
-    QUEST_FLAGS_EVENT          = 2,                         // Not used currently
+    QUEST_FLAGS_PARTY_ACCEPT   = 2,                         // Not used currently. If player in party, all players that can accept this quest will receive confirmation box to accept quest CMSG_QUEST_CONFIRM_ACCEPT/SMSG_QUEST_CONFIRM_ACCEPT
     QUEST_FLAGS_EXPLORATION    = 4,                         // Not used currently
     QUEST_FLAGS_SHARABLE       = 8,                         // Can be shared: Player::CanShareQuest()
@@ -168,4 +168,5 @@
         // table data accessors:
         uint32 GetQuestId() const { return QuestId; }
+        uint32 GetQuestMethod() const { return QuestMethod; }
         int32  GetZoneOrSort() const { return ZoneOrSort; }
         int32  GetSkillOrClass() const { return SkillOrClass; }
@@ -213,5 +214,5 @@
         uint32 GetQuestCompleteScript() const { return QuestCompleteScript; }
         bool   IsRepeatable() const { return QuestFlags & QUEST_MANGOS_FLAGS_REPEATABLE; }
-        bool   IsAutoComplete() const { return Objectives.empty(); }
+        bool   IsAutoComplete() const { return QuestMethod ? false : true; }
         uint32 GetFlags() const { return QuestFlags; }
         bool   IsDaily() const { return QuestFlags & QUEST_FLAGS_DAILY; }
@@ -256,4 +257,5 @@
     protected:
         uint32 QuestId;
+        uint32 QuestMethod;
         int32  ZoneOrSort;
         int32  SkillOrClass;
Index: trunk/src/game/ItemHandler.cpp
===================================================================
--- trunk/src/game/ItemHandler.cpp (revision 2)
+++ trunk/src/game/ItemHandler.cpp (revision 18)
@@ -681,11 +681,14 @@
     // Stop the npc if moving
     pCreature->StopMoving();
-    // load vendor items if not yet
-    pCreature->LoadGoods();
-
-    uint8 numitems = pCreature->GetItemCount();
+
+    VendorItemData const* vItems = pCreature->GetVendorItems();
+    if(!vItems)
+    {
+        _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0);
+        return;
+    }
+
+    uint8 numitems = vItems->GetItemCount();
     uint8 count = 0;
-    uint32 ptime = time(NULL);
-    uint32 diff;
 
     WorldPacket data( SMSG_LIST_INVENTORY, (8+1+numitems*8*4) );
@@ -695,35 +698,22 @@
     float discountMod = _player->GetReputationPriceDiscount(pCreature);
 
-    ItemPrototype const *pProto;
     for(int i = 0; i < numitems; i++ )
     {
-        CreatureItem* crItem = pCreature->GetItem(i);
-        if( crItem )
-        {
-            pProto = objmgr.GetItemPrototype(crItem->id);
-            if( pProto )
+        if(VendorItem const* crItem = vItems->GetItem(i))
+        {
+            if(ItemPrototype const *pProto = objmgr.GetItemPrototype(crItem->item))
             {
                 if((pProto->AllowableClass & _player->getClassMask()) == 0 && pProto->Bonding == BIND_WHEN_PICKED_UP && !_player->isGameMaster())
                     continue;
+
                 ++count;
-                if( crItem->incrtime != 0 && (crItem->lastincr + crItem->incrtime <= ptime) )
-                {
-                    diff = uint32((ptime - crItem->lastincr)/crItem->incrtime);
-                    if( (crItem->count + diff * pProto->BuyCount) <= crItem->maxcount )
-                        crItem->count += diff * pProto->BuyCount;
-                    else
-                        crItem->count = crItem->maxcount;
-                    crItem->lastincr = ptime;
-                }
+
+                // reputation discount
+                uint32 price = uint32(floor(pProto->BuyPrice * discountMod));
+
                 data << uint32(count);
-                data << uint32(crItem->id);
+                data << uint32(crItem->item);
                 data << uint32(pProto->DisplayInfoID);
-                data << uint32(crItem->maxcount <= 0 ? 0xFFFFFFFF : crItem->count);
-
-                uint32 price = pProto->BuyPrice;
-
-                // reputation discount
-                price = uint32(floor(pProto->BuyPrice * discountMod));
-
+                data << uint32(crItem->maxcount <= 0 ? 0xFFFFFFFF : pCreature->GetVendorItemCurrentCount(crItem));
                 data << uint32(price);
                 data << uint32(pProto->MaxDurability);
Index: trunk/src/game/WaypointMovementGenerator.cpp
===================================================================
--- trunk/src/game/WaypointMovementGenerator.cpp (revision 6)
+++ trunk/src/game/WaypointMovementGenerator.cpp (revision 18)
@@ -113,5 +113,5 @@
             creature.addUnitState(UNIT_STAT_ROAMING);
             if (creature.canFly())
-                creature.SetUnitMovementFlags(MOVEMENTFLAG_FLYING2);
+                creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
             const WaypointNode &node = i_path->at(i_currentNode);
             i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z);
@@ -177,5 +177,5 @@
             creature.addUnitState(UNIT_STAT_ROAMING);
             if (creature.canFly())
-                creature.SetUnitMovementFlags(MOVEMENTFLAG_FLYING2);
+                creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
             const WaypointNode &node = i_path->at(i_currentNode);
             i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z);
Index: trunk/src/game/GameObject.h
===================================================================
--- trunk/src/game/GameObject.h (revision 2)
+++ trunk/src/game/GameObject.h (revision 18)
@@ -583,5 +583,5 @@
         uint32 m_usetimes;
 
-        uint32 m_DBTableGuid;
+        uint32 m_DBTableGuid;                               ///< For new or temporary gameobjects is 0 for saved it is lowguid
         GameObjectInfo const* m_goInfo;
     private:
Index: trunk/src/game/Chat.cpp
===================================================================
--- trunk/src/game/Chat.cpp (revision 9)
+++ trunk/src/game/Chat.cpp (revision 18)
@@ -34,60 +34,4 @@
 
 bool ChatHandler::load_command_table = true;
-
-LanguageDesc lang_description[LANGUAGES_COUNT] =
-{
-    { LANG_ADDON,           0, 0                       },
-    { LANG_UNIVERSAL,       0, 0                       },
-    { LANG_ORCISH,        669, SKILL_LANG_ORCISH       },
-    { LANG_DARNASSIAN,    671, SKILL_LANG_DARNASSIAN   },
-    { LANG_TAURAHE,       670, SKILL_LANG_TAURAHE      },
-    { LANG_DWARVISH,      672, SKILL_LANG_DWARVEN      },
-    { LANG_COMMON,        668, SKILL_LANG_COMMON       },
-    { LANG_DEMONIC,       815, SKILL_LANG_DEMON_TONGUE },
-    { LANG_TITAN,         816, SKILL_LANG_TITAN        },
-    { LANG_THALASSIAN,    813, SKILL_LANG_THALASSIAN   },
-    { LANG_DRACONIC,      814, SKILL_LANG_DRACONIC     },
-    { LANG_KALIMAG,       817, SKILL_LANG_OLD_TONGUE   },
-    { LANG_GNOMISH,      7340, SKILL_LANG_GNOMISH      },
-    { LANG_TROLL,        7341, SKILL_LANG_TROLL        },
-    { LANG_GUTTERSPEAK, 17737, SKILL_LANG_GUTTERSPEAK  },
-    { LANG_DRAENEI,     29932, SKILL_LANG_DRAENEI      },
-    { LANG_ZOMBIE,          0, 0                       },
-    { LANG_GNOMISH_BINARY,  0, 0                       },
-    { LANG_GOBLIN_BINARY,   0, 0                       }
-};
-
-LanguageDesc const* GetLanguageDescByID(uint32 lang)
-{
-    for(int i = 0; i < LANGUAGES_COUNT; ++i)
-    {
-        if(uint32(lang_description[i].lang_id) == lang)
-            return &lang_description[i];
-    }
-
-    return NULL;
-}
-
-LanguageDesc const* GetLanguageDescBySpell(uint32 spell_id)
-{
-    for(int i = 0; i < LANGUAGES_COUNT; ++i)
-    {
-        if(lang_description[i].spell_id == spell_id)
-            return &lang_description[i];
-    }
-
-    return NULL;
-}
-
-LanguageDesc const* GetLanguageDescBySkill(uint32 skill_id)
-{
-    for(int i = 0; i < LANGUAGES_COUNT; ++i)
-    {
-        if(lang_description[i].skill_id == skill_id)
-            return &lang_description[i];
-    }
-
-    return NULL;
-}
 
 ChatCommand * ChatHandler::getCommandTable()
Index: trunk/src/game/Player.h
===================================================================
--- trunk/src/game/Player.h (revision 12)
+++ trunk/src/game/Player.h (revision 18)
@@ -1899,4 +1899,5 @@
 
         bool GetBGAccessByLevel(uint32 bgTypeId) const;
+        bool isAllowUseBattleGroundObject();
 
         /*********************************************************/
Index: trunk/src/game/GossipDef.cpp
===================================================================
--- trunk/src/game/GossipDef.cpp (revision 6)
+++ trunk/src/game/GossipDef.cpp (revision 18)
@@ -392,5 +392,5 @@
 
     pSession->SendPacket( &data );
-    //sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_STATUS NPC Guid=%u, status=%u",GUID_LOPART(npcGUID),questStatus);
+    sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_STATUS NPC Guid=%u, status=%u",GUID_LOPART(npcGUID),questStatus);
 }
 
@@ -478,5 +478,5 @@
     pSession->SendPacket( &data );
 
-    //sLog.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_DETAILS NPCGuid=%u, questid=%u",GUID_LOPART(npcGUID),pQuest->GetQuestId());
+    sLog.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_DETAILS NPCGuid=%u, questid=%u",GUID_LOPART(npcGUID),pQuest->GetQuestId());
 }
 
@@ -516,5 +516,5 @@
 
     data << uint32(pQuest->GetQuestId());
-    data << uint32(pQuest->GetMinLevel());                  // not MinLevel. Accepted values: 0, 1 or 2 Possible theory for future dev: 0==cannot in quest log, 1==can in quest log session only(removed on log out), 2==can in quest log always (save to db)
+    data << uint32(pQuest->GetQuestMethod());               // Accepted values: 0, 1 or 2. 0==IsAutoComplete() (skip objectives/details)
     data << uint32(pQuest->GetQuestLevel());                // may be 0
     data << uint32(pQuest->GetZoneOrSort());                // zone or sort to display in quest log
@@ -598,5 +598,5 @@
 
     pSession->SendPacket( &data );
-    //sLog.outDebug( "WORLD: Sent SMSG_QUEST_QUERY_RESPONSE questid=%u",pQuest->GetQuestId() );
+    sLog.outDebug( "WORLD: Sent SMSG_QUEST_QUERY_RESPONSE questid=%u",pQuest->GetQuestId() );
 }
 
@@ -680,5 +680,5 @@
     data << uint32(0);                                      // Honor points reward, not implemented
     pSession->SendPacket( &data );
-    //sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_OFFER_REWARD NPCGuid=%u, questid=%u",GUID_LOPART(npcGUID),pQuest->GetQuestId() );
+    sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_OFFER_REWARD NPCGuid=%u, questid=%u",GUID_LOPART(npcGUID),pQuest->GetQuestId() );
 }
 
@@ -759,4 +759,4 @@
 
     pSession->SendPacket( &data );
-    //sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_REQUEST_ITEMS NPCGuid=%u, questid=%u",GUID_LOPART(npcGUID),pQuest->GetQuestId() );
-}
+    sLog.outDebug( "WORLD: Sent SMSG_QUESTGIVER_REQUEST_ITEMS NPCGuid=%u, questid=%u",GUID_LOPART(npcGUID),pQuest->GetQuestId() );
+}
Index: trunk/src/game/QuestDef.cpp
===================================================================
--- trunk/src/game/QuestDef.cpp (revision 2)
+++ trunk/src/game/QuestDef.cpp (revision 18)
@@ -24,103 +24,104 @@
 {
     QuestId = questRecord[0].GetUInt32();
-    ZoneOrSort = questRecord[1].GetInt32();
-    SkillOrClass = questRecord[2].GetInt32();
-    MinLevel = questRecord[3].GetUInt32();
-    QuestLevel = questRecord[4].GetUInt32();
-    Type = questRecord[5].GetUInt32();
-    RequiredRaces = questRecord[6].GetUInt32();
-    RequiredSkillValue = questRecord[7].GetUInt32();
-    RepObjectiveFaction = questRecord[8].GetUInt32();
-    RepObjectiveValue = questRecord[9].GetInt32();
-    RequiredMinRepFaction = questRecord[10].GetUInt32();
-    RequiredMinRepValue = questRecord[11].GetInt32();
-    RequiredMaxRepFaction = questRecord[12].GetUInt32();
-    RequiredMaxRepValue = questRecord[13].GetInt32();
-    SuggestedPlayers = questRecord[14].GetUInt32();
-    LimitTime = questRecord[15].GetUInt32();
-    QuestFlags = questRecord[16].GetUInt16();
-    uint32 SpecialFlags = questRecord[17].GetUInt16();
-    CharTitleId = questRecord[18].GetUInt32();
-    PrevQuestId = questRecord[19].GetInt32();
-    NextQuestId = questRecord[20].GetInt32();
-    ExclusiveGroup = questRecord[21].GetInt32();
-    NextQuestInChain = questRecord[22].GetUInt32();
-    SrcItemId = questRecord[23].GetUInt32();
-    SrcItemCount = questRecord[24].GetUInt32();
-    SrcSpell = questRecord[25].GetUInt32();
-    Title = questRecord[26].GetCppString();
-    Details = questRecord[27].GetCppString();
-    Objectives = questRecord[28].GetCppString();
-    OfferRewardText = questRecord[29].GetCppString();
-    RequestItemsText = questRecord[30].GetCppString();
-    EndText = questRecord[31].GetCppString();
-
-    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
-        ObjectiveText[i] = questRecord[32+i].GetCppString();
-
-    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
-        ReqItemId[i] = questRecord[36+i].GetUInt32();
-
-    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
-        ReqItemCount[i] = questRecord[40+i].GetUInt32();
+    QuestMethod = questRecord[1].GetUInt32();
+    ZoneOrSort = questRecord[2].GetInt32();
+    SkillOrClass = questRecord[3].GetInt32();
+    MinLevel = questRecord[4].GetUInt32();
+    QuestLevel = questRecord[5].GetUInt32();
+    Type = questRecord[6].GetUInt32();
+    RequiredRaces = questRecord[7].GetUInt32();
+    RequiredSkillValue = questRecord[8].GetUInt32();
+    RepObjectiveFaction = questRecord[9].GetUInt32();
+    RepObjectiveValue = questRecord[10].GetInt32();
+    RequiredMinRepFaction = questRecord[11].GetUInt32();
+    RequiredMinRepValue = questRecord[12].GetInt32();
+    RequiredMaxRepFaction = questRecord[13].GetUInt32();
+    RequiredMaxRepValue = questRecord[14].GetInt32();
+    SuggestedPlayers = questRecord[15].GetUInt32();
+    LimitTime = questRecord[16].GetUInt32();
+    QuestFlags = questRecord[17].GetUInt16();
+    uint32 SpecialFlags = questRecord[18].GetUInt16();
+    CharTitleId = questRecord[19].GetUInt32();
+    PrevQuestId = questRecord[20].GetInt32();
+    NextQuestId = questRecord[21].GetInt32();
+    ExclusiveGroup = questRecord[22].GetInt32();
+    NextQuestInChain = questRecord[23].GetUInt32();
+    SrcItemId = questRecord[24].GetUInt32();
+    SrcItemCount = questRecord[25].GetUInt32();
+    SrcSpell = questRecord[26].GetUInt32();
+    Title = questRecord[27].GetCppString();
+    Details = questRecord[28].GetCppString();
+    Objectives = questRecord[29].GetCppString();
+    OfferRewardText = questRecord[30].GetCppString();
+    RequestItemsText = questRecord[31].GetCppString();
+    EndText = questRecord[32].GetCppString();
+
+    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
+        ObjectiveText[i] = questRecord[33+i].GetCppString();
+
+    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
+        ReqItemId[i] = questRecord[37+i].GetUInt32();
+
+    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
+        ReqItemCount[i] = questRecord[41+i].GetUInt32();
 
     for (int i = 0; i < QUEST_SOURCE_ITEM_IDS_COUNT; ++i)
-        ReqSourceId[i] = questRecord[44+i].GetUInt32();
+        ReqSourceId[i] = questRecord[45+i].GetUInt32();
 
     for (int i = 0; i < QUEST_SOURCE_ITEM_IDS_COUNT; ++i)
-        ReqSourceCount[i] = questRecord[48+i].GetUInt32();
+        ReqSourceCount[i] = questRecord[49+i].GetUInt32();
 
     for (int i = 0; i < QUEST_SOURCE_ITEM_IDS_COUNT; ++i)
-        ReqSourceRef[i] = questRecord[52+i].GetUInt32();
-
-    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
-        ReqCreatureOrGOId[i] = questRecord[56+i].GetInt32();
-
-    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
-        ReqCreatureOrGOCount[i] = questRecord[60+i].GetUInt32();
-
-    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
-        ReqSpell[i] = questRecord[64+i].GetUInt32();
+        ReqSourceRef[i] = questRecord[53+i].GetUInt32();
+
+    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
+        ReqCreatureOrGOId[i] = questRecord[57+i].GetInt32();
+
+    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
+        ReqCreatureOrGOCount[i] = questRecord[61+i].GetUInt32();
+
+    for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
+        ReqSpell[i] = questRecord[65+i].GetUInt32();
 
     for (int i = 0; i < QUEST_REWARD_CHOICES_COUNT; ++i)
-        RewChoiceItemId[i] = questRecord[68+i].GetUInt32();
+        RewChoiceItemId[i] = questRecord[69+i].GetUInt32();
 
     for (int i = 0; i < QUEST_REWARD_CHOICES_COUNT; ++i)
-        RewChoiceItemCount[i] = questRecord[74+i].GetUInt32();
+        RewChoiceItemCount[i] = questRecord[75+i].GetUInt32();
 
     for (int i = 0; i < QUEST_REWARDS_COUNT; ++i)
-        RewItemId[i] = questRecord[80+i].GetUInt32();
+        RewItemId[i] = questRecord[81+i].GetUInt32();
 
     for (int i = 0; i < QUEST_REWARDS_COUNT; ++i)
-        RewItemCount[i] = questRecord[84+i].GetUInt32();
+        RewItemCount[i] = questRecord[85+i].GetUInt32();
 
     for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i)
-        RewRepFaction[i] = questRecord[88+i].GetUInt32();
+        RewRepFaction[i] = questRecord[89+i].GetUInt32();
 
     for (int i = 0; i < QUEST_REPUTATIONS_COUNT; ++i)
-        RewRepValue[i] = questRecord[93+i].GetInt32();
-
-    RewOrReqMoney = questRecord[98].GetInt32();
-    RewMoneyMaxLevel = questRecord[99].GetUInt32();
-    RewSpell = questRecord[100].GetUInt32();
-    RewSpellCast = questRecord[101].GetUInt32();
-    RewMailTemplateId = questRecord[102].GetUInt32();
-    RewMailDelaySecs = questRecord[103].GetUInt32();
-    PointMapId = questRecord[104].GetUInt32();
-    PointX = questRecord[105].GetFloat();
-    PointY = questRecord[106].GetFloat();
-    PointOpt = questRecord[107].GetUInt32();
+        RewRepValue[i] = questRecord[94+i].GetInt32();
+
+    RewOrReqMoney = questRecord[99].GetInt32();
+    RewMoneyMaxLevel = questRecord[100].GetUInt32();
+    RewSpell = questRecord[101].GetUInt32();
+    RewSpellCast = questRecord[102].GetUInt32();
+    RewMailTemplateId = questRecord[103].GetUInt32();
+    RewMailDelaySecs = questRecord[104].GetUInt32();
+    PointMapId = questRecord[105].GetUInt32();
+    PointX = questRecord[106].GetFloat();
+    PointY = questRecord[107].GetFloat();
+    PointOpt = questRecord[108].GetUInt32();
 
     for (int i = 0; i < QUEST_EMOTE_COUNT; ++i)
-        DetailsEmote[i] = questRecord[108+i].GetUInt32();
-
-    IncompleteEmote = questRecord[112].GetUInt32();
-    CompleteEmote = questRecord[113].GetUInt32();
+        DetailsEmote[i] = questRecord[109+i].GetUInt32();
+
+    IncompleteEmote = questRecord[113].GetUInt32();
+    CompleteEmote = questRecord[114].GetUInt32();
 
     for (int i = 0; i < QUEST_EMOTE_COUNT; ++i)
-        OfferRewardEmote[i] = questRecord[114+i].GetInt32();
-
-    QuestStartScript = questRecord[118].GetUInt32();
-    QuestCompleteScript = questRecord[119].GetUInt32();
+        OfferRewardEmote[i] = questRecord[115+i].GetInt32();
+
+    QuestStartScript = questRecord[119].GetUInt32();
+    QuestCompleteScript = questRecord[120].GetUInt32();
 
     QuestFlags |= SpecialFlags << 16;
Index: trunk/src/game/TargetedMovementGenerator.cpp
===================================================================
--- trunk/src/game/TargetedMovementGenerator.cpp (revision 2)
+++ trunk/src/game/TargetedMovementGenerator.cpp (revision 18)
@@ -86,4 +86,6 @@
     i_destinationHolder.SetDestination(traveller, x, y, z);
     owner.addUnitState(UNIT_STAT_CHASE);
+    if (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->canFly())
+        owner.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
 }
 
@@ -95,4 +97,8 @@
         return;
     owner.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
+
+    if (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->canFly())
+        owner.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
+    
     _setTargetLocation(owner);
 }
@@ -144,4 +150,7 @@
     {
         owner.addUnitState(UNIT_STAT_CHASE);
+        if (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->canFly())
+            owner.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
+
         i_destinationHolder.StartTravel(traveller);
         return true;
Index: trunk/src/game/GameObject.cpp
===================================================================
--- trunk/src/game/GameObject.cpp (revision 2)
+++ trunk/src/game/GameObject.cpp (revision 18)
@@ -55,4 +55,6 @@
     m_cooldownTime = 0;
     m_goInfo = NULL;
+
+    m_DBTableGuid = 0;
 }
 
@@ -109,5 +111,4 @@
     Object::_Create(guidlow, goinfo->id, HIGHGUID_GAMEOBJECT);
 
-    m_DBTableGuid = guidlow;
     m_goInfo = goinfo;
 
@@ -479,5 +480,5 @@
 void GameObject::SaveToDB()
 {
-    // this should only be used when the creature has already been loaded
+    // this should only be used when the gameobject has already been loaded
     // perferably after adding to map, because mapid may not be valid otherwise
     GameObjectData const *data = objmgr.GetGOData(m_DBTableGuid);
@@ -497,5 +498,7 @@
     if (!goI)
         return;
-
+    
+    if (!m_DBTableGuid)
+        m_DBTableGuid = GetGUIDLow();
     // update in loaded data (changing data only in this place)
     GameObjectData& data = objmgr.NewGOData(m_DBTableGuid);
@@ -567,11 +570,9 @@
     uint32 go_state = data->go_state;
 
-    uint32 stored_guid = guid;
+    m_DBTableGuid = guid;
     if (map->GetInstanceId() != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT);
 
     if (!Create(guid,entry, map, x, y, z, ang, rotation0, rotation1, rotation2, rotation3, animprogress, go_state) )
         return false;
-
-    m_DBTableGuid = stored_guid;
 
     switch(GetGOInfo()->type)
@@ -590,5 +591,5 @@
                 m_spawnedByDefault = true;
                 m_respawnDelayTime = data->spawntimesecs;
-                m_respawnTime = objmgr.GetGORespawnTime(stored_guid, map->GetInstanceId());
+                m_respawnTime = objmgr.GetGORespawnTime(m_DBTableGuid, map->GetInstanceId());
 
                                                             // ready to respawn
@@ -1159,10 +1160,7 @@
             Player* player = (Player*)user;
 
-            if( player->InBattleGround() &&                 // in battleground
-                !player->IsMounted() &&                     // not mounted
-                !player->HasStealthAura() &&                // not stealthed
-                !player->HasInvisibilityAura() &&           // not invisible
-                player->isAlive())                          // live player
-            {
+            if( player->isAllowUseBattleGroundObject() )
+            {
+                // in battleground check
                 BattleGround *bg = player->GetBattleGround();
                 if(!bg)
@@ -1187,11 +1185,7 @@
             Player* player = (Player*)user;
 
-            if( player->InBattleGround() &&                 // in battleground
-                !player->IsMounted() &&                     // not mounted
-                !player->HasStealthAura() &&                // not stealthed
-                !player->HasInvisibilityAura() &&           // not invisible
-                !player->HasAura(SPELL_RECENTLY_DROPPED_FLAG, 0) &&  // can't pickup
-                player->isAlive())                          // live player
-            {
+            if( player->isAllowUseBattleGroundObject() )     
+            {
+                // in battleground check
                 BattleGround *bg = player->GetBattleGround();
                 if(!bg)
Index: trunk/src/game/ObjectMgr.h
===================================================================
--- trunk/src/game/ObjectMgr.h (revision 9)
+++ trunk/src/game/ObjectMgr.h (revision 18)
@@ -229,16 +229,6 @@
 typedef HM_NAMESPACE::hash_map<uint32, uint32> CacheNpcTextIdMap;
 
-// Vendors
-struct VendorItem
-{
-    uint32 item;
-    uint32 maxcount;
-    uint32 incrtime;
-    uint32 ExtendedCost;
-};
-typedef std::vector<VendorItem*> VendorItemList;
-
-typedef HM_NAMESPACE::hash_map<uint32, VendorItemList> CacheVendorItemMap;
-
+
+typedef HM_NAMESPACE::hash_map<uint32, VendorItemData> CacheVendorItemMap;
 typedef HM_NAMESPACE::hash_map<uint32, TrainerSpellData> CacheTrainerSpellMap;
 
@@ -258,4 +248,14 @@
 
 bool normalizePlayerName(std::string& name);
+
+struct MANGOS_DLL_SPEC LanguageDesc
+{
+    Language lang_id;
+    uint32   spell_id;
+    uint32   skill_id;
+};
+
+extern LanguageDesc lang_description[LANGUAGES_COUNT];
+MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
 
 class PlayerDumpReader;
@@ -733,5 +733,5 @@
         }
 
-        VendorItemList const* GetNpcVendorItemList(uint32 entry) const
+        VendorItemData const* GetNpcVendorItemList(uint32 entry) const
         {
             CacheVendorItemMap::const_iterator  iter = m_mCacheVendorItemMap.find(entry);
@@ -741,4 +741,7 @@
             return &iter->second;
         }
+        void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
+        bool RemoveVendorItem(uint32 entry,uint32 item);
+        bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL ) const;
     protected:
         uint32 m_auctionid;
Index: trunk/src/game/Level2.cpp
===================================================================
--- trunk/src/game/Level2.cpp (revision 6)
+++ trunk/src/game/Level2.cpp (revision 18)
@@ -1238,12 +1238,4 @@
         return false;
 
-    Creature* vendor = getSelectedCreature();
-    if (!vendor || !vendor->isVendor())
-    {
-        SendSysMessage(LANG_COMMAND_VENDORSELECTION);
-        SetSentErrorMessage(true);
-        return false;
-    }
-
     char* pitem  = extractKeyFromLink((char*)args,"Hitem");
     if (!pitem)
@@ -1253,4 +1245,5 @@
         return false;
     }
+
     uint32 itemId = atol(pitem);
 
@@ -1268,39 +1261,18 @@
     uint32 extendedcost = fextendedcost ? atol(fextendedcost) : 0;
 
-    ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
-    if(!pProto)
-    {
-        PSendSysMessage(LANG_ITEM_NOT_FOUND, itemId);
-        SetSentErrorMessage(true);
-        return false;
-    }
-
-    if(extendedcost && !sItemExtendedCostStore.LookupEntry(extendedcost))
-    {
-        PSendSysMessage(LANG_BAD_VALUE, extendedcost);
-        SetSentErrorMessage(true);
-        return false;
-    }
-
-    // load vendor items if not yet
-    vendor->LoadGoods();
-
-    if(vendor->FindItem(itemId))
-    {
-        PSendSysMessage(LANG_ITEM_ALREADY_IN_LIST,itemId);
-        SetSentErrorMessage(true);
-        return false;
-    }
-
-    if (vendor->GetItemCount() >= MAX_VENDOR_ITEMS)
-    {
-        SendSysMessage(LANG_COMMAND_ADDVENDORITEMITEMS);
-        SetSentErrorMessage(true);
-        return false;
-    }
-
-    // add to DB and to current ingame vendor
-    WorldDatabase.PExecuteLog("INSERT INTO npc_vendor (entry,item,maxcount,incrtime,extendedcost) VALUES('%u','%u','%u','%u','%u')",vendor->GetEntry(), itemId, maxcount,incrtime,extendedcost);
-    vendor->AddItem(itemId,maxcount,incrtime,extendedcost);
+    Creature* vendor = getSelectedCreature();
+
+    uint32 vendor_entry = vendor ? vendor->GetEntry() : 0;
+
+    if(!objmgr.IsVendorItemValid(vendor_entry,itemId,maxcount,incrtime,extendedcost,m_session->GetPlayer()))
+    {
+        SetSentErrorMessage(true);
+        return false;
+    }
+
+    objmgr.AddVendorItem(vendor_entry,itemId,maxcount,incrtime,extendedcost);
+
+    ItemPrototype const* pProto = objmgr.GetItemPrototype(itemId);
+
     PSendSysMessage(LANG_ITEM_ADDED_TO_LIST,itemId,pProto->Name1,maxcount,incrtime,extendedcost);
     return true;
@@ -1330,16 +1302,6 @@
     uint32 itemId = atol(pitem);
 
-    ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
-    if(!pProto)
-    {
-        PSendSysMessage(LANG_ITEM_NOT_FOUND, itemId);
-        SetSentErrorMessage(true);
-        return false;
-    }
-
-    // load vendor items if not yet
-    vendor->LoadGoods();
-
-    if (!vendor->RemoveItem(itemId))
+
+    if(!objmgr.RemoveVendorItem(vendor->GetEntry(),itemId))
     {
         PSendSysMessage(LANG_ITEM_NOT_IN_LIST,itemId);
@@ -1348,5 +1310,6 @@
     }
 
-    WorldDatabase.PExecuteLog("DELETE FROM npc_vendor WHERE entry='%u' AND item='%u'",vendor->GetEntry(), itemId);
+    ItemPrototype const* pProto = objmgr.GetItemPrototype(itemId);
+
     PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST,itemId,pProto->Name1);
     return true;
Index: trunk/src/game/Player.cpp
===================================================================
--- trunk/src/game/Player.cpp (revision 12)
+++ trunk/src/game/Player.cpp (revision 18)
@@ -5795,5 +5795,5 @@
         return;
 
-    ReputationOnKillEntry const* Rep = objmgr.GetReputationOnKilEntry(pVictim->GetEntry());
+    ReputationOnKillEntry const* Rep = objmgr.GetReputationOnKilEntry(((Creature*)pVictim)->GetCreatureInfo()->Entry);
 
     if(!Rep)
@@ -16381,9 +16381,6 @@
     }
 
-    // load vendor items if not yet
-    pCreature->LoadGoods();
-
-    CreatureItem* crItem = pCreature->FindItem(item);
-    if(!crItem)
+    VendorItemData const* vItems = pCreature->GetVendorItems();
+    if(!vItems || vItems->Empty())
     {
         SendBuyError( BUY_ERR_CANT_FIND_ITEM, pCreature, item, 0);
@@ -16391,8 +16388,19 @@
     }
 
-    if( crItem->maxcount != 0 && crItem->count < count )
-    {
-        SendBuyError( BUY_ERR_ITEM_ALREADY_SOLD, pCreature, item, 0);
+    VendorItem const* crItem = vItems->FindItem(item);
+    if(!crItem)
+    {
+        SendBuyError( BUY_ERR_CANT_FIND_ITEM, pCreature, item, 0);
         return false;
+    }
+
+    // check current item amount if it limited
+    if( crItem->maxcount != 0 )
+    {
+        if(pCreature->GetVendorItemCurrentCount(crItem) < pProto->BuyCount * count )
+        {
+            SendBuyError( BUY_ERR_ITEM_ALREADY_SOLD, pCreature, item, 0);
+            return false;
+        }
     }
 
@@ -16509,15 +16517,14 @@
         if(Item *it = StoreNewItem( dest, item, true ))
         {
-            if( crItem->maxcount != 0 )
-                crItem->count -= pProto->BuyCount * count;
+            uint32 new_count = pCreature->UpdateVendorItemCurrentCount(crItem,pProto->BuyCount * count);
 
             WorldPacket data(SMSG_BUY_ITEM, (8+4+4+4));
             data << pCreature->GetGUID();
-            data << (uint32)crItem->id;                     // entry
-            data << (uint32)crItem->count;
+            data << (uint32)crItem->item;
+            data << (uint32)(crItem->maxcount > 0 ? new_count : 0xFFFFFFFF);
             data << (uint32)count;
             GetSession()->SendPacket(&data);
 
-            SendNewItem(it, count, true, false, false);
+            SendNewItem(it, pProto->BuyCount*count, true, false, false);
         }
     }
@@ -16549,15 +16556,14 @@
         if(Item *it = EquipNewItem( dest, item, pProto->BuyCount * count, true ))
         {
-            if( crItem->maxcount != 0 )
-                crItem->count -= pProto->BuyCount * count;
+            uint32 new_count = pCreature->UpdateVendorItemCurrentCount(crItem,pProto->BuyCount * count);
 
             WorldPacket data(SMSG_BUY_ITEM, (8+4+4+4));
             data << pCreature->GetGUID();
-            data << (uint32)crItem->id;                     // entry
-            data << (uint32)crItem->count;
+            data << (uint32)crItem->item;
+            data << (uint32)(crItem->maxcount > 0 ? new_count : 0xFFFFFFFF);
             data << (uint32)count;
             GetSession()->SendPacket(&data);
 
-            SendNewItem(it, count, true, false, false);
+            SendNewItem(it, pProto->BuyCount*count, true, false, false);
 
             AutoUnequipOffhandIfNeed();
@@ -16570,5 +16576,5 @@
     }
 
-    return crItem->maxcount!=0?true:false;
+    return crItem->maxcount!=0;
 }
 
@@ -17175,5 +17181,5 @@
     // set fly flag if in fly form or taxi flight to prevent visually drop at ground in showup moment
     if(HasAuraType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED) || isInFlight())
-        SetUnitMovementFlags(GetUnitMovementFlags() | MOVEMENTFLAG_FLYING2);
+        AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
 }
 
@@ -18168,2 +18174,13 @@
     return false;
 }
+
+bool Player::isAllowUseBattleGroundObject()
+{
+    return ( //InBattleGround() &&                            // in battleground - not need, check in other cases
+             !IsMounted() &&                                  // not mounted
+             !HasStealthAura() &&                             // not stealthed
+             !HasInvisibilityAura() &&                        // not invisible
+             !HasAura(SPELL_RECENTLY_DROPPED_FLAG, 0) &&      // can't pickup
+             isAlive()                                        // live player
+           );
+}
Index: trunk/src/game/RandomMovementGenerator.cpp
===================================================================
--- trunk/src/game/RandomMovementGenerator.cpp (revision 2)
+++ trunk/src/game/RandomMovementGenerator.cpp (revision 18)
@@ -32,5 +32,4 @@
     float X,Y,Z,z,nx,ny,nz,wander_distance,ori,dist;
 
-    creature.GetRespawnCoord(X, Y, Z);
     creature.GetRespawnCoord(X, Y, Z, &ori, &wander_distance);
 
@@ -51,4 +50,9 @@
     nx = X + distanceX;
     ny = Y + distanceY;
+
+    // prevent invalid coordinates generation 
+    MaNGOS::NormalizeMapCoord(nx);
+    MaNGOS::NormalizeMapCoord(ny);
+
     dist = distanceX*distanceX + distanceY*distanceY;
 
@@ -88,5 +92,5 @@
     {
         i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
-        creature.SetUnitMovementFlags(MOVEMENTFLAG_FLYING2);
+        creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
     }
     //else if (is_water_ok) // Swimming mode to be done with more than this check
@@ -106,5 +110,5 @@
 
     if (creature.canFly())
-        creature.SetUnitMovementFlags(MOVEMENTFLAG_FLYING2);
+        creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
     else
         creature.SetUnitMovementFlags(irand(0,RUNNING_CHANCE_RANDOMMV) > 0 ? MOVEMENTFLAG_WALK_MODE : MOVEMENTFLAG_NONE );
@@ -145,5 +149,5 @@
         {
             if (creature.canFly())
-                creature.SetUnitMovementFlags(MOVEMENTFLAG_FLYING2);
+                creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
             else
                 creature.SetUnitMovementFlags(irand(0,RUNNING_CHANCE_RANDOMMV) > 0 ? MOVEMENTFLAG_WALK_MODE : MOVEMENTFLAG_NONE);
Index: trunk/src/game/PointMovementGenerator.cpp
===================================================================
--- trunk/src/game/PointMovementGenerator.cpp (revision 2)
+++ trunk/src/game/PointMovementGenerator.cpp (revision 18)
@@ -31,4 +31,7 @@
     Traveller<T> traveller(unit);
     i_destinationHolder.SetDestination(traveller,i_x,i_y,i_z);
+    
+    if (unit.GetTypeId() == TYPEID_UNIT && ((Creature*)&unit)->canFly())
+        unit.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
 }
 
Index: trunk/src/game/Spell.cpp
===================================================================
--- trunk/src/game/Spell.cpp (revision 15)
+++ trunk/src/game/Spell.cpp (revision 18)
@@ -3682,4 +3682,9 @@
                     return SPELL_FAILED_BAD_TARGETS;
 
+                // In BattleGround players can use only flags and banners
+                if( ((Player*)m_caster)->InBattleGround() &&
+                    !((Player*)m_caster)->isAllowUseBattleGroundObject() )
+                    return SPELL_FAILED_TRY_AGAIN;
+
                 // get the lock entry
                 LockEntry const *lockInfo = NULL;
Index: trunk/src/game/Pet.cpp
===================================================================
--- trunk/src/game/Pet.cpp (revision 2)
+++ trunk/src/game/Pet.cpp (revision 18)
@@ -1743,5 +1743,5 @@
     if(auraId == 35696)                                       // Demonic Knowledge
     {
-        int32 basePoints = aura->GetDamage() * (GetStat(STAT_STAMINA) + GetStat(STAT_INTELLECT)) / 100;
+        int32 basePoints = int32(aura->GetDamage() * (GetStat(STAT_STAMINA) + GetStat(STAT_INTELLECT)) / 100);
         CastCustomSpell(this,auraId,&basePoints, NULL, NULL, true );
     }
Index: trunk/src/game/Creature.cpp
===================================================================
--- trunk/src/game/Creature.cpp (revision 14)
+++ trunk/src/game/Creature.cpp (revision 18)
@@ -63,13 +63,34 @@
 }
 
+bool VendorItemData::RemoveItem( uint32 item_id )
+{
+    for(VendorItemList::iterator i = m_items.begin(); i != m_items.end(); ++i )
+    {
+        if((*i)->item==item_id)
+        {
+            m_items.erase(i);
+            return true;
+        }
+    }
+    return false;
+}
+
+VendorItem const* VendorItemData::FindItem(uint32 item_id) const
+{
+    for(VendorItemList::const_iterator i = m_items.begin(); i != m_items.end(); ++i )
+        if((*i)->item==item_id)
+            return *i;
+    return NULL;
+}
+
 Creature::Creature() :
 Unit(), i_AI(NULL),
 lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0),
-m_itemsLoaded(false), m_lootMoney(0), m_lootRecipient(0),
+m_lootMoney(0), m_lootRecipient(0),
 m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f),
 m_gossipOptionLoaded(false),m_emoteState(0), m_isPet(false), m_isTotem(false),
 m_regenTimer(2000), m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0),
 m_AlreadyCallAssistence(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false),
-m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),m_creatureInfo(NULL)
+m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),m_creatureInfo(NULL), m_DBTableGuid(0)
 {
     m_valuesCount = UNIT_END;
@@ -88,5 +109,5 @@
     CleanupsBeforeDelete();
 
-    m_vendor_items.clear();
+    m_vendorItemCounts.clear();
 
     delete i_AI;
@@ -504,4 +525,5 @@
                 break;
         }
+        LoadCreaturesAddon();
     }
 
@@ -674,8 +696,7 @@
                         break;
                     case GOSSIP_OPTION_VENDOR:
-                        // load vendor items if not yet
-                        LoadGoods();
-
-                        if(!GetItemCount())
+                    {
+                        VendorItemData const* vItems = GetVendorItems();
+                        if(!vItems || vItems->Empty())
                         {
                             sLog.outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_VENDOR but have empty trading item list.",
@@ -684,4 +705,5 @@
                         }
                         break;
+                    }
                     case GOSSIP_OPTION_TRAINER:
                         if(!isCanTrainingOf(pPlayer,false))
@@ -935,4 +957,7 @@
 uint32 Creature::GetNpcTextId()
 {
+    if (!m_DBTableGuid)
+        return DEFAULT_GOSSIP_MESSAGE;
+
     if(uint32 pos = objmgr.GetNpcGossip(m_DBTableGuid))
         return pos;
@@ -1047,4 +1072,6 @@
 {
     // update in loaded data
+    if (!m_DBTableGuid)
+        m_DBTableGuid = GetGUIDLow();
     CreatureData& data = objmgr.NewOrExistCreatureData(m_DBTableGuid);
 
@@ -1238,5 +1265,4 @@
     Object::_Create(guidlow, Entry, HIGHGUID_UNIT);
 
-    m_DBTableGuid = guidlow;
     if(!UpdateEntry(Entry, team, data))
         return false;
@@ -1264,5 +1290,5 @@
     }
 
-    uint32 stored_guid = guid;
+    m_DBTableGuid = guid;
     if (map->GetInstanceId() != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT);
 
@@ -1278,7 +1304,4 @@
         return false;
     }
-
-    m_DBTableGuid = stored_guid;
-    LoadCreaturesAddon();
 
     m_respawnradius = data->spawndist;
@@ -1347,22 +1370,4 @@
 }
 
-void Creature::LoadGoods()
-{
-    // already loaded;
-    if(m_itemsLoaded)
-        return;
-
-    m_vendor_items.clear();
-
-    VendorItemList const* vList = objmgr.GetNpcVendorItemList(GetEntry());
-    if(!vList)
-        return;
-
-    for (VendorItemList::const_iterator _item_iter = vList->begin(); _item_iter != vList->end(); ++_item_iter)
-        AddItem( (*_item_iter)->item, (*_item_iter)->maxcount, (*_item_iter)->incrtime, (*_item_iter)->ExtendedCost);
-
-    m_itemsLoaded = true;
-}
-
 bool Creature::hasQuest(uint32 quest_id) const
 {
@@ -1389,4 +1394,10 @@
 void Creature::DeleteFromDB()
 {
+    if (!m_DBTableGuid)
+    {
+        sLog.outDebug("Trying to delete not saved creature!");
+        return;
+    }
+
     objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0);
     objmgr.DeleteCreatureData(m_DBTableGuid);
@@ -1495,5 +1506,6 @@
     if(getDeathState()==DEAD)
     {
-        objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0);
+        if (m_DBTableGuid)
+            objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0);
         m_respawnTime = time(NULL);                         // respawn at next tick
     }
@@ -1717,5 +1729,5 @@
 void Creature::SaveRespawnTime()
 {
-    if(isPet())
+    if(isPet() || !m_DBTableGuid)
         return;
 
@@ -1753,6 +1765,9 @@
 CreatureDataAddon const* Creature::GetCreatureAddon() const
 {
-    if(CreatureDataAddon const* addon = ObjectMgr::GetCreatureAddon(m_DBTableGuid))
-        return addon;
+    if (m_DBTableGuid)
+    {
+        if(CreatureDataAddon const* addon = ObjectMgr::GetCreatureAddon(m_DBTableGuid))
+            return addon;
+    }
 
     // dependent from heroic mode entry
@@ -1957,4 +1972,82 @@
 }
 
+
+VendorItemData const* Creature::GetVendorItems() const
+{
+    return objmgr.GetNpcVendorItemList(GetEntry());
+}
+
+uint32 Creature::GetVendorItemCurrentCount(VendorItem const* vItem)
+{
+    if(!vItem->maxcount)
+        return vItem->maxcount;
+
+    VendorItemCounts::iterator itr = m_vendorItemCounts.begin();
+    for(; itr != m_vendorItemCounts.end(); ++itr)
+        if(itr->itemId==vItem->item)
+            break;
+
+    if(itr == m_vendorItemCounts.end())
+        return vItem->maxcount;
+
+    VendorItemCount* vCount = &*itr;
+
+    time_t ptime = time(NULL);
+
+    if( vCount->lastIncrementTime + vItem->incrtime <= ptime )
+    {
+        ItemPrototype const* pProto = objmgr.GetItemPrototype(vItem->item);
+
+        uint32 diff = uint32((ptime - vCount->lastIncrementTime)/vItem->incrtime);
+        if((vCount->count + diff * pProto->BuyCount) >= vItem->maxcount )
+        {
+            m_vendorItemCounts.erase(itr);        
+            return vItem->maxcount;
+        }
+
+        vCount->count += diff * pProto->BuyCount;
+        vCount->lastIncrementTime = ptime;
+    }
+
+    return vCount->count;
+}
+
+uint32 Creature::UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 used_count)
+{
+    if(!vItem->maxcount)
+        return 0;
+
+    VendorItemCounts::iterator itr = m_vendorItemCounts.begin();
+    for(; itr != m_vendorItemCounts.end(); ++itr)
+        if(itr->itemId==vItem->item)
+            break;
+
+    if(itr == m_vendorItemCounts.end())
+    {
+        uint32 new_count = vItem->maxcount > used_count ? vItem->maxcount-used_count : 0;
+        m_vendorItemCounts.push_back(VendorItemCount(vItem->item,new_count));
+        return new_count;
+    }
+
+    VendorItemCount* vCount = &*itr;
+
+    time_t ptime = time(NULL);
+
+    if( vCount->lastIncrementTime + vItem->incrtime <= ptime )
+    {
+        ItemPrototype const* pProto = objmgr.GetItemPrototype(vItem->item);
+
+        uint32 diff = uint32((ptime - vCount->lastIncrementTime)/vItem->incrtime);
+        if((vCount->count + diff * pProto->BuyCount) < vItem->maxcount )
+            vCount->count += diff * pProto->BuyCount;
+        else
+            vCount->count = vItem->maxcount;
+    }
+
+    vCount->count = vCount->count > used_count ? vCount->count-used_count : 0;
+    vCount->lastIncrementTime = ptime;
+    return vCount->count;
+}
+
 TrainerSpellData const* Creature::GetTrainerSpells() const
 {
Index: trunk/src/game/ObjectMgr.cpp
===================================================================
--- trunk/src/game/ObjectMgr.cpp (revision 6)
+++ trunk/src/game/ObjectMgr.cpp (revision 18)
@@ -71,4 +71,38 @@
 }
 
+LanguageDesc lang_description[LANGUAGES_COUNT] =
+{
+    { LANG_ADDON,           0, 0                       },
+    { LANG_UNIVERSAL,       0, 0                       },
+    { LANG_ORCISH,        669, SKILL_LANG_ORCISH       },
+    { LANG_DARNASSIAN,    671, SKILL_LANG_DARNASSIAN   },
+    { LANG_TAURAHE,       670, SKILL_LANG_TAURAHE      },
+    { LANG_DWARVISH,      672, SKILL_LANG_DWARVEN      },
+    { LANG_COMMON,        668, SKILL_LANG_COMMON       },
+    { LANG_DEMONIC,       815, SKILL_LANG_DEMON_TONGUE },
+    { LANG_TITAN,         816, SKILL_LANG_TITAN        },
+    { LANG_THALASSIAN,    813, SKILL_LANG_THALASSIAN   },
+    { LANG_DRACONIC,      814, SKILL_LANG_DRACONIC     },
+    { LANG_KALIMAG,       817, SKILL_LANG_OLD_TONGUE   },
+    { LANG_GNOMISH,      7340, SKILL_LANG_GNOMISH      },
+    { LANG_TROLL,        7341, SKILL_LANG_TROLL        },
+    { LANG_GUTTERSPEAK, 17737, SKILL_LANG_GUTTERSPEAK  },
+    { LANG_DRAENEI,     29932, SKILL_LANG_DRAENEI      },
+    { LANG_ZOMBIE,          0, 0                       },
+    { LANG_GNOMISH_BINARY,  0, 0                       },
+    { LANG_GOBLIN_BINARY,   0, 0                       }
+};
+
+LanguageDesc const* GetLanguageDescByID(uint32 lang)
+{
+    for(int i = 0; i < LANGUAGES_COUNT; ++i)
+    {
+        if(uint32(lang_description[i].lang_id) == lang)
+            return &lang_description[i];
+    }
+
+    return NULL;
+}
+
 ObjectMgr::ObjectMgr()
 {
@@ -135,6 +169,5 @@
 
     for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr)
-        for (VendorItemList::iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
-            delete (*itr2);
+        itr->second.Clear();
 
     for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr)
@@ -2698,33 +2731,33 @@
     mExclusiveQuestGroups.clear();
 
-    //                                                0      1           2             3         4           5     6              7
-    QueryResult *result = WorldDatabase.Query("SELECT entry, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue,"
-    //   8                    9                  10                     11                   12                     13                   14                15
+    //                                                0      1       2           3             4         5           6     7              8
+    QueryResult *result = WorldDatabase.Query("SELECT entry, Method, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue,"
+    //   9                    10                 11                     12                   13                     14                   15                16
         "RepObjectiveFaction, RepObjectiveValue, RequiredMinRepFaction, RequiredMinRepValue, RequiredMaxRepFaction, RequiredMaxRepValue, SuggestedPlayers, LimitTime,"
-    //   16          17            18           19           20           21              22                23         24            25
+    //   17          18            19           20           21           22              23                24         25            26
         "QuestFlags, SpecialFlags, CharTitleId, PrevQuestId, NextQuestId, ExclusiveGroup, NextQuestInChain, SrcItemId, SrcItemCount, SrcSpell,"
-    //   26     27       28          29               30                31       32              33              34              35
+    //   27     28       29          30               31                32       33              34              35              36
         "Title, Details, Objectives, OfferRewardText, RequestItemsText, EndText, ObjectiveText1, ObjectiveText2, ObjectiveText3, ObjectiveText4,"
-    //   36          37          38          39          40             41             42             43
+    //   37          38          39          40          41             42             43             44
         "ReqItemId1, ReqItemId2, ReqItemId3, ReqItemId4, ReqItemCount1, ReqItemCount2, ReqItemCount3, ReqItemCount4,"
-    //   44            45            46            47            48               49               50               51               52             53             54             55
+    //   45            46            47            48            49               50               51               52               53             54             54             55
         "ReqSourceId1, ReqSourceId2, ReqSourceId3, ReqSourceId4, ReqSourceCount1, ReqSourceCount2, ReqSourceCount3, ReqSourceCount4, ReqSourceRef1, ReqSourceRef2, ReqSourceRef3, ReqSourceRef4,"
-    //   56                  57                  58                  59                  60                     61                     62                     63
+    //   57                  58                  59                  60                  61                     62                     63                     64
         "ReqCreatureOrGOId1, ReqCreatureOrGOId2, ReqCreatureOrGOId3, ReqCreatureOrGOId4, ReqCreatureOrGOCount1, ReqCreatureOrGOCount2, ReqCreatureOrGOCount3, ReqCreatureOrGOCount4,"
-    //   64             65             66             67
+    //   65             66             67             68
         "ReqSpellCast1, ReqSpellCast2, ReqSpellCast3, ReqSpellCast4,"
-    //   68                69                70                71                72                73
+    //   69                70                71                72                73                74
         "RewChoiceItemId1, RewChoiceItemId2, RewChoiceItemId3, RewChoiceItemId4, RewChoiceItemId5, RewChoiceItemId6,"
-    //   74                   75                   76                   77                   78                   79
+    //   75                   76                   77                   78                   79                   80
         "RewChoiceItemCount1, RewChoiceItemCount2, RewChoiceItemCount3, RewChoiceItemCount4, RewChoiceItemCount5, RewChoiceItemCount6,"
-    //   80          81          82          83          84             85             86             87
+    //   81          82          83          84          85             86             87             88
         "RewItemId1, RewItemId2, RewItemId3, RewItemId4, RewItemCount1, RewItemCount2, RewItemCount3, RewItemCount4,"
-    //   88              89              90              91              92              93            94            95            96            97
+    //   89              90              91              92              93              94            95            96            97            98
         "RewRepFaction1, RewRepFaction2, RewRepFaction3, RewRepFaction4, RewRepFaction5, RewRepValue1, RewRepValue2, RewRepValue3, RewRepValue4, RewRepValue5,"
-    //   98             99                100       101           102                103               104         105     106     107
+    //   99             100               101       102           103                104               105         106     107     108
         "RewOrReqMoney, RewMoneyMaxLevel, RewSpell, RewSpellCast, RewMailTemplateId, RewMailDelaySecs, PointMapId, PointX, PointY, PointOpt,"
-    //   108            109            110            111           112              113            114                115                116                117
+    //   109            110            111            112           113              114            115                116                117                118
         "DetailsEmote1, DetailsEmote2, DetailsEmote3, DetailsEmote4,IncompleteEmote, CompleteEmote, OfferRewardEmote1, OfferRewardEmote2, OfferRewardEmote3, OfferRewardEmote4,"
-    //   118          119
+    //   119          120
         "StartScript, CompleteScript"
         " FROM quest_template");
@@ -2761,4 +2794,9 @@
 
         // additional quest integrity checks (GO, creature_template and item_template must be loaded already)
+
+        if( qinfo->GetQuestMethod() >= 3 )
+        {
+            sLog.outErrorDb("Quest %u has `Method` = %u, expected values are 0, 1 or 2.",qinfo->GetQuestId(),qinfo->GetQuestMethod());
+        }
 
         if (qinfo->QuestFlags & ~QUEST_MANGOS_FLAGS_DB_ALLOWED)
@@ -6149,5 +6187,5 @@
         if(entry==0)
         {
-            sLog.outString("Table `%s` contain reserved entry 0, ignored.",table);
+            sLog.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table);
             continue;
         }
@@ -6156,5 +6194,5 @@
             int32 start = min_value > 0 ? min_value : max_value;
             int32 end   = min_value > 0 ? max_value : min_value;
-            sLog.outString("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,start,end);
+            sLog.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,start,end);
             continue;
         }
@@ -6164,5 +6202,5 @@
         if(data.Content.size() > 0)
         {
-            sLog.outString("Table `%s` contain data for already loaded entry  %i (from another table?), ignored.",table,entry);
+            sLog.outErrorDb("Table `%s` contain data for already loaded entry  %i (from another table?), ignored.",table,entry);
             continue;
         }
@@ -6657,5 +6695,5 @@
     barGoLink bar( result->GetRowCount() );
 
-    uint32 count = 0,entry,spell;
+    uint32 count = 0;
     do
     {
@@ -6664,10 +6702,18 @@
         Field* fields = result->Fetch();
 
-        entry  = fields[0].GetUInt32();
-        spell  = fields[1].GetUInt32();
-
-        if(!GetCreatureTemplate(entry))
+        uint32 entry  = fields[0].GetUInt32();
+        uint32 spell  = fields[1].GetUInt32();
+
+        CreatureInfo const* cInfo = GetCreatureTemplate(entry);
+
+        if(!cInfo)
         {
             sLog.outErrorDb("Table `npc_trainer` have entry for not existed creature template (Entry: %u), ignore", entry);
+            continue;
+        }
+
+        if(!(cInfo->npcflag & UNIT_NPC_FLAG_TRAINER))
+        {
+            sLog.outErrorDb("Table `npc_trainer` have data for not creature template (Entry: %u) without trainer flag, ignore", entry);
             continue;
         }
@@ -6716,8 +6762,5 @@
     // For reload case 
     for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr)
-    {
-        for (VendorItemList::iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
-            delete (*itr2);
-    }
+        itr->second.Clear();
     m_mCacheVendorItemMap.clear();
 
@@ -6737,5 +6780,4 @@
 
     uint32 count = 0;
-    uint32 entry, item_id, ExtendedCost;
     do
     {
@@ -6743,40 +6785,16 @@
         Field* fields = result->Fetch();
 
-        entry = fields[0].GetUInt32();
-        if(!GetCreatureTemplate(entry))
-        {
-            sLog.outErrorDb("Table `npc_vendor` have data for not existed creature template (Entry: %u), ignore", entry);
+        uint32 entry        = fields[0].GetUInt32();
+        uint32 item_id      = fields[1].GetUInt32();
+        uint32 maxcount     = fields[2].GetUInt32();
+        uint32 incrtime     = fields[3].GetUInt32();
+        uint32 ExtendedCost = fields[4].GetUInt32();
+
+        if(!IsVendorItemValid(entry,item_id,maxcount,incrtime,ExtendedCost))
             continue;
-        }
-
-        item_id  = fields[1].GetUInt32();
-        if(!GetItemPrototype(item_id))
-        {
-            sLog.outErrorDb("Table `npc_vendor` for Vendor (Entry: %u) have in item list non-existed item (%u), ignore",entry,item_id);
-            continue;
-        }
-
-        ExtendedCost = fields[4].GetUInt32();
-        if(ExtendedCost && !sItemExtendedCostStore.LookupEntry(ExtendedCost))
-        {
-            sLog.outErrorDb("Table `npc_vendor` have Item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignore",item_id,ExtendedCost,entry);
-            continue;
-        }
-
-        VendorItemList& vList = m_mCacheVendorItemMap[entry];
-
-        if(vList.size() >= MAX_VENDOR_ITEMS)
-        {
-            sLog.outErrorDb( "Table `npc_vendor` has too many items (%u >= %i) for vendor (Entry: %u), ignore", vList.size(), MAX_VENDOR_ITEMS, entry);
-            continue;
-        }
-
-        VendorItem* pVendorItem = new VendorItem();
-        pVendorItem->item         = item_id;
-        pVendorItem->maxcount     = fields[2].GetUInt32();
-        pVendorItem->incrtime     = fields[3].GetUInt32();
-        pVendorItem->ExtendedCost = ExtendedCost;
-
-        vList.push_back(pVendorItem);
+
+        VendorItemData& vList = m_mCacheVendorItemMap[entry];
+
+        vList.AddItem(item_id,maxcount,incrtime,ExtendedCost);
         ++count;
 
@@ -6839,4 +6857,107 @@
 }
 
+void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 extendedcost )
+{
+    VendorItemData& vList = m_mCacheVendorItemMap[entry];
+    vList.AddItem(item,maxcount,incrtime,extendedcost);
+
+    WorldDatabase.PExecuteLog("INSERT INTO npc_vendor (entry,item,maxcount,incrtime,extendedcost) VALUES('%u','%u','%u','%u','%u')",entry, item, maxcount,incrtime,extendedcost);
+}
+
+bool ObjectMgr::RemoveVendorItem( uint32 entry,uint32 item )
+{
+    CacheVendorItemMap::iterator  iter = m_mCacheVendorItemMap.find(entry);
+    if(iter == m_mCacheVendorItemMap.end())
+        return false;
+
+    if(!iter->second.FindItem(item))
+        return false;
+
+    iter->second.RemoveItem(item);
+    WorldDatabase.PExecuteLog("DELETE FROM npc_vendor WHERE entry='%u' AND item='%u'",entry, item);
+    return true;
+}
+
+bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost, Player* pl ) const
+{
+    CreatureInfo const* cInfo = GetCreatureTemplate(vendor_entry);
+    if(!cInfo)
+    {
+        if(pl)
+            ChatHandler(pl).SendSysMessage(LANG_COMMAND_VENDORSELECTION);
+        else
+            sLog.outErrorDb("Table `npc_vendor` have data for not existed creature template (Entry: %u), ignore", vendor_entry);
+        return false;
+    }
+
+    if(!(cInfo->npcflag & UNIT_NPC_FLAG_VENDOR))
+    {
+        if(pl)
+            ChatHandler(pl).SendSysMessage(LANG_COMMAND_VENDORSELECTION);
+        else
+            sLog.outErrorDb("Table `npc_vendor` have data for not creature template (Entry: %u) without vendor flag, ignore", vendor_entry);
+        return false;
+    }
+
+    if(!GetItemPrototype(item_id))
+    {
+        if(pl)
+            ChatHandler(pl).PSendSysMessage(LANG_ITEM_NOT_FOUND, item_id);
+        else
+            sLog.outErrorDb("Table `npc_vendor` for Vendor (Entry: %u) have in item list non-existed item (%u), ignore",vendor_entry,item_id);
+        return false;
+    }
+
+    if(ExtendedCost && !sItemExtendedCostStore.LookupEntry(ExtendedCost))
+    {
+        if(pl)
+            ChatHandler(pl).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST,ExtendedCost);
+        else
+            sLog.outErrorDb("Table `npc_vendor` have Item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignore",item_id,ExtendedCost,vendor_entry);
+        return false;
+    }
+
+    if(maxcount > 0 && incrtime == 0)
+    {
+        if(pl)
+            ChatHandler(pl).PSendSysMessage("MaxCount!=0 (%u) but IncrTime==0", maxcount);
+        else
+            sLog.outErrorDb( "Table `npc_vendor` has `maxcount` (%u) for item %u of vendor (Entry: %u) but `incrtime`=0, ignore", maxcount, item_id, vendor_entry);
+        return false;
+    }
+    else if(maxcount==0 && incrtime > 0)
+    {
+        if(pl)
+            ChatHandler(pl).PSendSysMessage("MaxCount==0 but IncrTime<>=0");
+        else
+            sLog.outErrorDb( "Table `npc_vendor` has `maxcount`=0 for item %u of vendor (Entry: %u) but `incrtime`<>0, ignore", item_id, vendor_entry);
+        return false;
+    }
+
+    VendorItemData const* vItems = GetNpcVendorItemList(vendor_entry);
+    if(!vItems)
+        return true;                                        // later checks for non-empty lists
+
+    if(vItems->FindItem(item_id))
+    {
+        if(pl)
+            ChatHandler(pl).PSendSysMessage(LANG_ITEM_ALREADY_IN_LIST,item_id);
+        else
+            sLog.outErrorDb( "Table `npc_vendor` has duplicate items %u for vendor (Entry: %u), ignore", item_id, vendor_entry);
+        return false;
+    }
+
+    if(vItems->GetItemCount() >= MAX_VENDOR_ITEMS)
+    {
+        if(pl)
+            ChatHandler(pl).SendSysMessage(LANG_COMMAND_ADDVENDORITEMITEMS);
+        else
+            sLog.outErrorDb( "Table `npc_vendor` has too many items (%u >= %i) for vendor (Entry: %u), ignore", vItems->GetItemCount(), MAX_VENDOR_ITEMS, vendor_entry);
+        return false;
+    }
+
+    return true;
+}
+
 // Functions for scripting access
 const char* GetAreaTriggerScriptNameById(uint32 id)
@@ -6849,5 +6970,5 @@
     if(start_value >= 0 || start_value <= end_value)        // start/end reversed for negative values
     {
-        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());
+        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());
         start_value = -1;
         end_value = std::numeric_limits<int32>::min();
Index: trunk/src/game/Language.h
===================================================================
--- trunk/src/game/Language.h (revision 9)
+++ trunk/src/game/Language.h (revision 18)
@@ -304,4 +304,5 @@
     LANG_LOOKUP_PLAYER_CHARACTER        = 329,
     LANG_NO_PLAYERS_FOUND               = 330,
+    LANG_EXTENDED_COST_NOT_EXIST        = 331,
 
     // Room for more level 2
Index: trunk/src/trinitycore/TrinityCore.rc
===================================================================
--- trunk/src/trinitycore/TrinityCore.rc (revision 6)
+++ trunk/src/trinitycore/TrinityCore.rc (revision 18)
@@ -53,6 +53,6 @@
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,2,6721,676
- PRODUCTVERSION 0,2,6721,676
+ FILEVERSION 0,3,6731,680
+ PRODUCTVERSION 0,3,6731,680
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
@@ -70,10 +70,10 @@
         BEGIN
             VALUE "FileDescription", "TrinityCore"
-            VALUE "FileVersion", "0, 2, 6721, 676"
+            VALUE "FileVersion", "0, 3, 6731, 680"
             VALUE "InternalName", "TrinityCore"
             VALUE "LegalCopyright", "Copyright (C) 2008"
             VALUE "OriginalFilename", "TrinityCore.exe"
             VALUE "ProductName", "TrinityCore"
-            VALUE "ProductVersion", "0, 2, 6721, 676"
+            VALUE "ProductVersion", "0, 3, 6731, 680"
         END
     END
Index: trunk/src/bindings/scripts/include/sc_creature.cpp
===================================================================
--- trunk/src/bindings/scripts/include/sc_creature.cpp (revision 13)
+++ trunk/src/bindings/scripts/include/sc_creature.cpp (revision 18)
@@ -36,6 +36,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -55,6 +55,6 @@
         if (!InCombat)
         {
+            InCombat = true;
             Aggro(who);
-            InCombat = true;
         }
     }
@@ -583,6 +583,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -602,6 +602,6 @@
         if (!InCombat)
         {
+            InCombat = true;
             Aggro(who);
-            InCombat = true;
         }
     }
Index: trunk/src/bindings/scripts/scripts/creature/mob_event_ai.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/creature/mob_event_ai.cpp (revision 14)
+++ trunk/src/bindings/scripts/scripts/creature/mob_event_ai.cpp (revision 18)
@@ -56,6 +56,4 @@
                     ProcessEvent(*i);
                     break;
-                default:
-                    break;
             }
         }
@@ -613,10 +611,16 @@
                 }
 
-                //Interrupt any previous spell
-                if (caster->IsNonMeleeSpellCasted(false) && param3 & CAST_INTURRUPT_PREVIOUS)
-                    caster->InterruptNonMeleeSpells(false);
-
-                //Cast only if not casting or if spell is triggered
-                if (param3 & CAST_TRIGGERED || !caster->IsNonMeleeSpellCasted(false))
+                //Allowed to cast only if not casting (unless we interrupt ourself) or if spell is triggered
+                bool canCast = !(caster->IsNonMeleeSpellCasted(false) && (param3 & CAST_TRIGGERED | CAST_INTURRUPT_PREVIOUS));
+
+                // If cast flag CAST_AURA_NOT_PRESENT is active, check if target already has aura on them
+                if(param3 & CAST_AURA_NOT_PRESENT)
+                {
+                    for(uint8 i = 0; i < 3; ++i)
+                        if(target->HasAura(param1, i))
+                            return;
+                }
+
+                if (canCast)
                 {
                     const SpellEntry* tSpell = GetSpellStore()->LookupEntry(param1);
@@ -639,5 +643,12 @@
                             }
 
-                        }else caster->CastSpell(target, param1, (param3 & CAST_TRIGGERED));
+                        }else
+                        {
+                            //Interrupt any previous spell
+                            if (caster->IsNonMeleeSpellCasted(false) && param3 & CAST_INTURRUPT_PREVIOUS)
+                                caster->InterruptNonMeleeSpells(false);
+
+                            caster->CastSpell(target, param1, (param3 & CAST_TRIGGERED));
+                        }
 
                     }else if (EAI_ErrorLevel > 0)
@@ -997,9 +1008,9 @@
                     }
                     break;
-                default:
+                //default:
                     //TODO: enable below code line / verify this is correct to enable events previously disabled (ex. aggro yell), instead of enable this in void Aggro()
                     //(*i).Enabled = true;
                     //(*i).Time = 0;
-                    break;
+                    //break;
             }
         }
@@ -1030,6 +1041,4 @@
                     ProcessEvent(*i);
                     break;
-                default:
-                    break;
             }
         }
@@ -1051,6 +1060,4 @@
                     ProcessEvent(*i, killer);
                     break;
-                default:
-                    break;
             }
         }
@@ -1070,6 +1077,4 @@
                     ProcessEvent(*i, victim);
                     break;
-                default:
-                    break;
             }
         }
@@ -1089,6 +1094,4 @@
                 case EVENT_T_SUMMONED_UNIT:
                     ProcessEvent(*i, pUnit);
-                    break;
-                default:
                     break;
             }
@@ -1146,6 +1149,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -1194,6 +1197,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
@@ -1215,6 +1218,4 @@
                                 ProcessEvent(*i, pUnit);
                     }
-                    break;
-                default:
                     break;
             }
Index: trunk/src/bindings/scripts/scripts/creature/mob_event_ai.h
===================================================================
--- trunk/src/bindings/scripts/scripts/creature/mob_event_ai.h (revision 6)
+++ trunk/src/bindings/scripts/scripts/creature/mob_event_ai.h (revision 18)
@@ -114,4 +114,5 @@
     CAST_NO_MELEE_IF_OOM        = 0x08,     //Prevents creature from entering melee if out of mana or out of range
     CAST_FORCE_TARGET_SELF      = 0x10,     //Forces the target to cast this spell on itself
+    CAST_AURA_NOT_PRESENT       = 0x20,     //Only casts the spell if the target does not have an aura from the spell
 };
 
Index: trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_watchkeeper_gargolmar.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_watchkeeper_gargolmar.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_watchkeeper_gargolmar.cpp (revision 18)
@@ -109,6 +109,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_omor_the_unscarred.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_omor_the_unscarred.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_omor_the_unscarred.cpp (revision 18)
@@ -118,6 +118,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -139,6 +139,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_nethekurse.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_nethekurse.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_nethekurse.cpp (revision 18)
@@ -201,6 +201,6 @@
             if( !InCombat )
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -238,6 +238,6 @@
                 if( !InCombat )
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_kaelthas.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_kaelthas.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_kaelthas.cpp (revision 18)
@@ -216,6 +216,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
@@ -235,6 +235,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -864,11 +864,7 @@
                             DoPlaySoundToSet(m_creature, SOUND_SUMMON_PHOENIX1);
                             break;
-
                         case 1:
                             DoYell(SAY_SUMMON_PHOENIX2, LANG_UNIVERSAL, NULL);
                             DoPlaySoundToSet(m_creature, SOUND_SUMMON_PHOENIX2);
-                            break;
-
-                        default:
                             break;
                     }
@@ -1253,6 +1249,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
Index: trunk/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/boss_harbinger_skyriss.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/boss_harbinger_skyriss.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/boss_harbinger_skyriss.cpp (revision 18)
@@ -131,6 +131,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
@@ -149,6 +149,6 @@
             if( !InCombat )
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -237,6 +237,4 @@
                         Intro = true;
                         break;
-                    default:
-                        break;
                 }
             }else Intro_Timer -=diff;
Index: trunk/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/arcatraz.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/arcatraz.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/arcatraz.cpp (revision 18)
@@ -139,6 +139,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
@@ -154,6 +154,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -445,6 +445,4 @@
                     pInstance->SetData(TYPE_WARDEN_5,IN_PROGRESS);
                     break;
-                default:
-                    break;
             }
             CanSpawn = true;
@@ -506,6 +504,4 @@
                         DoPlaySoundToSet(m_creature,SOUND_WELCOME);
                         break;
-                    default:
-                        break;
                 }
                 CanSpawn = false;
@@ -554,6 +550,4 @@
                         EventProgress_Timer = 15000;
                         break;
-                    default:
-                        break;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_twinemperors.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_twinemperors.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_twinemperors.cpp (revision 18)
@@ -666,6 +666,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
Index: trunk/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_nexusprince_shaffar.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_nexusprince_shaffar.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_nexusprince_shaffar.cpp (revision 18)
@@ -107,6 +107,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/aunchindoun/auchenai_crypts/boss_exarch_maladaar.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/aunchindoun/auchenai_crypts/boss_exarch_maladaar.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/aunchindoun/auchenai_crypts/boss_exarch_maladaar.cpp (revision 18)
@@ -105,6 +105,4 @@
                     Class_Timer = 10000;
                     break;
-                default:
-                    break;
             }
         }else Class_Timer -= diff;
@@ -205,6 +203,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_tailonking_ikiss.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_tailonking_ikiss.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_tailonking_ikiss.cpp (revision 18)
@@ -116,6 +116,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp (revision 18)
@@ -126,6 +126,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_murmur.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_murmur.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_murmur.cpp (revision 18)
@@ -75,6 +75,6 @@
             if (!InCombat)
             {
+                InCombat = true;
                 Aggro(who);
-                InCombat = true;
             }
         }
@@ -96,6 +96,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/burning_steppes/burning_steppes.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/burning_steppes/burning_steppes.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/burning_steppes/burning_steppes.cpp (revision 18)
@@ -62,6 +62,6 @@
                 if (!InCombat)
                 {
+                    InCombat = true;
                     Aggro(who);
-                    InCombat = true;
                 }
             }
Index: trunk/src/bindings/scripts/scripts/zone/karazhan/boss_prince_malchezaar.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/karazhan/boss_prince_malchezaar.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/karazhan/boss_prince_malchezaar.cpp (revision 18)
@@ -583,5 +583,5 @@
         {
             //Check for base attack
-            if( m_creature->isAttackReady())
+            if( m_creature->isAttackReady() && m_creature->getVictim() )
             {
                 m_creature->AttackerStateUpdate(m_creature->getVictim());
@@ -589,5 +589,5 @@
             }
             //Check for offhand attack
-            if( m_creature->isAttackReady(OFF_ATTACK))
+            if( m_creature->isAttackReady(OFF_ATTACK) && m_creature->getVictim() )
             {
                 m_creature->AttackerStateUpdate(m_creature->getVictim(), OFF_ATTACK);
Index: trunk/src/bindings/scripts/scripts/zone/molten_core/instance_molten_core.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/molten_core/instance_molten_core.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/molten_core/instance_molten_core.cpp (revision 18)
@@ -164,7 +164,4 @@
                     FlamewakerPriest = creature->GetGUID();
                     break;
-
-                default:
-                    return;
             }
         }
Index: trunk/src/bindings/scripts/scripts/zone/netherstorm/netherstorm.cpp
===================================================================
--- trunk/src/bindings/scripts/scripts/zone/netherstorm/netherstorm.cpp (revision 6)
+++ trunk/src/bindings/scripts/scripts/zone/netherstorm/netherstorm.cpp (revision 18)
@@ -265,6 +265,4 @@
                     ++Phase;
                     break;
-                default:
-                    break;
             }
         } else Event_Timer -= diff;
Index: trunk/src/bindings/scripts/docs/EventAI.txt
===================================================================
--- trunk/src/bindings/scripts/docs/EventAI.txt (revision 2)
+++ trunk/src/bindings/scripts/docs/EventAI.txt (revision 18)
@@ -680,4 +680,5 @@
 3       8           CAST_NO_MELEE_IF_OOM           Prevents creature from entering melee if out of mana or out of range
 4       16          CAST_FORCE_TARGET_SELF         Forces the target to cast this spell on itself
+5       32          CAST_AURA_NOT_PRESENT          Only casts the spell on the target if the target does not have the aura from that spell on itself already.
 
 NOTE: You can add the numbers in the decimal column to combine flags. 
