Exemplo n.º 1
0
    public Container2D <GenSpace> GetGrid()
    {
        var map = new MultiMap <GenSpace>();

        map.PutAll(Grids, ShiftP);
        return(map);
    }
Exemplo n.º 2
0
    public override bool Place(Container2D <GenSpace> grid, LayoutObject obj, Theme theme, System.Random rand, out Boxing placed)
    {
        List <Bounding> options = obj.FindRectangles(GridWidth, GridLength, true, UnitTest);

        options = new List <Bounding>(options.Filter((bounds) =>
        {
            Counter counter = new Counter();
            grid.DrawRect(new Bounding(bounds, 1), FrontTest.IfThen(Draw.Count <GenSpace>(counter)));
            return(counter > 0);
        }));
        if (options.Count == 0)
        {
            placed = null;
            return(false);
        }
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
        {
            BigBoss.Debug.w(Logs.LevelGen, "Options:");
            if (GridWidth == 1 && GridLength == 1)
            {
                MultiMap <GenSpace> tmp = new MultiMap <GenSpace>();
                tmp.PutAll(obj);
                foreach (Bounding bounds in options)
                {
                    tmp.DrawRect(bounds, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, theme));
                }
                tmp.ToLog(Logs.LevelGen);
            }
            else
            {
                foreach (Bounding bounds in options)
                {
                    MultiMap <GenSpace> tmp = new MultiMap <GenSpace>();
                    tmp.PutAll(obj);
                    tmp.DrawRect(bounds, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, theme));
                    tmp.ToLog(Logs.LevelGen);
                }
            }
        }
        #endregion
        // Place startpoints
        placed = null;
        return(false);

        //placed = options.Random(rand);
        placed.Expand(1);
        GridLocation side = GridLocation.BOTTOMRIGHT;
        foreach (GridLocation loc in GridLocationExt.Dirs().Randomize(rand))
        {
            if (obj.DrawEdge(placed, loc, UnitTest, false))
            {
                side = loc;
                break;
            }
        }
        obj.DrawEdge(placed, side, Draw.SetTo(GridType.StairPlace, theme), false);
        return(true);
    }
Exemplo n.º 3
0
    public Container2D <GenSpace> GetGrid()
    {
        var map = new MultiMap <GenSpace>();

        foreach (ILayoutObject obj in Objects)
        {
            map.PutAll(obj.GetGrid());
        }
        return(map);
    }
        public async Task <Payment> CreatePayment(Guid accountId, Guid?paymentMethodId, PaymentTransaction paymentTransaction, List <string> controlPluginNames, Dictionary <string, string> pluginProperties, RequestOptions inputOptions)
        {
            var allowedTransactionTypes = new[] { "AUTHORIZE", "CREDIT", "PURCHASE" };

            if (accountId.Equals(Guid.Empty))
            {
                throw new ArgumentException("createPayment#accountId must not be empty");
            }

            if (paymentTransaction == null)
            {
                throw new ArgumentNullException(nameof(paymentTransaction));
            }

            if (!allowedTransactionTypes.Contains(paymentTransaction.TransactionType))
            {
                throw new ArgumentException("Invalid paymentTransaction type " + paymentTransaction.TransactionType);
            }

            if (paymentTransaction.Amount <= 0)
            {
                throw new ArgumentException("PaymentTransaction#amount cannot be 0 or less");
            }

            if (paymentTransaction.Currency == null)
            {
                throw new ArgumentException("PaymentTransaction#currency cannot be null");
            }

            var uri = Configuration.ACCOUNTS_PATH + "/" + accountId + "/" + Configuration.PAYMENTS;

            var param = new MultiMap <string>().Create(inputOptions.QueryParams);

            if (paymentMethodId.HasValue)
            {
                param.Add("paymentMethodId", paymentMethodId.ToString());
            }

            if (controlPluginNames != null && controlPluginNames.Count > 0)
            {
                param.PutAll(Configuration.CONTROL_PLUGIN_NAME, controlPluginNames);
            }

            StorePluginPropertiesAsParams(pluginProperties, ref param);
            var followLocation = inputOptions.FollowLocation ?? true;
            var requestOptions = inputOptions.Extend().WithQueryParams(param).WithFollowLocation(followLocation).Build();

            return(await _client.Post <Payment>(uri, paymentTransaction, requestOptions));
        }
