Ejemplo n.º 1
0
    void ConstructUnitDatabase()
    {
        for (int i = 0; i < unitData.Count; i++)
        {
            UnitVariables newUnit = gameObject.AddComponent <UnitVariables> ();
            newUnit.SetUnitVariables(unitData[i]["name"].ToString(), (int)unitData[i]["hp"], (int)unitData[i]["ap"],
                                     (int)unitData[i]["initiative"], (int)unitData[i]["id"], unitData[i]["weapon"].ToString(),
                                     unitData[i]["armor"].ToString());

            unitDatabase.Add(newUnit);
        }
    }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     // Add some basic unit variables into list
     for (int i = 0; i < 4; ++i)
     {
         //Gathers the name from the Unit Variable
         UnitVariables Stats = PlayerPrefab.GetComponent <UnitVariables> ();
         //Gathers the stats from the Json File
         Stats.Copy(UnitDatabase.Instance.FetchUnitByName(Stats.Name));
         ListOfUnitVariables.Add(Stats);
     }
 }
Ejemplo n.º 3
0
    // Update Unit Info Window for all units - Text values
    public void UpdateOpponentUnitInfo(UnitVariables OpponentStats)
    {
        // Get the end button gameobject
        Transform OpponentUnitInfoWindow = OpponentUnitInfoObject.transform.GetChild(0).transform;

        // Update values inside Unit Infor Window

        // Name
        Text Name = OpponentUnitInfoWindow.Find("Name variable").GetChild(0).GetComponent <Text>();

        Name.text = OpponentStats.Name.ToString();

        // HP
        Text HP = OpponentUnitInfoWindow.Find("HP variable").GetChild(0).GetComponent <Text>();

        HP.text = OpponentStats.HP.ToString();

        // AP
        Text AP = OpponentUnitInfoWindow.Find("AP variable").GetChild(0).GetComponent <Text>();

        AP.text = OpponentStats.AP.ToString();

        // Weapon
        Text WeaponT = OpponentUnitInfoWindow.Find("Weapon variable").GetChild(0).GetComponent <Text>();

        if (OpponentStats._weapon == null)
        {
            WeaponT.text = "";
        }
        else
        {
            WeaponT.text = OpponentStats._weapon.Title;
        }
        Image WeaponI = OpponentUnitInfoWindow.Find("Weapon variable").GetChild(1).GetComponent <Image>();

        WeaponI.sprite = Resources.Load <Sprite>("Sprite/Items/Weapons/" + OpponentStats._weapon.Icon);

        // Armor
        Text ArmorT = OpponentUnitInfoWindow.Find("Armor variable").GetChild(0).GetComponent <Text>();

        if (OpponentStats._armor == null)
        {
            ArmorT.text = "";
        }
        else
        {
            ArmorT.text = OpponentStats._armor.Title;
        }
        Image ArmorI = OpponentUnitInfoWindow.Find("Armor variable").GetChild(1).GetComponent <Image>();

        ArmorI.sprite = Resources.Load <Sprite>("Sprite/Items/Armors/" + OpponentStats._armor.Icon);
    }
Ejemplo n.º 4
0
    public void Copy(UnitVariables RealStats)
    {
        this.Name       = RealStats.Name;
        this.HP         = RealStats.HP;
        this.AP         = RealStats.AP;
        this.Initiative = RealStats.Initiative;
        this.ID         = RealStats.ID;
        this._weapon    = RealStats._weapon;
        this._armor     = RealStats._armor;

        this.startHP = RealStats.startHP;
        this.startAP = RealStats.startAP;
    }
Ejemplo n.º 5
0
    void Awake()
    {
        //		//Gathers the name from the Unit Variable
        Stats = this.gameObject.GetComponent <UnitVariables>();
        //		//Gathers the stats from the Json File
        Stats.Copy(UnitDatabase.Instance.FetchUnitByName(PlayerUnitVariables.Instance.GetListVariables()[PlayerManager.Instance.GetPlayerCount()].Name));
        // Code Optimising - Get Renderer Component once only
        rend         = GetComponent <Renderer>();
        DefaultColor = rend.material.color;
        // Code Optimising - Get UnitManager instance once only
        turnManager = TurnManager.Instance;
        // Set a random initial position for unit
        currNode = GridSystem.Instance.GetNode(Random.Range(0, 9), Random.Range(0, 9));
        currNode.SetOccupied(this.gameObject);
        transform.position = new Vector3(currNode.transform.position.x, transform.position.y, currNode.transform.position.z);

        // Set Unit's ID
        ID = PlayerManager.Instance.GetPlayerCount();
        PlayerManager.Instance.SetPlayerCount(PlayerManager.Instance.GetPlayerCount() + 1);

        // Init the path
        path = new Stack <Nodes>();
    }
