public void Complete(Creature creature, Skill skill, Packet packet)
{
var entityId = packet.GetLong();
var unkInt1 = packet.GetInt();
var unkInt2 = packet.GetInt();
// Get target
var target = ChannelServer.Instance.World.GetCreature(entityId);
if (target == null)
{
Send.Notice(creature, Localization.Get("Invalid target."));
goto L_End;
}
// Check range
if (!creature.GetPosition().InRange(target.GetPosition(), Range))
{
Send.Notice(creature, Localization.Get("Out of range."));
goto L_End;
}
// Check bandage, make sure he still has the item and that
// it wasn't switched with something else somehow.
if (creature.Temp.SkillItem1 == null || !creature.Temp.SkillItem1.HasTag("/bandage/") || !creature.Inventory.Has(creature.Temp.SkillItem1))
{
Log.Warning("FirstAid.Complete: Creature '{0:X16}' apparently switched the skill item somehow, between Ready and Complete.", creature.EntityId);
Send.Notice(creature, Localization.Get("Invalid bandage."));
goto L_End;
}
// Remove bandage
if (!creature.Inventory.Decrement(creature.Temp.SkillItem1))
{
Log.Error("FirstAid.Complete: Decrementing the skill item failed somehow.");
Send.Notice(creature, Localization.Get("Unknown error."));
goto L_End;
}
// Fails if target is moving.
if (target.IsMoving)
{
// Unofficial
Send.Notice(creature, Localization.Get("Failed because target was moving."));
// Fail motion?
goto L_End;
}
// Heal injuries
var rnd = RandomProvider.Get();
var heal = rnd.Next((int)skill.RankData.Var1, (int)skill.RankData.Var2 + 1);
// Add bonus from higher grade bandages
if (creature.Temp.SkillItem1.HasTag("/common_grade/"))
heal += 3;
else if (creature.Temp.SkillItem1.HasTag("/high_grade/"))
heal += 6;
else if (creature.Temp.SkillItem1.HasTag("/highest_grade/"))
heal += 10;
// 50% efficiency if target isn't resting
if (!target.Has(CreatureStates.SitDown))
heal /= 2;
target.Injuries -= heal;
Send.StatUpdateDefault(target);
// Skill training
if (skill.Info.Rank == SkillRank.Novice)
skill.Train(1); // Use First Aid.
// First Aid animation
Send.Effect(creature, Effect.UseMagic, "healing_firstaid", entityId);
L_End:
Send.SkillComplete(creature, skill.Info.Id, entityId, unkInt1, unkInt2);
}