public void MyUpdate()
    {
        Move();
        if (target == null)
        {
            return;
        }

        //get the distance between the chaser and the target
        float distance = Vector2.Distance(transform.position, target.position);

        //so long as the chaser is farther away than the minimum distance, move towards it at rate speed.
        if (distance < MINDIST)
        {
            HealthBehaviour health = target.GetComponent(typeof(HealthBehaviour)) as HealthBehaviour;
            DamageBehaviour damage = gameObject.GetComponent(typeof(DamageBehaviour)) as DamageBehaviour;
            if (health != null && damage != null)
            {
                if (!health.IsImmune)
                {
                    target.GetComponent <AudioSource>().Play();
                }
                health.ApplyDamage(damage.DamageAmount);
            }
        }

        if (target.position.x > transform.position.x && xMoveDirection < 0 ||
            target.position.x < transform.position.x && xMoveDirection > 0)
        {
            xMoveDirection *= -1;
        }
    }
Esempio n. 2
0
        //TODO: Remove this when atmos is implemented
        //This prevents players drifting into space indefinitely
        private IEnumerator ApplyTempSpaceDamage()
        {
            yield return(new WaitForSeconds(1f));

            healthBehaviorScript.RpcApplyDamage(null, 5, DamageType.OXY, BodyPartType.HEAD);
            //No idea why there is an isServer catch on RpcApplyDamage, but will apply on server as well in mean time:
            healthBehaviorScript.ApplyDamage(null, 5, DamageType.OXY, BodyPartType.HEAD);
            isApplyingSpaceDmg = false;
        }
Esempio n. 3
0
    private void OnTriggerEnter2D(Collider2D coll)
    {
        HealthBehaviour damageable = coll.GetComponent <HealthBehaviour>();

        if (damageable == null || damageable.IsDead || coll.gameObject == shooter)
        {
            return;
        }
        damageable.ApplyDamage(shooter, damage, damageType, bodyAim);
        //		Debug.LogFormat("Hit {0} for {1} with HealthBehaviour! bullet absorbed", damageable.gameObject.name, damage);
        PoolManager.Instance.PoolClientDestroy(gameObject);
    }
Esempio n. 4
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("Bullet"))
     {
         HealthBehaviour health = gameObject.GetComponent(typeof(HealthBehaviour)) as HealthBehaviour;
         DamageBehaviour damage = collision.gameObject.GetComponent(typeof(DamageBehaviour)) as DamageBehaviour;
         if (health != null && damage != null)
         {
             health.ApplyDamage(damage.DamageAmount);
         }
     }
 }
    [Command] //TODO fixme ghetto proof-of-concept
    public void CmdKnifeAttackMob(GameObject npcObj, GameObject weapon, Vector2 stabDirection, BodyPartType damageZone)
    {
        HealthBehaviour healthBehaviour = npcObj.GetComponent <HealthBehaviour>();

        if (healthBehaviour.IsDead == false)
        {
            if (!playerMove.allowInput || !allowAttack || playerMove.isGhost)
            {
                return;
            }

            if (npcObj != gameObject)
            {
                RpcMeleAttackLerp(stabDirection, weapon);
            }

            healthBehaviour
            .ApplyDamage(gameObject.name, 20, DamageType.BRUTE, damageZone);

            //this crap will remain here until moved to netmessages
            healthBehaviour.RpcApplyDamage(gameObject.name, 20, DamageType.BRUTE, damageZone);

            soundNetworkActions.RpcPlayNetworkSound("BladeSlice", transform.position);
            StartCoroutine(AttackCoolDown());
        }
        else
        {
            if (!playerMove.allowInput || playerMove.isGhost)
            {
                return;
            }
            if (npcObj.GetComponent <SimpleAnimal>())
            {
                SimpleAnimal attackTarget = npcObj.GetComponent <SimpleAnimal>();
                RpcMeleAttackLerp(stabDirection, weapon);
                attackTarget.Harvest();
                soundNetworkActions.RpcPlayNetworkSound("BladeSlice", transform.position);
            }
            else
            {
                PlayerHealth attackTarget = npcObj.GetComponent <PlayerHealth>();
                RpcMeleAttackLerp(stabDirection, weapon);
                attackTarget.Harvest();
                soundNetworkActions.RpcPlayNetworkSound("BladeSlice", transform.position);
            }
        }
    }
Esempio n. 6
0
    private void OnTriggerEnter2D(Collider2D coll)
    {
        HealthBehaviour damageable = coll.GetComponent <HealthBehaviour>();

        if (coll.gameObject == shooter && !isSuicide)
        {
            return;
        }

        if (damageable == null || damageable.IsDead)
        {
            return;
        }
        damageable.ApplyDamage(shooter, damage, damageType, bodyAim);
        Logger.LogTraceFormat("Hit {0} for {1} with HealthBehaviour! bullet absorbed", Category.Firearms, damageable.gameObject.name, damage);
        PoolManager.Instance.PoolClientDestroy(gameObject);
    }
