private void ProcessAiWithoutTarget(IAiEntity mov) { if (mov.Waypoints != null && mov.Waypoints.Length != 0) { return; } // supposedly should never enter here if (mov.Type == VisualType.Character || mov.Speed == 0) { return; } if (_random.Next(0, 100) < 35) { // wait max 2500 millisecs before having a new movement mov.LastMove = DateTime.UtcNow.AddMilliseconds(_random.Next(2500)); return; } int i = 0; Position <short> dest = null; while (dest == null && i < 25) { short xpoint = (short)_random.Next(0, 4); short ypoint = (short)_random.Next(0, 4); short firstX = mov.Position.X; short firstY = mov.Position.Y; dest = _map.GetFreePosition(firstX, firstY, xpoint, ypoint); i++; } if (dest == null) { return; } mov.Waypoints = _pathfinder.FindPath(mov.Position, dest, _map); }
private Task ProcessAiWithTarget(IAiEntity aiEntity, IBattleEntity target) { // if range is enough to attack, attack int distance = aiEntity.GetDistance(target); // get a random skill SkillDto skill = aiEntity.Skills.Values.OrderBy(s => _random.Next()).FirstOrDefault(s => s.Range >= distance); // no skill has range to hit target if (skill == null) { byte range = aiEntity.NpcMonster.BasicRange; // basic skill range if (distance > range) { // follow the target return(FollowTheTarget(aiEntity, target)); } skill = new SkillDto { HitType = (byte)SkillTargetType.SingleHit, Range = range, MpCost = 0, // basic skill costs nothing Cooldown = (short)(aiEntity.NpcMonster.BasicCooldown * 250), TargetType = (byte)SkillTargetType.SingleHit, Effect = aiEntity.NpcMonster.BasicSkill, AttackAnimation = 11, // default value for SingleTargetHit SkillType = 0 // default value for BasicSkill }; } // hit the target with the given skill return(aiEntity.EmitEventAsync(new UseSkillEvent { Skill = skill, Target = target })); }
private Task FollowTheTarget(IAiEntity aiEntity, IBattleEntity target) { return(Task.CompletedTask); }