Пример #1
0
    void Start()
    {
        pool = Contexts.sharedInstance.pool;

        pool.GetGroup(PoolMatcher.Audio).OnEntityAdded    += OnAudioAdded;
        pool.GetGroup(PoolMatcher.GameOver).OnEntityAdded += (group, entity, index, component) => StopMusic();
    }
        private async Task ProcessBlockAsync(long height, PoolContext db, CancellationToken cancellationToken)
        {
            var period       = Period;
            var oldestHeight = height - period - 1;
            var accounts     = await db.Accounts.Where(i => i.Shares.Any(x => x.BlockId <= height && x.BlockId > oldestHeight) && !i.AverageShareHistory.Any(x => x.Height == height)).Select(i => i.Id).ToListAsync(cancellationToken);

            int counter = 0;

            foreach (var account in accounts)
            {
                if (await db.AccountAverageShareHistory.AnyAsync(x => x.AccountId == account && x.Height == height, cancellationToken))
                {
                    continue;
                }
                var shares = await db.Shares.Where(i => i.AccountId == account && i.BlockId <= height && i.BlockId > oldestHeight).Select(i => new { i.BlockId, i.ShareValue }).ToListAsync(cancellationToken);

                var average = shares.GroupBy(i => i.BlockId).Select(x => x.Max(t => t.ShareValue)).Sum() / period;
                Logger.LogInformation("Account {accountId}, computed average shares {average} for block {blockHeight}", account, average, height);
                db.AccountAverageShareHistory.Add(new AccountAverageShareHistory()
                {
                    AccountId     = account,
                    Height        = height,
                    AverageShares = average
                });
                counter += 1;
                // Save every 1000 inserts, to avoid performance hit.
                if (counter % 1000 == 0)
                {
                    await db.SaveChangesAsync(cancellationToken);
                }
            }
            await db.SaveChangesAsync(cancellationToken);
        }
Пример #3
0
        public IActionResult OnPost()
        {
            if (!"requestTeam".Equals(action))
            {
                return(OnGet());
            }
            PoolContext dbCtx = new PoolContext();

            availableTeams   = dbCtx.Teams.OrderBy(t => t.Name).Where(t => !dbCtx.Owners.Select(o => o.TeamId).Contains(t.TeamId)).ToList();
            ownerAssignments = dbCtx.Owners.OrderBy(o => o.Username).ToList();
            checkCurrentOwnership(dbCtx);
            String userId   = HttpContext.User.FindFirst(ClaimTypes.Name).Value.ToString();
            String fullName = findFullName();

            if (canRequest)
            {
                Team  chosenTeam = availableTeams.ToArray()[new Random().Next(availableTeams.Count)];
                Owner newOwner   = new Owner {
                    Username = userId,
                    Team     = chosenTeam,
                    FullName = fullName
                };
                dbCtx.Owners.Add(newOwner);
                dbCtx.SaveChanges();
            }
            dbCtx.Dispose();
            return(OnGet());
        }
Пример #4
0
    public static PoolEntity PlayAudio(this PoolContext context,
                                       BaseAudioComponent source)
    {
        var e = context.CreateEntity();

        e.AddAudio(source.clips, source.randomizePitch);
        return(e);
    }
Пример #5
0
    public static PoolEntity AddToFoodBag(this PoolContext context,
                                          int pointsToAdd)
    {
        int existingPoints = context.foodBag.points;

        context.ReplaceFoodBag(pointsToAdd + existingPoints);
        return(context.foodBagEntity);
    }
Пример #6
0
 public static void DestroyEntityIfEmpty(this PoolContext context,
                                         PoolEntity entity)
 {
     if (entity.GetComponentIndices().Length == 0)
     {
         context.DestroyEntity(entity);
     }
 }
Пример #7
0
 private void Initializers(PlayerData playerData, PoolContext poolContext, LevelGeneratorData levelGeneratorData)
 {
     new PlayerInitializeController(playerData, poolContext.PlayerStartPosition, poolContext);
     new LevelGeneratorInitializeController(poolContext, levelGeneratorData);
     new CameraInitializeController(poolContext);
     new WheelieDetectorInitializeController(poolContext);
     new PlayerDistanceViewInitializeContoller(poolContext);
     new PlayerWheelieViewInitializeController(poolContext);
 }
Пример #8
0
    public TurnSystem(Contexts contexts)
        : base(contexts.pool)
    {
        pool = contexts.pool;

        turnBasedEntities = pool.GetGroup(PoolMatcher.TurnBased);
        turnBasedEntities.OnEntityAdded   += OnTurnBasedEntityAdded;
        turnBasedEntities.OnEntityRemoved += OnTurnBasedEntityRemoved;
    }
Пример #9
0
 private void Controllers(PoolContext poolContext, MainControllers updateController)
 {
     updateController.Add(new PlayerInputController(poolContext));
     updateController.Add(new LevelGeneratorController(poolContext));
     updateController.Add(new CameraController(poolContext));
     updateController.Add(new WheelieDetectorController(poolContext));
     updateController.Add(new PlayerDistanceView(poolContext));
     updateController.Add(new PlayerWheelieView(poolContext));
     updateController.Add(new RestartGameEventController(poolContext));
 }
Пример #10
0
        public IActionResult OnGet()
        {
            PoolContext dbCtx = new PoolContext();

            availableTeams   = dbCtx.Teams.OrderBy(t => t.Name).Where(t => !dbCtx.Owners.Select(o => o.TeamId).Contains(t.TeamId)).ToList();
            ownerAssignments = dbCtx.Owners.Include(o => o.Team).OrderBy(o => o.Username).ToList();
            checkCurrentOwnership(dbCtx);
            dbCtx.Dispose();
            return(Page());
        }
