Пример #1
0
    public void GetMaxes()
    {
        foreach (KeyValuePair <string, Dictionary <WeaponRarity, List <Weapon> > > type in order)
        {
            foreach (KeyValuePair <WeaponRarity, List <Weapon> > rarity in type.Value)
            {
                foreach (Weapon w in rarity.Value)
                {
                    switch (type.Key)
                    {
                    case "Automatic":
                        W_AutoGun wag = (W_AutoGun)w;
                        maxAutoDamage      = Mathf.Max(maxAutoDamage, wag.bulletDamage);
                        maxAutoRecoil      = Mathf.Max(maxAutoRecoil, wag.recoil);
                        maxAutoPushback    = Mathf.Max(maxAutoPushback, wag.bulletPushback);
                        maxFireRate        = Mathf.Max(maxFireRate, 1 / wag.fireRate);          // invert to get usable value
                        maxAutoAmmo        = Mathf.Max(maxAutoAmmo, wag.ammoCapacity);
                        maxAutoReloadSpeed = Mathf.Max(maxAutoReloadSpeed, 1 / wag.reloadRate); // invert to get usable value
                        break;

                    case "Semiautomatic":
                        W_SemiGun sag = (W_SemiGun)w;
                        maxSemiDamage      = Mathf.Max(maxSemiDamage, sag.bulletDamage);
                        maxSemiRecoil      = Mathf.Max(maxSemiRecoil, sag.recoil);
                        maxSemiPushback    = Mathf.Max(maxSemiPushback, sag.bulletPushback);
                        maxScatterCount    = Mathf.Max(maxScatterCount, sag.burstCount);
                        maxSemiAmmo        = Mathf.Max(maxSemiAmmo, sag.ammoCapacity);
                        maxSemiReloadSpeed = Mathf.Max(maxSemiReloadSpeed, 1 / sag.reloadRate);     // invert to get usable value
                        break;

                    case "Launcher":
                        W_Launcher l = (W_Launcher)w;
                        maxLauncherDamage      = Mathf.Max(maxLauncherDamage, l.coreDamage);
                        maxLauncherRecoil      = Mathf.Max(maxLauncherRecoil, l.recoil);
                        maxLauncherPushback    = Mathf.Max(maxLauncherPushback, l.corePushback);
                        maxProjectilePower     = Mathf.Max(maxProjectilePower, l.projectilePower);
                        maxLauncherAmmo        = Mathf.Max(maxLauncherAmmo, l.ammoCapacity);
                        maxLauncherReloadSpeed = Mathf.Max(maxLauncherReloadSpeed, 1 / l.reloadRate);     // invert to get usable value
                        break;

                    case "Sprayer":
                        W_Sprayer s = (W_Sprayer)w;
                        maxSprayerDamage      = Mathf.Max(maxSprayerDamage, s.bulletDamage);
                        maxSprayerRecoil      = Mathf.Max(maxSprayerRecoil, s.recoil);
                        maxSprayerPushback    = Mathf.Max(maxSprayerPushback, s.bulletPushback);
                        maxSprayDistance      = Mathf.Max(maxSprayDistance, s.sprayDistance);
                        maxSprayerAmmo        = Mathf.Max(maxSprayerAmmo, s.ammoCapacity);
                        maxSprayerReloadSpeed = Mathf.Max(maxSprayerReloadSpeed, 1 / s.reloadRate);     // invert to get usable value
                        break;

                    default:
                        Debug.LogError("WEIRD WEAPON TYPE");
                        break;
                    }
                }
            }
        }
    }
