Beispiel #1
0
    public virtual bool TakeDamage(float damage)
    {
        if (damage > defence && (damage - defence) > 0)
        {
            health -= (damage - defence);
        }
        if (health < 0)
        {
            health = 0.0f;
        }

        Companion tComp = this.gameObject.GetComponent <Companion>();

        if (tComp != null)
        {
            HeaderUI      headerUI   = CanvasScript.instance.headerUI.GetComponent <HeaderUI>();
            RectTransform rTransform = headerUI.companionFills[tComp.id].rectTransform;
            float         lackAmount = 1 - this.health / this.maxHealth;
            headerUI.companionFills[tComp.id].transform.localPosition = new Vector3(-122.42f * lackAmount * 0.5f, 0.0f, 0.0f);
            rTransform.sizeDelta = new Vector2(122.42f * (1 - lackAmount), rTransform.sizeDelta.y);

            headerUI.companionIcons[tComp.id].sprite = tComp.actorIcon;
            // CanvasScript.instance.headerUI.GetComponent<HeaderUI>().companionSliders[tComp.id].normalizedValue = tComp.health / tComp.maxHealth;
        }
        else if (this == Character.instance)
        {
            HeaderUI      headerUI   = CanvasScript.instance.headerUI.GetComponent <HeaderUI>();
            RectTransform rTransform = headerUI.actorFill.rectTransform;
            float         lackAmount = 1 - this.health / this.maxHealth;
            headerUI.actorFill.transform.localPosition = new Vector3(-122.42f * lackAmount * 0.5f, 0.0f, 0.0f);
            rTransform.sizeDelta      = new Vector2(122.42f * (1 - lackAmount), rTransform.sizeDelta.y);
            headerUI.actorIcon.sprite = Character.instance.actorIcon;
            // CanvasScript.instance.headerUI.GetComponent<HeaderUI>().actorSlider.normalizedValue = Character.instance.health / 100.0f;
        }
        else
        {
            Mob           tMob       = this.gameObject.GetComponent <Mob>();
            RectTransform rTransform = tMob.healthBarFill.rectTransform;
            float         lackAmount = 1 - this.health / tMob.maxHealth;
            tMob.healthBarFill.transform.localPosition = new Vector3(-1 * lackAmount * 0.5f, 0.0f, 0.0f);
            rTransform.sizeDelta = new Vector2(1 - lackAmount, rTransform.sizeDelta.y);
        }

        return(false);
    }
Beispiel #2
0
    public void Regenerate(float regenerationValue, Potion.PotionType potType)
    {
        switch (potType)
        {
        case Potion.PotionType.HEALTH:
            this.health = Mathf.Clamp(health + regenerationValue, 0f, this.maxHealth);
            Companion tComp = this.gameObject.GetComponent <Companion>();
            if (tComp != null)
            {
                HeaderUI      headerUI   = CanvasScript.instance.headerUI.GetComponent <HeaderUI>();
                RectTransform rTransform = headerUI.companionFills[tComp.id].rectTransform;
                float         lackAmount = 1 - this.health / this.maxHealth;
                headerUI.companionFills[tComp.id].transform.localPosition = new Vector3(-122.42f * lackAmount * 0.5f, 0.0f, 0.0f);
                rTransform.sizeDelta = new Vector2(122.42f * (1 - lackAmount), rTransform.sizeDelta.y);
                headerUI.companionIcons[tComp.id].sprite = tComp.actorIcon;
            }
            else if (this == Character.instance)
            {
                HeaderUI      headerUI   = CanvasScript.instance.headerUI.GetComponent <HeaderUI>();
                RectTransform rTransform = headerUI.actorFill.rectTransform;
                float         lackAmount = 1 - this.health / this.maxHealth;
                headerUI.actorFill.transform.localPosition = new Vector3(-122.42f * lackAmount * 0.5f, 0.0f, 0.0f);
                rTransform.sizeDelta      = new Vector2(122.42f * (1 - lackAmount), rTransform.sizeDelta.y);
                headerUI.actorIcon.sprite = Character.instance.actorIcon;
                if (CanvasScript.instance.characterPanel.activeInHierarchy)
                {
                    CanvasScript.instance.characterPanel.GetComponent <CharacterStats>().health.text = "Health: " + this.health;
                }
            }
            break;

        case Potion.PotionType.MANA:
            break;

        case Potion.PotionType.STAMINA:
            break;

        default:
            break;
        }
    }
    // Start is called before the first frame update
    protected override void Awake()
    {
        base.Awake();
        id = idCounter++;
        Companion tComp   = this.gameObject.GetComponent <Companion>();
        HeaderUI  tHeader = CanvasScript.instance.headerUI.GetComponent <HeaderUI>();

        tHeader.companionIcons[tComp.id].gameObject.SetActive(true);
        // tHeader.companionFills[tComp.id].gameObject.SetActive(true);
        tHeader.images[tComp.id].gameObject.SetActive(true);
        tHeader.companionIcons[tComp.id].sprite = tComp.actorIcon;
        // tHeader.companionFills[tComp.id].normalizedValue = tComp.health / this.maxHealth;

        detector = GetComponentInChildren <SpotEnemy>();

        this.actorType = NPC.ActorType.COMPANION;
        typesToTarget.Add(NPC.ActorType.MOB);

        AttackAreaDamage temp = hitPoint.GetComponent <AttackAreaDamage>();

        temp.damage = this.damage;
        this.SetState(new IdleState(this.gameObject));
    }