Esempio n. 1
0
 public Event(Guid instanceId, EventBase baseEvent, Guid map) //Global constructor
 {
     Id                 = instanceId;
     Global             = true;
     MapId              = map;
     BaseEvent          = baseEvent;
     SelfSwitch         = new bool[4];
     GlobalPageInstance = new EventPageInstance[BaseEvent.Pages.Count];
     X = (byte)baseEvent.SpawnX;
     Y = baseEvent.SpawnY;
     for (var i = 0; i < BaseEvent.Pages.Count; i++)
     {
         GlobalPageInstance[i] = new EventPageInstance(BaseEvent, BaseEvent.Pages[i], MapId, this, null);
     }
 }
Esempio n. 2
0
        public void Update(long timeMs)
        {
            var sendLeave            = false;
            var originalPageInstance = PageInstance;

            if (PageInstance != null)
            {
                //Check for despawn
                if (PageInstance.ShouldDespawn())
                {
                    X            = PageInstance.X;
                    Y            = PageInstance.Y;
                    PageInstance = null;
                    CallStack.Clear();
                    PlayerHasDied = false;
                    if (HoldingPlayer)
                    {
                        PacketSender.SendReleasePlayer(Player, Id);
                        HoldingPlayer = false;
                    }

                    sendLeave = true;
                }
                else
                {
                    if (!Global)
                    {
                        PageInstance.Update(
                            CallStack.Count > 0, timeMs
                            ); //Process movement and stuff that is client specific
                    }

                    //Check to see if we should process event commands
                    if (CallStack.Count > 0)
                    {
                        var curStack = CallStack.Peek();
                        if (curStack.WaitingForResponse == CommandInstance.EventResponse.Shop && Player.InShop == null)
                        {
                            curStack.WaitingForResponse = CommandInstance.EventResponse.None;
                        }

                        if (curStack.WaitingForResponse == CommandInstance.EventResponse.Crafting &&
                            Player.CraftingTableId == Guid.Empty)
                        {
                            curStack.WaitingForResponse = CommandInstance.EventResponse.None;
                        }

                        if (curStack.WaitingForResponse == CommandInstance.EventResponse.Bank && Player.InBank == false)
                        {
                            curStack.WaitingForResponse = CommandInstance.EventResponse.None;
                        }

                        if (curStack.WaitingForResponse == CommandInstance.EventResponse.Quest &&
                            !Player.QuestOffers.Contains(((StartQuestCommand)curStack.WaitingOnCommand).QuestId))
                        {
                            curStack.WaitingForResponse = CommandInstance.EventResponse.None;
                        }

                        if (curStack.WaitingForResponse == CommandInstance.EventResponse.Timer &&
                            WaitTimer < Globals.Timing.TimeMs)
                        {
                            curStack.WaitingForResponse = CommandInstance.EventResponse.None;
                        }

                        var commandsExecuted = 0;
                        while (curStack.WaitingForResponse == CommandInstance.EventResponse.None &&
                               !PageInstance.ShouldDespawn() &&
                               commandsExecuted < Options.EventWatchdogKillThreshhold)
                        {
                            if (curStack.WaitingForRoute != Guid.Empty)
                            {
                                if (curStack.WaitingForRoute == Player.Id)
                                {
                                    if (Player.MoveRoute == null ||
                                        Player.MoveRoute.Complete && Player.MoveTimer < Globals.Timing.TimeMs)
                                    {
                                        curStack.WaitingForRoute    = Guid.Empty;
                                        curStack.WaitingForRouteMap = Guid.Empty;
                                    }
                                }
                                else
                                {
                                    //Check if the exist exists && if the move route is completed.
                                    foreach (var evt in Player.EventLookup.Values)
                                    {
                                        if (evt.MapId == curStack.WaitingForRouteMap &&
                                            evt.BaseEvent.Id == curStack.WaitingForRoute)
                                        {
                                            if (evt.PageInstance == null)
                                            {
                                                break;
                                            }

                                            if (!evt.PageInstance.MoveRoute.Complete)
                                            {
                                                break;
                                            }

                                            curStack.WaitingForRoute    = Guid.Empty;
                                            curStack.WaitingForRouteMap = Guid.Empty;

                                            break;
                                        }
                                    }
                                }

                                if (curStack.WaitingForRoute != Guid.Empty)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                if (curStack.CommandIndex >= curStack.CommandList.Count)
                                {
                                    CallStack.Pop();
                                }
                                else
                                {
                                    if (WaitTimer < Globals.Timing.TimeMs)
                                    {
                                        CommandProcessing.ProcessCommand(curStack.Command, Player, this);
                                        commandsExecuted++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                if (CallStack.Count == 0)
                                {
                                    PlayerHasDied = false;

                                    break;
                                }
                            }

                            curStack = CallStack.Peek();
                        }

                        if (commandsExecuted >= Options.EventWatchdogKillThreshhold)
                        {
                            CallStack.Clear(); //Killing this event, we're over it.
                            if (this.BaseEvent.MapId == Guid.Empty)
                            {
                                Log.Error(Strings.Events.watchdogkillcommon.ToString(BaseEvent.Name));
                                if (Player.Power.IsModerator)
                                {
                                    PacketSender.SendChatMsg(
                                        Player, Strings.Events.watchdogkillcommon.ToString(BaseEvent.Name), Color.Red
                                        );
                                }
                            }
                            else
                            {
                                var map = MapInstance.Get(this.BaseEvent.MapId);
                                Log.Error(Strings.Events.watchdogkill.ToString(map.Name, BaseEvent.Name));
                                if (Player.Power.IsModerator)
                                {
                                    PacketSender.SendChatMsg(
                                        Player, Strings.Events.watchdogkill.ToString(map.Name, BaseEvent.Name),
                                        Color.Red
                                        );
                                }
                            }
                        }
                    }
                    else
                    {
                        if (PageInstance.Trigger == EventTrigger.Autorun && WaitTimer < Globals.Timing.TimeMs)
                        {
                            var newStack = new CommandInstance(PageInstance.MyPage);
                            CallStack.Push(newStack);
                        }
                    }
                }
            }

            if (PageInstance == null)
            {
                //Try to Spawn a PageInstance.. if we can
                for (var i = BaseEvent.Pages.Count - 1; i >= 0; i--)
                {
                    if (Conditions.CanSpawnPage(BaseEvent.Pages[i], Player, this))
                    {
                        if (Global)
                        {
                            if (MapInstance.Get(MapId).GetGlobalEventInstance(BaseEvent) != null)
                            {
                                PageInstance = new EventPageInstance(
                                    BaseEvent, BaseEvent.Pages[i], BaseEvent.Id, MapId, this, Player,
                                    MapInstance.Get(MapId).GetGlobalEventInstance(BaseEvent).GlobalPageInstance[i]
                                    );

                                sendLeave = false;
                                PageIndex = i;
                            }
                        }
                        else
                        {
                            PageInstance = new EventPageInstance(BaseEvent, BaseEvent.Pages[i], MapId, this, Player);
                            sendLeave    = false;
                            PageIndex    = i;
                        }

                        break;
                    }
                }

                if (sendLeave && originalPageInstance != null)
                {
                    PacketSender.SendEntityLeaveTo(Player, originalPageInstance);
                }
            }
        }
        public EventPageInstance(
            EventBase myEvent,
            EventPage myPage,
            Guid instanceId,
            Guid mapId,
            Event eventIndex,
            Player player,
            EventPageInstance globalClone
            ) : base(instanceId)
        {
            BaseEvent      = myEvent;
            Id             = BaseEvent.Id;
            GlobalClone    = globalClone;
            MyPage         = myPage;
            MapId          = mapId;
            X              = globalClone.X;
            Y              = globalClone.Y;
            Name           = myEvent.Name;
            MovementType   = globalClone.MovementType;
            MovementFreq   = globalClone.MovementFreq;
            MovementSpeed  = globalClone.MovementSpeed;
            DisablePreview = globalClone.DisablePreview;
            Trigger        = MyPage.Trigger;
            Passable       = globalClone.Passable;
            HideName       = globalClone.HideName;
            MyEventIndex   = eventIndex;
            MoveRoute      = globalClone.MoveRoute;
            mPathFinder    = new Pathfinder(this);
            SetMovementSpeed(MyPage.Movement.Speed);
            MyGraphic.Type     = globalClone.MyGraphic.Type;
            MyGraphic.Filename = globalClone.MyGraphic.Filename;
            MyGraphic.X        = globalClone.MyGraphic.X;
            MyGraphic.Y        = globalClone.MyGraphic.Y;
            MyGraphic.Width    = globalClone.MyGraphic.Width;
            MyGraphic.Height   = globalClone.MyGraphic.Height;
            Sprite             = MyPage.Graphic.Filename;
            mDirectionFix      = MyPage.DirectionFix;
            mWalkingAnim       = MyPage.WalkingAnimation;
            mRenderLayer       = MyPage.Layer;
            if (globalClone.MyGraphic.Type == EventGraphicType.Sprite)
            {
                switch (MyPage.Graphic.Y)
                {
                case 0:
                    Dir = 1;

                    break;

                case 1:
                    Dir = 2;

                    break;

                case 2:
                    Dir = 3;

                    break;

                case 3:
                    Dir = 0;

                    break;
                }
            }

            if (myPage.AnimationId != Guid.Empty)
            {
                Animations.Add(myPage.AnimationId);
            }

            Face     = MyPage.FaceGraphic;
            mPageNum = BaseEvent.Pages.IndexOf(MyPage);
            Player   = player;
            SendToPlayer();
        }