Example #1
0
    private void OnTriggerEnter(Collider col)
    {
        if (col.GetComponentInParent <IHittable>() == null)
        {
            return;
        }
        PlayerStats ps;

        if ((ps = col.GetComponentInParent <PlayerStats>()) != null && ps.gameObject == sourcePlayer.gameObject)
        {
            return;
        }
        else
        {
            Rigidbody r;
            if ((r = col.transform.GetComponent <Rigidbody>()) != null)
            {
                if (ps && !hasHit.Contains(ps))
                {
                    if (!hitSameTeam && ps.teamIndex == sourcePlayer.GetComponent <PlayerStats>().teamIndex&& ps.teamIndex != -1)
                    {
                        return;                                                                                                           // dont hit players on same team
                    }
                    hasHit.Add(ps);
                    HitManager.HitClientside(new HitArguments(r.GetComponentInParent <BasePlayer>().gameObject, sourcePlayer).withDamage(ability.damage).withEffect(effect).withEffectDuration(effectDuration).withHitSameTeam(hitSameTeam));
                    if (hasHit.Count <= 1)
                    {
                        Invoke("DestroyMe", effectDuration);
                    }
                }
            }
        }
    }
Example #2
0
    private void OnTriggerEnter(Collider col)
    {
        if (col.GetComponentInParent <IHittable>() == null)
        {
            return;
        }
        PlayerStats ps;

        if ((ps = col.GetComponentInParent <PlayerStats> ()) != null && ps.gameObject == sourcePlayer.gameObject)
        {
            return;
        }
        else
        {
            Rigidbody r;
            if ((r = col.transform.GetComponent <Rigidbody>()) != null)
            {
                if (ps)
                {
                    if (!hitSameTeam && ps.teamIndex == sourcePlayer.GetComponent <PlayerStats>().teamIndex&& ps.teamIndex != -1)
                    {
                        return;                                                                                                           // dont hit players on same team
                    }
                    r.GetComponentInParent <BasePlayer>().myRigid.AddExplosionForce(ability.pushForce, transform.position, radius);
                    HitManager.HitClientside(new HitArguments(r.GetComponentInParent <BasePlayer>().gameObject, sourcePlayer).withDamage(ability.damage).withHitSameTeam(hitSameTeam));
                }
                else
                {
                    r.AddExplosionForce(ability.pushForce, transform.position, radius);
                }
            }
        }
    }//TODO: add continuous upward force
Example #3
0
    public override void SpawnSpell(PlayerComponent.Buf data)
    {
        Vector3 spawnAngle    = data.vectorList[0];
        Vector3 spawnPosition = data.vectorList[1];


        // Spawn our spell in the place the server told us
        // However if we are the client, we don't wait for that luxury.
        GameObject spawn = GameObject.Instantiate(itemToSpawn, spawnPosition + transform.TransformDirection(spawnOffset), transform.rotation);
        Rigidbody  r;

        Quaternion aimAngle = Quaternion.LookRotation(spawnAngle);

        flameSpawned = GameObject.Instantiate(FlameThrowerEffect, spawnPosition + transform.TransformDirection(spawnOffset), aimAngle);
        if (r = spawn.GetComponent <Rigidbody>())
        {
            r.AddForce(spawnAngle * spawnSpeed);
        }
        OnSpellSpawned(spawn);

        Destroy(flameSpawned, lifetime);
        PlayerStats sourcePlayerStats = GetComponentInParent <PlayerStats>();

        HitManager.HitClientside(new HitArguments(sourcePlayerStats.gameObject, sourcePlayerStats.gameObject).withEffect(effect).withEffectDuration(cooldown));
    }
 public override void Effect_Update()
 {
     if (Time.time - lastDamage > coolDown)
     {
         if (targetStats.poisonStacks > 1)
         {
             targetStats.poisonStacks--;
             Destroy(this.gameObject);
         }
         lastDamage = Time.time;
         HitManager.HitClientside(new HitArguments(targetStats.gameObject, this.sourcePlayer.GetComponentInParent <PlayerStats> ().gameObject)
                                  .withDamage(damage));
     }
 }
