Example #1
0
    void Add_Clutter(HexagonCell cell)
    {
        if (cell.gameObject.tag == "Water" || cell.gameObject.tag == "Wall" || cell.gameObject.tag == "SlowingTile")
        {
            //don't do
        }
        else
        {
            int rand_clutter_amnt = Random.Range(0, 2);

            for (int i = 0; i < rand_clutter_amnt; i++)
            {
                int        rand_clutter   = Random.Range(0, Clutter_List.Count);
                GameObject clutter_object = Instantiate <GameObject>(Clutter_List[rand_clutter]);
                clutter_object.transform.SetParent(cell.transform);
                clutter_object.transform.localPosition = new Vector3(0, 0, 0);
                if (clutter_object.GetComponent <Clutter_Obj>().background)
                {
                    float pos_x_rand = Random.Range(-0.13f, 0.13f);
                    float pos_y_rand = Random.Range(0.08f, 0.1f);
                    clutter_object.transform.localPosition = new Vector3(pos_x_rand, pos_y_rand, 0);
                }
                else
                {
                    float pos_x_rand = Random.Range(-0.13f, 0.13f);
                    float pos_y_rand = Random.Range(-0.08f, -0.1f);
                    clutter_object.transform.localPosition = new Vector3(pos_x_rand, pos_y_rand, 0);
                }
            }
        }
    }
Example #2
0
 // Update is called once per frame
 private void Update()
 {
     if (!EventSystem.current.IsPointerOverGameObject())
     {
         // 鼠标邮件点击判断选择的单元格
         if (Input.GetMouseButton(0))
         {
             this.HandleInput();
             return;
         }
         // 按下u键的时候创建单位
         if (Input.GetKeyDown(KeyCode.U))
         {
             if (Input.GetKey(KeyCode.LeftShift))
             {
                 this.DestroyUnit();
             }
             else
             {
                 this.CreateUnit();
             }
             return;
         }
     }
     this.previousCell = null;
 }
Example #3
0
    public override HazardInfo CreateHazardAt(HexagonCell cell, Grid hexGrid)
    {
        HexagonCoord coord = cell.coords;

        int size = Random.Range(2, 3); // 0 = 1, 1 = 3, 2 = 5
        List <HexagonCell> frontier = new List <HexagonCell>();

        //HexagonCell curr = hexGrid.Get_Cell_Index(new HexagonCoord(rand.x, rand.z));
        for (int i = 0; i < hexGrid.cells.Length; i++)
        {
            int distance = cell.coords.FindDistanceTo(hexGrid.cells[i].coords);
            if (distance <= size)
            {
                frontier.Add(hexGrid.cells[i]);
            }
        }

        for (int j = 0; j < frontier.Count; j++)
        {
            frontier[j].Create_Rain();
        }
        cell.Create_Weather_Vane();

        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().lightningSound.Play();
        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().rainSound.Play();

        return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size, true));
    }
Example #4
0
    public override HazardInfo CreateHazard(int size, HexagonCoord coord, Grid hexGrid)
    {
        //int randRange = Random.Range(0, hexGrid.cells.Length);
        //HexagonCoord rand = hexGrid.cells[randRange].coords;

        //int size = Random.Range(2,5); // 0 = 1, 1 = 3, 2 = 5
        Debug.Log("hazard at (" + coord.x + "," + coord.z + ") with size: " + size);
        List <HexagonCell> frontier = new List <HexagonCell>();
        HexagonCell        curr     = hexGrid.Get_Cell_Index(new HexagonCoord(coord.x, coord.z));

        for (int i = 0; i < hexGrid.cells.Length; i++)
        {
            int distance = curr.coords.FindDistanceTo(hexGrid.cells[i].coords);
            if (distance <= size)
            {
                frontier.Add(hexGrid.cells[i]);
            }
        }
        for (int j = 0; j < frontier.Count; j++)
        {
            frontier[j].Create_Rain();
        }
        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().lightningSound.Play();
        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().rainSound.Play();
        return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size));
    }
    public virtual IEnumerator Effect(HexagonMapEditor editor, Grid hexGrid, int x, int z, int size) // does the effect of the hazard on the tiles that are in its size
    {
        List <HexagonCell> frontier = new List <HexagonCell>();                                      // list of nodes that the hazard has effect over
        HexagonCell        curr     = hexGrid.Get_Cell_Index(new HexagonCoord(x, z));

        //Debug.Log(type_name  +" hazard epicenter at: " + curr.coords.x + "," + curr.coords.Y_coord + "," + curr.coords.z);
        for (int i = 0; i < hexGrid.cells.Length; i++)
        {
            int distance = curr.coords.FindDistanceTo(hexGrid.cells[i].coords);
            if (distance <= size)
            {
                frontier.Add(hexGrid.cells[i]);
            }
        }
        for (int j = 0; j < frontier.Count; j++)
        {
            if (frontier[j].occupied)
            {
                frontier[j].unitOnTile.current_health -= 10;
                Debug.Log("Hazard effected " + frontier[j].unitOnTile.unit_name + " for 10 damage");
            }
        }
        yield return(new WaitForSeconds(anim_time));

        Debug.Log("effect finishing");
    }
