public bool Prepare(Creature creature, Skill skill, Packet packet)
{
var itemEntityId = 0L;
if (packet.Peek() == PacketElementType.String)
itemEntityId = MabiDictionary.Fetch<long>("ITEMID", packet.GetString());
Item bandage = null;
// Get given bandage item or select one from the inventory
if (itemEntityId != 0)
{
bandage = creature.Inventory.GetItem(itemEntityId);
if (bandage == null || !bandage.HasTag("/bandage/"))
{
Log.Warning("FirstAid.Prepare: Creature '{0:X16}' tried to use invalid bandage.", creature.EntityId);
return false;
}
}
else
{
// Get all bandages in inventory
var items = creature.Inventory.GetItems(a => a.HasTag("/bandage/"), StartAt.BottomRight);
// Cancel if there are none
if (items.Count == 0)
{
Send.Notice(creature, Localization.Get("You need more than one Bandage."));
return false;
}
var best = 0;
// Select the bandage with the highest quality,
// starting from the bottom right
foreach (var item in items)
{
var quality = 0;
if (item.HasTag("/common_grade/"))
quality = 1;
else if (item.HasTag("/high_grade/"))
quality = 2;
else if (item.HasTag("/highest_grade/"))
quality = 3;
// Select this item, if the quality is *better* than the
// previously selected one, we don't want to switch to a
// bandage of equal quality, since we want to get the one
// closest to the bottom right.
if (bandage == null || quality > best)
{
best = quality;
bandage = item;
}
}
// Sanity check, shouldn't happen. Ever.
if (bandage == null)
{
Log.Warning("FirstAid.Prepare: The impossible sanity check failed.");
return false;
}
}
creature.Temp.SkillItem1 = bandage;
Send.SkillInitEffect(creature, null);
Send.SkillPrepare(creature, skill.Info.Id, skill.GetCastTime());
return true;
}