Esempio n. 1
0
        /// <summary>
        /// Generates loot for Items and GOs.
        /// </summary>
        /// <param name="lootable">The Object or Unit that is being looted</param>
        /// <returns>The object's loot or null if there is nothing to get or the given Character can't access the loot.</returns>
        public static Asda2ObjectLoot CreateAndSendObjectLoot(IAsda2Lootable lootable, Character initialLooter,
                                                              Asda2LootEntryType type)
        {
            var oldLoot = initialLooter.LooterEntry.Loot;

            if (oldLoot != null)
            {
                oldLoot.ForceDispose();
            }
            var looters = FindLooters(lootable, initialLooter);

            var loot = CreateLoot <Asda2ObjectLoot>(lootable, initialLooter, type, 0); // TODO: pass mapid

            if (loot != null)
            {
                initialLooter.LooterEntry.Loot = loot;
                loot.Initialize(initialLooter, looters, 0); // TODO: pass mapid
                //LootHandler.SendLootResponse(initialLooter, loot);
            }
            else
            {
                //lootable.OnFinishedLooting();
                // empty Item -> Don't do anything
            }
            return(loot);
        }
Esempio n. 2
0
        public static List <Asda2LootItemEntry> GetEntries(Asda2LootEntryType type, uint id)
        {
            var entries = LootEntries[(uint)type];
            var list    = entries.Get(id);

            return(list);
        }
Esempio n. 3
0
 public override uint GetLootId(Asda2LootEntryType type)
 {
     if (m_entry is IGOLootableEntry)
     {
         return(((IGOLootableEntry)m_entry).LootId);
     }
     return(0);
 }
Esempio n. 4
0
 public override uint GetLootId(Asda2LootEntryType lootType)
 {
     switch (lootType)
     {
     case Asda2LootEntryType.Npc:
         return(Template.Id);
     }
     return(0);
 }
Esempio n. 5
0
        /// <summary>
        /// Returns all Items that can be looted off the given lootable
        /// </summary>
        public static Asda2LootItem[] CreateLootItems(uint lootId, Asda2LootEntryType type, IList <Asda2LooterEntry> looters, float dropChanceBoost)
        {
#if DEBUG
            if (!Asda2ItemMgr.Loaded)
            {
                return(Asda2LootItem.EmptyArray);
            }
#endif
            var entries = GetEntries(type, lootId);
            if (entries == null)
            {
                return(Asda2LootItem.EmptyArray);
            }
            var items = new Asda2LootItem[Math.Min(CharacterFormulas.MaxLootCount, entries.Count)];
            //var i = max;
            var i = 0;
            foreach (var entry in entries)
            {
                var chance = entry.DropChance * (LootItemDropFactor + dropChanceBoost);
                if ((100 * Utility.RandomFloat()) >= chance)
                {
                    continue;
                }

                var template = entry.ItemTemplate;
                if (template == null)
                {
                    // weird
                    continue;
                }

                /*if (!looters.Any(looter => template.CheckLootConstraints(looter.Owner)))
                 * {
                 *  continue;
                 * }*/

                items[i] = new Asda2LootItem(template,
                                             Utility.Random(entry.MinAmount, entry.MaxAmount),
                                             (uint)i);
                i++;

                if (i == CharacterFormulas.MaxLootCount)
                {
                    break;
                }
            }

            if (i == 0)
            {
                return(Asda2LootItem.EmptyArray);
            }

            Array.Resize(ref items, i);
            return(items);
        }
Esempio n. 6
0
 protected static void AddItems <T>(Asda2LootEntryType t, List <T> all) where T : Asda2LootItemEntry
 {
     foreach (List <Asda2LootItemEntry> entry in Asda2LootMgr.GetEntries(t))
     {
         if (entry != null)
         {
             foreach (Asda2LootItemEntry asda2LootItemEntry in entry)
             {
                 all.Add((T)asda2LootItemEntry);
             }
         }
     }
 }