Пример #2
0
    // ===========================================================
    //                      ATTACKS AND DAMAGE
    // ===========================================================

    /// <summary>
    /// Fires an AutoGun Weapon
    /// </summary>
    /// <param name="auto">Equipped W_AutoGun</param>
    public void FireAuto(W_AutoGun auto)
    {
        // Fire rate and ammo check
        if (Time.time > fireRateTimeStamp + auto.fireRate && ammoRemaining[auto] > 0)
        {
            // Updates fire rate and ammo
            fireRateTimeStamp   = Time.time;
            reloadRateTimeStamp = Time.time;
            ReduceAmmo(1);
            AchievementManager.Instance().OnEvent(AchievementType.shotsFired, 1, WeaponType.auto);

            // Calculates bullet path and draws ray
            Vector3 bulletPath = barrel.transform.up + new Vector3(Random.Range(-auto.spreadRange, auto.spreadRange), Random.Range(-auto.spreadRange, auto.spreadRange));
            ///Debug.DrawRay(barrel.transform.position, bulletPath * 1000f, Color.green, 1);


            // Raycasts bullet path
            if (Physics.Raycast(barrel.transform.position, bulletPath, out RaycastHit hit))
            {
                if (matchType == MatchType.Online)
                {
                    onlineArm.CmdDrawBullet(barrel.transform.position, hit.point);
                }
                else
                {
                    DrawBullet(barrel.transform.position, hit.point);
                }

                ///Debug.Log("HIT " + hit.collider.gameObject.name);
                if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Player"))
                {
                    float dropoffDmg = auto.bulletDamage * (Mathf.Pow(auto.dropoffMod, (hit.distance / auto.dropoffDist)));

                    Debug.Log("DMG: " + dropoffDmg + "  DIST: " + hit.distance);

                    if (hit.collider.gameObject.GetComponent <Player_Networked>() != null && matchType == MatchType.Online)
                    {
                        onlineArm.CmdAttack(hit.collider.gameObject.GetComponent <Player_Networked>(), dropoffDmg, player.GetPlayerID(), bulletPath.normalized * auto.bulletPushback, WeaponType.auto);
                    }
                    else if (hit.collider.gameObject.GetComponent <Player>() != null)
                    {
                        Attack(hit.collider.gameObject.GetComponent <Player>(), dropoffDmg, player.GetPlayerID(), bulletPath.normalized * auto.bulletPushback, WeaponType.auto);
                    }
                    //else if (hit.collider.gameObject.GetComponent<Player_AI>() != null)
                    //    Attack_AI(hit.collider.gameObject.GetComponent<Player_AI>(), auto.bulletDamage, player.GetPlayerID(), bulletPath.normalized * auto.bulletPushback, WeaponType.auto);
                }
            }

            // Pushes player
            player.EnactForce(bulletPath.normalized * -auto.recoil);
        }
    }
