Exemplo n.º 1
0
    /*
     * Restarts simulation with the chosen cell
     */
    public void streakPlate()
    {
        // If this one variable is not null, the rest should be good too
        if (cellClicked)
        {
            SimulationManager.Instance.clearDish();
            for (int i = 0; i < 5; i++)
            {
                // Reset SO
                System.Random rand = new System.Random();

                // Instantiate the chosen cell
                GameObject newCell = Instantiate(cellPrefab) as GameObject;

                // TODO: Update the location where cells first spawn and change the random we use to System
                newCell.transform.position = new Vector3(Random.Range(0, 10), 1, Random.Range(0, 8));
                CellBehaviour script = newCell.GetComponent <CellBehaviour>();
                script.setSeed(rand.Next());
                script.qsOn = isQSTriggered;
                script.setQsThreshold(qsThreshold);
                script.setTarget_time_for_LAI_1(target_time_for_LAI_1);
                script.energy          = energy;
                script.cellsReproduced = 0;
                script.setTarget_time(target_time);
            }
        }
    }
    //Function that is used to create the scene
    public void SetupScene()
    {
        gridHolder = new GameObject("Grid").transform;                                                     //Creates a grid to store and display all the cells

        mainCamera.transform.position = new Vector3(col / 2, row / 2, -10f);                               //Sets the position of the main camera to match the grid
        mainCamera.GetComponent <Camera>().orthographicSize = (col > row ? (col / 2 + 1) : (row / 2 + 1)); //Sets the camera style to match the grid size

        Vector3 cellPos = new Vector3(0f, 0f, 0f);                                                         //Sets the position of the grid to the centre of the screen

        //Scrolls through each of the defined x and y values of the grid
        for (int x = 0; x < col; x++)
        {
            for (int y = 0; y < row; y++)
            {
                cellPos.x = x;
                cellPos.y = y;
                GameObject cellInstant = Instantiate(cell, cellPos, Quaternion.identity) as GameObject; //Instantiates a cell for each position
                cellInstant.transform.SetParent(gridHolder);                                            //Sets the position of each cell

                cellBe         = cellInstant.GetComponent <CellBehaviour>();
                cellBe.isAlive = (Random.value <= spawn ? true : false);//Sets the spawn rate of cells

                cellBe.SetPosition(x, y);
                cellMatrix[x, y] = cellInstant;
            }
        }
    }
        public override void PerformCommand()
        {
            SpawnablesManager manager = Object.FindObjectOfType <SpawnablesManager>();

            Assert.IsNotNull(manager);
            Assert.IsNotNull(troopToSpawn);

            CellBehaviour spawnLocation = GetRandomFreeCell();

            switch (troopToSpawn)
            {
            case ENTITY.Launcher:
                manager.SpawnEntity(spawnLocation, troopToSpawn, Entity.Owner.AI);
                break;

            case ENTITY.Prisioner:
                manager.SpawnEntity(spawnLocation, troopToSpawn, Entity.Owner.AI);
                break;

            case ENTITY.Tank:
                manager.SpawnEntity(spawnLocation, troopToSpawn, Entity.Owner.AI);
                break;

            case ENTITY.Turret:
                manager.SpawnEntity(spawnLocation, troopToSpawn, Entity.Owner.AI);
                break;

            case ENTITY.Wall:
                manager.SpawnEntity(spawnLocation, troopToSpawn, Entity.Owner.AI);
                break;
            }
        }
Exemplo n.º 4
0
 void OnMouseEnter()
 {
     if (!EventSystem.current.IsPointerOverGameObject())
     {
         EntityBehaviour entity = IsThereAnEntity();
         EntityBehaviour currentEntityBehaviour = GameManager.instance.currentEntityBehaviour;
         if (GameManager.instance.selectedSpell != null)
         {
             if (cellsColor[cellsColor.Count - 1] == grid.reachableSpellRange)
             {
                 List <Vector2> aoeOfSpell = currentEntityBehaviour.GetAoeOfSpell(
                     GameManager.instance.selectedSpell,
                     new Vector2(x, y)
                     );
                 foreach (Vector2 cell in aoeOfSpell)
                 {
                     CellBehaviour cellBehaviour = grid.GetCellBehaviour(
                         x + (int)cell.x,
                         y + (int)cell.y
                         );
                     if (cellBehaviour != null && cellBehaviour.isWalkable)
                     {
                         coloredCells.Add(
                             new Vector2(x + (int)cell.x, y + (int)cell.y)
                             );
                         cellBehaviour.colorCell(grid.aoeSpellRange);
                     }
                 }
             }
         }
         else if (entity)
         {
             entity.MouseEnter();
         }
         else
         {
             if (!GameManager.instance.currentEntityBehaviour.doMove)
             {
                 List <Vector2> path = currentEntityBehaviour.SetMoveTargets(cell);
                 if (path.Count <= currentEntityBehaviour.character.stats[Characteristic.CurrentMP])
                 {
                     foreach (Vector2 cell in path)
                     {
                         coloredCells.Add(new Vector2(cell.x, cell.y));
                         grid.GetCellBehaviour(
                             (int)cell.x,
                             (int)cell.y
                             ).colorCell(grid.pathMP);
                     }
                 }
             }
         }
     }
     else
     {
         OnMouseExit();
     }
 }
Exemplo n.º 5
0
 public void CleanCells(List <Vector2> cells)
 {
     foreach (Vector2 cell in cells)
     {
         CellBehaviour cellBehaviour = GetCellBehaviour((int)cell.x, (int)cell.y);
         if (cellBehaviour != null && cellBehaviour.isWalkable)
         {
             cellBehaviour.removeColorCell();
         }
     }
 }
Exemplo n.º 6
0
 public void ColorCells(List <Vector2> cells, Material material)
 {
     foreach (Vector2 cell in cells)
     {
         CellBehaviour cellBehaviour = GetCellBehaviour((int)cell.x, (int)cell.y);
         if (cellBehaviour != null && cellBehaviour.isWalkable)
         {
             cellBehaviour.colorCell(material);
         }
     }
 }
