Пример #1
0
 public override void CallBack()
 {
     Deactivate();
     actor.Tasks.TryRemove("Respawn", out Task task);
     Map.Map map = Map.MapManager.Instance.GetMap(actor.MapInstanceID);
     if (map != null)
     {
         actor.X           = actor.X_Ori;
         actor.Y           = actor.Y_Ori;
         actor.Z           = actor.Z_Ori;
         actor.Status.Dead = false;
         actor.HP          = actor.MaxHP;
         map.RegisterActor(actor);
         actor.Invisible = false;
         map.OnActorVisibilityChange(actor);
         map.SendVisibleActorsToActor(actor);
     }
 }
Пример #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
        public void DoSpawn(Map.Map map)
        {
            if (IsQuest)
            {
                ActorQuest obj = new ActorQuest()
                {
                    MapID         = map.ID,
                    MapInstanceID = map.InstanceID,
                    X             = X,
                    Y             = Y,
                    Z             = Z,
                    EventHandler  = new ActorEventHandlers.QuestEventHandler()
                };
                map.RegisterActor(obj);
            }
            else if (IsCampfire)
            {
                ActorMapObj obj = new ActorMapObj(NpcID)
                {
                    ActorID           = (ulong)(map.InstanceID | 0xC00000) << 32 | NpcID,
                        MapID         = map.ID,
                        X             = X,
                        Y             = Y,
                        Z             = Z,
                        SpecialMapID  = SpecialMapID,
                        MapInstanceID = map.InstanceID,
                        EventHandler  = new ActorEventHandlers.DummyEventHandler()
                };
                map.Campfires.Add(obj.ActorID, obj);
            }
            else if (!IsMapObject)
            {
                for (int i = 0; i < Count; i++)
                {
                    short x;
                    short y;
                    if (Range > 0)
                    {
                        x = (short)Global.Random.Next(X - Range, X + Range);
                        y = (short)Global.Random.Next(Y - Range, Y + Range);
                    }
                    else
                    {
                        x = X;
                        y = Y;
                    }
                    ActorNPC npc = new ActorNPC(NPCDataFactory.Instance.Items[NpcID])
                    {
                        X              = x,
                        Y              = y,
                        Z              = Z,
                        X_Ori          = x,
                        Y_Ori          = y,
                        Z_Ori          = Z,
                        MoveRange      = MoveRange,
                        Dir            = Dir,
                        StandartMotion = Motion,
                        AppearEffect   = AppearEffect,
                        MapID          = MapID
                    };
                    if (ManaType > 0)
                    {
                        npc.ManaType = (Common.Actors.ManaType)ManaType;
                    }

                    if (Scripting.ScriptManager.Instance.NpcScripts.ContainsKey(NpcID))
                    {
                        Scripting.NPCScriptHandler handler = (Scripting.NPCScriptHandler)Activator.CreateInstance(Scripting.ScriptManager.Instance.NpcScripts[NpcID].GetType());
                        handler.NPC      = npc;
                        npc.EventHandler = handler;
                    }
                    else
                    {
                        npc.EventHandler = new ActorEventHandlers.NPCEventHandler(npc);
                    }

                    if (Delay > 0)
                    {
                        ((ActorEventHandlers.NPCEventHandler)npc.EventHandler).ShouldRespawn += () =>
                        {
                            Tasks.Actor.RespawnTask task = new Tasks.Actor.RespawnTask(Delay, npc);
                            task.Activate();
                        };
                    }
                    map.RegisterActor(npc);
                    npc.Invisible = Hidden;
                    map.OnActorVisibilityChange(npc);
                    map.SendVisibleActorsToActor(npc);
                    //spawns.Add(npc);
                }
            }
            else
            {
                ActorMapObj obj = new ActorMapObj(NpcID)
                {
                    ActorID   = (ulong)(map.InstanceID | 0x200000) << 32 | NpcID,
                        MapID = map.ID
                };
                if (Delay > 0)
                {
                    obj.RespawnTime = Delay;
                }

                obj.Special       = Special;
                obj.DragonStream  = DragonStream;
                obj.X             = X;
                obj.Y             = Y;
                obj.Z             = Z;
                obj.SpecialMapID  = SpecialMapID;
                obj.MapInstanceID = map.InstanceID;
                foreach (uint i in itemIDs.Keys)
                {
                    obj.ItemIDs[i] = itemIDs[i];
                }

                obj.MinGold      = MinGold;
                obj.MaxGold      = MaxGold;
                obj.EventHandler = new ActorEventHandlers.DummyEventHandler();
                map.MapObjects.Add(obj.ActorID, obj);
            }
        }
Пример #4
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);
            }
        }