Пример #11
0
    public static bool IsGameBoardPositionOpen(this PoolContext context, int x, int y,
                                               out ICollection <PoolEntity> entities)
    {
        var  gameBoard = context.gameBoard;
        bool edge      = x == -1 || x == gameBoard.columns || y == -1 || y == gameBoard.rows;

        if (edge)
        {
            entities = null;
            return(false);
        }
        entities = context.gameBoardCache.grid[x, y];
        return(entities == null || entities.Empty());
    }
Пример #12
0
    public Contexts()
    {
        pool = new PoolContext();

        var postConstructors = System.Linq.Enumerable.Where(
            GetType().GetMethods(),
            method => System.Attribute.IsDefined(method, typeof(Entitas.CodeGeneration.Attributes.PostConstructorAttribute))
            );

        foreach (var postConstructor in postConstructors)
        {
            postConstructor.Invoke(this, null);
        }
    }
Пример #13
0
        protected void checkCurrentOwnership(PoolContext dbCtx)
        {
            String userId = HttpContext.User.FindFirst(ClaimTypes.Name).Value.ToString();

            canRequest = false;
            myTeam     = null;
            if ((userId != null) && (userId.Length > 0))
            {
                Owner owner = dbCtx.Owners.Include(o => o.Team).Where(o => o.Username.Equals(userId)).DefaultIfEmpty(null).First();
                canRequest = owner == null;
                if (owner != null)
                {
                    myTeam = owner.Team;
                }
            }
        }
    // Use awake to ensure that this fires before the systems boot
    // otherwise it misses the initial level set
    void Awake()
    {
        levelImage = GetComponent <Image>();

        pool = Contexts.sharedInstance.pool;
        pool.GetGroup(PoolMatcher.Level).OnEntityAdded += (group, entity, index, component) =>
        {
            currentLevel = pool.level.level;
            pool.isLevelTransitionDelay = true;
            Invoke("ShowLevelImage", displayDelay);
        };
        pool.GetGroup(PoolMatcher.GameOver).OnEntityAdded += (group, entity, index, component) =>
        {
            GameOver();
        };
    }
Пример #15
0
    public GameBoardCacheSystem(Contexts contexts)
    {
        pool = contexts.pool;

        var gameBoard = pool.GetGroup(PoolMatcher.GameBoard);

        gameBoard.OnEntityAdded += (group, entity, index, component) =>
                                   CreateNewGameBoardCache((GameBoardComponent)component);
        gameBoard.OnEntityUpdated += (group, entity, index, previousComponent, newComponent) =>
                                     CreateNewGameBoardCache((GameBoardComponent)newComponent);

        var gameBoardElements = pool.GetGroup(Matcher <PoolEntity> .AllOf(
                                                  PoolMatcher.GameBoardElement, PoolMatcher.Position));

        gameBoardElements.OnEntityAdded   += OnGameBoardElementAdded;
        gameBoardElements.OnEntityUpdated += OnGameBoardElementUpdated;
        gameBoardElements.OnEntityRemoved += OnGameBoardElementRemoved;
    }
 public CoroutineSystem(Contexts contexts)
 {
     pool            = contexts.pool;
     coroutinesGroup = pool.GetGroup(PoolMatcher.Coroutine);
 }
Пример #17
0
 public CreateGameBoardSystem(Contexts contexts)
     : base(contexts.pool)
 {
     pool = contexts.pool;
     deleteOnExitGroup = pool.GetGroup(PoolMatcher.DeleteOnExit);
 }
 public DestructibleSystem(Contexts contexts)
     : base(contexts.pool)
 {
     pool = contexts.pool;
 }
Пример #19
0
 public AIMoveSystem(Contexts contexts)
     : base(contexts.pool)
 {
     pool = contexts.pool;
 }
Пример #20
0
 public ExitSystem(Contexts contexts)
     : base(contexts.pool)
 {
     pool      = contexts.pool;
     exitGroup = pool.GetGroup(PoolMatcher.Exit);
 }
Пример #21
0
 public PlayerWheelieView(PoolContext poolContext)
 {
     _poolContext = poolContext;
     _poolContext.WheelieText.text = _displayText;
 }
Пример #22
0
 public RidershipController(PoolContext context, HttpService httpservice)
 {
     dbContext = context;
 }
Пример #23
0
 public LoginRegController(PoolContext context)
 {
     dbContext = context;
 }
Пример #24
0
 public static bool IsGameBoardPositionOpen(this PoolContext context,
                                            PositionComponent position,
                                            out ICollection <PoolEntity> entities)
 {
     return(context.IsGameBoardPositionOpen(position.x, position.y, out entities));
 }
Пример #25
0
 public FoodSystem(Contexts contexts)
     : base(contexts.pool)
 {
     pool = contexts.pool;
 }
 public GameOverSystem(Contexts contexts)
     : base(contexts.pool)
 {
     pool = contexts.pool;
 }
Пример #27
0
 public InputSystem(Contexts contexts)
     : base(contexts.pool)
 {
     pool = contexts.pool;
 }
Пример #28
0
 public AddViewSystem(Contexts contexts)
     : base(contexts.pool)
 {
     pool = contexts.pool;
 }
Пример #29
0
 public AllControllersInitialozator(PlayerData playerData, PoolContext poolContext,
                                    MainControllers updateController, LevelGeneratorData levelGeneratorData)
 {
     Initializers(playerData, poolContext, levelGeneratorData);
     Controllers(poolContext, updateController);
 }
Пример #30
0
 public ProfileController(PoolContext context, HttpService httpservice)
 {
     dbContext = context;
 }