/// <summary>
        /// Get texture archive index based on gender.
        /// Assigns random gender for humans enemies with unspecified gender.
        /// </summary>
        /// <returns>Texture archive index.</returns>
        private int GetTextureArchive()
        {
            // If human with unspecified gender then randomise gender
            if (summary.Enemy.Affinity == MobileAffinity.Human && summary.Enemy.Gender == MobileGender.Unspecified)
            {
                if (DFRandom.random_range(0, 2) == 0)
                {
                    summary.Enemy.Gender = MobileGender.Male;
                }
                else
                {
                    summary.Enemy.Gender = MobileGender.Female;
                }
            }

            // Monster genders are always unspecified as there is no male/female variant
            if (summary.Enemy.Gender == MobileGender.Male || summary.Enemy.Gender == MobileGender.Unspecified)
            {
                return(summary.Enemy.MaleTexture);
            }
            else
            {
                return(summary.Enemy.FemaleTexture);
            }
        }
        void OnGUI()
        {
            if (!IsReady())
            {
                EditorGUILayout.HelpBox("DaggerfallUnity instance not ready. Have you set your Arena2 path?", MessageType.Info);
                return;
            }

            EditorGUILayout.Space();
            bankType = (NameHelper.BankTypes)EditorGUILayout.EnumPopup(new GUIContent("Type"), bankType);
            gender   = (Genders)EditorGUILayout.EnumPopup(new GUIContent("Gender"), gender);
            seed     = EditorGUILayout.IntField(new GUIContent("Seed"), seed);
            count    = EditorGUILayout.IntField(new GUIContent("Count"), count);
            if (GUILayout.Button("Generate Names"))
            {
                if (seed != -1)
                {
                    DFRandom.srand(seed);
                }

                generatedNames.Clear();
                for (int i = 0; i < count; i++)
                {
                    generatedNames.Add(nameHelper.FullName(bankType, gender));
                }
            }

            scrollPos = GUILayoutHelper.ScrollView(scrollPos, () =>
            {
                for (int i = 0; i < generatedNames.Count; i++)
                {
                    EditorGUILayout.SelectableLabel(generatedNames[i], EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                }
            });
        }
        public static int[] RandomTextureTableClassic(int seed, int randomDungeonTextures = 0)
        {
            byte[]  climateTextureArchiveIndices = { 0, 0, 1, 4, 4, 0, 3, 3, 3, 0 };
            short[] climateTextureArchives;
            if (randomDungeonTextures == 0)
            {
                climateTextureArchives = new short[] { 19, 119, 319, 419, 119 }
            }
            ;                                                                    // Values from classic, used in classic algorithm
            else
            {
                climateTextureArchives = new short[] { 19, 119, 119, 319, 419 }
            };                                                                   // Values for climate-based algorithm. Index 2 (unused) is a dummy value.

            int climate = Game.GameManager.Instance.PlayerGPS.CurrentClimateIndex;

            if (climate == (int)MapsFile.Climates.Ocean)
            {
                climate = (int)MapsFile.Climates.Swamp;
            }

            int classicIndexValue      = Game.Utility.TravelTimeCalculator.climateIndices[climate - (int)MapsFile.Climates.Ocean];
            int climateBasedIndexValue = climate - (int)MapsFile.Climates.Desert;

            int climateTextureArchiveIndex;

            if (randomDungeonTextures == 0) // classic algorithm
            {
                climateTextureArchiveIndex = climateTextureArchiveIndices[classicIndexValue];
            }
            else // climate-based algorithm
            {
                climateTextureArchiveIndex = climateTextureArchiveIndices[climateBasedIndexValue];
            }

            int textureArchiveOffset;

            DFRandom.srand(seed);
            int[] textureTable = new int[TableLength];

            // In classic, if climateTextureArchiveIndex is 1 here (only happens with rainforest climate), the following loop is skipped and
            // a dungeon in that climate will have the texture table of the last visited dungeon or, if no dungeons
            // had been visited since starting the program, the default dungeon textures. This seems like it must just be a bug, so the
            // recreation of the classic algorithm here assigns textures even if climateTextureArchiveIndex is 1.
            for (int i = 0; i < 5; ++i)
            {
                textureArchiveOffset = DFRandom.random_range_inclusive(0, 4);
                if (textureArchiveOffset == 2) // invalid
                {
                    textureArchiveOffset = 4;
                }
                textureTable[i] = climateTextureArchives[climateTextureArchiveIndex] + textureArchiveOffset;
            }

            textureTable[5] = (int)DFLocation.ClimateTextureSet.Interior_Sewer + 100 * climateTextureArchiveIndices[climateBasedIndexValue];
            return(textureTable);
        }
        void FixedUpdate()
        {
            // Clip needs to be loaded before it can be played.
            // Only try to apply a valid index range.
            if (audioClip == null && SoundIndex >= minIndex && SoundIndex < maxIndex)
            {
                Apply();
            }

            // Handle player checks
            if (playerCheck && audioSource && player)
            {
                bool playerInRange = (Vector3.Distance(transform.position, player.transform.position) <= audioSource.maxDistance);

                audioSource.enabled = playerInRange;
                // Allows volume to be adjusted without reloading game.
                audioSource.volume = DaggerfallUnity.Settings.SoundVolume;

                // Handle random play
                if (audioSource.enabled && playRandomly)
                {
                    bool classicUpdate = false;

                    if (classicUpdateTimer < Game.Entity.PlayerEntity.ClassicUpdateInterval)
                    {
                        classicUpdateTimer += Time.deltaTime;
                    }
                    else
                    {
                        classicUpdateTimer = 0;
                        classicUpdate      = true;
                    }

                    if (classicUpdate && DFRandom.rand() <= 100)
                    {
                        audioSource.Play();
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void StockHouseContainer(PlayerGPS.DiscoveredBuilding buildingData)
        {
            stockedDate = CreateStockedDate(DaggerfallUnity.Instance.WorldTime.Now);
            items.Clear();

            DFLocation.BuildingTypes buildingType = buildingData.buildingType;
            uint modelIndex = (uint)TextureRecord;

            //int buildingQuality = buildingData.quality;
            byte[] privatePropertyList = null;
            DaggerfallUnityItem item   = null;

            Game.Entity.PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;

            if (buildingType < DFLocation.BuildingTypes.House5)
            {
                if (modelIndex >= 2)
                {
                    if (modelIndex >= 4)
                    {
                        if (modelIndex >= 11)
                        {
                            if (modelIndex >= 15)
                            {
                                privatePropertyList = DaggerfallLootDataTables.privatePropertyItemsModels15AndUp[(int)buildingType];
                            }
                            else
                            {
                                privatePropertyList = DaggerfallLootDataTables.privatePropertyItemsModels11to14[(int)buildingType];
                            }
                        }
                        else
                        {
                            privatePropertyList = DaggerfallLootDataTables.privatePropertyItemsModels4to10[(int)buildingType];
                        }
                    }
                    else
                    {
                        privatePropertyList = DaggerfallLootDataTables.privatePropertyItemsModels2to3[(int)buildingType];
                    }
                }
                else
                {
                    privatePropertyList = DaggerfallLootDataTables.privatePropertyItemsModels0to1[(int)buildingType];
                }
                if (privatePropertyList == null)
                {
                    return;
                }
                int        randomChoice   = Random.Range(0, privatePropertyList.Length);
                ItemGroups itemGroup      = (ItemGroups)privatePropertyList[randomChoice];
                int        continueChance = 100;
                bool       keepGoing      = true;
                while (keepGoing)
                {
                    if (itemGroup != ItemGroups.MensClothing && itemGroup != ItemGroups.WomensClothing)
                    {
                        if (itemGroup == ItemGroups.MagicItems)
                        {
                            item = ItemBuilder.CreateRandomMagicItem(playerEntity.Level, playerEntity.Gender, playerEntity.Race);
                        }
                        else if (itemGroup == ItemGroups.Books)
                        {
                            item = ItemBuilder.CreateRandomBook();
                        }
                        else
                        {
                            if (itemGroup == ItemGroups.Weapons)
                            {
                                item = ItemBuilder.CreateRandomWeapon(playerEntity.Level);
                            }
                            else if (itemGroup == ItemGroups.Armor)
                            {
                                item = ItemBuilder.CreateRandomArmor(playerEntity.Level, playerEntity.Gender, playerEntity.Race);
                            }
                            else
                            {
                                System.Array enumArray = DaggerfallUnity.Instance.ItemHelper.GetEnumArray(itemGroup);
                                item = new DaggerfallUnityItem(itemGroup, Random.Range(0, enumArray.Length));
                            }
                        }
                    }
                    else
                    {
                        item = ItemBuilder.CreateRandomClothing(playerEntity.Gender, playerEntity.Race);
                    }
                    continueChance >>= 1;
                    if (DFRandom.rand() % 100 > continueChance)
                    {
                        keepGoing = false;
                    }
                    items.AddItem(item);
                }
            }
        }