Example #1
0
 //Assigns skill values to projectile traps
 private void ConfigureProjectileTrap(ProjectileTrap tc)
 {
     tc.dmg      = tc.baseDamage;
     tc.trapUses = (int)trapUses;
     tc.usesLeft = (int)trapUses;
     tc.aoe      = AoE;
     //Debug.Log("setting tc.aoe to " + AoE);
     tc.attraction = attraction;
     tc.charge     = charge;
     tc.split      = split;
     tc.zone       = GetCurrentLaneID();
     tc.vampDrain  = vampDrain;
 }
Example #2
0
    //spawns a single projectiletrap in the center of the lane
    void SpawnProjectileTrap()
    {
        //Debug.Log ("range is " + range);
        float spawnRadius = Dial.TRACK_LENGTH * P_TRAP_RANGE;
        float longRadius  = Dial.TRACK_LENGTH * (P_TRAP_RANGE + 0.2f);
        float shortRadius = Dial.TRACK_LENGTH * (P_TRAP_RANGE - 0.2f);
        //find your angle
        float ownangle = this.transform.eulerAngles.z;
        float angle    = (ownangle + 90) % 360;

        float leftAngle  = angle + 15f;
        float rightAngle = angle - 15f;

        angle      *= Mathf.Deg2Rad;
        leftAngle  *= Mathf.Deg2Rad;
        rightAngle *= Mathf.Deg2Rad;

        GameObject trap = Instantiate(Resources.Load("Prefabs/MainCanvas/ProjectileTrap")) as GameObject;

        trap.transform.SetParent(Dial.spawnLayer, false);
        RectTransform  trapRect = (RectTransform)trap.transform;
        RectTransform  rt       = (RectTransform)transform;
        ProjectileTrap tc       = trap.GetComponent <ProjectileTrap>();

        //make it the type of trap this thing fires
        ConfigureProjectileTrap(tc);

        //find where to spawn the trap
        Vector2[] spawnPoints       = new Vector2[1]; //set up potential trap locations
        float     gunDistFromCenter = Dial.DIAL_RADIUS;

        spawnPoints[0] = new Vector2((gunDistFromCenter + spawnRadius) * (float)Math.Cos(angle), (gunDistFromCenter + spawnRadius) * (float)Math.Sin(angle));

        //create a collision checker
        GameObject spawnScanner = Instantiate(Resources.Load("Prefabs/RectTransform")) as GameObject;

        spawnScanner.transform.SetParent(Dial.spawnLayer, false);
        CircleCollider2D focus    = spawnScanner.AddComponent <CircleCollider2D>() as CircleCollider2D;
        RectTransform    scanRect = spawnScanner.GetComponent <RectTransform>();

        focus.radius = 3f;
        //move it around and see if there's traps in place
        int spot = 0;

        for (int i = 0; i < 1; i++)
        {
            Vector2 loc = spawnPoints[i];
            scanRect.anchoredPosition = loc;
            //check if there's an opening there
            Collider2D[]    stuffHit = new Collider2D[10];
            ContactFilter2D filter   = new ContactFilter2D();
            filter.NoFilter();
            focus.OverlapCollider(filter, stuffHit); //fill array with all colliders intersecting scanner
            List <Collider2D> fieldHit = new List <Collider2D>();
            for (int j = 0; j < stuffHit.Length; j++)
            { //filter out anything that doesn't get damaged by the field
                Collider2D coll = stuffHit[j];
                if (coll != null && ((coll.gameObject.tag == "Trap") || (coll.gameObject.tag == "ProjectileTrap")))
                {
                    fieldHit.Add(coll);
                }
            }
            if (fieldHit.Count <= 0)
            {
                spot = i;
                break;
            }
        }
        Destroy(spawnScanner);

        trapRect.anchoredPosition = spawnPoints[spot];
        tc.transform.rotation     = transform.rotation;
    }
