All pastes #911452 Raw Edit

Someone

public text v1 · immutable
·published 2008-02-20 18:38 UTC
rendered paste body
Index: src/framework/Utilities/EventProcessor.h
===================================================================
--- src/framework/Utilities/EventProcessor.h	(revision 5258)
+++ src/framework/Utilities/EventProcessor.h	(working copy)
@@ -60,6 +60,15 @@
         void KillAllEvents();
         void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true);
         uint64 CalculateTime(uint64 t_offset);
+
+        template<class Check>
+        bool check(Check& check) const
+        {
+            for(EventList::const_iterator itr = m_events.begin(); itr != m_events.end(); ++itr)
+                if(check(itr->second))
+                    return true;
+            return false;
+        }
     protected:
         uint64 m_time;
         EventList m_events;
Index: src/game/Spell.cpp
===================================================================
--- src/game/Spell.cpp	(revision 5264)
+++ src/game/Spell.cpp	(working copy)
@@ -59,6 +59,21 @@
         && spellproto->Effect[1] == SPELL_EFFECT_APPLY_AURA && spellproto->EffectApplyAuraName[1] == SPELL_AURA_DUMMY;
 }
 
+struct SpellCastItemCheck
+{
+    explicit SpellCastItemCheck(Spell* spell) : i_spell(spell) {}
+
+    Spell const* i_spell;
+
+    bool operator() (BasicEvent const* event) const
+    {
+        if(SpellEvent const* spellEvent = dynamic_cast<SpellEvent const*>(event))
+            return spellEvent->GetSpell() != i_spell && spellEvent->GetSpell()->m_CastItem==i_spell->m_CastItem;
+        else
+            return false;
+    }
+};
+
 SpellCastTargets::SpellCastTargets()
 {
     m_unitTarget = NULL;
@@ -3618,6 +3633,11 @@
             if(!proto)
                 return SPELL_FAILED_ITEM_NOT_READY;
 
+            SpellCastItemCheck check(this);
+
+            if(p_caster->m_Events.check(check))             // fail if item already used in delayed spell
+                return SPELL_FAILED_ITEM_NOT_READY;
+
             for (int i = 0; i<5; i++)
             {
                 if (proto->Spells[i].SpellCharges)
Index: src/game/Spell.h
===================================================================
--- src/game/Spell.h	(revision 5258)
+++ src/game/Spell.h	(working copy)
@@ -832,6 +832,8 @@
 
         virtual bool Execute(uint64 e_time, uint32 p_time);
         virtual void Abort(uint64 e_time);
+
+        Spell* GetSpell() const { return m_Spell; }
     protected:
         Spell* m_Spell;
 };