using CommonAI.Zone; using CommonAI.Zone.Instance; using CommonAI.Zone.Formula; using CommonAI.Zone.UnitTriggers; using CommonLang; using CommonLang.Log; using CommonLang.Property; using System; using System.Collections.Generic; using System.Linq; using System.Text; using XmdsCommon.Plugin; using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator; using CommonAI.Data; using XmdsCommonServer.XLS.Data; using XmdsCommonSkill.Plugin.CardSkill; using XmdsCommon.JSGModule.Interface; using XmdsCommonServer.Plugin.Base; using CommonAI.Zone.Helper; namespace XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills { #region Skill. public enum AbstractSkillType { Value1 = 0, // Value2 = 1, // Value3 = 2, // Value4 = 3, // } //技能老祖. public abstract class AbstractSkill : IComparable { public AbstractSkill() { } public abstract int SkillID { get; } public int CompareTo(AbstractSkill obj) { SkillTypeAttribute desc_a = PropertyUtil.GetAttribute(this.GetType()); SkillTypeAttribute desc_b = PropertyUtil.GetAttribute(obj.GetType()); int r0 = desc_a.Category.CompareTo(desc_b.Category); if (r0 != 0) { return r0; } return this.SkillID - obj.SkillID; } public abstract void SkillDataChange(GameSkill gs, XmdsVirtual unit); public abstract int GetSkillValue(AbstractSkillType type); /// /// 初始化完所有技能回调 /// public virtual void InitOver(XmdsVirtual unit, GameSkill info) { OnInitOver(unit, info); } protected virtual void OnInitOver(XmdsVirtual unit, GameSkill info) { } protected void InitData(XmdsSkillData data, out XmdsSkillValue v, XmdsSkillData.XmdsSkillDataKey key) { try { v = data.GetParamValue(key); } catch (Exception error) { XmdsBattleHelper.LogError(string.Format("Skill【{0}】InitSkillParam【{1}】 \r\nError:{2}", this.SkillID, key, error.ToString())); v = XmdsSkillValue.Default; } } //接口之前相互手动调用 public virtual void DoSkillDispose(int skillID) { } } //技能基类. public abstract class UnitSkill : AbstractSkill { protected static Logger log = LoggerFactory.GetLogger("XmdsBattleSkill"); //技能是否激活 private bool mIsActive = true; public bool IsActive{get{return this.mIsActive;} set{this.mIsActive = value;} } /// /// 初始化主动技能 /// public void Init(GameSkill info, XmdsVirtual unit, ref SkillTemplate template) { OnRegistEvent(); OnBaseInit(info, unit, ref template); //伤害监听. if (unit != null) { unit.RegistCalDamage(OnCallDamageProcess, info, false, this.SkillID); //技能MP消耗预判. unit.RegistTryLaunchSkillEvent(OnUnitLaunchSkillEvent, info, false); //技能MP消耗. unit.RegistLaunchSkillOver(OnUnitLaunchSkillOver, info, false); } } //只调用一次的初始化 public void InitSkillParam(XmdsSkillData skillData) { OnBaseDataInit(skillData); OnInitSkillParam(); } public override void SkillDataChange(GameSkill gs, XmdsVirtual unit) { OnSkillDataChange(gs, unit); } protected virtual void OnSkillDataChange(GameSkill gs, XmdsVirtual unit) { } protected virtual void OnBaseDataInit(XmdsSkillData skillData) { } protected virtual void OnInitSkillParam() { } // 每次加载技能都会调用。初始化配置,针对于人物技能多重继承 protected virtual void OnInitConfig() { } protected virtual void OnRegistEvent() { } protected virtual void OnBaseInit(GameSkill info, XmdsVirtual unit, ref SkillTemplate template) { } private int OnHitProcess(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, GameSkill gs, ref XmdsCommonServer.Plugin.XmdsVirtual.AtkResult result) { int ret = 0; //技能逻辑. return ret; } /// /// 计算伤害事件结果. /// /// /// /// /// /// /// public virtual bool OnCallDamageProcess(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, GameSkill gs, ref XmdsCommonServer.Plugin.XmdsVirtual.AtkResult result, ref int damage) { return true; } /// /// 技能施放预判断. /// /// /// /// protected virtual bool OnUnitLaunchSkillEvent(GameSkill info, ref InstanceUnit.SkillState skill, XmdsVirtual launcher, ref InstanceUnit.LaunchSkillParam param) { return true; } /// /// 技能施放完成监听. /// /// /// /// /// protected virtual int OnUnitLaunchSkillOver(GameSkill info, XmdsCommonServer.Plugin.XmdsVirtual attacker, CommonAI.Zone.Instance.InstanceUnit.SkillState state) { return 0; } /// /// 输出错误日志. /// /// protected virtual void LogError(string text = null) { if (text != null) { log.Error(string.Format("技能【{0}】配置错误:{1}", SkillID, text)); } else { log.Error(string.Format("技能【{0}】配置错误", SkillID)); } } public virtual bool SkillAutoLaunchTest(InstanceUnit.SkillState ss, XmdsVirtual launcher) { return true; } public void Update(int intervalMS, bool slowRefresh) { OnUpdate(intervalMS, slowRefresh); } protected virtual void OnUpdate(int intervalMS, bool slowRefresh) { } /// /// 技能被销毁. /// public virtual void Dispose() { } } #endregion #region PassiveSkills public abstract class UnitPassiveSkill : AbstractSkill { protected static Logger log = LoggerFactory.GetLogger("XmdsBattleSkill"); public void Init(GameSkill skillInfo, XmdsVirtual owner) { this.OnInitConfig(skillInfo); OnInit(skillInfo, owner); } //只调用一次的初始化 public void InitSkillParam() { OnInitSkillParam(); } protected virtual void OnInitSkillParam() { } // 每次加载技能都会调用。初始化配置,针对于人物技能多重继承 protected virtual void OnInitConfig(GameSkill skillInfo) { } public void Update(int intervalMS, bool slowRefresh) { OnUpdate(intervalMS, slowRefresh); } public void Dispose(XmdsVirtual owner) { OnDispose(owner); } protected virtual void OnDispose(XmdsVirtual owner) { } protected virtual void OnInit(GameSkill skillInfo, XmdsVirtual owner) { } protected virtual void OnUpdate(int intervalMS, bool slowRefresh) { } protected virtual void LogError(string text = null) { if (text != null) { log.Error(string.Format("被动技能【{0}】配置错误:{1}", SkillID, text)); } else { log.Error(string.Format("被动技能【{0}】配置错误", SkillID)); } } public virtual bool ValidParameter(int lv, float[] formula) { bool ret = false; if (lv > formula.Length || lv <= 0) { ret = false; LogError(); } else { ret = true; } return ret; } public virtual int GetCDTotalTime() { return 0; } public virtual int GetCDPassTime() { return 0; } public virtual void SetCDPassTime(int timeMS) { } public virtual int GetDecreaseTotalTimeMS() { return 0; } public virtual void SetDecreaseTotalTimeMS(int timeMS) { } public override void SkillDataChange(GameSkill gs, XmdsVirtual unit) { OnSkillDataChange(gs, unit); } protected virtual void OnSkillDataChange(GameSkill gs, XmdsVirtual unit) { } } #endregion #region BUFF. /// /// BUFF基类. /// public abstract class UnitBuff : XmdsBuffVirtual { //buff等级. private int mBuffLv = 0; //绑定编辑器BUFF. protected int BindBuffID = 0; /// /// 是否无效. /// protected bool mInvalid = false; /// /// 能力ID(决定buff作用.) /// public abstract int GetAbilityID(); /// /// BUFF等级. /// public virtual int BuffLV { set { mBuffLv = value; } get { return mBuffLv; } } public int GetBindBuffID() { return this.BindBuffID; } protected virtual void OnBindTemplate(ref BuffTemplate buffTemplate) { } //重载BUFF模板,修改属性. public void OverrideTemplate(ref BuffTemplate buffTemplate) { BindBuffID = buffTemplate.ID; (buffTemplate.Properties as XmdsBuffProperties).addBuffVirtual(this); OnBindTemplate(ref buffTemplate); } public virtual void BuffBegin(XmdsVirtual hitter, XmdsVirtual attacker, InstanceUnit.BuffState state) { } public virtual void BuffEnd(XmdsVirtual hitter, InstanceUnit.BuffState state, bool replace) { } public virtual int BuffHit(XmdsVirtual hitter, XmdsVirtual attacker, AttackSource source, ref XmdsVirtual.AtkResult result) { return 0; } /// /// 是否有 /// /// public bool IsInvaild() { return mInvalid; } public virtual void CopyTo(UnitBuff other) { other.BindBuffID = this.BindBuffID; other.mBuffLv = this.mBuffLv; } public virtual void BuffUpdate(XmdsVirtual unit, InstanceUnit.BuffState state) { } } #endregion #region 事件监听. //监听事件. /// /// 产生伤害监听. /// public delegate float IOnHit(float damage, XmdsVirtual hitted, XmdsVirtual attacker, AttackSource source, ref XmdsVirtual.AtkResult result, DamageType damageType, GameSkill skill, ref bool isEndDispatch); /// /// 被动触发监听 /// public delegate void IOnTriggerStart(XmdsVirtual unit, XmdsVirtual target, UnitTriggerTemplate trigger, GameSkill sk); /// /// 测试Buff监听. /// public delegate void IOnBuffEvent(XmdsVirtual unit, InstanceUnit.BuffState buff, string result, GameSkill sk); /// /// 测试技能监听. /// public delegate bool ITestLaunchSkill(XmdsVirtual unit, InstanceUnit.SkillState skill, GameSkill sk); /// ///伤害计算监听. /// /// /// /// /// public delegate bool ICalDamage(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, GameSkill gs, ref XmdsCommonServer.Plugin.XmdsVirtual.AtkResult result, ref int damage); /// ///仇恨计算监听. /// /// /// /// /// public delegate void ICalThreadValue(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, GameSkill gs, ref XmdsCommonServer.Plugin.XmdsVirtual.AtkResult result); /// /// 技能释放完毕. /// /// /// /// public delegate int ILaunchSkillOver(GameSkill info, XmdsVirtual attacker, CommonAI.Zone.Instance.InstanceUnit.SkillState state); /// /// 测试攻击目标监听. /// /// /// /// public delegate XmdsVirtual IGetAtkTarget(XmdsVirtual target, GameSkill sk); public delegate void IGetSkillDamageInfo(XmdsVirtual attacker, XmdsVirtual hitter, ref AttackSource source, GameSkill gs); /// /// 技能结束监听. /// /// /// public delegate void IStateSkillEnd(XmdsVirtual owner, InstanceUnit.StateSkill state, GameSkill gs); /// /// 添加buff监听. /// /// /// /// public delegate bool ITryAddBuffEvent(ref BuffTemplate buff, XmdsVirtual attacker, XmdsVirtual hitter, GameSkill skill); public delegate bool IRemoveBuffEvent(ref BuffTemplate buff, XmdsVirtual player, BuffRemoveType type); /** 给其他玩家添加buff监听. */ public delegate void ISendBuffEvent(BuffTemplate buff, XmdsVirtual attacker, XmdsVirtual hitter); /// /// 重定向Spell监听. /// /// /// public delegate void ITrySendSpellEvent(GameSkill skill, XmdsVirtual launcher, LaunchSpell launch, ref SpellTemplate spell, ref JSGCreateSpellData createData, ref float startX, ref float startY); //法术释放完毕 public delegate void ISendSpellOverEvent(LaunchSpell launch, XmdsVirtual launcher, SpellTemplate spell, GameSkill skill, float startX, float startY); /// /// 监听施放技能. /// /// /// public delegate bool ITryLaunchSkillEvent(GameSkill skillInfo, ref InstanceUnit.SkillState skill, XmdsVirtual launcher, ref InstanceUnit.LaunchSkillParam param); /// /// 触发宠物提供给人物的技能能力 /// 返回true,结束下层传递 /// /// /// public delegate bool ITriggerPetSkillEvent(GameSkill skillInfo, ref InstanceUnit.SkillState skill, XmdsVirtual launcher, ref InstanceUnit.LaunchSkillParam param); /// /// 技能被打断事件通知 /// /// /// /// public delegate bool ISkillBlockEvent(XmdsVirtual launcher, InstanceUnit.StateSkill skill, InstanceUnit.State newState); /** * hp < 0加血事件, sender: 发送者,hitter:被加血的人 * hp > =0扣血, sender:攻击者,hitter: 要扣血的 * */ public delegate bool IAddOtherHPEvent(int hp, InstanceUnit sender, InstanceUnit hitter, AttackSource source, out int finalHP); //宠物承担主人伤害事件 public delegate int IShareMasterDmgEvent(int hp, InstanceUnit sender, InstanceUnit unit, GameSkill info, ref bool isEndDispatch); //扣定力 public delegate bool IReduceOtherMpEvent(int mp, InstanceUnit sender, InstanceUnit hitter, out int finalMP, AttackSource source); //得卡牌球 public delegate bool ITryAddCardBallEvent(XmdsVirtual player, CreateCardBallSource type, CardType cardType); //释放卡牌技能 public delegate bool ITriggerCardSkillEvent(XmdsVirtual player, XmdsVirtual hitter, GameSkill info, CardType cardType, int sameNums); public delegate bool IOnKillOtherUnitEvent(XmdsVirtual attacker, XmdsVirtual deader, GameSkill info); #endregion #region 战斗特殊事件. #endregion }