/** * Initializes the map content. This creates the warps, spawn areas, npcs and * other scripts. */ void initializeContent() { mContent=new MapContent(mMap); List<MapObject> objects=mMap.getObjects(); for(int i = 0;i < objects.Count;++i) { MapObject obj=objects[i]; string type=obj.getType(); if(type=="WARP") { string destMapName=obj.getProperty("DEST_MAP"); int destX=Convert.ToInt32(obj.getProperty("DEST_X")); int destY=Convert.ToInt32(obj.getProperty("DEST_Y")); //if(destMapName!=""&&destX&&destY) //TODO Check if(destMapName!="") { MapComposite destMap=MapManager.getMap(destMapName); if(destMap!=null) { WarpAction action=new WarpAction(destMap, destX, destY); insert(new TriggerArea(this, obj.getBounds(), action, false)); } } else { Logger.Write(LogLevel.Warning, "Unrecognized warp format"); } } else if(type=="SPAWN") { MonsterClass monster=null; int maxBeings=Convert.ToInt32(obj.getProperty("MAX_BEINGS")); int spawnRate=Convert.ToInt32(obj.getProperty("SPAWN_RATE")); string monsterName=obj.getProperty("MONSTER_ID"); int monsterId=Convert.ToInt32(monsterName); if(monsterId>0) { monster=Program.monsterManager.getMonster(monsterId); if(monster==null) { Logger.Write(LogLevel.Warning, "Couldn't find monster ID {0} for spawn area", monsterId); } } else { monster=Program.monsterManager.getMonsterByName(monsterName); if(monster==null) { Logger.Write(LogLevel.Warning, "Couldn't find monster {0} for spawn area", monsterName); } } if(monster!=null&&maxBeings>0&&spawnRate>0) { insert(new SpawnArea(this, monster, obj.getBounds(), maxBeings, spawnRate)); } } else if(type=="NPC") { int npcId=Convert.ToInt32(obj.getProperty("NPC_ID")); string scriptText=obj.getProperty("SCRIPT"); if(mScript!=null) { // Determine script engine by xml property string scriptEngineName=obj.getProperty("ENGINE"); if(scriptEngineName=="") { // Set engine to default value and print warning scriptEngineName=Configuration.getValue("script_defaultEngine", "lua"); Logger.Write(LogLevel.Warning, "No script engine specified for map script {0} falling back to default", mName); } mScript=Script.create(scriptEngineName); } if(npcId>0&&scriptText!="") { //TODO Implementieren // mScript.loadNPC(obj.getName(), npcId, // obj.getX(), obj.getY(), // scriptText); } else { Logger.Write(LogLevel.Warning, "Unrecognized format for npc"); } } else if(type=="SCRIPT") { string scriptFilename=obj.getProperty("FILENAME"); string scriptText=obj.getProperty("TEXT", ""); if(mScript!=null) { // Determine script engine by xml property string scriptEngineName=obj.getProperty("ENGINE", ""); if(scriptFilename!=""&&scriptEngineName=="") { // Engine property is empty - determine by filename scriptEngineName=Script.determineEngineByFilename(scriptFilename); } else if(scriptEngineName=="") { // Set engine to default value and print warning scriptEngineName=Configuration.getValue("script_defaultEngine", "lua"); Logger.Write(LogLevel.Warning, "No script engine specified for map script {0}, falling back to default", mName); } mScript=Script.create(scriptEngineName); } if(scriptFilename!="") { if(mScript != null) { mScript.loadFile(scriptFilename); } else { Logger.Write(LogLevel.Warning, "No script engine can't bet initialized", mName); } } else if(scriptText!=null) { //TODO Implementieren // string name="'"+obj.getName()+"'' in "+mName; // mScript.load(scriptText, name); } else { Logger.Write(LogLevel.Warning, "Unrecognized format for script"); } } } }
/// <summary> /// Initializes a new instance of the <see cref="WarpHandler"/> class. /// </summary> /// <param name="gameContext">The game context.</param> public WarpHandler(IGameContext gameContext) : base(gameContext) { this.warpAction = new WarpAction(); }