Exemple #1
0
        private static void TradeStop(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            Trade Trade = Instance.TradeManager.GetTradeForUser(Session.CharacterId);

            if (Trade == null)
            {
                return;
            }

            Instance.TradeManager.StopTradeForUser(Session.CharacterId);
            Session.SendData(TradeAbortedComposer.Compose(Session.CharacterId));

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor != null)
            {
                Actor.RemoveStatus("trd");
                Actor.UpdateNeeded = true;
            }

            Session TargetSession = SessionManager.GetSessionByCharacterId(Trade.UserOne == Session.CharacterId ?
                                                                           Trade.UserTwo : Trade.UserOne);

            if (TargetSession != null)
            {
                Instance.TradeManager.StopTradeForUser(TargetSession.CharacterId);
                TargetSession.SendData(TradeAbortedComposer.Compose(Session.CharacterId));

                RoomActor TargetActor = Instance.GetActorByReferenceId(TargetSession.CharacterId);

                if (TargetActor != null)
                {
                    TargetActor.RemoveStatus("trd");
                    TargetActor.UpdateNeeded = true;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Removes an actor from the room instance. DO NOT CALL DIRECTLY FOR HUMAN CHARACTERS.
        /// </summary>
        /// <param name="ActorId">Id of the actor to remove.</param>
        /// <returns>Boolean based on success of removal.</returns>
        public bool RemoveActorFromRoom(uint ActorId)
        {
            bool Success = false;

            lock (mActorSyncRoot)
            {
                RoomActor Actor = GetActor(ActorId);

                if (Actor == null)
                {
                    return(false);
                }

                if (Actor.Type == RoomActorType.UserCharacter)
                {
                    if (Actor.ReferenceId == Info.OwnerId && HasOngoingEvent)
                    {
                        StopEvent();
                    }

                    Trade Trade = TradeManager.GetTradeForUser(Actor.ReferenceId);

                    if (Trade != null)
                    {
                        TradeManager.StopTradeForUser(Trade.UserOne);
                        TradeManager.StopTradeForUser(Trade.UserTwo);

                        Session TargetSession = SessionManager.GetSessionByCharacterId(Actor.ReferenceId ==
                                                                                       Trade.UserOne ? Trade.UserTwo : Trade.UserOne);

                        if (TargetSession != null)
                        {
                            TargetSession.SendData(TradeAbortedComposer.Compose(Actor.ReferenceId));

                            RoomActor TargetActor = GetActorByReferenceId(TargetSession.CharacterId);

                            if (TargetActor != null)
                            {
                                TargetActor.RemoveStatus("trd");
                                TargetActor.UpdateNeeded = true;
                            }
                        }
                    }
                }

                foreach (RoomActor _Actor in mActors.Values)
                {
                    if (_Actor.Type == RoomActorType.AiBot)
                    {
                        if (_Actor.Id == Actor.Id)
                        {
                            Bot SelfBot = ((Bot)_Actor.ReferenceObject);
                            SelfBot.Brain.OnSelfLeaveRoom(this);

                            if (SelfBot.IsPet)
                            {
                                mPetCount--;
                            }
                        }
                        else
                        {
                            ((Bot)_Actor.ReferenceObject).Brain.OnUserLeave(this, Actor);
                        }
                    }
                }

                Success = mActors.Remove(ActorId);

                if (Success)
                {
                    BroadcastMessage(RoomUserRemovedComposer.Compose(ActorId));
                    MarkActorCountSyncNeeded();
                }
            }

            return(Success);
        }