Ejemplo n.º 6
0
Archivo: AI.cs Proyecto: Maversnipe/SP4
    // Use this for initialization
    void Awake()
    {
        rend = GetComponent <Renderer> ();

        //Gathers the name from the Unit Variable
        Stats = this.gameObject.GetComponent <UnitVariables> ();
        //Gathers the stats from the Json File
        Stats.Copy(UnitDatabase.Instance.FetchUnitByName(Stats.Name));

        MaxAP = Stats.AP;

        // Set AI Unit's ID
        ID = AICount;
        ++AICount;

        // Set the AI starting Position & occupies the current node
        if (this.tag == "aiProtect")
        {
            currNode = GridSystem.Instance.GetNode(Random.Range(0, 9), Random.Range(0, 9));
        }
        else
        {
            currNode = GridSystem.Instance.GetNode(Random.Range(0, GridSystem.Instance.GetRows()), Random.Range(0, GridSystem.Instance.GetColumn()));
        }
        //currNode = GridSystem.Instance.GetNode(0,0);
        currNode.SetOccupied(this.gameObject);
        this.transform.position = currNode.transform.position;
        TargetMovement          = this.transform.position;

        nextNode = currNode;

        turnManager = TurnManager.Instance;
        GridRef     = GridSystem.Instance;

        Path_Set    = false;
        isAttacking = false;
    }
Ejemplo n.º 7
0
 public void SetStats(UnitVariables n_Stats)
 {
     Stats = n_Stats;
 }
Ejemplo n.º 8
0
Archivo: AI.cs Proyecto: Maversnipe/SP4
    void DefensiveAction()
    {
        if (EnemyTarget == null)
        {
            Nodes Temp = null;

            for (int x = 0; x < GridRef.GetRows(); ++x)
            {
                for (int z = 0; z < GridRef.GetColumn(); ++z)
                {
                    if (GridRef.GetNode(x, z).GetOccupied() != null && GridRef.GetNode(x, z).GetOccupied().tag == "PlayerUnit")
                    {
                        if (Temp != null)                           // Temp Magnitude is more than current grid magnitude, change Temp altogether
                        {
                            if ((Temp.GetOccupied().transform.position - currNode.transform.position).magnitude > (GridRef.GetNode(x, z).GetOccupied().transform.position - currNode.transform.position).magnitude)
                            {
                                Temp = GridRef.GetNode(x, z);
                            }
                        }
                        else                             // Sets the first reference of Temp
                        {
                            Temp = GridRef.GetNode(x, z);
                        }
                    }
                }
            }

            EnemyTarget = Temp;
        }
        else
        {
            if (!Path_Set)
            {
                SetDefensivePath(currNode, EnemyTarget);
                m_path.Dequeue();
                Path_Set = true;
            }
            else
            {
                if (!isAttacking)
                {
                    // Assigns a node while also removing the assigned node from the path
                    Nodes TempMove = currNode;
                    if (m_path.Count != 0)
                    {
                        TempMove = m_path.Dequeue();
                    }
                    else
                    {
                        turnManager.CalculateRestHeal(this.gameObject);
                    }

                    // If the next area is or isn't the enemy target, act accordingly
                    if (TempMove != EnemyTarget)
                    {
                        currNode.SetOccupiedNULL();
                        currNode = TempMove;
                        currNode.SetOccupied(this.gameObject);
                    }
                    else
                    {
                        isAttacking = true;
                        TempMove.SetSelectable(false);
                        int damageDeal = turnManager.CalculateDamage(this.gameObject, EnemyTarget.GetOccupied());
                        EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().HP -= damageDeal;
                        if (EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().HP <= 0)
                        {
                            EnemyTarget = null;
                        }
                    }
                }
                else
                {
                    // prevent error - if player died
                    if (EnemyTarget.GetOccupied() == null)
                    {
                        EnemyTarget = null;
                        return;
                    }

                    UnitVariables Temp       = EnemyTarget.GetOccupied().GetComponent <Players> ().GetStats();
                    int           damageDeal = turnManager.CalculateDamage(this.gameObject, EnemyTarget.GetOccupied());
                    Temp.HP -= damageDeal;
                    EnemyTarget.GetOccupied().GetComponent <Players> ().SetStats(Temp);
                    EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().UpdateHealthBar();
                    EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().UpdateUnitInfo();
                    if (EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().HP <= 0)
                    {
                        EnemyTarget = null;
                    }
                }
                this.Stats.AP--;
            }
        }
    }
Ejemplo n.º 9
0
 public void SetUnitStats(UnitVariables _value)
 {
     m_Stats = _value;
 }