Example #3
0
    public virtual void OnTriggerEnter2D(Collider2D coll)
    {
        if (frozen)
        {
            return;                                         //invincible while boss is moving it
        }
        if (coll != null && coll.gameObject.tag == "Enemy") //handled before anything that cares about shields
        {
            if (knockChained)
            {
                Debug.Log("we hit something with knockchain");
                float timeEstimate = 1.3f; //how long stuff presumably gets knocked back for
                                           //it's an estimate since we can't see it directly (without writing a script to measure it)
                float duration      = knockbackTimer.TimeElapsedSecs();
                float remainingTime = timeEstimate - duration;
                if (remainingTime > 0)
                {
                    float power = (remainingTime / timeEstimate) * knockbackPower;
                    coll.GetComponent <Enemy>().SelfKnockback(power);
                    coll.GetComponent <Enemy>().SelfStun(stunDuration);
                    Debug.Log("we're calling selfknockback on something");
                }
            }
        }
        if (shield != null)
        {
            if (shield.hitThisFrame)//the shield handled collision for us this time
            {
                return;
            }
            else  //the shield was either missed or hasn't been handled by collision yet
            {
                if (secondaryCollisionTicket)
                {
                    //let execution through to actually handle the collision- we're calling this function manually
                    secondaryCollisionTicket = false; //punch the ticket
                }
                else                                  //skip colliding- wait until update to check if the shield got it for us
                {
                    collidedThisFrame = true;
                    heldCollision     = coll; //store the collision so we can handle it if/when we call this manually
                    return;
                }
            }
        }
        if (coll == null)
        {
            Debug.Log("bullet's gone");
            return;
        }
        //Debug.Log ("!!! we made it through to our own collision");
        if (coll.gameObject.tag == "Bullet") //if it's a bullet
        {
            Debug.Log("we got hit by a bullet");
            Bullet bc = coll.gameObject.GetComponent <Bullet>();
            if (bc != null)
            {
                if (bc.CheckActive()) //if we get a Yes, this bullet/trap/shield is active
                {
                    bc.enemyHit = this.gameObject;
                    GetStatused(bc);
                    //StartCoroutine (StatusEffectsBullet (bc));
                    //Vamp-Drain
                    if (bc.vampDrain > 0f)
                    {
                        //if this enemy's hp is about to drop to 0
                        if (hp < bc.dmg * bc.vampDrain)
                        {
                            dialCon.ChangeHealth(hp);
                        }
                        else
                        {
                            dialCon.ChangeHealth(bc.dmg * bc.vampDrain);
                        }
                    }
                    hp -= bc.dmg;

                    timesShot++;
                    bc.Collide();

                    if (hp <= 0)
                    {
                        hp = 0;
                        Die();
                    }
                }
            }
        }
        else if (coll.gameObject.tag == "BulletRadial") //if it's a radial bullet from a BulletTrap
        {
            Debug.Log("we got hit by a radialBullet");
            BulletRadial bc = coll.gameObject.GetComponent <BulletRadial>();
            if (bc != null)
            {
                if (bc.CheckActive())
                {
                    Debug.Log("this bulletRadial that hit an enemy IS active");
                    //bulletRadials ignore the enemy that tripped the PTrap to begin with
                    if (this.gameObject != bc.ignoredEnemy)
                    {
                        Debug.Log(this.gameObject.ToString() + "equals " + bc.ignoredEnemy.ToString());
                        bc.enemyHit = this.gameObject;
                        GetStatused(bc);
                        //StartCoroutine (StatusEffectsBullet (bc));
                        //Vamp-Drain
                        if (bc.vampDrain > 0f)
                        {
                            //if this enemy's hp is about to drop to 0
                            if (hp < bc.dmg * bc.vampDrain)
                            {
                                dialCon.ChangeHealth(hp);
                            }
                            else
                            {
                                dialCon.ChangeHealth(bc.dmg * bc.vampDrain);
                            }
                        }
                        hp -= bc.dmg;
                        timesShot++;
                        bc.Collide();

                        if (hp <= 0)
                        {
                            hp = 0;
                            Die();
                        }
                    }
                }
            }
        }
        else if (coll.gameObject.tag == "Trap")         //if it's a trap
        {
            if (tripsTraps)
            {
                Trap tc = coll.gameObject.GetComponent <Trap>();
                if (tc != null)
                {
                    if (tc.CheckActive())                     //if we get a Yes, this bullet/trap/shield is active
                    {
                        tc.enemyHit = this.gameObject;
                        //Vamp-Drain
                        if (tc.vampDrain > 0f)
                        {
                            //if this enemy's hp is about to drop to 0
                            if (hp < tc.dmg * tc.vampDrain)
                            {
                                dialCon.ChangeHealth(hp);
                            }
                            else
                            {
                                dialCon.ChangeHealth(tc.dmg * tc.vampDrain);
                            }
                        }
                        if (tc.aoe == 0f)
                        {
                            hp -= tc.dmg;
                        }
                        tc.Collide();
                        if (hp <= 0)
                        {
                            Die();
                        }
                    }
                }
            }
        }
        else if (coll.gameObject.tag == "ProjectileTrap") //if it's a projectiletrap
        {
            //Debug.Log("enemy collided with projectiletrap");
            if (tripsTraps)
            {
                //Debug.Log("enemy which collided with PTrap DOES trip traps");
                ProjectileTrap tc = coll.gameObject.GetComponent <ProjectileTrap>();
                if (tc != null)
                {
                    //Debug.Log("PTrap isn't null");
                    if (tc.CheckActive())
                    {
                        tc.enemyHit = this.gameObject;
                        //Vamp-Drain
                        if (tc.vampDrain > 0f)
                        {
                            //if this enemy's hp is about to drop to 0
                            if (hp < tc.dmg * tc.vampDrain)
                            {
                                dialCon.ChangeHealth(hp);
                            }
                            else
                            {
                                dialCon.ChangeHealth(tc.dmg * tc.vampDrain);
                            }
                        }
                        hp -= tc.dmg;
                        //Debug.Log("calling Collide() on projectiletrap");
                        tc.Collide();
                        if (hp <= 0)
                        {
                            Die();
                        }
                    }
                }
            }
        }
        else if (coll.gameObject.tag == "Shield")         //if it's a shield
        {
            //all handled by the shield collision now
        }
        else if (coll.gameObject.tag == "AoE")
        {
            //Debug.Log ("enemy collided with AoE");
            GameObject obj = coll.gameObject;
            AoE        ac  = obj.GetComponent <AoE>();
            if (ac.parent == "Bullet")
            {
                //StartCoroutine (StatusEffectsBullet (bc));
                if (ac.vampIsOn)
                {
                    if (hp < ac.vampDrain)
                    {
                        dialCon.ChangeHealth(hp);
                    }
                    else
                    {
                        dialCon.ChangeHealth(ac.vampDrain);
                    }
                }
                hp -= ac.aoeDamage;
                Debug.Log("damage taken: " + ac.aoeDamage);
                //timesShot++;
                if (hp <= 0)
                {
                    Die();
                }
            }
            else if (ac.parent == "Trap")
            {
                hp -= ac.aoeDamage;
                if (hp <= 0)
                {
                    Die();
                }
            }
        }
        //other types of collision?
    }