Ejemplo n.º 1
0
        static ItemPrefab RandomBasicSpawn()
        {
            if (MPTags.m_multiplayer_spawnable_powerups.Count > 0)
            {
                // Somewhat ugly but consistent/based on NetworkMatch.RandomAllowedMissileSpawn()
                // New algorithm
                float[] array = new float[4];
                for (int i = 0; i < MPTags.m_multiplayer_spawnable_powerups.Count; i++)
                {
                    MPTags.PowerupType type = (MPTags.PowerupType)MPTags.m_multiplayer_spawnable_powerups[i].type;
                    array[(int)type] = MPTags.m_multiplayer_spawnable_powerups[i].percent;
                }
                float num = 0f;
                for (int j = 0; j < 4; j++)
                {
                    num += array[j];
                }

                if (num > 0f)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        array[k] /= num;
                    }
                    float num2 = UnityEngine.Random.Range(0f, 1f);
                    float num3 = 0f;
                    for (int l = 0; l < 4; l++)
                    {
                        if (num2 < num3 + array[l])
                        {
                            return(PowerupTypeToPrefab((MPTags.PowerupType)l));
                        }
                        num3 += array[l];
                    }
                    Debug.Log("We had valid powerups, but couldn't choose one when spawning it");
                    return(ItemPrefab.num);
                }
            }
            else
            {
                // Original algorithm
                int num = UnityEngine.Random.Range(0, 4);
                if (NetworkMatch.AnyPlayersHaveAmmoWeapons())
                {
                    num = UnityEngine.Random.Range(0, 5);
                }
                switch (num)
                {
                case 1:
                case 2:
                    return(ItemPrefab.entity_item_energy);

                case 3:
                case 4:
                    return(ItemPrefab.entity_item_ammo);

                default:
                    return(ItemPrefab.entity_item_shields);
                }
            }

            return(ItemPrefab.num);
        }