Пример #3
0
    // Start is called before the first frame update
    void Start()
    {
        lastVisitedMenu = MainMenu;

        foreach (Transform child in menuGroup.transform)
        {
            menuList.Add(child.gameObject);
        }

        // Clear selected object
        EventSystem.current.SetSelectedGameObject(null);
        // Set button to MainFirst
        EventSystem.current.SetSelectedGameObject(mainFirstButton);

        // Go through all register Achievements
        foreach (Achievement a in AchievementManager.Instance().achievements)
        {
            // Create a GameObject based on achDisplay prefab
            GameObject curr = Instantiate(achievementPrefab, achievementContent.transform);

            MakeDisplay(curr, a);
        }

        // Set up Weapon loadout
        order = new Dictionary <string, Dictionary <WeaponRarity, List <Weapon> > >();
        // Dictionary 1 - Type { Auto = 0, Semi = 1, Launcher = 2, Sprayer = 3, ... }
        for (int i = 0; i < System.Enum.GetValues(typeof(WeaponType)).Length - 1; i++)  // - 1 gets rid of "none" from enum
        {
            switch (i)
            {
            case 0:
                order.Add("Automatic", new Dictionary <WeaponRarity, List <Weapon> >());
                break;

            case 1:
                order.Add("Semiautomatic", new Dictionary <WeaponRarity, List <Weapon> >());
                break;

            case 2:
                order.Add("Launcher", new Dictionary <WeaponRarity, List <Weapon> >());
                break;

            case 3:
                order.Add("Sprayer", new Dictionary <WeaponRarity, List <Weapon> >());
                break;

            default:
                Debug.LogError("Something went wrong");
                break;
            }
            // Dictionary 2 - Rarity { Common = 0, Uncommon = 1, Rare = 2, Legenday = 3 }
            foreach (WeaponRarity rarity in System.Enum.GetValues(typeof(WeaponRarity)))
            {
                string type = "";
                switch (i)
                {
                case 0:
                    type = "Automatic";
                    break;

                case 1:
                    type = "Semiautomatic";
                    break;

                case 2:
                    type = "Launcher";
                    break;

                case 3:
                    type = "Sprayer";
                    break;

                default:
                    Debug.LogError("Something went wrong");
                    break;
                }
                order[type].Add(rarity, new List <Weapon>());
            }
        }

        // Load weapons
        WeaponManager.Instance().LoadLoadout();

        // Sort through existing Weapons
        List <Weapon> allWeapons = WeaponManager.Instance().weapons;

        foreach (Weapon w in allWeapons)
        {
            WeaponRarity wr = w.rarity;

            if (w is W_AutoGun) // ordering[0]
            {
                switch (wr)
                {
                case WeaponRarity.Common:
                    order["Automatic"][WeaponRarity.Common].Add(w);
                    break;

                case WeaponRarity.Uncommon:
                    order["Automatic"][WeaponRarity.Uncommon].Add(w);
                    break;

                case WeaponRarity.Rare:
                    order["Automatic"][WeaponRarity.Rare].Add(w);
                    break;

                case WeaponRarity.Legendary:
                    order["Automatic"][WeaponRarity.Rare].Add(w);
                    break;

                default:
                    Debug.LogError("Auto weapon does not have listed rarity");
                    break;
                }
            }
            else if (w is W_SemiGun) // ordering[1]
            {
                switch (wr)
                {
                case WeaponRarity.Common:
                    order["Semiautomatic"][WeaponRarity.Common].Add(w);
                    break;

                case WeaponRarity.Uncommon:
                    order["Semiautomatic"][WeaponRarity.Uncommon].Add(w);
                    break;

                case WeaponRarity.Rare:
                    order["Semiautomatic"][WeaponRarity.Rare].Add(w);
                    break;

                case WeaponRarity.Legendary:
                    order["Semiautomatic"][WeaponRarity.Legendary].Add(w);
                    break;

                default:
                    Debug.LogError("Semi weapon does not have listed rarity");
                    break;
                }
            }
            else if (w is W_Launcher) // ordering[2]
            {
                switch (wr)
                {
                case WeaponRarity.Common:
                    order["Launcher"][WeaponRarity.Common].Add(w);
                    break;

                case WeaponRarity.Uncommon:
                    order["Launcher"][WeaponRarity.Uncommon].Add(w);
                    break;

                case WeaponRarity.Rare:
                    order["Launcher"][WeaponRarity.Rare].Add(w);
                    break;

                case WeaponRarity.Legendary:
                    order["Launcher"][WeaponRarity.Legendary].Add(w);
                    break;

                default:
                    Debug.LogError("Launcher weapon does not have listed rarity");
                    break;
                }
            }
            else if (w is W_Sprayer) // ordering[3]
            {
                switch (wr)
                {
                case WeaponRarity.Common:
                    order["Sprayer"][WeaponRarity.Common].Add(w);
                    break;

                case WeaponRarity.Uncommon:
                    order["Sprayer"][WeaponRarity.Uncommon].Add(w);
                    break;

                case WeaponRarity.Rare:
                    order["Sprayer"][WeaponRarity.Rare].Add(w);
                    break;

                case WeaponRarity.Legendary:
                    order["Sprayer"][WeaponRarity.Legendary].Add(w);
                    break;

                default:
                    Debug.LogError("Sprayer weapon does not have listed rarity");
                    break;
                }
            }
        }   // Done with Sorting

        // Set the Maxes
        GetMaxes();

        // Construct the display
        foreach (KeyValuePair <string, Dictionary <WeaponRarity, List <Weapon> > > type in order)
        {
            // Create group
            GameObject typeGroup = Instantiate(groupPrefab, weaponContent.transform);

            // Put name in group
            typeGroup.transform.Find("Weapon Type").Find("Text").GetComponent <Text>().text = type.Key;

            // Get area for Weapons
            Transform weaponList = typeGroup.transform.Find("Weapons");

            foreach (KeyValuePair <WeaponRarity, List <Weapon> > rarity in type.Value)
            {
                Color background;
                switch (rarity.Key)
                {
                case WeaponRarity.Common:
                    background = Color.white;
                    break;

                case WeaponRarity.Uncommon:
                    background = Color.green;
                    break;

                case WeaponRarity.Rare:
                    background = Color.blue;
                    break;

                case WeaponRarity.Legendary:
                    background = Color.magenta;
                    break;

                default:
                    background = Color.black;
                    break;
                }

                foreach (Weapon w in rarity.Value)
                {
                    // Create Weapon Display
                    GameObject weapon = Instantiate(weaponPrefab, weaponList);
                    weapon.GetComponent <Button>().onClick.AddListener(() => ChooseWeapon(w));
                    if (!w.unlocked)
                    {
                        weapon.GetComponent <Button>().interactable = false;
                    }
                    weaponButtons.Add(weapon);

                    // Set Weapon & stats
                    WeaponButtonContatiner wbc = weapon.transform.GetComponent <WeaponButtonContatiner>();
                    wbc.weapon = w;
                    // assign attributes
                    if (w is W_AutoGun)
                    {
                        W_AutoGun auto = (W_AutoGun)w;
                        wbc.damage       = auto.bulletDamage;
                        wbc.recoil       = auto.recoil;
                        wbc.pushback     = auto.bulletPushback;
                        wbc.variable     = 1f / auto.fireRate;
                        wbc.ammoCapacity = auto.ammoCapacity;
                        wbc.reloadSpeed  = 1f / auto.reloadRate;
                    }
                    else if (w is W_SemiGun)
                    {
                        W_SemiGun semi = (W_SemiGun)w;
                        wbc.damage       = semi.bulletDamage;
                        wbc.recoil       = semi.recoil;
                        wbc.pushback     = semi.bulletPushback;
                        wbc.variable     = semi.burstCount;
                        wbc.ammoCapacity = semi.ammoCapacity;
                        wbc.reloadSpeed  = 1f / semi.reloadRate;
                    }
                    else if (w is W_Launcher)
                    {
                        W_Launcher launcher = (W_Launcher)w;
                        wbc.damage       = launcher.coreDamage;
                        wbc.recoil       = launcher.recoil;
                        wbc.pushback     = launcher.corePushback;
                        wbc.variable     = launcher.projectilePower;
                        wbc.ammoCapacity = launcher.ammoCapacity;
                        wbc.reloadSpeed  = 1f / launcher.reloadRate;
                    }
                    else if (w is W_Sprayer)
                    {
                        W_Sprayer sprayer = (W_Sprayer)w;
                        wbc.damage       = sprayer.bulletDamage;
                        wbc.recoil       = sprayer.recoil;
                        wbc.pushback     = sprayer.bulletPushback;
                        wbc.variable     = sprayer.sprayDistance;
                        wbc.ammoCapacity = sprayer.ammoCapacity;
                        wbc.reloadSpeed  = 1f / sprayer.reloadRate;
                    }

                    // Set image
                    weapon.transform.Find("Image").GetComponent <Image>().sprite = w.icon;

                    // Set Rarity
                    weapon.GetComponent <Image>().color = background;
                }
            }
        }
    }
