private void MoveContainerToGround()
        {
            IItem extraItem;
            var   itemToUpdate = Thing as IItem;

            if (FromContainer == null || ToTile == null || itemToUpdate == null)
            {
                return;
            }

            // attempt to remove from the source container
            if (!FromContainer.RemoveContent(itemToUpdate.Type.TypeId, FromIndex, Count, out extraItem))
            {
                return;
            }

            if (extraItem != null)
            {
                itemToUpdate = extraItem;
            }

            // add the remaining item to the destination tile.
            IThing thing = itemToUpdate;

            ToTile.AddThing(ref thing, itemToUpdate.Count);

            // notify all spectator players of that tile.
            Game.Instance.NotifySpectatingPlayers(conn => new TileUpdatedNotification(conn, ToTile.Location, Game.Instance.GetMapTileDescription(conn.PlayerId, ToTile.Location)), ToTile.Location);

            // and handle collision.
            if (!ToTile.HandlesCollision)
            {
                return;
            }

            foreach (var itemWithCollision in ToTile.ItemsWithCollision)
            {
                var collisionEvents = Game.Instance.EventsCatalog[ItemEventType.Collision].Cast <CollisionItemEvent>();

                var candidate = collisionEvents.FirstOrDefault(e => e.ThingIdOfCollision == itemWithCollision.Type.TypeId && e.Setup(itemWithCollision, thing, Requestor as IPlayer) && e.CanBeExecuted);

                // Execute all actions.
                candidate?.Execute();
            }
        }
Exemplo n.º 2
0
        private void MoveFromSlotToGround()
        {
            if (Item == null || Requestor == null)
            {
                return;
            }

            bool partialRemove;

            // attempt to remove the item from the inventory
            var movingItem = Requestor.Inventory?.Remove(FromSlot, Count, out partialRemove);

            if (movingItem == null)
            {
                return;
            }

            // add the remaining item to the destination tile.
            IThing thing = movingItem;

            ToTile.AddThing(ref thing, movingItem.Count);

            // notify all spectator players of that tile.
            Game.Instance.NotifySpectatingPlayers(conn => new TileUpdatedNotification(conn, ToTile.Location, Game.Instance.GetMapTileDescription(conn.PlayerId, ToTile.Location)), ToTile.Location);

            // and handle collision.
            if (!ToTile.HandlesCollision)
            {
                return;
            }

            foreach (var itemWithCollision in ToTile.ItemsWithCollision)
            {
                var collisionEvents = Game.Instance.EventsCatalog[ItemEventType.Collision].Cast <CollisionItemEvent>();

                var candidate = collisionEvents.FirstOrDefault(e => e.ThingIdOfCollision == itemWithCollision.Type.TypeId && e.Setup(itemWithCollision, thing, Requestor as IPlayer) && e.CanBeExecuted);

                // Execute all actions.
                candidate?.Execute();
            }
        }
Exemplo n.º 3
0
        private void MoveThing()
        {
            if (FromTile == null || ToTile == null)
            {
                return;
            }

            var thing = Thing;

            FromTile.RemoveThing(ref thing, Count);

            ToTile.AddThing(ref thing, thing.Count);

            if (thing is ICreature)
            {
                Game.Instance.NotifySpectatingPlayers(
                    conn => new CreatureMovedNotification(
                        conn,
                        (thing as ICreature).CreatureId,
                        FromLocation,
                        FromStackPos,
                        ToLocation,
                        ToTile.GetStackPosition(Thing),
                        IsTeleport),
                    FromLocation,
                    ToLocation);
            }
            else
            {
                // TODO: see if we can save network bandwith here:
                // Game.Instance.NotifySpectatingPlayers(
                //        (conn) => new ItemMovedNotification(
                //            conn,
                //            (IItem)Thing,
                //            FromLocation,
                //            oldStackpos,
                //            ToLocation,
                //            destinationTile.GetStackPosition(Thing),
                //            false
                //        ),
                //        FromLocation,
                //        ToLocation
                //    );
                Game.Instance.NotifySpectatingPlayers(conn => new TileUpdatedNotification(conn, FromLocation, Game.Instance.GetMapTileDescription(conn.PlayerId, FromLocation)), FromLocation);

                Game.Instance.NotifySpectatingPlayers(conn => new TileUpdatedNotification(conn, ToLocation, Game.Instance.GetMapTileDescription(conn.PlayerId, ToLocation)), ToLocation);
            }

            if (FromTile.HandlesSeparation)
            {
                foreach (var itemWithSeparation in FromTile.ItemsWithSeparation)
                {
                    var separationEvents = Game.Instance.EventsCatalog[ItemEventType.Separation].Cast <SeparationItemEvent>();

                    var candidate = separationEvents.FirstOrDefault(e => e.ThingIdOfSeparation == itemWithSeparation.Type.TypeId && e.Setup(itemWithSeparation, thing, Requestor as IPlayer) && e.CanBeExecuted);

                    // Execute all actions.
                    candidate?.Execute();
                }
            }

            if (ToTile.HandlesCollision)
            {
                foreach (var itemWithCollision in ToTile.ItemsWithCollision)
                {
                    var collisionEvents = Game.Instance.EventsCatalog[ItemEventType.Collision].Cast <CollisionItemEvent>();

                    var candidate = collisionEvents.FirstOrDefault(e => e.ThingIdOfCollision == itemWithCollision.Type.TypeId && e.Setup(itemWithCollision, thing, Requestor as IPlayer) && e.CanBeExecuted);

                    // Execute all actions.
                    candidate?.Execute();
                }
            }
        }