Exemplo n.º 7
0
 private void EffectCell()
 {
     if (_turnHandler.currentTurn == PlayerType.Player)
     {
         lastCellSelected = hit.collider.GetComponent <CellBehaviour>();
         if (hit.collider.GetComponent <CellBehaviour>().GetOwner() == PlayerType.Player)
         {
             hit.collider.transform.DOLocalMoveY(0.5f, 0.3f);
         }
     }
 }
Exemplo n.º 8
0
    public CellPosition GetActualPosition(CellBehaviour actualCell)
    {
        var actualPosition = _cells.FirstOrDefault(x => x.Cell == actualCell);

        if (!actualPosition)
        {
            Debug.LogError("Não foi encontrado nenhuma celula");
            return(GetFirstPosition());
        }

        return(actualPosition);
    }
Exemplo n.º 9
0
    public CellPosition GetNexPosition(CellBehaviour actualCell, int amountOfCellsToMove)
    {
        var index         = _cells.FindIndex(x => x.Cell == actualCell);
        var nextCellIndex = index + amountOfCellsToMove;

        if (nextCellIndex >= _cells.Count)
        {
            return(_cells[_cells.Count - 1]);
        }
        if (nextCellIndex < 0)
        {
            return(_cells[0]);
        }
        return(_cells[nextCellIndex]);
    }
Exemplo n.º 10
0
 public bool MoveMade(CellBehaviour cell, Vector3 pos)
 {
     Debug.Log("Moving");
     Debug.Log("v: " + cell.ownerID + ", r: " + cell.isOwned());
     if (!cell.isOwned())
     {
         hasPlayed = true;
         Debug.Log("Moved");
         cellStates [(int)pos.x, (int)pos.y, (int)pos.z] = currentPlayer;
         Debug.Log(cellStates [(int)pos.x, (int)pos.y, (int)pos.z]);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 11
0
    public void GetTurretDamage()
    {
        if (damageTurretReceived)
        {
            return;
        }
        CellBehaviour cell = this.cell;

        if (cell.explosionBelongsTo.Count > 0)
        {
            foreach (TurretNPC t in cell.explosionBelongsTo)
            {
                this.GetComponent <Health>().ReceiveDamage(t.GetComponent <AreaAttack>().damage);
            }
        }

        damageTurretReceived = true;
    }
Exemplo n.º 12
0
    private void CreateMotionPointIndicator(CellBehaviour cell)
    {
        GameObject point = Instantiate(pointInMotionPrefab);

        point.transform.SetParent(pointsInMotionParent);
        point.transform.localPosition = Vector3.zero;
        point.transform.position      = new Vector3(cell.transform.position.x, cell.transform.position.y, point.transform.position.z);
        point.transform.localScale    = Vector3.one;

        Hashtable hash = iTween.Hash(
            "position", pointsIndicator.transform.position,
            "islocal", false,
            "time", Random.Range(pointAnimationTimeMin, pointAnimationTimeMax),
            "easeType", iTween.EaseType.easeInOutQuad,
            "oncomplete", "OnPointAnimationOver",
            "oncompletetarget", this.gameObject,
            "oncompleteparams", point
            );

        iTween.MoveTo(point, hash);
    }
Exemplo n.º 13
0
    void Start()
    {
        FirstOff = false;
        menuButton.onClick.AddListener(MainMenu);
        goCell = new List <List <GameObject> >();
        CreateHexagon();

        Cell = new CellBehaviour[GridSize * 2 + 1][];

        for (int q = 0; q < GridSize * 2 + 1; q++)
        {
            Cell[q] = new CellBehaviour[goCell[q].Count];

            for (int r = 0; r < goCell[q].Count; r++)
            {
                Cell[q][r] = goCell[q][r].GetComponent <CellBehaviour>();
                Cell[q][r].terrainLoader = GetComponent <TerrainLoader>();
            }
        }

        GenerateTerrain();
    }
Exemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))          //emerge cube
        {
            RaycastHit    hit;
            CellBehaviour select = FindGameObjectUnderMouse <CellBehaviour>(out hit);
            if (select != null)
            {
                select.SetBarrier();
            }
        }

        if (Input.GetMouseButtonDown(1))          //set as point
        {
            RaycastHit    hit;
            CellBehaviour select = FindGameObjectUnderMouse <CellBehaviour>(out hit);
            if (select != null)
            {
                select.Select();
            }
        }
    }
Exemplo n.º 15
0
    private void FillPositionMatrix()
    {
        cellsPositions = new Vector3[numberOfRow][];
        cellsInGame    = new CellBehaviour[numberOfRow][];
        for (int i = 0; i < numberOfRow; i++)
        {
            cellsPositions[i] = new Vector3[numberOfLines];
            cellsInGame[i]    = new CellBehaviour[numberOfLines];
        }

        if (autoFit)
        {
            float cellSizeX = backgroundObject.transform.localScale.x / numberOfRow;
            float cellSizeY = backgroundObject.transform.localScale.y / numberOfLines;
            cellSize = new Vector3(cellSizeX, cellSizeY, 1f);

            for (int x = 0; x < numberOfRow; x++)
            {
                for (int y = 0; y < numberOfLines; y++)
                {
                    cellsPositions[x][y] = new Vector3((cellSize.x / 2f) + (x * cellSize.x), (cellSize.y / 2f) + (y * cellSize.y), 0f);
                }
            }
        }
        else
        {
            //In Not autoFit Mode, all cells prefabs need to have the same scale!
            cellSize = new Vector3(cellsPrefabs[0].transform.localScale.x, cellsPrefabs[0].transform.localScale.y, 1f);

            for (int x = 0; x < numberOfRow; x++)
            {
                for (int y = 0; y < numberOfLines; y++)
                {
                    cellsPositions[x][y] = new Vector3((cellsPrefabs[0].transform.localScale.x / 2f) + (x * cellsPrefabs[0].transform.localScale.x), (cellsPrefabs[0].transform.localScale.y / 2f) + (y * cellsPrefabs[0].transform.localScale.y), 0f);
                }
            }
        }
    }
