Beispiel #1
0
        public ActionResult Detail(int id = 0)
        {
            ItemDao itemDao = new ItemDao();
            var     item    = itemDao.GetItem(id);

            if (item == null)
            {
                return(RedirectToAction("Error"));
            }

            return(View(item));
        }
        protected void BtnUpdate_OnClick(object sender, EventArgs e)
        {
            //Getting the current row and from that row getting the item object based
            //on its item id
            var currentRow = (GridViewRow)(((Button)sender)).NamingContainer;
            var id         = int.Parse(((HiddenField)GrdAdmin.Rows[currentRow.RowIndex].FindControl("ItemId")).Value);
            var item       = _itemDao.GetItem(id);

            //Setting session variables for both the item object as well as its corresponding item id
            Session["Item"]   = item;
            Session["ItemId"] = id;

            //Redirecting admin to the edit form
            Response.Redirect("AdminEditForm.aspx");
        }
Beispiel #3
0
        /// <summary>
        /// Try and resolve an item inside a room or persons inventory
        /// </summary>
        /// <param name="itemId">the item GUID</param>
        /// <returns>the tiem</returns>
        public Item ResolveItem(string itemId = null, ItemData itemData = null)
        {
            if (itemData == null)
            {
                itemData = ItemDao.GetItem(itemId);
            }

            if (itemData == null)
            {
                return(null);
            }

            var room = RoomManager.Instance.GetRoom(itemData.RoomId);

            if (room == null)
            {
                var player = PlayerManager.Instance.GetPlayerById(itemData.RoomId);

                if (player != null)
                {
                    return(player.Inventory.GetItem(itemData.Id.ToString()));
                }
            }
            else
            {
                if (room.ItemManager.Items == null)
                {
                    room.ItemManager.Load();
                }

                return(room.ItemManager.GetItem(itemData.Id.ToString()));
            }


            return(null);
        }
