public void ToEntity_WithValidDomain_ShouldMapCorrectly()
        {
            //Arrange
            var checkPoint = _fixture.Create <CheckPoint>();

            var expected = new CheckPointEntity
            {
                CheckPointId = checkPoint.CheckPointId,
                ShipmentId   = checkPoint.ShipmentId.GetValueOrDefault(),
                City         = checkPoint.City,
                Country      = checkPoint.Country,
                ControlType  = checkPoint.ControlType,
                PlaceType    = checkPoint.PlaceType,
                CreatedAt    = checkPoint.CreatedAt,
                UpdatedAt    = checkPoint.UpdatedAt
            };

            //Act
            var actualCheckPointEntity = checkPoint.ToEntity();

            //Assert
            actualCheckPointEntity
            .Should()
            .BeEquivalentTo(expected);
        }
Exemplo n.º 2
0
 public void setCheckpoint(CheckPointEntity checkpoint)
 {
     level.hasHadCheckpoint = true;
     destroyedStartEnts     = new Dictionary <int, Entity>(GlobalVars.removedStartingEntities);
     if (level.levelNum == 1)
     {
         preColor = !level.colorOrbObtained;
     }
     setSwitchCheckpoints();
     updatePlayerLoc();
 }
Exemplo n.º 3
0
        public async Task TryCheckout(CheckoutDto dto)
        {
            await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    CheckPointEntity checkPoint = await db.GetRepo <CheckPointEntity>().Get(dto.CheckPointId.Value);
                    AccountEntity account       = await db.GetRepo <AccountEntity>().Get(dto.AccountId.Value);

                    if (dto.CurrentManufactoryId.Value != checkPoint.Manufactory1Id && dto.CurrentManufactoryId.Value != checkPoint.Manufactory2Id)
                    {
                        DataValidationException exception = new DataValidationException();

                        exception.Add(
                            typeof(CheckoutDto), nameof(CheckoutDto.CurrentManufactoryId),
                            $"{nameof(CheckoutDto.CurrentManufactoryId)} must be one of manufactories associated with check point"
                            );

                        throw exception;
                    }

                    CheckPointEventEntity checkPointEvent = new CheckPointEventEntity()
                    {
                        account_id     = account.id,
                        check_point_id = checkPoint.id,
                        is_direct      = checkPoint.Manufactory1Id == dto.CurrentManufactoryId.Value,
                        timespan       = DateTime.Now
                    };

                    ManufactoryEntity targetManufactory = checkPointEvent.is_direct ? checkPoint.Manufactory2 : checkPoint.Manufactory1;
                    NotPermittedException ex            = null;

                    if (account.Roles.SelectMany(r => r.ManufactoryPermissions).Any(m => m.id == targetManufactory.id))
                    {
                        checkPointEvent.log = $"Checkout to Manufactory #{targetManufactory.id} via Check Point ${checkPoint.id} by Account #{account.id}: SUCCESS";
                    }
                    else
                    {
                        checkPointEvent.log = $"Checkout to Manufactory #{targetManufactory.id} via Check Point ${checkPoint.id} by Account #{account.id}: ACCESS DENIED";
                        ex = new NotPermittedException(checkPointEvent.log);
                    }

                    await db.GetRepo <CheckPointEventEntity>().Create(checkPointEvent);
                    await db.Save();

                    if (ex != null)
                    {
                        throw ex;
                    }
                }
            });
        }
Exemplo n.º 4
0
 public static CheckPoint ToDomain(this CheckPointEntity checkPoint)
 {
     return(checkPoint == null
                         ? null
                         : new CheckPoint(
                checkPointId: checkPoint.CheckPointId,
                shipmentId: checkPoint.ShipmentId,
                city: checkPoint.City,
                country: checkPoint.Country,
                controlType: checkPoint.ControlType,
                placeType: checkPoint.PlaceType,
                createdAt: checkPoint.CreatedAt,
                updatedAt: checkPoint.UpdatedAt));
 }
