public static void DoRollDamage(Agent1 agent, AnimAttackData data, float range) { if (agent == null || data == null) { return; } if (agent.BlackBoard.motionType != MotionType.ROLL) { return; } Vector3 attackerDir = agent.Forward; Vector3 dirToTarget = Vector3.zero; for (int i = 0; i < Game1.Instance.AgentMgr.agents.Count; i++) { Agent1 target = Game1.Instance.AgentMgr.agents[i]; if (target == null || target == agent || target.BlackBoard.IsAlive == false || target.BlackBoard.IsKnockedDown) { continue; } if (target.BlackBoard.invulnerable || (target.BlackBoard.damageOnlyFromBack && TransformTools.Instance.IsBehindTarget(agent.Transform, target.Transform) == false)) { // 攻击无效 ReceiveHitCompletelyBlocked(target, agent); HandleSound.PlaySoundBlocked(); continue; } dirToTarget = target.Position - agent.Position; if (dirToTarget.sqrMagnitude < range * range) { //if (data.useImpuls) //{ // ReceiveImpuls(target, agent, dirToTarget.normalized * data.hitMomentum); //} ReceiveDamage(target, agent, WeaponType.BODY, data.hitDamage, data.hitMomentum); HandleSound.PlaySoundHit(); } } }
public static void DoMeleeDamage(Agent1 agent, Agent1 mainTarget, WeaponType weaponType, AnimAttackData animAttackData, bool critical, bool knockdown, bool fatalAttack) { Vector3 dirToEnemy; Vector3 attackerDir = agent.Forward; for (int i = 0; i < Game1.Instance.AgentMgr.agents.Count; i++) { Agent1 target = Game1.Instance.AgentMgr.agents[i]; if (target == null || target == agent || target.BlackBoard.IsAlive == false || target.BlackBoard.IsKnockedDown) { continue; } if (fatalAttack) { // 一招制敌,如玩家的跳杀跌倒的敌人技能 ReceiveDamage(target, agent, weaponType, target.BlackBoard.maxHealth, animAttackData.hitMomentum); continue; } dirToEnemy = target.Position - agent.Position; float dist = dirToEnemy.magnitude; dirToEnemy.Normalize(); if (target.BlackBoard.invulnerable || (target.BlackBoard.damageOnlyFromBack && Vector3.Angle(attackerDir, target.Forward) > 80)) { // 攻击无效 ReceiveHitCompletelyBlocked(target, agent); HandleSound.PlaySoundBlocked(); continue; } if (dist > agent.BlackBoard.weaponRange) { if (animAttackData.hitAreaKnockdown && knockdown && dist < agent.BlackBoard.weaponRange * 1.2f) { // 击倒 ReceiveKnockDown(target, agent, dirToEnemy * animAttackData.hitMomentum); HandleSound.PlaySoundKnockDown(); } else if (animAttackData.useImpuls && dist < agent.BlackBoard.weaponRange * 1.4f) { // 击退 ReceiveImpuls(target, agent, dirToEnemy * animAttackData.hitMomentum); } continue; } if (dist > 0.5f && Vector3.Angle(attackerDir, dirToEnemy) > animAttackData.hitAngle) { if (animAttackData.useImpuls) { // 击退 ReceiveImpuls(target, agent, dirToEnemy * animAttackData.hitMomentum); } continue; } if (target.BlackBoard.criticalAllowed && animAttackData.hitCriticalType != CriticalHitType.NONE && agent.BlackBoard.FaceToOtherBack(target)) // from behind { // 碎尸 ReceiveCriticalHit(target, agent, animAttackData.hitCriticalType, false); HandleSound.PlaySoundHit(); } else if (target.BlackBoard.IsBlocking) { // 被格挡 ReceiveBlockedHit(target, agent, weaponType, animAttackData.hitDamage, animAttackData); HandleSound.PlaySoundBlocked(); } else if (target.BlackBoard.criticalAllowed && critical && (mainTarget == target || (animAttackData.hitCriticalType == CriticalHitType.HORIZONTAL && Random.Range(0, 100) < 30))) { // 碎尸 ReceiveCriticalHit(target, agent, animAttackData.hitCriticalType, false); HandleSound.PlaySoundHit(); } else if (animAttackData.hitAreaKnockdown && knockdown) { // 击倒 ReceiveKnockDown(target, agent, dirToEnemy * (1 - (dist / agent.BlackBoard.weaponRange) + animAttackData.hitMomentum)); HandleSound.PlaySoundKnockDown(); } else if (animAttackData.hitAngle == -1 /*比如attack whirl*/ || Vector3.Angle(attackerDir, dirToEnemy) < animAttackData.hitAngle) { // 普通伤害 ReceiveDamage(target, agent, weaponType, animAttackData.hitDamage, animAttackData.hitMomentum); HandleSound.PlaySoundHit(); } else { // miss HandleSound.PlaySoundMiss(); } } }