コード例 #1
0
        public void Load(ZoneServer server)
        {
            Log.write("Loading loot tables...");
            _rand       = new Random();
            _lootTables = new Dictionary <int, LootTable>();

            string[] tables = Directory.GetFiles(System.Environment.CurrentDirectory + "/Loot/", "*.xml");

            foreach (string table in tables)
            {
                LootTable newTable = new LootTable(table);
                _lootTables.Add(newTable.botID, newTable);
            }
        }
コード例 #2
0
        public void tryLootDrop(IEnumerable <Player> players, Bot dead, short posX, short posY)
        {
            if (players.Count() == 0)
            {
                return;
            }

            using (LogAssume.Assume(_logger))
            {
                LootTable lootTable = getLootTableByID(dead._type.Id);

                if (lootTable == null)
                {
                    Log.write("Could not find loot table for bot id {0}", dead._type.Id);
                    return;
                }

                int weightRoll = 0;
                //Spawn all of our normal items
                if (lootTable.normalLoot.Count > 0)
                {
                    foreach (LootInfo loot in lootTable.normalLoot)
                    {
                        if (loot._weight >= 100)
                        {
                            itemSpawn(loot._item, (ushort)loot._quantity, posX, posY, null);
                        }
                        else
                        {
                            weightRoll = _rand.Next(0, 100);
                            if (loot._weight >= weightRoll)
                            {
                                itemSpawn(loot._item, (ushort)loot._quantity, posX, posY, null);
                            }
                        }
                    }
                }


                int total    = 0;
                int position = 0;

                total += lootTable.commonChance;
                total += lootTable.uncommonChance;
                total += lootTable.setChance;
                total += lootTable.rareChance;

                Range commonRange = new Range(position, position + lootTable.commonChance);
                position += lootTable.commonChance;
                Range uncommonRange = new Range(position, position + lootTable.uncommonChance);
                position += lootTable.uncommonChance;
                Range setRange = new Range(position, position + lootTable.setChance);
                position += lootTable.setChance;
                Range rareRange = new Range(position, position + lootTable.rareChance);
                position  += lootTable.rareChance;
                weightRoll = 0;
                List <LootInfo> potentialLoot = new List <LootInfo>();
                foreach (Player player in players)
                {
                    Log.write("Trying loot drop for {0}", player._alias);
                    weightRoll = _rand.Next(0, total);

                    Log.write("Category Weight Roll: {0}", weightRoll);

                    if (weightRoll.IsWithin(commonRange.min, commonRange.max))
                    {
                        Log.write("selected commmon loot list");
                        potentialLoot = lootTable.commonLoot;
                    }
                    else if (weightRoll.IsWithin(uncommonRange.min, uncommonRange.max))
                    {
                        Log.write("selected uncommon loot list");
                        potentialLoot = lootTable.uncommonLoot;
                    }
                    else if (weightRoll.IsWithin(setRange.min, setRange.max))
                    {
                        Log.write("selected set loot list");
                        potentialLoot = lootTable.setLoot;
                    }
                    else if (weightRoll.IsWithin(rareRange.min, rareRange.max))
                    {
                        Log.write("selected rare loot list");
                        potentialLoot = lootTable.rareLoot;
                    }
                    else
                    {
                        //No loot for this guy :(
                        if (potentialLoot.Count == 0)
                        {
                            Log.write("no loot list selected");
                            continue;
                        }
                    }



                    int totalLootProbability = 0;
                    int rangePosition        = 0;
                    Dictionary <Range, LootInfo> lootRanges = new Dictionary <Range, LootInfo>();

                    foreach (LootInfo loot in potentialLoot)
                    {
                        totalLootProbability += loot._weight;
                        lootRanges.Add(new Range(rangePosition, rangePosition + loot._weight), loot);
                        rangePosition += loot._weight;
                    }

                    weightRoll = _rand.Next(0, totalLootProbability);
                    Log.write("Item Weight Roll: {0}", weightRoll);
                    LootInfo drop = lootRanges.FirstOrDefault(rng => weightRoll.IsWithin(rng.Key.min, rng.Key.max)).Value;

                    //Better luck next time!
                    if (drop == null)
                    {
                        continue;
                    }

                    //Likely a null item to simulate chance of no drop at all
                    if (drop._item == null)
                    {
                        continue;
                    }

                    //Give the lad his loot!
                    privateItemSpawn(drop._item, (ushort)drop._quantity, dead._state.positionX, dead._state.positionY, player, drop._type, dead, drop._name);
                }
            }
        }