public ThingMovementContainerToGround(uint creatureRequestingId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1)
            : base(creatureRequestingId, EvaluationTime.OnExecute)
        {
            // intentionally left thing null check out. Handled by Perform().
            var requestor = RequestorId == 0 ? null : Game.Instance.GetCreatureWithId(RequestorId);

            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.");
            }

            if (requestor == null)
            {
                throw new ArgumentNullException(nameof(requestor));
            }

            Thing = thingMoving;
            Count = count;

            FromLocation  = fromLocation;
            FromContainer = (requestor as IPlayer)?.GetContainer(FromLocation.Container);
            FromIndex     = (byte)FromLocation.Z;

            ToLocation = toLocation;
            ToTile     = Game.Instance.GetTileAt(ToLocation);

            Conditions.Add(new CanThrowBetweenEventCondition(RequestorId, requestor.Location, ToLocation));
            Conditions.Add(new GrabberHasContainerOpenEventCondition(RequestorId, FromContainer));
            Conditions.Add(new ContainerHasItemAndEnoughAmountEventCondition(Thing as IItem, FromContainer, FromIndex, Count));
            Conditions.Add(new LocationNotObstructedEventCondition(RequestorId, Thing, ToLocation));
            Conditions.Add(new LocationHasTileWithGroundEventCondition(ToLocation));

            ActionsOnPass.Add(new GenericEventAction(MoveContainerToGround));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericEvent"/> class.
        /// </summary>
        /// <param name="requestorId">The id of the creature requesting this event.</param>
        /// <param name="conditions">The conditions of the event.</param>
        /// <param name="onSuccessActions">The actions to run if the event passes conditions.</param>
        /// <param name="onFailActions">The actions to run if the event fails to pass conditions.</param>
        /// <param name="evaluationTime">Optional. The time on which the event's conditions should be evaluated. Default is <see cref="EvaluationTime.OnBoth"/>.</param>
        public GenericEvent(uint requestorId, IEventCondition [] conditions, IEventAction [] onSuccessActions, IEventAction[] onFailActions, EvaluationTime evaluationTime = EvaluationTime.OnBoth)
            : base(requestorId, evaluationTime)
        {
            if (conditions != null)
            {
                foreach (var condition in conditions)
                {
                    Conditions.Add(condition);
                }
            }

            if (onSuccessActions != null)
            {
                foreach (var action in onSuccessActions)
                {
                    ActionsOnPass.Add(action);
                }
            }

            if (onFailActions != null)
            {
                foreach (var action in onFailActions)
                {
                    ActionsOnFail.Add(action);
                }
            }
        }
        public ThingMovementGroundToSlot(uint creatureRequestingId, IThing thingMoving, Location fromLocation, byte fromStackPos, Location toLocation, byte count = 1)
            : base(creatureRequestingId, EvaluationTime.OnExecute)
        {
            if (count == 0 || count > 100)
            {
                throw new ArgumentException($"Invalid count {count}.", nameof(count));
            }

            FromLocation = fromLocation;
            FromStackPos = fromStackPos;
            FromTile     = Game.Instance.GetTileAt(FromLocation);

            ToLocation = toLocation;
            ToSlot     = (byte)toLocation.Slot;

            Thing = thingMoving;
            Count = count;

            var droppingItem = Requestor?.Inventory?[ToSlot];

            Conditions.Add(new SlotHasContainerAndContainerHasEnoughCapacityEventCondition(RequestorId, droppingItem));
            Conditions.Add(new GrabberHasEnoughCarryStrengthEventCondition(RequestorId, Thing, droppingItem));
            Conditions.Add(new ThingIsTakeableEventCondition(RequestorId, Thing));
            Conditions.Add(new LocationsMatchEventCondition(Thing?.Location ?? default(Location), FromLocation));
            Conditions.Add(new TileContainsThingEventCondition(Thing, FromLocation, Count));

            ActionsOnPass.Add(new GenericEventAction(MoveFromGroudToSlot));
        }
Esempio n. 4
0
        public ThingMovementSlotToGround(uint creatureRequestingId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1)
            : base(creatureRequestingId, EvaluationTime.OnExecute)
        {
            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.", nameof(count));
            }

            FromLocation = fromLocation;
            FromSlot     = (byte)fromLocation.Slot;

            ToLocation = toLocation;
            ToTile     = Game.Instance.GetTileAt(ToLocation);

            Item  = thingMoving as IItem;
            Count = count;

            if (Requestor != null)
            {
                Conditions.Add(new CanThrowBetweenEventCondition(RequestorId, Requestor.Location, ToLocation));
            }

            Conditions.Add(new SlotContainsItemAndCountEventCondition(creatureRequestingId, Item, FromSlot, Count));
            Conditions.Add(new LocationNotObstructedEventCondition(RequestorId, Item, ToLocation));
            Conditions.Add(new LocationHasTileWithGroundEventCondition(ToLocation));

            ActionsOnPass.Add(new GenericEventAction(MoveFromSlotToGround));
        }
