Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NPCSpawner"/> class.
        /// </summary>
        /// <param name="mapSpawnValues">The MapSpawnValues containing the values to use to create this NPCSpawner.</param>
        /// <param name="map">The Map instance to do the spawning on. The <see cref="MapID"/> of this Map must be equal to the
        /// <see cref="MapID"/> of the <paramref name="mapSpawnValues"/>.</param>
        /// <exception cref="ArgumentException">The <paramref name="map"/>'s <see cref="MapID"/> does not match the
        /// <paramref name="mapSpawnValues"/>'s <see cref="MapID"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="map" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="mapSpawnValues" /> is <c>null</c>.</exception>
        public NPCSpawner(IMapSpawnTable mapSpawnValues, Map map)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            if (mapSpawnValues == null)
            {
                throw new ArgumentNullException("mapSpawnValues");
            }

            if (map.ID != mapSpawnValues.MapID)
            {
                throw new ArgumentException("The map's MapID and mapSpawnValues's MapID do not match.", "map");
            }

            _map = map;
            _characterTemplate = _characterTemplateManager[mapSpawnValues.CharacterTemplateID];
            _amount            = mapSpawnValues.Amount;
            _area = new MapSpawnRect(mapSpawnValues).ToRectangle(map);

            if (_characterTemplate == null)
            {
                const string errmsg = "Failed to find the CharacterTemplate for CharacterTemplateID `{0}`.";
                var          err    = string.Format(errmsg, mapSpawnValues.CharacterTemplateID);
                if (log.IsFatalEnabled)
                {
                    log.Fatal(err);
                }
                Debug.Fail(err);
                throw new ArgumentException(err);
            }

            SpawnNPCs();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NPCSpawner"/> class.
        /// </summary>
        /// <param name="mapSpawnValues">The MapSpawnValues containing the values to use to create this NPCSpawner.</param>
        /// <param name="map">The Map instance to do the spawning on. The <see cref="MapID"/> of this Map must be equal to the
        /// <see cref="MapID"/> of the <paramref name="mapSpawnValues"/>.</param>
        /// <exception cref="ArgumentException">The <paramref name="map"/>'s <see cref="MapID"/> does not match the
        /// <paramref name="mapSpawnValues"/>'s <see cref="MapID"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="map" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="mapSpawnValues" /> is <c>null</c>.</exception>
        public NPCSpawner(IMapSpawnTable mapSpawnValues, Map map)
        {
            if (map == null)
                throw new ArgumentNullException("map");
            if (mapSpawnValues == null)
                throw new ArgumentNullException("mapSpawnValues");

            if (map.ID != mapSpawnValues.MapID)
                throw new ArgumentException("The map's MapID and mapSpawnValues's MapID do not match.", "map");

            _map = map;
            _characterTemplate = _characterTemplateManager[mapSpawnValues.CharacterTemplateID];
            _characterTemplateBody = BodyInfoManager.Instance.GetBody(_characterTemplate.TemplateTable.BodyID);
            _amount = mapSpawnValues.Amount;
            _area = new MapSpawnRect(mapSpawnValues).ToRectangle(map);
            _spawnDirection = mapSpawnValues.DirectionId;
            _respawn = mapSpawnValues.Respawn;

            if (_characterTemplate == null)
            {
                const string errmsg = "Failed to find the CharacterTemplate for CharacterTemplateID `{0}`.";
                var err = string.Format(errmsg, mapSpawnValues.CharacterTemplateID);
                if (log.IsFatalEnabled)
                    log.Fatal(err);
                Debug.Fail(err);
                throw new ArgumentException(err);
            }

            SpawnNPCs();
        }
 /// <summary>
 /// Checks if this <see cref="IMapSpawnTable"/> contains the same values as another <see cref="IMapSpawnTable"/>.
 /// </summary>
 /// <param name="source">The source <see cref="IMapSpawnTable"/>.</param>
 /// <param name="otherItem">The <see cref="IMapSpawnTable"/> to compare the values to.</param>
 /// <returns>
 /// True if this <see cref="IMapSpawnTable"/> contains the same values as the <paramref name="otherItem"/>; otherwise false.
 /// </returns>
 public static Boolean HasSameValues(this IMapSpawnTable source, IMapSpawnTable otherItem)
 {
     return(Equals(source.Amount, otherItem.Amount) && Equals(source.CharacterTemplateID, otherItem.CharacterTemplateID) &&
            Equals(source.Height, otherItem.Height) && Equals(source.ID, otherItem.ID) &&
            Equals(source.MapID, otherItem.MapID) && Equals(source.Width, otherItem.Width) && Equals(source.X, otherItem.X) &&
            Equals(source.Y, otherItem.Y));
 }
 /// <summary>
 /// Checks if this <see cref="IMapSpawnTable"/> contains the same values as another <see cref="IMapSpawnTable"/>.
 /// </summary>
 /// <param name="source">The source <see cref="IMapSpawnTable"/>.</param>
 /// <param name="otherItem">The <see cref="IMapSpawnTable"/> to compare the values to.</param>
 /// <returns>
 /// True if this <see cref="IMapSpawnTable"/> contains the same values as the <paramref name="otherItem"/>; otherwise false.
 /// </returns>
 public static Boolean HasSameValues(this IMapSpawnTable source, IMapSpawnTable otherItem)
 {
     return Equals(source.Amount, otherItem.Amount) && Equals(source.CharacterTemplateID, otherItem.CharacterTemplateID) &&
            Equals(source.Height, otherItem.Height) && Equals(source.ID, otherItem.ID) &&
            Equals(source.MapID, otherItem.MapID) && Equals(source.Width, otherItem.Width) && Equals(source.X, otherItem.X) &&
            Equals(source.Y, otherItem.Y);
 }
