public MapTile(WorldMap map, CoordXZ tileCoord) { this.map = map; this.tileCoord = tileCoord; zone = null; this.dirty = false; properties = new MapProperties(this); }
public MapZone GetCaseImage(ZoneAbstraite z, List<Personnage> liste, List<Quete>quete) { if (z != null) { MapZone map = new MapZone(z); BitmapSource bt = null; foreach (Personnage p in liste) { if (z != null && p != null && p.Position != null && p.Position.X == z.point.X && p.Position.Y == z.point.Y) { bt = ToWpfBitmap(p.Image); map.ToolTip += " " + p.Nom; } } if (bt == null) { foreach (Quete q in quete) { if (q.Type == TypeQuete.TrouverCase) { QueteZone qz = (QueteZone)q; if (qz != null && z != null && qz.ZoneATrouver.X == z.point.X && qz.ZoneATrouver.Y == z.point.Y) bt = ToWpfBitmap(cible); } } if (bt == null && (z.objets != null && z.objets.Count > 0)) { bt = ToWpfBitmap(objet); foreach(Objet o in z.objets) if (o.monType == monTypeObjet.Portoloin) bt = ToWpfBitmap(inconnu); } else if (bt == null && z.Walkable) bt = ToWpfBitmap(standard); else if (bt == null) bt = ToWpfBitmap(obstacle); } map.Source = bt; return map; } return null; }
public void Equality() { var zone1 = new MapZone("windowsId", "territory", new[] { "id1", "id2", "id3" }); var zone2 = new MapZone("windowsId", "territory", new[] { "id1", "id2", "id3" }); var zone3 = new MapZone("otherWindowsId", "territory", new[] { "id1", "id2", "id3" }); var zone4 = new MapZone("windowsId", "otherTerritory", new[] { "id1", "id2", "id3" }); var zone5 = new MapZone("windowsId", "territory", new[] { "id1", "id2" }); var zone6 = new MapZone("windowsId", "territory", new[] { "id1", "id2", "id4" }); TestHelper.TestEqualsClass(zone1, zone2, zone3); TestHelper.TestEqualsClass(zone1, zone2, zone4); TestHelper.TestEqualsClass(zone1, zone2, zone5); TestHelper.TestEqualsClass(zone1, zone2, zone6); }
public void ReadWrite() { var zone = new MapZone("windowsId", "territory", new[] { "id1", "id2", "id3" }); var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); zone.Write(writer); stream.Position = 0; var reader = new DateTimeZoneReader(stream, null); var zone2 = MapZone.Read(reader); Assert.AreEqual(zone, zone2); }
public override string GetStepParameters() { var parameters = new List <string>(); parameters.Add(Name != null ? Name.ToStepValue() : "$"); parameters.Add(Description != null ? Description.ToStepValue() : "$"); parameters.Add(GeodeticDatum != null ? GeodeticDatum.ToStepValue() : "$"); parameters.Add(VerticalDatum != null ? VerticalDatum.ToStepValue() : "$"); parameters.Add(MapProjection != null ? MapProjection.ToStepValue() : "$"); parameters.Add(MapZone != null ? MapZone.ToStepValue() : "$"); parameters.Add(MapUnit != null ? MapUnit.ToStepValue() : "$"); return(string.Join(", ", parameters.ToArray())); }
public void editWholeZone(MapZone node, int addOrDelete) { if (zoneCollection.ContainsKey(node.id) && addOrDelete == OPERATE_ADD) { Debug.Log("这个区域(" + node.id + ")已经被添加过了"); } else if (zoneCollection.ContainsKey(node.id) && addOrDelete == OPERATE_DELETE) { zoneCollection.Remove(node.id); } else if (!zoneCollection.ContainsKey(node.id) && addOrDelete == OPERATE_ADD) { zoneCollection[node.id] = node; } }
public void Launch_EventMerchant_MapZone() { MapZone zoneTest = new MapZone(null, false, 2); for (int i = 0; i < 3; i++) { Merchant merchant = zoneTest.EventMerchant(); Console.WriteLine("Merchant 1"); foreach (Item item in merchant.GetItemsAvailable) { Console.WriteLine("Name {0}, Description {1}", item.GetName, item.GetDescription); } } }
//九宫格 public List <MapZone> getNearbyZones(Vector3 posInWorld) { MapZone res = getZoneByPosition(posInWorld); int idx = res.idx; int idxY = idx / zoneNumX; int idxX = idx % zoneNumX; for (int di = -1; di <= 1; di++) { for (int dj = -1; dj <= 1; dj++) { } } return(null); }
private void LunarChimeraFall(On.RoR2.MapZone.orig_TryZoneStart orig, MapZone self, Collider other) { if (IsUnstableDesignChimera(other.gameObject)) { CharacterBody body = other.GetComponent <CharacterBody>(); if (body) { var teamComponent = body.teamComponent; teamComponent.teamIndex = TeamIndex.Player; //Set the team of it to player to avoid it dying when it falls into a hellzone. orig(self, other); //Run the effect of whatever zone it is in on it. Since it is of the Player team, it obviously gets teleported back into the zone. teamComponent.teamIndex = TeamIndex.Neutral; //Now make it hostile again. Thanks Obama. return; } } orig(self, other); }
public void SetMapZone(MapZone newZone) { buyOilField.RemoveListener(mapZone.buyOilField); buyCoalMine.RemoveListener(mapZone.buyCoalMine); buyLoggingCamp.RemoveListener(mapZone.buyLoggingSite); buyLobbyingPower.RemoveListener(mapZone.buyLobbyingPower); buyWasteDumpingSite.RemoveListener(mapZone.buyWasteDump); mapZone = newZone; buyOilField.AddListener(newZone.buyOilField); buyCoalMine.AddListener(newZone.buyCoalMine); buyLoggingCamp.AddListener(newZone.buyLoggingSite); buyWasteDumpingSite.AddListener(newZone.buyWasteDump); buyLobbyingPower.AddListener(newZone.buyLobbyingPower); }
static public void Start(MapRegion r, MapZone z, List <BasicTile> startZone) { //GameProcessor.encounterEnemies.Clear(); enemies.Clear(); region = r; zone = z; int min = z.zoneEncounterInfo.packSizeMin; int max = z.zoneEncounterInfo.packSizeMax; if (!cSpawnAmount.Equals(default(customSpawnAmount))) { min = cSpawnAmount.min; max = cSpawnAmount.max; } int amountOfEnemies = GamePlayUtility.Randomize(min, max); var spawnList = new List <TBAGW.KeyValuePair <int, EnemyAIInfo> >(); int index = 0; foreach (var item in zone.zoneEncounterInfo.enemySpawnChance) { spawnList.Add(new TBAGW.KeyValuePair <int, EnemyAIInfo>(item, z.zoneEncounterInfo.enemies[index])); index++; } spawnList = spawnList.OrderBy(ele => ele.Key).ToList(); while (enemies.Count < amountOfEnemies) { int maxTries = spawnList.Count; int currentTry = 0; while (currentTry < maxTries) { int percentage = GamePlayUtility.Randomize(0, 100); if (spawnList[currentTry].Key > percentage) { // enemies.Add(zone.zoneEncounterInfo.enemies[currentTry].ShallowCopy()); enemies.Add(spawnList[currentTry].Value.enemyCharBase); } currentTry++; } } //Console.WriteLine("I think I have a random list of enemies ready... Not sure though..."); // GenerateLocations(); NewGenerateLocationsCode(startZone); // return enemies; }
public void Start(MapZone zone, MapRegion region) { Show(); this.zone = zone; label2.Text = zone.ToString(); String enemies = ""; foreach (var item in zone.zoneEncounterInfo.enemies) { BaseCharacter temp = item.enemyCharBase; enemies += temp.CharacterName + " Spawn %: " + zone.zoneEncounterInfo.enemySpawnChance[zone.zoneEncounterInfo.enemies.IndexOf(item)] + "%\n"; } label3.Text = enemies; label5.Text = zone.zoneEncounterInfo.encounterChance + "%\n"; label7.Text = zone.zoneEncounterInfo.packSizeMin + " ~ " + zone.zoneEncounterInfo.packSizeMax + " enemies per battle"; this.region = region; }
public static bool Initialize(LuaScriptBattle lsb) { MapRegion mr = GameProcessor.loadedMap.mapRegions.Find(r => r.regionID == lsb.regionID); if (mr == null) { return(false); } MapZone mz = mr.regionZones.Find(z => z.zoneID == lsb.zoneID); if (mz == null) { return(false); } List <BasicTile> zoneTiles = new List <BasicTile>(); TBAGW.Utilities.Sprite.BaseSprite controller = TBAGW.Utilities.Control.Player.PlayerController.selectedSprite; controller.position = new Vector2(((int)lsb.partySpawn.x) * 64, ((int)lsb.partySpawn.y) * 64); controller.spriteGameSize.Location = controller.position.ToPoint(); controller.UpdatePosition(); if (mz.zoneTiles.Count == 0) { zoneTiles = GameProcessor.loadedMap.possibleTilesWithController(mz.returnBoundingZone(), TBAGW.Utilities.Control.Player.PlayerController.selectedSprite); mz.zoneTiles = zoneTiles; } else { zoneTiles = mz.zoneTiles; } var temp_loc = MapListUtility.returnMapRadius(2, zoneTiles, controller); //LUA.LuaScriptBattle.Initialize(lsb); foreach (var item in lsb.enemies) { item.ToEnemy(mz, temp_loc); } GameProcessor.EnableCombatStage(); GameProcessor.mainControllerBeforeCombat = TBAGW.Utilities.Control.Player.PlayerController.selectedSprite; CombatProcessor.InitializeFromScript(new Vector2(lsb.partySpawn.x, lsb.partySpawn.y), mr, mz, lsb); return(true); }
public void editZoneNode(MapNode node, int addOrDelete) { if (zoneCollection.ContainsKey(node.zoneId) == false && addOrDelete == OPERATE_DELETE) { return; } //Dictionary<MapNode, int> zoneDict; MapZone mapZone; if ((zoneCollection.ContainsKey(node.zoneId)) == false && addOrDelete == OPERATE_ADD) { mapZone = new MapZone(); //zoneDict = new Dictionary<MapNode, int>(); mapZone.id = node.zoneId; zoneCollection[node.zoneId] = mapZone; //zoneCollection[node.zoneId] = zoneDict; } else { //zoneDict = zoneCollection[node.zoneId]; mapZone = zoneCollection[node.zoneId]; } if (addOrDelete == OPERATE_ADD) { if (mapZone.nodeDict.ContainsKey(node) == true) { return; } else { mapZone.nodeDict[node] = 1; } } else if (addOrDelete == OPERATE_DELETE) { if (mapZone.nodeDict.ContainsKey(node)) { mapZone.nodeDict.Remove(node); } else { return; } } }
private void onStartEdit() { EditMapManager.Instance.EDIT_ZONE = true; MapZone editing_zone = new MapZone(); try { editing_zone.id = int.Parse(input_zoneId.text); } catch { editing_zone.id = 0; } editing_zone.countryflag = int.Parse(input_zone_country.text); editing_zone.type = int.Parse(input_zone_type.text); editing_zone.width = int.Parse(input_zone_width.text); editing_zone.height = int.Parse(input_zone_height.text); editing_zone.regiontype = int.Parse(input_zone_region.text); editing_zone.reliveHp = int.Parse(input_zone_reliveHp.text); string[] posList = input_zone_pos.text.Split(','); editing_zone.x = (int)PathUtil.Logic2RealX(int.Parse(posList[0])); editing_zone.y = (int)PathUtil.Logic2RealZ(int.Parse(posList[0])); EditMapManager.Instance.editing_zone_param = editing_zone; }
public void setBounds(GameObject targetMap) { float ratio = (float)Screen.width / (float)Screen.height; float ajuste = 0f; if (ratio >= 1.7f) { ajuste = 1.5f; } else if (ratio == 1.6f) { ajuste = 0.5f; } MapZone mapa = targetMap.GetComponent <MapZone>(); Transform pos = targetMap.GetComponent <Transform>(); limitTopLeftX = pos.position.x + (Camera.main.orthographicSize + (Camera.main.orthographicSize / 2) + ajuste); limitTopLeftY = pos.position.y - Camera.main.orthographicSize; limitBottomRightX = pos.position.x + mapa.TilesWidth - (Camera.main.orthographicSize + (Camera.main.orthographicSize / 2) + ajuste); limitBottomRightY = pos.position.y - mapa.TilesHeight + Camera.main.orthographicSize; }
public void Launch_EventFight_MapZone() { MapZone zoneTest = new MapZone(null, false, 2); for (int i = 0; i < 3; i++) { Console.WriteLine("Difficulty : {0}", i); foreach (Monster monster in zoneTest.EventFightRandom(i, null)) { Console.WriteLine("Name {0}, Level {1}, Race {2}, Front Position ? {3}", monster.Name, monster.Level, monster.Race, monster.FrontPosition); } } List <Monster> m = zoneTest.EventFightRandom(2, "slime"); Console.WriteLine("Difficulty : 3"); foreach (Monster monster in m) { Console.WriteLine("Name {0}, Level {1}, Race {2}, Front Position ? {3}", monster.Name, monster.Level, monster.Race, monster.FrontPosition); } }
private void MapZone_TryZoneStart(On.RoR2.MapZone.orig_TryZoneStart orig, MapZone self, Collider other) { orig(self, other); if (!Stage.instance) { return; } BulletstormPickupsComponent pickupsComponent = Stage.instance.GetComponent <BulletstormPickupsComponent>(); if (!pickupsComponent) { return; } CharacterBody characterBody = other.GetComponent <CharacterBody>(); if (!characterBody) { return; } TeamComponent teamComponent = characterBody.teamComponent; if (!teamComponent) { return; } if (teamComponent.teamIndex == TeamIndex.Player) { return; } if (self.zoneType == MapZone.ZoneType.OutOfBounds) { HealthComponent healthComponent = characterBody.healthComponent; if (healthComponent) { pickupsComponent.wasMapDeath = true; pickupsComponent.lastHitAttacker = healthComponent.lastHitAttacker; } } }
public void CreateWorld_2() { //The World MapWorld world = new MapWorld(); Dictionary <string, MapIsland> Islands = new Dictionary <string, MapIsland>(); //island 1 ------------------------------------------------------------ MapIsland island = new MapIsland(world, "island1"); island.PointX = 118; island.PointY = 31; //Instance for the Island MapInstance instance1 = new MapInstance(island, "island1_instance_1"); instance1.PointX = 130; instance1.PointY = 50; //list zone for instance on the island List <MapZone> listZone_instance1 = new List <MapZone>(); MapZone zone1 = new MapZone(instance1, true, 1); zone1.PointX = 50; zone1.PointY = 50; MapZone zone2 = new MapZone(instance1, true, 2); zone2.PointX = 150; zone2.PointY = 150; MapZone zone3 = new MapZone(instance1, true, 3); zone3.PointX = 250; zone3.PointY = 250; List <MapZone> listlink = new List <MapZone>(); listlink.Add(zone2); zone1.ListLink = listlink; listlink = new List <MapZone>(); listlink.Add(zone1); listlink.Add(zone3); zone2.ListLink = listlink; listlink = new List <MapZone>(); listlink.Add(zone2); zone3.ListLink = listlink; //Zone must be add like : first is the entry and last the exit listZone_instance1.Add(zone1); listZone_instance1.Add(zone2); listZone_instance1.Add(zone3); instance1.listZones = listZone_instance1; List <MapInstance> listinstances = new List <MapInstance>(); listinstances.Add(instance1); island.IslandInstances = listinstances; //city for the island MapCity city = new MapCity(island, "City1"); city.PointX = 100; city.PointY = 200; island.AddCity(city); //list sellable items for merchant and merch ListItems listI = new ListItems(); List <Item> itemsSell = new List <Item>(); itemsSell.Add(listI.Items[0]); Merchant merch1 = new Merchant("Vendeur général", itemsSell); merch1.PointX = 50; merch1.PointY = 325; merch1.Invent = world.Team.Invent; itemsSell.Add(listI.Items[1]); Merchant merch2 = new Merchant("herboriste", itemsSell); merch2.PointX = 250; merch2.PointY = 325; merch2.Invent = world.Team.Invent; //Add services Mortuary s1 = new Mortuary(city); s1.PointX = 300; s1.PointY = 110; Taverne s2 = new Taverne(); s2.PointX = 190; s2.PointY = 100; //list merchant for city List <object> listservices = new List <object>(); listservices.Add(merch1); listservices.Add(merch2); listservices.Add(s1); listservices.Add(s2); city.Services = listservices; //add island to world Islands.Add("island1", island); //island 2 ------------------------------------------------------------ island = new MapIsland(world, "island2"); island.PointX = 118; island.PointY = 231; //Instance for the Island instance1 = new MapInstance(island, "island2_instance_1"); instance1.PointX = 130; instance1.PointY = 250; //list zone for instance on the island listZone_instance1 = new List <MapZone>(); zone1 = new MapZone(instance1, true, 1); zone1.PointX = 50; zone1.PointY = 50; zone2 = new MapZone(instance1, true, 2); zone2.PointX = 150; zone2.PointY = 150; zone3 = new MapZone(instance1, true, 3); zone3.PointX = 250; zone3.PointY = 250; listlink = new List <MapZone>(); listlink.Add(zone2); zone1.ListLink = listlink; listlink = new List <MapZone>(); listlink.Add(zone1); listlink.Add(zone3); zone2.ListLink = listlink; listlink = new List <MapZone>(); listlink.Add(zone2); zone3.ListLink = listlink; listZone_instance1.Add(zone1); listZone_instance1.Add(zone2); listZone_instance1.Add(zone3); instance1.listZones = listZone_instance1; listinstances = new List <MapInstance>(); listinstances.Add(instance1); island.IslandInstances = listinstances; //city for the island city = new MapCity(island, "City2"); city.PointX = 200; city.PointY = 200; island.AddCity(city); //list sellable items for merchant and merch listI = new ListItems(); itemsSell = new List <Item>(); itemsSell.Add(listI.Items[1]); merch1 = new Merchant("Vendeur général", itemsSell); merch1.PointX = 50; merch1.PointY = 325; merch1.Invent = world.Team.Invent; //Add services s1 = new Mortuary(city); s1.PointX = 300; s1.PointY = 110; s2 = new Taverne(); s2.PointX = 190; s2.PointY = 100; //list merchant for city listservices = new List <object>(); listservices.Add(merch1); listservices.Add(s1); listservices.Add(s2); city.Services = listservices; //add island to world Islands.Add("island2", island); //End----------------------------------------------- //list link between island List <MapIsland> listlinkis = new List <MapIsland>(); listlinkis.Add(Islands["island2"]); Islands["island1"].ListLink = listlinkis; listlinkis = new List <MapIsland>(); listlinkis.Add(Islands["island1"]); Islands["island2"].ListLink = listlinkis; //add island to world world.Islands = Islands; world.ActualPosition = world.Islands["island1"]; //Serialize IFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream("../../../Ressources/NewWorld.bin", FileMode.Create, FileAccess.Write, FileShare.None)) { formatter.Serialize(stream, world); } }
public MapZone CreateZone(string name) { MapZone zone = new MapZone(this, name); zones.Add(name, zone); return zone; }
public void FromXml(string mapFilename) { XmlReaderSettings xmlSettings = new XmlReaderSettings(); XmlReader r = XmlReader.Create(mapFilename); // read until we find the start of the world description while (r.Read()) { // look for the start of the map description if (r.NodeType == XmlNodeType.Element) { if (r.Name == "WorldMap") { break; } } } // parse attributes for (int i = 0; i < r.AttributeCount; i++) { r.MoveToAttribute(i); // set the field in this object based on the element we just read switch (r.Name) { case "WorldName": worldName = r.Value; break; case "MinTileX": minTile.x = int.Parse(r.Value); break; case "MinTileZ": minTile.z = int.Parse(r.Value); break; case "MaxTileX": maxTile.x = int.Parse(r.Value); break; case "MaxTileZ": maxTile.z = int.Parse(r.Value); break; case "MinHeight": minHeight = float.Parse(r.Value); break; case "MaxHeight": maxHeight = float.Parse(r.Value); break; } } r.MoveToElement(); //Moves the reader back to the element node. // now parse the sub-elements while (r.Read()) { // look for the start of an element if (r.NodeType == XmlNodeType.Element) { // parse that element // save the name of the element string elementName = r.Name; switch (elementName) { case "Zone": MapZone zone = new MapZone(this, r); zones.Add(zone.Name, zone); break; case "Layer": MapLayer layer = MapLayer.MapLayerFactory(this, r); layers.Add(layer.LayerName, layer); layerAndWorldOWP.Add(layer); break; case "Property": properties.ParseProperty(r); break; } } else if (r.NodeType == XmlNodeType.EndElement) { break; } } }
private bool NewZonePlacementCallback(bool cancelled, Point location, object arg) { NewZoneData zoneData = (NewZoneData)arg; if (!cancelled) { // Check to see if the new zone overlaps any existing tiles for (int z = 0; z < zoneData.TilesHeight; z++) { int dz = z + gridOffset.z + location.Y; for (int x = 0; x < zoneData.TilesWidth; x++) { int dx = x + gridOffset.x + location.X; CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize); MapTile tile = worldMap.GetTile(tileCoord); if (tile != null) { // overlaps existing tiles return(false); } } } MapZone zone = worldMap.CreateZone(zoneData.ZoneName); int samplesPerTile = WorldMap.metersPerTile / zoneData.MetersPerSample; ValueMapLayer heightFieldLayer = worldMap.HeightFieldLayer as ValueMapLayer; for (int z = 0; z < zoneData.TilesHeight; z++) { int dz = z + gridOffset.z + location.Y; for (int x = 0; x < zoneData.TilesWidth; x++) { int dx = x + gridOffset.x + location.X; CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize); MapBuffer tileHeightmap = heightFieldLayer.CreateCompatibleMapBuffer(zoneData.Heightmap, zoneData.MetersPerSample, x * samplesPerTile, z * samplesPerTile, samplesPerTile, zoneData.MinHeight, zoneData.MaxHeight); MapTile tile = worldMap.CreateTile(tileCoord); tile.Zone = zone; if (tileHeightmap.MetersPerSample != heightFieldLayer.MetersPerSample) { tileHeightmap = tileHeightmap.Scale(worldMap.MetersPerTile / heightFieldLayer.MetersPerSample); } heightFieldLayer.CopyIn(tileCoord, tileHeightmap); ImageGridCell cell = imageGrid.CreateCell(x + location.X, z + location.Y); cell.Image = currentViewLayer.CreateThumbnail(tileCoord, worldMap.TileSize, imageGrid.CellSize); } } AddZone(zone); } return(true); }
protected void loadLayerHandler(object sender, EventArgs args) { ToolStripButton button = sender as ToolStripButton; MapZone zone = button.Tag as MapZone; using (LoadLayerDialog dlg = new LoadLayerDialog()) { DialogResult result; dlg.LayerNames = worldMap.LayerNames; result = dlg.ShowDialog(); if (result != DialogResult.OK) { return; } int tilesWidth = zone.MaxTileCoord.x - zone.MinTileCoord.x + 1; int tilesHeight = zone.MaxTileCoord.z - zone.MinTileCoord.z + 1; int zoneWidthMeters = tilesWidth * worldMap.TileSize / worldMap.OneMeter; int zoneHeightMeters = tilesHeight * worldMap.TileSize / worldMap.OneMeter; int metersPerPixel = zoneWidthMeters / dlg.LayerMapImage.Width; Debug.Assert(metersPerPixel == (zoneHeightMeters / dlg.LayerMapImage.Height)); int samplesPerTile = WorldMap.metersPerTile / metersPerPixel; MapLayer layer = worldMap.GetLayer(dlg.LayerName); for (int z = 0; z < tilesHeight; z++) { int dz = z + zone.MinTileCoord.z; for (int x = 0; x < tilesWidth; x++) { int dx = x + zone.MinTileCoord.x; CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize); MapBuffer tileMap; if (layer is ColorMapLayer) { ColorMapLayer tmpLayer = layer as ColorMapLayer; tileMap = tmpLayer.CreateCompatibleMapBuffer(dlg.LayerMapImage, metersPerPixel, x * samplesPerTile, z * samplesPerTile, samplesPerTile); } else { ValueMapLayer tmpLayer = layer as ValueMapLayer; tileMap = null; } MapTile tile = worldMap.GetTile(tileCoord); if (tileMap.MetersPerSample != layer.MetersPerSample) { tileMap = tileMap.Scale(worldMap.MetersPerTile / layer.MetersPerSample); } layer.CopyIn(tileCoord, tileMap); } } } }
public void saveMapXML() { XmlDocument xmlDocs = new XmlDocument(); string xmlPath = EditorConfig.ExcelDataDir + "../地图数据文件/xianwang/map/" + mapXmlId + ".xml"; XmlDeclaration dec = xmlDocs.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = xmlDocs.CreateElement("HLMapConfig"); xmlDocs.AppendChild(root); root.SetAttribute("resourceid", EditorData.mapTileId); root.SetAttribute("mapid", EditorData.mapId); Dictionary <int, string> row_region = new Dictionary <int, string>(); foreach (KeyValuePair <string, MapNpc> kp_npc in npcCollection) { MapNpc npcNode = kp_npc.Value; if (npcNode.target == null) { continue; } XmlElement ele_npc = xmlDocs.CreateElement("npc"); ele_npc.SetAttribute("id", npcNode.id.ToString()); ele_npc.SetAttribute("type", npcNode.type.ToString()); ele_npc.SetAttribute("x", npcNode.x.ToString()); ele_npc.SetAttribute("y", npcNode.y.ToString()); ele_npc.SetAttribute("direction", npcNode.direction.ToString()); ele_npc.SetAttribute("level", npcNode.level.ToString()); ele_npc.SetAttribute("scope", npcNode.scope.ToString()); ele_npc.SetAttribute("ai", npcNode.ai.ToString()); ele_npc.SetAttribute("modelId", npcNode.modelId); ele_npc.SetAttribute("name", npcNode.npcName.ToString()); ele_npc.SetAttribute("enemyType", npcNode.enemyType.ToString()); ele_npc.SetAttribute("num", npcNode.num.ToString()); ele_npc.SetAttribute("interval", npcNode.interval.ToString()); ele_npc.SetAttribute("height", npcNode.height.ToString()); ele_npc.SetAttribute("width", npcNode.width.ToString()); ele_npc.SetAttribute("chase", npcNode.chase.ToString()); ele_npc.SetAttribute("uniqueId", npcNode.uniqueId.ToString()); root.AppendChild(ele_npc); } foreach (KeyValuePair <int, MapZone> kp_zone in zoneCollection) { MapZone zoneNode = kp_zone.Value; if (zoneNode.target == null) { continue; } XmlElement ele_zone = xmlDocs.CreateElement("zonedef"); ele_zone.SetAttribute("id", zoneNode.id.ToString()); ele_zone.SetAttribute("type", zoneNode.type.ToString()); ele_zone.SetAttribute("regiontype", zoneNode.regiontype.ToString()); ele_zone.SetAttribute("contryflag", zoneNode.countryflag.ToString()); ele_zone.SetAttribute("x", zoneNode.x.ToString()); ele_zone.SetAttribute("y", zoneNode.y.ToString()); ele_zone.SetAttribute("width", zoneNode.width.ToString()); ele_zone.SetAttribute("height", zoneNode.height.ToString()); ele_zone.SetAttribute("zoneindex", zoneNode.zoneindex.ToString()); ele_zone.SetAttribute("eulerangles", zoneNode.eulerangles); root.AppendChild(ele_zone); row_region.Clear(); //fill nodes to dict by row num foreach (KeyValuePair <MapNode, int> kp_node in kp_zone.Value.nodeDict) { if (row_region.ContainsKey(kp_node.Key.y)) { row_region[kp_node.Key.y] += kp_node.Key.x + ","; } else { row_region[kp_node.Key.y] = kp_node.Key.x + ","; } } //append each row foreach (KeyValuePair <int, string> kp_region in row_region) { XmlElement ele_region = xmlDocs.CreateElement("region"); ele_region.SetAttribute("row", kp_region.Key.ToString()); ele_region.SetAttribute("points", kp_region.Value.Substring(0, kp_region.Value.Length - 1)); ele_zone.AppendChild(ele_region); } } foreach (KeyValuePair <int, MapWarp> kp_warp in warpCollection) { MapWarp warpNode = kp_warp.Value; if (warpNode.target == null) { continue; } XmlElement ele_warp = xmlDocs.CreateElement("waypoint"); ele_warp.SetAttribute("id", warpNode.id.ToString()); ele_warp.SetAttribute("type", warpNode.type.ToString()); ele_warp.SetAttribute("x", warpNode.warpX.ToString()); ele_warp.SetAttribute("y", warpNode.warpY.ToString()); ele_warp.SetAttribute("state", warpNode.state.ToString()); ele_warp.SetAttribute("name", warpNode.warpName); ele_warp.SetAttribute("openCondition", warpNode.openCondition.ToString()); ele_warp.SetAttribute("destMapId1", warpNode.destMapId.ToString()); ele_warp.SetAttribute("destPosX1", warpNode.destMapX.ToString()); ele_warp.SetAttribute("destPosY1", warpNode.destMapY.ToString()); ele_warp.SetAttribute("destMapId2", warpNode.destMapId.ToString()); ele_warp.SetAttribute("destPosX2", warpNode.destMapX.ToString()); ele_warp.SetAttribute("destPosY2", warpNode.destMapY.ToString()); ele_warp.SetAttribute("destMapId3", warpNode.destMapId.ToString()); ele_warp.SetAttribute("destPosX3", warpNode.destMapX.ToString()); ele_warp.SetAttribute("destPosY3", warpNode.destMapY.ToString()); ele_warp.SetAttribute("warpType", warpNode.warpType.ToString()); root.AppendChild(ele_warp); } foreach (KeyValuePair <int, MapDoor> kp_door in doorCollection) { MapDoor doorNode = kp_door.Value; if (doorNode.target == null) { continue; } XmlElement ele_door = xmlDocs.CreateElement("mapDoor"); ele_door.SetAttribute("id", doorNode.id.ToString()); ele_door.SetAttribute("type", doorNode.type.ToString()); ele_door.SetAttribute("x", doorNode.x.ToString()); ele_door.SetAttribute("y", doorNode.y.ToString()); ele_door.SetAttribute("width", doorNode.width.ToString()); ele_door.SetAttribute("height", doorNode.height.ToString()); ele_door.SetAttribute("state", doorNode.state.ToString()); ele_door.SetAttribute("res", doorNode.res); ele_door.SetAttribute("eulerangles", doorNode.eulerangles.ToString()); root.AppendChild(ele_door); } foreach (KeyValuePair <int, MapTrigger> kp_trigger in triggerCollection) { MapTrigger triggerNode = kp_trigger.Value; if (triggerNode.target == null) { continue; } XmlElement ele_trigger = xmlDocs.CreateElement("mapTrigger"); ele_trigger.SetAttribute("id", triggerNode.id.ToString()); ele_trigger.SetAttribute("type", triggerNode.type.ToString()); ele_trigger.SetAttribute("x", triggerNode.x.ToString()); ele_trigger.SetAttribute("y", triggerNode.y.ToString()); ele_trigger.SetAttribute("width", triggerNode.width.ToString()); ele_trigger.SetAttribute("height", triggerNode.height.ToString()); ele_trigger.SetAttribute("triggerType", triggerNode.triggerType.ToString()); try { ele_trigger.SetAttribute("triggerParam", triggerNode.triggerParam.ToString()); } catch { ele_trigger.SetAttribute("triggerParam", ""); } ele_trigger.SetAttribute("targetType", triggerNode.targetType.ToString()); ele_trigger.SetAttribute("targetParam", triggerNode.targetParam.ToString()); ele_trigger.SetAttribute("eulerangles", triggerNode.eulerangles.ToString()); root.AppendChild(ele_trigger); } foreach (KeyValuePair <int, MapEffectPoint> kp_effectpoint in effectPointCollection) { MapEffectPoint effectpointNode = kp_effectpoint.Value; if (effectpointNode.target == null) { continue; } XmlElement ele_effectpoint = xmlDocs.CreateElement("mapEffectPoint"); ele_effectpoint.SetAttribute("id", effectpointNode.id.ToString()); ele_effectpoint.SetAttribute("type", effectpointNode.type.ToString()); ele_effectpoint.SetAttribute("x", effectpointNode.x.ToString()); ele_effectpoint.SetAttribute("y", effectpointNode.y.ToString()); ele_effectpoint.SetAttribute("width", effectpointNode.width.ToString()); ele_effectpoint.SetAttribute("height", effectpointNode.height.ToString()); ele_effectpoint.SetAttribute("res", effectpointNode.res); ele_effectpoint.SetAttribute("eulerangles", effectpointNode.eulerangles.ToString()); root.AppendChild(ele_effectpoint); } foreach (KeyValuePair <int, MapLine> kp_line in lineCollection) { MapLine lineNode = kp_line.Value; if (lineNode.target == null) { continue; } XmlElement ele_line = xmlDocs.CreateElement("linedef"); ele_line.SetAttribute("id", lineNode.id.ToString()); ele_line.SetAttribute("type", lineNode.type.ToString()); ele_line.SetAttribute("x", lineNode.x.ToString()); ele_line.SetAttribute("y", lineNode.y.ToString()); ele_line.SetAttribute("startobjid", lineNode.starobjid.ToString()); string ptStr = ""; for (int j = 0; j < lineNode.linepts.Count; j++) { ptStr += lineNode.linepts[j].x.ToString() + " " + lineNode.linepts[j].y.ToString() + ";"; } ptStr = ptStr.Substring(0, ptStr.Length - 1); ele_line.SetAttribute("points", ptStr); root.AppendChild(ele_line); } xmlDocs.Save(xmlPath); Debug.Log("保存成功:" + xmlPath); }
public SaveStats(int maxHealth, int geo, MapZone mapZone, float playTime, int maxMPReserve, int permadeathMode, bool bossRushMode, float completionPercentage, bool unlockedCompletionRate) : base(maxHealth, geo, mapZone, playTime, maxMPReserve, permadeathMode, bossRushMode, completionPercentage, unlockedCompletionRate) { }
private bool CheckZones() { StartLocations = new List<Point>(); for (int i = 0; i < startLocationsCount; i++) { bool zoneFound = false; Point? centralPoint = null; while (!zoneFound) { // Get valid zones (non-sea zones with at least ZONE_SIZE_TRESHOLD compact area var validZones = zoneList.Where(p => p.valid); if (validZones.Count() < 1) { return false; } // Get biggest compact zone MapZone biggestCompact = null; foreach (var zone in validZones) { if (biggestCompact == null) biggestCompact = zone; else if (zone.compactSize > biggestCompact.compactSize) biggestCompact = zone; } // Get center of the biggest compact zone at least MIN_ZONE_DISTANCE from all start positions foreach (var point in biggestCompact.tiles) { // Check the distance to nearest start position bool validLocation = true; foreach (var item in StartLocations) { int xd = point.X - item.X; int yd = point.Y - item.Y; if (xd * xd + yd * yd < MIN_ZONE_DISTANCE * MIN_ZONE_DISTANCE) { validLocation = false; break; } } if (!validLocation) continue; // Get biggest value if (!centralPoint.HasValue) centralPoint = point; else if (tileZoneSize[point.X, point.Y] > tileZoneSize[centralPoint.Value.X, centralPoint.Value.Y]) centralPoint = point; } if (!centralPoint.HasValue) { biggestCompact.valid = false; zoneFound = false; } else { zoneFound = true; } } // Let this center is one of starting locations StartLocations.Add(centralPoint.Value); var startZone = new MapZone(); startZone.valid = false; startZone.tiles.Add(centralPoint.Value); zoneList.Add(startZone); // Make this zone inviable for next search Point[] borders = new Point[9] { centralPoint.Value, new Point(centralPoint.Value.X + MIN_ZONE_DISTANCE, centralPoint.Value.Y), new Point(centralPoint.Value.X - MIN_ZONE_DISTANCE, centralPoint.Value.Y), new Point(centralPoint.Value.X, centralPoint.Value.Y + MIN_ZONE_DISTANCE), new Point(centralPoint.Value.X, centralPoint.Value.Y - MIN_ZONE_DISTANCE), new Point(centralPoint.Value.X + MIN_ZONE_DISTANCE, centralPoint.Value.Y+ MIN_ZONE_DISTANCE), new Point(centralPoint.Value.X - MIN_ZONE_DISTANCE, centralPoint.Value.Y - MIN_ZONE_DISTANCE), new Point(centralPoint.Value.X - MIN_ZONE_DISTANCE, centralPoint.Value.Y + MIN_ZONE_DISTANCE), new Point(centralPoint.Value.X + MIN_ZONE_DISTANCE, centralPoint.Value.Y - MIN_ZONE_DISTANCE) }; // Assign new MapZones to the perimeter tiles so that the area within have lower map value foreach (var borderPoint in borders) { int nx = borderPoint.X; int ny = borderPoint.Y; if (nx < 0 || nx >= mapWidth) continue; if (ny < 0 || ny >= mapHeight) continue; tileZone[nx, ny].tiles.Remove(borderPoint); tileZone[nx, ny] = startZone; startZone.tiles.Add(borderPoint); tileZoneSize[nx, ny] = 0; } // Re-evaluate the mapzones for (int j = 0; j < 4; j++) { var surroundingPoint = GetSurroundingPoint(centralPoint.Value, Misc.FourDirection[j]); int nx = surroundingPoint.X; int ny = surroundingPoint.Y; if (nx < 0 || nx >= mapWidth) continue; if (ny < 0 || ny >= mapHeight) continue; DetermineSizes(tileZone[nx, ny], surroundingPoint); break; } } return true; }
public override string GetText() { MapZone mapZone = GetSanitizedMapzone(); return($"{PlayerData.instance.GetInt(nameof(PlayerData.grubsCollected))}({BingoUI.localSettings.AreaGrubs[mapZone]})"); }
public Meet(int result, MainForm Context, MapWorld World, MapZone zone) { InitializeComponent(); _context = Context; _world = World; _result = result; _mapZone = zone; if (result == 1) { //merchant label5.Text = "Ah ! Mais que vois-je ? Je suis un marchand ambulant, venez voir mes marchandises !"; label1.Text = "Non, merci."; label2.Text = "Oui, bien sûr !"; label3.Text = "Et si je me servais gratuitement ?"; pictureBox1.BackgroundImage = Image.FromFile(@"../../../Ressources/marchand.jpg"); } else if (result == 2) { //vieux string[] elder = zone.EventElder(); label5.Text = "Seriez-vous intéressé par une enigme ? La voilà : " + Environment.NewLine + elder[0]; label1.Text = "Non, merci."; Label[] listlabel = { label2, label3, label4 }; int ran = _context.world.Random.Next(0, 3); for (int i = 0; i < 3; i++) { if (i == ran) { listlabel[i].Text = elder[1]; _answerRiddle = elder[1]; } else { if (elder[2] != null) { listlabel[i].Text = elder[2]; elder[2] = null; } else { listlabel[i].Text = elder[3]; } } } pictureBox1.BackgroundImage = Image.FromFile(@"../../../Ressources/elder.png"); } else if (result == 3) { //rien label5.Text = "La zone semble déserte."; label1.Text = "Quitter"; pictureBox1.BackgroundImage = Image.FromFile(@"../../../Ressources/desert.png"); } else if (result == 4) { //fight label1.Text = "Quitter"; } else if (result == 5) { //bandit label5.Text = "Alte là ! La bourse ou la vie ?!"; label1.Text = "Fuir"; label2.Text = "Oui, tenez " + _world.Team.Invent.GetGold * 25 / 100 + " pièce d'or."; label3.Text = "Jamais !"; pictureBox1.BackgroundImage = Image.FromFile(@"../../../Ressources/bandit.jpg"); } label5.Location = new Point(label5.Parent.Width / 2 - label5.Width / 2, label5.Parent.Height / 2 - label5.Height / 2); }
protected void AddZone(MapZone zone) { TreeNode node = new TreeNode(zone.Name); node.Tag = zone; zonesNode.Nodes.Add(node); ContextMenuStrip menu = new ContextMenuStrip(); menu.ShowCheckMargin = false; menu.ShowImageMargin = false; menu.SuspendLayout(); ToolStripButton button = new ToolStripButton("Load Layer..."); button.Tag = zone; button.Click += new EventHandler(loadLayerHandler); menu.Items.Add(button); menu.ResumeLayout(); // update menu width int w = 0; foreach (ToolStripItem item in menu.Items) { if (item.Width > w) { w = item.Width; } } menu.Width = w; node.ContextMenuStrip = menu; }
void showNpcTool() { if (!npcLoaded) { if (GUILayout.Button("加载")) { loadNpc(); } } else { if (showAdd = EditorGUILayout.Foldout(showAdd, "添加npc")) { selAddNpc = GUILayout.Toolbar(selAddNpc, new string[] { "添加Npc", "添加怪物" }); if (selAddNpc == 0) { showNpcAdd(2); } else { showNpcAdd(1); } } EditorGUILayout.Separator(); if (showAddZone = EditorGUILayout.Foldout(showAddZone, "添加区域")) { EditorGUILayout.BeginVertical(); zone_id = EditorGUILayout.IntField("输入区域ID:", zone_id); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("区域类型:"); selReginType = EditorGUILayout.Popup(selReginType, regionType); if (GUILayout.Button("添加")) { MapZone node = new MapZone(); node.regiontype = selReginType; node.width = 4; node.height = 4; node.id = zone_id; npcHelper.AddZone(node); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } if (showAddWarp = EditorGUILayout.Foldout(showAddWarp, "添加传送门")) { if (GUILayout.Button("添加传送门")) { MapWarp node = new MapWarp(); npcHelper.AddWarp(node); } } if (showAddWarp = EditorGUILayout.Foldout(showAddWarp, "添加阻挡门")) { if (GUILayout.Button("添加阻挡门")) { MapDoor node = new MapDoor(); npcHelper.AddDoor(node); } } if (showAddWarp = EditorGUILayout.Foldout(showAddWarp, "添加触发器")) { if (GUILayout.Button("添加触发器")) { MapTrigger node = new MapTrigger(); npcHelper.AddTrigger(node); } } if (showAddWarp = EditorGUILayout.Foldout(showAddWarp, "添加地图特效")) { if (GUILayout.Button("添加地图特效")) { MapEffectPoint node = new MapEffectPoint(); npcHelper.AddEffectPoint(node); } } if (showAddLine = EditorGUILayout.Foldout(showAddLine, "添加挂机路线")) { EditorGUILayout.BeginVertical(); zone_id = EditorGUILayout.IntField("添加挂机路线:", line_starobjid); if (GUILayout.Button("添加挂机路线")) { MapLine node = new MapLine(line_starobjid); npcHelper.addLine(node); } EditorGUILayout.EndVertical(); } EditorGUILayout.Space(); EditorGUILayout.Separator(); if (GUILayout.Button("保存")) { try { npcHelper.saveMapXML(); // EditorGUILayout.HelpBox("保存成功 地图文件:" + mapFileName + ",通过性:" + curTile, MessageType.Info); } catch (Exception ex) { showError("保存失败"); } } GUILayout.Space(50); if (GUILayout.Button("重新加载npc表")) { EditorTool.LoadNpcConfig(); showAdd = false; } } }
private void DetermineSizes(MapZone zone, Point startAt) { // Determine sizes according to the neighbours Queue<Point> zonePoints = new Queue<Point>(); zonePoints.Enqueue(startAt); while (zonePoints.Count > 0) { Point currentZonePoint = zonePoints.Dequeue(); int x = currentZonePoint.X; int y = currentZonePoint.Y; int newTileValue = tileZoneSize[x, y]; int elev = MapElevations[x, y]; Point[] surroundingTiles = new Point[4]; for (int i = 0; i < 4; i++) { surroundingTiles[i] = GetSurroundingPoint(currentZonePoint, Misc.FourDirection[i]); } // if current tile is at the edge, set value to 1 if (x == 0 || x == mapWidth - 1) { newTileValue = 1; } else if (y == 0 || y == mapHeight - 1) { newTileValue = 1; } else { foreach (var point in surroundingTiles) { var surrTileZone = tileZone[point.X, point.Y]; var surrTileSize = tileZoneSize[point.X, point.Y]; var surrTileElev = MapElevations[point.X, point.Y]; // if neighbour is of another zone, set value to 1 if (surrTileZone != zone) { newTileValue = 1; break; } // if neighbour has too different elevation, set value to 1 if (Math.Abs(elev - surrTileElev) > CLIFF_THRESHOLD) { newTileValue = 1; break; } // if neighbour has (nonzero) lower value than the current tile, set value to neighbour's value + 1 if (surrTileSize != 0 && (surrTileSize + 1 < newTileValue || newTileValue == 0)) { newTileValue = surrTileSize + 1; } } } // if value has been changed, run update on neighbouring tiles if (newTileValue == tileZoneSize[x, y]) continue; tileZoneSize[x, y] = newTileValue; foreach (var point in surroundingTiles) { int nx = point.X; int ny = point.Y; if (nx < 0 || nx >= mapWidth) continue; if (ny < 0 || ny >= mapHeight) continue; // ignore it neighbour is of another zone if (tileZone[nx, ny] != zone) continue; // ignore if neighbour already has lower value var surrTileSize = tileZoneSize[nx, ny]; if (surrTileSize != 0 && surrTileSize + 1 < newTileValue) continue; // don't enqueue already queued tile if (zonePoints.Contains(point)) continue; zonePoints.Enqueue(point); } } // max value defines zone's compact size zone.compactSize = zone.tiles.Max(p => tileZoneSize[p.X, p.Y]); if (zone.compactSize < ZONE_SIZE_TRESHOLD) zone.valid = false; }
public override void OnZoneTrespass(CPlayerInfo playerInfo, ZoneAction action, MapZone sender, Point3D tresspassLocation, float tresspassPercentage, object trespassState) { base.OnZoneTrespass(playerInfo, action, sender, tresspassLocation, tresspassPercentage, trespassState); Output.Information("{0}: SoldierName:{1} Action:{2} Level:{3} Uid:{4} ZoneInclusive:{5} Location:({6},{7},{8}) Percentage:{9} State:{10}", "OnZoneTrespass", playerInfo.SoldierName, action, sender.LevelFileName, sender.UID, sender.ZoneInclusive, tresspassLocation.X, tresspassLocation.Y, tresspassLocation.Z, tresspassPercentage, trespassState); foreach (var item in sender.Tags) { Output.Information("{0}: MapZone Tag:{1}", "OnZoneTrespass", item); } foreach (var item in sender.ZonePolygon) { Output.Information("{0}: MapZone Polygon:({1},{2},{3})", "OnZoneTrespass", item.X, item.Y, item.Z); } }
public void LargeMapZone_MapZoneHit(MapZone sender, Entity entity, TeeEngine engine, GameTime gameTime) { }
/// <summary> /// Fires when a player takes [ZoneAction] and [flTresspassPercentage] > 0.0F /// </summary> /// <param name="cpiSoldier">The PlayerInfo object procon has on the player.</param> /// <param name="action">The action the player has taken on the zone</param> /// <param name="sender">The mapzone object that has fired the event</param> /// <param name="pntTresspassLocation">The location, reported by the game, that the action has taken place</param> /// <param name="flTresspassPercentage">The percentage (0.0F to 1.0F) that the circle created by the error radius (default 14m) that /// this player has tresspased on the zone at point [pntTresspassLocation].</param> /// <param name="trespassState">Additional information about the event. If the ZoneAction is Kill/Death then this object is type "Kill".</param> public virtual void OnZoneTrespass(CPlayerInfo playerInfo, ZoneAction action, MapZone sender, Point3D tresspassLocation, float tresspassPercentage, object trespassState) { }
public override void OnZoneTrespass(CPlayerInfo playerInfo, ZoneAction action, MapZone sender, Point3D tresspassLocation, float tresspassPercentage, object trespassState) { base.OnZoneTrespass(playerInfo, action, sender, tresspassLocation, tresspassPercentage, trespassState); }
public void readMapXML(string param_mapXmlId) { npcHelper.Reset(); mapXmlId = param_mapXmlId; XmlDocument xmlDocs = new XmlDocument(); string xmlPath = EditorConfig.ExcelDataDir + "../地图数据文件/xianwang/map/" + param_mapXmlId + ".xml"; if (File.Exists(xmlPath)) { XmlReaderSettings set = new XmlReaderSettings(); set.IgnoreComments = true; XmlReader reader = XmlReader.Create(xmlPath, set); xmlDocs.Load(reader); reader.Close(); XmlElement root = (XmlElement)xmlDocs.GetElementsByTagName("HLMapConfig")[0]; XmlNodeList npcXmlNodes = xmlDocs.GetElementsByTagName("npc"); for (int i = 0; i < npcXmlNodes.Count; i++) { XmlElement npcXml = (XmlElement)npcXmlNodes[i]; MapNpc npc_node = new MapNpc(int.Parse(npcXml.GetAttribute("id"))); npc_node.ai = int.Parse(npcXml.GetAttribute("ai")); if (npcXml.HasAttribute("chase")) { int.TryParse(npcXml.GetAttribute("chase"), out npc_node.chase); } npc_node.direction = int.Parse(npcXml.GetAttribute("direction")); npc_node.enemyType = int.Parse(npcXml.GetAttribute("enemyType")); npc_node.height = readIntAttribute(npcXml, "height"); npc_node.interval = readIntAttribute(npcXml, "interval"); npc_node.level = readIntAttribute(npcXml, "level"); npc_node.nkind = readIntAttribute(npcXml, "nkind"); npc_node.npcName = npcXml.GetAttribute("name").ToString(); npc_node.modelId = npcXml.GetAttribute("modelId"); npc_node.ntype = readIntAttribute(npcXml, "ntype"); npc_node.num = readIntAttribute(npcXml, "num"); npc_node.speed = readIntAttribute(npcXml, "speed"); npc_node.scope = readIntAttribute(npcXml, "scope"); npc_node.type = readIntAttribute(npcXml, "type"); npc_node.walklen = readIntAttribute(npcXml, "walklen"); npc_node.width = readIntAttribute(npcXml, "width"); npc_node.x = readIntAttribute(npcXml, "x"); npc_node.y = readIntAttribute(npcXml, "y"); npc_node.uniqueId = npcXml.GetAttribute("uniqueId"); editMapNpc(npc_node, OPERATE_ADD); } XmlNodeList zoneXmlNodes = xmlDocs.GetElementsByTagName("zonedef"); for (int i = 0; i < zoneXmlNodes.Count; i++) { XmlElement zoneXml = (XmlElement)zoneXmlNodes[i]; MapZone zone_node = new MapZone(); zone_node.id = int.Parse(zoneXml.GetAttribute("id")); try { zone_node.regiontype = int.Parse(zoneXml.GetAttribute("regiontype")); } catch { zone_node.type = 0; } zone_node.height = int.Parse(zoneXml.GetAttribute("height")); zone_node.type = int.Parse(zoneXml.GetAttribute("type")); zone_node.width = int.Parse(zoneXml.GetAttribute("width")); zone_node.x = int.Parse(zoneXml.GetAttribute("x")); zone_node.y = int.Parse(zoneXml.GetAttribute("y")); try { zone_node.countryflag = int.Parse(zoneXml.GetAttribute("contryflag")); } catch { zone_node.countryflag = 7; } try { zone_node.zoneindex = int.Parse(zoneXml.GetAttribute("zoneindex")); } catch { zone_node.zoneindex = 1; } try { zone_node.eulerangles = zoneXml.GetAttribute("eulerangles"); } catch { zone_node.eulerangles = ""; } foreach (XmlElement region_item in zoneXml.ChildNodes) { string[] col_list = region_item.GetAttribute("points").Split(','); for (int j = 0; j < col_list.Length; j++) { //id ,x ,y ,add MapNode region_node = new MapNode(zone_node.id, int.Parse(col_list[j]), int.Parse(region_item.GetAttribute("row")), OPERATE_ADD); zone_node.nodeDict[region_node] = 1; } } editWholeZone(zone_node, OPERATE_ADD); } XmlNodeList warpXmlNodes = xmlDocs.GetElementsByTagName("waypoint"); for (int i = 0; i < warpXmlNodes.Count; i++) { XmlElement warpXml = (XmlElement)warpXmlNodes[i]; MapWarp warp_node = new MapWarp(); warp_node.warpX = int.Parse(warpXml.GetAttribute("x")); warp_node.warpY = int.Parse(warpXml.GetAttribute("y")); //try { warp_node.regiontype = int.Parse(warpXml.GetAttribute("regiontype")); } //catch { warp_node.type = 0; } warp_node.warpName = warpXml.GetAttribute("name"); warp_node.type = int.Parse(warpXml.GetAttribute("type")); warp_node.state = int.Parse(warpXml.GetAttribute("state")); warp_node.destMapId = int.Parse(warpXml.GetAttribute("destMapId1")); warp_node.destMapX = int.Parse(warpXml.GetAttribute("destPosX1")); warp_node.destMapY = int.Parse(warpXml.GetAttribute("destPosY1")); warp_node.id = readIntAttribute(warpXml, "id"); warp_node.warpType = readIntAttribute(warpXml, "warpType"); try { warp_node.openCondition = int.Parse(warpXml.GetAttribute("openCondition")); } catch { warp_node.openCondition = 0; } addMapWarp(warp_node, OPERATE_ADD); } XmlNodeList doorXmlNodes = xmlDocs.GetElementsByTagName("mapDoor"); for (int i = 0; i < doorXmlNodes.Count; i++) { XmlElement doorXml = (XmlElement)doorXmlNodes[i]; MapDoor door_node = new MapDoor(); door_node.id = readIntAttribute(doorXml, "id"); door_node.type = int.Parse(doorXml.GetAttribute("type")); door_node.x = int.Parse(doorXml.GetAttribute("x")); door_node.y = int.Parse(doorXml.GetAttribute("y")); //try { warp_node.regiontype = int.Parse(warpXml.GetAttribute("regiontype")); } //catch { warp_node.type = 0; } door_node.width = int.Parse(doorXml.GetAttribute("width")); door_node.height = int.Parse(doorXml.GetAttribute("height")); door_node.state = int.Parse(doorXml.GetAttribute("state")); door_node.res = doorXml.GetAttribute("res"); door_node.eulerangles = doorXml.GetAttribute("eulerangles"); addMapDoor(door_node, OPERATE_ADD); } XmlNodeList triggerXmlNodes = xmlDocs.GetElementsByTagName("mapTrigger"); for (int i = 0; i < triggerXmlNodes.Count; i++) { XmlElement triggerXml = (XmlElement)triggerXmlNodes[i]; MapTrigger trigger_node = new MapTrigger(); trigger_node.id = readIntAttribute(triggerXml, "id"); trigger_node.type = int.Parse(triggerXml.GetAttribute("type")); trigger_node.x = int.Parse(triggerXml.GetAttribute("x")); trigger_node.y = int.Parse(triggerXml.GetAttribute("y")); trigger_node.width = int.Parse(triggerXml.GetAttribute("width")); trigger_node.height = int.Parse(triggerXml.GetAttribute("height")); //try { warp_node.regiontype = int.Parse(warpXml.GetAttribute("regiontype")); } //catch { warp_node.type = 0; } try { trigger_node.triggerType = int.Parse(triggerXml.GetAttribute("triggerType")); } catch { trigger_node.triggerType = 0; } try { trigger_node.triggerParam = triggerXml.GetAttribute("triggerParam"); } catch { trigger_node.triggerParam = ""; } trigger_node.targetType = int.Parse(triggerXml.GetAttribute("targetType")); trigger_node.targetParam = triggerXml.GetAttribute("targetParam"); trigger_node.eulerangles = triggerXml.GetAttribute("eulerangles"); addMapTrigger(trigger_node, OPERATE_ADD); } XmlNodeList effectPointXmlNodes = xmlDocs.GetElementsByTagName("mapEffectPoint"); for (int i = 0; i < effectPointXmlNodes.Count; i++) { XmlElement effectPointXml = (XmlElement)effectPointXmlNodes[i]; MapEffectPoint effectpoint_node = new MapEffectPoint(); effectpoint_node.id = int.Parse(effectPointXml.GetAttribute("id")); effectpoint_node.type = int.Parse(effectPointXml.GetAttribute("type")); effectpoint_node.x = int.Parse(effectPointXml.GetAttribute("x")); effectpoint_node.y = int.Parse(effectPointXml.GetAttribute("y")); effectpoint_node.width = int.Parse(effectPointXml.GetAttribute("width")); effectpoint_node.height = int.Parse(effectPointXml.GetAttribute("height")); effectpoint_node.res = effectPointXml.GetAttribute("res"); effectpoint_node.eulerangles = effectPointXml.GetAttribute("eulerangles"); addMapEffectPoint(effectpoint_node, OPERATE_ADD); } XmlNodeList lineXmlNodes = xmlDocs.GetElementsByTagName("linedef"); for (int i = 0; i < lineXmlNodes.Count; i++) { XmlElement lineXML = (XmlElement)lineXmlNodes[i]; MapLine line_node = new MapLine(int.Parse(lineXML.GetAttribute("startobjid"))); line_node.x = int.Parse(lineXML.GetAttribute("x")); line_node.y = int.Parse(lineXML.GetAttribute("y")); //try { warp_node.regiontype = int.Parse(warpXml.GetAttribute("regiontype")); } //catch { warp_node.type = 0; } line_node.id = int.Parse(lineXML.GetAttribute("id")); string ptStr = lineXML.GetAttribute("points"); line_node.type = int.Parse(lineXML.GetAttribute("type")); //line_node.pointsStr = ptStr; line_node.linepts = new List <MapLinePoint>(); string[] ptArr = ptStr.Split(';'); for (int j = 0; j < ptArr.Length; j++) { line_node.linepts.Add(new MapLinePoint(int.Parse(ptArr[j].Split(' ')[0]), int.Parse(ptArr[j].Split(' ')[1]))); } addMapLine(line_node, OPERATE_ADD); } } else { //XmlDeclaration dec = xmlDocs.CreateXmlDeclaration("1.0", "UTF-8", null); //xmlDocs.AppendChild(dec); //XmlElement root = xmlDocs.CreateElement("Hoolai"); //xmlDocs.AppendChild(root); //xmlDocs.Save(xmlPath); } initMapNpc(); initMapWarp(); initZone(); initLine(); initMapDoor(); initMapTrigger(); initMapEffectPoint(); }
public void saveMapXML() { XmlDocument xmlDocs = new XmlDocument(); string xmlPath = Application.streamingAssetsPath.Substring(0, Application.streamingAssetsPath.Length - 15) + "map/" + mapXmlId + ".xml"; XmlDeclaration dec = xmlDocs.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = xmlDocs.CreateElement("HLMapConfig"); xmlDocs.AppendChild(root); Dictionary <int, string> row_region = new Dictionary <int, string>(); foreach (KeyValuePair <string, MapNpc> kp_npc in npcCollection) { MapNpc npcNode = kp_npc.Value; XmlElement ele_npc = xmlDocs.CreateElement("npc"); ele_npc.SetAttribute("id", npcNode.id.ToString()); ele_npc.SetAttribute("type", npcNode.ntype.ToString()); ele_npc.SetAttribute("x", npcNode.x.ToString()); ele_npc.SetAttribute("y", npcNode.y.ToString()); ele_npc.SetAttribute("direction", npcNode.direction.ToString()); ele_npc.SetAttribute("level", npcNode.level.ToString()); ele_npc.SetAttribute("scope", npcNode.scope.ToString()); ele_npc.SetAttribute("ai", npcNode.ai.ToString()); ele_npc.SetAttribute("modelId", npcNode.modelId); //ele_npc.SetAttribute("name", npcNode.name.ToString()); ele_npc.SetAttribute("enemyType", npcNode.enemyType.ToString()); ele_npc.SetAttribute("num", npcNode.num.ToString()); ele_npc.SetAttribute("interval", npcNode.interval.ToString()); ele_npc.SetAttribute("height", npcNode.height.ToString()); ele_npc.SetAttribute("width", npcNode.width.ToString()); ele_npc.SetAttribute("chase", npcNode.chase.ToString()); ele_npc.SetAttribute("uniqueId", npcNode.uniqueId.ToString()); root.AppendChild(ele_npc); } foreach (KeyValuePair <int, MapZone> kp_zone in zoneCollection) { MapZone zoneNode = kp_zone.Value; XmlElement ele_zone = xmlDocs.CreateElement("zonedef"); ele_zone.SetAttribute("id", zoneNode.id.ToString()); ele_zone.SetAttribute("type", zoneNode.type.ToString()); ele_zone.SetAttribute("regintype", zoneNode.regiontype.ToString()); ele_zone.SetAttribute("countryflag", zoneNode.countryflag.ToString()); ele_zone.SetAttribute("x", zoneNode.x.ToString()); ele_zone.SetAttribute("y", zoneNode.y.ToString()); ele_zone.SetAttribute("width", zoneNode.width.ToString()); ele_zone.SetAttribute("height", zoneNode.height.ToString()); root.AppendChild(ele_zone); row_region.Clear(); //fill nodes to dict by row num foreach (KeyValuePair <MapNode, int> kp_node in kp_zone.Value.nodeDict) { if (row_region.ContainsKey(kp_node.Key.y)) { row_region[kp_node.Key.y] += kp_node.Key.x + ","; } else { row_region[kp_node.Key.y] = kp_node.Key.x + ","; } } //append each row foreach (KeyValuePair <int, string> kp_region in row_region) { XmlElement ele_region = xmlDocs.CreateElement("region"); ele_region.SetAttribute("row", kp_region.Key.ToString()); ele_region.SetAttribute("points", kp_region.Value.Substring(0, kp_region.Value.Length - 1)); ele_zone.AppendChild(ele_region); } } foreach (KeyValuePair <int, MapWarp> kp_warp in warpCollection) { MapWarp warpNode = kp_warp.Value; XmlElement ele_warp = xmlDocs.CreateElement("waypoint"); ele_warp.SetAttribute("id", warpNode.id.ToString()); ele_warp.SetAttribute("type", warpNode.type.ToString()); ele_warp.SetAttribute("x", warpNode.warpX.ToString()); ele_warp.SetAttribute("y", warpNode.warpY.ToString()); ele_warp.SetAttribute("state", warpNode.state.ToString()); ele_warp.SetAttribute("name", warpNode.warpName); ele_warp.SetAttribute("destMapId1", warpNode.destMapId.ToString()); ele_warp.SetAttribute("destPosX1", warpNode.destMapX.ToString()); ele_warp.SetAttribute("destPosY1", warpNode.destMapY.ToString()); ele_warp.SetAttribute("destMapId2", warpNode.destMapId.ToString()); ele_warp.SetAttribute("destPosX2", warpNode.destMapX.ToString()); ele_warp.SetAttribute("destPosY2", warpNode.destMapY.ToString()); ele_warp.SetAttribute("destMapId3", warpNode.destMapId.ToString()); ele_warp.SetAttribute("destPosX3", warpNode.destMapX.ToString()); ele_warp.SetAttribute("destPosY3", warpNode.destMapY.ToString()); root.AppendChild(ele_warp); } xmlDocs.Save(xmlPath); }
/// <summary> /// Fires when a player takes [ZoneAction] and [flTresspassPercentage] > 0.0F /// </summary> /// <param name="playerInfo">The PlayerInfo object procon has on the player.</param> /// <param name="action">The action the player has taken on the zone</param> /// <param name="sender">The mapzone object that has fired the event</param> /// <param name="tresspassLocation">The location, reported by the game, that the action has taken place</param> /// <param name="tresspassPercentage">The percentage (0.0F to 1.0F) that the circle created by the error radius (default 14m) that /// this player has tresspased on the zone at point [pntTresspassLocation].</param> /// <param name="trespassState">Additional information about the event. If the ZoneAction is Kill/Death then this object is type "Kill".</param> public virtual void OnZoneTrespass(CPlayerInfo playerInfo, ZoneAction action, MapZone sender, Point3D tresspassLocation, float tresspassPercentage, object trespassState) { }
private void GenerateTerrain() { double xoff = rand.NextDouble(); double yoff = rand.NextDouble(); PerlinNoise pn = new PerlinNoise(ROUGHNESS, 8, xoff, yoff); tileZone = new MapZone[mapWidth, mapHeight]; tileZoneSize = new int[mapWidth, mapHeight]; MapElevations = new int[mapWidth, mapHeight]; zoneList = new List<MapZone>(); for (int iRow = 0; iRow < mapHeight; iRow++) { for (int iCol = 0; iCol < mapWidth; iCol++) { // Get elevation double elevDouble = pn.PerlinNoise2D(iRow, iCol); Point point = new Point(iCol, iRow); int elev = (int)Math.Floor(elevDouble); MapElevations[iCol, iRow] = elev; bool underSea = elev < MapBoard.SEA_LEVEL; // Set mapzones (which will help us determining start locations) // Try to find valid neighbours List<Point> mergeCandidates = new List<Point>(); foreach (var dir in Misc.FourDirection) { Point iterPoint = GetSurroundingPoint(point, dir); if (iterPoint.X < 0 || iterPoint.Y < 0 || iterPoint.X >= mapWidth || iterPoint.Y >= mapHeight) continue; if (MapElevations[iterPoint.X, iterPoint.Y] == 0) continue; if (tileZone[iterPoint.X, iterPoint.Y] == null) continue; mergeCandidates.Add(iterPoint); } bool makeNew = true; // Try to merge into existing mapzone foreach (var iterPoint in mergeCandidates) { // Check boundaries if (iterPoint.X < 0) continue; if (iterPoint.Y < 0) continue; var iterZone = tileZone[iterPoint.X, iterPoint.Y]; var iterElev = MapElevations[iterPoint.X, iterPoint.Y]; var iterUnderSea = iterElev < MapBoard.SEA_LEVEL; bool merge = false; // If one Tile is land and other is sea, the zones are different if (iterUnderSea != underSea) { continue; } // Merge undersea tiles if (iterUnderSea) { merge = true; } // Land tiles that aren't forming cliff are in same zone else if (Math.Abs(iterElev - elev) <= MapBoard.CLIFF_THRESHOLD) { merge = true; } if (merge) { // If the tile has no mapzone, just assign the tile to the other mapzone if (tileZone[iCol, iRow] == null) { iterZone.tiles.Add(point); tileZone[iCol, iRow] = iterZone; } // otherwise we have to merge the current and other mapzone else if (tileZone[iCol, iRow] != iterZone) { MapZone mergeFrom = tileZone[iCol, iRow]; MapZone mergeTo = iterZone; if (mergeFrom.tiles.Count() > mergeTo.tiles.Count()) { var tmp = mergeTo; mergeTo = mergeFrom; mergeFrom = tmp; } for (int i = 0; i < mergeFrom.tiles.Count; i++) { Point aPoint = mergeFrom.tiles[i]; mergeTo.tiles.Add(aPoint); tileZone[aPoint.X, aPoint.Y] = mergeTo; } zoneList.Remove(mergeFrom); } makeNew = false; } } // If tile couldn't be assigned into other mapzone, create new if (makeNew) { var zone = new MapZone(); zone.tiles.Add(point); if (underSea) zone.valid = false; tileZone[iCol, iRow] = zone; zoneList.Add(zone); } } } }