Ejemplo n.º 1
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        if (m_DamageWallMessages.CalculateEntityCount() == 0)
        {
            return(inputDependencies);
        }

        SINGLETON_GridDefinitions t_GridDef = GetSingleton <SINGLETON_GridDefinitions>();

        NativeArray <Entity>       na_BreakWallMessageEntities = m_DamageWallMessages.ToEntityArray(Allocator.TempJob);
        NativeArray <MC_BreakWall> na_BreakWallMessages        = m_DamageWallMessages.ToComponentDataArray <MC_BreakWall>(Allocator.TempJob);

        NativeArray <Entity>        na_PlayerEntities  = m_Players.ToEntityArray(Allocator.TempJob);
        NativeArray <C_PlayerIndex> na_PlayerIndexes   = m_Players.ToComponentDataArray <C_PlayerIndex>(Allocator.TempJob);
        NativeArray <C_PlayerPos>   na_PlayerPositions = m_Players.ToComponentDataArray <C_PlayerPos>(Allocator.TempJob);

        NativeArray <Entity>    na_GridEntities = m_Grid.ToEntityArray(Allocator.TempJob);
        NativeArray <C_GridPos> na_Grid         = m_Grid.ToComponentDataArray <C_GridPos>(Allocator.TempJob);


        EntityCommandBuffer ecb_Cleanup = CleanupMessageBarrier.CreateCommandBuffer();
        MC_BreakWall        mc_CurrentMessage;

        Entity      t_CurrentPlayerEntity = default;
        C_PlayerPos c_CurrentPlayerPos    = default;
        C_PlayerPos c_CurrentEnemyPos     = default;

        Entity    t_CurrentGridEntity = default;
        C_GridPos c_CurrentGridPos    = default;

        for (int i = 0; i < na_BreakWallMessages.Length; i++)
        {
            mc_CurrentMessage = na_BreakWallMessages[i];

            for (int j = 0; j < na_PlayerIndexes.Length; j++)
            {
                if (mc_CurrentMessage.PlayerId != na_PlayerIndexes[j].PlayerId)
                {
                    c_CurrentEnemyPos = na_PlayerPositions[j];
                }
                else
                {
                    t_CurrentPlayerEntity = na_PlayerEntities[j];
                    c_CurrentPlayerPos    = na_PlayerPositions[j];
                }
            }

            for (int j = 0; j < na_Grid.Length; j++)
            {
                if (c_CurrentPlayerPos.Pos != na_Grid[j].Pos)
                {
                    continue;
                }
                c_CurrentGridPos    = na_Grid[j];
                t_CurrentGridEntity = na_GridEntities[j];
            }

            unsafe
            {
                if (c_CurrentGridPos.WallStates[(int)mc_CurrentMessage.WallDirection] == (byte)WallStates.Damaged)
                {
                    Debug.Log($"Already Damaged: {c_CurrentGridPos}");
                    U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 12);
                }
                else
                {
                    c_CurrentGridPos.WallStates[(int)mc_CurrentMessage.WallDirection] = (byte)WallStates.Damaged;
                    ecb_Cleanup.SetComponent(t_CurrentGridEntity, c_CurrentGridPos);

                    Vector2Int t_DuplicateWall = default;
                    switch (mc_CurrentMessage.WallDirection)
                    {
                    case WallIndexes.Up:
                        t_DuplicateWall = c_CurrentGridPos.Pos + new Vector2Int(0, -1);
                        break;

                    case WallIndexes.Down:
                        t_DuplicateWall = c_CurrentGridPos.Pos + new Vector2Int(0, 1);
                        break;

                    case WallIndexes.Left:
                        t_DuplicateWall = c_CurrentGridPos.Pos + new Vector2Int(-1, 0);
                        break;

                    case WallIndexes.Right:
                        t_DuplicateWall = c_CurrentGridPos.Pos + new Vector2Int(1, 0);
                        break;

                    default:
                        break;
                    }
                    Debug.Log($"Broken Wall: {c_CurrentGridPos}");

                    for (int j = 0; j < na_Grid.Length; j++)
                    {
                        if (t_DuplicateWall != na_Grid[j].Pos)
                        {
                            continue;
                        }

                        C_GridPos c_UpdatedDuplicateWall = na_Grid[j];

                        switch (mc_CurrentMessage.WallDirection)
                        {
                        case WallIndexes.Up:
                            c_UpdatedDuplicateWall.WallStates[(int)WallIndexes.Down] = (byte)WallStates.Damaged;
                            break;

                        case WallIndexes.Down:
                            c_UpdatedDuplicateWall.WallStates[(int)WallIndexes.Up] = (byte)WallStates.Damaged;
                            break;

                        case WallIndexes.Left:
                            c_UpdatedDuplicateWall.WallStates[(int)WallIndexes.Right] = (byte)WallStates.Damaged;
                            break;

                        case WallIndexes.Right:
                            c_UpdatedDuplicateWall.WallStates[(int)WallIndexes.Left] = (byte)WallStates.Damaged;
                            break;

                        default:
                            break;
                        }
                        ecb_Cleanup.SetComponent(na_GridEntities[j], c_UpdatedDuplicateWall);
                        Debug.Log($"Broken Wall: {c_UpdatedDuplicateWall}");
                    }

                    U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 13);

                    // Notifies the enemy visor
                    int i_TileHandle;
                    U_ServerUtils.
                    NotifyEnemyVisor(
                        ref ecb_Cleanup,
                        in na_PlayerEntities,
                        in na_PlayerIndexes,
                        in na_PlayerPositions,
                        mc_CurrentMessage.PlayerId,
                        0, out i_TileHandle);

                    WallIndexes e_RelativeToEnemyDirection = U_ServerUtils.MapTilePositionToIndex(i_TileHandle);
                    int         i_EnemySoundMessage        = 0;
                    switch (e_RelativeToEnemyDirection)
                    {
                    case WallIndexes.Up:
                        i_EnemySoundMessage = 15;
                        break;

                    case WallIndexes.Down:
                        i_EnemySoundMessage = 18;
                        break;

                    case WallIndexes.Left:
                        i_EnemySoundMessage = 16;
                        break;

                    case WallIndexes.Right:
                        i_EnemySoundMessage = 17;
                        break;

                    case WallIndexes.Diagonal:
                        i_EnemySoundMessage = 14;
                        break;

                    case WallIndexes.Center:
                        i_EnemySoundMessage = 1;
                        break;

                    default:
                        break;
                    }

                    U_ServerUtils.NotifyEnemyText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, i_EnemySoundMessage);
                }
            }
            ecb_Cleanup.DestroyEntity(na_BreakWallMessageEntities[i]);
        }

        na_BreakWallMessageEntities.Dispose();
        na_BreakWallMessages.Dispose();

        na_PlayerEntities.Dispose();
        na_PlayerIndexes.Dispose();
        na_PlayerPositions.Dispose();

        na_GridEntities.Dispose();
        na_Grid.Dispose();
        return(inputDependencies);
    }
