public void UpdateValues()
    {
        var textChildren = GetComponentsInChildren <TextMeshProUGUI>();

        textChildren[0].text = _defender.GetComponent <Health>().GetHealth.ToString();

        textChildren[4].text = _defender.GetPowerCost().ToString() + "P";
        textChildren[5].text = _defender.GetMoneyCost().ToString() + "M";

        var shooter = _defender.GetComponent <Shooter>();
        var plane   = _defender.isPlane;

        if (shooter)
        {
            textChildren[2].text = shooter.GetProjectileDamage().ToString();
        }
        else if (plane)
        {
            textChildren[0].text = "";
            textChildren[1].text = "";
            textChildren[2].text = _defender.GetComponent <Plane>().GetBombDamage.ToString();

            _movePrefab(textChildren[2]);
            _movePrefab(textChildren[3]);
        }
        else
        {
            textChildren[2].text = _defender.GetComponent <Exploder>().GetDamage.ToString();
        }
    }
Exemplo n.º 2
0
 void OnMouseDown()
 {
     if (FindObjectOfType <StarDisplay>().CurrentStars() >= defenderPrefab.GetComponent <Defender>().GetStarsCost() /*&& canPlant == true*/)//nếu số tiền trên bảng điểm nhiều hơn hoặc bằng số tiền của defender thì sẽ kích hoạt
     {
         sounds[0].Play();
         FindObjectOfType <DefenderSpawner>().SetSelectedDefender(defenderPrefab);
         //canPlant = false;
         //StartCoroutine(WaitTime());
     }
     else if (FindObjectOfType <StarDisplay>().CurrentStars() < defenderPrefab.GetComponent <Defender>().GetStarsCost() /*|| canPlant == false*/)
     {
         sounds[1].Play();
     }
 }
Exemplo n.º 3
0
	// Use this for initialization
	void Start () {
		myDefender = FindObjectOfType<Defender>();
		myHealth = myDefender.GetComponent<Health>();
		myAudioSource = myDefender.GetComponent<AudioSource>();
		if(!myAudioSource) {
			myAudioSource = myDefender.gameObject.AddComponent<AudioSource>();
		}
		
		
		myText = transform.parent.GetComponentInChildren<Text>();
		myText.text = " ";
		barLevel = Status.LEVEL0;
		damageCounter = 0;
		
		playerHealthBar = FindObjectOfType<HealthBar>();
	}
Exemplo n.º 4
0
        public override void Execute()
        {
            base.Execute();

            Health defenderHealth = Defender.GetComponent <Health>();

            defenderHealth.Hurt(DamageDealt);
        }
Exemplo n.º 5
0
 public void DoAttack(float damage)
 {
     if (!currentTarget)
     {
         return;
     }
     currentTarget.GetComponent <Health>().DealDamage(damage);
 }
Exemplo n.º 6
0
 public void Attack()
 {
     if (defender == null)
     {
         return;
     }
     defender.GetComponent <Health>().TakeHealth(damage);
 }
Exemplo n.º 7
0
 protected IEnumerator Atacking(Defender defender)
 {
     while (defender)
     {
         defender.GetComponent <Health>().TakeHealth(damage);
         yield return(new WaitForSeconds(AttackPeriodTime));
     }
 }
Exemplo n.º 8
0
    protected void StrikeCurrentTarget()
    {
        if (!currentTarget)
        {
            return;
        }

        currentTarget.GetComponent <Health>().DealDamage(damage);
    }
Exemplo n.º 9
0
    private Vector2 SnapToGrid(Vector2 worldPos)
    {
        Vector2 offset = _defenderPrefab.GetComponent <Entity>().offset;

        float gridX = Mathf.RoundToInt(worldPos.x) + offset.x;
        float gridY = Mathf.RoundToInt(worldPos.y) + offset.y;

        return(new Vector2(gridX, gridY));
    }
Exemplo n.º 10
0
    private void OnMouseDown()
    {
        Defender selectedDefender = FindObjectOfType <DefenderSpawner>().defender;

        if (selectedDefender.GetComponent <Scissors>())
        {
            Defender scissors = Instantiate(selectedDefender, transform.position, transform.rotation) as Defender; //we are calling a method which will return the position that will feed into first called method
        }
    }