Example #6
0
 /// <summary>
 /// // Removes a given HexagonCell from all containers
 /// </summary>
 /// <param name="HexagonCell"></param>
 public void RemoveHexagonCellFromAllContainers(HexagonCell HexagonCell)
 {
     foreach (BoxTypeFeature key in _hexContainers.Keys)
     {
         RemoveHexagonCellFromContainer(HexagonCell, key);
     }
 }
Example #7
0
    /// <summary>
    /// // Returns a list of validated neighboring cube HexagonCells at a evaluation distance of 1
    /// </summary>
    /// <param name="cube"></param>
    /// <param name="cleanResults"></param>
    /// <returns></returns>
    public List <Vector3> GetReachableCubes(Vector3 cube, bool cleanResults = true)
    {
        List <Vector3> cubes = new List <Vector3>();

        HexagonCell originHexagonCell  = GetHexagonCellFromContainer(cube, _tileFeature);
        HexagonCell currentHexagonCell = null;
        Vector3     currentCube        = cube;

        for (int i = 0; i < 6; i++)
        {
            currentCube        = GetNeighborCube(cube, i);
            currentHexagonCell = GetHexagonCellFromContainer(currentCube, _tileFeature);

            if (currentHexagonCell != null)
            {
                cubes.Add(currentCube);
            }
        }

        if (cleanResults)
        {
            return(CleanCubeResults(cubes));
        }
        return(cubes);
    }
Example #8
0
    public int damageDealt = 30; // amount of damage dealt by this effect

    public override HazardInfo CreateHazardAt(HexagonCell cell, Grid hexGrid)
    {
        // code to spawn the particle system or whatever to show the effect

        //Debug.Log("shooting poison gas on map");
        HexagonCoord       coord    = cell.coords;
        int                size     = 1;
        List <HexagonCell> frontier = new List <HexagonCell>();

        //HexagonCell curr = hexGrid.Get_Cell_Index(new HexagonCoord(rand.x, rand.z));

        //HexagonCell hexa_cell = coord.

        for (int i = 0; i < hexGrid.cells.Length; i++)
        {
            int distance = cell.coords.FindDistanceTo(hexGrid.cells[i].coords);
            if (distance <= size)
            {
                frontier.Add(hexGrid.cells[i]);
            }
        }

        for (int j = 0; j < frontier.Count; j++)
        {
            frontier[j].Create_Poison_Cloud();
        }
        //GameObject.FindGameObjectWithTag("SoundManager").GetComponent<SoundManager>().lightningSound.Play();
        //GameObject.FindGameObjectWithTag("SoundManager").GetComponent<SoundManager>().rainSound.Play();


        return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, 1));
    }
    public void Sort_renderer(GameObject object_to_sort, HexagonCell _target_location)
    {
        Anima2D.SpriteMeshInstance Sprite_Mesh = object_to_sort.GetComponent <Anima2D.SpriteMeshInstance>();
        if (Sprite_Mesh != null)
        {
            Sprite_Mesh.sortingOrder = Sprite_Mesh.GetComponent <Mesh_Layer>()._ordered_layer
                                       + ((_target_location.coords.X_coord + _target_location.coords.Y_coord) * Static_Variable_Container.max_sprite_sort);
        }

        SpriteRenderer sprite_rend = object_to_sort.GetComponent <SpriteRenderer>();

        if (sprite_rend != null)
        {
            sprite_rend.sortingOrder = sprite_rend.GetComponent <Mesh_Layer>()._ordered_layer
                                       + ((_target_location.coords.X_coord + _target_location.coords.Y_coord) * Static_Variable_Container.max_sprite_sort);
        }

        Canvas canvas_rend = object_to_sort.GetComponent <Canvas>();

        if (canvas_rend != null)
        {
            canvas_rend.sortingOrder = canvas_rend.GetComponent <Mesh_Layer>()._ordered_layer
                                       + ((_target_location.coords.X_coord + _target_location.coords.Y_coord) * Static_Variable_Container.max_sprite_sort);
        }
    }
