internal static bool HitTest(Vector3D srcPoint, Rectangle3D srcRectangle, SpatialTransform3D transform) { // Semi principal axes var a = srcRectangle.Width/2; var b = srcRectangle.Height/2; var c = srcRectangle.Depth/2; // Center of ellipse var x1 = srcRectangle.Left + a; var y1 = srcRectangle.Top + b; var z1 = srcRectangle.Front + c; return Math.Abs(ComputePointEllipsoidAltitude(a, b, c, new Vector3D(x1, y1, z1), srcPoint)) - 1 <= HitTestDistance/transform.CumulativeScale; }
private static Rectangle3D[] GetArea(BaseHouse house) { int x = house.X; int y = house.Y; //int z = house.Z; Rectangle2D[] houseArea = house.Area; var area = new Rectangle3D[houseArea.Length]; for (int i = 0; i < area.Length; i++) { Rectangle2D rect = houseArea[i]; area[i] = ConvertTo3D(new Rectangle2D(x + rect.Start.X, y + rect.Start.Y, rect.Width, rect.Height)); } return area; }
/// <summary> /// Serialize /// </summary> /// <param name="e"></param> private static void OnSave(WorldSaveEventArgs e) { string CurRegion = ""; try { if (Directory.Exists("Saves/Regions/Seasons/")) { Directory.Delete("Saves/Regions/Seasons/", true); } foreach (Region r in Region.Regions) { if (r != null) { if (!(r is ISeasons)) { continue; } if (r.GetType().IsAbstract || !r.GetType().IsSubclassOf(typeof(Region))) { continue; } CurRegion = r.Name; if (!Directory.Exists("Saves/Regions/Seasons/" + r.Map + "/")) { Directory.CreateDirectory("Saves/Regions/Seasons/" + r.Map + "/"); } string name = "(" + r.Name + ")"; string nameTmp = ""; #if (RUNUO_1) if (r.Coords != null) { for (int i = 0; i < r.Coords.Count; ++i) { object obj = r.Coords[i]; if (obj is Rectangle3D) { Rectangle3D r3d = ( Rectangle3D )obj; nameTmp += r3d.ToString( ); } else if (obj is Rectangle2D) { Rectangle2D r2d = ( Rectangle2D )obj; nameTmp += r2d.ToString( ); } } name += "(" + MD5Hash(nameTmp) + ")"; } if (name == null || name == "" || name.Length == 0) { name += "(" + r.UId + ")"; } #else if (r.Area != null) { for (int i = 0; i < r.Area.Length; ++i) { Rectangle3D r3d = r.Area[i]; nameTmp += r3d.ToString(); } name += "(" + MD5Hash(nameTmp) + ")"; } #endif try { GenericWriter writer = new BinaryFileWriter(Path.Combine("Saves/Regions/Seasons/" + r.Map + "/", name + ".bin"), true); Season season = ((ISeasons)r).Season; writer.Write((int)season); SavedCount++; writer.Close(); } catch (Exception ex1) { Console.WriteLine("[SeasonTracker] Serialize: ({0})", CurRegion); Console.WriteLine(ex1.ToString()); } } } } catch (Exception ex2) { Console.WriteLine("[SeasonTracker] OnSave: ({0})", CurRegion); Console.WriteLine(ex2.ToString()); } Console.WriteLine("[SeasonTracker] Saved {0} Region Seasons!", SavedCount); SavedCount = 0; }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); m_EventArea = reader.ReadRect3D(); UpdateRegions(); }
public void DoChooseArea(Mobile from, Map map, Point3D start, Point3D end, object control) { if (this != null) { List<Rectangle3D> areas = new List<Rectangle3D>(); if (m_RegionArea != null) { foreach (Rectangle3D rect in m_RegionArea) areas.Add(rect); } if (start.Z == end.Z || start.Z < end.Z) { if (start.Z != Server.Region.MinZ) --start.Z; if (end.Z != Server.Region.MaxZ) ++end.Z; } else { if (start.Z != Server.Region.MaxZ) ++start.Z; if (end.Z != Server.Region.MinZ) --end.Z; } Rectangle3D newrect = new Rectangle3D(start, end); areas.Add(newrect); m_RegionArea = areas.ToArray(); UpdateRegion(); } }
public VolumeHeaderData(IList<IDicomAttributeProvider> sourceSops, Size3D arrayDimensions, Vector3D voxelSpacing, Vector3D volumePositionPatient, Matrix3D volumeOrientationPatient, int bitsAllocated, int bitsStored, bool isSigned, int paddingValue, double rescaleSlope, double rescaleIntercept, RescaleUnits rescaleUnits, string laterality = null) { Platform.CheckForNullReference(sourceSops, "sourceSops"); Platform.CheckTrue(sourceSops.Count > 0, "At least one sourceSop is required"); Platform.CheckForNullReference(arrayDimensions, "arrayDimensions"); Platform.CheckForNullReference(voxelSpacing, "voxelSpacing"); Platform.CheckForNullReference(volumePositionPatient, "originPatient"); Platform.CheckForNullReference(volumeOrientationPatient, "orientationPatient"); _volumeOrientationPatient = volumeOrientationPatient; var firstSop = sourceSops[0]; ArrayDimensions = arrayDimensions; VoxelSpacing = voxelSpacing; VolumePositionPatient = volumePositionPatient; VolumeOrientationPatientX = volumeOrientationPatient.GetRow(0); VolumeOrientationPatientY = volumeOrientationPatient.GetRow(1); VolumeOrientationPatientZ = volumeOrientationPatient.GetRow(2); Modality = firstSop[DicomTags.Modality].ToString(); SourceStudyInstanceUid = firstSop[DicomTags.StudyInstanceUid].ToString(); SourceSeriesInstanceUid = firstSop[DicomTags.SeriesInstanceUid].ToString(); FrameOfReferenceUid = firstSop[DicomTags.FrameOfReferenceUid].ToString(); BitsPerVoxel = bitsAllocated; Signed = isSigned; PaddingValue = paddingValue; RescaleSlope = rescaleSlope; RescaleIntercept = rescaleIntercept; RescaleUnits = rescaleUnits ?? RescaleUnits.None; Laterality = laterality ?? string.Empty; VolumeSize = new Vector3D(ArrayDimensions.Width*VoxelSpacing.X, ArrayDimensions.Height*VoxelSpacing.Y, ArrayDimensions.Depth*VoxelSpacing.Z); VolumeBounds = new Rectangle3D(new Vector3D(0, 0, 0), VolumeSize); VolumeCenter = 0.5f*VolumeBounds.Size; VolumeCenterPatient = ConvertToPatient(VolumeCenter); // populate the DICOM data set FillDataSet(_collection, sourceSops, bitsAllocated, bitsStored, isSigned, rescaleSlope, rescaleIntercept, laterality); }
//public PointRadiusBuffer CreateRadiusBuffer(float[] radius) //{ // return (this.Factory as PointGridFactory).CreateRadiusBufferData(this, radius); //} //public PointRadiusBuffer CreateRadiusBuffer(float radius) //{ // return (this.Factory as PointGridFactory).CreateRadiusBufferData(this, radius); //} protected override Rectangle3D InitSourceActiveBounds() { if (this.Positions == null || this.Positions.Length <= 0) { throw new ArgumentException("Points has No Value"); } vec3 v = this.Positions[0]; var rect3d = new Rectangle3D(v, v); for (int i = 0; i < this.Positions.Length; i++) { rect3d.Union(this.Positions[i]); } return rect3d; }
private static void BuildTeleporters(string elementName, XmlElement root, ref int unique) { foreach (XmlElement region in root.GetElementsByTagName(elementName)) { var list = new Dictionary<WorldLocation, WorldLocation>(); Map locMap = null; Map teleMap = null; foreach (XmlElement tile in region.GetElementsByTagName("tiles")) { Point3D from = Point3D.Parse(Utility.GetAttribute(tile, "from", "(0, 0, 0)")); Map fromMap = Map.Parse(Utility.GetAttribute(tile, "frommap", null)); Point3D to = Point3D.Parse(Utility.GetAttribute(tile, "to", "(0, 0, 0)")); Map toMap = Map.Parse(Utility.GetAttribute(tile, "tomap", null)); int id = Utility.ToInt32(Utility.GetAttribute(tile, "ItemID", "-1")); int hue = Utility.ToInt32(Utility.GetAttribute(tile, "Hue", "-1")); if (fromMap == null) { throw new ArgumentException(string.Format("Map parsed as null: {0}", from)); } if (toMap == null) { throw new ArgumentException(string.Format("Map parsed as null: {0}", to)); } if (Siege.SiegeShard && (fromMap == Map.Trammel || toMap == Map.Trammel)) { continue; } list.Add(new WorldLocation(from, fromMap), new WorldLocation(to, toMap)); if (list.Count == 1) { locMap = fromMap; teleMap = toMap; } if (id > -1) { if (!fromMap.FindItems<Static>(from, 0).Any(s => s.ItemID == id)) { var st = new Static(id); if (hue > -1) { st.Hue = hue; } st.MoveToWorld(from, fromMap); } } } if (list.Count > 0) { Rectangle3D[] recs = new Rectangle3D[list.Count]; var i = 0; foreach (var kvp in list) { recs[i++] = new Rectangle3D(kvp.Key.Location.X, kvp.Key.Location.Y, kvp.Key.Location.Z - 5, 1, 1, 10); } TeleportRegion teleRegion; if (!Siege.SiegeShard && locMap != null && locMap.Rules != MapRules.FeluccaRules && teleMap.Rules == MapRules.FeluccaRules) { teleRegion = new TeleportRegionPVPWarning(string.Format("Teleport Region {0}", unique.ToString()), locMap, recs, list); } else { teleRegion = new TeleportRegion(string.Format("Teleport Region {0}", unique.ToString()), locMap, recs, list); } teleRegion.Register(); unique++; } } }
private void Compute(Rectangle3D area, ParallelLoopState state) { if (IsDisposed) { VitaNexCore.TryCatch(state.Stop); return; } // Check all corners to skip large bodies of water. if (Filters.Contains(TileFlag.Wet)) { var land1 = Facet.Tiles.GetLandTile(area.Start.X, area.Start.Y); // TL var land2 = Facet.Tiles.GetLandTile(area.End.X, area.Start.Y); // TR var land3 = Facet.Tiles.GetLandTile(area.Start.X, area.End.Y); // BL var land4 = Facet.Tiles.GetLandTile(area.End.X, area.End.Y); // BR if ((land1.Ignored || TileData.LandTable[land1.ID].Flags.HasFlag(TileFlag.Wet)) && (land2.Ignored || TileData.LandTable[land2.ID].Flags.HasFlag(TileFlag.Wet)) && (land3.Ignored || TileData.LandTable[land3.ID].Flags.HasFlag(TileFlag.Wet)) && (land4.Ignored || TileData.LandTable[land4.ID].Flags.HasFlag(TileFlag.Wet))) { return; } } int x, y, z, h; LandTile land; TileFlag flags; bool valid; for (x = area.Start.X; !IsDisposed && x < area.End.X; x++) { for (y = area.Start.Y; !IsDisposed && y < area.End.Y; y++) { h = GetHashCode(x, y); if (_Points.ContainsKey(h)) { continue; } land = Facet.Tiles.GetLandTile(x, y); if (land.Ignored) { continue; } z = land.Z; if (!CanSpawn(x, y, z)) { continue; } if (Filters.Length > 0) { flags = TileData.LandTable[land.ID].Flags; if (Filters.Any(f => flags.HasFlag(f))) { continue; } valid = true; foreach (var tile in Facet.Tiles.GetStaticTiles(x, y)) { flags = TileData.ItemTable[tile.ID].Flags; if (Filters.Any(f => flags.HasFlag(f))) { valid = false; break; } } if (!valid) { continue; } } if (Validator != null) { lock (Validator) { if (!Validator(Facet, x, y, z)) { continue; } } } if (IsDisposed) { break; } lock (_Points) { _Points[h] = new Point3D(x, y, z); } } } }
public void Invalidate() { if (IsDisposed) { return; } Interlocked.Exchange(ref _Image, null); Interlocked.Exchange(ref _ImageBG, null); Interlocked.Exchange(ref _ImageFG, null); _Points.Clear(); if (Facet == null || Facet == Map.Internal) { return; } Region region; if (String.IsNullOrWhiteSpace(Region) || Region == "Default") { region = Facet.DefaultRegion; } else if (!Facet.Regions.TryGetValue(Region, out region)) { return; } if (region == null || (!region.IsDefault && (region.Area == null || region.Area.Length == 0))) { return; } if (region.IsDefault) { var fw = Facet.MapID <= 1 ? 5120 : Facet.Width; var fh = Facet.MapID <= 1 ? 4096 : Facet.Height; var fd = Server.Region.MaxZ - Server.Region.MinZ; _Bounds = new Rectangle3D(0, 0, Server.Region.MinZ, fw, fh, fd); Parallel.ForEach(_Bounds.Slice(Stride, Stride), Compute); } else { int x1 = Int16.MaxValue, y1 = Int16.MaxValue, z1 = SByte.MaxValue; int x2 = Int16.MinValue, y2 = Int16.MinValue, z2 = SByte.MinValue; foreach (var o in region.Area) { x1 = Math.Min(x1, o.Start.X); y1 = Math.Min(y1, o.Start.Y); z1 = Math.Min(z1, o.Start.Z); x2 = Math.Max(x2, o.End.X); y2 = Math.Max(y2, o.End.Y); z2 = Math.Max(z2, o.End.Z); } _Bounds = new Rectangle3D(x1, y1, z1, x2 - x1, y2 - y1, z2 - z1); Parallel.ForEach(region.Area.SelectMany(r => r.Slice(Stride, Stride)), Compute); } Center = _Bounds.GetCenter2D(); }
protected override void OnGenerate() { base.OnGenerate(); CreateZone("Trial of Elements", new Rectangle2D(70, 1990, 180, 250)); //CreateZone("Trial of Elements Staging Area", new Rectangle2D(135, 2183, 50, 50)); CreateZone("Trial of Earth", Circles[0] = new Rectangle3D(135, 2055, 0, 50, 50, 100)); CreateZone("Trial of Fire", Circles[1] = new Rectangle3D(71, 1991, 0, 50, 50, 100)); CreateZone("Trial of Frost", Circles[2] = new Rectangle3D(199, 1991, 0, 50, 50, 100)); CreateZone("Trial of Poison", Circles[3] = new Rectangle3D(71, 2119, 0, 50, 50, 100)); CreateZone("Trial of Energy", Circles[4] = new Rectangle3D(199, 2119, 0, 50, 50, 100)); Altar = CreateItem <VoltaicAltar>(new Point3D(160, 2188, 0), false, new object[] { this }); StagingArea = new Rectangle3D(135, 2183, -20, 50, 50, 60); var center = StagingArea.Start.Clone2D(25, 25).ToPoint3D(); Stage.AddRange(center.GetAllPointsInRange(Map, 25, false).Select(p => CreateStatic(11846, p, false))); foreach (var s in Stage) { s.Hue = 2999; } foreach (var p in center.GetAllPointsInRange(Map, 25, 25, false)) { CreateItem <LOSBlocker>(p.ToPoint3D(20), false); } for (var i = 0; i < Floors.Length; i++) { center = Circles[i].Start.Clone2D(25, 25).ToPoint3D(); Floors[i] = center.GetAllPointsInRange(Map, 25, false).Select(p => CreateStatic(11846, p, false)).ToList(); foreach (var p in center.GetAllPointsInRange(Map, 25, 25, false)) { CreateItem <LOSBlocker>(p.ToPoint3D(20), false); } } Bosses[0] = BossEarth = CreateMobile <EarthAspect>(new Point3D(160, 2060, 0), true, true, 1.20); Bosses[1] = BossFire = CreateMobile <FireAspect>(new Point3D(96, 1996, 0), true, true, 1.40); Bosses[2] = BossFrost = CreateMobile <FrostAspect>(new Point3D(224, 1996, 0), true, true, 1.60); Bosses[3] = BossPoison = CreateMobile <PoisonAspect>(new Point3D(96, 2124, 0), true, true, 1.80); Bosses[4] = BossEnergy = CreateMobile <EnergyAspect>(new Point3D(224, 2124, 0), true, true, 2.00); for (var i = 0; i < Bosses.Length; i++) { if (Bosses[i] != null && !Bosses[i].Deleted) { Infos[i] = Pair.Create(Bosses[i].RawName, Bosses[i].Hue); } else { Infos[i] = Pair.Create("Elemental Aspect", 0); } } /*for (var i = 0; i < Bosses.Length; i++) * { * Bosses[i].Home = Circles[i].Start.Clone2D(25, 25).ToPoint3D(); * Bosses[i].RangeHome = 25; * }*/ for (var i = 0; i < Floors.Length; i++) { var hue = Bosses[i].Hue; Floors[i].ForEachReverse(s => s.Hue = hue); } var r = Utility.Random(360); for (var i = 0; i < TeleportersTo.Length; i++) { var a = Angle.FromDegrees(r + (i * 72)); var p = a.GetPoint3D(160, 2208, 0, 10); TeleportersTo[i] = CreateItem <InternalTeleporter>(p, false); } TeleportersFrom[0] = CreateItem <InternalTeleporter>(new Point3D(160, 2100, 0), false); TeleportersFrom[1] = CreateItem <InternalTeleporter>(new Point3D(96, 2036, 0), false); TeleportersFrom[2] = CreateItem <InternalTeleporter>(new Point3D(224, 2036, 0), false); TeleportersFrom[3] = CreateItem <InternalTeleporter>(new Point3D(96, 2164, 0), false); TeleportersFrom[4] = CreateItem <InternalTeleporter>(new Point3D(224, 2164, 0), false); for (var i = 0; i < TeleportersTo.Length && i < TeleportersFrom.Length; i++) { var t1 = TeleportersTo[i]; var t2 = TeleportersFrom[i]; t1.PointDest = t2.Location; t2.PointDest = t1.Location; t1.ItemID = t2.ItemID = 19403; t1.Movable = t2.Movable = false; t1.Visible = t2.Visible = true; t1.Active = t2.Active = true; t1.MapDest = t2.MapDest = Map; switch (i) { case 0: // Earth { t1.Name = "Trial of Earth [Tier 1]"; t2.Name = "Exit Trial of Earth"; t1.Hue = t2.Hue = BossEarth.Hue; } break; case 1: // Fire { t1.Name = "Trial of Fire [Tier 2]"; t2.Name = "Exit Trial of Fire"; t1.Hue = t2.Hue = BossFire.Hue; } break; case 2: // Frost { t1.Name = "Trial of Frost [Tier 3]"; t2.Name = "Exit Trial of Frost"; t1.Hue = t2.Hue = BossFrost.Hue; } break; case 3: // Poison { t1.Name = "Trial of Poison [Tier 4]"; t2.Name = "Exit Trial of Poison"; t1.Hue = t2.Hue = BossPoison.Hue; } break; case 4: // Energy { t1.Name = "Trial of Energy [Tier 5]"; t2.Name = "Exit Trial of Energy"; t1.Hue = t2.Hue = BossEnergy.Hue; } break; } } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); _BoardMap = version >= 2 ? reader.ReadMap() : Map; _AllowPlayerConfiguration = version < 1 || reader.ReadBool(); State = (BoardGameState) reader.ReadInt(); _CostToPlay = reader.ReadInt(); CurrentMaxPlayers = reader.ReadInt(); _BoardWidth = reader.ReadInt(); _BoardHeight = reader.ReadInt(); GameZone = new Rectangle3D(new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt()), new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt())); _BoardOffset = new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt()); int count = reader.ReadInt(); for (int i = 0; i < count; i++) { Players.Add(reader.ReadMobile()); } count = reader.ReadInt(); for (int i = 0; i < count; i++) { BackgroundItems.Add((GamePiece) reader.ReadItem()); } if (_State == BoardGameState.Pending || _State == BoardGameState.Recruiting) { _State = BoardGameState.Inactive; _Players = null; } _BoardGameRegion = new BoardGameRegion(this); _BoardGameRegion.Register(); _SettingsReady = !_AllowPlayerConfiguration; }
public RemoveAreaGump(RegionControl r) : base(25, 300) { m_Control = r; Closable = true; Dragable = true; Resizable = false; AddPage(0); AddBackground(23, 32, 412, 256, 9270); AddAlphaRegion(19, 29, 418, 263); AddLabel(186, 45, 1152, "Remove Area"); //+25 between 'em. int itemsThisPage = 0; int nextPageNumber = 1; if (r.RegionArea != null) { for (int i = 0; i < r.RegionArea.Length; i++) { Rectangle3D rect = ((Rectangle3D)r.RegionArea[i]); if (itemsThisPage >= 8 || itemsThisPage == 0) { itemsThisPage = 0; if (nextPageNumber != 1) { AddButton(393, 45, 4007, 4009, 0, GumpButtonType.Page, nextPageNumber); //Forward button -> #0 } AddPage(nextPageNumber++); if (nextPageNumber != 2) { AddButton(35, 45, 4014, 4016, 1, GumpButtonType.Page, nextPageNumber - 2); //Back Button -> #1 } } AddButton(70, 75 + 25 * itemsThisPage, 4017, 4019, 100 + i, GumpButtonType.Reply, 0); //Button is 100 + i //AddLabel(116, 77 + 25*i, 0, "(1234, 5678)"); AddLabel(116, 77 + 25 * itemsThisPage, 1152, String.Format("({0}, {1}, {2})", rect.Start.X, rect.Start.Y, rect.Start.Z)); AddLabel(232, 78 + 25 * itemsThisPage, 1152, "<-->"); //AddLabel(294, 77 + 25*i, 0, "(9876, 5432)"); AddLabel(294, 77 + 25 * itemsThisPage, 1152, String.Format("({0}, {1}, {2})", rect.End.X, rect.End.Y, rect.End.Z)); itemsThisPage++; } } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); switch (version) { case 6: { _minZ = reader.ReadInt(); _maxZ = reader.ReadInt(); goto case 5; } case 5: { m_EditAccessLevel = (AccessLevel)reader.ReadInt(); goto case 4; } case 4: { m_RegionArea = ReadRect3DArray(reader); m_Flags = (RegionFlag)reader.ReadInt(); m_RestrictedSpells = ReadBitArray(reader); m_RestrictedSkills = ReadBitArray(reader); m_Active = reader.ReadBool(); m_RegionName = reader.ReadString(); m_RegionPriority = reader.ReadInt(); m_Music = (MusicName)reader.ReadInt(); m_PlayerLogoutDelay = reader.ReadTimeSpan(); m_LightLevel = reader.ReadInt(); if (version <= 4) { reader.ReadMap(); reader.ReadPoint3D(); reader.ReadMap(); reader.ReadPoint3D(); } break; } case 3: //pre-RunUO 2.0 { m_LightLevel = reader.ReadInt(); goto case 2; } case 2: { m_Music = (MusicName)reader.ReadInt(); goto case 1; } case 1: { List <Rectangle2D> rects2d = ReadRect2DArray(reader); foreach (Rectangle2D rect in rects2d) { Rectangle3D newrect = Server.Region.ConvertTo3D(rect); DoChooseArea(null, this.Map, newrect.Start, newrect.End, this); } m_RegionPriority = reader.ReadInt(); m_PlayerLogoutDelay = reader.ReadTimeSpan(); m_RestrictedSpells = ReadBitArray(reader); m_RestrictedSkills = ReadBitArray(reader); m_Flags = (RegionFlag)reader.ReadInt(); m_RegionName = reader.ReadString(); break; } case 0: { List <Rectangle2D> rects2d = ReadRect2DArray(reader); foreach (Rectangle2D rect in rects2d) { Rectangle3D newrect = Server.Region.ConvertTo3D(rect); DoChooseArea(null, this.Map, newrect.Start, newrect.End, this); } m_RestrictedSpells = ReadBitArray(reader); m_RestrictedSkills = ReadBitArray(reader); m_Flags = (RegionFlag)reader.ReadInt(); m_RegionName = reader.ReadString(); break; } } m_AllControls.Add(this); if (RegionNameTaken(m_RegionName)) { m_RegionName = FindNewName(m_RegionName); } UpdateRegion(); }
public RegionControl(Rectangle3D rect): base(5609) { Visible = false; Movable = false; Name = "Region Controller"; if (m_AllControls == null) m_AllControls = new List<RegionControl>(); m_AllControls.Add(this); m_RegionName = FindNewName("Custom Region"); m_RegionPriority = CustomRegion.DefaultPriority; m_RestrictedSpells = new BitArray(SpellRegistry.Types.Length); m_RestrictedSkills = new BitArray(SkillInfo.Table.Length); DoChooseArea(null, this.Map, rect.Start, rect.End, this); if(m_Region != null) m_Region.GoLocation = new Point3D( 0, 0, 0 ); UpdateRegion(); }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); if (version >= 2) { _BoardMap = reader.ReadMap(); } else { _BoardMap = Map; } if (version >= 1) { _AllowPlayerConfiguration = reader.ReadBool(); } else { _AllowPlayerConfiguration = true; } State = (BoardGameState)reader.ReadInt(); _CostToPlay = reader.ReadInt(); CurrentMaxPlayers = reader.ReadInt(); _BoardWidth = reader.ReadInt(); _BoardHeight = reader.ReadInt(); GameZone = new Rectangle3D(new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt()), new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt())); _BoardOffset = new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt()); int count = reader.ReadInt(); for (int i = 0; i < count; i++) { Players.Add(reader.ReadMobile()); } count = reader.ReadInt(); for (int i = 0; i < count; i++) { BackgroundItems.Add((GamePiece)reader.ReadItem()); } if (_State == BoardGameState.Pending || _State == BoardGameState.Recruiting) { _State = BoardGameState.Inactive; _Players = null; } _BoardGameRegion = new BoardGameRegion(this); _BoardGameRegion.Register(); _SettingsReady = !_AllowPlayerConfiguration; }
public BritainTownSquareRegion(Rectangle3D area, Region parent, string name) : base(name, Map.Felucca, parent, area) { }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); m_ChallengeArea = new Rectangle3D[0]; switch (version) { case 2: case 1: { m_Disable = reader.ReadBool(); goto case 0; } case 0: { m_Music = (MusicName)reader.ReadInt(); m_Priority = reader.ReadInt(); if (version < 2) { // old region area reader.ReadRect2D(); } m_ChallengeRegionName = reader.ReadString(); string mapname = reader.ReadString(); try{ m_ChallengeMap = Map.Parse(mapname); } catch {} m_CopiedRegion = reader.ReadString(); // do the coord list int count = reader.ReadInt(); if (count > 0) { // the old version used 2D rectangles for the region area. The new version uses 3D if (version < 2) { Rectangle2D[] area = new Rectangle2D[count]; for (int i = 0; i < count; i++) { area[i] = reader.ReadRect2D(); } m_ChallengeArea = Region.ConvertTo3D(area); } else { m_ChallengeArea = new Rectangle3D[count]; for (int i = 0; i < count; i++) { m_ChallengeArea[i] = new Rectangle3D(reader.ReadPoint3D(), reader.ReadPoint3D()); } } } break; } } // refresh the region Timer.DelayCall(TimeSpan.Zero, new TimerCallback(RefreshRegions)); }
public static void ShowRectBounds(Rectangle3D r, Map m, Mobile from, bool control, bool active) { if (m == Map.Internal || m == null) return; int hue = 0; if(control && active) hue = 0x3F; else if(control && !active) hue = 0x26; else if(!control) hue = 1151; Point3D p1 = new Point3D(r.Start.X, r.Start.Y - 1, from.Z); //So we dont' need to create a new one each point Point3D p2 = new Point3D(r.Start.X, r.Start.Y + r.Height - 1, from.Z); //So we dont' need to create a new one each point Effects.SendLocationEffect(new Point3D(r.Start.X - 1, r.Start.Y - 1, from.Z), m, 251, 75, 1, hue, 3); //Top Corner //Testing color for (int x = r.Start.X; x <= (r.Start.X + r.Width - 1); x++) { p1.X = x; p2.X = x; p1.Z = from.Z; p2.Z = from.Z; Effects.SendLocationEffect(p1, m, 249, 75, 1, hue, 3); //North bound Effects.SendLocationEffect(p2, m, 249, 75, 1, hue, 3); //South bound } p1 = new Point3D(r.Start.X - 1, r.Start.Y - 1, from.Z); p2 = new Point3D(r.Start.X + r.Width - 1, r.Start.Y, from.Z); for (int y = r.Start.Y; y <= (r.Start.Y + r.Height - 1); y++) { p1.Y = y; p2.Y = y; p1.Z = from.Z; p2.Z = from.Z; Effects.SendLocationEffect(p1, m, 250, 75, 1, hue, 3); //West Bound Effects.SendLocationEffect(p2, m, 250, 75, 1, hue, 3); //East Bound } }
public abstract void Write(Rectangle3D value);
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); m_GuardedArea = reader.ReadRect3D(); m_UnguardedArea = reader.ReadRect3D(); m_RemoveLocation = reader.ReadPoint3D(); m_RemoveMap = reader.ReadMap(); UpdateRegions(); }
public override void Write(Rectangle3D value) { Write(value.Start); Write(value.End); }
//this method initializes the game control and connects it with this item public override void UpdatePosition() { GameZone = new Rectangle3D(new Point3D(X + BoardOffset.X, Y + BoardOffset.X, BoardOffset.Z - 100), new Point3D(X + BoardOffset.X + BoardWidth, Y + BoardOffset.Y + BoardHeight, BoardOffset.Z + 100)); base.UpdatePosition(); }
private void InitRectangles() { if (m_Rectangles != null) { return; } // Test if area rectangles are overlapping, and in that case break them into smaller non overlapping rectangles for (int i = 0; i < this.Area.Length; i++) { m_RectBuffer2.Add(this.Area[i]); for (int j = 0; j < m_RectBuffer1.Count && m_RectBuffer2.Count > 0; j++) { Rectangle3D comp = m_RectBuffer1[j]; for (int k = m_RectBuffer2.Count - 1; k >= 0; k--) { Rectangle3D rect = m_RectBuffer2[k]; int l1 = rect.Start.X, r1 = rect.End.X, t1 = rect.Start.Y, b1 = rect.End.Y; int l2 = comp.Start.X, r2 = comp.End.X, t2 = comp.Start.Y, b2 = comp.End.Y; if (l1 < r2 && r1 > l2 && t1 < b2 && b1 > t2) { m_RectBuffer2.RemoveAt(k); int sz = rect.Start.Z; int ez = rect.End.X; if (l1 < l2) { m_RectBuffer2.Add(new Rectangle3D(new Point3D(l1, t1, sz), new Point3D(l2, b1, ez))); } if (r1 > r2) { m_RectBuffer2.Add(new Rectangle3D(new Point3D(r2, t1, sz), new Point3D(r1, b1, ez))); } if (t1 < t2) { m_RectBuffer2.Add(new Rectangle3D(new Point3D(Math.Max(l1, l2), t1, sz), new Point3D(Math.Min(r1, r2), t2, ez))); } if (b1 > b2) { m_RectBuffer2.Add(new Rectangle3D(new Point3D(Math.Max(l1, l2), b2, sz), new Point3D(Math.Min(r1, r2), b1, ez))); } } } } m_RectBuffer1.AddRange(m_RectBuffer2); m_RectBuffer2.Clear(); } m_Rectangles = m_RectBuffer1.ToArray(); m_RectBuffer1.Clear(); m_RectangleWeights = new int[m_Rectangles.Length]; for (int i = 0; i < m_Rectangles.Length; i++) { Rectangle3D rect = m_Rectangles[i]; int weight = rect.Width * rect.Height; m_RectangleWeights[i] = weight; m_TotalWeight += weight; } }
public RegionControl(Rectangle3D[] rects): base(5609) { Visible = false; Movable = false; Name = "Region Controller"; if (m_AllControls == null) m_AllControls = new List<RegionControl>(); m_AllControls.Add(this); m_RegionName = FindNewName("Custom Region"); m_RegionPriority = Server.Region.DefaultPriority; m_RestrictedSpells = new BitArray(SpellRegistry.Types.Length); m_RestrictedSkills = new BitArray(SkillInfo.Table.Length); foreach (Rectangle3D rect3d in rects) { DoChooseArea(null, Map, rect3d.Start, rect3d.End, this); } UpdateRegion(); }
public Point3D RandomSpawnLocation(int spawnHeight, bool land, bool water, Point3D home, int range) { Map map = this.Map; if (map == Map.Internal) { return(Point3D.Zero); } InitRectangles(); if (m_TotalWeight <= 0) { return(Point3D.Zero); } for (int i = 0; i < 10; i++) // Try 10 times { int x, y, minZ, maxZ; if (home == Point3D.Zero) { int rand = Utility.Random(m_TotalWeight); x = int.MinValue; y = int.MinValue; minZ = int.MaxValue; maxZ = int.MinValue; for (int j = 0; j < m_RectangleWeights.Length; j++) { int curWeight = m_RectangleWeights[j]; if (rand < curWeight) { Rectangle3D rect = m_Rectangles[j]; x = rect.Start.X + rand % rect.Width; y = rect.Start.Y + rand / rect.Width; minZ = rect.Start.Z; maxZ = rect.End.Z; break; } rand -= curWeight; } } else { x = Utility.RandomMinMax(home.X - range, home.X + range); y = Utility.RandomMinMax(home.Y - range, home.Y + range); minZ = int.MaxValue; maxZ = int.MinValue; for (int j = 0; j < this.Area.Length; j++) { Rectangle3D rect = this.Area[j]; if (x >= rect.Start.X && x < rect.End.X && y >= rect.Start.Y && y < rect.End.Y) { minZ = rect.Start.Z; maxZ = rect.End.Z; break; } } if (minZ == int.MaxValue) { continue; } } if (x < 0 || y < 0 || x >= map.Width || y >= map.Height) { continue; } LandTile lt = map.Tiles.GetLandTile(x, y); int ltLowZ = 0, ltAvgZ = 0, ltTopZ = 0; map.GetAverageZ(x, y, ref ltLowZ, ref ltAvgZ, ref ltTopZ); TileFlag ltFlags = TileData.LandTable[lt.ID & TileData.MaxLandValue].Flags; bool ltImpassable = ((ltFlags & TileFlag.Impassable) != 0); if (!lt.Ignored && ltAvgZ >= minZ && ltAvgZ < maxZ) { if ((ltFlags & TileFlag.Wet) != 0) { if (water) { m_SpawnBuffer1.Add(ltAvgZ); } } else if (land && !ltImpassable) { m_SpawnBuffer1.Add(ltAvgZ); } } StaticTile[] staticTiles = map.Tiles.GetStaticTiles(x, y, true); for (int j = 0; j < staticTiles.Length; j++) { StaticTile tile = staticTiles[j]; ItemData id = TileData.ItemTable[tile.ID & TileData.MaxItemValue]; int tileZ = tile.Z + id.CalcHeight; if (tileZ >= minZ && tileZ < maxZ) { if ((id.Flags & TileFlag.Wet) != 0) { if (water) { m_SpawnBuffer1.Add(tileZ); } } else if (land && id.Surface && !id.Impassable) { m_SpawnBuffer1.Add(tileZ); } } } Sector sector = map.GetSector(x, y); for (int j = 0; j < sector.Items.Count; j++) { Item item = sector.Items[j]; if (!(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue && item.AtWorldPoint(x, y)) { m_SpawnBuffer2.Add(item); if (!item.Movable) { ItemData id = item.ItemData; int itemZ = item.Z + id.CalcHeight; if (itemZ >= minZ && itemZ < maxZ) { if ((id.Flags & TileFlag.Wet) != 0) { if (water) { m_SpawnBuffer1.Add(itemZ); } } else if (land && id.Surface && !id.Impassable) { m_SpawnBuffer1.Add(itemZ); } } } } } if (m_SpawnBuffer1.Count == 0) { m_SpawnBuffer1.Clear(); m_SpawnBuffer2.Clear(); continue; } int z; switch (m_SpawnZLevel) { case SpawnZLevel.Lowest: { z = int.MaxValue; for (int j = 0; j < m_SpawnBuffer1.Count; j++) { int l = m_SpawnBuffer1[j]; if (l < z) { z = l; } } break; } case SpawnZLevel.Highest: { z = int.MinValue; for (int j = 0; j < m_SpawnBuffer1.Count; j++) { int l = m_SpawnBuffer1[j]; if (l > z) { z = l; } } break; } default: // SpawnZLevel.Random { int index = Utility.Random(m_SpawnBuffer1.Count); z = m_SpawnBuffer1[index]; break; } } m_SpawnBuffer1.Clear(); if (!Region.Find(new Point3D(x, y, z), map).AcceptsSpawnsFrom(this)) { m_SpawnBuffer2.Clear(); continue; } int top = z + spawnHeight; bool ok = true; for (int j = 0; j < m_SpawnBuffer2.Count; j++) { Item item = m_SpawnBuffer2[j]; ItemData id = item.ItemData; if ((id.Surface || id.Impassable) && item.Z + id.CalcHeight > z && item.Z < top) { ok = false; break; } } m_SpawnBuffer2.Clear(); if (!ok) { continue; } if (ltImpassable && ltAvgZ > z && ltLowZ < top) { continue; } for (int j = 0; j < staticTiles.Length; j++) { StaticTile tile = staticTiles[j]; ItemData id = TileData.ItemTable[tile.ID & TileData.MaxItemValue]; if ((id.Surface || id.Impassable) && tile.Z + id.CalcHeight > z && tile.Z < top) { ok = false; break; } } if (!ok) { continue; } for (int j = 0; j < sector.Mobiles.Count; j++) { Mobile m = sector.Mobiles[j]; if (m.X == x && m.Y == y && (m.AccessLevel == AccessLevel.Player || !m.Hidden)) { if (m.Z + 16 > z && m.Z < top) { ok = false; break; } } } if (ok) { return(new Point3D(x, y, z)); } } return(Point3D.Zero); }
public static void WriteRect3DArray(GenericWriter writer, Rectangle3D[] ary) { if (ary == null) { writer.Write(0); return; } writer.Write(ary.Length); for (int i = 0; i < ary.Length; i++) { Rectangle3D rect = (ary[i]); writer.Write(rect.Start); writer.Write(rect.End); } return; }
public void DoChooseSpectatorArea(Mobile from, Map map, Point3D start, Point3D end, object control) { if (this != null) { List <Rectangle3D> areas = new List <Rectangle3D>(); if (this.m_SpectatorArea != null) { foreach (Rectangle3D rect in this.m_SpectatorArea) { areas.Add(rect); } } // Fix for incorrect X Coordinates... if (start.X < end.X) { end.X += 1; } else { start.X += 1; } // Fix for incorrect Y Coordinates... if (start.Y < end.Y) { end.Y += 1; } else { start.Y += 1; } // Added Lord Dio's Z Value Fix if (start.Z == end.Z || start.Z < end.Z) { if (start.Z != Server.Region.MinZ) { start.Z = Server.Region.MinZ; } if (end.Z != Server.Region.MaxZ) { end.Z = Server.Region.MaxZ; } } else { if (start.Z != Server.Region.MaxZ) { start.Z = Server.Region.MaxZ; } if (end.Z != Server.Region.MinZ) { end.Z = Server.Region.MinZ; } } Rectangle3D newrect = new Rectangle3D(start, end); areas.Add(newrect); this.m_SpectatorArea = areas.ToArray(); this.UpdateRegions(); from.CloseGump(typeof(ArenaInfoGump)); from.SendGump(new ArenaInfoGump()); from.CloseGump(typeof(SpectatorAreaGump)); from.SendGump(new SpectatorAreaGump(this)); } }
public SimpleNoHousingRegion(Map map, Rectangle3D[] area) : base(null, map, Region.DefaultPriority, area) { }
/// <summary> /// Deserialize /// </summary> private static void OnLoad() { string CurRegion = ""; try { foreach (Region r in Region.Regions) { if (r != null) { if (!(r is ISeasons)) { continue; } if (r.GetType().IsAbstract || !r.GetType().IsSubclassOf(typeof(Region))) { continue; } CurRegion = r.Name; if (!Directory.Exists("Saves/Regions/Seasons/" + r.Map + "/")) { Directory.CreateDirectory("Saves/Regions/Seasons/" + r.Map + "/"); } string name = "(" + r.Name + ")"; string nameTmp = ""; #if (RUNUO_1) if (r.Coords != null) { for (int i = 0; i < r.Coords.Count; ++i) { object obj = r.Coords[i]; if (obj is Rectangle3D) { Rectangle3D r3d = (Rectangle3D)obj; nameTmp += r3d.ToString(); } else if (obj is Rectangle2D) { Rectangle2D r2d = (Rectangle2D)obj; nameTmp += r2d.ToString(); } } name += "(" + MD5Hash(nameTmp) + ")"; } if (name == null || name == "" || name.Length == 0) { name += "(" + r.UId + ")"; } #else if (r.Area != null) { for (int i = 0; i < r.Area.Length; ++i) { Rectangle3D r3d = r.Area[i]; nameTmp += r3d.ToString(); } name += "(" + MD5Hash(nameTmp) + ")"; } #endif if (!File.Exists(Path.Combine("Saves/Regions/Seasons/" + r.Map + "/", name + ".bin"))) { return; } using (FileStream bin = new FileStream(Path.Combine("Saves/Regions/Seasons/" + r.Map + "/", name + ".bin"), FileMode.Open, FileAccess.Read, FileShare.Read)) { try { GenericReader reader = new BinaryFileReader(new BinaryReader(bin)); Season season = (Season)reader.ReadInt(); ((ISeasons)r).Season = season; LoadedCount++; } catch (Exception ex1) { Console.WriteLine("[SeasonTracker] Deserialize: ({0})", CurRegion); Console.WriteLine(ex1.ToString()); } } } } } catch (Exception ex2) { Console.WriteLine("[SeasonTracker] OnLoad: ({0})", CurRegion); Console.WriteLine(ex2.ToString()); } Console.WriteLine("[SeasonTracker] Tracking {0} Regions' Seasons...", LoadedCount); LoadedCount = 0; }