Exemplo n.º 11
0
    private void SpawnDefender(Vector2 worldPos)
    {
        Defender newDefender = Instantiate(defender, worldPos, Quaternion.identity) as Defender;
        Shooter  shooter     = newDefender.GetComponent <Shooter>();

        if (shooter != null)
        {
            shooter.SetLane(worldPos.y);
        }
    }
    private void SpawnDefender()
    {
        var defenderCost = defender.GetComponent <Defender>().GetStarsCost();

        if (starsDisplay.GetStars() >= defenderCost)
        {
            var pos         = GetSquareClicked();
            var newDefender = Instantiate(defender, new Vector2(Mathf.Round(pos.x), Mathf.Round(pos.y)), Quaternion.identity, defendersParent.transform);
            starsDisplay.ReduceStars(defenderCost);
        }
    }
Exemplo n.º 13
0
        public override void Undo()
        {
            base.Undo();

            Health defenderHealth = Defender.GetComponent <Health>();

            if (defenderHealth != null)
            {
                defenderHealth.Heal(DamageDealt);
            }
        }
Exemplo n.º 14
0
    public void AttackTarget()
    {
        if (!target)
        {
            ToggleWalk();
            animator.SetBool("doAttack", false);

            return;
        }

        target.GetComponent <Health>().DecHealth(damage);
    }
Exemplo n.º 15
0
    protected override void SetBehevior(Defender defender)
    {
        var grave = defender.GetComponent <Grave>();

        if (grave)
        {
            Jump();
        }
        else
        {
            Attack(defender);
        }
    }
Exemplo n.º 16
0
    //Called from animation attacking. Damage set within event
    public void StrikeCurrentTarget(float damage)
    {
        Health health = currentTarget.GetComponent <Health>();

        if (health)
        {
            health.TakeDamage(damage);
        }
        else
        {
            return;
        }
    }
Exemplo n.º 17
0
    public void StrikeCurrentTarget(float damage)
    {
        if (!currentTarget)
        {
            return;
        }

        Health health = currentTarget.GetComponent <Health>();

        if (health)
        {
            health.DealDamage(damage);
        }
    }