Exemplo n.º 5
0
        //Reads in a paint image and adds all entities to the level.
        public void readImage(Level level)
        {
            for (int y = 0; y < img.Height; y++)
            {
                for (int x = 0; x < img.Width; x++)
                {
                    //Get the color of the pixel
                    Color col = img.GetPixel(x, y);

                    float levelX = x;
                    float levelY = y;

                    //First check for cases which have some variation in possible color values
                    //i.e. something identified with only it's RG, or GB, or RB, or just R or G or B
                    if (col.R == switchReserveRed)
                    {
                        Entity s = null;

                        if (col.G == permSwitchG)
                        {
                            s = new SwitchEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight);
                        }
                        else if (col.G == presSwitchG)
                        {
                            //Pressure Switch
                            s = new PressureSwitchEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileWidth);
                            TimedSwitchComponent timeComp = ( TimedSwitchComponent )s.getComponent(GlobalVars.TIMED_SWITCH_COMPONENT_NAME);
                            timeComp.baseTime = 0;
                        }
                        else
                        {
                            s = new TimedSwitchEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileWidth);
                            TimedSwitchComponent timeComp = ( TimedSwitchComponent )s.getComponent(GlobalVars.TIMED_SWITCH_COMPONENT_NAME);
                            timeComp.baseTime = col.G / 10;
                        }
                        s.isStartingEntity = true;
                        adjustLocation(s, level);
                        switches.Add(col.B, s);
                        level.addEntity(s.randId, s);
                    }
                    else if (col.R == spikeSwitchReserveRed)
                    {
                        float time = -1;
                        if (col.G < 255)
                        {
                            time = col.G / 10;
                        }
                        Entity s = new SpikeSwitchEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight, time);

                        s.isStartingEntity = true;
                        adjustLocation(s, level);
                        switches.Add(col.B, s);
                        level.addEntity(s.randId, s);
                    }
                    else if (col.R == shooterRedUp || col.R == shooterRedRight || col.R == shooterRedDown || col.R == shooterRedLeft)
                    {
                        float betweenBursts = ( float )col.B / ( float )10;
                        int   switchId      = col.G;

                        TimedShooterEntity shooter = new TimedShooterEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight, betweenBursts, 1, col.R - 110, switchId);
                        if (switchId == 0)
                        {
                            shooter.removeComponent(GlobalVars.SWITCH_LISTENER_COMPONENT_NAME);
                        }
                        else
                        {
                            SwitchListenerComponent slComp = ( SwitchListenerComponent )shooter.getComponent(GlobalVars.SWITCH_LISTENER_COMPONENT_NAME);
                            if (switches.ContainsKey(switchId))
                            {
                                slComp.switchId = switches[switchId].randId;
                            }
                            else
                            {
                                unmachedSwitchListeners.Add(slComp, switchId);
                            }
                        }
                        adjustLocation(shooter, level);
                        shooter.isStartingEntity = true;
                        level.addEntity(shooter);
                    }
                    else if (col.R == smushRed && (col.B - 4 <= 0))
                    {
                        int switchId           = col.G;
                        SmushBlockEntity smush = new SmushBlockEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight, col.B, switchId);

                        if (switchId == 0)
                        {
                            smush.removeComponent(GlobalVars.SWITCH_LISTENER_COMPONENT_NAME);
                        }
                        else
                        {
                            SwitchListenerComponent slComp = ( SwitchListenerComponent )smush.getComponent(GlobalVars.SWITCH_LISTENER_COMPONENT_NAME);
                            if (switches.ContainsKey(switchId))
                            {
                                slComp.switchId = switches[switchId].randId;
                            }
                            else
                            {
                                unmachedSwitchListeners.Add(slComp, switchId);
                            }
                        }

                        adjustLocation(smush, level);
                        smush.isStartingEntity = true;
                        level.addEntity(smush);
                    }
                    else if (col.G == tallDoorReserveGreen || col.G == wideDoorReserveGreen || col.G == openTallDoorReserveGreen || col.G == openWideDoorReserveGreen)
                    {
                        float width  = tallDoorWidth;
                        float height = tallDoorHeight;

                        if (col.G == wideDoorReserveGreen || col.G == openWideDoorReserveGreen)
                        {
                            width  = wideDoorWidth;
                            height = wideDoorHeight;
                        }

                        DoorEntity door = new DoorEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight, width, height, (col.G % 100 == 0 || col.G % 100 == 1));
                        adjustLocation(door, level);
                        SwitchListenerComponent slComp = ( SwitchListenerComponent )door.getComponent(GlobalVars.SWITCH_LISTENER_COMPONENT_NAME);
                        door.isStartingEntity = true;
                        //check for its switch
                        if (switches.ContainsKey(col.B))
                        {
                            slComp.switchId = switches[col.B].randId;
                        }
                        else
                        {
                            unmachedSwitchListeners.Add(slComp, col.B);
                        }
                        level.addEntity(door);
                    }
                    else if (col.R == spikeRed && col.G == spikeGreen && (col.B - 4 <= 0))
                    {
                        SpikeEntity spike = new SpikeEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight, col.B);
                        adjustLocation(spike, level);
                        spike.isStartingEntity = true;
                        level.addEntity(spike);
                    }
                    else if (col.R == signRed && col.G == signGreen)
                    {
                        SignEntity signEnt = new SignEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight, col.B);
                        adjustLocation(signEnt, level);
                        signEnt.isStartingEntity = true;
                        level.addEntity(signEnt);
                    }

                    //Now just check for the specific colors
                    else if (col == playerCol)
                    {
                        Player player = new Player(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight);
                        adjustLocation(player, level);
                        PositionComponent posComp = ( PositionComponent )player.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                        level.getMovementSystem().teleportToNoCollisionCheck(posComp, posComp.x, posComp.y - GlobalVars.MIN_TILE_SIZE / 2);
                        posComp.setCurrentLocToStartingLoc();
                        player.isStartingEntity = true;
                        level.addEntity(player.randId, player);
                    }
                    else if (col == movePlatformTurn)
                    {
                        PlatformTurnEntity platTurn = new PlatformTurnEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight);
                        adjustLocation(platTurn, level);
                        platTurn.isStartingEntity = true;
                        level.addEntity(platTurn.randId, platTurn);
                    }
                    else if (col == basicGroundCol)
                    {
                        float groundX     = (levelX) * tileWidth;
                        float groundWidth = tileWidth;

                        BasicGround ground = new BasicGround(level, rand.Next(Int32.MinValue, Int32.MaxValue), groundX, (levelY) * tileHeight, groundWidth, tileHeight);
                        adjustLocation(ground, level);
                        ground.isStartingEntity = true;
                        level.addEntity(ground.randId, ground);

                        if (!GlobalVars.fullForegroundImage)
                        {
                            //If no ground above it, change to a grass sprite
                            List <Entity> above = level.getCollisionSystem().findObjectAtPoint((levelX) * tileWidth, (levelY - 1) * tileWidth);
                            if (above.Count <= 0 || !(above[0] is BasicGround))
                            {
                                ground.changeSprite(false);
                            }
                        }
                    }
                    else if (col == testEntityColor)
                    {
                        float      xLoc = (levelX) * tileWidth;
                        float      yLoc = (levelY) * tileHeight;
                        int        id   = rand.Next(Int32.MinValue, Int32.MaxValue);
                        TestEntity test = new TestEntity(level, id, xLoc, yLoc);
                        adjustLocation(test, level);
                        test.isStartingEntity = true;
                        level.addEntity(test.randId, test);
                    }
                    else if (col == simpleEnemyColor)
                    {
                        float             xLoc  = (levelX) * tileWidth;
                        float             yLoc  = (levelY) * tileHeight;
                        int               id    = rand.Next(Int32.MinValue, Int32.MaxValue);
                        SimpleEnemyEntity enemy = new SimpleEnemyEntity(level, id, xLoc, yLoc, false);
                        adjustLocation(enemy, level);
                        enemy.isStartingEntity = true;
                        level.addEntity(enemy.randId, enemy);
                    }
                    else if (col == flyingEnemyColor)
                    {
                        float             xLoc  = (levelX) * tileWidth;
                        float             yLoc  = (levelY) * tileHeight;
                        int               id    = rand.Next(Int32.MinValue, Int32.MaxValue);
                        FlyingEnemyEntity enemy = new FlyingEnemyEntity(level, id, xLoc, yLoc, false);
                        adjustLocation(enemy, level);
                        enemy.isStartingEntity = true;
                        level.addEntity(enemy.randId, enemy);
                    }
                    else if (col == shieldWalkingEnemyColor)
                    {
                        float             xLoc  = (levelX) * tileWidth;
                        float             yLoc  = (levelY) * tileHeight;
                        int               id    = rand.Next(Int32.MinValue, Int32.MaxValue);
                        SimpleEnemyEntity enemy = new SimpleEnemyEntity(level, id, xLoc, yLoc, true);
                        adjustLocation(enemy, level);
                        enemy.isStartingEntity = true;
                        level.addEntity(enemy.randId, enemy);
                    }
                    else if (col == shieldFlyingEnemyColor)
                    {
                        float             xLoc  = (levelX) * tileWidth;
                        float             yLoc  = (levelY) * tileHeight;
                        int               id    = rand.Next(Int32.MinValue, Int32.MaxValue);
                        FlyingEnemyEntity enemy = new FlyingEnemyEntity(level, id, xLoc, yLoc, true);
                        adjustLocation(enemy, level);
                        enemy.isStartingEntity = true;
                        level.addEntity(enemy.randId, enemy);
                    }
                    else if (col == checkPointCollider)
                    {
                        CheckPointEntity checkEnt = new CheckPointEntity(level, rand.Next(Int32.MinValue, Int32.MaxValue), levelX * tileWidth, levelY * tileHeight);
                        adjustLocation(checkEnt, level);
                        checkEnt.isStartingEntity = true;
                        level.addEntity(checkEnt.randId, checkEnt);
                    }/*else if ( col == checkPointCollider ) {
                      *
                      * float xLoc = ( levelX ) * tileWidth;
                      * float yLoc = ( levelY ) * tileHeight;
                      * int id = rand.Next( Int32.MinValue, Int32.MaxValue );
                      * EndLevelEntity lvlEnd = new EndLevelEntity( level, id, xLoc, yLoc );
                      * adjustLocation( lvlEnd, level );
                      * lvlEnd.isStartingEntity = true;
                      * level.addEntity( lvlEnd.randId, lvlEnd );
                      *
                      * }*/
                    else if (col == vertMovPlatCol)
                    {
                        float xLoc = (levelX) * tileWidth;
                        float yLoc = (levelY) * tileHeight;
                        int   id   = rand.Next(Int32.MinValue, Int32.MaxValue);

                        MovingPlatformEntity plat = new MovingPlatformEntity(level, id, xLoc, yLoc);
                        adjustLocation(plat, level);

                        plat.isStartingEntity = true;
                        level.addEntity(plat);
                    } /*else if ( col == horizMovPlatCol ) {
                       *
                       * float xLoc = ( levelX ) * tileWidth;
                       * float yLoc = ( levelY ) * tileHeight;
                       * int id = rand.Next( Int32.MinValue, Int32.MaxValue );
                       *
                       * MovingPlatformEntity plat = new MovingPlatformEntity( level, id, xLoc, yLoc );
                       * adjustLocation( plat, level );
                       *
                       * plat.isStartingEntity = true;
                       * MovingPlatformComponent movPlatComp = ( MovingPlatformComponent )plat.getComponent( GlobalVars.MOVING_PLATFORM_COMPONENT_NAME );
                       * movPlatComp.vertical = false;
                       * VelocityComponent velComp = ( VelocityComponent )plat.getComponent( GlobalVars.VELOCITY_COMPONENT_NAME );
                       * velComp.y = 0;
                       * level.addEntity( plat );
                       *
                       * }*/
                    else if (col == bouncePickup)
                    {
                        float xLoc = (levelX) * tileWidth;
                        float yLoc = (levelY) * tileHeight;
                        int   id   = rand.Next(Int32.MinValue, Int32.MaxValue);

                        PowerupPickupEntity pickup = new PowerupPickupEntity(level, id, xLoc, yLoc, GlobalVars.BOUNCE_NUM);
                        adjustLocation(pickup, level);

                        pickup.isStartingEntity = true;
                        level.addEntity(pickup);
                    }
                    else if (col == speedyPickup)
                    {
                        float xLoc = (levelX) * tileWidth;
                        float yLoc = (levelY) * tileHeight;
                        int   id   = rand.Next(Int32.MinValue, Int32.MaxValue);

                        PowerupPickupEntity pickup = new PowerupPickupEntity(level, id, xLoc, yLoc, GlobalVars.SPEED_NUM);
                        adjustLocation(pickup, level);

                        pickup.isStartingEntity = true;
                        level.addEntity(pickup);
                    }
                    else if (col == jmpPickup)
                    {
                        float xLoc = (levelX) * tileWidth;
                        float yLoc = (levelY) * tileHeight;
                        int   id   = rand.Next(Int32.MinValue, Int32.MaxValue);

                        PowerupPickupEntity pickup = new PowerupPickupEntity(level, id, xLoc, yLoc, GlobalVars.JMP_NUM);
                        adjustLocation(pickup, level);

                        pickup.isStartingEntity = true;
                        level.addEntity(pickup);
                    }
                    else if (col == glidePickup)
                    {
                        float xLoc = (levelX) * tileWidth;
                        float yLoc = (levelY) * tileHeight;
                        int   id   = rand.Next(Int32.MinValue, Int32.MaxValue);

                        PowerupPickupEntity pickup = new PowerupPickupEntity(level, id, xLoc, yLoc, GlobalVars.GLIDE_NUM);
                        adjustLocation(pickup, level);

                        pickup.isStartingEntity = true;
                        level.addEntity(pickup);
                    }
                    else if (col == spawnPickup)
                    {
                        float xLoc = (levelX) * tileWidth;
                        float yLoc = (levelY) * tileHeight;
                        int   id   = rand.Next(Int32.MinValue, Int32.MaxValue);

                        PowerupPickupEntity pickup = new PowerupPickupEntity(level, id, xLoc, yLoc, GlobalVars.SPAWN_NUM);
                        adjustLocation(pickup, level);

                        pickup.isStartingEntity = true;
                        level.addEntity(pickup);
                    }
                    else if (col == grapPickup)
                    {
                        float xLoc = (levelX) * tileWidth;
                        float yLoc = (levelY) * tileHeight;
                        int   id   = rand.Next(Int32.MinValue, Int32.MaxValue);

                        PowerupPickupEntity pickup = new PowerupPickupEntity(level, id, xLoc, yLoc, GlobalVars.GRAP_NUM);
                        adjustLocation(pickup, level);

                        pickup.isStartingEntity = true;
                        level.addEntity(pickup);
                    }
                    else if (col == visionOrbUnlock)
                    {
                        float xLoc = (levelX) * tileWidth;
                        float yLoc = (levelY) * tileHeight;
                        int   id   = rand.Next(Int32.MinValue, Int32.MaxValue);

                        VisionOrbUnlock visUnlock = new VisionOrbUnlock(level, id, xLoc, yLoc);
                        adjustLocation(visUnlock, level);

                        visUnlock.isStartingEntity = true;
                        level.addEntity(visUnlock);
                    }
                }
            }

            //Match any unmatched switch listeners to their switch
            foreach (SwitchListenerComponent sc in unmachedSwitchListeners.Keys)
            {
                if (switches.ContainsKey(unmachedSwitchListeners[sc]))
                {
                    SwitchListenerComponent slComp = sc;
                    slComp.switchId = switches[unmachedSwitchListeners[sc]].randId;
                }
                else
                {
                    Console.WriteLine("Unmatched Switch Listener - B: " + unmachedSwitchListeners[sc]);
                }
            }
        }
Exemplo n.º 6
0
 public void setupCheckpoint(CheckPointEntity checkpoint)
 {
     checkpointData.setCheckpoint(checkpoint);
 }