Beispiel #1
0
    IEnumerator AttackSequence()
    {
        isAttacking = true;

        Vector3 startOffset = mainHand.transform.position - attackCenter.position;

        mainHand.Reparent(!player.isFlipped, false, attackTarget);
        yield return(new WaitForSeconds(attackCooldown / 4f));

        Vector3 endOffset = mainHand.transform.position - attackCenter.position;

        //add some buffer
        Vector3 dir = endOffset - startOffset;

        RaycastHit2D[] hits = Physics2D.CircleCastAll(attackCenter.position + startOffset, 0.3f, dir.normalized, dir.magnitude, attackableLayers);
        foreach (RaycastHit2D hit in hits)
        {
            DamageableObject health = hit.collider.GetComponent <DamageableObject>();
            if (health != this)
            {
                health.TakeDamage(damage);
            }
        }

        yield return(new WaitForSeconds(attackCooldown / 4f));

        mainHand.Reparent(player.isFlipped, false);
        yield return(new WaitForSeconds(attackCooldown / 2f));

        isAttacking = false;
    }
Beispiel #2
0
    void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player")
        {
            Ship         shipHit        = other.gameObject.GetComponentInParent <Ship>();
            ShipMovement playerMovement = other.gameObject.GetComponentInParent <ShipMovement>();
            if (shipHit.playerEnum != owningPlayer)
            {
                //Do damage to the player hit
                shipHit.TakeDamage(damage);

                //Slow the player while in the beam
                playerMovement.SlowPlayer(slowingFactor);

                GameObject explosion = Instantiate(explosionPrefab, other.transform.position, new Quaternion()) as GameObject;
                Destroy(explosion, 5f);
            }
        }
        else if (other.tag == "ProtagShip")
        {
            DamageableObject otherShip = other.gameObject.GetComponentInParent <DamageableObject>();
            otherShip.TakeDamage(damage);

            GameObject explosion = Instantiate(explosionPrefab, other.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
        }
    }