Example #10
0
    //used for putting sprites in the right order, so that everything appears as it should (further away tiles appear behind those closer up)
    public void Order_Cell(HexagonCell _cell, int num_sprites_per_cell)
    {
        //int _current_sorting_order = _cell.gameObject.GetComponent<SpriteRenderer>().sortingOrder;
        //_cell.gameObject.GetComponent<SpriteRenderer>().sortingOrder = _current_sorting_order +
        //    ((_cell.coords.X_coord + _cell.coords.Y_coord) * num_sprites_per_cell);

        int count = 0;

        SpriteRenderer[] sprites = _cell.gameObject.GetComponentsInChildren <SpriteRenderer>(true);
        //Debug.Log("--------------------" + sprites.Length);
        foreach (SpriteRenderer sprite_renderer in sprites)
        {
            sprite_renderer.sortingOrder = sprite_renderer.sortingOrder
                                           + ((_cell.coords.X_coord + _cell.coords.Y_coord) * num_sprites_per_cell);
            count += 1;
            //Debug.Log("" + count + ": " + num_sprites_per_cell + " " + sprite_renderer.sortingOrder);
        }

        Canvas[] canvases = _cell.gameObject.GetComponentsInChildren <Canvas>(true);
        foreach (Canvas canvas_rend in canvases)
        {
            canvas_rend.sortingOrder = canvas_rend.sortingOrder
                                       + ((_cell.coords.X_coord + _cell.coords.Y_coord) * Static_Variable_Container.max_sprite_sort);
        }
    }
