示例#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;
        }
示例#2
0
        /// <summary>
        /// Client: 
        ///     Checks if the Client's character can attempt to use the IUsableEntity. If false, the Client
        ///     wont even attempt to use the IUsableEntity. If true, the Client will attempt to use it, but
        ///     it is not guarenteed the Server will also allow it to be used.
        /// Server:
        ///     Checks if the specified Entity may use the IUsableEntity.
        /// </summary>
        /// <param name="charEntity">The CharacterEntity that is trying to use this IUsableEntity. For the Client,
        /// this will always be the User's Character. Can be null.</param>
        /// <returns>True if this IUsableEntity can be used by the <paramref name="charEntity"/>, else false.</returns>
        public override bool CanUse(DynamicEntity charEntity)
        {
            // Check that the base usage rules pass
            if (!base.CanUse(charEntity))
                return false;

            // Add custom rules here

            return true;
        }
示例#3
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;
        }
示例#4
0
 public static PacketWriter UpdateVelocityAndPosition(DynamicEntity dynamicEntity, TickCount currentTime)
 {
     var pw = GetWriter();
     UpdateVelocityAndPosition(pw, dynamicEntity, currentTime);
     return pw;
 }
示例#5
0
 public static void UpdateVelocityAndPosition(PacketWriter pw, DynamicEntity dynamicEntity, TickCount currentTime)
 {
     pw.Write(ServerPacketID.UpdateVelocityAndPosition);
     pw.Write(dynamicEntity.MapEntityIndex);
     dynamicEntity.SerializePositionAndVelocity(pw, currentTime);
 }
示例#6
0
 public static PacketWriter SynchronizeDynamicEntity(DynamicEntity dynamicEntity)
 {
     var pw = GetWriter();
     SynchronizeDynamicEntity(pw, dynamicEntity);
     return pw;
 }
示例#7
0
 public static void SynchronizeDynamicEntity(PacketWriter pw, DynamicEntity dynamicEntity)
 {
     pw.Write(ServerPacketID.SynchronizeDynamicEntity);
     pw.Write(dynamicEntity.MapEntityIndex);
     dynamicEntity.Serialize(pw);
 }
示例#8
0
 public static PacketWriter CreateDynamicEntity(DynamicEntity dynamicEntity)
 {
     var pw = GetWriter();
     CreateDynamicEntity(pw, dynamicEntity);
     return pw;
 }
示例#9
0
 public static void CreateDynamicEntity(PacketWriter pw, DynamicEntity dynamicEntity)
 {
     pw.Write(ServerPacketID.CreateDynamicEntity);
     pw.Write(dynamicEntity.MapEntityIndex);
     DynamicEntityFactory.Instance.Write(pw, dynamicEntity, true);
 }
        /// <summary>
        /// Writes a <see cref="DynamicEntity"/> to a stream.
        /// </summary>
        /// <param name="writer"><see cref="IValueWriter"/> to write the <see cref="DynamicEntity"/> to.</param>
        /// <param name="dEntity"><see cref="DynamicEntity"/> to write to the stream.</param>
        /// <param name="compact">Whether or not the <see cref="DynamicEntity"/> is to be stored in a way that is optimized
        /// for size. The compact format is not guaranteed to remain stable. Because of this, the compact format should
        /// never be used for persistent storage. It is recommended to only use the compact format in network IO.
        /// The <paramref name="compact"/> value must be the same when reading and writing. That is, you cannot write
        /// with <paramref name="compact"/> set to true, then read back with it set to false, or vise versa.</param>
        /// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="dEntity"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="dEntity"/> is not of a valid that <see cref="Type"/>
        /// that is supported by this factory.</exception>
        public void Write(IValueWriter writer, DynamicEntity dEntity, bool compact = false)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");
            if (dEntity == null)
                throw new ArgumentNullException("dEntity");

            var type = dEntity.GetType();
            var typeName = _typeCollection[type];

            // FUTURE: Make use of the "compact" argument to write the typeName as an ID, not a string. Difficulty is finding a reliable way to share the IDs to use.

            if (typeName == null)
            {
                const string errmsg = "Failed to write. The specified DynamicEntity `{0}` is not of a supported type ({1}).";
                throw new ArgumentException(string.Format(errmsg, dEntity, dEntity.GetType()));
            }

            writer.Write(_typeStringKey, typeName);
            dEntity.WriteAll(writer);
        }
        /// <summary>
        /// Filter used to find a DynamicEntity for the User to use.
        /// </summary>
        /// <param name="dynamicEntity">The User's character.</param>
        /// <returns>True if it can be used by the <paramref name="dynamicEntity"/>, else false.</returns>
        static bool UsableEntityFilter(DynamicEntity dynamicEntity)
        {
            // Make sure it is usable
            var asUsable = dynamicEntity as IUsableEntity;
            if (asUsable == null)
                return false;

            // Check that this DynamicEntity can use it
            return asUsable.CanUse(dynamicEntity);
        }
示例#12
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 abstract bool Use(DynamicEntity charEntity);
示例#13
0
        /// <summary>
        /// Client: 
        ///     Checks if the Client's character can attempt to use the IUsableEntity. If false, the Client
        ///     wont even attempt to use the IUsableEntity. If true, the Client will attempt to use it, but
        ///     it is not guarenteed the Server will also allow it to be used.
        /// Server:
        ///     Checks if the specified Entity may use the IUsableEntity.
        /// </summary>
        /// <param name="charEntity">The CharacterEntity that is trying to use this IUsableEntity. For the Client,
        /// this will always be the User's Character. Can be null.</param>
        /// <returns>True if this IUsableEntity can be used by the <paramref name="charEntity"/>, else false.</returns>
        public virtual bool CanUse(DynamicEntity charEntity)
        {
            if (charEntity == null)
                return false;

            return true;
        }