Beispiel #4
0
 public Item GetItem(int id)
 {
     return(_itemDao.GetItem(id));
 }
 public Item GetItem(String itemName)
 {
     return(idao.GetItem(itemName));
 }
        public override void OnInteract(IEntity entity, int requestData)
        {
            var roomUser = entity.RoomEntity;
            var room     = entity.RoomEntity.Room;

            if (!string.IsNullOrEmpty(roomUser.AuthenticateTeleporterId))
            {
                return;
            }

            Position front = Item.Position.GetSquareInFront();

            if (front != roomUser.Position && Item.Position != roomUser.Position)
            {
                roomUser.Move(front.X, front.Y);
                return;
            }

            var teleporterData = (TeleporterExtraData)GetJsonObject();

            string   pairId = ((TeleporterExtraData)GetJsonObject()).LinkedItem;
            ItemData targetTeleporterData = ItemDao.GetItem(pairId);

            Item.UpdateState(TELEPORTER_OPEN);

            roomUser.Move(Item.Position.X, Item.Position.Y);
            roomUser.WalkingAllowed = false;

            // Broken link, make user walk in then walk out
            if (string.IsNullOrEmpty(pairId) || targetTeleporterData == null || RoomManager.Instance.GetRoom(targetTeleporterData.RoomId) == null)
            {
                Task.Delay(1000).ContinueWith(t =>
                {
                    roomUser.Move(
                        Item.Position.GetSquareInFront().X,
                        Item.Position.GetSquareInFront().Y
                        );
                });


                Task.Delay(2000).ContinueWith(t =>
                {
                    Item.UpdateState(TELEPORTER_CLOSE);
                });

                Task.Delay(2500).ContinueWith(t =>
                {
                    roomUser.WalkingAllowed = true;
                });

                return;
            }

            var targetTeleporter = ItemManager.Instance.ResolveItem(targetTeleporterData.Id.ToString());
            var pairedTeleporter = targetTeleporter ?? new Item(targetTeleporterData);
            var pairedData       = ((TeleporterExtraData)pairedTeleporter.Interactor.GetJsonObject());

            roomUser.AuthenticateTeleporterId = pairedTeleporter.Data.Id.ToString();

            // Check if the user is inside the teleporter, if so, walk out. Useful if the user is stuck inside.
            if (Item.Position == roomUser.Position &&
                !RoomTile.IsValidTile(roomUser.Room, entity, Item.Position.GetSquareInFront()))
            {
                Item.UpdateState(TELEPORTER_EFFECTS);

                Task.Delay(1000).ContinueWith(t =>
                {
                    if (string.IsNullOrEmpty(roomUser.AuthenticateTeleporterId))
                    {
                        return;
                    }

                    Item.UpdateState(TELEPORTER_CLOSE);
                });

                Task.Delay(2000).ContinueWith(t =>
                {
                    if (string.IsNullOrEmpty(roomUser.AuthenticateTeleporterId))
                    {
                        return;
                    }

                    if (pairedTeleporter.Data.RoomId == Item.Data.RoomId)
                    {
                        pairedTeleporter.UpdateState(TELEPORTER_EFFECTS);

                        var newPosition      = pairedTeleporter.Position.Copy();
                        newPosition.Rotation = pairedTeleporter.Position.Rotation;

                        roomUser.Warp(newPosition, instantUpdate: true);
                    }
                    else
                    {
                        roomUser.AuthenticateRoomId = pairedTeleporter.Data.RoomId;
                        roomUser.Room.Forward(roomUser.Entity);
                    }
                });

                // Handle teleporting in the same room
                if (pairedTeleporter.Data.RoomId == Item.Data.RoomId)
                {
                    Task.Delay(3000).ContinueWith(t =>
                    {
                        if (string.IsNullOrEmpty(roomUser.AuthenticateTeleporterId))
                        {
                            return;
                        }

                        pairedTeleporter.UpdateState(TELEPORTER_OPEN);

                        roomUser.Move(
                            pairedTeleporter.Position.GetSquareInFront().X,
                            pairedTeleporter.Position.GetSquareInFront().Y);

                        roomUser.WalkingAllowed = true;
                    });

                    Task.Delay(4000).ContinueWith(t =>
                    {
                        if (string.IsNullOrEmpty(roomUser.AuthenticateTeleporterId))
                        {
                            return;
                        }

                        pairedTeleporter.UpdateState(TELEPORTER_CLOSE);
                        roomUser.AuthenticateTeleporterId = null;
                    });
                }

                return;
            }

            // Resume normal teleportation
            Task.Delay(1000).ContinueWith(t =>
            {
                if (string.IsNullOrEmpty(roomUser.AuthenticateTeleporterId))
                {
                    return;
                }

                Item.UpdateState(TELEPORTER_EFFECTS);
            });

            Task.Delay(1500).ContinueWith(t =>
            {
                if (string.IsNullOrEmpty(roomUser.AuthenticateTeleporterId))
                {
                    return;
                }

                Item.UpdateState(TELEPORTER_CLOSE);

                if (pairedTeleporter.Data.RoomId != Item.Data.RoomId)
                {
                    roomUser.AuthenticateRoomId = pairedTeleporter.Room.Data.Id;
                    pairedTeleporter.Room.Forward(roomUser.Entity);
                }
                else
                {
                    roomUser.Warp(pairedTeleporter.Position.Copy(), instantUpdate: true);
                }

                if (pairedTeleporter.Data.RoomId == Item.Data.RoomId)
                {
                    pairedTeleporter.UpdateState(TELEPORTER_EFFECTS);
                }
            });

            if (pairedTeleporter.Data.RoomId == Item.Data.RoomId)
            {
                Task.Delay(3000).ContinueWith(t =>
                {
                    if (roomUser.RoomId != room.Data.Id)
                    {
                        roomUser.AuthenticateTeleporterId = null;
                        return;
                    }

                    pairedTeleporter.UpdateState(TELEPORTER_OPEN);

                    roomUser.WalkingAllowed = true;
                    roomUser.Move(
                        pairedTeleporter.Position.GetSquareInFront().X,
                        pairedTeleporter.Position.GetSquareInFront().Y);
                });

                Task.Delay(4000).ContinueWith(t =>
                {
                    if (roomUser.RoomId != room.Data.Id)
                    {
                        roomUser.AuthenticateTeleporterId = null;
                        return;
                    }

                    roomUser.AuthenticateTeleporterId = null;

                    if (pairedTeleporter.Data.RoomId == Item.Data.RoomId)
                    {
                        pairedTeleporter.UpdateState(TELEPORTER_CLOSE);
                    }
                    else
                    {
                        pairedTeleporter.UpdateState(TELEPORTER_CLOSE);
                    }
                });
            }
        }