Exemplo n.º 1
0
        /// <summary>
        /// Client:
        ///     Handles any additional usage stuff. When this is called, it is to be assumed that the Server has recognized
        ///     the IUsableEntity as having been successfully used.
        /// Server:
        ///     Attempts to use this IUsableEntity on the <paramref name="charEntity"/>.
        /// </summary>
        /// <param name="charEntity">CharacterEntity that is trying to use this IUsableEntity. Can be null.</param>
        /// <returns>True if this IUsableEntity was successfully used, else false. On the Client, this is generally
        /// unused.</returns>
        public override bool Use(DynamicEntity charEntity)
        {
            if (Used != null)
            {
                Used.Raise(this, EventArgsHelper.Create(charEntity));
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Client:
        ///     Handles any additional usage stuff. When this is called, it is to be assumed that the Server has recognized
        ///     the IUsableEntity as having been successfully used.
        /// Server:
        ///     Attempts to use this IUsableEntity on the <paramref name="charEntity"/>.
        /// </summary>
        /// <param name="charEntity">CharacterEntity that is trying to use this IUsableEntity. Can be null.</param>
        /// <returns>True if this IUsableEntity was successfully used, else false. On the Client, this is generally
        /// unused.</returns>
        public override bool Use(DynamicEntity charEntity)
        {
            // Check if we can use
            if (!CanUse(charEntity))
            {
                return(false);
            }

            if (!Open)
            {
                Open = true; // For testing after we've tried it once, we'll open it!
                return(false);
            }

            // Teleport to a new map
            if (DestinationMap > 0)
            {
                var c = (Character)charEntity;
                if (c.Map.ID != DestinationMap)
                {
                    var newMap = c.World.GetMap(DestinationMap);
                    if (newMap == null)
                    {
                        const string errmsg = "Failed to teleport Character `{0}` - Invalid DestMap `{1}`.";
                        Debug.Fail(string.Format(errmsg, c, this));
                        if (log.IsErrorEnabled)
                        {
                            log.ErrorFormat(errmsg, c, this);
                        }
                        return(false);
                    }

                    c.Teleport(newMap, Destination);
                }
            }

            // Teleport the CharacterEntity to our predefined location
            charEntity.Position = Destination;

            // Notify listeners
            if (Used != null)
            {
                Used.Raise(this, EventArgsHelper.Create(charEntity));
            }

            // Successfully used
            return(true);
        }