/// <summary> /// Prepares skill, fails if no Bandage is found. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> public bool Prepare(Creature creature, Skill skill, Packet packet) { var itemEntityId = 0L; if (packet.Peek() == PacketElementType.String) { itemEntityId = MabiDictionary.Fetch <long>("ITEMID", packet.GetString()); } // TODO: Get bandage if not item skill // Bandages are used starting from the bottom-right corner. // Higher quality bandages will take priority over lower quality bandages regardless of placement. // ~_______~ // GetItem(ByTag) (starting in lower right?) // TODO: Check actual bandage if (creature.Inventory.Count(BandageItemId) == 0) { Send.Notice(creature, Localization.Get("You need more than one Bandage.")); return(false); } Send.SkillInitEffect(creature, null); Send.SkillPrepare(creature, skill.Info.Id, skill.GetCastTime()); return(true); }
/// <summary> /// Prepares skill. /// </summary> /// <remarks> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> public bool Prepare(Creature creature, Skill skill, Packet packet) { var parameters = packet.GetString(); var itemEntityId = MabiDictionary.Fetch <long>("ITEMID", parameters); var guild = creature.Guild; if (itemEntityId == 0 || creature.Inventory.GetItem(itemEntityId) == null) { Log.Warning("HiddenGuildStoneSetting.Prepare: User '{0}' tried to use skill with invalid item.", creature.Client.Account.Id); return(false); } else if (guild == null) { Send.MsgBox(creature, Localization.Get("You're not in a guild.")); return(false); } else if (creature.GuildMember.Rank != GuildMemberRank.Leader) { Send.MsgBox(creature, Localization.Get("Only the guild leader can place the guild stone.")); return(false); } else if (guild.HasStone) { Send.MsgBox(creature, Localization.Get("Your guild already has a guild stone.")); return(false); } skill.Stacks = 1; skill.State = SkillState.Ready; Send.Echo(creature, Op.SkillReady, packet); return(true); }
/// <summary> /// Prepares skill. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> public bool Prepare(Creature creature, Skill skill, Packet packet) { var dict = packet.GetString(); var enchantItemEntityId = MabiDictionary.Fetch <long>("ITEMID", dict); // Check everythig in Complete. // Response Send.Echo(creature, Op.SkillUse, packet); skill.State = SkillState.Used; return(true); }
public bool Prepare(Creature creature, Skill skill, Packet packet) { var dict = packet.GetString(); // Get item entity id creature.Temp.NameColorItemEntityId = MabiDictionary.Fetch <long>("ITEMID", dict); if (creature.Temp.NameColorItemEntityId == 0) { Log.Warning("NameColorChange: Invalid item id '{0}' from creature '{1:X16}'.", creature.Temp.NameColorItemEntityId, creature.EntityId); return(false); } // Go into ready mode Send.SkillReady(creature, skill.Info.Id, dict); skill.State = SkillState.Ready; return(true); }
/// <summary> /// Readies skill, saving the item id to use for later. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> public bool Ready(Creature creature, Skill skill, Packet packet) { if (skill.Info.Id == SkillId.Campfire) { creature.Temp.FirewoodItemId = packet.GetInt(); Send.SkillReady(creature, skill.Info.Id, creature.Temp.FirewoodItemId); } else { var dict = packet.GetString(); creature.Temp.CampfireKitItemEntityId = MabiDictionary.Fetch <long>("ITEMID", dict); Send.SkillReady(creature, skill.Info.Id, dict); } return(true); }
/// <summary> /// Prepares skill, reading the item to use from the packet. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> public bool Prepare(Creature creature, Skill skill, Packet packet) { var dictStr = packet.GetString(); byte unkByte = 0; if (packet.Peek() == PacketElementType.Byte) { unkByte = packet.GetByte(); } // Get item entity id var itemEntityId = MabiDictionary.Fetch <long>("ITEMID", dictStr); if (itemEntityId == 0) { Log.Warning("HiddenTownBack: Item entity id missing."); return(false); } // Get item var item = creature.Inventory.GetItem(itemEntityId); if (item == null) { Log.Warning("HiddenTownBack: Creature '{0:X16}' tried to use non-existing item.", creature.EntityId); return(false); } // Set callback for Complete creature.Skills.Callback(skill.Info.Id, () => { // Try to warp and remove item if successful if (Warp(creature, item)) { creature.Inventory.Remove(item); } }); Send.SkillUse(creature, skill.Info.Id, itemEntityId, unkByte, ""); skill.State = SkillState.Used; return(true); }
/// <summary> /// Completes skill, applying the enchant. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> public void Complete(Creature creature, Skill skill, Packet packet) { var dict = packet.GetString(); var enchantItemEntityId = MabiDictionary.Fetch <long>("ITEMID", dict); // Check enchant var elemental = creature.Inventory.GetItem(enchantItemEntityId); if (elemental == null) { Log.Warning("EnchantElementalAllSlot.Complete: User '{0}' tried to enchant with a non-existent elemental.", creature.Client.Account.Id); goto L_Fail; } // Check option set var optionSetId = elemental.MetaData1.GetInt("ENELEM"); var optionSetData = AuraData.OptionSetDb.Find(optionSetId); if (optionSetData == null) { Log.Warning("EnchantElementalAllSlot.Complete: User '{0:X16}' tried to enchant with unknown option set '{1}'.", creature.Client.Account.Id, optionSetId); goto L_Fail; } // Apply elementals var equip = creature.Inventory.GetMainEquipment(); foreach (var item in equip) { item.ApplyOptionSet(optionSetData, true); Send.ItemUpdate(creature, item); Send.AcquireEnchantedItemInfo(creature, item.EntityId, item.Info.Id, optionSetId); } // Decrement elemental creature.Inventory.Decrement(elemental); Send.Effect(creature, Effect.Enchant, (byte)EnchantResult.Success); L_Fail: Send.Echo(creature, packet); }
/// <summary> /// Prepares skill, getting the used item. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> public bool Prepare(Creature creature, Skill skill, Packet packet) { var parameters = packet.GetString(); // Check item var itemEntityId = MabiDictionary.Fetch <long>("ITEMID", parameters); if (itemEntityId == 0) { Log.Warning("HiddenResurrection: Creature '{0:X16}' tried to use skill without item."); return(false); } var item = creature.Inventory.GetItem(itemEntityId); if (item == null) { Log.Warning("HiddenResurrection: Creature '{0:X16}' tried to use skill with non-existing item."); return(false); } if (!item.HasTag("/usable/resurrection/")) { Log.Warning("HiddenResurrection: Creature '{0:X16}' tried to use skill with invalid item."); return(false); } // Check if any party members are actually dead if party feather if (item.HasTag("/party/") && !creature.Party.GetMembers().Any(a => a != creature && a.IsDead && a.DeadMenu.Has(ReviveOptions.PhoenixFeather))) { Send.MsgBox(creature, Localization.Get("There is no one available to resurrect.")); return(false); } creature.Temp.SkillItem1 = item; // Response Send.Echo(creature, Op.SkillReady, packet); skill.State = SkillState.Ready; return(true); }
/// <summary> /// Prepares skill, fails if no Bandage is found. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> 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); }