You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			207 lines
		
	
	
		
			8.2 KiB
		
	
	
	
		
			C#
		
	
		
		
			
		
	
	
			207 lines
		
	
	
		
			8.2 KiB
		
	
	
	
		
			C#
		
	
| 
											2 years ago
										 | using Entitas; | ||
|  | using Game; | ||
|  | using System; | ||
|  | using System.Collections.Generic; | ||
|  | 
 | ||
|  | namespace Game | ||
|  | { | ||
|  |     //连招输入数据 | ||
|  |     public class ComboInputRecord | ||
|  |     { | ||
|  |         public PPlayerInput InputInfo; | ||
|  |         public float TimeRecord; | ||
|  |         public bool CancelIgore; | ||
|  |         public bool Active; | ||
|  |     } | ||
|  |     //武器携带的技能数据 | ||
|  |     public class WeaponSkill | ||
|  |     { | ||
|  |         public Dictionary<Tuple<EComboStance, EComboTriggerType>, string> SkillDict = new Dictionary<Tuple<EComboStance, EComboTriggerType>, string>(); | ||
|  |         public Dictionary<EComboTriggerType, string> SkillAnyDict = new Dictionary<EComboTriggerType, string>(); | ||
|  |         public HashSet<string> SkillSet = new HashSet<string>(); | ||
|  |     } | ||
|  | } | ||
|  | [Game] | ||
|  | public class ComboComponent : IComponent | ||
|  | { | ||
|  |     public List<string> WeaponList = new List<string>(); //武器列表 | ||
|  |     public MetaData<int> WeaponNow = new MetaData<int>();//当前武器下标 | ||
|  |     public Dictionary<string, WeaponSkill> WeaponSkillDict = new Dictionary<string, WeaponSkill>();//武器技能 | ||
|  |     public EComboStance Stance;         //当前真正的姿态,进入后摇后更新 | ||
|  |     public EComboStance PreStance;      //当前技能的后摇姿态,释放技能时更新 | ||
|  |     public List<ComboInputRecord> InputQueue = new List<ComboInputRecord>();//指令缓存 | ||
|  |     public float TriggerCancelSafeTime = 0; //清除cache的保护时间 | ||
|  |     public HashSet<EFunctionKey> KeyPressSet = new HashSet<EFunctionKey>(); //按下状态的按键 | ||
|  |     public EMoveCommand MoveCommand = EMoveCommand.Stop;    //移动指令 技能释放时会根据最新的移动指令调整方向 | ||
|  |     public bool IsJumpCancelable = false;       //当前技能是否能通过跳跃取消 | ||
|  |     public bool IsGroundCancelable = false;     //当前技能是否能通过落地取消 | ||
|  |     public bool IsSkillCancelable = false;       //当前技能是否能通过其他技能取消 | ||
|  | 
 | ||
|  |     public int TargetLock = 0;                  //锁定的目标id 0为当前无目标 -1为当前范围内找不到目标 | ||
|  |     public Dictionary<int, float> TargetLastLockTime = new Dictionary<int, float>();   //距离目标上次锁定的时间 一段时间内无法重复锁定相同目标以便切换目标 | ||
|  |     public MetaData<int> TargetInteract = new MetaData<int>();              //交互的目标id 0为当前无目标 | ||
|  | 
 | ||
|  | } | ||
|  | 
 | ||
