Browse Source

MMO-19086: 随从不受到怪物伤害,当玩家受到怪物伤害时,帮玩家分担N%的伤害

meijun 3 years ago
parent
commit
18bc83223d

+ 2 - 0
Common/CommonAI/Zone/Formula/IFormulas.cs

@@ -321,6 +321,8 @@ namespace CommonAI.Zone.Formula
 		InstanceUnit GetMasterUnit();
 		void StartRecoverMP(bool reset = false);
 		bool IsCanReduceMP(bool force);
+		/** 分发宠物为主人承担伤害事件 */
+		void DispatchShareMasterDmgEvent(int shareDmg, InstanceUnit sender);
 
 	   //获取玩家宠物接口
 		InstanceUnit GetPetUnit();

+ 22 - 7
Common/CommonAI/Zone/Instance/InstanceUnit.cs

@@ -1023,7 +1023,7 @@ namespace CommonAI.Zone.Instance
 		public int ReduceHP(int hp, InstanceUnit attacker, bool sendHit = true, UnitHitEvent hitMessage = null,
 			bool IngoreHealEffect = false, DamageSource dmgSrc = DamageSource.Def)
         {
-			//目标无敌,不扣血
+			//1.目标无敌,不扣血
             if (IsDead() || hp == 0 || ( hp > 0 && this.IsInvincible))
             {
                 return 0;
@@ -1044,12 +1044,27 @@ namespace CommonAI.Zone.Instance
 				this.Statistic.LogDamage(attacker.Statistic, hp);
 			}
 
-			//传递加血事件
-			if(hp < 0 && attacker != null)
-			{
-				int finalHP = hp;
-				attacker.Virtual.DispatchAddOtherHPEvent(-hp, this, out finalHP);
-				hp = -finalHP;
+			//2. 针对有发送者的伤害来源
+			if(attacker != null)
+			{				
+				if (hp < 0)
+				{
+					//2.1 传递加血事件
+					int finalHP = hp;
+					attacker.Virtual.DispatchAddOtherHPEvent(-hp, this, out finalHP);
+					hp = -finalHP;
+				}
+				else if(this.IsPlayer)
+				{
+					//2.2 如果为玩家,伤害来源存在且为怪物,宠物可以分担伤害
+					InstanceUnit petUnit = this.Virtual.GetPetUnit();
+					if(petUnit != null)
+					{
+						int petShareDmg = Math.Max(1, (int)(hp * XmdsConstConfig.PET_SHARE_MASTERDMG_RATIO));
+						hp = Math.Max(1, hp - petShareDmg);
+						petUnit.AddHP(-petShareDmg, this);
+					}
+				}
 			}
 			
             this.DoAddHP(-hp);

+ 9 - 6
Common/CommonAI/Zone/InstanceZoneFactory.Simple.cs

@@ -140,15 +140,18 @@ namespace CommonAI.Zone.Simple
 
     public class SimpleFormula : IFormula
     {
-        //----------------------------------------------------------------------------------------------
-
-        public class SimpleCFG : ICommonConfig
-        {
+		//----------------------------------------------------------------------------------------------
 
-        }
+		public class SimpleCFG : ICommonConfig
+		{
+			public void init()
+			{
+				
+			}
+		}
 
 
-        public class SimpleUnitProperties : IUnitProperties
+		public class SimpleUnitProperties : IUnitProperties
         {
             public SimpleUnitProperties()
             {

+ 5 - 1
Common/CommonAI/Zone/InstanceZoneFactory.cs

@@ -243,7 +243,11 @@ namespace CommonAI.Zone
     }
     //---------------------------------------------------------------------------------------------
 
-    public interface ICommonConfig { }
+    public interface ICommonConfig
+	{
+		void init();
+	}
+
     public interface IUnitProperties : ICloneable, IExternalizable { }
     public interface ISkillProperties : ICloneable, IExternalizable
     {

+ 1 - 0
Common/CommonAI/Zone/ZoneEditor/EditorTemplates.cs

@@ -231,6 +231,7 @@ namespace CommonAI.Zone.ZoneEditor
         {
             this.templates.CFG = LoadXmlAs<Config>(dir + "/config.xml", new Config());
             this.templates.ExtConfig = LoadXmlAs<ICommonConfig>(dir + "/config_ext.xml", TemplateManager.Factory.CreateCommonCFG());
+			this.templates.ExtConfig.init();
         }
 
         public string LoadResVersion()

+ 5 - 0
Common/CommonAI/data/XmdsConstConfig.cs

@@ -115,5 +115,10 @@ namespace CommonAI
 		//默认不受【击飞, 黑洞效果控制】影响的体重值。 (>=即可)
 		//攻击质量一般需要<=100(攻击力度  - 单位体重 > 0 才会才生受击效果)
 		public static readonly int DEFAULT_WEIGHT = 100;
+
+
+		//下面只是为了中转用的
+		public static float PET_SHARE_MASTERDMG_RATIO = 0.2f;       //宠物分担玩家伤害系数
+		public static float PET_HEALD_RATIO = 1.0f;
 	}
 }

+ 20 - 3
XmdsCommon/Plugin/XmdsConfig.cs

@@ -1,4 +1,5 @@
-using CommonAI.Data;
+using CommonAI;
+using CommonAI.Data;
 using CommonAI.Zone;
 using CommonLang;
 using CommonLang.Property;
@@ -129,16 +130,32 @@ namespace XmdsCommon.Plugin
 		[DescAttribute("出牌顺序", "卡牌系统")]
 		public List<CardType> CARD_GET_LIST = new List<CardType>();
 
+
+		[DescAttribute("宠物受道灵治疗系数(小数)", "宠物")]
+		public float PET_HEALD_RATIO = 1.0f;
+		[DescAttribute("宠物分担玩家伤害系数(小数)", "宠物")]
+		public float PET_SHARE_MASTERDMG_RATIO = 0.2f;
+
 		public override string ToString()
         {
             return "Xmds 配置扩展属性";
         }
         public static XmdsConfig Instance
         {
-            get;
+			get;
             private set;
         }
-        public XmdsConfig() { Instance = this; }
+        public XmdsConfig()
+		{
+			Instance = this;			
+		}
+
+		public void init()
+		{
+			//初始化CommAI配置
+			XmdsConstConfig.PET_HEALD_RATIO = PET_HEALD_RATIO;
+			XmdsConstConfig.PET_SHARE_MASTERDMG_RATIO = PET_SHARE_MASTERDMG_RATIO;
+		}
 
     }
 }

+ 1 - 1
XmdsCommonServer/Plugin/Scene/XmdsServerScene.cs

@@ -253,7 +253,7 @@ namespace XmdsCommonServer.Plugin.Scene
 				else if (target.IsPet)
 				{
 					// 攻击者是宠物或者非主人
-					if (src.IsPet || (src.IsPlayer && target.Virtual.GetMasterID() != src.ID))
+					//if (src.IsPet || (src.IsPlayer && target.Virtual.GetMasterID() != src.ID))
 					{
 						return false;
 					}

+ 3 - 0
XmdsCommonServer/Plugin/XmdsSkillTemplate/Skills/XmdsSkill.cs

@@ -493,6 +493,9 @@ namespace XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills
 	/// <param name="launcher"></param>
 	public delegate bool IAddOtherHPEvent(int hp, InstanceUnit sender, InstanceUnit hitter, out int finalHP);
 
+	//宠物承担主人伤害事件
+	public delegate bool IShareMasterDmgEvent(int hp, InstanceUnit sender, InstanceUnit unit);
+
 	//扣定力
 	public delegate bool IReduceOtherMpEvent(int mp, InstanceUnit sender, InstanceUnit hitter, out int finalMP, AttackSource source);
 	//得卡牌球

+ 57 - 1
XmdsCommonServer/Plugin/XmdsVirtual/XmdsVirtual.Event.cs

@@ -65,6 +65,8 @@ namespace XmdsCommonServer.Plugin
 
 		//加血事件
 		readonly private List<OnAddOtherHPEvnet> mAddOtherHPList = new List<OnAddOtherHPEvnet>();
+		//承担伤害监听
+		readonly private List<OnShareMasterDmgEvent> mShareMasterDmgList = new List<OnShareMasterDmgEvent>();
 		//扣定力
 		readonly private List<OnReduceOtherMpEvnet> mReduceMPList = new List<OnReduceOtherMpEvnet>();
 		//获得卡牌珠监听
@@ -281,6 +283,16 @@ namespace XmdsCommonServer.Plugin
 			}
 		}
 