Exemplo n.º 16
0
    IEnumerator AutoTickRedBloodCells()
    {
        while (true)
        {
            yield return(new WaitForSeconds(3f));

            if (cellsRoleSystem.RedBloodCells.Count != 0)
            {
                if (cellsRoleSystem.RedBloodCells.Count > RedBloodCellCount)
                {
                    CellBehaviour CellPlus1 = cellsRoleSystem.RedBloodCells[RedBloodCellCount].GetComponent <CellBehaviour>();
                    CellPlus1.showPointsGained();
                    if (DNAPSTier > Stats.stats.ADNTier)
                    {
                        Stats.stats.ADN += (1 * Mathf.Pow(1000, DNAPSTier - Stats.stats.ADNTier)) * .1f;
                    }
                    else if (DNAPSTier < Stats.stats.ADNTier)
                    {
                        Stats.stats.ADN += (1 / Mathf.Pow(1000, Stats.stats.ADNTier - DNAPSTier)) * .1f;
                    }
                    else
                    {
                        Stats.stats.ADN += 1;
                    }
                    RedBloodCellCount++;
                }
                else
                {
                    RedBloodCellCount = 0;
                }
            }
            else
            {
                Debug.Log("no Red Blood Cells");
            }
        }
    }
    /*
     * This method goes on the submit button
     * Saves the values inputted by user to the scriptable object
     */
    public void storeValues()
    {
        int txt;

        // Disallow blank entries and negative values
        reprodLimitText = reprodLimitField.GetComponent <Text>().text;
        if (!reprodLimitText.Equals("") && Convert.ToInt32(reprodLimitText) > 0)
        {
            UISettings.reproductionLimit = 1 * Convert.ToInt32(reprodLimitText);
        }

        agarNutLevelText = agarNutLevelField.GetComponent <Text>().text;
        if (!agarNutLevelText.Equals("") && Convert.ToInt32(agarNutLevelText) > 0)
        {
            int newLevel = 1 * Convert.ToInt32(agarNutLevelText);
            UISettings.agarLevel = newLevel;

            SimulationManager.Instance.grid.resetNutrientLevels(newLevel);
        }

        abRadiusText = abRadiusField.GetComponent <Text>().text;
        if (!abRadiusText.Equals("") && Convert.ToInt32(abRadiusText) > 0)
        {
            UISettings.ABRadius = 1 * Convert.ToInt32(abRadiusText);
        }

        spText = spField.GetComponent <Text>().text;
        if (!spText.Equals("") && Convert.ToInt32(spText) > 0)
        {
            UISettings.splitThreshold = 1 * Convert.ToInt32(spText);
        }

        // Variable set to wherever the slider is
        UISettings.tetResistance = tetStrengthSlider.value;

        energyText = energyField.GetComponent <Text>().text;
        if (!energyText.Equals("") && Convert.ToInt32(energyText) > 0)
        {
            int newEnergy = 1 * Convert.ToInt32(energyText);
            UISettings.energy = newEnergy;

            GameObject[] cells = GameObject.FindGameObjectsWithTag("cell");
            foreach (GameObject cell in cells)
            {
                CellBehaviour script = cell.GetComponent <CellBehaviour>();
                script.energy = newEnergy;
            }
        }

        cellCountText = cellCountField.GetComponent <Text>().text;
        if (!cellCountText.Equals("") && Convert.ToInt32(cellCountText) > 0)
        {
            int newCellCount = 1 * Convert.ToInt32(cellCountText);
            UISettings.numberOfCells = newCellCount;
        }

        // Different variables affected by the sliders value depending on which
        // dropdown is chosen
        if (dropDown.value == 0)
        {
            UISettings.LAI_1MutationRadius = mutationSlider.value;
        }

        else if (dropDown.value == 1)
        {
            UISettings.reproductionMutationRadius = mutationSlider.value;
        }

        else if (dropDown.value == 2)
        {
            UISettings.qsThresholdMutationRadius = mutationSlider.value;
        }
    }
Exemplo n.º 18
0
    public void SetPushTargets(Vector2 cell, int qty)
    {
        int i    = qty < 0 ? -1 : 1;
        int incr = qty < 0 ? -1 : 1;

        if (cell.x - x > cell.y - y && (cell.x - x) + (cell.y - y) >= 0) // Front
        {
            while (i != qty + incr)
            {
                CellBehaviour cellBehaviour = grid.GetCellBehaviour(x - i, y);
                if (cellBehaviour == null ||
                    !cellBehaviour.isWalkable ||
                    grid.GetEntityOnCell(x - i, y) != null)
                {
                    break;
                }
                pushTargets.Add(new Vector2(x - i, y));
                i += qty < 0 ? -1 : 1;
            }
        }
        else if (cell.x - x >= cell.y - y && (cell.x - x) + (cell.y - y) < 0) // Left
        {
            while (i != qty + incr)
            {
                CellBehaviour cellBehaviour = grid.GetCellBehaviour(x, y + i);
                if (cellBehaviour == null || !cellBehaviour.isWalkable ||
                    grid.GetEntityOnCell(x, y + i) != null)
                {
                    break;
                }
                pushTargets.Add(new Vector2(x, y + i));
                i += qty < 0 ? -1 : 1;
            }
        }
        else if (cell.x - x < cell.y - y && (cell.x - x) + (cell.y - y) <= 0) // Back
        {
            while (i != qty + incr)
            {
                CellBehaviour cellBehaviour = grid.GetCellBehaviour(x + i, y);
                if (cellBehaviour == null ||
                    !cellBehaviour.isWalkable ||
                    grid.GetEntityOnCell(x + i, y) != null)
                {
                    break;
                }
                pushTargets.Add(new Vector2(x + i, y));
                i += qty < 0 ? -1 : 1;
            }
        }
        else if (cell.x - x <= cell.y - y && (cell.x - x) + (cell.y - y) > 0) // Right
        {
            while (i != qty + incr)
            {
                CellBehaviour cellBehaviour = grid.GetCellBehaviour(x, y - i);
                if (cellBehaviour == null ||
                    !cellBehaviour.isWalkable ||
                    grid.GetEntityOnCell(x, y - i) != null)
                {
                    break;
                }
                pushTargets.Add(new Vector2(x, y - i));
                i += qty < 0 ? -1 : 1;
            }
        }
    }
