Beispiel #1
0
 private static Route CreateRoute(float x, float y, RegionF region)
 => new Route
 {
     Enforce = true,
     From    = new Vector2(x, y),
     To      = region.Midpoint
 };
Beispiel #2
0
 public Quad(RegionF region)
 {
     Points      = new Vector2[4];
     TopLeft     = new Vector2(region.X, region.Y);
     TopRight    = new Vector2(region.Right, region.Y);
     BottomLeft  = new Vector2(region.X, region.Bottom);
     BottomRight = new Vector2(region.Right, region.Bottom);
 }
        public bool Intersects(RegionF region)
        {
            var quad = new Quad(region);

            return(region.Contains(Origin) ||
                   Intersects(quad.GetLeftLine()) ||
                   Intersects(quad.GetTopLine()) ||
                   Intersects(quad.GetRightLine()) ||
                   Intersects(quad.GetBottomLine()));
        }
Beispiel #4
0
        internal static Line GetLineToRegion(float x, float y, RegionF region)
        {
            Line    line         = new Line(x, y, region.Midpoint.X, region.Midpoint.Y);
            Vector2?intersection = line.GetClosestIntersection(region);

            if (intersection.HasValue)
            {
                line.B = intersection.Value;
            }

            return(line);
        }
Beispiel #5
0
 private static Canvas CreateCanvas(RegionF region, ImmutableColor backgroundColor)
 => CreateCanvas(region.Width, region.Height, backgroundColor);
Beispiel #6
0
        private static void DrawRectangleOn(Canvas canvas, RegionF region, ImmutableColor color)
        {
            RegionF flat = RegionF.Floor(region);

            canvas.DrawRectangle((int)flat.X, (int)flat.Y, (int)flat.Width, (int)flat.Height, color);
        }
Beispiel #7
0
 internal static Line GetLineToRegion(Vector2 point, RegionF region)
 => GetLineToRegion(point.X, point.Y, region);
Beispiel #8
0
 // TODO: Transfer to .JSON file.
 public static World World => new World()
 {   // Okonos
     Id        = "world0",
     Name      = "Okonos",
     Perimeter = new Vector2(512, 512),
     Scale     = 1.0f, // 1 pixel in the world would take 1 minute at default ratio.
     // sectors are 1/4 of the distance ratio
     Sectors = new List <Sector>
     {
         new Sector("sector0", "Sector 0", new Vector2(16, 356), SectorScale.Small)
         {
             Exterior   = new Sprite(@"..\assets\exterior\exterior_test.png"),
             Entrance   = new Vector2(0, 16),
             Structures = new List <Structure>
             {
                 new Structure
                 {
                     Id    = "str_decor",
                     Name  = "The Devoid Fountain",
                     Shape = new RegionF(35, 23, 1, 1),
                     Type  = StructureType.Decoration
                 },
                 new Structure
                 {
                     Id    = "str_tent",
                     Name  = "Tent",
                     Shape = new RegionF(63, 63, 1, 1),
                     Type  = StructureType.Tent
                 }
             },
             Areas = new List <Area>
             {
                 new Area
                 {
                     Id        = "area0",
                     Name      = "Area A",
                     Shape     = new RegionF(0, 0, 32, 32),
                     Entrances = new List <Vector2>
                     {
                         new Vector2(32, 15)
                     },
                     Constructs = new List <Construct>
                     {
                         new Market("mk0", "Market A1")
                         {
                             CanBuyFrom  = true,
                             CanSellFrom = true,
                             SellRate    = 0.7f,
                             Tag         = ConstructType.Market,
                             Catalog     = new CatalogGenerator
                             {
                                 Size      = 4,
                                 Dimension = ItemDimension.Physical,
                                 MaxStack  = 2
                             },
                             Vendors = new List <Vendor>
                             {
                                 new Vendor
                                 {
                                     Id   = "vendor0",
                                     Name = "Vendor",
                                     // 0b MIND ENERGY NATURE TACTICS IDENTITY
                                     // 0b    1      1      0       0        0
                                     Personality = new Personality(0b11000),
                                     Schedule    = new Schedule
                                     {
                                         Shifts = new List <Shift>
                                         {
                                             new Shift(DayOfWeek.Saturday, 0, 0, TimeSpan.FromHours(22)),
                                             new Shift(DayOfWeek.Sunday, 0, 0, TimeSpan.FromHours(16)),
                                             new Shift(DayOfWeek.Tuesday, 0, 0, TimeSpan.FromHours(22)),
                                             new Shift(DayOfWeek.Wednesday, 0, 0, TimeSpan.FromHours(22))
                                         }
                                     }
                                 }
                             }
                         },
Beispiel #9
0
        // TODO: Use Engine.GetVisibleRegions(Husk husk);

        public bool Judge(Husk husk)
        {
            if (Ids?.Count() > 0)
            {
                return(Ids.Contains(husk.Location.Id));
            }

            if (Region.HasValue)
            {
                Location location = husk.Location.GetLocation();

                if (Structure.HasValue)
                {
                    var results = location.Filter(Structure.Value);

                    if (results.Any(x => (Interaction == InteractionType.View ? husk.Hitbox.Sight : husk.Hitbox.Reach)
                                    .Intersects(x.Shape)))
                    {
                        return(true);
                    }
                }

                if (Location.HasValue)
                {
                    if (Construct.HasValue && (location as Construct) != null)
                    {
                        if (!Construct.Value.HasFlag((location as Construct).Tag))
                        {
                            return(false);
                        }
                    }

                    if (!Location.Value.HasFlag(location.Type))
                    {
                        return(false);
                    }
                }

                if (!Region.Value.HasFlag(location.Subtype))
                {
                    return(false);
                }
            }

            if (X.HasValue && Y.HasValue)
            {
                float x = husk.Location.X;
                float y = husk.Location.Y;

                if (!string.IsNullOrWhiteSpace(Id))
                {
                    if (Id != husk.Location.Id)
                    {
                        return(false);
                    }
                }

                if (Width > 0 && Height > 0)
                {
                    return(RegionF.Contains(X.Value, Y.Value, Width, Height, x, y));
                }

                if (Radius > 0)
                {
                    return(CircleF.Contains(X.Value, Y.Value, Radius, x, y));
                }

                return((Interaction == InteractionType.View ? husk.Hitbox.Sight : husk.Hitbox.Reach)
                       .Contains(X.Value, Y.Value));
            }

            if (!string.IsNullOrWhiteSpace(Id))
            {
                if (Depth == BindDepth.In)
                {
                    Location location = Engine.World.Find(Id);

                    return(location.GetChildren().Any(x => x.Id == husk.Location.Id));
                }

                return(Id == husk.Location.Id);
            }

            Console.WriteLine("No eligible regions were matched.");
            return(false);
        }