Esempio n. 5
0
        public ThingMovementSlotToContainer(uint requestorId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1)
            : base(requestorId, EvaluationTime.OnExecute)
        {
            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.", nameof(count));
            }

            if (Requestor == null)
            {
                throw new ArgumentException("Invalid requestor id.", nameof(requestorId));
            }

            FromLocation = fromLocation;
            FromSlot     = (byte)FromLocation.Slot;

            ToLocation  = toLocation;
            ToContainer = (Requestor as IPlayer)?.GetContainer(ToLocation.Container);
            ToIndex     = (byte)ToLocation.Z;

            Item  = thingMoving as IItem;
            Count = count;

            Conditions.Add(new SlotContainsItemAndCountEventCondition(RequestorId, Item, FromSlot, Count));
            Conditions.Add(new GrabberHasContainerOpenEventCondition(RequestorId, ToContainer));
            Conditions.Add(new ContainerHasEnoughCapacityEventCondition(ToContainer));

            ActionsOnPass.Add(new GenericEventAction(MoveSlotToContainer));
        }
Esempio n. 6
0
        public ThingMovementOnMap(uint creatureRequestingId, IThing thingMoving, Location fromLocation, byte fromStackPos, Location toLocation, byte count = 1, bool isTeleport = false)
            : base(creatureRequestingId, EvaluationTime.OnBoth)
        {
            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.", nameof(count));
            }

            FromLocation = fromLocation;
            FromStackPos = fromStackPos;
            FromTile     = Game.Instance.GetTileAt(FromLocation);

            ToLocation = toLocation;
            ToTile     = Game.Instance.GetTileAt(ToLocation);

            Thing      = thingMoving;
            Count      = count;
            IsTeleport = isTeleport;

            if (!isTeleport && Requestor != null)
            {
                Conditions.Add(new CanThrowBetweenEventCondition(RequestorId, FromLocation, ToLocation));
            }

            Conditions.Add(new RequestorIsInRangeToMoveEventCondition(RequestorId, FromLocation));
            Conditions.Add(new LocationNotObstructedEventCondition(RequestorId, Thing, ToLocation));
            Conditions.Add(new LocationHasTileWithGroundEventCondition(ToLocation));
            Conditions.Add(new UnpassItemsInRangeEventCondition(RequestorId, Thing, ToLocation));
            Conditions.Add(new LocationsMatchEventCondition(Thing?.Location ?? default(Location), FromLocation));
            Conditions.Add(new TileContainsThingEventCondition(Thing, FromLocation, Count));

            ActionsOnPass.Add(new GenericEventAction(MoveThing));
        }
Esempio n. 7
0
        public ThingMovementContainerToContainer(uint requestorId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1)
            : base(requestorId, EvaluationTime.OnExecute)
        {
            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.", nameof(count));
            }

            if (Requestor == null)
            {
                throw new ArgumentException("Invalid requestor id.", nameof(requestorId));
            }

            Thing = thingMoving;
            Count = count;

            FromLocation  = fromLocation;
            FromContainer = (Requestor as IPlayer)?.GetContainer(FromLocation.Container);
            FromIndex     = (byte)FromLocation.Z;

            ToLocation  = toLocation;
            ToContainer = (Requestor as IPlayer)?.GetContainer(ToLocation.Container);
            ToIndex     = (byte)ToLocation.Z;

            if (FromContainer?.HolderId != ToContainer?.HolderId && ToContainer?.HolderId == RequestorId)
            {
                Conditions.Add(new GrabberHasEnoughCarryStrengthEventCondition(RequestorId, Thing));
            }

            Conditions.Add(new GrabberHasContainerOpenEventCondition(RequestorId, FromContainer));
            Conditions.Add(new ContainerHasItemAndEnoughAmountEventCondition(Thing as IItem, FromContainer, FromIndex, Count));
            Conditions.Add(new GrabberHasContainerOpenEventCondition(RequestorId, ToContainer));

            ActionsOnPass.Add(new GenericEventAction(MoveBetweenContainers));
        }
Esempio n. 8
0
        public Notification(Connection connection)
            : base(connection?.PlayerId ?? 0, EvaluationTime.OnSchedule)
        {
            Connection      = connection ?? throw new ArgumentNullException(nameof(connection));
            ResponsePackets = new List <IPacketOutgoing>();

            ActionsOnPass.Add(new GenericEventAction(Send));
        }