Example #11
0
        public bool ClickOnGrid(float xmax, float ymax, float x, float y)
        {
            PointF p = new PointF(x, y);

            float s1 = (xmax - 1) / ((hexagonCellGrid.Length + 1) / 2 + hexagonCellGrid.Length);
            float s2 = (ymax - 1) / (hexagonCellGrid.Length * SQRT_3 + SQRT_3 / 2);

            var s = Math.Min(s1, s2);

            for (int row = 0; row < hexagonCellGrid.Length; row++)
            {
                for (int col = 0; col < hexagonCellGrid[row].Length; col++)
                {
                    if (hexagonCellGrid[row][col] != null)
                    {
                        var points = HexToPoints(s, row, col);

                        if (IsPointInPolygon(points, p))
                        {
                            clicked = hexagonCellGrid[row][col];
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Example #12
0
 /// <summary>
 /// // Hides and Clears all HexagonCells for a given container key
 /// </summary>
 /// <param name="key"></param>
 public void HideAndClearhexContainer(BoxTypeFeature key)
 {
     foreach (HexagonCell HexagonCell in GetHexagonCellsFromContainer(key))
     {
         HexagonCell.Hide();
     }
     ClearHexagonCellsFromContainer(key);
 }
Example #13
0
 /// <summary>
 /// // Shows all HexagonCells for a given container key
 /// </summary>
 /// <param name="key"></param>
 /// <param name="bCollider"></param>
 public void ShowHexagonCellsInContainer(BoxTypeFeature key, bool bCollider = true)
 {
     foreach (HexagonCell HexagonCell in GetHexagonCellsFromContainer(key))
     {
         HexagonCell.Show();
         AddHexagonCellToContainer(HexagonCell, "visible");
     }
 }
Example #14
0
        public HexAreaHint(HexGrid grid, HexagonCell cell)
        {
            Source   = cell;
            Number   = cell.Hint.Number;
            AllCells = GetCells(grid, cell).ToList().AsReadOnly();

            CleanConditions();
        }
Example #15
0
 /// <summary>
 /// // Hides all HexagonCells for a given container key
 /// </summary>
 /// <param name="key"></param>
 public void HideHexagonCellsInContainer(BoxTypeFeature key)
 {
     foreach (HexagonCell HexagonCell in GetHexagonCellsFromContainer(key))
     {
         HexagonCell.Hide();
         RemoveHexagonCellFromContainer(HexagonCell, "visible");
     }
 }
Example #16
0
    public void trigger_effect_on_unit()
    {
        HexagonCell _cell         = editor.hexGrid.GetCell(Unit_Getting_Attacked.transform.position);
        Spawn_Flash flash_spawn   = GetComponentInChildren <Spawn_Flash>();
        GameObject  flash_hit_obj = flash_spawn.Show_Flash_Hit(Unit_Getting_Attacked);

        re_sort_object_position(_cell, flash_hit_obj.GetComponent <SpriteRenderer>());
    }
Example #17
0
        /// <summary>
        /// 移除单位
        /// </summary>
        private void DestroyUnit()
        {
            HexagonCell cell = this.GetCellUnderCursor();

            if (cell && cell.Unit)
            {
                this.hexagonGrid.RemoveUnit(cell.Unit);
            }
        }
Example #18
0
        public HexRowHint(HexGrid grid, HexagonCell cell)
        {
            Source   = cell;
            Type     = ConvertHintType(cell.Hint);
            Number   = cell.Hint.Number;
            AllCells = GetCells(grid, cell).ToList().AsReadOnly();

            CleanConditions();
        }
Example #19
0
    /// <summary>
    /// // Removes a given HexagonCell from the given container key
    /// </summary>
    /// <param name="HexagonCell"></param>
    /// <param name="key"></param>
    public void RemoveHexagonCellFromContainer(HexagonCell HexagonCell, BoxTypeFeature key)
    {
        Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key);

        if (hexContainer.ContainsKey(HexagonCell.cube))
        {
            hexContainer.Remove(HexagonCell.cube);
        }
    }
    public virtual HazardInfo CreateHazardAt(HexagonCell cell, Grid hexGrid)
    {
        // code to spawn the particle system or whatever to show the effect

        //Debug.Log("shooting poison gas on map");
        HexagonCoord coord = cell.coords;
        int          size  = Random.Range(0, 3);

        return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size));
    }
Example #21
0
 public MyCell(HexagonCell hexagonCell, string ownerName)
 {
     Id         = hexagonCell.Id;
     Resources  = hexagonCell.Resources;
     Neighbours = new NeighbourCell[hexagonCell.Neighbours.Length];
     for (int i = 0; i < hexagonCell.Neighbours.Length; i++)
     {
         Neighbours[i] = new NeighbourCell(hexagonCell.Neighbours[i], ownerName);
     }
 }
Example #22
0
    /// <summary>
    /// // Adds a given HexagonCell to the given container key
    /// </summary>
    /// <param name="HexagonCell"></param>
    /// <param name="key"></param>
    /// <returns></returns>
    public bool AddHexagonCellToContainer(HexagonCell HexagonCell, BoxTypeFeature key)
    {
        Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key);

        if (!hexContainer.ContainsKey(HexagonCell.cube))
        {
            hexContainer.Add(HexagonCell.cube, HexagonCell);
            return(true);
        }
        return(false);
    }
Example #23
0
        /// <summary>
        /// 当前选中的单元格更新,并返回选中的单元格是否变更
        /// </summary>
        /// <returns><c>true</c>, if current cell was updated, <c>false</c> otherwise.</returns>
        private bool UpdateCurrentCell()
        {
            HexagonCell cell = this.hexagonGrid.GetCell(Camera.main.ScreenPointToRay(Input.mousePosition));

            if (cell != this.currentCell)
            {
                this.currentCell = cell;
                return(true);
            }
            return(false);
        }
Example #24
0
    /// <summary>
    /// // Removes and destroys a Coordinate for a given cube coordinate
    /// </summary>
    /// <param name="cube"></param>
    public void RemoveCube(Vector3 cube)
    {
        HexagonCell hexagonCell = GetHexagonCellFromContainer(cube, _tileFeature);

        if (hexagonCell == null)
        {
            return;
        }

        RemoveHexagonCellFromAllContainers(hexagonCell);
        Destroy(hexagonCell.gameObject);
    }
 public override void DebufTeam(string team, HexagonCell myCell) // every unit that was buffed gets debuffed
 {
     for (int i = 0; i < wasBuffed.Count; i++)                   // for every unit that was buffed
     {
         if (wasBuffed[i] != null)
         {
             Debuf(wasBuffed[i]); //debuf them
         }
         defense -= 5;
     }
     wasBuffed.Clear(); //clear the list
 }
Example #26
0
    public override HazardInfo CreateHazardAt(HexagonCell cell, Grid hexGrid)
    {
        HexagonCoord coord = cell.coords;
        //int randRange = Random.Range(0, hexGrid.cells.Length);
        //HexagonCoord rand = hexGrid.cells[randRange].coords;

        int size = Random.Range(1, 3); // 0 = 1, 1 = 3, 2 = 5

        Debug.Log("hazard at (" + coord.x + "," + coord.z + ") with size: " + size);
        cell.Create_Weather_Vane();
        return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size, true));
    }