Exemplo n.º 19
0
 void                 Awake() => cellBehaviour = new CellBehaviour(GetComponent <Collider>());
Exemplo n.º 20
0
 public void SetInnitialPosition(CellBehaviour cellBehaviour)
 {
     actualCell = cellBehaviour;
 }
        private void InitializeNode(int i, int j, Vector3 nodeWorldPosition, Node.ENodeType nodeType, CellBehaviour cell)
        {
            Grid[i, j]                 = Instantiate(NodePrefab, nodeWorldPosition, Quaternion.identity, nodeContainer.transform);
            Grid[i, j].NodeType        = nodeType;
            Grid[i, j].WorldPosition   = nodeWorldPosition;
            Grid[i, j].cell            = cell;
            Grid[i, j].pathfindingGrid = this;

            if (nodeType == Node.ENodeType.NonWalkable)
            {
                Material mat = Grid[i, j].GetComponent <MeshRenderer>().material;
                mat.color = new Color(0.1f, 0, 0, 0.1f);
                Grid[i, j].GetComponent <MeshRenderer>().material = mat;
            }
            else
            {
                Material mat = Grid[i, j].GetComponent <MeshRenderer>().material;
                mat.color = new Color(0, 0.2f, 0, 0.1f);
                Grid[i, j].GetComponent <MeshRenderer>().material = mat;
            }

            Grid[i, j].transform.localScale *= ScaleFactor;

            Grid[i, j].GridX = i;
            Grid[i, j].GridZ = j;
        }
        private void CreateGrid()
        {
            if (nodeContainer != null)
            {
                Destroy(nodeContainer);
            }

            nodeContainer = new GameObject("Node Container");
            nodeContainer.transform.SetParent(this.transform);
            Grid = new Node[GridSizeX, GridSizeZ];
            Vector3 gridOrigin;

            //Collider[] results = new Collider[16];

            if (UseTransformAsGridOrigin)
            {
                gridOrigin = transform.position;
            }
            else
            {
                gridOrigin = transform.position - Vector3.right * GridWorldSize.x / 2 - Vector3.forward * GridWorldSize.y / 2;
            }

            Debug.DrawRay(Vector3.zero, gridOrigin);
            for (int i = 0; i < GridSizeX; i++)
            {
                for (int j = 0; j < GridSizeZ; j++)
                {
                    Node.ENodeType nodeType          = Node.ENodeType.Walkable;
                    CellBehaviour  cell              = null;
                    Vector3        nodeWorldPosition = gridOrigin + Vector3.right * (i * _nodeDiameter + NodePrefab.NodeRadius) +
                                                       Vector3.forward * (j * _nodeDiameter + NodePrefab.NodeRadius);

                    /*results = new Collider[16];
                     *                  Physics.OverlapBoxNonAlloc(nodeWorldPosition,
                     *                          new Vector3(NodeRadius, NodeRadius, NodeRadius), results,Quaternion.identity);*/

                    Collider[] colliders = Physics.OverlapBox(nodeWorldPosition, new Vector3(0f, NodePrefab.NodeRadius, 0f), Quaternion.identity);
                    //Collider[] colliders = Physics.OverlapBox(nodeWorldPosition, new Vector3(0, NodePrefab.NodeRadius * 2, 0), Quaternion.identity);

                    LevelController levelController = FindObjectOfType <LevelController>();

                    foreach (var collider in colliders)
                    {
                        if (collider.GetComponent <Entity>() == levelController.TryingToMove())
                        {
                            continue;
                        }

                        if (collider.GetComponent <Entity>())
                        {
                            nodeType = Node.ENodeType.NonWalkable;
                            break;
                        }
                    }

                    Collider[] cols = Physics.OverlapBox(nodeWorldPosition, new Vector3(0, NodePrefab.NodeRadius, 0), Quaternion.identity, _cellMask);
                    cell = cols[0].gameObject.GetComponent <CellBehaviour>();
                    InitializeNode(i, j, nodeWorldPosition, nodeType, cell);
                }
            }
        }
    public void SpawnEntity(CellBehaviour cell, ENTITY _entityToSpawn, Entity.Owner owner)
    {
        if (!_levelController.CheckIfCanSpawn(owner))
        {
            return;
        }

        GameObject entitySpawned    = null;
        GameObject entityToSpawn    = null;
        AudioClip  entitySpawnSound = null;

        switch (_entityToSpawn)
        {
        case ENTITY.None:
            Debug.Log("Antes debes seleccionar una tropa! ");
            FindObjectOfType <AttackButtonController>().GetComponent <AttackButtonController>().ShowButtons();
            soundManagerRef.PlaySingle(soundManagerRef.incorrectMovement);
            break;

        case ENTITY.Prisioner:
            lastTroopSpawned = ENTITY.Prisioner;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Prisioner.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.cageSoundSpawn;
            break;

        case ENTITY.Launcher:
            lastTroopSpawned = ENTITY.Launcher;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Launcher.ToString() + owner.ToString());
            entityToSpawn.GetComponentInChildren <ParticleSystem>().Stop();
            entitySpawnSound = soundManagerRef.launcherSoundSpawn;
            break;

        case ENTITY.Tank:
            lastTroopSpawned = ENTITY.Tank;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Tank.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.tankSoundSpawn;
            break;

        case ENTITY.Wall:
            lastTroopSpawned = ENTITY.Wall;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Wall.ToString() + owner.ToString());
            break;

        case ENTITY.Turret:
            lastTroopSpawned = ENTITY.Turret;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Turret.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.turretSoundSpawn;
            break;
        }

        if (entityToSpawn == null)
        {
            return;
        }
        int  bloodCost   = entityToSpawn.GetComponent <Entity>().bloodCost;
        bool bloodEnough = owner == Entity.Owner.Player ? bloodCost <= _bloodController.GetCurrentPlayerBlood() : bloodCost <= _bloodController.GetCurrentAIBlood();

        if (bloodEnough)
        {
            if (entityToSpawn != null)
            {
                soundManagerRef.PlaySingle(entitySpawnSound);
                entitySpawned = Instantiate(entityToSpawn, new Vector3(cell.transform.position.x, 0f, cell.transform.position.z), entityToSpawn.transform.rotation);
                entitySpawned.GetComponent <Entity>().SetEntity(owner);
                entitySpawned.GetComponent <Entity>().entityType = lastTroopSpawned;

                if (owner == Entity.Owner.Player)
                {
                    currentEntitySelected = ENTITY.None;
                }

                //Node node = _influenceMapComponent.GetNodeAtLocation(new Vector3(cell.transform.position.x, 1f, cell.transform.position.z));

                OnSpawnedTroop?.Invoke(entitySpawned.GetComponent <Entity>());

                if (owner == Entity.Owner.Player)
                {
                    _levelController.currentTroopsPlayerSpawned++;
                    _bloodController.DecreasePlayerBloodValue(entitySpawned.GetComponent <Entity>().bloodCost);
                }
                else if (owner == Entity.Owner.AI)
                {
                    Debug.Log("decreasing blood");
                    _levelController.currentTroopsAISpawned++;
                    _bloodController.DecreaseAIBloodValue(entitySpawned.GetComponent <Entity>().bloodCost);
                }

                FindObjectOfType <AttackButtonController>().GetComponent <AttackButtonController>().HideButtons();
                cell.GetComponent <CellBehaviour>().entityIn = entitySpawned.GetComponent <AbstractNPCBrain>();
                entitySpawned.GetComponent <Entity>().cell   = cell.GetComponent <CellBehaviour>();
            }
        }

        else
        {
            Instantiate(Resources.Load <GameObject>("Prefabs/Popups/SimpleInfoPopup")).GetComponent <SimpleInfoPopupController>().SetPopup("PLAYER", "NOT ENOUGH\nBLOOD");
        }
    }
