private void ManualInitGrid()
    {
        const int   sizeX    = 7;
        const int   sizeZ    = 23;
        const float cellSize = 1f;

        gridSystem.Init(new Int2(sizeX, sizeZ), cellSize, new Int2(3, 22));
        int[,] map = new int[sizeX, sizeZ]
        {
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
        };

        HashSet <PlatformGroup> init = new HashSet <PlatformGroup>();

        for (int x = 0; x < sizeX; x++)
        {
            for (int z = 0; z < sizeZ; z++)
            {
                if (map[x, z] == 1)
                {
                    init.Add(gridSystem.PlacePlatform(x, z));
                }
            }
        }

        PlatformGroup.Restructure(init, new Int2(3, 0));
    }
Example #2
0
    public static PlatformGroup Combine(HashSet <PlatformGroup> groups, Int2 playerIdx)
    {
        GameObject    output      = new GameObject("PlatformGroup");
        PlatformGroup outputGroup = output.AddComponent <PlatformGroup>();

        outputGroup.container = new HashSet <Platform>();
        //outputGroup.OnGroupMoved += robot.replanPath;
        //transfer ownership
        foreach (PlatformGroup group in groups)
        {
            outputGroup.container.UnionWith(group.container);
        }

        bool lockedGroup = false;

        //Vector2 robotPos2d = new Vector2(robot.transform.position.x, robot.transform.position.z);
        foreach (PlatformGroup group in groups)
        {
            if (ReferenceEquals(group, gridSystem.ComputeGroup(playerIdx)) ||
                ReferenceEquals(group, gridSystem.ComputeGroup(gridSystem.goal)))
            {
                lockedGroup = true;
                break;
            }
        }

        foreach (Platform pf in outputGroup.container)
        {
            pf.group = outputGroup;
        }

        //transfer childObjs
        List <Transform> children = new List <Transform>();

        foreach (PlatformGroup group in groups)
        {
            for (int i = 0; i < group.gameObject.transform.childCount; i++)
            {
                children.Add(group.gameObject.transform.GetChild(i));
            }
            foreach (Transform child in children)
            {
                child.transform.parent = output.transform;
            }

            children.Clear();
            group.container.Clear();
            Destroy(group.gameObject);
        }

        if (lockedGroup)
        {
            foreach (Transform child in output.transform)
            {
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.lockedPfLayer);//?
            }
        }

        return(outputGroup);
    }
Example #3
0
        /// <summary>
        /// Gets an array of all platform folder names
        /// </summary>
        /// <returns>Array of platform folders</returns>
        public static string[] GetPlatformFolderNames()
        {
            if (CachedPlatformFolderNames == null)
            {
                List <string> PlatformFolderNames = new List <string>();

                // Find all the platform folders to exclude from the list of precompiled modules
                foreach (UnrealTargetPlatform TargetPlatform in Enum.GetValues(typeof(UnrealTargetPlatform)))
                {
                    if (TargetPlatform != UnrealTargetPlatform.Unknown)
                    {
                        PlatformFolderNames.Add(TargetPlatform.ToString());
                    }
                }

                // Also exclude all the platform groups that this platform is not a part of
                foreach (UnrealPlatformGroup PlatformGroup in Enum.GetValues(typeof(UnrealPlatformGroup)))
                {
                    PlatformFolderNames.Add(PlatformGroup.ToString());
                }

                // Save off the list as an array
                CachedPlatformFolderNames = PlatformFolderNames.ToArray();
            }
            return(CachedPlatformFolderNames);
        }
Example #4
0
    private void updatePlayerLayer()
    {
        if (prevGroup == null)
        {
            prevGroup = gridSystem.ComputeGroup(new Vector2(transform.position.x, transform.position.z));
            foreach (Transform child in prevGroup.gameObject.transform)
            {
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.lockedPfLayer);//(?)
            }
        }

        var currGroup = gridSystem.ComputeGroup(new Vector2(transform.position.x, transform.position.z));

        if (currGroup != prevGroup)
        {
            foreach (Transform child in prevGroup.gameObject.transform)
            {
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.movablePfLayer);//(?)
            }
            foreach (Transform child in currGroup.gameObject.transform)
            {
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.lockedPfLayer);//(?)
            }
            prevGroup = currGroup;
        }
    }