Esempio n. 9
0
        public CreatureMovementOnMap(uint requestorId, ICreature creatureMoving, Location fromLocation, Location toLocation, bool isTeleport = false, byte count = 1)
            : base(requestorId, creatureMoving, fromLocation, creatureMoving.GetStackPosition(), toLocation, count, isTeleport)
        {
            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.", nameof(count));
            }

            AttemptedDirection = fromLocation.DirectionTo(toLocation, true);

            // don't add any conditions if this wasn't a creature requesting.
            if (!IsTeleport && Requestor != null)
            {
                Conditions.Add(new LocationNotAviodEventCondition(RequestorId, Thing, ToLocation));
                Conditions.Add(new LocationsAreDistantByEventCondition(FromLocation, ToLocation));
                Conditions.Add(new CreatureThrowBetweenFloorsEventCondition(RequestorId, Thing, ToLocation));
            }

            ActionsOnPass.Add(new GenericEventAction(MoveCreature));
        }
Esempio n. 10
0
        public ThingMovementSlotToSlot(uint requestorId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1)
            : base(requestorId, EvaluationTime.OnExecute)
        {
            // intentionally left thing null check out. Handled by Perform().
            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.");
            }

            FromLocation = fromLocation;
            FromSlot     = (byte)FromLocation.Slot;

            ToLocation = toLocation;
            ToSlot     = (byte)ToLocation.Slot;

            Item  = thingMoving as IItem;
            Count = count;

            Conditions.Add(new SlotContainsItemAndCountEventCondition(requestorId, Item, FromSlot, Count));

            ActionsOnPass.Add(new GenericEventAction(MoveBetweenSlots));
        }
        public ThingMovementGroundToContainer(uint requestorId, IThing thingMoving, Location fromLocation, byte fromStackPos, Location toLocation, byte count = 1)
            : base(requestorId, EvaluationTime.OnExecute)
        {
            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.");
            }

            if (Requestor == null)
            {
                throw new ArgumentException("Invalid requestor id.", nameof(requestorId));
            }

            Thing = thingMoving;
            Count = count;

            FromLocation = fromLocation;
            FromStackPos = fromStackPos;
            FromTile     = Game.Instance.GetTileAt(FromLocation);

            ToLocation  = toLocation;
            ToContainer = (Requestor as IPlayer)?.GetContainer(toLocation.Container);
            ToIndex     = (byte)ToLocation.Z;

            if (ToContainer != null && ToContainer.HolderId == RequestorId)
            {
                Conditions.Add(new GrabberHasEnoughCarryStrengthEventCondition(RequestorId, Thing));
            }

            Conditions.Add(new GrabberHasContainerOpenEventCondition(RequestorId, ToContainer));
            Conditions.Add(new ContainerHasEnoughCapacityEventCondition(ToContainer));
            Conditions.Add(new ThingIsTakeableEventCondition(RequestorId, Thing));
            Conditions.Add(new LocationsMatchEventCondition(Thing?.Location ?? default(Location), FromLocation));
            Conditions.Add(new TileContainsThingEventCondition(Thing, FromLocation, Count));

            ActionsOnPass.Add(new GenericEventAction(PickupToContainer));
        }
Esempio n. 12
0
        public ThingMovementContainerToSlot(uint requestorId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1)
            : base(requestorId, EvaluationTime.OnExecute)
        {
            if (count == 0)
            {
                throw new ArgumentException("Invalid count zero.", nameof(count));
            }

            if (Requestor == null)
            {
                throw new ArgumentException("Invalid requestor id.", nameof(requestorId));
            }

            Thing = thingMoving;
            Count = count;

            FromLocation  = fromLocation;
            FromContainer = (Requestor as IPlayer)?.GetContainer(FromLocation.Container);
            FromIndex     = (byte)FromLocation.Z;

            ToLocation = toLocation;
            ToSlot     = (byte)ToLocation.Slot;

            var droppingItem = Requestor.Inventory?[ToSlot];

            if (FromContainer != null && FromContainer.HolderId != RequestorId)
            {
                Conditions.Add(new GrabberHasEnoughCarryStrengthEventCondition(RequestorId, Thing, droppingItem));
            }

            Conditions.Add(new SlotHasContainerAndContainerHasEnoughCapacityEventCondition(RequestorId, droppingItem));
            Conditions.Add(new GrabberHasContainerOpenEventCondition(RequestorId, FromContainer));
            Conditions.Add(new ContainerHasItemAndEnoughAmountEventCondition(Thing as IItem, FromContainer, FromIndex, Count));

            ActionsOnPass.Add(new GenericEventAction(MoveContainerToSlot));
        }