Esempio n. 1
0
 public void SetRank(UnitRank rank)
 {
     this.rank = rank;
     //Initialize the values
     unitName.text  = UnitUtilities.ReadableRank(rank);
     image.sprite   = UnitImageManager.GetRankImage(rank);
     remaining.text = UnitManager.GetPlacementAmountForUnit(rank).ToString();
 }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        //Generate first row of defender
        foreach (UnitRank rank in Enum.GetValues(typeof(UnitRank)))
        {
            if (!rank.Equals(UnitRank.Unknown))
            {
                GameObject cell = Instantiate(UnitImage);
                cell.transform.SetParent(Parent);
                Image i = cell.GetComponent <Image>();
                i.sprite = UnitImageManager.GetRankImage(rank);
            }
        }
        //Generate the attacker rows
        foreach (UnitRank attacker in Enum.GetValues(typeof(UnitRank)))
        {
            if (!attacker.Equals(UnitRank.Unknown))
            {
                //Generate attacker cell
                GameObject cell = Instantiate(UnitImage);
                cell.transform.SetParent(Parent);
                Image i = cell.GetComponent <Image>();
                i.sprite = UnitImageManager.GetRankImage(attacker);
                //Iterate over possibles
                foreach (UnitRank rank in Enum.GetValues(typeof(UnitRank)))
                {
                    if (!rank.Equals(UnitRank.Unknown))
                    {
                        GameObject rCell = Instantiate(UnitImage);
                        rCell.transform.SetParent(Parent);
                        Image        ri     = rCell.GetComponent <Image>();
                        BattleResult result = UnitUtilities.ResolveBattle(attacker, rank);
                        switch (result)
                        {
                        case BattleResult.Success:
                        {
                            ri.sprite = check;
                            break;
                        }

                        case BattleResult.Fail:
                        {
                            ri.sprite = redx;
                            break;
                        }

                        case BattleResult.Split:
                        {
                            ri.sprite = split;
                            break;
                        }
                        }
                    }
                }
            }
        }
    }
Esempio n. 3
0
    public void AddPiece(BoardPosition position, UnitRank rank)
    {
        //Check for existing piece, remove it if needed.
        //Debug.Log("atteming to add " + UnitUtilities.ReadableRank(rank) + " at " + position.ToString());
        bool equal = false;

        if (pieces.ContainsKey(position))
        {
            UnitPiece existing;
            if (pieces.TryGetValue(position, out existing))
            {
                if (existing.Rank.Equals(rank))
                {
                    //We're not going to remove then add the same exact piece to the same position
                    equal = true;
                }
                else
                {
                    RemovePiece(position);
                }
            }
        }
        if (!equal)
        {
            Transform target = BoardManager.GetTransformForPosition(position);
            if (!EqualityComparer <Transform> .Default.Equals(target, default(Transform)))
            {
                GameObject plane = Instantiate(UnitPlane);
                UnitPiece  piece = GeneratePiece(rank, plane);
                if (piece.Owner != null)
                {
                    piece.Piece.transform.SetParent(piece.Owner.Holder.transform);
                    plane.name  = UnitUtilities.ReadableRank(rank);
                    plane.layer = LayerMask.NameToLayer("Pieces");
                    Vector3 planePos = target.position;
                    planePos.z = GOLayer.UNIT_LAYER;
                    plane.transform.position = planePos;
                    Renderer r = plane.GetComponent <Renderer>();
                    r.material = MaterialManager.GetRankMaterial(rank);
                    pieces.Add(position, piece);
                    EventManager.Raise(new UnitPlacedEvent(position, piece));
                }
                else
                {
                    piece.Destroy();
                    Destroy(plane);
                }
            }
        }
    }
Esempio n. 4
0
    public void HandleBattle(UnitPiece attacker, BoardPosition attackerPosition, UnitPiece defender, BoardPosition defenderPosition)
    {
        BattleResult result = UnitUtilities.ResolveBattle(attacker.Rank, defender.Rank);

        // Based on result, update players
        switch (result)
        {
        case BattleResult.Success:
        {
            // Remove from defender owner
            defender.Owner.Pieces.Remove(defender);
            break;
        }

        case BattleResult.Fail:
        {
            // Remove from attacker owner
            attacker.Owner.Pieces.Remove(attacker);
            break;
        }

        case BattleResult.Split:
        {
            //Remove both
            attacker.Owner.Pieces.Remove(attacker);
            defender.Owner.Pieces.Remove(defender);
            break;
        }

        default:
        {
            break;
        }
        }
        EventManager.Raise(new UnitBattleResultEvent(attacker, defender, attackerPosition, defenderPosition, result));
        turnComplete = true;
    }