Ejemplo n.º 2
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        if (m_ShootPlayerMessages.CalculateEntityCount() == 0)
        {
            return(inputDependencies);
        }

        SINGLETON_GridDefinitions singletong_GridDef = GetSingleton <SINGLETON_GridDefinitions>();

        NativeArray <Entity> na_BreakWallMessageEntities         = m_ShootPlayerMessages.ToEntityArray(Allocator.TempJob);
        NativeArray <MC_ShootInDirection> na_ShootPlayerMessages = m_ShootPlayerMessages.ToComponentDataArray <MC_ShootInDirection>(Allocator.TempJob);

        NativeArray <Entity>        na_PlayerEntities  = m_Players.ToEntityArray(Allocator.TempJob);
        NativeArray <C_PlayerIndex> na_PlayerIndexes   = m_Players.ToComponentDataArray <C_PlayerIndex>(Allocator.TempJob);
        NativeArray <C_PlayerPos>   na_PlayerPositions = m_Players.ToComponentDataArray <C_PlayerPos>(Allocator.TempJob);

        NativeArray <Entity>    na_GridEntities = m_Grid.ToEntityArray(Allocator.TempJob);
        NativeArray <C_GridPos> na_Grid         = m_Grid.ToComponentDataArray <C_GridPos>(Allocator.TempJob);


        EntityCommandBuffer ecb_Cleanup = CleanupMessageBarrier.CreateCommandBuffer();
        MC_ShootInDirection mc_CurrentMessage;
        C_PlayerPos         c_CurrentPlayerPos = default;
        C_PlayerPos         c_EnemyPlayerPos   = new C_PlayerPos {
            Pos = new Vector2Int(-1, -1)
        };

        C_GridPos c_CurrentGridPos;


        for (int i = 0; i < na_ShootPlayerMessages.Length; i++)
        {
            mc_CurrentMessage = na_ShootPlayerMessages[i];

            for (int j = 0; j < na_PlayerIndexes.Length; j++)
            {
                if (mc_CurrentMessage.PlayerId != na_PlayerIndexes[j].PlayerId)
                {
                    c_EnemyPlayerPos = na_PlayerPositions[j];
                }
                else
                {
                    c_CurrentPlayerPos = na_PlayerPositions[j];
                }
            }

            if (c_CurrentPlayerPos.Pos == c_EnemyPlayerPos.Pos)
            {
                U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 28);
                Debug.Log("Shot Enemy");
                return(inputDependencies);
            }

            Vector2Int t_RequiredEnemyPos = default;
            switch (mc_CurrentMessage.WallDirection)
            {
            case WallIndexes.Up:
                t_RequiredEnemyPos = new Vector2Int(0, -1);
                break;

            case WallIndexes.Down:
                t_RequiredEnemyPos = new Vector2Int(0, 1);
                break;

            case WallIndexes.Left:
                t_RequiredEnemyPos = new Vector2Int(-1, 0);
                break;

            case WallIndexes.Right:
                t_RequiredEnemyPos = new Vector2Int(1, 0);
                break;

            default:
                break;
            }
            t_RequiredEnemyPos.x = Mathf.Clamp(t_RequiredEnemyPos.x, 0, singletong_GridDef.RowCount);
            t_RequiredEnemyPos.y = Mathf.Clamp(t_RequiredEnemyPos.x, 0, singletong_GridDef.ColumnCount);

            int i_CheckingWallDirection = 0;
            int i_HitTextMessage        = 0;
            switch (mc_CurrentMessage.WallDirection)
            {
            case WallIndexes.Up:
                i_CheckingWallDirection = (int)WallIndexes.Down;
                i_HitTextMessage        = 29;
                break;

            case WallIndexes.Down:
                i_CheckingWallDirection = (int)WallIndexes.Up;
                i_HitTextMessage        = 32;
                break;

            case WallIndexes.Left:
                i_CheckingWallDirection = (int)WallIndexes.Right;
                i_HitTextMessage        = 30;
                break;

            case WallIndexes.Right:
                i_CheckingWallDirection = (int)WallIndexes.Left;
                i_HitTextMessage        = 31;
                break;

            default:
                break;
            }

            for (int j = 0; j < na_GridEntities.Length; j++)
            {
                c_CurrentGridPos = na_Grid[j];

                unsafe {
                    if (c_CurrentGridPos.Pos != t_RequiredEnemyPos)
                    {
                        continue;
                    }

                    if (c_CurrentGridPos.WallStates[i_CheckingWallDirection] != (byte)WallStates.Open)
                    {
                        U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 26);
                    }
                    else
                    {
                        if (c_CurrentGridPos.Pos == t_RequiredEnemyPos)
                        {
                            U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, i_HitTextMessage);
                        }
                    }
                }
            }
            ecb_Cleanup.DestroyEntity(na_BreakWallMessageEntities[i]);
        }

        na_BreakWallMessageEntities.Dispose();
        na_ShootPlayerMessages.Dispose();

        na_PlayerIndexes.Dispose();
        na_PlayerPositions.Dispose();

        na_GridEntities.Dispose();
        na_Grid.Dispose();
        return(inputDependencies);
    }