|  | namespace Game | ||
|  | { | ||
|  |     public abstract partial class Util | ||
|  |     { | ||
|  |         public static bool HasSkill(GameEntity entity, string skillId) | ||
|  |         { | ||
|  |             var weaponSkill = GetWeaponSkillBySkillId(entity, skillId); | ||
|  |             if (weaponSkill == null) | ||
|  |             { | ||
|  |                 return false; | ||
|  |             } | ||
|  |             return weaponSkill.SkillSet.Contains(skillId); | ||
|  |         } | ||
|  |         public static void AddSkillAll(GameEntity entity) | ||
|  |         { | ||
|  |             var skillCfgDatas = Util.GetSkillMasterConfigDataAll(); | ||
|  |             foreach (var skillCfgData in skillCfgDatas) | ||
|  |             { | ||
|  |                 AddSkill(entity, skillCfgData.TechnicalName); | ||
|  |             } | ||
|  |         } | ||
|  |         public static void AddSkill(GameEntity entity, string skillId) | ||
|  |         { | ||
|  |             var weaponSkill = GetWeaponSkillBySkillId(entity, skillId); | ||
|  |             if (weaponSkill == null) | ||
|  |             { | ||
|  |                 return; | ||
|  |             } | ||
|  |             if (weaponSkill.SkillSet.Contains(skillId)) | ||
|  |             { | ||
|  |                 return; | ||
|  |             } | ||
|  |             weaponSkill.SkillSet.Add(skillId); | ||
|  | 
 | ||
|  |             var skillCfg = Util.GetSkillMasterConfig(skillId); | ||
|  |             var stance = (EComboStance)skillCfg.SkillCombo.StanceStart; | ||
|  |             var triggerType = (EComboTriggerType)skillCfg.SkillCombo.TriggerType; | ||
|  | 
 | ||
|  |             if (stance == EComboStance.Any) | ||
|  |             { | ||
|  |                 //顶替 | ||
|  |                 if (weaponSkill.SkillAnyDict.ContainsKey(triggerType)) | ||
|  |                 { | ||
|  |                     RemoveSkill(entity, weaponSkill.SkillAnyDict[triggerType]); | ||
|  |                 } | ||
|  |                 weaponSkill.SkillAnyDict.Add(triggerType, skillId); | ||
|  |             } | ||
|  |             else | ||
|  |             { | ||
|  |                 var skillKey = new Tuple<EComboStance, EComboTriggerType>(stance, triggerType); | ||
|  |                 //顶替 | ||
|  |                 if (weaponSkill.SkillDict.ContainsKey(skillKey)) | ||
|  |                 { | ||
|  |                     RemoveSkill(entity, weaponSkill.SkillDict[skillKey]); | ||
|  |                 } | ||
|  |                 weaponSkill.SkillDict.Add(skillKey, skillId); | ||
|  |             } | ||
|  |         } | ||
|  |         public static void RemoveSkill(GameEntity entity, string skillId) | ||
|  |         { | ||
|  |             var weaponSkill = GetWeaponSkillBySkillId(entity, skillId); | ||
|  |             if (weaponSkill == null) | ||
|  |             { | ||
|  |                 return; | ||
|  |             } | ||
|  |             if (!weaponSkill.SkillSet.Contains(skillId)) | ||
|  |             { | ||
|  |                 return; | ||
|  |             } | ||
|  |             weaponSkill.SkillSet.Remove(skillId); | ||
|  |             foreach (var item in weaponSkill.SkillDict) | ||
|  |             { | ||
|  |                 if (item.Value == skillId) | ||
|  |                 { | ||
|  |                     weaponSkill.SkillDict.Remove(item.Key); | ||
|  |                     break;//原则上只有一个 | ||
|  |                 } | ||
|  |             } | ||
|  |             foreach (var item in weaponSkill.SkillAnyDict) | ||
|  |             { | ||
|  |                 if (item.Value == skillId) | ||
|  |                 { | ||
|  |                     weaponSkill.SkillAnyDict.Remove(item.Key); | ||
|  |                     break;//原则上只有一个 | ||
|  |                 } | ||
|  |             } | ||
|  | 
 | ||
|  |         } | ||
|  |         public static WeaponSkill GetWeaponSkillBySkillId(GameEntity entity, string skillId) | ||
|  |         { | ||
|  |             var combo = entity.combo; | ||
|  |             var skillCfg = Util.GetSkillMasterConfig(skillId); | ||
|  |             var weaponId = skillCfg.SkillCombo.Weapon.TechnicalName; | ||
|  |             if (combo.WeaponSkillDict.ContainsKey(weaponId)) | ||
|  |             { | ||
|  |                 return combo.WeaponSkillDict[weaponId]; | ||
|  |             } | ||
|  |             return null; | ||
|  |         } | ||
|  |         public static WeaponSkill GetWeaponSkillNow(GameEntity entity) | ||
|  |         { | ||
|  |             var combo = entity.combo; | ||
|  |             return combo.WeaponSkillDict[combo.WeaponList[combo.WeaponNow.Value]]; | ||
|  |         } | ||
|  |         public static bool HasComboAny(GameEntity entity, EComboTriggerType triggerType) | ||
|  |         { | ||
|  |             var combo = entity.combo; | ||
|  |             var weaponSkill = GetWeaponSkillNow(entity); | ||
|  |             return weaponSkill.SkillAnyDict.ContainsKey(triggerType); | ||
|  |         } | ||
|  |         public static string GetComboAny(GameEntity entity, EComboTriggerType triggerType) | ||
|  |         { | ||
|  |             var combo = entity.combo; | ||
|  |             var weaponSkill = GetWeaponSkillNow(entity); | ||
|  |             return weaponSkill.SkillAnyDict[triggerType]; | ||
|  |         } | ||
|  |         public static bool HasCombo(GameEntity entity, Tuple<EComboStance, EComboTriggerType> skillKey) | ||
|  |         { | ||
|  |             var combo = entity.combo; | ||
|  |             var weaponSkill = GetWeaponSkillNow(entity); | ||
|  |             return weaponSkill.SkillDict.ContainsKey(skillKey); | ||
|  |         } | ||
|  |         public static string GetCombo(GameEntity entity, Tuple<EComboStance, EComboTriggerType> skillKey) | ||
|  |         { | ||
|  |             var combo = entity.combo; | ||
|  |             var weaponSkill = GetWeaponSkillNow(entity); | ||
|  |             return weaponSkill.SkillDict[skillKey]; | ||
|  |         } | ||
|  | 
 | ||
|  |         public static void SetWeaponList(GameEntity entity, List<string> weaponList) | ||
|  |         { | ||
|  |             var combo = entity.combo; | ||
|  |             combo.WeaponList = weaponList; | ||
|  |             combo.WeaponNow.Value = 0; | ||
|  |             foreach (var item in weaponList) | ||
|  |             { | ||
|  |                 combo.WeaponSkillDict[item] = new WeaponSkill(); | ||
|  |             } | ||
|  |         } | ||
|  |         public static void SetWeaponListAll(GameEntity entity) | ||
|  |         { | ||
|  |             var weaponCfgDatas = Util.GetWeaponConfigDataAll(); | ||
|  |             var weaponIdList = new List<string>(); | ||
|  |             foreach (var weaponCfgData in weaponCfgDatas) | ||
|  |             { | ||
|  |                 weaponIdList.Add(weaponCfgData.TechnicalName); | ||
|  |             } | ||
|  |             SetWeaponList(entity, weaponIdList); | ||
|  |         } | ||
|  | 
 | ||
|  | 
 | ||
|  |         public static void ClearCombo(GameEntity entity) | ||
|  |         { | ||
|  |             entity.combo.Stance = EComboStance.Idle; | ||
|  |             entity.combo.PreStance = EComboStance.Idle; | ||
|  |             entity.combo.MoveCommand = EMoveCommand.Stop; | ||
|  |             entity.combo.WeaponSkillDict.Clear(); | ||
|  |             entity.combo.InputQueue.Clear(); | ||
|  |             entity.combo.KeyPressSet.Clear(); | ||
|  |         } | ||
|  |     } | ||
|  | } |