Exemplo n.º 5
0
    public override bool Place(Container2D <GenSpace> grid, LayoutObject obj, Theme theme, Random rand, out Boxing placed)
    {
        int           max     = Math.Max(GridWidth, GridLength);
        List <Boxing> options = new List <Boxing>(
            grid.FindBoxes(
                GridWidth,
                GridLength,
                GridLocation.TOP,
                new BoxedAction <GenSpace>(
                    frontTest.And(Draw.ContainedIn(obj)),
                    unitTest),
                true,
                true,
                obj.Bounding.Expand(max))
            .Filter((box) =>
        {
            Counter counter = new Counter();
            bool ret        = grid.DrawEdge(box, box.Front,
                                            Draw.HasAround(false,
                                                           Draw.And(Draw.IsType <GenSpace>(GridType.Floor), Draw.Count <GenSpace>(counter)).
                                                           Or(Draw.Walkable())));
            return(ret && counter > 0);
        }));

        if (options.Count == 0)
        {
            placed = null;
            return(false);
        }
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
        {
            BigBoss.Debug.w(Logs.LevelGen, "Options:");
            foreach (Boxing boxing in options)
            {
                MultiMap <GenSpace> tmp = new MultiMap <GenSpace>();
                tmp.PutAll(obj);
                tmp.DrawRect(boxing, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, theme));
                tmp.DrawEdge(boxing, boxing.Front, Draw.SetTo(GridType.INTERNAL_RESERVED_BLOCKED, theme));
                tmp.ToLog(Logs.LevelGen);
            }
        }
        #endregion
        // Place startpoints
        placed = options.Random(rand);
        obj.DrawEdge(placed, placed.Front, Draw.Around(false, Draw.IsType <GenSpace>(GridType.Floor).IfThen(Draw.SetTo(GridType.StairPlace, theme))));
        return(true);
    }
Exemplo n.º 6
0
 public Container2D <GenSpace> GetConnectedGrid()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Get Connected Grid " + this);
     }
     #endregion
     List <LayoutObject> connected = ConnectedToAll();
     var arrOut = new MultiMap <GenSpace>();
     foreach (var obj in connected)
     {
         arrOut.PutAll(obj.Grids, obj.ShiftP);
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
     {
         BigBoss.Debug.printFooter(Logs.LevelGen, "Get Connected Grid " + this);
     }
     #endregion
     return(arrOut);
 }
Exemplo n.º 7
0
    protected void ClusterAround(LayoutObjectContainer cluster, LayoutObject obj)
    {
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader("Cluster Around");
        }
        #endregion
        obj.ShiftOutside(cluster, new Point(1, 0), null, false, false);
        obj.Shift(-1, 0); // Shift to overlapping slightly
        MultiMap <bool> visited = new MultiMap <bool>();
        visited[0, 0] = true;
        ProbabilityList <ClusterInfo> shiftOptions = new ProbabilityList <ClusterInfo>();
        Queue <Point> shiftQueue = new Queue <Point>();
        shiftQueue.Enqueue(new Point());
        Container2D <GenSpace> clusterGrid = cluster.GetGrid();
        Container2D <GenSpace> objGrid     = obj.GetGrid();
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            var tmp = new MultiMap <GenSpace>();
            tmp.PutAll(obj.GetGrid());
            tmp.PutAll(cluster.GetGrid());
            tmp.ToLog(Logs.LevelGen, "Starting placement");
        }
        #endregion
        while (shiftQueue.Count > 0)
        {
            Point curShift = shiftQueue.Dequeue();
            #region Debug
            if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen))
            {
                var tmpMap = new MultiMap <GenSpace>();
                tmpMap.PutAll(clusterGrid);
                tmpMap.PutAll(objGrid, curShift);
                tmpMap.ToLog(Logs.LevelGen, "Analyzing at shift " + curShift);
            }
            #endregion
            // Test if pass
            List <Point> intersectPoints = new List <Point>();
            if (objGrid.DrawAll((arr, x, y) =>
            {
                if (GridTypeEnum.EdgeType(arr[x, y].GetGridType()))
                {
                    GridType clusterType = clusterGrid[x + curShift.x, y + curShift.y].GetGridType();
                    if (clusterType == GridType.NULL)
                    {
                        return(true);
                    }
                    intersectPoints.Add(new Point(x, y));
                    return(GridTypeEnum.EdgeType(clusterType));
                }
                else
                {
                    return(!clusterGrid.Contains(x + curShift.x, y + curShift.y));
                }
            }) &&
                intersectPoints.Count > 0)
            { // Passed test
                // queue surrounding points
                visited.DrawAround(curShift.x, curShift.y, true, Draw.Not(Draw.EqualTo(true)).IfThen(Draw.AddTo <bool>(shiftQueue).And(Draw.SetTo(true))));

                #region Debug
                if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen))
                {
                    BigBoss.Debug.w(Logs.LevelGen, "passed with " + intersectPoints.Count);
                }
                #endregion
                shiftOptions.Add(new ClusterInfo()
                {
                    Shift = curShift, Intersects = intersectPoints
                }, Math.Pow(intersectPoints.Count, 3));
            }
        }
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            shiftOptions.ToLog(Logs.LevelGen, "Shift options");
        }
        #endregion
        List <Point> clusterDoorOptions = new List <Point>();
        ClusterInfo  info;
        var          placed = new List <Value2D <GenSpace> >(0);
        while (shiftOptions.Take(Rand, out info))
        {
            clusterGrid.DrawPoints(info.Intersects, Draw.CanDrawDoor().IfThen(Draw.AddTo <GenSpace>(clusterDoorOptions)).Shift(info.Shift));
            #region Debug
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                BigBoss.Debug.w(Logs.LevelGen, "selected " + info.Shift);
                var tmpMap = new MultiMap <GenSpace>();
                clusterGrid.DrawAll(Draw.CopyTo(tmpMap));
                objGrid.DrawAll(Draw.CopyTo(tmpMap, info.Shift));
                tmpMap.DrawPoints(info.Intersects, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, Theme).Shift(info.Shift));
                tmpMap.ToLog(Logs.LevelGen, "Intersect Points");
                tmpMap = new MultiMap <GenSpace>();
                clusterGrid.DrawAll(Draw.CopyTo(tmpMap));
                objGrid.DrawAll(Draw.CopyTo(tmpMap, info.Shift));
                tmpMap.DrawPoints(clusterDoorOptions, Draw.SetTo(GridType.Door, Theme));
                tmpMap.ToLog(Logs.LevelGen, "Cluster door options");
            }
            #endregion
            if (clusterDoorOptions.Count > 0)
            { // Cluster side has door options
                obj.Shift(info.Shift.x, info.Shift.y);
                placed = obj.PlaceSomeDoors(clusterDoorOptions, Theme, Rand);
                if (placed.Count != 0)
                { // Placed a door
                    foreach (Point p in placed)
                    {
                        LayoutObject clusterObj;
                        cluster.GetObjAt(p, out clusterObj);
                        obj.Connect(clusterObj);
                    }
                    break;
                }
                else
                {
                    #region Debug
                    if (BigBoss.Debug.logging(Logs.LevelGen))
                    {
                        BigBoss.Debug.w(Logs.LevelGen, "selected point failed to match " + info.Shift + ". Backing up");
                    }
                    #endregion
                    obj.Shift(-info.Shift.x, -info.Shift.y);
                }
            }
        }
        if (placed.Count == 0)
        {
            throw new ArgumentException("Could not cluster rooms");
        }
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            var tmpMap = new MultiMap <GenSpace>();
            tmpMap.PutAll(clusterGrid);
            tmpMap.PutAll(obj.GetGrid());
            tmpMap.ToLog(Logs.LevelGen, "Final setup " + info.Shift);
            BigBoss.Debug.printFooter("Cluster Around");
        }
        #endregion
    }
