예제 #1
0
        public static void OnDoubleClickRedirected(Mobile from, object o)
        {
            if (o == null || (!(o is BaseTool)))
            {
                return;
            }

            BaseTool tool = (BaseTool)o;

            if (tool.IsChildOf(from.Backpack) || tool.Parent == from)
            {
                CraftSystem system = tool.CraftSystem;

                int num = system.CanCraft(from, tool, null);

                if (num > 0 && (num != 1044267 || !Core.SE)) // Blacksmithing shows the gump regardless of proximity of an anvil and forge after SE
                {
                    from.SendLocalizedMessage(num);
                }
                else
                {
                    CraftContext context = system.GetContext(from);

                    from.SendGump(new CraftGump(from, system, tool, null));
                }
            }
            else
            {
                from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
            }
        }
예제 #2
0
        public static void OnDoubleClickRedirected(Mobile from, object o)
        {
            if (!(o is object[]))
            {
                return;
            }
            object[] arglist = (object[])o;

            if (arglist.Length != 1)
            {
                return;
            }

            if (!(arglist[0] is BaseTool))
            {
                return;
            }

            BaseTool tool = (BaseTool)arglist[0];

            if (tool.IsChildOf(from.Backpack) || tool.Parent == from)
            {
                CraftSystem system = tool.CraftSystem;

                int num = system.CanCraft(from, tool, null);

                if (num > 0)
                {
                    from.SendLocalizedMessage(num);
                }
                else
                {
                    CraftContext context = system.GetContext(from);

                    from.SendGump(new CraftGump(from, system, tool, null));
                }
            }
            else
            {
                from.SendAsciiMessage("That must be in your pack for you to use it.");                   // That must be in your pack for you to use it.
            }
        }
