public static void Update(float deltaTime, List <GameObject> nearbyNPC, GameMap map, NonPlayerCharacter caller) { caller.aiBehaviorComponent.Clock.Update(deltaTime); caller.PhysicsComponent.objective = nearbyNPC.Where(u => PhysicsProcessor.GetDistanceFromUnit(u.PhysicsComponent, caller.PhysicsComponent) < caller.StatsComponent.Range).FirstOrDefault(); if (caller.PhysicsComponent.objective != null) { AIAgressive(caller, map); } else { AIIdle(caller, map); } }
private static void AIAgressive(NonPlayerCharacter caller, GameMap map) { PhysicsProcessor.StopAllMovement(caller.PhysicsComponent); if (caller.aiBehaviorComponent.Clock.isIntervalTicked(Constants.NPC.DEFAULT_UNIT_MOVE_INTERVAL_AGGRESIVE)) { if (caller.PhysicsComponent.objective.PhysicsComponent.position.Y < caller.PhysicsComponent.position.Y) { PhysicsProcessor.MoveUp(caller.PhysicsComponent); caller.PhysicsComponent.FacingDirection = FacingDirections.UP; } if (caller.PhysicsComponent.objective.PhysicsComponent.position.Y > caller.PhysicsComponent.position.Y) { PhysicsProcessor.MoveDown(caller.PhysicsComponent); caller.PhysicsComponent.FacingDirection = FacingDirections.DOWN; } if (caller.PhysicsComponent.objective.PhysicsComponent.position.X > caller.PhysicsComponent.position.X) { PhysicsProcessor.MoveRight(caller.PhysicsComponent); caller.PhysicsComponent.FacingDirection = FacingDirections.RIGHT; } if (caller.PhysicsComponent.objective.PhysicsComponent.position.X < caller.PhysicsComponent.position.X) { PhysicsProcessor.MoveLeft(caller.PhysicsComponent); caller.PhysicsComponent.FacingDirection = FacingDirections.LEFT; } if (CheckColission(map, caller.PhysicsComponent.destination)) { caller.PhysicsComponent.destination = caller.PhysicsComponent.position; } } caller.SkillSet.Where(s => s is MeleeSkill).FirstOrDefault().Execute(caller, caller.PhysicsComponent.objective); }