Aura.Channel.Skills.Magic.Enchant.Prepare C# (CSharp) Метод

Prepare() публичный Метод

Prepares skill.
public Prepare ( Creature creature, Skill skill, Packet packet ) : bool
creature Aura.Channel.World.Entities.Creature
skill Skill
packet Packet
Результат bool
		public bool Prepare(Creature creature, Skill skill, Packet packet)
		{
			Item item, enchant;

			if (creature.Temp.ActiveEntrustment == null)
			{
				var itemEntityId = packet.GetLong();
				long enchantEntityId = 0;

				if (skill.Info.Id == SkillId.HiddenEnchant)
				{
					enchantEntityId = packet.GetLong();
				}
				else if (skill.Info.Id == SkillId.Enchant)
				{
					var rightHand = creature.RightHand;
					var magazine = creature.Magazine;

					enchantEntityId = (magazine == null ? 0 : magazine.EntityId);

					if (rightHand == null || !rightHand.HasTag("/enchant/powder/"))
					{
						Log.Warning("Enchant.Prepare: Creature '{0:X16}' tried to use Enchant without powder.");
						return false;
					}

					if (magazine == null || !magazine.HasTag("/lefthand/enchant/"))
					{
						Log.Warning("Enchant.Prepare: Creature '{0:X16}' tried to use Enchant without enchant.");
						return false;
					}
				}

				// Get items
				item = creature.Inventory.GetItem(itemEntityId);
				enchant = creature.Inventory.GetItem(enchantEntityId);
			}
			else
			{
				item = creature.Temp.ActiveEntrustment.GetItem1();
				enchant = creature.Temp.ActiveEntrustment.GetItem2();
			}

			// Check item
			if (item == null)
			{
				Log.Warning("Enchant.Prepare: Creature '{0:X16}' tried to enchant non-existing item.");
				return false;
			}

			// Check enchant
			if (enchant == null)
			{
				Log.Warning("Enchant.Prepare: Creature '{0:X16}' tried to enchant with non-existing enchant item.");
				return false;
			}

			if (!enchant.HasTag("/enchant/"))
			{
				Log.Warning("Enchant.Prepare: Creature '{0:X16}' tried to enchant with invalid enchant scroll.");
				return false;
			}

			if (enchant.OptionInfo.Durability == 0 && enchant.OptionInfo.DurabilityOriginal != 0)
			{
				Send.Notice(creature, Localization.Get("This scroll is no longer valid for enchantment."));
				return false;
			}

			// Check ranks
			var optionSetId = this.GetOptionSetid(enchant);
			var optionSetData = AuraData.OptionSetDb.Find(optionSetId);
			if (optionSetData == null)
			{
				Log.Warning("Enchant.Prepare: Creature '{0:X16}' tried to enchant with unknown option set '{0}'.", optionSetId);
				return false;
			}

			if (!optionSetData.IgnoreRank)
			{
				// Skill rank for enchants of r5 and above
				if (optionSetData.Rank >= SkillRank.R5 && skill.Info.Rank < SkillRank.R5)
				{
					Send.Notice(creature, Localization.Get("Your Enchant skill must be Rank 5 or above to use this Enchant Scroll."));
					return false;
				}

				// Sequence for enchants of r9 and above
				if (optionSetData.Rank >= SkillRank.R9)
				{
					var checkSetId = (optionSetData.Type == UpgradeType.Prefix ? item.OptionInfo.Prefix : item.OptionInfo.Suffix);
					var checkSetData = AuraData.OptionSetDb.Find(checkSetId);
					if (checkSetData == null || checkSetData.Rank + 1 < optionSetData.Rank)
					{
						// Unofficial
						Send.Notice(creature, Localization.Get("You need to enchant Enchantments of R9 and above in sequence."));
						return false;
					}
				}
			}

			// Check expiration
			var checkExpiration = (optionSetData.Type == UpgradeType.Prefix ? "XPRPFX" : "XPRSFX");
			if (enchant.MetaData1.Has(checkExpiration))
			{
				var expiration = enchant.MetaData1.GetDateTime(checkExpiration);
				if (DateTime.Now > expiration)
				{
					Send.MsgBox(creature, Localization.Get("No enchantment options available.\nThis scroll is expired."));
					return false;
				}
			}

			// Save items for Complete
			creature.Temp.SkillItem1 = item;
			creature.Temp.SkillItem2 = enchant;

			// Response
			Send.Echo(creature, Op.SkillUse, packet);
			skill.State = SkillState.Used;

			return true;
		}