Example #5
0
    // Use this for initialization
    void Start()
    {
        hitHittables = new ArrayList();

        RaycastHit[] hits = Physics.SphereCastAll(transform.position, range, Vector3.one);
        // Hits returns an array of everything in the sphere length, however we are just looking at the start
        foreach (RaycastHit hit in hits)
        {
            bool isSourcePlayer = false;
            if (!inLOS(hit))
            {
                continue;
            }

            PlayerStats ps;
            if ((ps = hit.transform.GetComponentInParent <PlayerStats>()))
            {
                //print(ps);
                if (ps.gameObject == sourcePlayer.gameObject)
                {
                    isSourcePlayer = true;
                }
                if (!isSourcePlayer && !hitSameTeam && ps.teamIndex == sourcePlayer.GetComponent <PlayerStats>().teamIndex&& ps.teamIndex != -1)
                {
                    continue;                                                                                                                              // dont hit players on same team
                }
            }
            Rigidbody r;
            if ((r = hit.transform.GetComponent <Rigidbody>()) != null && !r.GetComponent <Projectile>())
            {
                if (ps)
                {
                    // Do something different, not as harsh hit forces
                    if (!ps.death)
                    {
                        r.AddForce(Vector3.up * verticalPushForce * (isSourcePlayer ? (pushForce * sourcePlayerForceMultiplier):pushForce) * 2);
                    }
                    r.AddExplosionForce((isSourcePlayer ? (pushForce * sourcePlayerForceMultiplier) : pushForce) * 0.5f, transform.position, range);
                }
                else
                {
                    r.AddExplosionForce(pushForce, transform.position, range);
                }
            }
            IHittable h;
            if ((h = hit.transform.GetComponentInParent <IHittable>()) != null)
            {
                if (hitHittables.Contains(h))
                {
                    //print("Not hitting " + hit.transform.name + ", has already been hit");
                }
                else
                {
                    Transform target = hit.transform;
                    // If this is a player, we should be hitting from the distance of the root of the player, not the limb
                    if (ps)
                    {
                        target = ps.transform;
                    }
                    // If distance is 0, damage factor is 1. If distance is r, damage factor is 0.
                    float damageFactor = (-1 * Vector3.Distance(hit.transform.position, transform.position) / range) + 1;
                    //print ("Damage Factor " + damageFactor);
                    HitManager.HitClientside(new HitArguments(((Component)hit.transform.gameObject.GetComponentInParent <IHittable>()).gameObject, sourcePlayer.GetComponentInParent <PlayerStats>().gameObject)
                                             .withDamage((isSourcePlayer ? sourcePlayerDamageMultiplier : 1) * (((maxDamage - minDamage) * damageFactor) + minDamage))
                                             .withDamageType(damageType)
                                             .withEffect(effect)
                                             .withEffectDuration(effectDuration)
                                             .withHitSameTeam(hitSameTeam)
                                             .withSourcePosition(new Vector3(transform.position.x, transform.position.z)));
                    //Debug.DrawLine (hit.transform.position, transform.position, Color.red, 10);
                    //print ("Hitting the player " + target + ", and the object " + hit.transform + " with damage " + ((maxDamage/Vector3.Distance(hit.transform.position, transform.position) + 1) + minDamage));
                    hitHittables.Add(h);
                }
            }
        }
    }