Пример #4
0
    public void OnPlayerJoined(PlayerInput loadoutLayout)
    {
        int playerId = MenuManager.Instance().numPlayers++;

        loadoutLayout.GetComponent <TempFix>().playerId = playerId;

        // Put layout in correct spot
        loadoutLayout.transform.SetParent(transform, false);
        loadoutLayout.gameObject.name = "Player Loadout " + playerId;

        // set button onClick()'s
        // Back Arm
        Transform backArm = loadoutLayout.transform.Find("Loadouts").Find("Back Arm Loadout");

        backArm.Find("Weapon A").GetComponent <Button>().onClick.AddListener(() => DisplayWeapons(playerId + "BA"));
        backArm.Find("Weapon B").GetComponent <Button>().onClick.AddListener(() => DisplayWeapons(playerId + "BB"));
        backArm.Find("Weapon C").GetComponent <Button>().onClick.AddListener(() => DisplayWeapons(playerId + "BC"));
        backArm.Find("Weapon D").GetComponent <Button>().onClick.AddListener(() => DisplayWeapons(playerId + "BD"));
        // Front Arm
        Transform frontArm = loadoutLayout.transform.Find("Loadouts").Find("Front Arm Loadout");

        frontArm.Find("Weapon A").GetComponent <Button>().onClick.AddListener(() => DisplayWeapons(playerId + "FA"));
        frontArm.Find("Weapon B").GetComponent <Button>().onClick.AddListener(() => DisplayWeapons(playerId + "FB"));
        frontArm.Find("Weapon C").GetComponent <Button>().onClick.AddListener(() => DisplayWeapons(playerId + "FC"));
        frontArm.Find("Weapon D").GetComponent <Button>().onClick.AddListener(() => DisplayWeapons(playerId + "FD"));

        WeaponManager.Instance().LoadLoadout();

        // Update Loadouts
        for (int i = 0; i < WeaponManager.Instance().playerLoadouts[playerId][0].Length; i++)
        {
            backArm.GetChild(i + 1).Find("Image").GetComponent <Image>().sprite  = WeaponManager.Instance().playerLoadouts[playerId][0][i].icon;
            frontArm.GetChild(i + 1).Find("Image").GetComponent <Image>().sprite = WeaponManager.Instance().playerLoadouts[playerId][1][i].icon;
        }

        Dictionary <string, Dictionary <WeaponRarity, List <Weapon> > > order = MenuManager.Instance().order;

        // Check that Display not already made
        if (weaponButtons.ContainsKey(playerId))
        {
            return;
        }
        // Construct the display
        List <GameObject> temp = new List <GameObject>();

        foreach (KeyValuePair <string, Dictionary <WeaponRarity, List <Weapon> > > type in order)
        {
            // Create group
            Transform  weaponContent = loadoutLayout.transform.Find("Selection").Find("Scroll View").Find("Viewport").Find("Content");
            GameObject typeGroup     = Instantiate(groupPrefab, weaponContent);

            // Put name in group
            typeGroup.transform.Find("Weapon Type").Find("Text").GetComponent <Text>().text = type.Key;

            // Get area for Weapons
            Transform weaponList = typeGroup.transform.Find("Weapons");

            foreach (KeyValuePair <WeaponRarity, List <Weapon> > rarity in type.Value)
            {
                Color background;
                switch (rarity.Key)
                {
                case WeaponRarity.Common:
                    background = Color.white;
                    break;

                case WeaponRarity.Uncommon:
                    background = Color.green;
                    break;

                case WeaponRarity.Rare:
                    background = Color.blue;
                    break;

                case WeaponRarity.Legendary:
                    background = Color.magenta;
                    break;

                default:
                    background = Color.black;
                    break;
                }

                foreach (Weapon w in rarity.Value)
                {
                    // Create Weapon Display
                    GameObject weapon = Instantiate(weaponPrefab, weaponList);
                    weapon.GetComponent <Button>().onClick.AddListener(() => ChooseWeapon(playerId, w));
                    if (!w.unlocked)
                    {
                        weapon.GetComponent <Button>().interactable = false;
                    }
                    temp.Add(weapon);

                    // Set Weapon & stats
                    WeaponButtonContatiner wbc = weapon.transform.GetComponent <WeaponButtonContatiner>();
                    wbc.weapon = w;
                    // assign attributes
                    if (w is W_AutoGun)
                    {
                        W_AutoGun auto = (W_AutoGun)w;
                        wbc.damage       = auto.bulletDamage;
                        wbc.recoil       = auto.recoil;
                        wbc.pushback     = auto.bulletPushback;
                        wbc.variable     = 1f / auto.fireRate;
                        wbc.ammoCapacity = auto.ammoCapacity;
                        wbc.reloadSpeed  = 1f / auto.reloadRate;
                    }
                    else if (w is W_SemiGun)
                    {
                        W_SemiGun semi = (W_SemiGun)w;
                        wbc.damage       = semi.bulletDamage;
                        wbc.recoil       = semi.recoil;
                        wbc.pushback     = semi.bulletPushback;
                        wbc.variable     = 1f / semi.burstCount;
                        wbc.ammoCapacity = semi.ammoCapacity;
                        wbc.reloadSpeed  = 1f / semi.reloadRate;
                    }
                    else if (w is W_Launcher)
                    {
                        W_Launcher launcher = (W_Launcher)w;
                        wbc.damage       = launcher.coreDamage;
                        wbc.recoil       = launcher.recoil;
                        wbc.pushback     = launcher.corePushback;
                        wbc.variable     = 1f / launcher.projectilePower;
                        wbc.ammoCapacity = launcher.ammoCapacity;
                        wbc.reloadSpeed  = 1f / launcher.reloadRate;
                    }
                    else if (w is W_Sprayer)
                    {
                        W_Sprayer sprayer = (W_Sprayer)w;
                        wbc.damage       = sprayer.bulletDamage;
                        wbc.recoil       = sprayer.recoil;
                        wbc.pushback     = sprayer.bulletPushback;
                        wbc.variable     = 1f / sprayer.sprayDistance;
                        wbc.ammoCapacity = sprayer.ammoCapacity;
                        wbc.reloadSpeed  = 1f / sprayer.reloadRate;
                    }

                    // Set image
                    weapon.transform.Find("Image").GetComponent <Image>().sprite = w.icon;

                    // Set Rarity
                    weapon.GetComponent <Image>().color = background;
                }
            }
        }

        weaponButtons.Add(playerId, temp);
    }