예제 #1
0
		/// <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 materials = new List<ProductionMaterial>();
			var hits = new List<HammerHit>();

			var stage = (Stage)packet.GetByte();
			var propEntityId = packet.GetLong();
			var unkInt1 = packet.GetInt();
			var existingItemEntityId = packet.GetLong();
			var finishId = packet.GetInt();

			if (stage == Stage.Progression)
			{
				// Materials
				if (!this.ReadMaterials(creature, packet, out materials))
					return false;
			}
			else if (stage == Stage.Finish)
			{
				// Hits
				if (!this.ReadHits(creature, packet, out hits))
					return false;
			}
			else
			{
				Send.ServerMessage(creature, Localization.Get("Stage error, please report."));
				Log.Error("Tailoring: Unknown progress stage '{0}'.", stage);
				return false;
			}

			// Check tools
			if (!this.CheckTools(creature))
				return false;

			// Check if ready for completion
			if (stage == Stage.Progression && existingItemEntityId != 0)
			{
				// Check item
				var item = creature.Inventory.GetItem(existingItemEntityId);
				if (item == null)
				{
					Log.Warning("Blacksmithing.Complete: Creature '{0:X16}' tried to work on non-existent item.", creature.EntityId);
					return false;
				}

				// Check prop
				var prop = creature.Region.GetProp(propEntityId);
				if (prop == null || !creature.GetPosition().InRange(prop.GetPosition(), 500))
				{
					Send.Notice(creature, Localization.Get("You need an anvil."));
					return false;
				}

				// Check item progress
				if (item.MetaData1.GetFloat(ProgressVar) == 1)
				{
					var rnd = RandomProvider.Get();

					// Get manual
					var manualId = creature.Magazine.MetaData1.GetInt("FORMID");
					var manualData = AuraData.ManualDb.Find(ManualCategory.Blacksmithing, manualId);
					if (manualData == null)
					{
						Log.Error("Blacksmithing.Complete: Manual '{0}' not found.", manualId);
						Send.ServerMessage(creature, Localization.Get("Failed to look up pattern, please report."));
						return false;
					}

					// Get items to decrement
					var requiredMaterials = manualData.GetFinish(finishId).Materials;
					List<ProductionMaterial> toDecrement;
					if (!this.GetItemsToDecrement(creature, Stage.Finish, manualData, requiredMaterials, materials, out toDecrement))
						return false;

					// Decrement mats
					this.DecrementMaterialItems(creature, toDecrement, rnd);

					// Start minigame
					var deviation = (byte)(skill.Info.Rank < SkillRank.R9 ? 3 : 2);
					var dots = new List<BlacksmithDot>();
					for (int i = 0; i < 5; ++i)
					{
						var dot = new BlacksmithDot();

						dot.Deviation = rnd.Next(0, deviation + 1);
						dot.X = rnd.Next(FieldMin, FieldMax + 1);
						dot.Y = rnd.Next(FieldMin, FieldMax + 1);

						// Use static displacement until we know the formula.
						dot.TimeDisplacement = 1; // rnd.Between(0.81f, 0.98f);

						dots.Add(dot);
					}

					Send.BlacksmithingMiniGame(creature, prop, item, dots, deviation);

					// Save dots for finish
					creature.Temp.BlacksmithingMiniGameDots = dots;
					creature.Temp.CreationFinishId = finishId;

					return false;
				}
			}

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

			return true;
		}
예제 #2
0
        /// <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 materials = new List <ProductionMaterial>();
            var hits      = new List <HammerHit>();

            var stage                = (Stage)packet.GetByte();
            var propEntityId         = packet.GetLong();
            var unkInt1              = packet.GetInt();
            var existingItemEntityId = packet.GetLong();
            var finishId             = packet.GetInt();

            if (stage == Stage.Progression)
            {
                // Materials
                if (!this.ReadMaterials(creature, packet, out materials))
                {
                    return(false);
                }
            }
            else if (stage == Stage.Finish)
            {
                // Hits
                if (!this.ReadHits(creature, packet, out hits))
                {
                    return(false);
                }
            }
            else
            {
                Send.ServerMessage(creature, Localization.Get("Stage error, please report."));
                Log.Error("Tailoring: Unknown progress stage '{0}'.", stage);
                return(false);
            }

            // Check tools
            if (!this.CheckTools(creature))
            {
                return(false);
            }

            // Check if ready for completion
            if (stage == Stage.Progression && existingItemEntityId != 0)
            {
                // Check item
                var item = creature.Inventory.GetItem(existingItemEntityId);
                if (item == null)
                {
                    Log.Warning("Blacksmithing.Complete: Creature '{0:X16}' tried to work on non-existent item.", creature.EntityId);
                    return(false);
                }

                // Check prop
                var prop = creature.Region.GetProp(propEntityId);
                if (prop == null || !creature.GetPosition().InRange(prop.GetPosition(), 500))
                {
                    Send.Notice(creature, Localization.Get("You need an anvil."));
                    return(false);
                }

                // Check item progress
                if (item.MetaData1.GetFloat(ProgressVar) == 1)
                {
                    var rnd = RandomProvider.Get();

                    // Get manual
                    var manualId   = creature.Magazine.MetaData1.GetInt("FORMID");
                    var manualData = AuraData.ManualDb.Find(ManualCategory.Blacksmithing, manualId);
                    if (manualData == null)
                    {
                        Log.Error("Blacksmithing.Complete: Manual '{0}' not found.", manualId);
                        Send.ServerMessage(creature, Localization.Get("Failed to look up pattern, please report."));
                        return(false);
                    }

                    // Get items to decrement
                    var requiredMaterials = manualData.GetFinish(finishId).Materials;
                    List <ProductionMaterial> toDecrement;
                    if (!this.GetItemsToDecrement(creature, Stage.Finish, manualData, requiredMaterials, materials, out toDecrement))
                    {
                        return(false);
                    }

                    // Decrement mats
                    this.DecrementMaterialItems(creature, toDecrement, rnd);

                    // Start minigame
                    var deviation = (byte)(skill.Info.Rank < SkillRank.R9 ? 3 : 2);
                    var dots      = new List <BlacksmithDot>();
                    for (int i = 0; i < 5; ++i)
                    {
                        var dot = new BlacksmithDot();

                        dot.Deviation = rnd.Next(0, deviation + 1);
                        dot.X         = rnd.Next(FieldMin, FieldMax + 1);
                        dot.Y         = rnd.Next(FieldMin, FieldMax + 1);

                        // Use static displacement until we know the formula.
                        dot.TimeDisplacement = 1;                         // rnd.Between(0.81f, 0.98f);

                        dots.Add(dot);
                    }

                    Send.BlacksmithingMiniGame(creature, prop, item, dots, deviation);

                    // Save dots for finish
                    creature.Temp.BlacksmithingMiniGameDots = dots;
                    creature.Temp.CreationFinishId          = finishId;

                    return(false);
                }
            }

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

            return(true);
        }