public void FollowSummoner(float time) { // If stopped then random Vector3 randomPosition = CacheMonsterCharacterEntity.spawnPosition + new Vector3(Random.Range(-1f, 1f) * randomWanderDistance, 0, Random.Range(-1f, 1f) * randomWanderDistance); if (CacheMonsterCharacterEntity.Summoner != null) { randomPosition = CacheMonsterCharacterEntity.Summoner.GetSummonPosition(); } CacheMonsterCharacterEntity.SetTargetEntity(null); SetDestination(time, randomPosition); }
protected void UpdateActivity(float time) { if (!CacheMonsterCharacterEntity.IsServer || CacheMonsterCharacterEntity.Identity.CountSubscribers() == 0 || monsterDatabase == null) { return; } if (CacheNavMeshAgent.velocity.magnitude > 0) { CacheMonsterCharacterEntity.MovementState = MovementState.Forward | MovementState.IsGrounded; } else { CacheMonsterCharacterEntity.MovementState = MovementState.IsGrounded; } if (CacheMonsterCharacterEntity.IsDead()) { StopMove(); CacheMonsterCharacterEntity.SetTargetEntity(null); return; } Vector3 currentPosition = CacheMonsterCharacterEntity.CacheTransform.position; if (CacheMonsterCharacterEntity.Summoner != null && Vector3.Distance(currentPosition, CacheMonsterCharacterEntity.Summoner.CacheTransform.position) > gameInstance.minFollowSummonerDistance) { // Follow summoner with stat's move speed FollowSummoner(time); return; } if (CacheMonsterCharacterEntity.Summoner == null && CacheMonsterCharacterEntity.isInSafeArea) { // If monster move into safe area, wander to another place RandomWanderTarget(time); return; } BaseCharacterEntity targetEntity; if (CacheMonsterCharacterEntity.TryGetTargetEntity(out targetEntity)) { if (targetEntity.IsDead() || targetEntity.isInSafeArea) { // If target is dead or in safe area stop attacking CacheMonsterCharacterEntity.SetTargetEntity(null); return; } UpdateAttackTarget(time, currentPosition, targetEntity); } else { // Find target when it's time if (time >= findTargetTime) { SetFindTargetTime(time); AggressiveFindTarget(time, currentPosition); return; } // Wandering when it's time if (time >= wanderTime) { RandomNextWanderTime(time); RandomWanderTarget(time); return; } } }