示例#1
0
        private ActorExt GetCurrentTarget()
        {
            ulong[] actors = hateTable.Keys.ToArray();
            Map.Map map    = MapManager.Instance.GetMap(npc.MapInstanceID);
            if (map == null)
            {
                Deactivate();
                return(null);
            }
            int      hate  = int.MinValue;
            ActorExt found = null;

            foreach (ulong i in actors)
            {
                int val = hateTable[i];
                if (val > hate)
                {
                    found = map.GetActor(i) as ActorExt;
                    if (found == null || found.Status.Stealth)
                    {
                        found = null;
                        continue;
                    }
                    if (found == null || i == npc.ActorID || FactionRelationFactory.Instance[npc.Faction][found.Faction] == Relations.Friendly)
                    {
                        hateTable.TryRemove(i, out val);
                        continue;
                    }
                    hate = val;
                }
            }
            return(found);
        }
示例#2
0
 public override void CallBack()
 {
     try
     {
         Map.Map map = Map.MapManager.Instance.GetMap(actor.MapInstanceID);
         if (map == null)
         {
             actor.Tasks.TryRemove("CorpseDelete", out Task task);
             Deactivate();
         }
         if (!already)
         {
             already         = true;
             actor.Invisible = false;
             map.OnActorVisibilityChange(actor);
             map.DeleteActor(actor.NPC);
         }
         else
         {
             if ((actor.AvailableItems.Count > 0) || actor.NPC.BaseData.QuestIDs.Count > 0)
             {
                 if (!shoudDisappear)
                 {
                     shoudDisappear = true;
                     dueTime        = 60000;
                     Activate();
                     actor.ShouldDisappear = true;
                     UpdateEvent evt = new UpdateEvent()
                     {
                         Actor      = actor,
                         UpdateType = UpdateTypes.DeleteCorpse
                     };
                     map.SendEventToAllActorsWhoCanSeeActor(MapEvents.EVENT_BROADCAST, evt, actor, false);
                 }
                 else
                 {
                     actor.Items = null;
                     actor.Gold  = 0;
                     if (actor.CurrentPickingPlayer > 0)
                     {
                         if (map.GetActor(actor.CurrentPickingPlayer) is ActorPC pc)
                         {
                             pc.Client().SendActorCorpseClose(actor.ActorID);
                         }
                     }
                     actor.Tasks.TryRemove("CorpseDelete", out Task task);
                     Deactivate();
                     actor.ShouldDisappear = true;
                     map.DeleteActor(actor);
                 }
             }
             else
             {
                 actor.Tasks.TryRemove("CorpseDelete", out Task task);
                 Deactivate();
                 actor.ShouldDisappear = true;
                 map.DeleteActor(actor);
             }
         }
     }
     catch (Exception ex)
     {
         SmartEngine.Core.Logger.Log.Error(ex);
         actor.Tasks.TryRemove("CorpseDelete", out Task task);
         Deactivate();
     }
 }
示例#3
0
        private void CheckAggro()
        {
            try
            {
                Map.Map map = MapManager.Instance.GetMap(npc.MapInstanceID);
                if (map == null)
                {
                    Deactivate();
                    return;
                }
                int      distance = int.MaxValue;
                ActorExt found    = null;
                foreach (KeyValuePair <ulong, ulong> i in npc.VisibleActors)
                {
                    ulong id = i.Key;
                    if (map.GetActor(id) is ActorExt target)
                    {
                        if (target.Status.Stealth || (target.Status.Dead && !target.Status.Recovering))
                        {
                            continue;
                        }

                        if (FactionRelationFactory.Instance[npc.Faction][target.Faction] == Relations.Enemy)
                        {
                            if (target.Status.Dead && !target.Status.Recovering)
                            {
                                continue;
                            }

                            int len = npc.DistanceToActor(target);
                            if (len < distance)
                            {
                                found    = target;
                                distance = len;
                            }
                        }
                    }
                }
                if (found != null && distance < npc.BaseData.AggroRange)
                {
                    if (!hateTable.ContainsKey(found.ActorID))
                    {
                        if (found is ActorPC pc)
                        {
                            pc.Client().SendActorAggro(npc.ActorID);
                        }
                        if (npc.Invisible)
                        {
                            npc.Invisible = false;
                            map.OnActorVisibilityChange(npc);
                        }
                        ActorNPC npc2 = found as ActorNPC;
                        hateTable[found.ActorID] = 20;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex);
            }
        }