Beispiel #3
0
    //TODO: Move the ship-specific logic to Ship subclasses and common logic to Ship base class
    protected virtual void OnTriggerEnter(Collider other)
    {
        //Destroy bullets upon hitting a killzone
        if (other.tag == "KillZone")
        {
            curState = BulletState.none;
            DestroyThisBullet();
        }
        //Deal damage to any other player hit
        else if (other.tag == "Player")
        {
            Ship      shipHit      = other.gameObject.GetComponentInParent <Ship>();
            Character characterHit = shipHit.character;

            if (characterHit.playerEnum != owningPlayer)
            {
                //Masochists with the shield up are immune to incoming bullets
                if (characterHit.characterType == CharactersEnum.m*******t)
                {
                    M*******t masochistHit = characterHit as M*******t;
                    if (masochistHit != null && masochistHit.masochistShip.shieldUp)
                    {
                        return;
                    }
                }

                //TODO: Re-add m*******t damage multiplier to bullet creation
                //Do damage to the player hit
                shipHit.TakeDamage(damage);

                GameObject explosion = Instantiate(explosionPrefab, other.gameObject.transform.position, new Quaternion()) as GameObject;
                Destroy(explosion, 5f);
                curState = BulletState.none;
                DestroyThisBullet();
            }
            //TODO: What the heck? Why is this thisPlayer == vampire? We should re-write this
            //If the bullet was absorbed by the vampire with it's shield up, heal slightly instead of doing damage
            else if (owningPlayer != PlayerEnum.none && thisPlayer.character.characterType == CharactersEnum.vampire)
            {
                if (curState == BulletState.absorbedByVampire)
                {
                    shipHit.TakeDamage(damage * -vampShieldHealAmount);
                    curState = BulletState.none;
                    damage   = 1;
                    DestroyThisBullet();
                }
            }
        }
        //Deal damage to any ProtagShip hit
        else if (other.tag == "ProtagShip")
        {
            DamageableObject otherShip = other.gameObject.GetComponentInParent <DamageableObject>();
            otherShip.TakeDamage(damage);

            GameObject explosion = Instantiate(explosionPrefab, other.gameObject.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
            curState = BulletState.none;
            DestroyThisBullet();
        }
    }
Beispiel #4
0
    //Deal damage to every enemy that was inside the attack hitbox when it was enabled
    void DealDamage(DamageableObject other)
    {
        //Determine damage dealt for the attack
        float attackDamage = Random.Range(damageMin, damageMax + 1);

        //Determine if the attack was a critical hit
        //If so, double the damage dealt
        if (Random.Range(0, 1.0f) <= critChance)
        {
            attackDamage = attackDamage * 2;
        }

        //JPS: Apply calculations for enchantments, such as additional crit chance, freezing chance, etc.

        other.TakeDamage(attackDamage);
    }
Beispiel #5
0
    void Explode()
    {
        if (hasExploded)
        {
            return;
        }
        hasExploded = true;
        if (GameManager.S.inGame)
        {
            SoundManager.instance.Play("Explosion");
        }
        foreach (var bullet in trappedBullets)
        {
            if (bullet != null)
            {
                bullet.gameObject.layer = LayerMask.NameToLayer("Default");
            }
        }

        //Remove the hitboxes and sprite
        Destroy(inner);
        Destroy(outer);
        GetComponent <SpriteRenderer>().enabled = false;

        //Stop the inner particle system and immediately destroy the outer particle system
        innerParticleSystem.Stop();
        Destroy(outerParticleSystem.gameObject);

        //Play the explosion particle system
        explosion.Play();
        Collider[] hitTargets = Physics.OverlapSphere(transform.position, explosionRadius);
        foreach (Collider target in hitTargets)
        {
            //JPS: Bug, if a protag ship gets hit, it won't have a PlayerShip component
            if (target.gameObject.tag == "Player" || target.gameObject.tag == "ProtagShip")
            {
                DamageableObject shipHit = target.GetComponentInParent <DamageableObject>();
                shipHit.TakeDamage(explosionDamage);
            }
        }

        //Clean up
        Destroy(gameObject, 5f);
    }
Beispiel #6
0
    protected virtual bool CheckCollision(Vector3 direction, float distance)
    {
        Physics.Raycast(transform.position, direction.normalized, out hit, distance + colliderRadius, allowedLayers);
        bool IHit = hit.collider == null ? true : false;

        if (!IHit)
        {
            DamageableObject hitTarget = hit.collider.GetComponent <DamageableObject>();
            if (hitTarget != null)
            {
                hitTarget.TakeDamage(1);
                if (health <= 5)
                {
                    TakeDamage(1000);
                }
                TakeDamage(1);
            }
        }

        return(IHit);
    }
Beispiel #7
0
    protected virtual void KillProjectile()
    {
        DamageableObject objectHiit = hit.collider.gameObject.GetComponent <DamageableObject>();

        if (objectHiit != null)
        {
            objectHiit.TakeDamage(Damage * damageMultiplier);
            if (playerUse)
            {
                ObjectPool.Instance.AddToList(gameObject);
            }
            else
            {
                Destroy(gameObject);
            }
        }
        else
        {
            Debug.Log("nothing found");
        }

        GameVariables.Instance.RemoveProjectile(projectileTransform.gameObject);
    }
Beispiel #8
0
    //Damage any player or protag ship that is within the explosion
    void DamageTarget(Collider other)
    {
        if (other.tag == "Player")
        {
            Ship shipHit = other.gameObject.GetComponentInParent <Ship>();
            //Do damage to the player hit
            float     multiplier      = 1f;
            M*******t masochistPlayer = GameManager.S.players[(int)owningPlayer].character as M*******t;
            if (masochistPlayer != null)
            {
                multiplier = masochistPlayer.masochistShip.damageMultiplier;
            }
            damageDealt = CalculateDamageDealt(other.transform) * multiplier;
            shipHit.TakeDamage(damageDealt);
            //print("Damage Dealt: " + damageDealt);

            GameObject explosion = Instantiate(explosionPrefab, other.gameObject.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
        }
        else if (other.tag == "ProtagShip")
        {
            DamageableObject otherShip       = other.gameObject.GetComponentInParent <DamageableObject>();
            M*******t        masochistPlayer = GameManager.S.players[(int)owningPlayer].character as M*******t;
            if (masochistPlayer != null)
            {
                damageDealt = CalculateDamageDealt(other.transform) * masochistPlayer.masochistShip.damageMultiplier;
            }
            else
            {
                damageDealt = CalculateDamageDealt(other.transform);
            }
            otherShip.TakeDamage(damageDealt);

            GameObject explosion = Instantiate(explosionPrefab, other.gameObject.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
        }
    }