예제 #1
0
        /// <summary>
        /// Call this to trigger the spawning of the loot. Will spawn one item per event, picking the item randomly
        /// per event using the defined weight. Every call will pick randomly again (but most of the time, the caller
        /// will destroy the LootSpawner too as you spawn loot from something only once)
        /// </summary>
        public void SpawnLoot()
        {
            Vector3 position = transform.position;

            SFXManager.PlaySound(SFXManager.Use.WorldSound, new SFXManager.PlayData()
            {
                Clip     = SpawnedClip,
                Position = position
            });

            //we go over all the events.
            for (int i = 0; i < Events.Length; ++i)
            {
                SpawnEvent Event = Events[i];

                //first iterate over all object to make a total weight value.
                int totalWeight = 0;
                foreach (var entry in Event.Entries)
                {
                    totalWeight += entry.Weight;
                }

                //if we don't have any weight just exit
                if (totalWeight == 0)
                {
                    continue;
                }

                //then go back again on all the object to build a lookup table based on percentage.
                List <InternalPurcentageEntry> lookupTable = new List <InternalPurcentageEntry>();
                float previousPercent = 0.0f;
                foreach (var entry in Event.Entries)
                {
                    float percent = entry.Weight / (float)totalWeight;
                    InternalPurcentageEntry percentageEntry = new InternalPurcentageEntry();
                    percentageEntry.Entry      = entry;
                    percentageEntry.Percentage = previousPercent + percent;

                    previousPercent = percentageEntry.Percentage;

                    lookupTable.Add(percentageEntry);
                }

                float rng = Random.value;
                for (int k = 0; k < lookupTable.Count; ++k)
                {
                    if (rng <= lookupTable[k].Percentage)
                    {
                        GameObject obj = new GameObject(lookupTable[k].Entry.Item.ItemName);
                        //GameObject obj = Instantiate(lookupTable[k].Entry.Item.WorldObjectPrefab);
                        var l = obj.AddComponent <Loot>();
                        l.Item = lookupTable[k].Entry.Item;

                        l.Spawn(position);

                        break;
                    }
                }
            }
        }
예제 #2
0
        public AudioClip GetSwingSound()
        {
            if (SwingSounds == null || SwingSounds.Length == 0)
            {
                return(SFXManager.GetDefaultSwingSound());
            }

            return(SwingSounds[Random.Range(0, SwingSounds.Length)]);
        }
예제 #3
0
        public AudioClip GetHitSound()
        {
            if (HitSounds == null || HitSounds.Length == 0)
            {
                return(SFXManager.GetDefaultHit());
            }

            return(HitSounds[Random.Range(0, HitSounds.Length)]);
        }
예제 #4
0
        public override void InteractWith(CharacterData target)
        {
            target.Inventory.AddItem(Item);
            SFXManager.PlaySound(SFXManager.Use.Sound2D, new SFXManager.PlayData()
            {
                Clip = SFXManager.PickupSound
            });

            UISystem.Instance.InventoryWindow.Load(target);
            Destroy(gameObject);
        }
예제 #5
0
        void Awake()
        {
            Instance    = this;
            m_Instances = new Queue <AudioSource> [m_Prefabs.Length];
            for (int i = 0; i < m_Prefabs.Length; ++i)
            {
                m_Instances[i] = new Queue <AudioSource>();

                for (int k = 0; k < m_PoolAmount[i]; ++k)
                {
                    var audioSource = Instantiate(m_Prefabs[i]);

                    m_Instances[i].Enqueue(audioSource);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Damage the Character by the AttackData given as parameter. See the documentation for that class for how to
        /// add damage to that attackData. (this will be done automatically by weapons, but you may need to fill it
        /// manually when writing special elemental effect)
        /// </summary>
        /// <param name="attackData"></param>
        public void Damage(Weapon.AttackData attackData)
        {
            if (HitClip.Length != 0)
            {
                SFXManager.PlaySound(SFXManager.Use.Player, new SFXManager.PlayData()
                {
                    Clip     = HitClip[Random.Range(0, HitClip.Length)],
                    PitchMax = 1.1f,
                    PitchMin = 0.8f,
                    Position = transform.position
                });
            }

            Stats.Damage(attackData);

            OnDamage?.Invoke();
        }