public MobReset(Room room, int indexNumber, int maximumRoom, int respawn) { Room = room; IndexNumber = indexNumber; MaximumRoom = maximumRoom; Respawn = respawn; Name = "MobReset of " + indexNumber + " in " + room.ToString() + " (limit " + maximumRoom + ")"; }
public Area Generate() { Area area = new Area(); int indexNumber; Room prevRoom = null; Room room = null; Exit exit; int i = 0; int x = 500; int y = 500; int dir = -1; int prevDir = -1; Directions[] dirNormal = new Directions[] { Directions.North, Directions.South, Directions.West, Directions.East }; Directions[] dirOpposite = new Directions[] { Directions.South, Directions.North, Directions.East, Directions.West }; Random rand = new Random(); while (i < IndexNumbers.Count) { indexNumber = IndexNumbers[i]; room = new Room(indexNumber); area.Rooms.Add(room); Coordinates[x, y] = indexNumber; if (prevRoom != null) { while (true) { dir = rand.Next(0, 3); if (dir != -1 && prevDir != -1 && dirNormal[dir] == dirOpposite[prevDir]) continue; room.Exits[dirNormal[dir]] = new Exit(indexNumber, prevRoom.IndexNumber); prevRoom.Exits[dirOpposite[dir]] = new Exit(prevRoom.IndexNumber, indexNumber); break; } Global.Log("Created " + prevRoom.IndexNumber + " to " + indexNumber + " (" + dir.ToString() + ")"); } prevDir = dir; prevRoom = room; i++; } return area; }
public bool Load(string name) { XmlDocument document = new XmlDocument(); XmlNode collection; XmlElement element; try { document.Load(name); } catch { Global.Error("ERROR: Area '" + name + "' not found.\n"); return false; } element = document.DocumentElement; Name = element.GetAttribute("name"); Global.Log(" " + Name + ":\n"); collection = element["rooms"]; Room newRoom; foreach (XmlNode node in collection.ChildNodes) { newRoom = new Room(Convert.ToInt32(node.Attributes["index"].Value)); newRoom.Load(node, this); Rooms.Add(newRoom); } collection = element["mobs"]; Mob newMob; foreach (XmlNode node in collection.ChildNodes) { newMob = new Mob(node); } Global.AreaTable.Add(Global.AreaTable.Count, this); Global.Log(" " + Name + " loaded, "); ForceSpawn(); Global.Log("spawned\n"); return true; }
/// <summary> /// Move the Mob from current room to destination room, sending direction-based messages /// if provided. /// </summary> /// <param name="destination">The destination Room</param> /// <param name="direction">The direction the Mob is moving</param> /// <returns></returns> public bool Move(Room destination, string direction) { if (direction != "") { if (Room != null) Room.Remove(this, Name + " leaves " + direction + ".\n\r"); destination.Add(this, Name + " has arrived.\n\r"); } else { if (Room != null) Room.Remove(this); destination.Add(this); } Room = destination; return true; }
/// <summary> /// Move the Mob from current Room to destination Room, sending no messages. /// </summary> /// <param name="destination">The destination Room</param> /// <returns></returns> public bool Move(Room destination) { return Move(destination, ""); }
/// <summary> /// Remove all references to this Mob, preparing it for garbage collection. /// </summary> public void Delete() { foreach(Affect affect in Affects) Affects = new List<Affect>(); Room.Remove(this, ""); Room = null; foreach (Mob mob in Global.Mobs) { if (mob.TargetEnemy == this) mob.TargetEnemy = null; if (mob.TargetAlly == this) mob.TargetAlly = null; } }