Example #27
0
    public void Enqueue(HexagonCell cell)
    {
        count += 1;
        int priority = cell.SearchPriority;

        while (priority >= list.Count)
        {
            list.Add(null);
        }
        cell.NextWithSamePriority = list[priority];
        list[priority]            = cell;
    }
Example #28
0
    void TouchCell(Vector3 position)
    {
        position = transform.InverseTransformPoint(position);
        HexagonCoord coordinates = HexagonCoord.FromPosition(position);
        int          index       = coordinates.X_coord + coordinates.Z_coord * width + coordinates.Z_coord / 2;

        Debug.Log(index);
        HexagonCell cell = cells[index];

        cell.color = touchedColor;
        hexMesh.Triangulate(cells);
    }
Example #29
0
        /// <summary>
        /// 创建单位
        /// </summary>
        private void CreateUnit()
        {
            HexagonCell cell = this.GetCellUnderCursor();

            // 选中的单元格不是空
            // 当前单元格上没有其他单位时才能创建单位
            if (cell && !cell.Unit)
            {
                // 单位放到地图上
                this.hexagonGrid.AddUnit(Instantiate <HexagonUnit> (this.unitPrefab), cell, Random.Range(0f, 360f));
            }
        }
Example #30
0
    public IEnumerator HopToPlace(Grid hexGrid, HexagonCell unitCell, int index, int distance)
    {
        //All Movement Audio Goes Here
        if (Moving_Lines_List.Length > 0)
        {
            int Chosen_Voice_Line_Index = Random.Range(0, Moving_Lines_List.Length);
            Moving_Lines_List[Chosen_Voice_Line_Index].Play();
        }

        string name = unitCell.unitOnTile.unit_name;
        Stack <HexagonCell> result  = hexGrid.FindPath(unitCell, hexGrid.cells[index]);
        HexagonCoord        current = unitCell.coords;

        while (result.Count > 0)
        {
            HexagonCell temp = result.Pop();
            if (temp.coords.x > current.x || (temp.coords.x == current.x && temp.coords.z == current.z + 1)) //going right
            {
                if (!direction)                                                                              //facing left
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = true;
                }
            }
            else //going left
            {
                if (direction)
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = false;
                }
            }
            StartCoroutine(Moving());
            yield return(new WaitForSeconds(0.3f));

            transform.position = temp.transform.position;
            current            = temp.coords;
            editor.re_sort_unit_position(this, hexGrid.GetCell(temp.transform.position));
            yield return(new WaitForSeconds(0.3f));
        }
        if (slowed)
        {
            slowing_counter -= 1;
            Debug.Log(name + " is slowed for " + slowing_counter + " more turns");
            if (slowing_counter == 0)
            {
                current_mobility = mobility;
                slowed           = false;
                Debug.Log(name + " is no longer slowed");
            }
        }
    }