/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected override bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { bool needForge = false; foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey<ItemTemplate>(material.IngredientId_nb); if (template != null && template.Model == 519) // metal bar { needForge = true; break; } } if (needForge) { foreach (GameStaticItem item in player.GetItemsInRadius(CRAFT_DISTANCE)) { if (item.Name == "forge" || item.Model == 478) // Forge return true; } player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client, "Crafting.CheckTool.NotHaveTools", itemToCraft.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); player.Out.SendMessage(LanguageMgr.GetTranslation(ServerProperties.Properties.DB_LANGUAGE, "Crafting.CheckTool.FindForge"), eChatType.CT_System, eChatLoc.CL_SystemWindow); if (player.Client.Account.PrivLevel > 1) return true; return false; } return true; }
/// <summary> /// Calculate the minumum needed secondary crafting skill level to make the item /// </summary> public override int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { switch (itemToCraft.Object_Type) { case (int)eObjectType.CrushingWeapon: case (int)eObjectType.SlashingWeapon: case (int)eObjectType.ThrustWeapon: case (int)eObjectType.TwoHandedWeapon: case (int)eObjectType.PolearmWeapon: case (int)eObjectType.Flexible: case (int)eObjectType.Sword: case (int)eObjectType.Hammer: case (int)eObjectType.Axe: case (int)eObjectType.Spear: case (int)eObjectType.HandToHand: case (int)eObjectType.Blades: case (int)eObjectType.Blunt: case (int)eObjectType.Piercing: case (int)eObjectType.LargeWeapons: case (int)eObjectType.CelticSpear: case (int)eObjectType.Scythe: return recipe.CraftingLevel - 60; } return base.GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft); }
/// <summary> /// Gain a point in the appropriate skills for a recipe and materials /// </summary> public override void GainCraftingSkillPoints(GamePlayer player, DBCraftedItem recipe, IList<DBCraftedXItem> rawMaterials) { if (Util.Chance(CalculateChanceToGainPoint(player, recipe))) { player.GainCraftingSkill(eCraftingSkill.SiegeCrafting, 1); player.Out.SendUpdateCraftingSkills(); } }
/// <summary> /// Gain a point in the appropriate skills for a recipe and materials /// </summary> public override void GainCraftingSkillPoints(GamePlayer player, DBCraftedItem recipe, IList <DBCraftedXItem> rawMaterials) { if (Util.Chance(CalculateChanceToGainPoint(player, recipe))) { player.GainCraftingSkill(eCraftingSkill.Fletching, 1); base.GainCraftingSkillPoints(player, recipe, rawMaterials); player.Out.SendUpdateCraftingSkills(); } }
/// <summary> /// Gain a point in the appropriate skills for a recipe and materials /// </summary> public virtual void GainCraftingSkillPoints(GamePlayer player, DBCraftedItem recipe, IList <DBCraftedXItem> rawMaterials) { foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb); if (template != null) { switch (template.Model) { case 522: // "cloth square" case 537: // "heavy thread" { if (player.GetCraftingSkillValue(eCraftingSkill.ClothWorking) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.ClothWorking, 1); } break; } case 521: // "leather square" { if (player.GetCraftingSkillValue(eCraftingSkill.LeatherCrafting) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.LeatherCrafting, 1); } break; } case 519: // "metal bars" { if (player.GetCraftingSkillValue(eCraftingSkill.MetalWorking) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.MetalWorking, 1); } break; } case 520: // "wooden boards" { if (player.GetCraftingSkillValue(eCraftingSkill.WoodWorking) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.WoodWorking, 1); } break; } } } } player.Out.SendUpdateCraftingSkills(); }
/// <summary> /// Gain a point in the appropriate skills for a recipe and materials /// </summary> public override void GainCraftingSkillPoints(GamePlayer player, DBCraftedItem recipe, IList<DBCraftedXItem> rawMaterials) { if (Util.Chance(CalculateChanceToGainPoint(player, recipe))) { if (player.GetCraftingSkillValue(eCraftingSkill.MetalWorking) < subSkillCap) player.GainCraftingSkill(eCraftingSkill.MetalWorking, 1); player.Out.SendUpdateCraftingSkills(); } }
protected override void BuildCraftedItem(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft) { GameSiegeWeapon siegeweapon = null; switch ((eObjectType)itemToCraft.Object_Type) { case eObjectType.SiegeBalista: { siegeweapon = new GameSiegeBallista(); } break; case eObjectType.SiegeCatapult: { siegeweapon = new GameSiegeCatapult(); } break; case eObjectType.SiegeCauldron: { siegeweapon = new GameSiegeCauldron(); } break; case eObjectType.SiegeRam: { siegeweapon = new GameSiegeRam(); } break; case eObjectType.SiegeTrebuchet: { siegeweapon = new GameSiegeTrebuchet(); } break; default: { base.BuildCraftedItem(player, recipe, itemToCraft); return; } } //actually stores the Id_nb of the siegeweapon siegeweapon.ItemId = itemToCraft.Id_nb; siegeweapon.LoadFromDatabase(itemToCraft); siegeweapon.CurrentRegion = player.CurrentRegion; siegeweapon.Heading = player.Heading; siegeweapon.X = player.X; siegeweapon.Y = player.Y; siegeweapon.Z = player.Z; siegeweapon.Realm = player.Realm; siegeweapon.AddToWorld(); }
/// <summary> /// Gain a point in the appropriate skills for a recipe and materials /// </summary> public override void GainCraftingSkillPoints(GamePlayer player, DBCraftedItem recipe, IList <DBCraftedXItem> rawMaterials) { if (Util.Chance(CalculateChanceToGainPoint(player, recipe))) { if (player.GetCraftingSkillValue(eCraftingSkill.ClothWorking) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.ClothWorking, 1); player.Out.SendUpdateCraftingSkills(); } } }
/// <summary> /// Calculate the minumum needed secondary crafting skill level to make the item /// </summary> public override int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { switch (itemToCraft.Object_Type) { case (int)eObjectType.Cloth: case (int)eObjectType.Leather: case (int)eObjectType.Studded: return(recipe.CraftingLevel - 30); } return(base.GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft)); }
private static DBCraftedItem AddOneCompleteRecipeToDatabase() { var itemToCraft = new ItemTemplate(); itemToCraft.Id_nb = "item_to_craft"; itemToCraft.Name = "Item To Craft"; itemToCraft.AllowedClasses = ""; itemToCraft.CanUseEvery = 0; AddDatabaseEntry(itemToCraft); var craftedItem = new DBCraftedItem(); craftedItem.CraftedItemID = itemToCraftID.ToString(); craftedItem.Id_nb = itemToCraft.Id_nb; craftedItem.CraftingLevel = 1; craftedItem.CraftingSkillType = 1; AddDatabaseEntry(craftedItem); var ingredient1 = new DBCraftedXItem(); ingredient1.Count = 1; ingredient1.ObjectId = "id1"; ingredient1.CraftedItemId_nb = craftedItem.Id_nb; ingredient1.IngredientId_nb = "item1_id"; AddDatabaseEntry(ingredient1); var ingredient2 = new DBCraftedXItem(); ingredient2.Count = 2; ingredient2.ObjectId = "id2"; ingredient2.CraftedItemId_nb = craftedItem.Id_nb; ingredient2.IngredientId_nb = "item2_id"; AddDatabaseEntry(ingredient2); var ingredientItem1 = new ItemTemplate(); ingredientItem1.Id_nb = ingredient1.IngredientId_nb; ingredientItem1.Name = "First Ingredient Name"; ingredientItem1.AllowedClasses = ""; ingredientItem1.Price = 10000; ingredientItem1.CanUseEvery = 0; AddDatabaseEntry(ingredientItem1); var ingredientItem2 = new ItemTemplate(); ingredientItem2.Id_nb = ingredient2.IngredientId_nb; ingredientItem2.Name = "Second Ingredient Name"; ingredientItem2.AllowedClasses = ""; ingredientItem2.CanUseEvery = 0; ingredientItem2.Price = 20000; AddDatabaseEntry(ingredientItem2); return(craftedItem); }
/// <summary> /// Make the item when craft time is finished /// </summary> protected virtual int MakeItem(RegionTimer timer) { GamePlayer player = timer.Properties.getProperty <GamePlayer>(PLAYER_CRAFTER, null); DBCraftedItem recipe = timer.Properties.getProperty <DBCraftedItem>(RECIPE_BEING_CRAFTED, null); IList <DBCraftedXItem> rawMaterials = timer.Properties.getProperty <IList <DBCraftedXItem> >(RECIPE_RAW_MATERIAL_LIST, null); if (player == null || recipe == null || rawMaterials == null) { if (player != null) { player.Out.SendMessage("Could not find recipe or item to craft!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); } log.Error("Crafting.MakeItem: Could not retrieve player, recipe, or raw materials to craft from CraftTimer."); return(0); } ItemTemplate itemToCraft = GameServer.Database.FindObjectByKey <ItemTemplate>(recipe.Id_nb); if (itemToCraft == null) { return(0); } player.CraftTimer.Stop(); player.Out.SendCloseTimerWindow(); if (Util.Chance(CalculateChanceToMakeItem(player, recipe))) { if (!RemoveUsedMaterials(player, recipe, rawMaterials)) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.MakeItem.NotAllMaterials"), eChatType.CT_System, eChatLoc.CL_SystemWindow); if (player.Client.Account.PrivLevel == 1) { return(0); } } BuildCraftedItem(player, recipe, itemToCraft); GainCraftingSkillPoints(player, recipe, rawMaterials); } else { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.MakeItem.LoseNoMaterials", itemToCraft.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); player.Out.SendPlaySound(eSoundType.Craft, 0x02); } return(0); }
/// <summary> /// Calculate the minumum needed secondary crafting skill level to make the item /// </summary> public override int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { switch(itemToCraft.Object_Type) { case (int)eObjectType.Studded: case (int)eObjectType.Chain: case (int)eObjectType.Plate: case (int)eObjectType.Reinforced: case (int)eObjectType.Scale: return recipe.CraftingLevel - 60; } return base.GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft); }
/// <summary> /// Calculate the minumum needed secondary crafting skill level to make the item /// </summary> public override int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { switch (itemToCraft.Object_Type) { case (int)eObjectType.Studded: case (int)eObjectType.Chain: case (int)eObjectType.Plate: case (int)eObjectType.Reinforced: case (int)eObjectType.Scale: return(recipe.CraftingLevel - 60); } return(base.GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft)); }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected override bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { foreach (GameStaticItem item in player.GetItemsInRadius(CRAFT_DISTANCE)) { if (item.Name.ToLower() == "forge" || item.Model == 478) // Forge return true; } player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Crafting.CheckTool.NotHaveTools", itemToCraft.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); player.Out.SendMessage(LanguageMgr.GetTranslation(ServerProperties.Properties.DB_LANGUAGE, "Crafting.CheckTool.FindForge"), eChatType.CT_System, eChatLoc.CL_SystemWindow); if (player.Client.Account.PrivLevel > 1) return true; return false; }
/// <summary> /// Calculate chance to succes /// </summary> public virtual int CalculateChanceToMakeItem(GamePlayer player, DBCraftedItem recipe) { int con = GetItemCon(player.GetCraftingSkillValue(m_eskill), recipe.CraftingLevel); if (con < -3) { con = -3; } if (con > 3) { con = 3; } switch (con) { // Chance to MAKE ! (100 - chance to fail) case -3: return(100); case -2: return(100); case -1: return(100); case 0: return(100 - 8); case 1: return(100 - 16); case 2: return(100 - 32); case 3: return(0); default: return(0); } }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected override bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { foreach (GameStaticItem item in player.GetItemsInRadius(CRAFT_DISTANCE)) { if (item.Name.ToLower() == "alchemy table" || item.Model == 820) // Alchemy Table { return(true); } } player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Crafting.CheckTool.NotHaveTools", itemToCraft.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); player.Out.SendMessage(LanguageMgr.GetTranslation(ServerProperties.Properties.SERV_LANGUAGE, "Crafting.CheckTool.FindAlchemyTable"), eChatType.CT_System, eChatLoc.CL_SystemWindow); if (player.Client.Account.PrivLevel > 1) { return(true); } return(false); }
/// <summary> /// Called when player tries to begin crafting an item /// </summary> public virtual void CraftItem(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { if (!CanPlayerStartToCraftItem(player, recipe, itemToCraft, rawMaterials)) { return; } if (player.IsCrafting) { StopCraftingCurrentItem(player, itemToCraft); return; } int craftingTime = GetCraftingTime(player, recipe, rawMaterials); player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CraftItem.BeginWork", itemToCraft.Name, CalculateChanceToMakeItem(player, recipe).ToString()), eChatType.CT_Missed, eChatLoc.CL_SystemWindow); player.Out.SendTimerWindow(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CraftItem.CurrentlyMaking", itemToCraft.Name), craftingTime); player.Stealth(false); StartCraftingTimerAndSetCallBackMethod(player, recipe, rawMaterials, craftingTime); }
public override int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { switch (itemToCraft.Object_Type) { case (int)eObjectType.Fired: //tested case (int)eObjectType.Longbow: //tested case (int)eObjectType.Crossbow: //tested case (int)eObjectType.Instrument: //tested case (int)eObjectType.RecurvedBow: case (int)eObjectType.CompositeBow: return recipe.CraftingLevel - 20; case (int)eObjectType.Arrow: //tested case (int)eObjectType.Bolt: //tested case (int)eObjectType.Thrown: return recipe.CraftingLevel - 15; case (int)eObjectType.Staff: //tested return recipe.CraftingLevel - 35; } return base.GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft); }
public override int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { switch (itemToCraft.Object_Type) { case (int)eObjectType.Fired: //tested case (int)eObjectType.Longbow: //tested case (int)eObjectType.Crossbow: //tested case (int)eObjectType.Instrument: //tested case (int)eObjectType.RecurvedBow: case (int)eObjectType.CompositeBow: return(recipe.CraftingLevel - 20); case (int)eObjectType.Arrow: //tested case (int)eObjectType.Bolt: //tested case (int)eObjectType.Thrown: return(recipe.CraftingLevel - 15); case (int)eObjectType.Staff: //tested return(recipe.CraftingLevel - 35); } return(base.GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft)); }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected override bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { bool needForge = false; foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb); if (template != null && template.Model == 519) // metal bar { needForge = true; break; } } if (needForge) { foreach (GameStaticItem item in player.GetItemsInRadius(CRAFT_DISTANCE)) { if (item.Name == "forge" || item.Model == 478) // Forge { return(true); } } player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Crafting.CheckTool.NotHaveTools", itemToCraft.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); player.Out.SendMessage(LanguageMgr.GetTranslation(ServerProperties.Properties.DB_LANGUAGE, "Crafting.CheckTool.FindForge"), eChatType.CT_System, eChatLoc.CL_SystemWindow); if (player.Client.Account.PrivLevel > 1) { return(true); } return(false); } return(true); }
protected virtual bool CanPlayerStartToCraftItem(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { if (!GameServer.ServerRules.IsAllowedToCraft(player, itemToCraft)) { return(false); } if (!CheckForTools(player, recipe, itemToCraft, rawMaterials)) { return(false); } if (!CheckSecondCraftingSkillRequirement(player, recipe, itemToCraft, rawMaterials)) { return(false); } if (!CheckRawMaterials(player, recipe, itemToCraft, rawMaterials)) { return(false); } if (player.IsMoving || player.IsStrafing) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CraftItem.MoveAndInterrupt"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (player.InCombat) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CraftItem.CantCraftInCombat"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } return(true); }
/// <summary> /// Calculate chance to succes /// </summary> public virtual int CalculateChanceToMakeItem(GamePlayer player, DBCraftedItem recipe) { int con = GetItemCon(player.GetCraftingSkillValue(m_eskill), recipe.CraftingLevel); if (con < -3) con = -3; if (con > 3) con = 3; switch (con) { // Chance to MAKE ! (100 - chance to fail) case -3: return 100; case -2: return 100; case -1: return 100; case 0: return 100 - 8; case 1: return 100 - 16; case 2: return 100 - 32; case 3: return 0; default: return 0; } }
/// <summary> /// Calculate crafting time /// </summary> public virtual int GetCraftingTime(GamePlayer player, DBCraftedItem recipe, IList <DBCraftedXItem> rawMaterials) { double baseMultiplier = (recipe.CraftingLevel / 100) + 1; ushort materialsCount = 0; foreach (DBCraftedXItem material in rawMaterials) { materialsCount += (ushort)material.Count; } int craftingTime = (int)(baseMultiplier * materialsCount / 4); // Player does check for capital city bonus as well craftingTime = (int)(craftingTime / player.CraftingSpeed); //keep bonuses reduction in crafting time if (Keeps.KeepBonusMgr.RealmHasBonus(DOL.GS.Keeps.eKeepBonusType.Craft_Timers_5, (eRealm)player.Realm)) { craftingTime = (int)(craftingTime / 1.05); } else if (Keeps.KeepBonusMgr.RealmHasBonus(DOL.GS.Keeps.eKeepBonusType.Craft_Timers_3, (eRealm)player.Realm)) { craftingTime = (int)(craftingTime / 1.03); } int con = GetItemCon(player.GetCraftingSkillValue(m_eskill), recipe.CraftingLevel); double mod = 1.0; switch (con) { case -3: mod = 0.4; break; case -2: mod = 0.6; break; case -1: mod = 0.8; break; case 0: mod = 1.0; break; case 1: mod = 1.0; break; case 2: mod = 1.0; break; case 3: mod = 1.0; break; } craftingTime = (int)(craftingTime * mod); if (craftingTime < 1) { craftingTime = 1; } return(craftingTime); }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected virtual bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { return(true); }
/// <summary> /// Verify that player has the needed materials to craft an item /// </summary> public virtual bool CheckRawMaterials(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { ArrayList missingMaterials = null; lock (player.Inventory) { foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb); if (template == null) { player.Out.SendMessage("Can't find a material (" + material.IngredientId_nb + ") needed for this recipe.", eChatType.CT_System, eChatLoc.CL_SystemWindow); log.Error("Cannot find raw material ItemTemplate: " + material.IngredientId_nb + ") needed for recipe: " + recipe.CraftedItemID); return(false); } bool result = false; int count = material.Count; foreach (InventoryItem item in player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack)) { if (item != null && item.Name == template.Name) { if (item.Count >= count) { result = true; break; } else { count -= item.Count; } } } if (result == false) { if (missingMaterials == null) { missingMaterials = new ArrayList(5); } missingMaterials.Add("(" + count + ") " + template.Name); } } if (missingMaterials != null) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckRawMaterial.NoIngredients", itemToCraft.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckRawMaterial.YouAreMissing", itemToCraft.Name), eChatType.CT_Important, eChatLoc.CL_SystemWindow); foreach (string materialName in missingMaterials) { player.Out.SendMessage(materialName, eChatType.CT_Important, eChatLoc.CL_ChatWindow); } if (player.Client.Account.PrivLevel == (uint)ePrivLevel.Player) { return(false); } } return(true); } }
/// <summary> /// Calculate the minumum needed secondary crafting skill level to make the item /// </summary> public virtual int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { return 0; }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected override bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { // TODO : implement tool checks based on recipes return(true); }
protected virtual void StartCraftingTimerAndSetCallBackMethod(GamePlayer player, DBCraftedItem recipe, IList<DBCraftedXItem> rawMaterials, int craftingTime) { player.CraftTimer = new RegionTimer(player); player.CraftTimer.Callback = new RegionTimerCallback(MakeItem); player.CraftTimer.Properties.setProperty(PLAYER_CRAFTER, player); player.CraftTimer.Properties.setProperty(RECIPE_BEING_CRAFTED, recipe); player.CraftTimer.Properties.setProperty(RECIPE_RAW_MATERIAL_LIST, rawMaterials); player.CraftTimer.Start(craftingTime * 1000); }
/// <summary> /// Called when player tries to begin crafting an item /// </summary> public virtual void CraftItem(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { if (!CanPlayerStartToCraftItem(player, recipe, itemToCraft, rawMaterials)) { return; } if (player.IsCrafting) { StopCraftingCurrentItem(player, itemToCraft); return; } int craftingTime = GetCraftingTime(player, recipe, rawMaterials); player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CraftItem.BeginWork", itemToCraft.Name, CalculateChanceToMakeItem(player, recipe).ToString()), eChatType.CT_Missed, eChatLoc.CL_SystemWindow); player.Out.SendTimerWindow(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CraftItem.CurrentlyMaking", itemToCraft.Name), craftingTime); player.Stealth(false); StartCraftingTimerAndSetCallBackMethod(player, recipe, rawMaterials, craftingTime); }
/// <summary> /// Make the crafted item and add it to player's inventory /// </summary> /// <param name="player"></param> /// <param name="recipe"></param> /// <returns></returns> protected virtual void BuildCraftedItem(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft) { Dictionary <int, int> changedSlots = new Dictionary <int, int>(5); // key : > 0 inventory ; < 0 ground || value: < 0 = new item count; > 0 = add to old lock (player.Inventory) { int count = itemToCraft.PackSize < 1 ? 1 : itemToCraft.PackSize; foreach (InventoryItem item in player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack)) { if (item == null) { continue; } if (item.Id_nb.Equals(itemToCraft.Id_nb) == false) { continue; } if (item.Count >= itemToCraft.MaxCount) { continue; } int countFree = item.MaxCount - item.Count; if (count > countFree) { changedSlots.Add(item.SlotPosition, countFree); // existing item should be changed count -= countFree; } else { changedSlots.Add(item.SlotPosition, count); // existing item should be changed count = 0; break; } } if (count > 0) // Add new object { eInventorySlot firstEmptySlot = player.Inventory.FindFirstEmptySlot(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack); if (firstEmptySlot == eInventorySlot.Invalid) { changedSlots.Add(-1, -count); // Create the item on the ground } else { changedSlots.Add((int)firstEmptySlot, -count); // Create the item in the free slot } count = 0; } InventoryItem newItem = null; player.Inventory.BeginChanges(); Dictionary <int, int> .Enumerator enumerator = changedSlots.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <int, int> slot = enumerator.Current; int countToAdd = slot.Value; if (countToAdd > 0) // Add to exiting item { newItem = player.Inventory.GetItem((eInventorySlot)slot.Key); if (newItem != null && player.Inventory.AddCountToStack(newItem, countToAdd)) { InventoryLogging.LogInventoryAction("(craft)", player, eInventoryActionType.Other, newItem.Template, countToAdd); // count incremented, continue with next change continue; } } if (recipe.MakeTemplated) { string adjItem = itemToCraft.Id_nb + (GetQuality(player, recipe).ToString()); ItemTemplate adjItemToCraft = GameServer.Database.FindObjectByKey <ItemTemplate>(adjItem); if (adjItemToCraft != null) { newItem = GameInventoryItem.Create <ItemTemplate>(adjItemToCraft); } else { newItem = GameInventoryItem.Create <ItemTemplate>(itemToCraft); } } else { ItemUnique unique = new ItemUnique(itemToCraft); GameServer.Database.AddObject(unique); newItem = GameInventoryItem.Create <ItemUnique>(unique); newItem.Quality = GetQuality(player, recipe); } newItem.IsCrafted = true; newItem.Creator = player.Name; newItem.Count = -countToAdd; if (slot.Key > 0) // Create new item in the backpack { player.Inventory.AddItem((eInventorySlot)slot.Key, newItem); InventoryLogging.LogInventoryAction("(craft)", player, eInventoryActionType.Craft, newItem.Template, newItem.Count); } else // Create new item on the ground { player.CreateItemOnTheGround(newItem); player.Out.SendDialogBox(eDialogCode.SimpleWarning, 0, 0, 0, 0, eDialogType.Ok, true, LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.BuildCraftedItem.BackpackFull", itemToCraft.Name)); } } player.Inventory.CommitChanges(); player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.BuildCraftedItem.Successfully", itemToCraft.Name, newItem.Quality), eChatType.CT_Missed, eChatLoc.CL_SystemWindow); if (recipe.MakeTemplated == false && newItem.Quality == 100) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.BuildCraftedItem.Masterpiece"), eChatType.CT_Important, eChatLoc.CL_SystemWindow); player.Out.SendPlaySound(eSoundType.Craft, 0x04); } else { player.Out.SendPlaySound(eSoundType.Craft, 0x03); } } }
/// <summary> /// Calculate crafted item quality /// </summary> private int GetQuality(GamePlayer player, DBCraftedItem item) { // 2% chance to get masterpiece, 1:6 chance to get 94-99%, if legendary or if grey con // otherwise moving the most load towards 94%, the higher the item con to the crafter skill //1.87 patch raises min quality to 96% // legendary if (player.GetCraftingSkillValue(m_eskill) >= 1000) { if (Util.Chance(2)) { return(100); // 2% chance for master piece } return(96 + Util.Random(3)); } int delta = GetItemCon(player.GetCraftingSkillValue(m_eskill), item.CraftingLevel); if (delta < -2) { if (Util.Chance(2)) { return(100); // grey items get 2% chance to be master piece } return(96 + Util.Random(3)); // handle grey items like legendary } // this is a type of roulette selection, imagine a roulette wheel where all chances get different sized // fields where the ball can drop, the bigger the field, the bigger the chance // field size is modulated by item con and can be also 0 // possible chance allocation scheme for yellow item // 99: // 98: // 97: o // 96: oo // where one 'o' marks 100 size, this example results in 10% chance for yellow items to be 97% quality delta = delta * 100; int[] chancePart = new int[4]; // index ranges from 96%(0) to 99%(5) int sum = 0; for (int i = 0; i < 4; i++) { chancePart[i] = Math.Max((4 - i) * 100 - delta, 0); // 0 minimum sum += chancePart[i]; } // selection int rand = Util.Random(sum); for (int i = 3; i >= 0; i--) { if (rand < chancePart[i]) { return(96 + i); } rand -= chancePart[i]; } // if something still not clear contact Thrydon/Blue return(96); }
/// <summary> /// Calculate the minumum needed secondary crafting skill level to make the item /// </summary> public virtual int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { return(0); }
/// <summary> /// Calculate chance to gain point /// </summary> public virtual int CalculateChanceToGainPoint(GamePlayer player, DBCraftedItem recipe) { int con = GetItemCon(player.GetCraftingSkillValue(m_eskill), recipe.CraftingLevel); if (con < -3) con = -3; if (con > 3) con = 3; int chance = 0; switch (con) { case -3: return 0; case -2: chance = 15; break; case -1: chance = 30; break; case 0: chance = 45; break; case 1: chance = 55; break; case 2: chance = 45; break; case 3: return 0; default: return 0; } // In capital cities bonuses to crafting apply (patch 1.86) if (player.CurrentRegion.IsCapitalCity) { chance += player.CraftingSkillBonus; if (chance < 0) chance = 0; if (chance > 100) chance = 100; } return chance; }
/// <summary> /// Calculate crafting time /// </summary> public virtual int GetCraftingTime(GamePlayer player, DBCraftedItem recipe, IList<DBCraftedXItem> rawMaterials) { double baseMultiplier = (recipe.CraftingLevel / 100) + 1; ushort materialsCount = 0; foreach (DBCraftedXItem material in rawMaterials) { materialsCount += (ushort)material.Count; } int craftingTime = (int)(baseMultiplier * materialsCount / 4); // Player does check for capital city bonus as well craftingTime = (int)(craftingTime / player.CraftingSpeed); //keep bonuses reduction in crafting time if (Keeps.KeepBonusMgr.RealmHasBonus(DOL.GS.Keeps.eKeepBonusType.Craft_Timers_5, (eRealm)player.Realm)) craftingTime = (int)(craftingTime / 1.05); else if (Keeps.KeepBonusMgr.RealmHasBonus(DOL.GS.Keeps.eKeepBonusType.Craft_Timers_3, (eRealm)player.Realm)) craftingTime = (int)(craftingTime / 1.03); int con = GetItemCon(player.GetCraftingSkillValue(m_eskill), recipe.CraftingLevel); double mod = 1.0; switch (con) { case -3: mod = 0.4; break; case -2: mod = 0.6; break; case -1: mod = 0.8; break; case 0: mod = 1.0; break; case 1: mod = 1.0; break; case 2: mod = 1.0; break; case 3: mod = 1.0; break; } craftingTime = (int)(craftingTime * mod); if (craftingTime < 1) craftingTime = 1; return craftingTime; }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected virtual bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { return true; }
/// <summary> /// Calculate crafted item quality /// </summary> private int GetQuality(GamePlayer player, DBCraftedItem item) { // 2% chance to get masterpiece, 1:6 chance to get 94-99%, if legendary or if grey con // otherwise moving the most load towards 94%, the higher the item con to the crafter skill //1.87 patch raises min quality to 96% // legendary if (player.GetCraftingSkillValue(m_eskill) >= 1000) { if (Util.Chance(2)) { return 100; // 2% chance for master piece } return 96 + Util.Random(3); } int delta = GetItemCon(player.GetCraftingSkillValue(m_eskill), item.CraftingLevel); if (delta < -2) { if (Util.Chance(2)) return 100; // grey items get 2% chance to be master piece return 96 + Util.Random(3); // handle grey items like legendary } // this is a type of roulette selection, imagine a roulette wheel where all chances get different sized // fields where the ball can drop, the bigger the field, the bigger the chance // field size is modulated by item con and can be also 0 // possible chance allocation scheme for yellow item // 99: // 98: // 97: o // 96: oo // where one 'o' marks 100 size, this example results in 10% chance for yellow items to be 97% quality delta = delta * 100; int[] chancePart = new int[4]; // index ranges from 96%(0) to 99%(5) int sum = 0; for (int i = 0; i < 4; i++) { chancePart[i] = Math.Max((4 - i) * 100 - delta, 0); // 0 minimum sum += chancePart[i]; } // selection int rand = Util.Random(sum); for (int i = 3; i >= 0; i--) { if (rand < chancePart[i]) return 96 + i; rand -= chancePart[i]; } // if something still not clear contact Thrydon/Blue return 96; }
/// <summary> /// Remove used raw material from player inventory /// </summary> /// <param name="player"></param> /// <param name="recipe"></param> /// <returns></returns> public virtual bool RemoveUsedMaterials(GamePlayer player, DBCraftedItem recipe, IList <DBCraftedXItem> rawMaterials) { Dictionary <int, int?> dataSlots = new Dictionary <int, int?>(10); lock (player.Inventory) { foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb); if (template == null) { player.Out.SendMessage("Can't find a material (" + material.IngredientId_nb + ") needed for this recipe.", eChatType.CT_System, eChatLoc.CL_SystemWindow); log.Error("RemoveUsedMaterials: Cannot find raw material ItemTemplate: " + material.IngredientId_nb + " needed for recipe: " + recipe.CraftedItemID); return(false); } bool result = false; int count = material.Count; foreach (InventoryItem item in player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack)) { if (item != null && item.Name == template.Name) { if (item.Count >= count) { if (item.Count == count) { dataSlots.Add(item.SlotPosition, null); } else { dataSlots.Add(item.SlotPosition, count); } result = true; break; } else { dataSlots.Add(item.SlotPosition, null); count -= item.Count; } } } if (result == false) { return(false); } } } player.Inventory.BeginChanges(); Dictionary <int, int?> .Enumerator enumerator = dataSlots.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <int, int?> de = enumerator.Current; InventoryItem item = player.Inventory.GetItem((eInventorySlot)de.Key); if (item != null) { if (!de.Value.HasValue) { player.Inventory.RemoveItem(item); } else { player.Inventory.RemoveCountFromStack(item, de.Value.Value); } InventoryLogging.LogInventoryAction(player, "(craft)", eInventoryActionType.Craft, item.Template, de.Value.HasValue ? de.Value.Value : item.Count); } } player.Inventory.CommitChanges(); return(true); //all raw material removed and item created }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected override bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { return(base.CheckForTools(player, recipe, itemToCraft, rawMaterials)); }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected override bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { // TODO : implement tool checks based on recipes return true; }
/// <summary> /// Check if the player has enough secondary crafting skill to build the item /// </summary> /// <param name="player"></param> /// <param name="recipe"></param> /// <returns></returns> public virtual bool CheckSecondCraftingSkillRequirement(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList <DBCraftedXItem> rawMaterials) { int minimumLevel = GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft); if (minimumLevel <= 0) { return(true); // no requirement needed } foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb); if (template == null) { player.Out.SendMessage("Can't find a material (" + material.IngredientId_nb + ") needed for recipe.", eChatType.CT_System, eChatLoc.CL_SystemWindow); log.Error("Cannot find raw material ItemTemplate: " + material.IngredientId_nb + ") needed for recipe: " + recipe.CraftedItemID); return(false); } switch (template.Model) { case 522: //"cloth square" case 537: //"heavy thread" { if (player.GetCraftingSkillValue(eCraftingSkill.ClothWorking) < minimumLevel) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckSecondCraftingSkillRequirement.NoClothworkingSkill", minimumLevel, template.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } break; } case 521: //"leather square" { if (player.GetCraftingSkillValue(eCraftingSkill.LeatherCrafting) < minimumLevel) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckSecondCraftingSkillRequirement.NoLeathercraftingSkill", minimumLevel, template.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } break; } case 519: //"metal bars" { if (player.GetCraftingSkillValue(eCraftingSkill.MetalWorking) < minimumLevel) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckSecondCraftingSkillRequirement.NoMetalworkingSkill", minimumLevel, template.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } break; } case 520: //"wooden boards" { if (player.GetCraftingSkillValue(eCraftingSkill.WoodWorking) < minimumLevel) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckSecondCraftingSkillRequirement.NoWoodworkingSkill", minimumLevel, template.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } break; } } } return(true); }
/// <summary> /// Remove used raw material from player inventory /// </summary> /// <param name="player"></param> /// <param name="recipe"></param> /// <returns></returns> public virtual bool RemoveUsedMaterials(GamePlayer player, DBCraftedItem recipe, IList<DBCraftedXItem> rawMaterials) { Dictionary<int, int?> dataSlots = new Dictionary<int, int?>(10); lock (player.Inventory) { foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey<ItemTemplate>(material.IngredientId_nb); if (template == null) { player.Out.SendMessage("Can't find a material (" + material.IngredientId_nb + ") needed for this recipe.", eChatType.CT_System, eChatLoc.CL_SystemWindow); log.Error("RemoveUsedMaterials: Cannot find raw material ItemTemplate: " + material.IngredientId_nb + " needed for recipe: " + recipe.CraftedItemID); return false; } bool result = false; int count = material.Count; foreach (InventoryItem item in player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack)) { if (item != null && item.Name == template.Name) { if (item.Count >= count) { if (item.Count == count) { dataSlots.Add(item.SlotPosition, null); } else { dataSlots.Add(item.SlotPosition, count); } result = true; break; } else { dataSlots.Add(item.SlotPosition, null); count -= item.Count; } } } if (result == false) { return false; } } } player.Inventory.BeginChanges(); Dictionary<int, int?>.Enumerator enumerator = dataSlots.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<int, int?> de = enumerator.Current; InventoryItem item = player.Inventory.GetItem((eInventorySlot)de.Key); if (item != null) { if (!de.Value.HasValue) { player.Inventory.RemoveItem(item); } else { player.Inventory.RemoveCountFromStack(item, de.Value.Value); } InventoryLogging.LogInventoryAction(player, "(craft)", eInventoryActionType.Craft, item.Template, de.Value.HasValue ? de.Value.Value : item.Count); } } player.Inventory.CommitChanges(); return true;//all raw material removed and item created }
/// <summary> /// Calculate the minumum needed secondary crafting skill level to make the item /// </summary> public override int GetSecondaryCraftingSkillMinimumLevel(DBCraftedItem recipe, ItemTemplate itemToCraft) { switch (itemToCraft.Object_Type) { case (int)eObjectType.Cloth: case (int)eObjectType.Leather: case (int)eObjectType.Studded: return recipe.CraftingLevel - 30; } return base.GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft); }
/// <summary> /// Make the crafted item and add it to player's inventory /// </summary> /// <param name="player"></param> /// <param name="recipe"></param> /// <returns></returns> protected virtual void BuildCraftedItem(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft) { Dictionary<int, int> changedSlots = new Dictionary<int, int>(5); // key : > 0 inventory ; < 0 ground || value: < 0 = new item count; > 0 = add to old lock (player.Inventory) { int count = itemToCraft.PackSize < 1 ? 1 : itemToCraft.PackSize; foreach (InventoryItem item in player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack)) { if (item == null) continue; if (item.Id_nb.Equals(itemToCraft.Id_nb) == false) continue; if (item.Count >= itemToCraft.MaxCount) continue; int countFree = item.MaxCount - item.Count; if (count > countFree) { changedSlots.Add(item.SlotPosition, countFree); // existing item should be changed count -= countFree; } else { changedSlots.Add(item.SlotPosition, count); // existing item should be changed count = 0; break; } } if (count > 0) // Add new object { eInventorySlot firstEmptySlot = player.Inventory.FindFirstEmptySlot(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack); if (firstEmptySlot == eInventorySlot.Invalid) { changedSlots.Add(-1, -count); // Create the item on the ground } else { changedSlots.Add((int)firstEmptySlot, -count); // Create the item in the free slot } count = 0; } InventoryItem newItem = null; player.Inventory.BeginChanges(); Dictionary<int, int>.Enumerator enumerator = changedSlots.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<int, int> slot = enumerator.Current; int countToAdd = slot.Value; if (countToAdd > 0) // Add to exiting item { newItem = player.Inventory.GetItem((eInventorySlot)slot.Key); if (newItem != null && player.Inventory.AddCountToStack(newItem, countToAdd)) { InventoryLogging.LogInventoryAction("(craft)", player, eInventoryActionType.Other, newItem.Template, countToAdd); // count incremented, continue with next change continue; } } if (recipe.MakeTemplated) { string adjItem = itemToCraft.Id_nb+(GetQuality(player, recipe).ToString()); ItemTemplate adjItemToCraft = GameServer.Database.FindObjectByKey<ItemTemplate>(adjItem); if (adjItemToCraft != null) { newItem = GameInventoryItem.Create<ItemTemplate>(adjItemToCraft); } else { newItem = GameInventoryItem.Create<ItemTemplate>(itemToCraft); } } else { ItemUnique unique = new ItemUnique(itemToCraft); GameServer.Database.AddObject(unique); newItem = GameInventoryItem.Create<ItemUnique>(unique); newItem.Quality = GetQuality(player, recipe); } newItem.IsCrafted = true; newItem.Creator = player.Name; newItem.Count = -countToAdd; if (slot.Key > 0) // Create new item in the backpack { player.Inventory.AddItem((eInventorySlot)slot.Key, newItem); InventoryLogging.LogInventoryAction("(craft)", player, eInventoryActionType.Craft, newItem.Template, newItem.Count); } else // Create new item on the ground { player.CreateItemOnTheGround(newItem); player.Out.SendDialogBox(eDialogCode.SimpleWarning, 0, 0, 0, 0, eDialogType.Ok, true, LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.BuildCraftedItem.BackpackFull", itemToCraft.Name)); } } player.Inventory.CommitChanges(); player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.BuildCraftedItem.Successfully", itemToCraft.Name, newItem.Quality), eChatType.CT_Missed, eChatLoc.CL_SystemWindow); if (recipe.MakeTemplated == false && newItem.Quality == 100) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.BuildCraftedItem.Masterpiece"), eChatType.CT_Important, eChatLoc.CL_SystemWindow); player.Out.SendPlaySound(eSoundType.Craft, 0x04); } else { player.Out.SendPlaySound(eSoundType.Craft, 0x03); } } }
/// <summary> /// Check if the player is near the needed tools (forge, lathe, etc) /// </summary> /// <param name="player">the crafting player</param> /// <param name="recipe">the recipe being used</param> /// <param name="itemToCraft">the item to make</param> /// <param name="rawMaterials">a list of raw materials needed to create this item</param> /// <returns>true if required tools are found</returns> protected override bool CheckForTools(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { return base.CheckForTools(player, recipe, itemToCraft, rawMaterials); }
/// <summary> /// Calculate chance to gain point /// </summary> public virtual int CalculateChanceToGainPoint(GamePlayer player, DBCraftedItem recipe) { int con = GetItemCon(player.GetCraftingSkillValue(m_eskill), recipe.CraftingLevel); if (con < -3) { con = -3; } if (con > 3) { con = 3; } int chance = 0; switch (con) { case -3: return(0); case -2: chance = 15; break; case -1: chance = 30; break; case 0: chance = 45; break; case 1: chance = 55; break; case 2: chance = 45; break; case 3: return(0); default: return(0); } // In capital cities bonuses to crafting apply (patch 1.86) if (player.CurrentRegion.IsCapitalCity) { chance += player.CraftingSkillBonus; if (chance < 0) { chance = 0; } if (chance > 100) { chance = 100; } } return(chance); }
/// <summary> /// Check if the player has enough secondary crafting skill to build the item /// </summary> /// <param name="player"></param> /// <param name="recipe"></param> /// <returns></returns> public virtual bool CheckSecondCraftingSkillRequirement(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { int minimumLevel = GetSecondaryCraftingSkillMinimumLevel(recipe, itemToCraft); if (minimumLevel <= 0) return true; // no requirement needed foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey<ItemTemplate>(material.IngredientId_nb); if (template == null) { player.Out.SendMessage("Can't find a material (" + material.IngredientId_nb + ") needed for recipe.", eChatType.CT_System, eChatLoc.CL_SystemWindow); log.Error("Cannot find raw material ItemTemplate: " + material.IngredientId_nb + ") needed for recipe: " + recipe.CraftedItemID); return false; } switch (template.Model) { case 522: //"cloth square" case 537: //"heavy thread" { if (player.GetCraftingSkillValue(eCraftingSkill.ClothWorking) < minimumLevel) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckSecondCraftingSkillRequirement.NoClothworkingSkill", minimumLevel, template.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return false; } break; } case 521: //"leather square" { if (player.GetCraftingSkillValue(eCraftingSkill.LeatherCrafting) < minimumLevel) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckSecondCraftingSkillRequirement.NoLeathercraftingSkill", minimumLevel, template.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return false; } break; } case 519: //"metal bars" { if (player.GetCraftingSkillValue(eCraftingSkill.MetalWorking) < minimumLevel) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckSecondCraftingSkillRequirement.NoMetalworkingSkill", minimumLevel, template.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return false; } break; } case 520: //"wooden boards" { if (player.GetCraftingSkillValue(eCraftingSkill.WoodWorking) < minimumLevel) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckSecondCraftingSkillRequirement.NoWoodworkingSkill", minimumLevel, template.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return false; } break; } } } return true; }
protected virtual void StartCraftingTimerAndSetCallBackMethod(GamePlayer player, DBCraftedItem recipe, IList <DBCraftedXItem> rawMaterials, int craftingTime) { player.CraftTimer = new RegionTimer(player); player.CraftTimer.Callback = new RegionTimerCallback(MakeItem); player.CraftTimer.Properties.setProperty(PLAYER_CRAFTER, player); player.CraftTimer.Properties.setProperty(RECIPE_BEING_CRAFTED, recipe); player.CraftTimer.Properties.setProperty(RECIPE_RAW_MATERIAL_LIST, rawMaterials); player.CraftTimer.Start(craftingTime * 1000); }
/// <summary> /// Begin salvaging a siege weapon /// </summary> /// <param name="player"></param> /// <param name="siegeWeapon"></param> /// <returns></returns> public static int BeginWork(GamePlayer player, GameSiegeWeapon siegeWeapon) { if (siegeWeapon == null) { return(0); } // Galenas siegeWeapon.ReleaseControl(); siegeWeapon.RemoveFromWorld(); bool error = false; DBCraftedItem recipe = GameServer.Database.SelectObject <DBCraftedItem>("Id_nb ='" + siegeWeapon.ItemId + "'"); if (recipe == null) { player.Out.SendMessage("Error retrieving salvage data!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.Error("Salvage Siege Error: DBCraftedItem is null for" + siegeWeapon.ItemId); return(1); } IList <DBCraftedXItem> rawMaterials = GameServer.Database.SelectObjects <DBCraftedXItem>("`CraftedItemId_nb` = '" + recipe.Id_nb + "'"); if (rawMaterials == null || rawMaterials.Count == 0) { player.Out.SendMessage("No raw materials provided for this siege weapon!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.Error("Salvage Siege Error: No Raw Materials found for " + siegeWeapon.ItemId); return(1); } if (player.IsCrafting) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.IsAllowedToBeginWork.EndCurrentAction"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(0); } InventoryItem item; ItemTemplate template; foreach (DBCraftedXItem material in rawMaterials) { template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb); if (template == null) { player.Out.SendMessage("Missing raw material " + material.IngredientId_nb + "!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.Error("Salvage Siege Error: Raw Material not found " + material.IngredientId_nb); return(1); } item = GameInventoryItem.Create <ItemTemplate>(template); item.Count = material.Count; if (!player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, item)) { error = true; break; } InventoryLogging.LogInventoryAction("(salvage)", player, eInventoryActionType.Craft, item.Template, item.Count); } if (error) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.NoRoom"), eChatType.CT_System, eChatLoc.CL_SystemWindow); } return(1); }
/// <summary> /// Verify that player has the needed materials to craft an item /// </summary> public virtual bool CheckRawMaterials(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { ArrayList missingMaterials = null; lock (player.Inventory) { foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey<ItemTemplate>(material.IngredientId_nb); if (template == null) { player.Out.SendMessage("Can't find a material (" + material.IngredientId_nb + ") needed for this recipe.", eChatType.CT_System, eChatLoc.CL_SystemWindow); log.Error("Cannot find raw material ItemTemplate: " + material.IngredientId_nb + ") needed for recipe: " + recipe.CraftedItemID); return false; } bool result = false; int count = material.Count; foreach (InventoryItem item in player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack)) { if (item != null && item.Name == template.Name) { if (item.Count >= count) { result = true; break; } else { count -= item.Count; } } } if (result == false) { if (missingMaterials == null) { missingMaterials = new ArrayList(5); } missingMaterials.Add("(" + count + ") " + template.Name); } } if (missingMaterials != null) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckRawMaterial.NoIngredients", itemToCraft.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CheckRawMaterial.YouAreMissing", itemToCraft.Name), eChatType.CT_Important, eChatLoc.CL_SystemWindow); foreach (string materialName in missingMaterials) { player.Out.SendMessage(materialName, eChatType.CT_Important, eChatLoc.CL_ChatWindow); } if (player.Client.Account.PrivLevel == (uint)ePrivLevel.Player) return false; } return true; } }
protected virtual bool CanPlayerStartToCraftItem(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft, IList<DBCraftedXItem> rawMaterials) { if (!GameServer.ServerRules.IsAllowedToCraft(player, itemToCraft)) { return false; } if (!CheckForTools(player, recipe, itemToCraft, rawMaterials)) { return false; } if (!CheckSecondCraftingSkillRequirement(player, recipe, itemToCraft, rawMaterials)) { return false; } if (!CheckRawMaterials(player, recipe, itemToCraft, rawMaterials)) { return false; } if (player.IsMoving || player.IsStrafing) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CraftItem.MoveAndInterrupt"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return false; } if (player.InCombat) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractCraftingSkill.CraftItem.CantCraftInCombat"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return false; } return true; }
/// <summary> /// Gain a point in the appropriate skills for a recipe and materials /// </summary> public virtual void GainCraftingSkillPoints(GamePlayer player, DBCraftedItem recipe, IList<DBCraftedXItem> rawMaterials) { foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey<ItemTemplate>(material.IngredientId_nb); if (template != null) { switch (template.Model) { case 522: //"cloth square" case 537: //"heavy thread" { if (player.GetCraftingSkillValue(eCraftingSkill.ClothWorking) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.ClothWorking, 1); } break; } case 521: //"leather square" { if (player.GetCraftingSkillValue(eCraftingSkill.LeatherCrafting) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.LeatherCrafting, 1); } break; } case 519: //"metal bars" { if (player.GetCraftingSkillValue(eCraftingSkill.MetalWorking) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.MetalWorking, 1); } break; } case 520: //"wooden boards" { if (player.GetCraftingSkillValue(eCraftingSkill.WoodWorking) < subSkillCap) { player.GainCraftingSkill(eCraftingSkill.WoodWorking, 1); } break; } } } } player.Out.SendUpdateCraftingSkills(); }