Ejemplo n.º 1
0
    public void AttackTarget(Transform target)
    {
        IHaveStrength _myStats = GetComponent <IHaveStrength>();

        if (_myStats != null)
        {
            if (!isAttacking)
            {
                isAttacking = true;
                StartCoroutine(AttackCooldown());

                IHaveHealth _stats = target.GetComponent <IHaveHealth>();
                if (_stats != null)
                {
                    if (_stats.Health > 0)
                    {
                        //Do damage
                        IDamagable _takeDamage = target.GetComponent <IDamagable>();
                        if (_takeDamage != null)
                        {
                            _takeDamage.ITakeDamage(_myStats.Strength, _stats);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    private void Awake()
    {
        this.gameObject.SetActive(true);
        boxCollider2D.isTrigger = true;
        parent = GetComponentInParent <Actor>();
        Debug.Log("The parent is: " + parent.name);

        //reference to the current health of the parent object's IHaveHealth Health property
        healthAmount = GetComponentInParent <IHaveHealth>();
    }
Ejemplo n.º 3
0
    public void SendDamageMessage(GameObject obj, int shooterID)
    {
        int         id            = _players.IndexOf(obj);
        IHaveHealth health        = _players[id].GetComponent(typeof(IHaveHealth)) as IHaveHealth;
        float       currentHealth = health.GetHealth();

        string s = SerializationScript.SerializePlayerHealth(id, currentHealth, shooterID);

        SendData(s, 1, true);
    }
Ejemplo n.º 4
0
    public void SetUp(HeadPlacement h, Transform p, IHaveHealth ph)
    {
        transform.position   = p.transform.position + h.Offset;
        transform.localScale = h.ScaleValues;
        transform.SetParent(p);

        gameObject.AddComponent <SphereCollider>();

        parent       = p;
        parentHealth = ph;
    }
Ejemplo n.º 5
0
    protected override void Deactivate()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, _radius);
        foreach (Collider item in colliders)
        {
            IHaveHealth temp = item.GetComponent <IHaveHealth>();
            if (temp != null)
            {
                temp.GetDamage(_damage);
            }
        }

        base.Deactivate();
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Update a players health based on a health pack (host)
    /// </summary>
    /// <param name="splitCode">The message data from the packets</param>
    internal void HealthPlayer(string[] splitCode)
    {
        int   id     = int.Parse(splitCode[1]);
        float health = float.Parse(splitCode[2]);

        IHaveHealth target = network.GetPlayerOfID(id).GetComponent(typeof(IHaveHealth)) as IHaveHealth;

        target.GainHealth(health);

        if (splitCode.Length >= 4)
        {
            int boxID = int.Parse(splitCode[3]);
            EventHealthPickUp(boxID);
        }
    }
Ejemplo n.º 7
0
    internal void UpdateHealth(string[] splitCode)
    {
        int id        = int.Parse(splitCode[1]);
        int shooterID = int.Parse(splitCode[3]);

        float       currentHealth = float.Parse(splitCode[2]);
        IHaveHealth target        = network.GetPlayerOfID(id).GetComponent(typeof(IHaveHealth)) as IHaveHealth;
        float       damage        = target.GetHealth() - currentHealth;

        target?.TakeDamage(damage, shooterID);

        if (shooterID * -1 == _myID)
        {
            target?.SimulateDamage(network.GetPlayerOfID(id).transform.position + Vector3.up, damage);
        }
    }
Ejemplo n.º 8
0
    // Start is called before the first frame update
    void Start()
    {
        if (haveHealth == null)
        {
            haveHealth = GetComponentInParent <IHaveHealth>();
        }
        //Looks for an event of OnHealthChanged in the IHaveHealth variable
        haveHealth.OnHealthChanged += HaveHealth_OnHealthChanged;

        if (image == null)
        {
            image = GetComponent <Image>();
        }

        //Changes the value of the slider to the value of the IHaveHealth variable
        image.fillAmount = haveHealth.Health / 100;
    }
Ejemplo n.º 9
0
    void Hunt()
    {
        if (_reach != null)
        {
            if (_nav.agent.remainingDistance <= _reach.Reach)
            {
                if (curTarget != null)
                {
                    IHaveHealth _health = curTarget.GetComponent <IHaveHealth>();
                    if (_health != null)
                    {
                        if (_health.Health > 0)
                        {
                            if (_attack != null)
                            {
                                _attack.AttackTarget(curTarget);
                            }
                        }
                        else
                        {
                            if (_harvest != null)
                            {
                                _harvest.HarvestTarget(curTarget);
                            }
                        }
                    }
                    else if (curTarget.GetComponent <IAmPlant>() != null)
                    {
                        //Harvest

                        if (_harvest != null)
                        {
                            _harvest.HarvestTarget(curTarget);
                        }
                    }
                }
                else
                {
                    isHunting = false;
                }
            }
        }
    }
Ejemplo n.º 10
0
 void UseAid(IHaveHealth health)
 {
     _healSystem.Heal(health, _value);
     SetEnable(false);
 }
Ejemplo n.º 11
0
 public void Heal(IHaveHealth health, int value)
 {
     health.Health.Value = Mathf.Clamp(health.Health.Value + value, 0, health.MaxHealth.Value);
 }
Ejemplo n.º 12
0
    /// <summary>
    /// Update the health of a player based on a health pack (client)
    /// </summary>
    /// <param name="id"> ID of the player to heal </param>
    /// <param name="health"> The amount to heal the player. </param>
    internal void HealthPlayer(int id, float health)
    {
        IHaveHealth target = network.GetPlayerOfID(id).GetComponent(typeof(IHaveHealth)) as IHaveHealth;

        target.GainHealth(health);
    }