Exemplo n.º 24
0
    public void CellRoleAsign(int cellRole)
    {
        switch (cellRole)
        {
        case 0:     // add IdleCell
            GameObject    AddedCell    = Instantiate(Cell);
            CellBehaviour AddedCellBeh = AddedCell.GetComponent <CellBehaviour>();
            AddedCellBeh.body = BodyParts[CurrentBodyPart];
            ;                AddedCellBeh.CellScriptableObject = CellsScriptableObjects[0];
            AddedCell.name = "Cell" + "(" + Stats.stats.cells + ")";
            IdleCells.Add(AddedCell);
            break;

        // ------------- RED BLOOD CELL ------------//
        case 1:     // add RedBloodCell
            if (IdleCells.Count > 0)
            {
                GameObject CellChange;
                CellChange = IdleCells[IdleCells.Count - 1];
                IdleCells.RemoveAt(IdleCells.Count - 1);
                CellBehaviour cellChangeBeh = CellChange.GetComponent <CellBehaviour>();
                cellChangeBeh.CellScriptableObject = CellsScriptableObjects[1];
                RedBloodCells.Add(CellChange);
                redBloodCellSystem.AddRedBloodCell();
                Debug.Log("addedRedBloodCell");

                break;
            }
            else
            {
                Debug.Log("OutOfIdleCells");
                break;
            }

        case -1:     // remove RedBloodCell
            if (RedBloodCells.Count > 0)
            {
                GameObject CellChange;
                CellChange = RedBloodCells[RedBloodCells.Count - 1];
                RedBloodCells.RemoveAt(RedBloodCells.Count - 1);
                CellBehaviour cellChangeBeh = CellChange.GetComponent <CellBehaviour>();
                cellChangeBeh.CellScriptableObject = CellsScriptableObjects[0];
                IdleCells.Add(CellChange);
                redBloodCellSystem.RemoveRedBloodCell();
                Debug.Log("RemovedRedBloodCell");
                break;
            }
            else
            {
                Debug.Log("noRedBloodCells");
                break;
            }

        // ------------- WHITE BLOOD CELL ------------//
        case 2:    // add White Blood Cell
            if (IdleCells.Count > 0)
            {
                GameObject CellChange;
                CellChange = IdleCells[IdleCells.Count - 1];
                IdleCells.RemoveAt(IdleCells.Count - 1);
                CellBehaviour cellChangeBeh = CellChange.GetComponent <CellBehaviour>();
                cellChangeBeh.CellScriptableObject = CellsScriptableObjects[2];
                WhiteBloodCells.Add(CellChange);
                whiteBloodCellSystem.AddWhiteBloodCell();
                break;
            }
            else
            {
                Debug.Log("OutOfIdleCells");
                break;
            }

        case -2:    // Remove White Blood Cell
            if (WhiteBloodCells.Count > 0)
            {
                GameObject CellChange;
                CellChange = WhiteBloodCells[WhiteBloodCells.Count - 1];
                WhiteBloodCells.RemoveAt(WhiteBloodCells.Count - 1);
                CellBehaviour cellChangeBeh = CellChange.GetComponent <CellBehaviour>();
                cellChangeBeh.CellScriptableObject = CellsScriptableObjects[0];
                IdleCells.Add(CellChange);
                whiteBloodCellSystem.RemoveWhiteBloodCell();
                break;
            }
            else
            {
                Debug.Log("no WhiteBloodCells");
                break;
            }
        }
    }