+		protected class OnShareMasterDmgEvent : IHandle
+		{
+			public readonly IShareMasterDmgEvent m_hand;
+			public OnShareMasterDmgEvent(IShareMasterDmgEvent handler, GameSkill skill) : base(skill, true)
+			{
+				this.m_hand = handler;
+
+			}
+		}
+
 		class OnReduceOtherMpEvnet : IHandle
 		{
 			public readonly IReduceOtherMpEvent m_hand;
@@ -929,6 +941,32 @@ namespace XmdsCommonServer.Plugin
 			return ret;
 		}
 
+		public int RegistShareMasterDmgEvent(IShareMasterDmgEvent call, GameSkill gs)
+		{
+			OnShareMasterDmgEvent handle = new OnShareMasterDmgEvent(call, gs);
+			int ret = HandleUUIDCreate();
+			mShareMasterDmgList.Add(handle);
+			mHandleMap.Add(ret, handle);
+			return ret;
+		}
+
+		public bool UnRegistShareMasterDmgEvent(int handleUUID)
+		{
+			bool ret = false;
+			IHandle handle = null;
+
+			if (mHandleMap.TryGetValue(handleUUID, out handle))
+			{
+				if (handle != null && handle is OnShareMasterDmgEvent)
+				{
+					ret = mShareMasterDmgList.Remove(handle as OnShareMasterDmgEvent);
+					mHandleMap.Remove(handleUUID);
+				}
+			}
+
+			return ret;
+		}
+
 		public int RegistReduceMPEvent(IReduceOtherMpEvent call, GameSkill gs)
 		{
 			OnReduceOtherMpEvnet handle = new OnReduceOtherMpEvnet(call, gs);
@@ -1463,7 +1501,20 @@ namespace XmdsCommonServer.Plugin
 			}
 		}
 