Esempio n. 7
0
        protected static void AddItems <T>(Asda2LootEntryType t, List <T> all)
            where T : Asda2LootItemEntry
        {
            var entries = Asda2LootMgr.GetEntries(t);

            foreach (var list in entries)
            {
                if (list != null)
                {
                    foreach (var entry in list)
                    {
                        all.Add((T)entry);
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>Generates loot for Items and GOs.</summary>
        /// <param name="lootable">The Object or Unit that is being looted</param>
        /// <returns>The object's loot or null if there is nothing to get or the given Character can't access the loot.</returns>
        public static Asda2ObjectLoot CreateAndSendObjectLoot(IAsda2Lootable lootable, Character initialLooter,
                                                              Asda2LootEntryType type)
        {
            Asda2Loot loot1 = initialLooter.LooterEntry.Loot;

            if (loot1 != null)
            {
                loot1.ForceDispose();
            }
            IList <Asda2LooterEntry> looters = Asda2LootMgr.FindLooters(lootable, initialLooter);
            Asda2ObjectLoot          loot2   =
                Asda2LootMgr.CreateLoot <Asda2ObjectLoot>(lootable, initialLooter, type, MapId.Silaris);

            if (loot2 != null)
            {
                initialLooter.LooterEntry.Loot = (Asda2Loot)loot2;
                loot2.Initialize(initialLooter, looters, MapId.Silaris);
            }

            return(loot2);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns all Items that can be looted off the given lootable
        /// </summary>
        public static Asda2LootItem[] CreateLootItems(uint lootId, Asda2LootEntryType type,
                                                      IList <Asda2LooterEntry> looters, float dropChanceBoost)
        {
            List <Asda2LootItemEntry> entries = Asda2LootMgr.GetEntries(type, lootId);

            if (entries == null)
            {
                return(Asda2LootItem.EmptyArray);
            }
            Asda2LootItem[] array   = new Asda2LootItem[Math.Min(CharacterFormulas.MaxLootCount, entries.Count)];
            int             newSize = 0;

            foreach (Asda2LootItemEntry asda2LootItemEntry in entries)
            {
                if (100.0 * (double)Utility.RandomFloat() <
                    (double)(asda2LootItemEntry.DropChance * (Asda2LootMgr.LootItemDropFactor + dropChanceBoost)))
                {
                    Asda2ItemTemplate itemTemplate = asda2LootItemEntry.ItemTemplate;
                    if (itemTemplate != null)
                    {
                        array[newSize] = new Asda2LootItem(itemTemplate,
                                                           Utility.Random(asda2LootItemEntry.MinAmount, asda2LootItemEntry.MaxAmount), (uint)newSize);
                        ++newSize;
                        if (newSize == CharacterFormulas.MaxLootCount)
                        {
                            break;
                        }
                    }
                }
            }

            if (newSize == 0)
            {
                return(Asda2LootItem.EmptyArray);
            }
            Array.Resize <Asda2LootItem>(ref array, newSize);
            return(array);
        }
Esempio n. 10
0
 public override uint GetLootId(Asda2LootEntryType type)
 {
     return(m_template.Id);
 }
Esempio n. 11
0
        /// <summary>
        /// Whether the given lootable contains quest items for the given Character when looting with the given type
        /// </summary>
        public static bool ContainsQuestItemsFor(this IAsda2Lootable lootable, Character chr, Asda2LootEntryType type)
        {
            Asda2Loot loot = lootable.Loot;

            if (loot != null)
            {
                return(((IEnumerable <Asda2LootItem>)loot.Items).Any <Asda2LootItem>((Func <Asda2LootItem, bool>)(item =>
                {
                    if (item.Template.HasQuestRequirements)
                    {
                        return item.Template.CheckQuestConstraints(chr);
                    }
                    return false;
                })));
            }
            List <Asda2LootItemEntry> entries = lootable.GetEntries(type);

            if (entries != null)
            {
                return(entries.Any <Asda2LootItemEntry>((Func <Asda2LootItemEntry, bool>)(entry =>
                {
                    if (entry.ItemTemplate.HasQuestRequirements)
                    {
                        return entry.ItemTemplate.CheckQuestConstraints(chr);
                    }
                    return false;
                })));
            }
            return(false);
        }
Esempio n. 12
0
 public static List <Asda2LootItemEntry> GetEntries(this IAsda2Lootable lootable, Asda2LootEntryType type)
 {
     return(Asda2LootMgr.GetEntries(type, lootable.GetLootId(type)));
 }
Esempio n. 13
0
        /// <summary>
        /// Generates normal loot (usually for dead mob-corpses).
        /// Returns null, if the loot is empty.
        /// </summary>
        /// <param name="lootable">The Object or Unit that is being looted</param>
        public static Asda2Loot GetOrCreateLoot(IAsda2Lootable lootable, Character triggerChar, Asda2LootEntryType type)
        {
            Asda2Loot loot = lootable.Loot;

            if (loot != null)
            {
                if (loot.IsMoneyLooted && loot.RemainingCount == 0)
                {
                    return((Asda2Loot)null);
                }
                loot.Looters.Clear();
            }
            else
            {
                lootable.Loot = loot =
                    (Asda2Loot)Asda2LootMgr.CreateLoot <Asda2NPCLoot>(lootable, triggerChar, type, MapId.Silaris);
            }

            return(loot);
        }
Esempio n. 14
0
        /// <summary>
        /// Creates a new Loot object and returns it or null, if there is nothing to be looted.
        /// </summary>
        /// <typeparam name="T"><see cref="ObjectLoot"/> or <see cref="NPCLoot"/></typeparam>
        /// <param name="lootable"></param>
        /// <param name="initialLooter"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static T CreateLoot <T>(IAsda2Lootable lootable, Character initialLooter, Asda2LootEntryType type, MapId mapid)
            where T : Asda2Loot, new()
        {
            var looters = FindLooters(lootable, initialLooter);

            var dropChanceBoost = 0f;
            var goldAmountBoost = 0f;

            foreach (var asda2LootItemEntry in looters)
            {
                dropChanceBoost += asda2LootItemEntry.Owner.Asda2DropChance - 1;
                goldAmountBoost += goldAmountBoost + asda2LootItemEntry.Owner.Asda2GoldAmountBoost - 1;
            }
            var items = CreateLootItems(lootable.GetLootId(type), type, looters, dropChanceBoost);
            var money = lootable.LootMoney * (DefaultMoneyDropFactor + goldAmountBoost);

            if (items.Length == 0 && money == 0)
            {
                if (lootable is GameObject)
                {
                    // TODO: Don't mark GO as lootable if it has nothing to loot
                    money = 1;
                }
            }

            if (items.Length > 0 || money > 0)
            {
                var loot = new T {
                    Lootable = lootable, Money = (uint)(money > UInt32.MaxValue ? 1 : money), Items = items
                };
                foreach (var asda2LootItem in items)
                {
                    asda2LootItem.Loot = loot;
                }
                loot.Initialize(initialLooter, looters, mapid);
                return(loot);
            }
            else
            {
                //var loot = new T { Lootable = lootable, Money = 1, Items = LootItem.EmptyArray };
                //loot.Initialize(initialLooter, looters);
                //return loot;
                return(null);
            }
        }
Esempio n. 15
0
 public static List <Asda2LootItemEntry>[] GetEntries(Asda2LootEntryType type)
 {
     return(Asda2LootMgr.LootEntries[(uint)type]);
 }
Esempio n. 16
0
 public virtual uint GetLootId(Asda2LootEntryType type)
 {
     return(0);
 }
Esempio n. 17
0
        /// <summary>
        /// Whether the given lootable contains quest items for the given Character when looting with the given type
        /// </summary>
        public static bool ContainsQuestItemsFor(this IAsda2Lootable lootable, Character chr, Asda2LootEntryType type)
        {
            var loot = lootable.Loot;

            if (loot != null)
            {
                // loot has already been created
                return(loot.Items.Any(item => item.Template.HasQuestRequirements && item.Template.CheckQuestConstraints(chr)));
            }

            // no loot yet -> check what happens if we create any
            var entries = lootable.GetEntries(type);

            if (entries != null)
            {
                return(entries.Any(entry => entry.ItemTemplate.HasQuestRequirements && entry.ItemTemplate.CheckQuestConstraints(chr)));
            }
            return(false);
        }
Esempio n. 18
0
        /// <summary>
        /// Creates a new Loot object and returns it or null, if there is nothing to be looted.
        /// </summary>
        /// <typeparam name="T"><see cref="T:WCell.RealmServer.Looting.ObjectLoot" /> or <see cref="T:WCell.RealmServer.Looting.NPCLoot" /></typeparam>
        /// <param name="lootable"></param>
        /// <param name="initialLooter"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static T CreateLoot <T>(IAsda2Lootable lootable, Character initialLooter, Asda2LootEntryType type,
                                       MapId mapid) where T : Asda2Loot, new()
        {
            IList <Asda2LooterEntry> looters = Asda2LootMgr.FindLooters(lootable, initialLooter);
            float dropChanceBoost            = 0.0f;
            float num1 = 0.0f;

            foreach (Asda2LooterEntry asda2LooterEntry in (IEnumerable <Asda2LooterEntry>)looters)
            {
                dropChanceBoost += asda2LooterEntry.Owner.Asda2DropChance - 1f;
                num1            += (float)((double)num1 + (double)asda2LooterEntry.Owner.Asda2GoldAmountBoost - 1.0);
            }

            Asda2LootItem[] lootItems =
                Asda2LootMgr.CreateLootItems(lootable.GetLootId(type), type, looters, dropChanceBoost);
            float num2 = (float)lootable.LootMoney * ((float)Asda2LootMgr.DefaultMoneyDropFactor + num1);

            if (lootItems.Length == 0 && (double)num2 == 0.0 && lootable is GameObject)
            {
                num2 = 1f;
            }
            if (lootItems.Length <= 0 && (double)num2 <= 0.0)
            {
                return(default(T));
            }
            T instance = Activator.CreateInstance <T>();

            instance.Lootable = lootable;
            instance.Money    = (double)num2 > 4294967296.0 ? 1U : (uint)num2;
            instance.Items    = lootItems;
            T obj = instance;

            foreach (Asda2LootItem asda2LootItem in lootItems)
            {
                asda2LootItem.Loot = (Asda2Loot)obj;
            }
            obj.Initialize(initialLooter, looters, mapid);
            return(obj);
        }
Esempio n. 19
0
 public static List <Asda2LootItemEntry> GetEntries(Asda2LootEntryType type, uint id)
 {
     return(Asda2LootMgr.LootEntries[(uint)type].Get <List <Asda2LootItemEntry> >(id));
 }
Esempio n. 20
0
        /// <summary>
        /// Generates normal loot (usually for dead mob-corpses).
        /// Returns null, if the loot is empty.
        /// </summary>
        /// <param name="lootable">The Object or Unit that is being looted</param>
        public static Asda2Loot GetOrCreateLoot(IAsda2Lootable lootable, Character triggerChar, Asda2LootEntryType type)
        {
            var loot = lootable.Loot;

            if (loot != null)
            {
                // apparently mob got killed a 2nd time
                if (loot.IsMoneyLooted && loot.RemainingCount == 0)
                {
                    // already looted empty
                    return(null);
                }
                loot.Looters.Clear();
            }
            else
            {
                lootable.Loot = loot = CreateLoot <Asda2NPCLoot>(lootable, triggerChar, type, 0); // TODO: pass mapid
            }

            return(loot);
        }