Exemplo n.º 25
0
 public bool IsLastCell(CellBehaviour actualCell)
 {
     return(actualCell == _cells[_cells.Count - 1].Cell);
 }
Exemplo n.º 26
0
 void Start()
 {
     cellBehaviour = GetComponent <CellBehaviour>();
 }
Exemplo n.º 27
0
    CellBehaviour[] GetNeighbours(CellBehaviour cell)
    {
        CellBehaviour[] neighbour = new CellBehaviour[6];
        Vector2         TilePos   = cell.TilePostition;

        if (GetCellByPos(new Vector2(TilePos.x + 1, TilePos.y)) != null)
        {
            neighbour[0] = GetCellByPos(new Vector2(TilePos.x + 1, TilePos.y));
        }
        else
        {
            neighbour[0] = null;
        }

        if (GetCellByPos(new Vector2(TilePos.x, TilePos.y + 1)) != null)
        {
            neighbour[1] = GetCellByPos(new Vector2(TilePos.x, TilePos.y + 1));
        }
        else
        {
            neighbour[1] = null;
        }

        if (GetCellByPos(new Vector2(TilePos.x - 1, TilePos.y + 1)) != null)
        {
            neighbour[2] = GetCellByPos(new Vector2(TilePos.x - 1, TilePos.y + 1));
        }
        else
        {
            neighbour[2] = null;
        }

        if (GetCellByPos(new Vector2(TilePos.x - 1, TilePos.y)) != null)
        {
            neighbour[3] = GetCellByPos(new Vector2(TilePos.x - 1, TilePos.y));
        }
        else
        {
            neighbour[3] = null;
        }

        if (GetCellByPos(new Vector2(TilePos.x, TilePos.y - 1)) != null)
        {
            neighbour[4] = GetCellByPos(new Vector2(TilePos.x, TilePos.y - 1));
        }
        else
        {
            neighbour[4] = null;
        }

        if (GetCellByPos(new Vector2(TilePos.x + 1, TilePos.y - 1)) != null)
        {
            neighbour[5] = GetCellByPos(new Vector2(TilePos.x + 1, TilePos.y - 1));
        }
        else
        {
            neighbour[5] = null;
        }

        return(neighbour);
    }
Exemplo n.º 28
0
    public void GenerateRivers()
    {
        float             SeaLevel         = 0.1f;
        int               RiverCount       = 0;
        CellBehaviour     HighestTileOnMap = Cell[0][0];
        List <GameObject> HighestTile      = new List <GameObject>();

        HighestTile.Add(goCell[0][0]);
        for (int q = 0; q < GridSize * 2 + 1; q++)
        {
            for (int r = 0; r < goCell[q].Count; r++)
            {
                if (Cell[q][r].altitude < SeaLevel)
                {
                    Cell[q][r].TileBiome = CellBehaviour.BiomeType.Ocean;
                    StreamCells.Add(Cell[q][r]);
                    Cell[q][r].transform.localScale = new Vector3(1, SeaLevel, 1);
                }

                if (HighestTileOnMap.altitude < Cell[q][r].altitude)
                {
                    HighestTileOnMap = Cell[q][r];
                }

                //if (HexDistance(HighestTile[0].GetComponent<CellBehaviour>().TilePostition, Cell[q][r].TilePostition) > )
                //{
                //
                //}
            }
        }
        HighestTile[0] = HighestTileOnMap.gameObject;

        int RiverLength = 200;

        CellBehaviour[] neighbours = null;
        for (int i = 0; i < 0; i++)
        {
            neighbours = GetNeighbours(HighestTile[i].GetComponent <CellBehaviour>());
            for (int z = 0; z < neighbours.Length; z++)
            {
                neighbours[z].GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
                StreamCells.Add(neighbours[z]);
                HighestTile.Add(neighbours[z].gameObject);
                CellBehaviour[] Innerneighbours = null;
                if (neighbours[z] != null)
                {
                    Innerneighbours = GetNeighbours(neighbours[z].GetComponent <CellBehaviour>());
                    for (int p = 0; p < Innerneighbours.Length; p++)
                    {
                        Innerneighbours[p].GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
                        StreamCells.Add(Innerneighbours[p]);
                        HighestTile.Add(Innerneighbours[p].gameObject);
                        Innerneighbours[p].altitude *= 0.9f;
                    }
                }
            }
        }

        CellBehaviour[] neighbour = new CellBehaviour[6];

        for (int q = 0; q < HighestTile.Count; q++)
        {
            CellBehaviour NextHighestTile;
            CellBehaviour SecondHighestTile = null;
            HighestTile[q].GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
            NextHighestTile = HighestTile[q].GetComponent <CellBehaviour>();

            for (int i = 0; i < RiverLength; i++)
            {
                #region Getting Neighbours

                neighbour = GetNeighbours(HighestTile[q].GetComponent <CellBehaviour>());

                NextHighestTile = HighestTileOnMap;

                for (int l = 0; l < 6; l++)
                {
                    if (neighbour[l] != null)
                    {
                        if (NextHighestTile.altitude > neighbour[l].altitude)
                        {
                            SecondHighestTile = NextHighestTile;
                            NextHighestTile   = neighbour[l];
                        }
                    }
                }

                #endregion

                if (i == 0)
                {
                    if (NextHighestTile.gameObject == HighestTile[q])
                    {
                        break;
                    }

                    bool[] IsGonnaBeWater = new bool[6];
                    for (int v = 0; v < 6; v++)
                    {
                        IsGonnaBeWater[v] = (UnityEngine.Random.value < 0.5f ? true : false);

                        if (neighbour[v] && IsGonnaBeWater[v])
                        {
                            neighbour[v].TileBiome = CellBehaviour.BiomeType.Ocean;
                        }
                    }
                }
                else if (NextHighestTile.GetComponent <CellBehaviour>().TileBiome == CellBehaviour.BiomeType.Ocean)
                {
                    break;
                }
                else if (NextHighestTile.gameObject == HighestTile[q])
                {
                    for (int v = 0; v < 6; v++)
                    {
                        if (neighbour[v])
                        {
                            neighbour[v].TileBiome = CellBehaviour.BiomeType.Ocean;
                        }
                    }
                    break;
                }

                if (SecondHighestTile)
                {
                    StreamCells.Add(SecondHighestTile);
                    SecondHighestTile.GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
                }

                NextHighestTile.GetComponent <CellBehaviour>().TileBiome = CellBehaviour.BiomeType.Ocean;
                StreamCells.Add(NextHighestTile);
                HighestTile[q] = NextHighestTile.gameObject;
            }
        }
    }