Exemplo n.º 5
0
/// <summary>
/// Copies the column values into the given DbParameterValues using the database column name
/// with a prefixed @ as the key. The key must already exist in the DbParameterValues
/// for the value to be copied over. If any of the keys in the DbParameterValues do not
/// match one of the column names, or if there is no field for a key, then it will be
/// ignored. Because of this, it is important to be careful when using this method
/// since columns or keys can be skipped without any indication.
/// </summary>
/// <param name="source">The object to copy the values from.</param>
/// <param name="paramValues">The DbParameterValues to copy the values into.</param>
        public static void TryCopyValues(this IMapSpawnTable source, NetGore.Db.DbParameterValues paramValues)
        {
            for (int i = 0; i < paramValues.Count; i++)
            {
                switch (paramValues.GetParameterName(i))
                {
                case "amount":
                    paramValues[i] = (System.Byte)source.Amount;
                    break;


                case "character_template_id":
                    paramValues[i] = (System.UInt16)source.CharacterTemplateID;
                    break;


                case "direction_id":
                    paramValues[i] = (System.Int16)source.DirectionId;
                    break;


                case "height":
                    paramValues[i] = (System.Nullable <System.UInt16>)source.Height;
                    break;


                case "id":
                    paramValues[i] = (System.Int32)source.ID;
                    break;


                case "map_id":
                    paramValues[i] = (System.UInt16)source.MapID;
                    break;


                case "respawn":
                    paramValues[i] = (System.UInt16)source.Respawn;
                    break;


                case "width":
                    paramValues[i] = (System.Nullable <System.UInt16>)source.Width;
                    break;


                case "x":
                    paramValues[i] = (System.Nullable <System.UInt16>)source.X;
                    break;


                case "y":
                    paramValues[i] = (System.Nullable <System.UInt16>)source.Y;
                    break;
                }
            }
        }
 /// <summary>
 /// Copies the column values into the given DbParameterValues using the database column name
 /// with a prefixed @ as the key. The keys must already exist in the DbParameterValues;
 ///  this method will not create them if they are missing.
 /// </summary>
 /// <param name="source">The object to copy the values from.</param>
 /// <param name="paramValues">The DbParameterValues to copy the values into.</param>
 public static void CopyValues(this IMapSpawnTable source, DbParameterValues paramValues)
 {
     paramValues["amount"] = source.Amount;
     paramValues["character_template_id"] = (UInt16)source.CharacterTemplateID;
     paramValues["height"] = source.Height;
     paramValues["id"]     = (Int32)source.ID;
     paramValues["map_id"] = (UInt16)source.MapID;
     paramValues["width"]  = source.Width;
     paramValues["x"]      = source.X;
     paramValues["y"]      = source.Y;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Copies the values from the given <paramref name="source"/> into this MapSpawnTable.
 /// </summary>
 /// <param name="source">The IMapSpawnTable to copy the values from.</param>
 public void CopyValuesFrom(IMapSpawnTable source)
 {
     Amount = source.Amount;
     CharacterTemplateID = source.CharacterTemplateID;
     Height = source.Height;
     ID     = source.ID;
     MapID  = source.MapID;
     Width  = source.Width;
     X      = source.X;
     Y      = source.Y;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Copies the column values into the given Dictionary using the database column name
 /// with a prefixed @ as the key. The keys must already exist in the Dictionary;
 /// this method will not create them if they are missing.
 /// </summary>
 /// <param name="source">The object to copy the values from.</param>
 /// <param name="dic">The Dictionary to copy the values into.</param>
 public static void CopyValues(IMapSpawnTable source, IDictionary <String, Object> dic)
 {
     dic["amount"] = source.Amount;
     dic["character_template_id"] = source.CharacterTemplateID;
     dic["height"] = source.Height;
     dic["id"]     = source.ID;
     dic["map_id"] = source.MapID;
     dic["width"]  = source.Width;
     dic["x"]      = source.X;
     dic["y"]      = source.Y;
 }
Exemplo n.º 9
0
/// <summary>
/// Copies the column values into the given DbParameterValues using the database column name
/// with a prefixed @ as the key. The keys must already exist in the DbParameterValues;
///  this method will not create them if they are missing.
/// </summary>
/// <param name="source">The object to copy the values from.</param>
/// <param name="paramValues">The DbParameterValues to copy the values into.</param>
        public static void CopyValues(this IMapSpawnTable source, NetGore.Db.DbParameterValues paramValues)
        {
            paramValues["amount"] = (System.Byte)source.Amount;
            paramValues["character_template_id"] = (System.UInt16)source.CharacterTemplateID;
            paramValues["height"] = (System.Nullable <System.UInt16>)source.Height;
            paramValues["id"]     = (System.Int32)source.ID;
            paramValues["map_id"] = (System.UInt16)source.MapID;
            paramValues["width"]  = (System.Nullable <System.UInt16>)source.Width;
            paramValues["x"]      = (System.Nullable <System.UInt16>)source.X;
            paramValues["y"]      = (System.Nullable <System.UInt16>)source.Y;
        }
Exemplo n.º 10
0
/// <summary>
/// Copies the values from the given <paramref name="source"/> into this MapSpawnTable.
/// </summary>
/// <param name="source">The IMapSpawnTable to copy the values from.</param>
        public void CopyValuesFrom(IMapSpawnTable source)
        {
            this.Amount = (System.Byte)source.Amount;
            this.CharacterTemplateID = (DemoGame.CharacterTemplateID)source.CharacterTemplateID;
            this.Height = (System.Nullable <System.UInt16>)source.Height;
            this.ID     = (DemoGame.MapSpawnValuesID)source.ID;
            this.MapID  = (NetGore.World.MapID)source.MapID;
            this.Width  = (System.Nullable <System.UInt16>)source.Width;
            this.X      = (System.Nullable <System.UInt16>)source.X;
            this.Y      = (System.Nullable <System.UInt16>)source.Y;
        }
Exemplo n.º 11
0
/// <summary>
/// Copies the column values into the given Dictionary using the database column name
/// with a prefixed @ as the key. The keys must already exist in the Dictionary;
/// this method will not create them if they are missing.
/// </summary>
/// <param name="source">The object to copy the values from.</param>
/// <param name="dic">The Dictionary to copy the values into.</param>
        public static void CopyValues(IMapSpawnTable source, System.Collections.Generic.IDictionary <System.String, System.Object> dic)
        {
            dic["amount"] = (System.Byte)source.Amount;
            dic["character_template_id"] = (DemoGame.CharacterTemplateID)source.CharacterTemplateID;
            dic["height"] = (System.Nullable <System.UInt16>)source.Height;
            dic["id"]     = (DemoGame.MapSpawnValuesID)source.ID;
            dic["map_id"] = (NetGore.World.MapID)source.MapID;
            dic["width"]  = (System.Nullable <System.UInt16>)source.Width;
            dic["x"]      = (System.Nullable <System.UInt16>)source.X;
            dic["y"]      = (System.Nullable <System.UInt16>)source.Y;
        }
        /// <summary>
        /// Copies the column values into the given DbParameterValues using the database column name
        /// with a prefixed @ as the key. The key must already exist in the DbParameterValues
        /// for the value to be copied over. If any of the keys in the DbParameterValues do not
        /// match one of the column names, or if there is no field for a key, then it will be
        /// ignored. Because of this, it is important to be careful when using this method
        /// since columns or keys can be skipped without any indication.
        /// </summary>
        /// <param name="source">The object to copy the values from.</param>
        /// <param name="paramValues">The DbParameterValues to copy the values into.</param>
        public static void TryCopyValues(this IMapSpawnTable source, DbParameterValues paramValues)
        {
            for (var i = 0; i < paramValues.Count; i++)
            {
                switch (paramValues.GetParameterName(i))
                {
                case "amount":
                    paramValues[i] = source.Amount;
                    break;

                case "character_template_id":
                    paramValues[i] = (UInt16)source.CharacterTemplateID;
                    break;

                case "height":
                    paramValues[i] = source.Height;
                    break;

                case "id":
                    paramValues[i] = (Int32)source.ID;
                    break;

                case "map_id":
                    paramValues[i] = (UInt16)source.MapID;
                    break;

                case "width":
                    paramValues[i] = source.Width;
                    break;

                case "x":
                    paramValues[i] = source.X;
                    break;

                case "y":
                    paramValues[i] = source.Y;
                    break;
                }
            }
        }
Exemplo n.º 13
0
/// <summary>
/// Copies the values from the given <paramref name="source"/> into this MapSpawnTable.
/// </summary>
/// <param name="source">The IMapSpawnTable to copy the values from.</param>
public void CopyValuesFrom(IMapSpawnTable source)
{
this.Amount = (System.Byte)source.Amount;
this.CharacterTemplateID = (DemoGame.CharacterTemplateID)source.CharacterTemplateID;
this.DirectionId = (NetGore.Direction)source.DirectionId;
this.Height = (System.Nullable<System.UInt16>)source.Height;
this.ID = (DemoGame.MapSpawnValuesID)source.ID;
this.MapID = (NetGore.World.MapID)source.MapID;
this.Respawn = (System.UInt16)source.Respawn;
this.Width = (System.Nullable<System.UInt16>)source.Width;
this.X = (System.Nullable<System.UInt16>)source.X;
this.Y = (System.Nullable<System.UInt16>)source.Y;
}
Exemplo n.º 14
0
/// <summary>
/// Copies the column values into the given Dictionary using the database column name
/// with a prefixed @ as the key. The keys must already exist in the Dictionary;
/// this method will not create them if they are missing.
/// </summary>
/// <param name="source">The object to copy the values from.</param>
/// <param name="dic">The Dictionary to copy the values into.</param>
public static void CopyValues(IMapSpawnTable source, System.Collections.Generic.IDictionary<System.String,System.Object> dic)
{
dic["amount"] = (System.Byte)source.Amount;
dic["character_template_id"] = (DemoGame.CharacterTemplateID)source.CharacterTemplateID;
dic["direction_id"] = (NetGore.Direction)source.DirectionId;
dic["height"] = (System.Nullable<System.UInt16>)source.Height;
dic["id"] = (DemoGame.MapSpawnValuesID)source.ID;
dic["map_id"] = (NetGore.World.MapID)source.MapID;
dic["respawn"] = (System.UInt16)source.Respawn;
dic["width"] = (System.Nullable<System.UInt16>)source.Width;
dic["x"] = (System.Nullable<System.UInt16>)source.X;
dic["y"] = (System.Nullable<System.UInt16>)source.Y;
}
Exemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnValues"/> class.
 /// </summary>
 /// <param name="dbController">The IDbController used to synchronize changes to the values.</param>
 /// <param name="v">The IMapSpawnTable containing the values to use.</param>
 MapSpawnValues(IDbController dbController, IMapSpawnTable v)
     : this(dbController, v.ID, v.MapID, v.CharacterTemplateID, v.Amount, new MapSpawnRect(v))
 {
 }
Exemplo n.º 16
0
 /// <summary>
 /// Copies the values from the given <paramref name="source"/> into this MapSpawnTable.
 /// </summary>
 /// <param name="source">The IMapSpawnTable to copy the values from.</param>
 public void CopyValuesFrom(IMapSpawnTable source)
 {
     Amount = source.Amount;
     CharacterTemplateID = source.CharacterTemplateID;
     Height = source.Height;
     ID = source.ID;
     MapID = source.MapID;
     Width = source.Width;
     X = source.X;
     Y = source.Y;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnTable"/> class.
 /// </summary>
 /// <param name="source">IMapSpawnTable to copy the initial values from.</param>
 public MapSpawnTable(IMapSpawnTable source)
 {
     CopyValuesFrom(source);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnValues"/> class.
 /// </summary>
 /// <param name="dbController">The IDbController used to synchronize changes to the values.</param>
 /// <param name="v">The IMapSpawnTable containing the values to use.</param>
 MapSpawnValues(IDbController dbController, IMapSpawnTable v)
     : this(dbController, v.ID, v.MapID, v.CharacterTemplateID, v.Amount, new MapSpawnRect(v))
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// Copies the column values into the given Dictionary using the database column name
 /// with a prefixed @ as the key. The keys must already exist in the Dictionary;
 /// this method will not create them if they are missing.
 /// </summary>
 /// <param name="source">The object to copy the values from.</param>
 /// <param name="dic">The Dictionary to copy the values into.</param>
 public static void CopyValues(IMapSpawnTable source, IDictionary<String, Object> dic)
 {
     dic["amount"] = source.Amount;
     dic["character_template_id"] = source.CharacterTemplateID;
     dic["height"] = source.Height;
     dic["id"] = source.ID;
     dic["map_id"] = source.MapID;
     dic["width"] = source.Width;
     dic["x"] = source.X;
     dic["y"] = source.Y;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnTable"/> class.
 /// </summary>
 /// <param name="source">IMapSpawnTable to copy the initial values from.</param>
 public MapSpawnTable(IMapSpawnTable source)
 {
     CopyValuesFrom(source);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnRect"/> struct.
 /// </summary>
 /// <param name="mapSpawnTable">The map spawn table.</param>
 public MapSpawnRect(IMapSpawnTable mapSpawnTable)
     : this(mapSpawnTable.X, mapSpawnTable.Y, mapSpawnTable.Width, mapSpawnTable.Height)
 {
 }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnRect"/> struct.
 /// </summary>
 /// <param name="mapSpawnTable">The map spawn table.</param>
 public MapSpawnRect(IMapSpawnTable mapSpawnTable)
     : this(mapSpawnTable.X, mapSpawnTable.Y, mapSpawnTable.Width, mapSpawnTable.Height)
 {
 }