Example #6
0
    void OnTriggerEnter(Collider col)
    {
        /* CHECKS FOR HIT VALIDIDTY */
        if (done)
        {
            return;
        }
        if (hitThem && dieOnHit)
        {
            return;                      // We only want to hit one object... for some reason it collides multiple times before destroying itself
        }
        if (col.isTrigger)
        {
            return;                // Only want our own trigger effects
        }
        PlayerStats ps;

        if (!sourcePlayer)
        {
            return;                // Shouldn't collide with anything that isn't a source player
        }
        if ((ps = col.GetComponentInParent <PlayerStats>()))
        {
            if (ps.gameObject == sourcePlayer.gameObject)
            {
                return;
            }
            if (!hitSameTeam && ps.teamIndex == sourcePlayer.GetComponent <PlayerStats>().teamIndex&& ps.teamIndex != -1)
            {
                return;                                                                                                           // dont hit players on same team
            }
        }
        /* ACTIONS TO TAKE POST-HIT */

        hitThem = true;
        if (col.GetComponentInParent <IHittable>() != null && !hasHitThem.Contains(ps))
        {
            HitManager.HitClientside(HitManager.HitVerificationMethod.projectile, new HitArguments(((Component)col.gameObject.GetComponentInParent <IHittable>()).gameObject, sourcePlayer.GetComponentInParent <PlayerStats>().gameObject)
                                     .withDamage(damage)
                                     .withDamageType(damageType)
                                     .withEffect(effect)
                                     .withEffectDuration(effectDuration)
                                     .withHitSameTeam(hitSameTeam));
            hasHitThem.Insert(hasHitThem.Count, ps);
        }
        else if (this.transform.localScale.x < maxDistanceToHaveEndParticleEffect)
        {
            done = true;
            Destroy(this.particleEffect);
            Destroy(this.GetComponentInChildren <ParticleSystem>().gameObject, .2f);
            trailParticles.Stop();
            GameObject endParticleEffect = GameObject.Instantiate(particleEffectForWhenItHitsAWall, this.transform.position, this.transform.rotation);
            if (this.transform.localScale.x / endParticleScaleDivisor < maxEndParticleScale)
            {
                endParticleEffect.transform.localScale = this.transform.localScale / endParticleScaleDivisor;
            }
            else
            {
                endParticleEffect.transform.localScale = new Vector3(maxEndParticleScale, maxEndParticleScale, maxEndParticleScale);
            }
            Destroy(endParticleEffect, endingParticleEffectLifetime);
            Destroy(this.gameObject, endingParticleEffectLifetime);
        }

        if (dieOnHit)
        {
            if (explodeParticles)
            {
                trailParticles.Stop();
                ParticleSystem.MainModule m = trailParticles.main;
                m.loop = false;
                trailParticles.transform.parent = null;
                GameObject spawn = GameObject.Instantiate(explodeParticles, transform.position, Quaternion.identity);
                Explosion  e;
                if ((e = spawn.GetComponent <Explosion>()))
                {
                    e.sourcePlayer = sourcePlayer;
                }
            }
            Destroy(this.gameObject);
        }
    }
Example #7
0
    void OnTriggerEnter(Collider col)
    {
        /* CHECKS FOR HIT VALIDIDTY */
        if (hasHit && dieOnHit)
        {
            return;                     // We only want to hit one object... for some reason it collides multiple times before destroying itself
        }
        if (col.isTrigger)
        {
            return;                // Only want our own trigger effects
        }
        PlayerStats ps;

        if (!sourcePlayer)
        {
            return;                // Shouldn't collide with anything that isn't a source player
        }
        if ((ps = col.GetComponentInParent <PlayerStats>()))
        {
            if (ps.gameObject == sourcePlayer.gameObject)
            {
                return;
            }
            if (!hitSameTeam && ps.teamIndex == sourcePlayer.GetComponent <PlayerStats>().teamIndex&& ps.teamIndex != -1)
            {
                return;                                                                                                           // dont hit players on same team
            }
        }
        /* ACTIONS TO TAKE POST-HIT */

        hasHit = true;
        Rigidbody myRigid = this.GetComponent <Rigidbody> ();

        if (col.GetComponentInParent <IHittable>() != null)
        {
            //Debug.DrawLine(transform.position, new Vector3((transform.position.x - col.transform.position.x) * -5 + col.transform.position.x, transform.position.y, (transform.position.z - col.transform.position.z) * -5 + col.transform.position.z), Color.blue, 10f);
            //Debug.DrawLine(new Vector3(transform.position.x, transform.position.y, transform.position.z), new Vector3(transform.position.x, transform.position.y, transform.position.z) - myRigid.velocity, Color.red, 10f);
            HitManager.HitClientside(HitManager.HitVerificationMethod.projectile, new HitArguments(((Component)col.gameObject.GetComponentInParent <IHittable>()).gameObject, sourcePlayer.GetComponentInParent <PlayerStats>().gameObject)
                                     .withDamage(damage)
                                     .withDamageType(damageType)
                                     .withEffect(effect)
                                     .withEffectDuration(effectDuration)
                                     .withSourcePosition(new Vector3((transform.position.x - col.transform.position.x) * -5 + col.transform.position.x, (transform.position.z - col.transform.position.z) * -5 + col.transform.position.z))
                                     .withHitSameTeam(hitSameTeam));
        }

        if (dieOnHit)
        {
            if (explodeParticles)
            {
                trailParticles.Stop();
                ParticleSystem.MainModule m = trailParticles.main;
                m.loop = false;
                trailParticles.transform.parent = null;
                GameObject spawn = GameObject.Instantiate(explodeParticles, transform.position, Quaternion.identity);
                Explosion  e;
                if ((e = spawn.GetComponent <Explosion>()))
                {
                    e.sourcePlayer = sourcePlayer;
                }
            }
            Destroy(this.gameObject);
        }
    }