Example #5
0
        /// <summary>
        /// Finds a list of folder names to exclude when building for this platform
        /// </summary>
        public FileSystemName[] GetExcludedFolderNames()
        {
            if (CachedExcludedFolderNames == null)
            {
                // Find all the platform folders to exclude from the list of precompiled modules
                List <FileSystemName> Names = new List <FileSystemName>();
                foreach (UnrealTargetPlatform TargetPlatform in Enum.GetValues(typeof(UnrealTargetPlatform)))
                {
                    if (TargetPlatform != UnrealTargetPlatform.Unknown && TargetPlatform != Platform)
                    {
                        Names.Add(new FileSystemName(TargetPlatform.ToString()));
                    }
                }

                // Also exclude all the platform groups that this platform is not a part of
                List <UnrealPlatformGroup> IncludePlatformGroups = new List <UnrealPlatformGroup>(UEBuildPlatform.GetPlatformGroups(Platform));
                foreach (UnrealPlatformGroup PlatformGroup in Enum.GetValues(typeof(UnrealPlatformGroup)))
                {
                    if (!IncludePlatformGroups.Contains(PlatformGroup))
                    {
                        Names.Add(new FileSystemName(PlatformGroup.ToString()));
                    }
                }

                // Save off the list as an array
                CachedExcludedFolderNames = Names.ToArray();
            }
            return(CachedExcludedFolderNames);
        }
Example #6
0
    public void SpawnGroup(Vector3 space)
    {
        PlatformGroup pg = GetGroupForSpace(space);

        while (pg.HasFreeSpace())
        {
            GeneratePlatform(pg.GetRandomFreeSpace());
        }
    }
Example #7
0
    private List <PlatformGroup> GroupSpaces(List <Vector3> availableSpacesToGroup)
    {
        List <PlatformGroup> groups = new List <PlatformGroup>();

        if (amountOfGroups < 1)
        {
            amountOfGroups = 1;
        }

        int maxBaseGroupSize = (int)(availableSpacesToGroup.Count / amountOfGroups);

        Dictionary <PlatformGroup, bool> platformRisen = new Dictionary <PlatformGroup, bool>();

        float maxDistance = 1.5f * tileSize.magnitude;

        for (float j = 0; j < amountOfGroups; j++)
        {
            PlatformGroup pg = new PlatformGroup();
            groups.Add(pg);
            platformRisen.Add(pg, Random.value < chanceToRisePlatform);

            int     size   = 1;
            Vector3 center = availableSpacesToGroup[Random.Range(0, availableSpacesToGroup.Count)];
            availableSpacesToGroup.Remove(center);
            for (int i = 0; i < availableSpacesToGroup.Count; i++)
            {
                if (maxBaseGroupSize <= size)
                {
                    break;
                }

                if (Vector3.Distance(center, availableSpacesToGroup[i]) <= maxDistance)
                {
                    Vector3 v = availableSpacesToGroup[i];
                    availableSpacesToGroup.Remove(v);
                    i--;

                    v.y = platformRisen[pg] ? risenPlatformHeight : 0;
                    pg.AddSpace(v);
                    size++;
                }
            }
        }

        while (maxAmount > (maxFreeSpaces - availableSpacesToGroup.Count) && availableSpacesToGroup.Count > 0)
        {
            //TODO not do bs
            Vector3 space            = availableSpacesToGroup[0];
            int     randomGroupIndex = Random.Range(0, groups.Count);
            groups[randomGroupIndex].AddSpace(space);
            availableSpacesToGroup.Remove(space);
        }

        return(groups);
    }