Exemplo n.º 18
0
    public void StrikeCurrentTarget(float damage)
    {
        if (!currentTarget)
        {
            return;
        }

        Health health = currentTarget.GetComponent <Health>();

        if (health)
        {
            // increase damage by 10 % per difficulty
            damage += Mathf.Round((float)(damage * 0.1 * PlayerPrefsController.GetDifficulty()));
            health.DealDamage(damage);
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Defender defender = collision.gameObject.GetComponent <Defender>();

        if (defender)
        {
            if (defender.GetComponent <Gravestone>())
            {
                GetComponent <Animator>().SetTrigger("Jump");
            }
            else
            {
                GetComponent <Attacker>().RespondToThreat(defender.gameObject);
            }
        }
    }
Exemplo n.º 20
0
 private void Start()
 {
     foreach (Transform child in transform)
     {
         if (child.name == "Text")
         {
             if (defenderPrefab)
             {
                 child.GetComponent <Text>().text = defenderPrefab.GetComponent <Defender>().GetCoinCost().ToString();
             }
             else
             {
                 child.GetComponent <Text>().text = "";
             }
         }
     }
 }
    private void SpawnDefender(Vector2 roundedPosition)
    {
        //Vector3 rotationVector = new Vector3(0, -180, 0);
        //GameObject newDefender = Instantiate(defender, roundedPosition, Quaternion.Euler(rotationVector)) as GameObject; //as GO so that we can see it in our hierarchy
        if (defender.GetComponent <Scissors>())
        {
            { return; }
        }
        else
        {
            Defender newDefender = Instantiate(defender, roundedPosition, transform.rotation) as Defender; //as GO so that we can see it in our hierarchy
            newDefender.transform.parent = defenderParent.transform;
            Debug.Log("I spawned");
        }

        //Debug.Log(roundedPosition);
    }
Exemplo n.º 22
0
        public void UpdateProperties(Defender defender)
        {
            var handleObject = defender.GetComponent <HandleObject>();

            DamagePrice.text   = defender.Damage < defender.MaxDamage ? handleObject.DamagePrice.ToString("F0") : "Maxed";
            CooldownPrice.text = defender.Cooldown > defender.MinCooldown? handleObject.CooldownPrice.ToString("F0") : "Maxed";
            SellPrice.text     = ((uint)(defender.Damage / defender.Cooldown) * 10).ToString();

            if (Targer == defender)
            {
                return;
            }
            Targer = defender;
            RemoveListeners();
            UpgradeDamage.onClick.AddListener(() => handleObject.Upgrade(UpgradeType.Damage));
            UpgradeCooldown.onClick.AddListener(() => handleObject.Upgrade(UpgradeType.Cooldown));
            Sell.onClick.AddListener(() => handleObject.Sell());
        }
Exemplo n.º 23
0
    private void OnTriggerEnter2D(Collider2D otherCollider)
    {
        GameObject otherObject = otherCollider.gameObject;


        Defender possibleDefender = otherObject.GetComponent <Defender>();

        if (possibleDefender)
        {
            if (possibleDefender.GetComponent <GravestoneBehavior>())
            {
                GetComponent <Animator>().SetTrigger("JumpTrigger");
            }
            else
            {
                StartCoroutine(GetComponent <Attacker>().Attack(possibleDefender));
            }
        }
    }// end of method OnTriggerEnter2D
Exemplo n.º 24
0
    public override void OnEnter()
    {
        HeroShelf.Hide();
        EnemyShelf.Hide();

        TweenCatcher.SetActive(true);
        Attacker = CombatManager.Instance.Attacker.DiceObject.transform;
        Defender = CombatManager.Instance.Defender.DiceObject.transform;

        AttackersRB = Attacker.GetComponent <Rigidbody>();
        DefendersRB = Defender.GetComponent <Rigidbody>();

        AttackersBC = Attacker.GetComponent <BoxCollider>();
        DefendersBC = Defender.GetComponent <BoxCollider>();

        AttackersRB.isKinematic = true;
        DefendersRB.isKinematic = true;

        AttackersBC.isTrigger = true;
        DefendersBC.isTrigger = true;

        AttackersRest = Attacker.GetComponent <CheckForNonCollision>().RestPosition;
        DefendersRest = Defender.GetComponent <CheckForNonCollision>().RestPosition;

        if (Attacker.Equals(Defender))
        {
            Attacker.DOMove(SinglePosition.position, .5f).OnComplete(HandleSelfHeal);
        }
        else if (CombatManager.Instance.Attacker.UpSide.Ability.TargetType == ETargetType.Enemy)
        {
            Attacker.DOMove(AttackerPosition.position, .5f);
            Defender.DOMove(DefenderPosition.position, .5f).OnComplete(StartAttack);
        }
        else
        {
            Attacker.DOMove(AttackerPosition.position, .5f);
            Defender.DOMove(DefenderPosition.position, .5f).OnComplete(StartHeal);
        }
    }
Exemplo n.º 25
0
 public void SetSelectedDefender(Defender defenderToSelect)
 {
     defenderPrefab = defenderToSelect;
     int defenderCost = defenderPrefab.GetComponent <Defender>().GetDefenderCost();
 }
Exemplo n.º 26
0
 private void Start()
 {
     starCostText      = GetComponentInChildren <TextMeshProUGUI>();
     starCostText.text = defenderPrefab.GetComponent <Defender>().GetStarCost().ToString();
 }
Exemplo n.º 27
0
    void CreateSquadTooltip(Squad squad, Vector2 pos)
    {
        Reset();

        if (squad.transform.Find("Units").childCount > 0)
        {
            unit = squad.transform.Find("Units").GetChild(0).GetComponent <Defender>();
        }

        if (squad.transform.Find("Leader").childCount > 0)
        {
            leader = squad.transform.Find("Leader").GetChild(0).GetComponent <Defender>();
        }

        if (leader != null)
        {
            leaderHealth  = leader.GetComponent <Health>();
            leaderShooter = leader.GetComponent <Shooter>();
        }

        if (unit != null)
        {
            unitHealth  = unit.GetComponent <Health>();
            unitShooter = unit.GetComponent <Shooter>();
        }

        stringBuilder.Append("<b><size=24>" + squad.name + "</size></b>\n\n");

        stringBuilder.Append(squad.description + "\n\n");

        stringBuilder.Append("<b>Cost:</b> " + squad.GetGoldCost().ToString() + " Gold, " + squad.GetSuppliesCost().ToString() + " Supplies\n\n");

        if (squad.GetShootRange() > 0)
        {
            if (squad.squadType == SquadType.Archers)
            {
                stringBuilder.Append("<b>Shoot Range:</b> ");
            }
            else if (squad.squadType == SquadType.Spearmen)
            {
                stringBuilder.Append("<b>Throw Range:</b> ");
            }
            else if (squad.squadType == SquadType.Priests)
            {
                stringBuilder.Append("<b>Heal Range:</b> ");
            }
            else
            {
                Debug.LogError("Squad type not accounted for in order to show the shoot/throw range in the squad's tooltip. Fix me!");
            }

            stringBuilder.Append(squad.GetShootRange().ToString() + "\n\n");
        }

        if (unit != null)
        {
            stringBuilder.Append("<b>Unit Stats:</b>\n");
            stringBuilder.Append("Health: " + (unitHealth.GetMaxHealth() + squadData.GetHealthData(squad.squadType, false)).ToString() + "\n");

            if (unit.bluntDamage > 0f || unit.slashDamage > 0f || unit.piercingDamage > 0f || unit.fireDamage > 0f)
            {
                if (unit.bluntDamage > 0f)
                {
                    stringBuilder.Append("Melee <i>Blunt</i> Damage: " + (unit.bluntDamage + squadData.GetBluntDamageData(squad.squadType, false)).ToString() + "\n");
                }

                if (unit.slashDamage > 0f)
                {
                    stringBuilder.Append("Melee <i>Slash</i> Damage: " + (unit.slashDamage + squadData.GetSlashDamageData(squad.squadType, false)).ToString() + "\n");
                }

                if (unit.piercingDamage > 0f)
                {
                    stringBuilder.Append("Melee <i>Piercing</i> Damage: " + (unit.piercingDamage + squadData.GetPiercingDamageData(squad.squadType, false)).ToString() + "\n");
                }

                if (unit.fireDamage > 0f)
                {
                    stringBuilder.Append("Melee <i>Fire</i> Damage: " + (unit.fireDamage + squadData.GetFireDamageData(squad.squadType, false)).ToString() + "\n");
                }
            }

            if (unitShooter != null && (unitShooter.bluntDamage > 0f || unitShooter.piercingDamage > 0f || unitShooter.fireDamage > 0f))
            {
                if (unitShooter.bluntDamage > 0f)
                {
                    stringBuilder.Append("Ranged <i>Blunt</i> Damage: " + (unitShooter.bluntDamage + squadData.GetRangedBluntDamageData(squad.squadType, false)).ToString() + "\n");
                }

                if (unitShooter.piercingDamage > 0f)
                {
                    stringBuilder.Append("Ranged <i>Piercing</i> Damage: " + (unitShooter.piercingDamage + squadData.GetRangedPiercingDamageData(squad.squadType, false)).ToString() + "\n");
                }

                if (unitShooter.fireDamage > 0f)
                {
                    stringBuilder.Append("Ranged <i>Fire</i> Damage: " + (unitShooter.fireDamage + squadData.GetRangedFireDamageData(squad.squadType, false)).ToString() + "\n");
                }

                stringBuilder.Append("Ranged Accuracy: " + (unitShooter.accuracy + squadData.GetRangedAccuracyData(squad.squadType, false)).ToString() + "%\n");
            }
        }

        if (leader != null)
        {
            stringBuilder.Append("\n<b>Leader Stats:</b>\n");
            stringBuilder.Append("Health: " + (leaderHealth.GetMaxHealth() + squadData.GetHealthData(squad.squadType, true)).ToString() + "\n");

            if (leader.bluntDamage > 0f || leader.slashDamage > 0f || leader.piercingDamage > 0f || leader.fireDamage > 0f)
            {
                if (leader.bluntDamage > 0)
                {
                    stringBuilder.Append("Melee <i>Blunt</i> Damage: " + (leader.bluntDamage + squadData.GetBluntDamageData(squad.squadType, true)).ToString() + "\n");
                }

                if (leader.slashDamage > 0)
                {
                    stringBuilder.Append("Melee <i>Slash</i> Damage: " + (leader.slashDamage + squadData.GetSlashDamageData(squad.squadType, true)).ToString() + "\n");
                }

                if (leader.piercingDamage > 0)
                {
                    stringBuilder.Append("Melee <i>Piercing</i> Damage: " + (leader.piercingDamage + squadData.GetPiercingDamageData(squad.squadType, true)).ToString() + "\n");
                }

                if (leader.fireDamage > 0)
                {
                    stringBuilder.Append("Melee <i>Fire</i> Damage: " + (leader.fireDamage + squadData.GetFireDamageData(squad.squadType, true)).ToString() + "\n");
                }
            }

            if (leaderShooter != null && (leaderShooter.bluntDamage > 0f || leaderShooter.piercingDamage > 0f || leaderShooter.fireDamage > 0f))
            {
                if (leaderShooter.bluntDamage > 0f)
                {
                    stringBuilder.Append("Ranged <i>Blunt</i> Damage: " + (leaderShooter.bluntDamage + squadData.GetRangedBluntDamageData(squad.squadType, true)).ToString() + "\n");
                }

                if (leaderShooter.piercingDamage > 0f)
                {
                    stringBuilder.Append("Ranged <i>Piercing</i> Damage: " + (leaderShooter.piercingDamage + squadData.GetRangedPiercingDamageData(squad.squadType, true)).ToString() + "\n");
                }

                if (leaderShooter.fireDamage > 0f)
                {
                    stringBuilder.Append("Ranged <i>Fire</i> Damage: " + (leaderShooter.fireDamage + squadData.GetRangedFireDamageData(squad.squadType, true)).ToString() + "\n");
                }

                stringBuilder.Append("Ranged Accuracy: " + (leaderShooter.accuracy + squadData.GetRangedAccuracyData(squad.squadType, true)).ToString() + "%\n");
            }
        }

        stringBuilder.Append("\n<b>Resistances:</b>\n");
        if (unitHealth != null)
        {
            stringBuilder.Append("Blunt: " + (unitHealth.bluntResistance * 100).ToString() + "%\n");
            stringBuilder.Append("Piercing: " + (unitHealth.piercingResistance * 100).ToString() + "%\n");
            stringBuilder.Append("Slash: " + (unitHealth.slashResistance * 100).ToString() + "%\n");
            stringBuilder.Append("Fire: " + (unitHealth.fireResistance * 100).ToString() + "%");
        }
        else if (leaderHealth != null)
        {
            stringBuilder.Append("Blunt: " + (leaderHealth.bluntResistance * 100).ToString() + "%\n");
            stringBuilder.Append("Piercing: " + (leaderHealth.piercingResistance * 100).ToString() + "%\n");
            stringBuilder.Append("Slash: " + (leaderHealth.slashResistance * 100).ToString() + "%\n");
            stringBuilder.Append("Fire: " + (leaderHealth.fireResistance * 100).ToString() + "%");
        }

        tooltipText.text = stringBuilder.ToString();

        SetBackgroundSize();
        transform.position = pos + new Vector2(-0.15f, 0.5f);
    }
    private void LabelButtonWithCost()
    {
        Text costText = GetComponentInChildren <Text>();

        costText.text = defenderPrefab.GetComponent <Defender>().GetStarCost().ToString();
    }
Exemplo n.º 29
0
    public void UpdateValues()
    {
        var textChildren = GetComponentsInChildren <TextMeshProUGUI>();

        if (_controlTower)
        {
            textChildren[0].text = _controlTower.GetHealth < 1 ? "--" : _controlTower.GetHealth.ToString();

            if (_controlTower.IsFixable)
            {
                textChildren[2].text = "";
                textChildren[3].text = "";
                textChildren[4].text = "";
                textChildren[5].text = "";

                textChildren[6].text = _controlTower.PowerCost.ToString() + "P";
                textChildren[7].text = _controlTower.MoneyCost.ToString() + "M";

                textChildren[8].text = "FIX";
            }
            else if (_controlTower.IsActive)
            {
                textChildren[2].text = "+" + _currencyController.GetControlTowerMoneyAffordance;
                textChildren[3].text = "POWER";
                textChildren[4].text = "+" + _currencyController.GetControlTowerPowerAffordance;
                textChildren[5].text = "MONEY";

                textChildren[6].text = "";
                textChildren[7].text = "";
                textChildren[8].text = "";
            }
            else     // dead
            {
                textChildren[2].text = "";
                textChildren[3].text = "";
                textChildren[4].text = "";
                textChildren[5].text = "";
                textChildren[6].text = "";
                textChildren[7].text = "";
                textChildren[8].text = "";
            }
        }
        else     // Currency Button
        {
            textChildren[0].text = _defender.GetComponent <Health>().GetHealth.ToString();

            var currencyProducer = FindObjectOfType <InfoController>().GetDefenderFromButton().GetComponent <CurrencyProducer>();

            // currency producer does not belong to button -- find boolean IsPower another way

            textChildren[2].text = currencyProducer.IsPower
                ? "+" + _currencyController.GetPowerAffordance
                : "+" + _currencyController.GetMoneyAffordance;
            textChildren[3].text = currencyProducer.IsPower ? "POWER" : "MONEY";

            // Second line of affordances
            textChildren[4].text = textChildren[5].text = "";

            textChildren[6].text = _defender.GetPowerCost() + "P";
            textChildren[7].text = _defender.GetMoneyCost() + "M";

            textChildren[8].text = "";
        }
    }