/// <summary> /// 选择目标方法:在攻击的时候,选择{什么范围中的敌人作为}攻击的目标 /// </summary> /// <param name="skillData">技能对象</param> /// <param name="skillOwner">技能拥有者的transform</param> /// <returns>选中的目标</returns> public GameObject[] SelectTarget(SkillData skillData, SkillDeployer skillDeployer) { List <GameObject> list = new List <GameObject>(); // 1 添加技能影响范围的目标 list.AddRange(skillDeployer.enterTrigger.EnterObjs); if (list.Count <= 0) { Debug.LogError("圆形攻击目标为0"); return(null); } Transform depTf = skillDeployer.transform; // 2 从所有攻击目标中 找出攻击范围中活着的敌人 list = list.FindAll(go => Vector3.Distance(go.transform.position, depTf.position) < skillData.attackDistance && go.GetComponent <CharacterStatus>().chBase.HP > 0); if (null == list || list.Count <= 0) { return(null); } // 3 根据释放的技能,选择一个或多个敌人 switch (skillData.attackType) { case SkillAttackType.Single: GameObject obj = ArrayHelper.Min(list.ToArray(), go => Vector3.Distance(go.transform.position, depTf.position)); return(new GameObject[] { obj }); case SkillAttackType.Group: return(list.ToArray()); default: YellowEvents.SendEvent(YellowEventName.error, YellowErrorText.notSkillType); return(null); } }
private IEnumerator RepeatDamage(SkillDeployer deployer, SkillData skillData) { float attackTime = 0; do { // 1 对多个目标执行伤害 if (skillData.attackTargets != null && skillData.attackTargets.Length > 0) { for (int i = 0; i < skillData.attackTargets.Length; i++) { OnceDamage(skillData, skillData.attackTargets[i]); } } // 2 等待一个伤害间隔 yield return(new WaitForSeconds(skillData.damageInterval)); attackTime = attackTime + skillData.damageInterval; // ! 那么 damageInterval 不能为0 if (skillData.damageInterval <= 0) { YellowEvents.SendEvent(YellowEventName.error, YellowErrorText.errorSkilldamageInterval + skillData.name); skillData.damageInterval = 0.1f; } // 3 攻击完一次后,重新选取目标 skillData.attackTargets = deployer.ResetTargets(); } while (attackTime <= skillData.durationTime); }
public void TargerImpact(SkillDeployer deployer, SkillData skillData, GameObject goSelf) { if (skillData.Owner != null && skillData.Owner.gameObject != null) { baseDamage = skillData.Owner.GetComponent <CharacterStatus>().Damage; } deployer.StartCoroutine(RepeatDamage(deployer, skillData)); }
private void OnceDamage(SkillDeployer deployer) { for (int i = 0; i < deployer.CurrentSkillData.attackTargets.Length; i++) { deployer.CurrentSkillData.attackTargets[i].GetComponent <CharacterStatus>().Damage(deployer.CurrentSkillData.owner.GetComponent <CharacterStatus>().baseATK *deployer.CurrentSkillData.atkRatio); } //单次伤害 //遍历被攻击的目标 data.attackTargets,调用受伤方法。 // }
/// <summary> /// 影响自身方法 /// </summary> /// <param name="deployer">技能释放器</param> /// <param name="skillData">技能数据对象</param> /// <param name="goSelf">自身或队友对象</param> /// //private PlayerStatus playerStatus; public void SelfImpact(SkillDeployer deployer, SkillData skillData, GameObject goSelf) { if (skillData.Owner == null) { return; } var chStatus = skillData.Owner.GetComponent <CharacterStatus>(); chStatus.SP -= skillData.costSP; }
/// 影响目标的操作【方法】 /// <param name="deployer">技能施放器</param> /// <param name="skillData">技能数据对象</param> /// <param name="goSelf">目标对象</param> public void TargetImpact(SkillDeployer deployer, SkillData skillData, GameObject goTarget) { //获取技能拥有者的基础伤害 if (skillData.Owner != null && skillData.Owner.gameObject != null) { baseDamage = skillData.Owner. GetComponent <CharacterStatus>().Damage; } //执行伤害 deployer.StartCoroutine(RepeatDamage(deployer, skillData)); }
private IEnumerator RepeatDamage(SkillDeployer deployer) { float atkTime = 0; do { OnceDamage(deployer); yield return(new WaitForSeconds(deployer.CurrentSkillData.atkInterval - Time.deltaTime)); atkTime += (deployer.CurrentSkillData.atkInterval - Time.deltaTime); deployer.CalculateTargets(); } while (atkTime < deployer.CurrentSkillData.durationTime); }
/// <summary> /// 重复攻击 /// </summary> /// <returns></returns> private IEnumerator RepeatAttack(SkillDeployer deployer) { float atkTime = 0; do { if (deployer.CurrentSkillData.attackTargets != null) { Attack(deployer.CurrentSkillData); } yield return(new WaitForSeconds(deployer.CurrentSkillData.atkInterval)); atkTime += deployer.CurrentSkillData.atkInterval; //再次计算攻击目标 deployer.CalculateTargets(); } while (atkTime < deployer.CurrentSkillData.durationTime); }
//生成技能 public void GenerateSkill(SkillData data) { //GameObject skillG0 = Instantiate(data.skillPrefab,transform.position,transform.rotation); GameObject skillG0 = GameObjectPool.Instance.CreateObject(data.prefabName, data.skillPrefab, transform.position, transform.rotation); GameObjectPool.Instance.CollectObjectSeconds(skillG0, data.durationTime); //传递技能数据 SkillDeployer deployer = skillG0.GetComponent <SkillDeployer>(); //赋值初始化准备技能算法 deployer.CurrentSkillData = data; //开始执行算法 deployer.DeployerSkill(); //Destroy(skillG0, data.durationTime); //开启冷却 StartCoroutine(CoolTimeDown(data)); }
//重复伤害 private IEnumerator RepeatDamage(SkillDeployer deploy, SkillData skill) { float attackTime = 0; do { if (skill.attackTargets != null && skill.attackTargets.Length > 0) { //对多个 目标执行伤害 for (int i = 0; i < skill.attackTargets.Length; i++) { OnceDamage(skill, skill.attackTargets[i]);//** } } //间隔一个时间,再次执行伤害 yield return(new WaitForSeconds(skill.damageInterval)); attackTime += skill.damageInterval;//!! durationTime不是0, //damageInterval也不能为0 //攻击一次之后,要重新选取目标 skill.attackTargets = deploy.ResetTarget(); //先去实现施放器的 方法,再完成这里 }while(attackTime < skill.durationTime); //!!防止死循环 }
//多次伤害 private IEnumerator RepeatDamage(SkillDeployer deployer, SkillData skillData) { float attackTime = 0; do { if (skillData.attackTargets != null && skillData.attackTargets.Length != 0) { //对目标执行伤害 for (int i = 0; i < skillData.attackTargets.Length; i++) { OnceDamage(skillData, skillData.attackTargets[i]); } } yield return(new WaitForSeconds(skillData.damageInterval)); attackTime += skillData.damageInterval; //攻击一次要重置目标 skillData.attackTargets = deployer.ResetTargets(); } while (attackTime < skillData.durationTime); //防止死循环 }
public void TargetImpact(SkillDeployer deployer, SkillData skillData, GameObject targetGo) { // 2 执行伤害 deployer.StartCoroutine(RepeatDamage(deployer, skillData)); }
public void Excute(SkillDeployer deployer) { deployer.StartCoroutine(RepeatDamage(deployer)); }
public void DoImpact(SkillDeployer deployer) { var chState = deployer.CurrentSkillData.owner.GetComponent <CharacterStatus>(); chState.SP -= deployer.CurrentSkillData.costSP; }
public void DoImpact(SkillDeployer deployer) { //攻击 deployer.StartCoroutine(RepeatAttack(deployer)); }
public void Excute(SkillDeployer deployer) { deployer.CurrentSkillData.owner.GetComponent <CharacterStatus>().SP -= deployer.CurrentSkillData.costSP; }