Ejemplo n.º 1
0
    // projectile hit me!
    public void hitByProjectile(BulletBS bullet, Character_BS shooter)
    {
        WeaponBS weapon   = bullet.weapon;
        float    critRoll = UnityEngine.Random.Range(0.0f, 1.0f);
        float    accRoll  = UnityEngine.Random.Range(0.0f, 1.0f);
        int      damage   = weapon.damage;

        if (critRoll <= weapon.critChance * shooter.missileSkill) // less than or equal to crit chance
        {
            // crit!
            damage *= 10; // mult by 10
        }

        if (accRoll >= weapon.accuracy * shooter.missileSkill)
        {
            damage = 0;
        }
        health -= damage;
    }
Ejemplo n.º 2
0
    public void MakeAttack(GameObject attacker, Vector2 direction, WeaponBS weapon)
    {
        // checks for validity in the character class
        GameObject prefab;
        GameObject newMissile;
        GameObject newMelee;
        bool       didAttack = true;
        Transform  shotspawn = weapon.shotspawn; // shortcut

        switch (weapon.type)
        {
        // creates an object to act like projectile
        case WeaponBS.Type.Projectile:
            if (weapon.ClipItem.rounds > 0)
            {
                prefab     = weapon.Missile_Prefab;
                newMissile = Instantiate(prefab, shotspawn.position, shotspawn.rotation) as GameObject;
                BulletBS newBBS = newMissile.GetComponent <BulletBS>();    // mono behave, act like bullet (maybe need to add more variety)
                newBBS.weapon  = weapon;
                newBBS.shooter = attacker;
                newBBS.Shoot(direction);
            }
            else
            {
                didAttack = false;
            }

            break;

        // detects hits with raycast
        case WeaponBS.Type.Missile:
            if (weapon.ClipItem.rounds > 0)
            {
                List <GameObject> ignoreList = new List <GameObject>();
                ignoreList.Add(attacker);

                RaycastHit2D[] allHits = Physics2D.RaycastAll(weapon.shotspawn.position, direction, weapon.range);
                foreach (RaycastHit2D hit in allHits)
                {
                    GameObject  go = hit.collider.gameObject;
                    BarricadeBS br = go.GetComponent <BarricadeBS>();

                    if (ignoreList.Contains(go) || br != null)
                    {
                        //print("SHOT not blocked by " + go.name);
                    }
                    else
                    {
                        Character_BS ch = go.GetComponent <Character_BS>();
                        if (ch != null)
                        {
                            ch.hitByMissile(weapon, attacker.GetComponent <Character_BS>());
                        }
                        break;
                    }
                }
            }
            else
            {
                didAttack = false;
            }
            break;

        // creates a little nonmoving object to detect hits
        case WeaponBS.Type.Melee:
            prefab   = weapon.Melee_Prefab;
            newMelee = Instantiate(prefab, shotspawn.position, shotspawn.rotation) as GameObject;

            MeleeAttackBS meleeattack = newMelee.GetComponent <MeleeAttackBS>();
            meleeattack.weapon        = weapon;
            newMelee.transform.parent = attacker.transform;
            meleeattack.attacker      = attacker;
            // still make noise when we attack

            break;

        default:
            break;
        }
        if (didAttack)
        {
            MakeNoise(attacker, shotspawn.position, weapon.noise);
            weapon.makeSound();
            weapon.attackUpdate(); // update the weapon
        }
    }