Exemplo n.º 29
0
    public void SetTerrain()
    {
        for (int q = 0; q < GridSize * 2 + 1; q++)
        {
            for (int r = 0; r < goCell[q].Count; r++)
            {
                Cell[q][r].SetTileProperties(Noise[q][r], BiomeHumidity[q][r]);
            }
        }

        GenerateRivers();

        for (int q = 0; q < GridSize * 2 + 1; q++)
        {
            for (int r = 0; r < goCell[q].Count; r++)
            {
                if (Cell[q][r].TileBiome != CellBehaviour.BiomeType.Ocean)
                {
                    CellBehaviour ClosestStream = StreamCells[0];

                    for (int i = 0; i < StreamCells.Count; i++)
                    {
                        if (HexDistance(Cell[q][r].TilePostition, StreamCells[i].TilePostition) < HexDistance(Cell[q][r].TilePostition, ClosestStream.TilePostition))
                        {
                            ClosestStream = StreamCells[i];
                        }
                    }
                    float DistanceShade = Mathf.Clamp(HexDistance(Cell[q][r].TilePostition, ClosestStream.TilePostition) / 10, 0, 0.9f);
                    Cell[q][r].humidity = Mathf.Clamp(Cell[q][r].humidity + DistanceShade / 2, 0, 1);
                    Cell[q][r].GetComponent <UVScroller>().SetTexture(ObjectType.Biome, Cell[q][r].gameObject, (int)Cell[q][r].TileType, (Cell[q][r].humidity - 1) * -1);
                }

                if (Cell[q][r].TileBiome == CellBehaviour.BiomeType.Ocean)
                {
                    #region Getting Neighbours
                    List <float>         WaterLevels       = new List <float>();
                    float                waterNeighbours   = 0;
                    float                normalWaterLevel  = 0;
                    List <CellBehaviour> neighbour         = new List <CellBehaviour>();
                    List <CellBehaviour> NotWaterNeighbour = new List <CellBehaviour>();
                    bool FoundNonWater = false;


                    if (GetCellByPos(new Vector2(Cell[q][r].TilePostition.x + 1, Cell[q][r].TilePostition.y)) != null)
                    {
                        neighbour.Add(GetCellByPos(new Vector2(Cell[q][r].TilePostition.x + 1, Cell[q][r].TilePostition.y)));
                        if (neighbour[neighbour.Count - 1].TileBiome == CellBehaviour.BiomeType.Ocean)
                        {
                            waterNeighbours++;
                        }
                        else
                        {
                            FoundNonWater = true;
                        }
                    }

                    if (GetCellByPos(new Vector2(Cell[q][r].TilePostition.x, Cell[q][r].TilePostition.y + 1)) != null)
                    {
                        neighbour.Add(GetCellByPos(new Vector2(Cell[q][r].TilePostition.x, Cell[q][r].TilePostition.y + 1)));
                        if (neighbour[neighbour.Count - 1].TileBiome == CellBehaviour.BiomeType.Ocean)
                        {
                            waterNeighbours++;
                        }
                        else
                        {
                            FoundNonWater = true;
                        }
                    }

                    if (GetCellByPos(new Vector2(Cell[q][r].TilePostition.x - 1, Cell[q][r].TilePostition.y + 1)) != null)
                    {
                        neighbour.Add(GetCellByPos(new Vector2(Cell[q][r].TilePostition.x - 1, Cell[q][r].TilePostition.y + 1)));
                        if (neighbour[neighbour.Count - 1].TileBiome == CellBehaviour.BiomeType.Ocean)
                        {
                            waterNeighbours++;
                        }
                        else
                        {
                            FoundNonWater = true;
                        }
                    }

                    if (GetCellByPos(new Vector2(Cell[q][r].TilePostition.x - 1, Cell[q][r].TilePostition.y)) != null)
                    {
                        neighbour.Add(GetCellByPos(new Vector2(Cell[q][r].TilePostition.x - 1, Cell[q][r].TilePostition.y)));
                        if (neighbour[neighbour.Count - 1].TileBiome == CellBehaviour.BiomeType.Ocean)
                        {
                            waterNeighbours++;
                        }
                        else
                        {
                            FoundNonWater = true;
                        }
                    }

                    if (GetCellByPos(new Vector2(Cell[q][r].TilePostition.x, Cell[q][r].TilePostition.y - 1)) != null)
                    {
                        neighbour.Add(GetCellByPos(new Vector2(Cell[q][r].TilePostition.x, Cell[q][r].TilePostition.y - 1)));
                        if (neighbour[neighbour.Count - 1].TileBiome == CellBehaviour.BiomeType.Ocean)
                        {
                            waterNeighbours++;
                        }
                        else
                        {
                            FoundNonWater = true;
                        }
                    }

                    if (GetCellByPos(new Vector2(Cell[q][r].TilePostition.x + 1, Cell[q][r].TilePostition.y - 1)) != null)
                    {
                        neighbour.Add(GetCellByPos(new Vector2(Cell[q][r].TilePostition.x + 1, Cell[q][r].TilePostition.y - 1)));
                        if (neighbour[neighbour.Count - 1].TileBiome == CellBehaviour.BiomeType.Ocean)
                        {
                            waterNeighbours++;
                        }
                        else
                        {
                            FoundNonWater = true;
                        }
                    }

                    #endregion
                    if (FoundNonWater)
                    {
                        CellBehaviour SmallestNonWaterTile = neighbour[0];

                        for (int i = 0; i < neighbour.Count; i++)
                        {
                            if (neighbour[i].TileBiome != CellBehaviour.BiomeType.Ocean)
                            {
                                SmallestNonWaterTile = neighbour[i];
                                FoundNonWater        = true;
                                break;
                            }
                        }

                        for (int i = 0; i < neighbour.Count; i++)
                        {
                            if (neighbour[i])
                            {
                                if (neighbour[i].TileBiome != CellBehaviour.BiomeType.Ocean)
                                {
                                    if (neighbour[i].altitude < SmallestNonWaterTile.altitude)
                                    {
                                        SmallestNonWaterTile = neighbour[i];
                                    }
                                }
                            }
                        }

                        Cell[q][r].transform.localScale = new Vector3(1, Mathf.Clamp(SmallestNonWaterTile.altitude * 0.1f, 0.1f, 1f), 1);
                    }


                    for (int i = 0; i < neighbour.Count; i++)
                    {
                        if (neighbour[i])
                        {
                            WaterLevels.Add(neighbour[i].transform.localScale.y);
                        }
                    }

                    for (int v = 0; v < WaterLevels.Count; v++)
                    {
                        normalWaterLevel += WaterLevels[v];
                    }

                    normalWaterLevel /= WaterLevels.Count;

                    Cell[q][r].transform.localScale = new Vector3(1, normalWaterLevel, 1);

                    float waterDepth = Mathf.Lerp(0, 1, waterNeighbours / 6f) * 0.75f;

                    Cell[q][r].GetComponent <UVScroller>().SetTexture(ObjectType.Biome, Cell[q][r].gameObject, (float)Cell[q][r].TileBiome, Mathf.Clamp(waterDepth + (Cell[q][r].humidity * 0.25f), 0.1f, 1f));
                }
            }
        }
    }
    //Generate the grid of given dimensions
    void GenGrid()
    {
        //Reference objects
        GameObject cellRef     = (GameObject)Instantiate(Resources.Load("Cell"));
        GameObject mistakeRef  = (GameObject)Instantiate(Resources.Load("MistakeMarker"));
        GameObject clueTileRef = (GameObject)Instantiate(Resources.Load("ClueGrid"));

        float posX, posY;

        //grid is generated from the bottom up
        for (int r = (rows + clueNum - 1); r >= 0; r--)
        {
            int rowShift = 0; //row counter for skipping empty clues
            for (int c = (cols - 1); c >= -(clueNum); c--)
            {
                int colShift = 0; //col counter for skipping empty clues
                if (r < rows)
                {
                    if (c >= 0)
                    {
                        //instantiate cell
                        GameObject    cell          = (GameObject)Instantiate(cellRef, transform);
                        CellBehaviour cellBehaviour = cell.GetComponent <CellBehaviour>();
                        cellBehaviour.correct     = solMat[r, c];
                        cellBehaviour.gridManager = this;

                        posX = c - (cols / 2);
                        posY = r - (rows / 2);

                        cell.transform.position = new Vector3(posX, posY, 0);
                    }
                    else
                    {
                        if (clueTileGrid[r, 0, (c + clueNum)] != 0 || (clueTileGrid[r, 0, 0] == 0 && clueTileGrid[r, 0, 1] == 0) && (c + clueNum == 0))
                        {
                            //instantiate non-zero clue, or final clue if there are no non-zero clues
                            GameObject clueTile = (GameObject)Instantiate(clueTileRef, transform);
                            clueTile.GetComponent <TextMeshPro>().text = clueTileGrid[r, 0, (c + clueNum)].ToString();

                            posX = (c + rowShift) - (cols / 2);
                            posY = r - (rows / 2);

                            clueTile.transform.position = new Vector3(posX, posY, 0);
                        }
                        else
                        {
                            rowShift++;
                        }
                    }
                }
                else
                {
                    if (c >= 0)
                    {
                        if (clueTileGrid[c, 1, (r - rows)] != 0 || (clueTileGrid[c, 1, 0] == 0 && clueTileGrid[c, 1, 1] == 0) && (r - rows == 0))
                        {
                            //instantiate non-zero clue, or final clue if there are no non-zero clues
                            GameObject clueTile = (GameObject)Instantiate(clueTileRef, transform);
                            clueTile.GetComponent <TextMeshPro>().text = clueTileGrid[c, 1, (r - rows)].ToString();

                            posX = c - (cols / 2);
                            posY = (r - colShift) - (rows / 2);

                            clueTile.transform.position = new Vector3(posX, posY, 0);
                        }
                        else
                        {
                            colShift++;
                        }
                    }
                }
            }
        }

        for (int i = 0; i < maxMistakes; i++)
        {
            //display mistake markers
            GameObject mistakeMarker = (GameObject)Instantiate(mistakeRef, transform);

            posX = cols;
            posY = i + 1.3f;

            mistakeMarker.transform.position = new Vector3(posX, posY, 0);
            mistakeSprites[i] = mistakeMarker;
        }

        //destroy reference objects
        Destroy(cellRef);
        Destroy(mistakeRef);
        Destroy(clueTileRef);

        //reset the timer to zero.
        timer       = 0.0f;
        timerActive = true;
    }