Ejemplo n.º 3
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        if (m_MovePlayerMessages.CalculateEntityCount() == 0)
        {
            return(inputDependencies);
        }

        SINGLETON_GridDefinitions t_GridDef = GetSingleton <SINGLETON_GridDefinitions>();

        NativeArray <Entity>        na_MovePlayerMessageEntities = m_MovePlayerMessages.ToEntityArray(Allocator.TempJob);
        NativeArray <MC_MovePlayer> na_MovePlayerMessages        = m_MovePlayerMessages.ToComponentDataArray <MC_MovePlayer>(Allocator.TempJob);

        NativeArray <Entity>        na_PlayerEntities  = m_Players.ToEntityArray(Allocator.TempJob);
        NativeArray <C_PlayerIndex> na_PlayerIndexes   = m_Players.ToComponentDataArray <C_PlayerIndex>(Allocator.TempJob);
        NativeArray <C_PlayerPos>   na_PlayerPositions = m_Players.ToComponentDataArray <C_PlayerPos>(Allocator.TempJob);

        NativeArray <C_GridPos> na_Grid = m_Grid.ToComponentDataArray <C_GridPos>(Allocator.TempJob);


        EntityCommandBuffer ecb_Cleanup = CleanupMessageBarrier.CreateCommandBuffer();
        MC_MovePlayer       mc_CurrentMessage;

        Entity      t_CurrentPlayerEntity = default;
        C_PlayerPos c_CurrentPlayerPos    = default;
        C_PlayerPos c_EnemyPlayerPos      = default;

        C_GridPos c_CurrentGridPos;

        for (int i = 0; i < na_MovePlayerMessages.Length; i++)
        {
            mc_CurrentMessage = na_MovePlayerMessages[i];

            for (int j = 0; j < na_PlayerIndexes.Length; j++)
            {
                if (mc_CurrentMessage.PlayerId != na_PlayerIndexes[j].PlayerId)
                {
                    c_EnemyPlayerPos = na_PlayerPositions[j];
                }
                else
                {
                    t_CurrentPlayerEntity = na_PlayerEntities[j];
                    c_CurrentPlayerPos    = na_PlayerPositions[j];
                }
            }

            for (int j = 0; j < na_Grid.Length; j++)
            {
                if (c_CurrentPlayerPos.Pos != na_Grid[j].Pos)
                {
                    continue;
                }
                c_CurrentGridPos = na_Grid[j];
                break;
            }

            unsafe
            {
                if (c_CurrentGridPos.WallStates[(int)mc_CurrentMessage.WallDirection] == (byte)WallStates.Open)
                {
                    Vector2Int t_NewPos = default;
                    switch (mc_CurrentMessage.WallDirection)
                    {
                    case WallIndexes.Up:
                        t_NewPos = c_CurrentPlayerPos.Pos + new Vector2Int(0, -1);
                        break;

                    case WallIndexes.Down:
                        t_NewPos = c_CurrentPlayerPos.Pos + new Vector2Int(0, 1);
                        break;

                    case WallIndexes.Left:
                        t_NewPos = c_CurrentPlayerPos.Pos + new Vector2Int(-1, 0);
                        break;

                    case WallIndexes.Right:
                        t_NewPos = c_CurrentPlayerPos.Pos + new Vector2Int(1, 0);
                        break;

                    default:
                        break;
                    }

                    if ((t_NewPos.x >= 0 && t_NewPos.x < t_GridDef.RowCount) &&
                        (t_NewPos.y >= 0 && t_NewPos.y < t_GridDef.ColumnCount))
                    {
                        ecb_Cleanup.SetComponent(t_CurrentPlayerEntity, new C_PlayerPos
                        {
                            Pos = t_NewPos
                        });

                        // Notifies the player that he moved.
                        U_ServerUtils
                        .NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 6);

                        // Finds the new position in the grid.
                        for (int j = 0; j < na_Grid.Length; j++)
                        {
                            if (t_NewPos != na_Grid[j].Pos)
                            {
                                continue;
                            }
                            c_CurrentGridPos = na_Grid[j];
                            break;
                        }

                        // Writes to the player the status of the room.
                        if (c_CurrentGridPos.WallStates[(int)WallIndexes.Up] == (byte)WallStates.Damaged)
                        {
                            U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 2);
                        }
                        if (c_CurrentGridPos.WallStates[(int)WallIndexes.Left] == (byte)WallStates.Damaged)
                        {
                            U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 3);
                        }
                        if (c_CurrentGridPos.WallStates[(int)WallIndexes.Right] == (byte)WallStates.Damaged)
                        {
                            U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 4);
                        }
                        if (c_CurrentGridPos.WallStates[(int)WallIndexes.Down] == (byte)WallStates.Damaged)
                        {
                            U_ServerUtils.NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 5);
                        }

                        // Notifies the enemy visor
                        int i_TileHandle;
                        U_ServerUtils.
                        NotifyEnemyVisor(
                            ref ecb_Cleanup,
                            in na_PlayerEntities,
                            in na_PlayerIndexes,
                            in na_PlayerPositions,
                            mc_CurrentMessage.PlayerId,
                            0, out i_TileHandle);

                        WallIndexes e_RelativeToEnemyDirection = U_ServerUtils.MapTilePositionToIndex(i_TileHandle);
                        int         i_EnemySoundMessage        = 0;
                        switch (e_RelativeToEnemyDirection)
                        {
                        case WallIndexes.Up:
                            i_EnemySoundMessage = 8;
                            break;

                        case WallIndexes.Down:
                            i_EnemySoundMessage = 11;
                            break;

                        case WallIndexes.Left:
                            i_EnemySoundMessage = 9;
                            break;

                        case WallIndexes.Right:
                            i_EnemySoundMessage = 10;
                            break;

                        case WallIndexes.Diagonal:
                            i_EnemySoundMessage = 7;
                            break;

                        case WallIndexes.Center:
                            i_EnemySoundMessage = 1;
                            break;

                        default:
                            break;
                        }

                        U_ServerUtils.NotifyEnemyText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, i_EnemySoundMessage);
                    }
                    else
                    {
                        // Notifies the player that he failed to move due to touching the edge of the Grid.
                        U_ServerUtils
                        .NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, 33);
                    }
                }
                else
                {
                    int i_MessageIndex = -1;
                    switch (mc_CurrentMessage.WallDirection)
                    {
                    case WallIndexes.Up:
                        i_MessageIndex = 2;
                        break;

                    case WallIndexes.Down:
                        i_MessageIndex = 5;
                        break;

                    case WallIndexes.Left:
                        i_MessageIndex = 3;
                        break;

                    case WallIndexes.Right:
                        i_MessageIndex = 4;
                        break;

                    default:
                        break;
                    }
                    // Notifies the player that he failed to move due to the wall being broken.
                    U_ServerUtils
                    .NotifyPlayerText(ref ecb_Cleanup, in na_PlayerEntities, in na_PlayerIndexes, mc_CurrentMessage.PlayerId, i_MessageIndex);
                }
            }
            ecb_Cleanup.DestroyEntity(na_MovePlayerMessageEntities[i]);
        }

        na_MovePlayerMessageEntities.Dispose();
        na_MovePlayerMessages.Dispose();

        na_PlayerEntities.Dispose();
        na_PlayerIndexes.Dispose();
        na_PlayerPositions.Dispose();

        na_Grid.Dispose();
        return(inputDependencies);
    }