예제 #3
0
		public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft, bool showGumps)
		{
			int badCraft = craftSystem.CanCraft(from, tool, m_Type);

            if (badCraft > 0)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
                else
                    from.SendLocalizedMessage(badCraft);

                return;
            }

		    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
		    {
		        if (tool.CraftSystem == DefBlacksmithy.CraftSystem)
		        {
		            if (from.FindItemOnLayer(Layer.OneHanded) != tool)
		            {
		                from.SendGump(new CraftGump(from, craftSystem, tool, string.Format("You must have your smith hammer equipped!")));
		                return;
		            }
		        }
		        else
		        {
		            if (!tool.IsChildOf(from.Backpack))
		            {
		                from.SendGump(new CraftGump(from, craftSystem, tool, string.Format("You must have your tool in your backpack!")));
		                return;
		            }
		        }
		    }
		    else
		    {
		        from.SendLocalizedMessage(badCraft);
		        return;
		    }


		    object checkMessage = null;
			int checkResHue = 0, checkMaxAmount = 0;
			
			// Not enough resource to craft it
			if ( !ConsumeRes( from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage ) )
			{
                if (!tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                else if (checkMessage is int && (int)checkMessage > 0)
                    from.SendLocalizedMessage((int)checkMessage);
                else if (checkMessage is string)
                    from.SendMessage((string)checkMessage);

				return;
			}
			if (!ConsumeAttributes(from, ref checkMessage, false))
			{
				if (!tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
				else if (checkMessage is int && (int)checkMessage > 0)
					from.SendLocalizedMessage((int)checkMessage);
				else if (checkMessage is string)
					from.SendMessage((string)checkMessage);

				return;
			}

			bool toolBroken = false;

			int ignored = 1;
			int endquality = 1;

			bool allRequiredSkills = true;

			if (CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills))
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message))
				{
					if (!tool.Deleted && tool.UsesRemaining > 0)
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}
			    if (!ConsumeAttributes(from, ref message, true))
			    {
			        if (!tool.Deleted && tool.UsesRemaining > 0)
			            from.SendGump(new CraftGump(from, craftSystem, tool, message));
			        else if (message is int && (int)message > 0)
			            from.SendLocalizedMessage((int)message);
			        else if (message is string)
			            from.SendMessage((string)message);

			        return;
			    }

			    if (tool is WeaversSpool)
                    tool.UsesRemaining--;

				if (craftSystem is DefBlacksmithy)
				{
					AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
					if (hammer != null && hammer != tool)
					{
						hammer.UsesRemaining--;
						if (hammer.UsesRemaining < 1)
							hammer.Delete();
					}
				}

                if (tool.UsesRemaining < 1)
                    toolBroken = true;

                if (toolBroken)
                    tool.Delete();

				int num = 0;

				Item item;
				if (customCraft != null)
					item = customCraft.CompleteCraft(out num);
				else if (typeof(MapItem).IsAssignableFrom(ItemType) && from.Map != Map.Trammel && from.Map != Map.Felucca)
				{
					item = new IndecipherableMap();
					from.SendLocalizedMessage(1070800); // The map you create becomes mysteriously indecipherable.
				}
				else
					item = Activator.CreateInstance(ItemType) as Item;

				if (item != null && !item.Deleted)
				{
                    if (craftSystem is DefCarpentry)
                    {
                        if (RetainsColorFrom(m_System, item.GetType()))
                        {
                            if (typeRes == typeof (OakLog))
                                item.Name = string.Format("Oak {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (AshLog))
                                item.Name = string.Format("Ash {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (YewLog))
                                item.Name = string.Format("Yew {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (HeartwoodLog))
                                item.Name = string.Format("Heartwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (BloodwoodLog))
                                item.Name = string.Format("Bloodwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (FrostwoodLog))
                                item.Name = string.Format("Frostwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof(MahoganyLog))
                                item.Name = string.Format("Mahoganywood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof(CedarLog))
                                item.Name = string.Format("Cedarwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof(WillowLog))
                                item.Name = string.Format("Willowwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof(MystWoodLog))
                                item.Name = string.Format("Mystwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                        }
                    }

					if (item is ICraftable)
					{
                        if (item.Hue == 0)
                            item.Hue = resHue;

						endquality = ((ICraftable)item).OnCraft(quality, makersMark, from, craftSystem, typeRes, tool, this, resHue);
					}
					else if (item.Hue == 0)
					{
						item.Hue = resHue;

					    //Flag all high quality non ICraftable with a makers mark in the string
						if (craftSystem.MarkOption && makersMark && quality == 2 && from.Skills[craftSystem.MainSkill].Base >= 100.0)
						{
							endquality = quality;

						    item.Name = string.Format("{0} crafted by {1}", !string.IsNullOrEmpty(item.Name) ? item.Name : CliLoc.LocToString(item.LabelNumber), from.Name);
						}
					}

					if (maxAmount > 0)
						if (!item.Stackable && item is IUsesRemaining)
							((IUsesRemaining)item).UsesRemaining *= maxAmount;
						else
							item.Amount = maxAmount;

                    #region Add to pack or ground if overweight
                    //Taran: Check to see if player is overweight. If they are and the item drops to the
                    //ground then a check is made to see if it can be stacked. If it can't and  more than 
                    //20 items of the same type exist in the same tile then the last item gets removed. This 
                    //check is made so thousands of items can't exist in 1 tile and crash people in the same area.
                    if (from.AddToBackpack(item))
                    {
                        if (item is SpellScroll)
                            from.SendAsciiMessage("You put the {0} scroll in your pack.", item.Name ?? CliLoc.LocToString(item.LabelNumber));
                        else
                            from.SendAsciiMessage("You put the {0} in your pack.", item.Name ?? CliLoc.LocToString(item.LabelNumber));
                    }
                    else if (!item.Deleted)
                    {
                        IPooledEnumerable eable = from.Map.GetItemsInRange(from.Location, 0);
                        int amount = 0;
                        Item toRemove = null;

                        foreach (Item i in eable)
                        {
                            if (i != item && i.ItemID == item.ItemID)
                            {
                                if (i.StackWith(from, item, false))
                                {
                                    toRemove = item;
                                    break;
                                }
                                
                                amount++;
                            }
                        }

                        from.SendAsciiMessage("You are overweight and put the {0} on the ground.", item.Name ?? CliLoc.LocToString(item.LabelNumber));

                        if (toRemove != null)
                            toRemove.Delete();

                        else if (amount >= 5 && amount < 20)
                            from.LocalOverheadMessage(MessageType.Regular, 906, true, string.Format("{0} identical items on the ground detected, no more than 20 is allowed!", amount));

                        else if (amount >= 20)
                        {
                            from.LocalOverheadMessage(MessageType.Regular, 906, true, "Too many identical items on the ground, removing!");
                            item.Delete();
                        }

                        eable.Free();
                    }
                    #endregion

                    if (from.AccessLevel > AccessLevel.Player)
						CommandLogging.WriteLine(from, "Crafting {0} with craft system {1}", CommandLogging.Format(item), craftSystem.GetType().Name);

				}

				if (num == 0)
					num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);

				bool queryFactionImbue = false;
				int availableSilver = 0;
				FactionItemDefinition def = null;
				Faction faction = null;

				if (item is IFactionItem)
				{
					def = FactionItemDefinition.Identify(item);

					if (def != null)
					{
						faction = Faction.Find(from);

						if (faction != null)
						{
							Town town = Town.FromRegion(from.Region);

							if (town != null && town.Owner == faction)
							{
								Container pack = from.Backpack;

								if (pack != null)
								{
									availableSilver = pack.GetAmount(typeof(Silver));

									if (availableSilver >= def.SilverCost)
										queryFactionImbue = Faction.IsNearType(from, def.VendorType, 12);
								}
							}
						}
					}
				}

				// TODO: Scroll imbuing

				if (queryFactionImbue)
					from.SendGump(new FactionImbueGump(quality, item, from, craftSystem, tool, num, availableSilver, faction, def));
				else if (!tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, num));
				else if (num > 0)
					from.SendLocalizedMessage(num);
			}
			else if (!allRequiredSkills)
				if (!tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
				else
					from.SendLocalizedMessage(1044153); // You don't have the required skills to attempt this item.
			else
			{
				ConsumeType consumeType = (UseAllRes ? ConsumeType.Half : ConsumeType.All);
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true))
				{
					if (!tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}

				//tool.UsesRemaining--;

                if (tool is WeaversSpool)
                    tool.UsesRemaining--;

				if (tool.UsesRemaining < 1)
					toolBroken = true;

				if (toolBroken)
					tool.Delete();

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

				if (!tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
				else if (num > 0)
					from.SendLocalizedMessage(num);
			}
		}