Exemplo n.º 8
0
    public static void ShiftOutside(this ILayoutObject obj, ILayoutObject rhs, Point dir, Point hint, bool rough, bool finalShift)
    {
        Point reducBase = dir.Reduce();
        Point reduc = new Point(reducBase);
        int   xShift, yShift;

        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, "Shift Outside " + obj.ToString());
            BigBoss.Debug.w(Logs.LevelGen, "Shifting outside of " + rhs.ToString());
            BigBoss.Debug.w(Logs.LevelGen, "Shift " + dir + "   Reduc shift: " + reduc);
            BigBoss.Debug.w(Logs.LevelGen, "Bounds: " + obj.Bounding + "  RHS bounds: " + rhs.Bounding);
            var tmp = new MultiMap <GenSpace>();
            tmp.PutAll(rhs.GetGrid());
            tmp.PutAll(obj.GetGrid());
            tmp.ToLog(Logs.LevelGen, "Before shifting");
        }
        #endregion
        Point at;
        while (obj.Intersects(rhs, hint, out at))
        {
            if (rough)
            {
                obj.Shift(reduc.x, reduc.y);
                at.Shift(reduc);
                hint = at;
            }
            else
            {
                reduc.Take(out xShift, out yShift);
                obj.Shift(xShift, yShift);
                if (reduc.isZero())
                {
                    reduc = new Point(reducBase);
                }
                at.Shift(xShift, yShift);
                hint = at;
            }
            #region DEBUG
            if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen))
            {
                BigBoss.Debug.w(Logs.LevelGen, "Intersected at " + at);
                var tmp = new MultiMap <GenSpace>();
                tmp.PutAll(rhs.GetGrid());
                tmp.PutAll(obj.GetGrid());
                tmp.ToLog(Logs.LevelGen, "After shifting");
            }
            #endregion
        }
        if (finalShift)
        {
            obj.Shift(dir.x, dir.y);
        }
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printFooter(Logs.LevelGen, "Shift Outside " + obj.ToString());
        }
        #endregion
    }