/// <summary>
        /// If new SalvageYield table is empty then copy values from old Salvage table
        /// </summary>
        public void Update()
        {
            int count = 0;
            var newSalvage = GameServer.Database.SelectAllObjects<SalvageYield>();

            if (newSalvage == null || newSalvage.Count == 0)
            {
                log.InfoFormat("Updating the SalvageYield table...", count);

                var oldSalvage = GameServer.Database.SelectAllObjects<DBSalvage>();

                foreach (DBSalvage salvage in oldSalvage)
                {
                    SalvageYield salvageYield = new SalvageYield();
                    salvageYield.ID = ++count; // start at 1
                    salvageYield.ObjectType = salvage.ObjectType;
                    salvageYield.SalvageLevel = salvage.SalvageLevel;
                    salvageYield.MaterialId_nb = salvage.Id_nb;
                    salvageYield.Count = 0;
                    salvageYield.Realm = salvage.Realm;
                    salvageYield.PackageID = SalvageYield.LEGACY_SALVAGE_ID;
                    GameServer.Database.AddObject(salvageYield);
                }
            }

            if (count > 0)
            {
                log.InfoFormat("Copied {0} entries from Salvage to SalvageYield.", count);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calculate the count per Object_Type
        /// </summary>
        public static int GetCountForSalvage(InventoryItem item, SalvageYield salvage, ItemTemplate rawMaterial)
        {
            long maxCount = 0;

			if (rawMaterial == null)
				return 0;

            #region Weapons

            switch ((eObjectType)item.Object_Type)
            {
                case eObjectType.RecurvedBow:
                case eObjectType.CompositeBow:
                case eObjectType.Longbow:
                case eObjectType.Crossbow:
                case eObjectType.Staff:
                case eObjectType.Fired:
                    maxCount += 36;
                    break;
                case eObjectType.Thrown:
                case eObjectType.CrushingWeapon:
                case eObjectType.SlashingWeapon:
                case eObjectType.ThrustWeapon:
                case eObjectType.Flexible:
                case eObjectType.Blades:
                case eObjectType.Blunt:
                case eObjectType.Piercing:
                case eObjectType.Sword:
                case eObjectType.Hammer:
                case eObjectType.LeftAxe:
                case eObjectType.Axe:
                case eObjectType.HandToHand:
                    {
                        int dps = item.DPS_AF;
                        if (dps > 520)
                            maxCount += 10;
                        else
                            maxCount += 5;
                        break;
                    }
                case eObjectType.TwoHandedWeapon:
                case eObjectType.PolearmWeapon:
                case eObjectType.LargeWeapons:
                case eObjectType.CelticSpear:
                case eObjectType.Scythe:
                case eObjectType.Spear:
                    {
                        int dps = item.DPS_AF;
                        if (dps > 520)
                            maxCount += 15;
                        else
                            maxCount += 10;
                    }
                    break;
                case eObjectType.Shield:
                    switch (item.Type_Damage)
                    {
                        case 1:
                            maxCount += 5;
                            break;
                        case 2:
                            maxCount += 8;
                            break;
                        case 3:
                            maxCount += 12;
                            break;
                        default:
                            maxCount += 5;
                            break;
                    }
                    break;
                case eObjectType.Instrument:
                    switch (item.Type_Damage)
                    {
                        case 1:
                            maxCount += 5;
                            break;
                        case 2:
                            maxCount += 8;
                            break;
                        case 3:
                            maxCount += 12;
                            break;
                        default:
                            maxCount += 5;
                            break;

                    }
                    break;

                #endregion Weapons

            #region Armor

                case eObjectType.Cloth:
                case eObjectType.Leather:
                case eObjectType.Reinforced:
                case eObjectType.Studded:
                case eObjectType.Scale:
                case eObjectType.Chain:
                case eObjectType.Plate:
                    switch (item.Item_Type)
                    {
                        case Slot.HELM:
                            maxCount += 12;
                            break;
                        case Slot.TORSO:
                            maxCount += 17;
                            break;
                        case Slot.LEGS:
                            maxCount += 15;
                            break;

                        case Slot.ARMS:
                            maxCount += 10;
                            break;

                        case Slot.HANDS:
                            maxCount += 6;
                            break;
                        case Slot.FEET:
                            maxCount += 5;
                            break;
                        default:
                            maxCount += 5;
                            break;
                    }
                    break;
            }
        #endregion Armor

            #region Modifications

            if (maxCount < 1)
                maxCount = (int)(item.Price * 0.45 / rawMaterial.Price);

            int toadd = 0;

            if (item.Quality > 97 && !item.IsCrafted)
                for (int i = 97; i < item.Quality;)
                {
                    toadd += 3;
                    i++;
                }

            if (item.Price > 300000 && !item.IsCrafted)
            {
                long i = item.Price;
                i = item.Price / 100000;
                toadd += (int)i;
            }

            if (toadd > 0)
                maxCount += toadd;

            #region SpecialFix MerchantList

            if (item.Bonus8 > 0)
                if (item.Bonus8Type == 0 || item.Bonus8Type.ToString() == "")
                    maxCount = item.Bonus8;

            #endregion SpecialFix MerchantList

            if (item.Condition != item.MaxCondition && item.Condition < item.MaxCondition)
            {
                long usureoverall = (maxCount * ((item.Condition / 5) / 1000)) / 100; // assume that all items have 50000 base con
                maxCount = usureoverall;
            }

            if (maxCount < 1)
                maxCount = 1;
            else if (maxCount > 500)
                maxCount = 500;

            #endregion Modifications

            return (int)maxCount;
        }
Esempio n. 3
0
		/// <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;
		}
Esempio n. 4
0
        public void OnCommand(GameClient client, string[] args)
        {
            if (args.Length < 2)
            {
                DisplaySyntax(client);
                return;
            }

            try
            {
                #region List

                if (args[1].ToLower() == "list")
                {
                    List<string> list = new List<string>();
                    int count = 0;
                    foreach (int value in Enum.GetValues(typeof(eCraftingSkill)))
                    {
                        if (++count < 16) // get rid of duplicate due to _Last
                            list.Add(value + " = " + Enum.GetName(typeof(eCraftingSkill), value));
                    }

                    client.Out.SendCustomTextWindow(LanguageMgr.GetTranslation(client, "GMCommands.Crafting.SkillDescription"), list);
                    return;
                }

                #endregion List

                #region Salvage

                if (args[1].ToLower() == "salvageinfo")
                {
                    List<string> list = new List<string>();
                    int salvageID = Convert.ToInt32(args[2]);
                    SalvageYield salvage = GameServer.Database.SelectObject<SalvageYield>("ID=" + salvageID);

                    if (salvage == null)
                    {
                        DisplayMessage(client, "SalvageYield ID not found!");
                        return;
                    }

                    ItemTemplate template = GameServer.Database.FindObjectByKey<ItemTemplate>(salvage.MaterialId_nb);
                    string materialName = "Not Found!";

                    if (template != null)
                    {
                        materialName = template.Name;
                    }

                    list.Add("SalvageYield ID: " + salvageID);
                    list.Add("     ObjectType: " + (salvage.ObjectType == 0 ? "Unused" : salvage.ObjectType.ToString()));
                    list.Add("   SalvageLevel: " + (salvage.SalvageLevel == 0 ? "Unused" : salvage.SalvageLevel.ToString()));
                    list.Add("       Material: " + materialName + " (" + salvage.MaterialId_nb + ")");
                    list.Add("          Count: " + (salvage.Count == 0 ? "Calculated" : salvage.Count.ToString()));
                    list.Add("          Realm: " + (salvage.Realm == 0 ? "Any" : GlobalConstants.RealmToName((eRealm)salvage.Realm)));
                    list.Add("      PackageID: " + salvage.PackageID);

                    client.Out.SendCustomTextWindow("SalvageYield ID " + salvageID, list);
                    return;
                }

                if (args[1].ToLower() == "salvageadd" || args[1].ToLower() == "salvageupdate")
                {
                    try
                    {
                        int salvageID = Convert.ToInt32(args[2]);
                        string material = args[3];
                        int count = Convert.ToInt32(args[4]);
                        byte realm = 0;
                        string package = "";

                        if (args.Length > 5)
                            realm = Convert.ToByte(args[5]);

                        if (args.Length > 6)
                            package = args[6];

                        ItemTemplate template = GameServer.Database.FindObjectByKey<ItemTemplate>(material);

                        if (template == null)
                        {
                            DisplayMessage(client, "Material id_nb " + material + " not found!");
                            return;
                        }

                        SalvageYield salvage = GameServer.Database.SelectObject<SalvageYield>("ID=" + salvageID);

                        if (args[1].ToLower() == "salvageadd")
                        {
                            if (salvage != null)
                            {
                                DisplayMessage(client, "This SalvageYield ID already exists, use salvageupdate to change it.");
                                return;
                            }

                            salvage = new SalvageYield();
                            if (salvageID > 0)
                                salvage.ID = salvageID;

                            salvage.MaterialId_nb = material;
                            salvage.Count = Math.Max(1, count);
                            salvage.Realm = realm;

                            if (package == "")
                            {
                                package = client.Player.Name;
                            }

                            salvage.PackageID = package;

                            GameServer.Database.AddObject(salvage);

                            DisplayMessage(client, string.Format("Created SalvageYield ID: {0}, Material: {1}, Count: {2}, Realm: {3}, PackageID: {4}",
                                                                    salvage.ID, salvage.MaterialId_nb, salvage.Count, salvage.Realm, salvage.PackageID));
                        }
                        else
                        {
                            if (salvage == null)
                            {
                                DisplayMessage(client, "SalvageID not found!");
                                return;
                            }

                            if (salvage.PackageID == SalvageYield.LEGACY_SALVAGE_ID)
                            {
                                DisplayMessage(client, "This SalvageYield ID is used for legacy salvage support and can not be updated.");
                                return;
                            }

                            salvage.MaterialId_nb = material;
                            salvage.Count = Math.Max(1, count);
                            salvage.Realm = realm;

                            if (string.IsNullOrEmpty(salvage.PackageID) && package == "")
                            {
                                package = client.Player.Name;
                            }

                            if (package != "")
                            {
                                salvage.PackageID = package;
                            }

                            GameServer.Database.SaveObject(salvage);

                            DisplayMessage(client, string.Format("Updated SalvageYield ID: {0}, Material: {1}, Count: {2}, Realm: {3}, PackageID: {4}",
                                                                    salvage.ID, salvage.MaterialId_nb, salvage.Count, salvage.Realm, salvage.PackageID));
                        }
                    }
                    catch
                    {
                        DisplaySyntax(client);
                    }

                    return;
                }

                #endregion Salvage

                GamePlayer target = null;
                if ((client.Player.TargetObject != null) && (client.Player.TargetObject is GamePlayer))
                    target = client.Player.TargetObject as GamePlayer;
                else
                {
                    DisplayMessage(client, LanguageMgr.GetTranslation(client, "GMCommands.Crafting.NoPlayerTarget"));
                    return;
                }

                switch (args[1].ToLower())
                {
                    #region Add

                    case "add":
                        {
                            eCraftingSkill craftingSkillID = eCraftingSkill.NoCrafting;
                            int startLevel = 1;
                            try
                            {
                                craftingSkillID = (eCraftingSkill)Convert.ToUInt16(args[2]);
                                if (args.Length > 3)
                                    startLevel = Convert.ToUInt16(args[3]);

                                AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(craftingSkillID);
                                if (skill == null)
                                {
                                    DisplayMessage(client, LanguageMgr.GetTranslation(client, "GMCommands.Crafting.InvalidSkill"));
                                }
                                else
                                {
                                    if (target.AddCraftingSkill(craftingSkillID, startLevel))
                                    {
                                        target.Out.SendUpdateCraftingSkills();
                                        target.SaveIntoDatabase();
                                        DisplayMessage(client, LanguageMgr.GetTranslation(client, "GMCommands.Crafting.SkillAdded", skill.Name));
                                    }
                                    else
                                    {
                                        DisplayMessage(client, LanguageMgr.GetTranslation(client, "GMCommands.Crafting.AlreadyHaveSkill", target.Name, skill.Name));
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                DisplaySyntax(client);
                            }
                            break;
                        }

                    #endregion Add

                    #region Change

                    case "change":
                        {
                            eCraftingSkill craftingSkillID = eCraftingSkill.NoCrafting;
                            int amount = 1;
                            try
                            {
                                craftingSkillID = (eCraftingSkill)Convert.ToUInt16(args[2]);
                                if (args.Length > 3)
                                    amount = Convert.ToUInt16(args[3]);

                                AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(craftingSkillID);
                                if (skill == null)
                                {
                                    DisplayMessage(client, LanguageMgr.GetTranslation(client, "GMCommands.Crafting.InvalidSkill"));
                                }
                                else
                                {
                                    if (target.GetCraftingSkillValue(craftingSkillID) < 0)
                                    {
                                        DisplayMessage(client, LanguageMgr.GetTranslation(client, "GMCommands.Crafting.NotHaveSkillAddIt", target.Name, skill.Name));
                                        return;
                                    }

                                    target.GainCraftingSkill(craftingSkillID, amount);
                                    target.Out.SendUpdateCraftingSkills();
                                    target.SaveIntoDatabase();
                                    DisplayMessage(client, LanguageMgr.GetTranslation(client, "GMCommands.Crafting.SkillChanged", skill.Name));
                                    DisplayMessage(client, LanguageMgr.GetTranslation(client, "GMCommands.Crafting.NowHasSkillPoints", target.Name, target.GetCraftingSkillValue(craftingSkillID), (eCraftingSkill)craftingSkillID));
                                }
                            }
                            catch (Exception)
                            {
                                DisplaySyntax(client);
                                return;
                            }
                            break;
                        }

                    #endregion Change

                    #region Default

                    default:
                        {
                            DisplaySyntax(client);
                            break;
                        }

                    #endregion Default
                }
            }
            catch
            {
                DisplaySyntax(client);
            }
        }