public bool TryGetAttackingCharacter(out BaseCharacterEntity character) { character = null; if (PlayerCharacterEntity.TryGetTargetEntity(out character)) { if (character.CanReceiveDamageFrom(PlayerCharacterEntity)) { return(true); } else { character = null; } } return(false); }
public void AggressiveFindTarget(float time, Vector3 currentPosition) { // Aggressive monster or summoned monster will find target to attack if (monsterDatabase.characteristic != MonsterCharacteristic.Aggressive && CacheMonsterCharacterEntity.Summoner == null) { return; } BaseCharacterEntity targetCharacter; if (!CacheMonsterCharacterEntity.TryGetTargetEntity(out targetCharacter) || targetCharacter.IsDead()) { // If no target enenmy or target enemy is dead, Find nearby character by layer mask List <Collider> foundObjects = new List <Collider>(Physics.OverlapSphere(currentPosition, monsterDatabase.visualRange, gameInstance.characterLayer.Mask)); foreach (Collider foundObject in foundObjects) { BaseCharacterEntity characterEntity = foundObject.GetComponent <BaseCharacterEntity>(); // Attack target settings if (characterEntity == null || !characterEntity.CanReceiveDamageFrom(CacheMonsterCharacterEntity)) { // If character is null or cannot receive damage from monster, skip it continue; } if (CacheMonsterCharacterEntity.Summoner != null && CacheMonsterCharacterEntity.Summoner != characterEntity.GetTargetEntity()) { // If character is not attacking summoner, skip it continue; } if (!CacheMonsterCharacterEntity.IsEnemy(characterEntity)) { // If character is not enemy, skip it continue; } // Found target, attack it SetStartFollowTargetTime(time); CacheMonsterCharacterEntity.SetAttackTarget(characterEntity); break; } } }
public bool CanReceiveDamageFrom(IAttackerEntity attacker) { return(characterEntity.CanReceiveDamageFrom(attacker)); }