Example #8
0
    private List <PlatformGroup> GroupSpaces(List <Vector3> availableSpacesToGroup)
    {
        List <PlatformGroup> groups = new List <PlatformGroup>();

        if (settings.amountOfGroups < 1)
        {
            settings.amountOfGroups = 1;
        }

        int maxBaseGroupSize = (int)(availableSpacesToGroup.Count / settings.amountOfGroups);

        Dictionary <PlatformGroup, bool> platformRisen = new Dictionary <PlatformGroup, bool>();

        float maxDistance = 1.5f * Math.Max(hexFieldGenerator.GetTileSize().width, hexFieldGenerator.GetTileSize().height);

        for (float j = 0; j < settings.amountOfGroups; j++)
        {
            PlatformGroup pg = new PlatformGroup();
            groups.Add(pg);
            platformRisen.Add(pg, Random.value < settings.chanceToRisePlatform);

            int     size   = 1;
            Vector3 center = availableSpacesToGroup[Random.Range(0, availableSpacesToGroup.Count)];
            availableSpacesToGroup.Remove(center);
            for (int i = 0; i < availableSpacesToGroup.Count; i++)
            {
                if (maxBaseGroupSize <= size)
                {
                    break;
                }

                if (Vector3.Distance(center, availableSpacesToGroup[i]) <= maxDistance)
                {
                    Vector3 v = availableSpacesToGroup[i];
                    availableSpacesToGroup.Remove(v);
                    i--;

                    v.y = platformRisen[pg] ? settings.risenPlatformHeight : 0;
                    pg.AddSpace(v);
                    size++;
                }
            }
        }

        while (settings.maxAmount > (hexFieldGenerator.GetSpacesCount() - availableSpacesToGroup.Count) && availableSpacesToGroup.Count > 0)
        {
            //TODO not do bs
            Vector3 space            = availableSpacesToGroup[0];
            int     randomGroupIndex = Random.Range(0, groups.Count);
            groups[randomGroupIndex].AddSpace(space);
            availableSpacesToGroup.Remove(space);
        }

        return(groups);
    }
        public static string ToCommaDelimited(PlatformGroup platformGroup)
        {
            List <int> result;

            if (_mapplatformgroup.TryGetValue(platformGroup, out result))
            {
                return(result.ToCommaDelimitedString());
            }

            return(string.Empty);
        }
Example #10
0
    //private static RobotController robot { get { return LevelController.Instance.robotController; } }

    public static PlatformGroup CreatePfGroup(Platform pf)
    {
        GameObject    pfGroupObj = new GameObject("PlatformGroup");
        PlatformGroup pfGroup    = pfGroupObj.AddComponent <PlatformGroup>();

        pfGroup.container = new HashSet <Platform>();
        pfGroup.AddPlatform(pf);
        //pfGroup.OnGroupMoved += robot.replanPath;
        pf.transform.parent = pfGroupObj.transform;
        pf.group            = pfGroup;

        return(pfGroup);
    }
Example #11
0
    // Use this function to place new platform
    public PlatformGroup PlacePlatform(int x, int z)
    {
        if (pfContainer[x][z] != null)
        {
            //throw new UnityException("platform already exist");
            return(null);
        }

        pfContainer[x][z] = Instantiate(pfPrefab,
                                        (transform.position + new Vector3(x, 0f, z)) * cellSize, Quaternion.identity) as Platform;
        pfContainer[x][z].gridSystem = this;
        pfContainer[x][z].index      = new Int2(x, z);

        return(PlatformGroup.CreatePfGroup(pfContainer[x][z]));
    }
Example #12
0
    public static PlatformGroup Combine(PlatformGroup lhs, PlatformGroup rhs, Int2 playerIdx)
    {
        GameObject output = new GameObject("PlatformGroup");
        PlatformGroup outputGroup = output.AddComponent<PlatformGroup>();
        outputGroup.container = new HashSet<Platform>();
        //outputGroup.OnGroupMoved += robot.replanPath;

        //transfer ownership
        outputGroup.container.UnionWith(lhs.container);
        outputGroup.container.UnionWith(rhs.container);

        //transfer childObjs
        List<Transform> children = new List<Transform>();
        for (int i = 0; i < lhs.gameObject.transform.childCount; i++)
            children.Add(lhs.gameObject.transform.GetChild(i));
        foreach (Transform child in children)
            child.transform.parent = output.transform;

        children.Clear();
        for (int i = 0; i < rhs.gameObject.transform.childCount; i++)
            children.Add(rhs.gameObject.transform.GetChild(i));
        foreach (Transform child in children)
            child.transform.parent = output.transform;

        //Vector2 robotPos2d = new Vector2(robot.transform.position.x, robot.transform.position.z);
        if (ReferenceEquals(lhs, gridSystem.ComputeGroup(playerIdx)) ||
            ReferenceEquals(rhs, gridSystem.ComputeGroup(playerIdx)) ||
            ReferenceEquals(lhs, gridSystem.ComputeGroup(gridSystem.goal)) ||
            ReferenceEquals(rhs, gridSystem.ComputeGroup(gridSystem.goal)))
        {
            foreach (Transform child in output.transform)
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.lockedPfLayer);//?

        }

        foreach (Platform pf in outputGroup.container)
            pf.group = outputGroup;

        lhs.container.Clear();
        rhs.container.Clear();
        Destroy(lhs.gameObject);
        Destroy(rhs.gameObject);

        return outputGroup;
    }
