Example #1
0
 internal void HostilityTarget()
 {
     if (IsHostile && Target == -1)
     {
         Character character = ServerManager.Instance.Sessions.FirstOrDefault(s => s?.Character != null && s.Character.Hp > 0 && !s.Character.InvisibleGm && !s.Character.Invisible && s.Character.MapInstance == MapInstance && Map.GetDistance(new MapCell {
             X = MapX, Y = MapY
         }, new MapCell {
             X = s.Character.PositionX, Y = s.Character.PositionY
         }) < (NoticeRange == 0 ? Monster.NoticeRange : NoticeRange))?.Character;
         if (character != null)
         {
             if (!OnNoticeEvents.Any() && MoveEvent == null)
             {
                 Target = character.CharacterId;
                 if (!Monster.NoAggresiveIcon && LastEffect.AddSeconds(5) < DateTime.Now)
                 {
                     character.Session.SendPacket(GenerateEff(5000));
                 }
             }
             OnNoticeEvents.ForEach(e =>
             {
                 EventHelper.Instance.RunEvent(e, monster: this);
             });
             OnNoticeEvents.RemoveAll(s => s != null);
         }
     }
 }
Example #2
0
        /// <summary>
        /// Hostility on actual Target
        /// </summary>
        internal void HostilityTarget()
        {
            if (!IsHostile || Target != null)
            {
                return;
            }
            IBattleEntity target = MapInstance.BattleEntities.FirstOrDefault(e => e.IsTargetable(SessionType()) && IsFactionTargettable(e.Faction) && Map.GetDistance(GetPos(), e.GetPos()) < (NoticeRange == 0 ? Monster.NoticeRange : NoticeRange));

            if (target == null || MoveEvent != null)
            {
                return;
            }
            if (OnNoticeEvents.Any())
            {
                OnNoticeEvents.ToList().ForEach(e => { EventHelper.Instance.RunEvent(e, monster: this); });
                OnNoticeEvents.Clear();
                return;
            }

            Target = target;
            if (!Monster.NoAggresiveIcon && LastEffect.AddSeconds(5) < DateTime.Now && target.GetSession() is Character character)
            {
                character?.Session.SendPacket(GenerateEff(5000));
            }
        }