コード例 #1
0
    void Start()
    {
        pool = Contexts.sharedInstance.pool;

        pool.GetGroup(PoolMatcher.Audio).OnEntityAdded    += OnAudioAdded;
        pool.GetGroup(PoolMatcher.GameOver).OnEntityAdded += (group, entity, index, component) => StopMusic();
    }
コード例 #2
0
        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;
                }
            }
        }
コード例 #14
0
    // 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;
    }
コード例 #16
0
 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);
 }
コード例 #18
0
 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;
 }
コード例 #26
0
 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;
 }