private DropData GetFishingDrop(Creature creature, Random rnd)
{
var prop = creature.Temp.FishingProp;
if (prop == null)
return null;
// Get equip
var rightHand = creature.RightHand;
var magazine = creature.Magazine;
var rod = rightHand == null ? 0 : rightHand.Info.Id;
var bait = magazine == null ? 0 : magazine.Info.Id;
// Get grounds
var grounds = (IEnumerable<FishingGroundData>)AuraData.FishingGroundsDb.Entries.Values;
var eventGrounds = ChannelServer.Instance.GameEventManager.GlobalBonuses.GetFishingGrounds();
if (eventGrounds.Any())
grounds = grounds.Concat(eventGrounds);
// Check all grounds ordered by priority
foreach (var fishingGround in grounds.OrderByDescending(a => a.Priority))
{
// Check chance
if (rnd.Next(100) >= fishingGround.Chance)
continue;
// Check equip
if ((fishingGround.Rod != 0 && fishingGround.Rod != rod) || (fishingGround.Bait != 0 && fishingGround.Bait != bait))
continue;
// Check locations
var locationCondition = (fishingGround.Locations.Length == 0);
foreach (var location in fishingGround.Locations)
{
try
{
// Check events
var evs = creature.Region.GetMatchingEvents(location);
foreach (var ev in evs)
{
// Check if prop is inside event shape, break at first success
if (ev.IsInside((int)prop.Info.X, (int)prop.Info.Y))
{
locationCondition = true;
break;
}
}
if (locationCondition)
break;
}
catch (ArgumentException ex)
{
Log.Error("Fishing.GetFishingDrop: {0}", ex.Message);
}
}
// Conditions not met
if (!locationCondition)
continue;
// Conditions met
var items = fishingGround.Items;
var totalChance = fishingGround.TotalItemChance;
// Get random item
var n = 0.0;
var chance = rnd.NextDouble() * totalChance;
foreach (var item in items)
{
n += item.Chance;
if (chance <= n)
return item;
}
throw new Exception("Fishing.GetFishingDrop: Failed to get item.");
}
return null;
}