Exemplo n.º 1
0
        /// <summary>
        /// Drops item to the map as an ItemMonster.
        /// </summary>
        /// <remarks>
        /// Items are typically dropped by "tossing" them from the source,
        /// such as a killed monster. The given position is the initial
        /// position, and the item is then tossed in the given direction,
        /// by the distance.
        /// </remarks>
        /// <param name="map">Map to drop to the item on.</param>
        /// <param name="position">Initial position of the drop item.</param>
        /// <param name="direction">Direction to toss the item in.</param>
        /// <param name="distance">Distance to toss the item.</param>
        public ItemMonster Drop(Map map, Position position, Direction direction, float distance)
        {
            // ZC_NORMAL_ItemDrop animates the item flying from its
            // initial drop position to its final position. To keep
            // everything in sync, we use the monster's position as
            // the drop position, then add the item to the map,
            // and then make it fly and set the final position.
            // the direction of the item becomes the direction
            // it flies in.
            // FromGround is necessary for the client to attempt to
            // pick up the item. Might act as "IsYourDrop" for items.

            var itemMonster = ItemMonster.Create(this);
            var flyDropPos  = position.GetRelative(direction, distance);

            itemMonster.Position      = position;
            itemMonster.Direction     = direction;
            itemMonster.FromGround    = true;
            itemMonster.DisappearTime = DateTime.Now.AddSeconds(ChannelServer.Instance.Conf.World.DropDisappearSeconds);

            map.AddMonster(itemMonster);

            itemMonster.Position = flyDropPos;
            Send.ZC_NORMAL_ItemDrop(itemMonster, direction, distance);

            return(itemMonster);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates item monster from item.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static ItemMonster Create(Item item)
        {
            if (!ChannelServer.Instance.Data.ItemMonsterDb.TryFind(item.Id, out var data))
            {
                throw new ArgumentException($"No monster id found for item '{item.Id}'.");
            }

            var monster = new ItemMonster(item, data.MonsterId);

            return(monster);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Turns item monster into an item and adds it to the character's
        /// inventory.
        /// </summary>
        /// <param name="itemMonster"></param>
        public void PickUp(ItemMonster itemMonster)
        {
            itemMonster.PickedUp = true;
            itemMonster.Item.ClearProtections();

            // Play pickup animation. This is what actually makes the item
            // disappear, the client doesn't seem to react to ZC_LEAVE in
            // the case of items. Or at least not reliably? It's weird.
            Send.ZC_ITEM_GET(this, itemMonster);

            // Add the item to the inventory
            this.Inventory.Add(itemMonster.Item, InventoryAddType.PickUp);

            // Remove it from the map, so it can't be picked up again.
            this.Map.RemoveMonster(itemMonster);
        }