/// <summary> /// Check if the player can begin to salvage an item /// </summary> /// <param name="player"></param> /// <param name="item"></param> /// <returns></returns> public static bool IsAllowedToBeginWork(GamePlayer player, InventoryItem item) { if (player.InCombat) { player.Out.SendMessage("You can't salvage while in combat.", eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (item.IsNotLosingDur || item.IsIndestructible) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.NoSalvage", item.Name + ". This item is indestructible"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } // using negative numbers to indicate item cannot be salvaged if (item.SalvageYieldID < 0) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client, "Salvage.BeginWork.NoSalvage", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (item.SlotPosition < (int)eInventorySlot.FirstBackpack || item.SlotPosition > (int)eInventorySlot.LastBackpack) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.IsAllowedToBeginWork.BackpackItems"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } eCraftingSkill skill = CraftingMgr.GetSecondaryCraftingSkillToWorkOnItem(item); if (skill == eCraftingSkill.NoCrafting) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.NoSalvage", item.Name + ". You do not have the required secondary skill"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (player.IsCrafting) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.IsAllowedToBeginWork.EndCurrentAction"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (player.GetCraftingSkillValue(skill) < (0.75 * CraftingMgr.GetItemCraftLevel(item))) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.IsAllowedToBeginWork.NotEnoughSkill", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } return(true); }
/// <summary> /// Check if the player own can enchant the item /// </summary> /// <param name="player"></param> /// <param name="item"></param> /// <param name="percentNeeded">min 50 max 100</param> /// <returns></returns> public static bool IsAllowedToBeginWork(GamePlayer player, InventoryItem item, int percentNeeded) { if (item.IsNotLosingDur) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Repair.IsAllowedToBeginWork.CantRepair", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (item.SlotPosition < (int)eInventorySlot.FirstBackpack || item.SlotPosition > (int)eInventorySlot.LastBackpack) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Repair.IsAllowedToBeginWork.BackpackItems"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } eCraftingSkill skill = CraftingMgr.GetSecondaryCraftingSkillToWorkOnItem(item); if (skill == eCraftingSkill.NoCrafting) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Repair.IsAllowedToBeginWork.CantRepair", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (player.IsCrafting) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Repair.IsAllowedToBeginWork.EndCurrentAction"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (item.Condition >= item.MaxCondition) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Repair.IsAllowedToBeginWork.FullyRepaired", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } if (player.GetCraftingSkillValue(skill) < ((percentNeeded / 100) * CraftingMgr.GetItemCraftLevel(item))) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Repair.IsAllowedToBeginWork.NotEnoughSkill", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } return(true); }
/// <summary> /// Calculate the chance of sucess /// </summary> protected static int CalculateSuccessChances(GamePlayer player, InventoryItem item) { eCraftingSkill skill = CraftingMgr.GetSecondaryCraftingSkillToWorkOnItem(item); if (skill == eCraftingSkill.NoCrafting) { return(0); } int chancePercent = (int)((90 / (CraftingMgr.GetItemCraftLevel(item) * 0.5)) * player.GetCraftingSkillValue(skill)) - 80; // 50% = 10% chance, 100% = 100% chance if (chancePercent > 100) { chancePercent = 100; } else if (chancePercent < 0) { chancePercent = 0; } return(chancePercent); }
/// <summary> /// Return the material yield for this salvage. /// </summary> public static int GetMaterialYield(GamePlayer player, InventoryItem item, SalvageYield salvageYield, ItemTemplate rawMaterial) { int maxCount = 0; if (rawMaterial == null) { return(0); } if (ServerProperties.Properties.USE_NEW_SALVAGE) { maxCount = GetCountForSalvage(item, salvageYield, rawMaterial); } else { maxCount = (int)(item.Price * 0.45 / rawMaterial.Price); // crafted item return max 45% of the item value in material if (item.IsCrafted) { maxCount = (int)Math.Ceiling((double)maxCount / 2); } } int playerPercent = player.GetCraftingSkillValue(CraftingMgr.GetSecondaryCraftingSkillToWorkOnItem(item)) * 100 / CraftingMgr.GetItemCraftLevel(item); if (playerPercent > 100) { playerPercent = 100; } else if (playerPercent < 75) { playerPercent = 75; } int minCount = (int)(((maxCount - 1) / 25f) * playerPercent) - ((3 * maxCount) - 4); //75% => min = 1; 100% => min = maxCount; salvageYield.Count = Util.Random(minCount, maxCount); return(salvageYield.Count); }
/// <summary> /// Begin salvaging an inventory item /// </summary> /// <param name="item"></param> /// <param name="player"></param> /// <returns></returns> public static int BeginWork(GamePlayer player, InventoryItem item) { SalvageYield salvageYield = null; if (!IsAllowedToBeginWork(player, item)) { return(0); } int salvageLevel = CraftingMgr.GetItemCraftLevel(item) / 100; if (salvageLevel > 9) { salvageLevel = 9; // max 9 } string sql = ""; if (item.SalvageYieldID == 0) { sql = "ObjectType=" + item.Object_Type + " AND SalvageLevel=" + salvageLevel; } else { sql = "ID=" + item.SalvageYieldID; } if (ServerProperties.Properties.USE_SALVAGE_PER_REALM) { // Some items use realm, some do not, so allow a find of either a set realm, or 0 sql += " AND (Realm=" + item.Realm + " OR Realm=0)"; } salvageYield = GameServer.Database.SelectObject <SalvageYield>(sql); ItemTemplate material = null; if (salvageYield != null && string.IsNullOrEmpty(salvageYield.MaterialId_nb) == false) { material = GameServer.Database.FindObjectByKey <ItemTemplate>(salvageYield.MaterialId_nb); if (material == null) { player.Out.SendMessage("Can't find material (" + material.Id_nb + ") needed to salvage this item!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.ErrorFormat("Salvage Error for ID: {0}: Material not found: {1}", salvageYield.ID, material.Id_nb); } } if (material == null) { if (salvageYield == null && item.SalvageYieldID > 0) { player.Out.SendMessage("This items salvage recipe (" + item.SalvageYieldID + ") not implemented yet.", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.ErrorFormat("SalvageYield ID {0} not found for item: {1}", item.SalvageYieldID, item.Name); } else if (salvageYield == null) { player.Out.SendMessage("Salvage recipe not found for this item.", eChatType.CT_System, eChatLoc.CL_SystemWindow); log.ErrorFormat("Salvage Lookup Error: ObjectType: {0}, Item: {1}", item.Object_Type, item.Name); } return(0); } if (player.IsMoving || player.IsStrafing) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.InterruptSalvage"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(0); } if (player.IsStealthed) { player.Stealth(false); } player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.BeginSalvage", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); // clone the yield entry and update values to work with this salvage (not saved to the DB) SalvageYield yield = salvageYield.Clone() as SalvageYield; if (item.SalvageYieldID == 0 || yield.Count == 0) { // Calculated salvage values int count = GetMaterialYield(player, item, yield, material); if (count < 1) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.NoSalvage", item.Name + ". The material returned amount is zero"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(0); } } player.Out.SendTimerWindow(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.Salvaging", item.Name), yield.Count); player.CraftTimer = new RegionTimer(player); player.CraftTimer.Callback = new RegionTimerCallback(Proceed); player.CraftTimer.Properties.setProperty(AbstractCraftingSkill.PLAYER_CRAFTER, player); player.CraftTimer.Properties.setProperty(SALVAGED_ITEM, item); player.CraftTimer.Properties.setProperty(SALVAGE_YIELD, yield); player.CraftTimer.Start(yield.Count * 1000); return(1); }