public ItemTemplate[] GetLoot()
{
ArrayList loot = new ArrayList(m_fixedItemDrops.Count + m_dropCount);
loot.AddRange(m_fixedItemDrops);
int dice;
ArrayList lootCandidates = new ArrayList();
if ( m_dropCount != 0)
{
// Big logic change. The intended flow of the original code was to iterate over the drop list
// DropCount times, each iteration doing the following:
// 1.) clear lootCandidates array
// 2.) for each loot item in m_randomItemDrops roll D100 against frequency
// 3.) each winner gts into lootCandidates array
// 4.) pick one random winner out of lootCandidates, add to the returned loot list
// The bug reported was caused by the loot.Add being outside the main loop. only
// the last winner made it into the loot array that is returned.
// There is a secondary defect that surfaces once the loop issue is fixed. There is
// a high chance of duplicate items dropping. This is counter to live game server
// behavior.
//
// New logic iterates once accross m_randomItemDrops, rolling D100 against frequency.
// Winner items are placed into lootCandidates. Once that loop is complete, we enter
// into a second loop. In each iteration, we select one random winner from lootCandidates,
// add it the to returned loot array, then remove it from lootCandidates. This avoids
// code-induced duplicates. I imagine that ArrayList.RemoveAt() is a little expensive on cpu
// cycles as it has to collapse the array each time an item is removed. A second option is
// to build a matching array of booleans, set all to false, and each time a winner is copied
// to loot, set the value in the matching array at the same index value to true. This introduces
// the need for a nested loop to avoid true values in the matching array, and if not coded properly,
// will hang the server as it loops an infinite number of times. The third option is to ignore
// all of this, say that dupes are o.k., pull loot.Add inside the main loop of the old code
// and move on.
// new logic
lootCandidates.Clear();
foreach (LootEntry lootEntry in m_randomItemDrops)
{
dice = Util.Random(1, 100);
if (lootEntry.Chance >= dice)
lootCandidates.Add(lootEntry.ItemTemplate);
}
// At this point, the candidate list is filled with items that passed
// the %chance to drop, so we need to put DropCount of them into the return loot object.
//
// Initial control thought is to use the ArrayList.RemoveAt method and change the loop control
// to include a check on lootCandidates.Count. This assumes that the removeAt function re-builds
// the array and updates ArrayList.Count. If not, we'll be throwing exceptions like mad.
// copy random winners to returned loot list
if (lootCandidates.Count > 0)
{
for (int i = 0; (i < m_dropCount && lootCandidates.Count != 0); i++)
{
int tmpidx;
tmpidx = Util.Random(lootCandidates.Count - 1);
loot.Add(lootCandidates[tmpidx]);
lootCandidates.RemoveAt(tmpidx);
}
}
}
return (ItemTemplate[])loot.ToArray(typeof(ItemTemplate));
}
}


19:41:24,048 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - experienced necyomancer count = 24
19:41:24,048 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - arcere decaduto count = 4
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - grand chancellor adremal count = 323
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - clay jotun runner count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - dastur count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - blodfelag soothsayer count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - frit count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - virilus count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - ostadi count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Inquisitor Morrian count = 50
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - sett matron count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - naburite drinker count = 6
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - sidhe draoi count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - pendragon ardent count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - gorgon stalker count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - yar count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - karise count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - soldato spettrale decaduto count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - mangled troll invader count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - igo count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - blindsnake count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - lurker count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - uaimh forager count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - hoiples count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - ibn count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - suralle count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - spiteful wraith count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - General Korand count = 18
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - lady leana count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - arachite greensilk count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - wyulv count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - bottom feeder count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - svartalf sorcerer count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - kasora count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - shadowhunter count = 5
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - fomorian xexen count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - aqueous slug count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - wood-eater queen count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - mountain mephit count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - gala count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - small hill cat count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - olcasar belladonna count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - ellyll explorer count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - wood-eater worker count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - olcasar warrior count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Sylver count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - deep shrouder count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - gemclicker horder count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - slythcur count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - moor wolf count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - shyene muire count = 6
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - olcasar tracker count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - uaimh delver count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - olcasar twister count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - olcasar tainter count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - olcasar stonemelder count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - olcasar spikelord count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - olcasar mystic count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - hypogean beast count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - flesh stripper count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - blue cattail sporite count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - balorian liosliath count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - goblin snatcher count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - winter wolf count = 4
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - mud crab warrior count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - lord dasirual count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - merrow maiden count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - torc count = 7
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - urchin scavenger count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - scratchfoot scrounger count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - kaen kedger count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - curmudgeon rockclimber count = 4
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - grundor count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - chaplain count = 4
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - gardener count = 4
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - gwacka tree count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - zombie count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - muire head butler count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - fenrir tracker count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Golestandt count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Golestandt count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - soth count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Urgan Ulgeth count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Urgan Golr count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Urgan Nalkagh count = 2
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Mevos count = 3
19:41:24,064 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Selsan Solis count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Virilis orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Soulsinger Arthim orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - High Lord Baln orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Grundor orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Prugor orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Sephucoth orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - manta ray orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - umbrood warrior orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - Lady Leana orphaned count = 2
19:41:26,158 - [MAIN] - INFO - DOL.GS.LootGeneratorTemplate - manowar orphaned count = 2
Users browsing this forum: No registered users and 1 guest