Exemplo n.º 1
0
    // TODO equip an item (as a weapon)
    public void equipWeapon(WeaponBS weapon)
    {
        SpriteRenderer sr;

        if (weapon.type == WeaponBS.Type.Projectile || weapon.type == WeaponBS.Type.Missile)
        {
            if (missileWeapon != null)
            {
                sr         = missileWeapon.gameObject.GetComponent <SpriteRenderer>();
                sr.enabled = false;
            }
            missileWeapon = weapon;
        }
        else
        {
            if (meleeWeapon != null)
            {
                sr         = meleeWeapon.gameObject.GetComponent <SpriteRenderer>();
                sr.enabled = false;
            }
            meleeWeapon = weapon;
        }
        sr         = weapon.gameObject.GetComponent <SpriteRenderer>();
        sr.enabled = true;
    }
Exemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     if (weapon == null)
     {
         weapon = gameObject.GetComponentInParent <WeaponBS>(); // the item is the parent obj, then weapon is a field
     }
     GameObject.Destroy(gameObject, 0.1f);                      // delete after 1 second (DEFAULT, REPLACE LATER)
 }
Exemplo n.º 3
0
 public bool isCompatible(WeaponBS weapon)
 {
     if (ammoType == weapon.ammoType)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
    // melee attack hit  me
    public void hitByMelee(WeaponBS weapon, Character_BS attacker)
    {
        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 * attacker.meleeSkill) // less than or equal to crit chance
        {
            // crit!
            damage *= 10; // mult by 10
        }
        if (accRoll >= weapon.accuracy * attacker.meleeSkill)
        {
            damage = 0;
        }
        health -= damage;
        //print("Melee attack from: " + weapon.item.gameObject.name + " dealt " + damage.ToString() + " damage.");
    }
Exemplo n.º 5
0
    // missile hit me!
    public void hitByMissile(WeaponBS weapon, Character_BS shooter)
    {
        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;
    }
Exemplo n.º 6
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
        }
    }