Example #1
0
    private void initWeapon(int weaponIndex)
    {
        Weapon weapon = null;

//		int rand = UnityEngine.Random.Range(0, Enum.GetNames(typeof(WeaponType)).Length);

        WeaponType type = WeaponType.BLASTER;        //rand == 0? WeaponType.BLASTER:

        //rand == 1? WeaponType.PLASMER:
        //rand == 2? WeaponType.CHARGER:
        //rand == 3? WeaponType.EMITTER:
        //rand == 4? WeaponType.WAVER:
        //rand == 5? WeaponType.LAUNCHER:
        //WeaponType.SUPPRESSOR;

        switch (type)
        {
        case WeaponType.BLASTER: weapon = Instantiate <Transform>(blasterPrefab).GetComponent <Blaster>(); break;

        case WeaponType.PLASMER: weapon = Instantiate <Transform>(plasmerPrefab).GetComponent <Plasmer>(); break;

        case WeaponType.CHARGER: weapon = Instantiate <Transform>(chargerPrefab).GetComponent <Charger>(); break;

        case WeaponType.EMITTER: weapon = Instantiate <Transform>(emitterPrefab).GetComponent <Emitter>(); break;

        case WeaponType.WAVER: weapon = Instantiate <Transform>(waverPrefab).GetComponent <Waver>(); break;

        case WeaponType.LAUNCHER: weapon = Instantiate <Transform>(launcherPrefab).GetComponent <Launcher>(); break;

        case WeaponType.SUPPRESSOR: weapon = Instantiate <Transform>(suppressorPrefab).GetComponent <Suppressor>(); break;
        }

        weapon.init(this);
        weapon.setWeaponType(type);
        weapon.setDamage(type.damage() - 3, type.damage() + 3);
        weapon.setReloadTime(type.reloadTime());
        weapon.setPlayerTransform(playerShip);

        weapon.transform.SetParent(transform);

        Vector3 posit = getWeaponPosition(weaponIndex);

        weapon.transform.position = new Vector3(transform.position.x + posit.x, transform.position.y + posit.y, posit.z);

        weapon.getRender().sortingOrder = sortingOrder + 2;

        switch (weaponIndex)
        {
        case 0: weapon_1 = weapon; break;

        case 1: weapon_2 = weapon; break;

        case 2: weapon_3 = weapon; break;

        case 3: weapon_4 = weapon; break;

        case 4: weapon_5 = weapon; break;
        }
    }
Example #2
0
    public static WeaponData createWeaponData(WeaponType type)
    {
        ItemQuality quality = randQuality();
        float       level   = randLevel();

        int   damage     = Mathf.RoundToInt(type.damage() * level * qualityMultiplier(quality));
        float reloadTime = (type.reloadTime() / level) * (quality == ItemQuality.UNIQUE? 0.6f: quality == ItemQuality.SUPERIOR? 0.8f: 1);

        WeaponData data = new WeaponData(quality, level, type, damage - type.damageRange(), damage + type.damageRange(), reloadTime);

        data.initCommons(calculateCost(data), calculateEnergy(data));

        return(data);
    }