Esempio n. 7
0
    public void CmdRequestMeleeAttack(GameObject victim, string slot, Vector2 stabDirection, BodyPartType damageZone)
    {
        if (!playerMove.allowInput ||
            playerMove.isGhost ||
            !victim ||
            !playerScript.playerNetworkActions.SlotNotEmpty(slot) ||
            !PlayerManager.PlayerInReach(victim.transform)
            )
        {
            return;
        }
        var             weapon       = playerScript.playerNetworkActions.Inventory[slot];
        ItemAttributes  weaponAttr   = weapon.GetComponent <ItemAttributes>();
        HealthBehaviour victimHealth = victim.GetComponent <HealthBehaviour>();


        // checks object and component existence before defining healthBehaviour variable.
        if (victimHealth.IsDead == false)
        {
            if (!allowAttack)
            {
                return;
            }

            if (victim != gameObject)
            {
                RpcMeleeAttackLerp(stabDirection, weapon);
            }

            victimHealth.ApplyDamage(gameObject, ( int )weaponAttr.hitDamage, DamageType.BRUTE, damageZone);
            if (weaponAttr.hitDamage > 0)
            {
                PostToChatMessage.SendItemAttackMessage(weapon, gameObject, victim, (int)weaponAttr.hitDamage, damageZone);
            }

            soundNetworkActions.RpcPlayNetworkSound(weaponAttr.hitSound, transform.position);
            StartCoroutine(AttackCoolDown());
        }
        else
        {
            //Butchering if we can
            if (weaponAttr.type != ItemType.Knife)
            {
                return;
            }
            if (victim.GetComponent <SimpleAnimal>())
            {
                SimpleAnimal attackTarget = victim.GetComponent <SimpleAnimal>();
                RpcMeleeAttackLerp(stabDirection, weapon);
                attackTarget.Harvest();
                soundNetworkActions.RpcPlayNetworkSound("BladeSlice", transform.position);
            }
            else
            {
                PlayerHealth attackTarget = victim.GetComponent <PlayerHealth>();
                RpcMeleeAttackLerp(stabDirection, weapon);
                attackTarget.Harvest();
                soundNetworkActions.RpcPlayNetworkSound("BladeSlice", transform.position);
            }
        }
    }
Esempio n. 8
0
    public void CmdRequestMeleeAttack(GameObject victim, string slot, Vector2 stabDirection,
                                      BodyPartType damageZone, LayerType layerType)
    {
        if (!playerMove.allowInput ||
            playerMove.isGhost ||
            !victim ||
            !playerScript.playerNetworkActions.SlotNotEmpty(slot) ||
            !playerScript.playerHealth.serverPlayerConscious
            )
        {
            return;
        }
        if (!allowAttack)
        {
            return;
        }

        var            weapon     = playerScript.playerNetworkActions.Inventory[slot];
        ItemAttributes weaponAttr = weapon.GetComponent <ItemAttributes>();

        // If Tilemap LayerType is not None then it is a tilemap being attacked
        if (layerType != LayerType.None)
        {
            var tileChangeManager = victim.GetComponent <TileChangeManager>();
            if (tileChangeManager == null)
            {
                return;
            }

            //Tilemap stuff:
            var tileMapDamage = tileChangeManager.GetTilemap(layerType).gameObject.GetComponent <TilemapDamage>();
            if (tileMapDamage != null)
            {
                //Wire cutters should snip the grills instead:
                if (weaponAttr.itemName == "wirecutters" &&
                    tileMapDamage.Layer.LayerType == LayerType.Grills)
                {
                    tileMapDamage.WireCutGrill((Vector2)transform.position + stabDirection);
                    StartCoroutine(AttackCoolDown());
                    return;
                }

                tileMapDamage.DoMeleeDamage((Vector2)transform.position + stabDirection,
                                            gameObject, (int)weaponAttr.hitDamage);

                playerMove.allowInput = false;
                RpcMeleeAttackLerp(stabDirection, weapon);
                StartCoroutine(AttackCoolDown());
                return;
            }
            return;
        }

        //This check cannot be used with TilemapDamage as the transform position is always far away
        if (!playerScript.IsInReach(victim.transform.position))
        {
            return;
        }

        //Meaty bodies:
        HealthBehaviour victimHealth = victim.GetComponent <HealthBehaviour>();

        if (victimHealth.IsDead && weaponAttr.type == ItemType.Knife)
        {
            if (victim.GetComponent <SimpleAnimal>())
            {
                SimpleAnimal attackTarget = victim.GetComponent <SimpleAnimal>();
                RpcMeleeAttackLerp(stabDirection, weapon);
                playerMove.allowInput = false;
                attackTarget.Harvest();
                soundNetworkActions.RpcPlayNetworkSound("BladeSlice", transform.position);
            }
            else
            {
                PlayerHealth attackTarget = victim.GetComponent <PlayerHealth>();
                RpcMeleeAttackLerp(stabDirection, weapon);
                playerMove.allowInput = false;
                attackTarget.Harvest();
                soundNetworkActions.RpcPlayNetworkSound("BladeSlice", transform.position);
            }
            return;
        }

        if (victim != gameObject)
        {
            RpcMeleeAttackLerp(stabDirection, weapon);
            playerMove.allowInput = false;
        }

        victimHealth.ApplyDamage(gameObject, (int)weaponAttr.hitDamage, DamageType.BRUTE, damageZone);
        if (weaponAttr.hitDamage > 0)
        {
            PostToChatMessage.SendItemAttackMessage(weapon, gameObject, victim, (int)weaponAttr.hitDamage, damageZone);
        }

        soundNetworkActions.RpcPlayNetworkSound(weaponAttr.hitSound, transform.position);
        StartCoroutine(AttackCoolDown());
    }