Beispiel #1
0
        /// <summary>
        /// Gets the thing with the specified parameters or
        /// null if such a thing can't be found. Note: The thing
        /// must be visible for the player.
        /// </summary>
        /// <param name="player">The player for whom to get the item.</param>
        /// <param name="pos">The position of the item.</param>
        /// <param name="stackpos">The stackposition of the thing.</param>
        /// <param name="usePosZ">Use position.z for index instead of stackpos.</param>
        /// <returns>The thing or null if can't be found.</returns>
        public Thing GetThing(Player player, Position pos, byte stackpos, bool usePosZ)
        {
            //container/inventory
            if (CarryingPos(pos)) {
                if (ContainerPos(pos)) { //From container
                    int containerIndex = pos.y - CONTAINER_HEADER;
                    int itemIndex = usePosZ ? pos.z : stackpos;
                    Container container = player.GetContainerByIndex(containerIndex);
                    if (container == null) {
                        return null;
                    }
                    return container.GetItemByIndex(itemIndex);
                } else { //inventory
                    return player.GetInventoryItem((byte)pos.y);
                }
            } else if (player.CanSee(pos)) { //ground
                if (stackpos == Constants.STACKPOS_TOP_ITEM) {
                    return map.GetTopThing(pos);
                } else {
                    Tile tile = map.GetTile(pos);
                    if (tile == null) {
                        return null;
                    }
                    return tile.GetThing(stackpos);
                }
            }

            return null;
        }