-		
+		/** 分发宠物承担主人伤害事件 */
+		public void DispatchShareMasterDmgEvent(int shareDmg, InstanceUnit sender)
+		{
+			for (int i = mShareMasterDmgList.Count - 1; i >= 0; --i)
+			{
+				OnShareMasterDmgEvent hitend = mShareMasterDmgList[i];
+				if (hitend.m_hand.Invoke(shareDmg, sender, this.mUnit))
+				{
+					break;
+				}
+			}
+		}
+
+
 		/** 分发扣定力事件 */
 		public void DispatchAddMPEvent(int mp, InstanceUnit hitter, out int finalMP, AttackSource source)
 		{
@@ -1622,6 +1673,7 @@ namespace XmdsCommonServer.Plugin
 			this.mTryAddCardBallList.Clear();
 			this.mReduceMPList.Clear();
 			this.mTriggerCardSkillList.Clear();
+			this.mShareMasterDmgList.Clear();
 
 			mHandleUUID = 0;
         }
@@ -1742,6 +1794,10 @@ namespace XmdsCommonServer.Plugin
 				{
 					result = UnRegistTriggerCardSkillEvent(uuid);
 				}
+				else if(handle is OnShareMasterDmgEvent)
+				{
+					result = UnRegistShareMasterDmgEvent(uuid);
+				}
 				else
 				{
 					log.Error("RemoveEventByUUID not process type: " + handle);

+ 5 - 3
XmdsCommonServer/Plugin/XmdsVirtual/XmdsVirtual_Pet.cs

@@ -1,9 +1,11 @@
 using CommonAI.Data;
 using CommonAI.Zone.Instance;
+using System.Collections.Generic;
 using XmdsCommon.Message;
 using XmdsCommon.Plugin;
 using XmdsCommonServer.Message;
 using XmdsCommonServer.Plugin.Units;
+using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
 
 namespace XmdsCommonServer.Plugin
 {
@@ -23,7 +25,7 @@ namespace XmdsCommonServer.Plugin
         /// </summary>
         private XmdsVirtual_Player.ItemRecoveryTask mHPMPRecoveryTask = new XmdsVirtual_Player.ItemRecoveryTask();
 
-        private XmdsVirtual mMaster = null;
+		private XmdsVirtual mMaster = null;
 
 		public XmdsVirtual_Pet(XmdsInstancePet unit) : base(unit)
         {
@@ -369,7 +371,7 @@ namespace XmdsCommonServer.Plugin
                 mMaster = null;
             }
 
-            base.Dispose();
+			base.Dispose();
         }
 
         public override bool IsAttackable(XmdsVirtual attacker)
@@ -401,5 +403,5 @@ namespace XmdsCommonServer.Plugin
                 base.TeamMemberVisible = value;
             }
         }
-    }
+	}
 }