Example #13
0
    public GameObject GeneratePlatform(GameObject prefab, Vector3 targetPosition)
    {
        // make platform move straight up to target position
        Vector3 spawnPos = GetSpawnPos(targetPosition);

        GameObject    platform = EntityManager.CreateInstanceOf(prefab, spawnPos, prefab.transform.rotation, settings.groundRootTransform);
        PlatformGroup pg       = GetGroupForSpace(targetPosition);

        if (pg.IsFree(targetPosition))
        {
            pg.UseSpace(targetPosition, platform);

            // setup freeing of space after selfdestruct
            PlatformController platformController = platform.GetComponent <PlatformController>();
            platformController.AddSelfDestructListener(() => pg.FreeSpace(targetPosition));
        }

        return(platform);
    }
Example #14
0
    private Vector3 GetFreePlatformPosition(List <PlatformGroup> available)
    {
        if (available.Count < 1)
        {
            throw new InvalidOperationException("No free space available!");
        }

        PlatformGroup pg = available[Random.Range(0, available.Count)];

        if (pg.HasFreeSpace())
        {
            return(pg.GetRandomFreeSpace());
        }

        List <PlatformGroup> a = new List <PlatformGroup>();

        a.AddRange(available);
        a.Remove(pg);
        return(GetFreePlatformPosition(a));
    }
Example #15
0
    public void StartMoveGroup(PlatformMoveType type, Int2 playerIdx)
    {
        if (gridSystem.ExistMovingGroup)
        {
            return;
        }

        int units = ComputeMoveUnits(type, playerIdx);

        //HashSet<PlatformGroup> colGroups = ComputeNeighborGroups();
        if (units == 0)
        {
            HashSet <PlatformGroup> colGroups = ComputeNeighborGroups();
            colGroups.Add(this);
            PlatformGroup.Combine(colGroups, playerIdx);
            return;
        }

        gridSystem.ExistMovingGroup = true;
        StartCoroutine(MoveGroupCoroutine(type, units, playerIdx));
    }
