/// <summary> /// 判定技能伤害 /// </summary> public void ProcessSpellAttack(EntityCharacter source, float range, float percent) { Vector3 position = source.Root.transform.position; for (int i = 0; i < _entitys.Count; i++) { EntityObject entity = _entitys[i]; if (entity.EntityID == source.EntityID) { continue; } if (entity is EntityCharacter) { EntityCharacter target = entity as EntityCharacter; float distance = Vector3.Distance(position, target.Root.transform.position); distance -= target.CharData.BodyRadius; if (distance < range) { // 计算最终伤害值 double damage = source.CharData.Damage * (percent / 100f) - target.CharData.Armor; if (damage < 1) { damage = 1; } BattleEvent.DamageHurt msg = new BattleEvent.DamageHurt(); msg.SourceEntityID = source.EntityID; msg.TargetEntityID = target.EntityID; msg.Damage = damage; target.HandleEvent(msg); } } } }
protected override void OnHandleEvent(IEventMessage msg) { if (msg is BattleEvent.DamageHurt) { if (CharData.IsDead == false) { BattleEvent.DamageHurt message = msg as BattleEvent.DamageHurt; CharData.DamageHurt(message.Damage); CharAnim.Play("getHit"); // 随机播放角色受击音效 string soundName = Avatar.GetRandomGetHitSound(); if (string.IsNullOrEmpty(soundName) == false) { AudioManager.Instance.PlaySound(soundName); } } } else if (msg is BattleEvent.CharacterDead) { CharSkill.ForbidAll(); CharAnim.Play("die"); // 播放角色死亡音效 string soundName = Avatar.GetDeadSound(); if (string.IsNullOrEmpty(soundName) == false) { AudioManager.Instance.PlaySound(soundName); } } }