public virtual void Destroy() { Clear(); for (int i = 0; i < mRunningScriptEffects.Count; ++i) { mRunningScriptEffects[i].Clear(Owner); } mRunningScriptEffects.Clear(); if (mOnUnitWillDieHandle != null) { mOnUnitWillDieHandle.Dispose(); mOnUnitWillDieHandle = null; BuffManager.UnregisterUnitWillDie(this); } if (mOnUnitBeSlayedHandle != null) { mOnUnitBeSlayedHandle.Dispose(); mOnUnitBeSlayedHandle = null; BuffManager.UnregisterUnitBeSlayed(this); } if (mOnUnitBeSummonedHandle != null) { mOnUnitBeSummonedHandle.Dispose(); mOnUnitBeSummonedHandle = null; BuffManager.UnregisterUnitBeSummoned(this); } if (mOnUnitWillHurtHandle != null) { mOnUnitWillHurtHandle.Dispose(); mOnUnitWillHurtHandle = null; BuffManager.UnregisterUnitWillHurt(this); } if (mOnUnitBeHurtedHandle != null) { mOnUnitBeHurtedHandle.Dispose(); mOnUnitBeHurtedHandle = null; BuffManager.UnregisterUnitBeHurted(this); } if (mOnUnitWillHealHandle != null) { mOnUnitWillHealHandle.Dispose(); mOnUnitWillHealHandle = null; BuffManager.UnregisterUnitWillHeal(this); } if (mOnUnitBeHealedHandle != null) { mOnUnitBeHealedHandle.Dispose(); mOnUnitBeHealedHandle = null; BuffManager.UnregisterUnitBeHealed(this); } if (mOnUnitCastSpellHandle != null) { mOnUnitCastSpellHandle.Dispose(); mOnUnitCastSpellHandle = null; BuffManager.UnregisterUnitCastSpell(this); } if (mOnSpellHitHandle != null) { mOnSpellHitHandle.Dispose(); mOnSpellHitHandle = null; BuffManager.UnregisterSpellHit(this); } }
public Buff(int templateID, UnitBase owner, UnitBase caster) { this.mTemplateID = templateID; this.Owner = owner; this.Caster = caster; this.ID = id; mPauseCount = 0; var config = ConfigManager.Buff.getRow(templateID); bool isScriptBuff = config.isScriptBuff; //是否有脚本 this.Groups = config.Groups; this.mRejectionGroups = config.RejectionGroups; this.OverlayTactics = config.OverlayTactics; this.Desc = config.Desc; this.Delay = config.Delay; this.isLoop = config.isLoop; this.mCfgDuration = config.Duration; this.isIndividual = config.isIndividual; this.isClearable = config.isClearable; this.isNegative = config.isNegative; if (config.BuffEffect != null) { this.mEffects = new BuffEffect[config.BuffEffect.Length]; } else { this.mEffects = new BuffEffect[0]; } for (int i = 0; i < this.mEffects.Length; ++i) { this.mEffects[i] = new BuffEffect(config.BuffEffect[i]); } if (isScriptBuff) { var lua = LuaInterface.Singleton.GetLuaState(); LuaTable buff = lua.Require <LuaTable>(string.Format("buff/buff{0}", templateID)); if (buff == null) { Debug.LogErrorFormat("load buff/buff{0}.lua failed!", templateID); } else { LuaFunction newFunc = buff["new"] as LuaFunction; newFunc.BeginPCall(); newFunc.PCall(); mLuaBuff = (LuaTable)newFunc.CheckLuaTable(); newFunc.EndPCall(); LuaFunction init = mLuaBuff["init"] as LuaFunction; if (init != null) { init.BeginPCall(); init.Push(mLuaBuff); init.Push(id); init.Push(templateID); init.Push(owner); init.Push(caster); init.PCall(); init.EndPCall(); } else { Debug.LogErrorFormat("buff/buff{0}.lua dont find init function !", templateID); } mOnUnitWillDieHandle = mLuaBuff["OnUnitWillDie"] as LuaFunction; if (mOnUnitWillDieHandle != null) { BuffManager.RegisterUnitWillDie(this); } mOnUnitBeSlayedHandle = mLuaBuff["OnUnitBeSlayed"] as LuaFunction; if (mOnUnitBeSlayedHandle != null) { BuffManager.RegisterUnitBeSlayed(this); } mOnUnitBeSummonedHandle = mLuaBuff["OnUnitBeSummoned"] as LuaFunction; if (mOnUnitBeSummonedHandle != null) { BuffManager.RegisterUnitBeSummoned(this); } mOnUnitWillHurtHandle = mLuaBuff["OnUnitWillHurt"] as LuaFunction; if (mOnUnitWillHurtHandle != null) { BuffManager.RegisterUnitWillHurt(this); } mOnUnitBeHurtedHandle = mLuaBuff["OnUnitBeHurted"] as LuaFunction; if (mOnUnitBeHurtedHandle != null) { BuffManager.RegisterUnitBeHurted(this); } mOnUnitWillHealHandle = mLuaBuff["OnUnitWillHeal"] as LuaFunction; if (mOnUnitWillHealHandle != null) { BuffManager.RegisterUnitWillHeal(this); } mOnUnitBeHealedHandle = mLuaBuff["OnUnitBeHealed"] as LuaFunction; if (mOnUnitBeHealedHandle != null) { BuffManager.RegisterUnitBeHealed(this); } mOnUnitCastSpellHandle = mLuaBuff["OnUnitCastSpell"] as LuaFunction; if (mOnUnitCastSpellHandle != null) { BuffManager.RegisterUnitCastSpell(this); } mOnSpellHitHandle = mLuaBuff["OnSpellHit"] as LuaFunction; if (mOnSpellHitHandle != null) { BuffManager.RegisterSpellHit(this); } } } this.Duration = this.mCfgDuration; this.mDelay = this.Delay; if (mDelay == 0) { Apply(); } mElapseTime = 0; }