public Creature(CreatureType ctype) { if (ctype != null) { type_name = ctype.name; } }
public CreatureBrush getBrush() { CreatureType type = CreatureDatabase.creatureDatabase[type_name]; if (type != null) { return(type.brush); } return(null); }
public string getName() { CreatureType type = CreatureDatabase.creatureDatabase[type_name]; if (type != null) { return(type.name); } return(""); }
public bool isNpc() { CreatureType type = CreatureDatabase.creatureDatabase[type_name]; if (type != null) { return(type.isNpc); } return(false); }
public Outfit getLookType() { CreatureType type = CreatureDatabase.creatureDatabase[type_name]; if (type != null) { return(type.outfit); } return(new Outfit()); }
public void loadFromXML(String fileName, bool standard) { XElement doc = XElement.Load(fileName); foreach (XElement node in doc.Elements()) { if (node.Name.LocalName == "creature") { CreatureType ct = CreatureType.loadFromXML(node); if (ct != null) { ct.standard = standard; if (this[ct.name] != null) { Messages.AddWarning("Duplicate creature name ! " + ct.name + " Discarding..."); } else { creature_map.Add(ct.name.ToLower(), ct); } } } } }
public CreatureType this[String creatureName] { get { if (creatureName == null) { return(null); } CreatureType ret = null; if (creature_map.TryGetValue(creatureName.ToLower(), out ret)) { return(ret); } else { return(null); } } set { creature_map[creatureName] = value; } }
private void LoadSpawns() { String spawnFileName = Path.GetDirectoryName(FileName) + "\\" + spawnFile; if (!File.Exists(spawnFileName)) { return; } XElement spawnDoc = XElement.Load(spawnFileName); int intVal = 0; string strVal = ""; foreach (XElement nodeSpawn in spawnDoc.Elements()) { if (nodeSpawn.Name.LocalName == "spawn") { bool posok = true; Position spawnpos = new Position(); intVal = nodeSpawn.Attribute("centerx").GetInt32(); if (intVal > 0) { spawnpos.X = intVal; } else { posok = false; } intVal = nodeSpawn.Attribute("centery").GetInt32(); if (intVal > 0) { spawnpos.Y = intVal; } else { posok = false; } intVal = nodeSpawn.Attribute("centerz").GetInt32(); if (intVal > 0) { spawnpos.Z = intVal; } else { posok = false; } if (!posok) { //"Bad position data on one spawn, discarding..."; continue; } int radius = 1; intVal = nodeSpawn.Attribute("radius").GetInt32(); if (intVal > 0) { radius = Math.Max(1, intVal); } else { //Couldn't read radius of spawn.. discarding spawn... continue; } Tile tile = this.getTile(spawnpos); if (tile != null && tile.spawn != null) { //Duplicate spawn on position continue; } Spawn spawn = new Spawn(radius); if (tile == null) { tile = new Tile(); tile.Position = spawnpos; this.setTile(spawnpos, tile); } tile.spawn = spawn; this.AddSpawn(tile); foreach (XElement creatureNode in nodeSpawn.Elements()) { if ((creatureNode.Name.LocalName == "monster") || (creatureNode.Name.LocalName == "npc")) { String name = ""; int spawntime = Settings.GetInteger(Key.DEFAULT_SPAWNTIME); bool isNpc = (creatureNode.Name.LocalName == "npc"); name = creatureNode.Attribute("name").GetString(); if (name == "") { //No name of monster spawn at continue; } intVal = creatureNode.Attribute("spawntime").GetInt32(); if (intVal > 0) { spawntime = intVal; } posok = true; Position creaturepos = new Position(spawnpos); if (creatureNode.Attribute("x") != null) { creaturepos.x += creatureNode.Attribute("x").GetInt32(); } else { posok = false; } if (creatureNode.Attribute("y") != null) { creaturepos.y += creatureNode.Attribute("y").GetInt32(); } else { posok = false; } if (posok == false) { //Bad creature position data, discarding creature continue; } if (Math.Abs(creaturepos.x - spawnpos.x) > radius) { radius = Math.Abs(creaturepos.x - spawnpos.x); } if (Math.Abs(creaturepos.y - spawnpos.y) > radius) { radius = Math.Abs(creaturepos.y - spawnpos.y); } radius = Math.Min(radius, Settings.GetInteger(Key.MAX_SPAWN_RADIUS)); Tile creature_tile = null; if (creaturepos == spawnpos) { creature_tile = tile; } else { creature_tile = this.getTile(creaturepos); } if (creature_tile == null) { //Discarding creature continue; } CreatureType type = CreatureDatabase.creatureDatabase[name]; if (type == null) { CreatureDatabase.creatureDatabase.addMissingCreatureType(name, isNpc); } Creature creature = new Creature(type); creature.setSpawnTime(spawntime); creature_tile.creature = creature; if (creature_tile.spawn_count == 0) { Spawn creature_spawn = new Spawn(5); creature_tile.spawn = creature_spawn; AddSpawn(creature_tile); } } } } } }
public static CreatureType loadFromXML(XElement node) { String tmp_type = node.Attribute("type").GetString(); if (tmp_type == "") { Messages.AddWarning("Couldn't read type tag of creature node."); return(null); } if (tmp_type != "monster" && tmp_type != "npc") { Messages.AddWarning("Invalid type tag of creature node " + tmp_type); return(null); } String tmp_name = node.Attribute("name").GetString(); if (tmp_name == "") { Messages.AddWarning("Couldn't read name tag of creature node."); return(null); } CreatureType ct = new CreatureType(); ct.name = tmp_name; ct.isNpc = (tmp_type == "npc"); int intVal = node.Attribute("looktype").GetInt32(); if (intVal > 0) { ct.outfit.lookType = intVal; /* VERIFICAR SERVER TODO * if (gui.gfx.getCreatureSprite(intVal) == NULL) * { * wxString war; * war << wxT("Invalid creature \"") << wxstr(tmp_name) << wxT("\" look type #"); * war << intVal; * warnings.push_back(war); * } */ } intVal = node.Attribute("lookitem").GetInt32(); if (intVal > 0) { ct.outfit.lookItem = intVal; } intVal = node.Attribute("lookaddon").GetInt32(); if (intVal > 0) { ct.outfit.lookAddon = intVal; } intVal = node.Attribute("lookhead").GetInt32(); if (intVal > 0) { ct.outfit.lookHead = intVal; } intVal = node.Attribute("lookbody").GetInt32(); if (intVal > 0) { ct.outfit.lookBody = intVal; } intVal = node.Attribute("looklegs").GetInt32(); if (intVal > 0) { ct.outfit.lookLegs = intVal; } intVal = node.Attribute("lookfeet").GetInt32(); if (intVal > 0) { ct.outfit.lookFeet = intVal; } return(ct); }