Example #16
0
    private void ManualInitGrid()
    {
        gridSystem.Init(new Int2(sizeX, sizeZ), cellSize, new Int2(goalX, goalZ));
        //gridSizeX = 7
        //gridSizeZ = 20
        if (gridSystem.gridSizeX != 7 || gridSystem.gridSizeZ != 22)
        {
            throw new UnityException("gridSystem has a different size  than that of manual initialization ");
        }

        int[,] map = new int[7, 22]
        {
            { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1 },
            { 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
            { 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0 },
            { 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1 },
            { 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0 },
            { 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1 },
            { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 }
        };


        HashSet <PlatformGroup> init = new HashSet <PlatformGroup>();

        for (int x = 0; x < 7; x++)
        {
            for (int z = 0; z < 22; z++)
            {
                if (map[x, z] == 1)
                {
                    init.Add(gridSystem.PlacePlatform(x, z));
                }
            }
        }

        PlatformGroup.Restructure(init, gridSystem.ComputeIdx(new Vector2(robotController.transform.position.x, robotController.transform.position.z)));
    }
Example #17
0
    public static HashSet <PlatformGroup> Restructure(HashSet <PlatformGroup> groups, Int2 playerIdx)
    {
        //NO EMPTY GROUP ALLOWED

        bool[,] seen = new bool[gridSystem.gridSizeX, gridSystem.gridSizeZ];

        HashSet <HashSet <PlatformGroup> > components = new HashSet <HashSet <PlatformGroup> >();

        foreach (PlatformGroup group in groups)
        {
            var iter = group.container.GetEnumerator();
            iter.MoveNext();
            var pf = iter.Current;
            if (seen[pf.index._x, pf.index._z])
            {
                continue;
            }
            HashSet <PlatformGroup> component = new HashSet <PlatformGroup>();

            //flood fill
            Queue <Int2> indices = new Queue <Int2>();
            indices.Enqueue(pf.index);
            while (indices.Count > 0)
            {
                Int2 curr = indices.Dequeue();
                seen[curr._x, curr._z] = true;
                if (gridSystem[curr] != null)
                {
                    component.Add(gridSystem[curr].group);
                    if (curr._x > 0 && !seen[curr._x - 1, curr._z])
                    {
                        indices.Enqueue(new Int2(curr._x - 1, curr._z));
                    }
                    if (curr._x < gridSystem.gridSizeX - 1 && !seen[curr._x + 1, curr._z])
                    {
                        indices.Enqueue(new Int2(curr._x + 1, curr._z));
                    }
                    if (curr._z > 0 && !seen[curr._x, curr._z - 1])
                    {
                        indices.Enqueue(new Int2(curr._x, curr._z - 1));
                    }
                    if (curr._z < gridSystem.gridSizeZ - 1 && !seen[curr._x, curr._z + 1])
                    {
                        indices.Enqueue(new Int2(curr._x, curr._z + 1));
                    }
                }
            }

            components.Add(component);
        }

        //components should have no overlapping
        HashSet <PlatformGroup> output = new HashSet <PlatformGroup>();

        foreach (var component in components)
        {
            output.Add(PlatformGroup.Combine(component, playerIdx));
        }

        return(output);
    }
Example #18
0
    //private
    private IEnumerator MoveGroupCoroutine(PlatformMoveType type, int units, Int2 playerIdx)
    {
        foreach (Platform pf in container)
        {
            pf.StartMove(type, units);
        }

        bool waitAll = true;

        while (waitAll)
        {
            waitAll = false;
            foreach (Platform pf in container)
            {
                if (pf.IsMoving)
                {
                    waitAll = true;
                }
            }
            yield return(null);
        }

        //maintain gridSystem
        foreach (Platform pf in container)
        {
            gridSystem[pf.index] = null;
        }
        switch (type)
        {
        case PlatformMoveType.AxisX:
        {
            foreach (Platform pf in container)
            {
                pf.index._x         += units;
                gridSystem[pf.index] = pf;
            }
            break;
        }

        case PlatformMoveType.AxisZ:
        {
            foreach (Platform pf in container)
            {
                pf.index._z         += units;
                gridSystem[pf.index] = pf;
            }
            break;
        }

        default: throw new NotImplementedException();
        }

        //trigger combination
        HashSet <PlatformGroup> colGroups = ComputeNeighborGroups();

        colGroups.Add(this);

        //should update player's platform group here
        PlatformGroup.Combine(colGroups, playerIdx);

        //consider using event instead
        //LevelController.platformMoved = true;

        if (OnGroupMoved != null)
        {
            OnGroupMoved();
        }

        gridSystem.ExistMovingGroup = false;
    }
Example #19
0
    // Update is called once per frame
    void Update()
    {
        counter += Time.deltaTime;

        if (ignited == PlatformGroup.None)
        {
            for (int i = 0; i < platformInner.Length; i++)
            {
                platformInner[i].GetComponentInChildren<Burning>().Disable();
                platformCorner[i].GetComponentInChildren<Burning>().Disable();
                platformExterior[i].GetComponentInChildren<Burning>().Disable();
            }

            //change enabled checkpoint
            player.GetComponent<TeleTarget>().teleTarget = primaryCheckpoint;
        }
        else if (ignited == PlatformGroup.Inner)
        {
            if (counter >= platformBurnDuration)
            {
                for (int i = 0; i < platformInner.Length; i++)
                {
                    platformInner[i].GetComponent<Burning>().Disable();
                    platformCorner[i].GetComponent<Burning>().Enable();

                    //change enabled checkpoint
                    player.GetComponent<TeleTarget>().teleTarget = primaryCheckpoint;
                }
                counter -= platformBurnDuration;
                ignited = PlatformGroup.Corner;
            }
            else
            {
                if (platformInner.Length > 0)
                {
                    if (!platformInner[0].GetComponent<Burning>().onFire)
                    {
                        for (int i = 0; i < platformInner.Length; i++)
                        {
                            platformInner[i].GetComponent<Burning>().Enable();

                        }
                    }
                }
            }
        }
        else if (ignited == PlatformGroup.Corner)
        {
            if (counter >= platformBurnDuration)
            {
                for (int i = 0; i < platformInner.Length; i++)
                {

                    platformCorner[i].GetComponent<Burning>().Disable();
                    platformExterior[i].GetComponent<Burning>().Enable();
                }
                counter -= platformBurnDuration;
                ignited = PlatformGroup.Exterior;
            }
        }
        else if (ignited == PlatformGroup.Exterior)
        {
            if (counter >= platformBurnDuration)
            {
                for (int i = 0; i < platformInner.Length; i++)
                {
                    platformExterior[i].GetComponent<Burning>().Disable();
                    platformInner[i].GetComponent<Burning>().Enable();
                    //Change back enabled checkpoint.
                    player.GetComponent<TeleTarget>().teleTarget = secondaryCheckpoint;

                }
                counter -= platformBurnDuration;
                ignited = PlatformGroup.Inner;
            }
        }
    }
        public async Task <IActionResult> Get(string account, string password)
        {
            if (!IsLocalRequest())
            {
                return(NotFound());
            }
            var set = dbContext.Set <PlatformUser>();

            if (set.Any(x => x.Account == account))
            {
                return(BadRequest("account exists"));
            }
            var newUser = new PlatformUser
            {
                Account  = account,
                Password = passwordHashService.Hash(password),
                Name     = account,
                Status   = UserStatus.Active
            };
            await set.AddAsync(newUser);

            var flagSet   = dbContext.Set <PlatformFlag>();
            var groupSet  = dbContext.Set <PlatformGroup>();
            var groupFlag = await flagSet.FindAsync("SuperGroup");

            PlatformGroup group;

            if (groupFlag == null)
            {
                group = new PlatformGroup {
                    Name = "Administrator", IsEnabled = true
                };
                await groupSet.AddAsync(group);

                await dbContext.SaveChangesAsync();

                groupFlag = new PlatformFlag {
                    Flag = "SuperGroup", Value = group.Id.ToString()
                };
                await flagSet.AddAsync(groupFlag);
            }
            else
            {
                group = await groupSet.FindAsync(long.Parse(groupFlag.Value));
            }
            var roleSet = dbContext.Set <PlatformGroupRole>();
            var roles   = functionService.Functions.SelectMany(x => x.Permissions.Select(y => new { Function = x, Permission = y })).Select(x => new PlatformGroupRole
            {
                FunctionRoleCode = x.Permission.PermissionCode,
                FunctionCode     = x.Function.Code,
                Permission       = PermissionStatus.Granted,
                PlatformGroupId  = group.Id
            });

            dbContext.UpdateSet(roles,
                                x => x.PlatformGroupId == group.Id, (x, y) => x.FunctionCode == y.FunctionCode && x.FunctionRoleCode == y.FunctionRoleCode,
                                (o, n) => o.Permission = n.Permission
                                );
            await dbContext.Set <PlatformUserGroup>().AddAsync(new PlatformUserGroup {
                PlatformGroup = group, PlatformUser = newUser
            });

            await dbContext.SaveChangesAsync();

            return(Ok());
        }
    private void updatePlayerLayer()
    {
        if (prevGroup == null)
        {
            prevGroup = gridSystem.ComputeGroup(new Vector2(transform.position.x, transform.position.z));
            foreach (Transform child in prevGroup.gameObject.transform)
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.lockedPfLayer);//(?)
        }

        var currGroup = gridSystem.ComputeGroup(new Vector2(transform.position.x, transform.position.z));
        if (currGroup != prevGroup)
        {
            foreach (Transform child in prevGroup.gameObject.transform)
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.movablePfLayer);//(?)

            foreach (Transform child in currGroup.gameObject.transform)
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.lockedPfLayer);//(?)

            prevGroup = currGroup;
        }
    }