/// <summary> /// 初始化临时血量 用于判断 清空攻击目标数据 /// </summary> /// <param name="isMyTeam">是否是我方队伍</param> private void initRoleAttackData(bool isMyTeam) { List <BattleRole> targetList; if (!isMyTeam) { targetList = this.targetTeam; } else { targetList = this.myTeam; } int count = targetList.Count; for (int i = 0; i < count; ++i) { BattleRole br = targetList[i]; br.setAttackTarget(null); br.isAttacking = false; br.heroVo.tempHp = br.heroVo.hp; } }
/// <summary> /// 获取被攻击目标(普通攻击) /// </summary> /// <param name="isMyTeam">是否是我方队伍攻击</param> private void getAttackTarget(bool isMyTeam) { List <BattleRole> targetList; List <BattleRole> targetAry; if (isMyTeam) { targetList = this.targetTeam; targetAry = this.targetTeamAry; } else { targetList = this.myTeam; targetAry = this.myTeamAry; } this.initRoleAttackData(isMyTeam); int count = this.attackList.Count; int targetCount = targetList.Count; //关闭列表 存放一次进攻后血量为0的角色 List <int> closeList = new List <int>(); for (int i = 0; i < count; ++i) { BattleRole attackRole = this.attackList[i]; float dis = float.MaxValue; int index = -1; //查找距离最近的对手 for (int j = 0; j < targetCount; ++j) { BattleRole targetBr = targetList[j]; if (closeList.IndexOf(targetBr.index) != -1) { continue; } float curDis = (attackRole.posIndexVector - targetBr.posIndexVector).sqrMagnitude; if (curDis < dis) { index = j; dis = curDis; } } //计算被攻击者剩余血量 如果进攻后血量为0 则放入关闭列表中 if (index != -1) { BattleRole chooseBr = targetList[index]; if (DamageUtils.checkRoleDead(attackRole.heroVo, chooseBr.heroVo)) { closeList.Add(chooseBr.index); } //将目标存放进去 attackRole.setAttackTarget(chooseBr); if (attackRole.heroVo.attackRangeType != 0) { List <BattleRole> rangeAttackRoleList = new List <BattleRole>(); bool isHorizontal = attackRole.heroVo.attackRangeType == BattleConstant.ATTACK_RANGE_HORIZONTAL; int [] rangeIndexAry = BattleFormation.getPosIndexByDirection(isHorizontal, chooseBr.index); //遍历posIndexAry 剔除 chooseBr.index 和 closeList中的索引 //判断checkRoleDead 将血为空的添加进col int length = rangeIndexAry.Length; for (int j = 0; j < length; j++) { int rangeIndex = rangeIndexAry[j]; if (rangeIndex == chooseBr.index || closeList.IndexOf(rangeIndex) != -1) { continue; } BattleRole rangeAttackRole = targetAry[rangeIndex]; if (rangeAttackRole != null && !rangeAttackRole.isDeaded) { if (DamageUtils.checkRoleDead(attackRole.heroVo, rangeAttackRole.heroVo)) { closeList.Add(chooseBr.index); } rangeAttackRoleList.Add(rangeAttackRole); } } attackRole.setAttackRangeTarget(rangeAttackRoleList); } attackRole.isAttacking = true; } } }