public void loadCharacter(unitScript u, bool ally = true)
    {
        if (ally)
        {
            unit = u;
        }
        Transform characterPanel = transform;
        Transform statPannel     = characterPanel.Find(ally?"StatPanel":"EnemyStatPanel");

        UnityEngine.UI.Text nameText = statPannel.Find("Name").GetComponent <UnityEngine.UI.Text>();
        nameText.text = u.getName();

        statPannel.FindChild("Image").GetComponent <Image>().sprite = u.getPortrait();

        var strengthText = statPannel.Find("Strength").GetComponent <UnityEngine.UI.Text>();

        strengthText.text = u.getStrength().ToString();

        var skillText = statPannel.Find("Skill").GetComponent <UnityEngine.UI.Text>();

        skillText.text = u.getSkill().ToString();

        var speedText = statPannel.Find("Speed").GetComponent <UnityEngine.UI.Text>();

        speedText.text = u.getSpeed().ToString();

        var smartsText = statPannel.Find("Smarts").GetComponent <UnityEngine.UI.Text>();

        smartsText.text = u.getSmarts().ToString();

        loadHealth(u.getHealth(), u.getMaxHealth(), statPannel);

        if (ally)
        {
            if (unit.doorsWithinRange.Count > 0)
            {
                transform.FindChild("CharacterPanel").FindChild("DoorButton").GetComponent <Button>().interactable = true;
            }
            else
            {
                transform.FindChild("CharacterPanel").FindChild("DoorButton").GetComponent <Button>().interactable = false;
            }
        }

        loadWeaponData(u, ally);
    }
Пример #2
0
    protected bool MeleeAttack(unitScript unit, unitScript clickedUnit, bool initialAttack = true)
    {
        // Check attack can occur
        if (unit.getCurrentWeapon().type == WeaponType.ranged || unit == null || clickedUnit == null)
        {
            return(false);
        }

        float distance = Vector2.Distance(unit.GetComponent <GridItem>().getPos(), clickedUnit.GetComponent <GridItem>().getPos());

        if (!(unit.getCurrentWeapon().type == WeaponType.melee) || distance > ((MeleeWeapon)unit.getCurrentWeapon()).range)
        {
            return(false);
        }

        // Given it can roll the dice
        float roll = UnityEngine.Random.Range(0.0f, 1.0f);

        float chanceToHit = meleeChanceToHit(unit, clickedUnit);

        print(roll + " " + chanceToHit);
        if (roll < chanceToHit)
        {
            clickedUnit.takeDamage(unit.getStrength() + unit.getCurrentWeapon().damage);
        }
        else
        {
            clickedUnit.displayMiss();
        }
        unit.activateAttack();
        if (initialAttack && clickedUnit.getStrikeback() == false)
        {
            bool result = MeleeAttack(clickedUnit, unit, false);
            if (result)
            {
                clickedUnit.useStrikeback();
            }
        }
        return(true);
    }