Ejemplo n.º 1
0
        private static bool HandleDispenser(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
            case ItemEventType.Moved:
            {
                RoomActor InteractingActor = (Item.TemporaryInteractionReferenceIds.ContainsKey(0) ?
                                              Instance.GetActor(Item.TemporaryInteractionReferenceIds[0]) : null);

                if (InteractingActor != null)
                {
                    InteractingActor.UnblockWalking();
                }

                goto case ItemEventType.InstanceLoaded;
            }

            case ItemEventType.InstanceLoaded:
            {
                if (Item.DisplayFlags != "0")
                {
                    Item.DisplayFlags = "0";
                    Item.BroadcastStateUpdate(Instance);
                }

                return(true);
            }

            case ItemEventType.Interact:
            {
                RoomActor InteractingActor = Instance.GetActorByReferenceId(Session.CharacterId);

                if (InteractingActor == null)
                {
                    return(true);
                }

                if (InteractingActor.Position.X != Item.SquareInFront.X || InteractingActor.Position.Y !=
                    Item.SquareInFront.Y)
                {
                    InteractingActor.MoveToItemAndInteract(Item, RequestData, Opcode);
                    return(true);
                }

                if (Item.TemporaryInteractionReferenceIds.Count == 0)
                {
                    Item.TemporaryInteractionReferenceIds.Add(0, InteractingActor.Id);

                    InteractingActor.BlockWalking();
                    InteractingActor.PositionToSet = Item.SquareInFront;

                    int NewRot = Rotation.Calculate(InteractingActor.Position.GetVector2(),
                                                    Item.RoomPosition.GetVector2());

                    if (InteractingActor.BodyRotation != NewRot)
                    {
                        InteractingActor.BodyRotation = NewRot;
                        InteractingActor.HeadRotation = NewRot;
                        InteractingActor.UpdateNeeded = true;
                    }

                    Item.DisplayFlags = "1";
                    Item.BroadcastStateUpdate(Instance);

                    Item.RequestUpdate(2);
                }

                return(true);
            }

            case ItemEventType.UpdateTick:
            {
                if (Item.DisplayFlags != "0")
                {
                    Item.DisplayFlags = "0";
                    Item.BroadcastStateUpdate(Instance);
                }

                if (Item.TemporaryInteractionReferenceIds.Count < 1)
                {
                    return(true);
                }

                RoomActor InteractingActor = Instance.GetActor(Item.TemporaryInteractionReferenceIds[0]);
                Item.TemporaryInteractionReferenceIds.Clear();

                if (InteractingActor == null)
                {
                    return(true);
                }

                InteractingActor.CarryItem(DrinkSetManager.GetRandomDrinkForSet(Item.Definition.BehaviorData));

                int NewRot = Rotation.Calculate(InteractingActor.Position.GetVector2(),
                                                Item.RoomPosition.GetVector2());

                if (InteractingActor.BodyRotation != NewRot)
                {
                    InteractingActor.BodyRotation = NewRot;
                    InteractingActor.HeadRotation = NewRot;
                    InteractingActor.UpdateNeeded = true;
                }

                InteractingActor.UnblockWalking();
                return(true);
            }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public override void PerformUpdate(RoomInstance Instance)
        {
            if (mNextSpeechAttempt <= 0)
            {
                string Message = BotManager.GetRandomSpeechForBotDefinition(mSelfBot.DefinitionId);

                if (Message != null && Message.Length > 0)
                {
                    mSelfActor.Chat(Message);
                }

                mNextSpeechAttempt = RandomGenerator.GetNext(0, 255);
            }
            else
            {
                mNextSpeechAttempt--;
            }

            if (!mSelfActor.IsMoving && mNextMovementAttempt <= 0)
            {
                switch (mSelfBot.WalkMode)
                {
                    default:
                    case BotWalkMode.STAND:

                        break;

                    case BotWalkMode.FREEROAM:

                        mSelfActor.MoveTo(new Vector2(RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeX - 1),
                            RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeY - 1)));
                        break;

                    case BotWalkMode.SPECIFIED_RANGE:

                        ReadOnlyCollection<Vector2> Possibilites = mSelfBot.PredefinedPositions;
                        mSelfActor.MoveTo(Possibilites[RandomGenerator.GetNext(0, (Possibilites.Count - 1))]);
                        break;
                }

                mNextMovementAttempt = RandomGenerator.GetNext(0, 180);
                mNeedsRotation = true;
            }
            else
            {
                mNextMovementAttempt--;

                if (!mSelfActor.IsMoving)
                {
                    if (mMovingToServePos)
                    {
                        mMovingToServePos = false;
                        mSelfActor.CarryItem(mServingItemId);
                        mSelfActor.MoveTo(mActorServePos);
                    }
                    else if (mServingItemId > 0)
                    {
                        mSelfActor.CarryItem(0);

                        RoomActor TargetActor = Instance.GetActor(mServingActorId);

                        if (TargetActor != null)
                        {
                            TargetActor.CarryItem(mServingItemId);

                            int NewRot = Rotation.Calculate(mActorServePos, TargetActor.Position.GetVector2());

                            mSelfActor.HeadRotation = NewRot;
                            mSelfActor.BodyRotation = NewRot;
                            mNeedsRotation = true;

                            mSelfActor.UpdateNeeded = true;
                        }

                        mServingItemId = 0;
                    }
                    else if (mNeedsRotation && mSelfBot.Rotation >= 0)
                    {
                        mSelfActor.BodyRotation = mSelfBot.Rotation;
                        mSelfActor.HeadRotation = mSelfBot.Rotation;
                        mNeedsRotation = false;
                    }
                }
            }
        }