/// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="desiredQuality">
        /// </param>
        /// <param name="ts">
        /// </param>
        /// <param name="sourceItem">
        /// </param>
        /// <param name="targetItem">
        /// </param>
        /// <returns>
        /// </returns>
        private static bool WindowBuild(
            IZoneClient client,
            int desiredQuality,
            TradeSkillEntry ts,
            Item sourceItem,
            Item targetItem)
        {
            if (!((ts.MinTargetQL >= targetItem.Quality) || (ts.MinTargetQL == 0)))
            {
                return(false);
            }

            if (!ts.ValidateRange(sourceItem.Quality, targetItem.Quality))
            {
                return(false);
            }

            foreach (TradeSkillSkill tss in ts.Skills)
            {
                if (client.Controller.Character.Stats[tss.StatId].Value
                    < Convert.ToInt32(tss.Percent / 100M * targetItem.Quality))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="quality">
        /// </param>
        public static void TradeSkillBuildPressed(ZoneClient client, int quality)
        {
            TradeSkillInfo source = client.Character.TradeSkillSource;
            TradeSkillInfo target = client.Character.TradeSkillTarget;

            Item sourceItem = client.Character.BaseInventory.GetItemInContainer(source.Container, source.Placement);
            Item targetItem = client.Character.BaseInventory.GetItemInContainer(target.Container, target.Placement);

            TradeSkillEntry ts = TradeSkill.Instance.GetTradeSkillEntry(sourceItem.HighID, targetItem.HighID);

            quality = Math.Min(quality, ItemLoader.ItemList[ts.ResultHighId].Quality);
            if (ts != null)
            {
                if (WindowBuild(client, quality, ts, sourceItem, targetItem))
                {
                    Item           newItem        = new Item(quality, ts.ResultLowId, ts.ResultHighId);
                    InventoryError inventoryError = client.Character.BaseInventory.TryAdd(newItem);
                    if (inventoryError == InventoryError.OK)
                    {
                        AddTemplate.Send(client, newItem);

                        // Delete source?
                        if ((ts.DeleteFlag & 1) == 1)
                        {
                            client.Character.BaseInventory.RemoveItem(source.Container, source.Placement);
                            DeleteItem.Send(client, source.Container, source.Placement);
                        }

                        // Delete target?
                        if ((ts.DeleteFlag & 2) == 2)
                        {
                            client.Character.BaseInventory.RemoveItem(target.Container, target.Placement);
                            DeleteItem.Send(client, target.Container, target.Placement);
                        }

                        client.Character.Playfield.Publish(
                            ChatText.CreateIM(
                                client.Character,
                                SuccessMessage(
                                    sourceItem,
                                    targetItem,
                                    new Item(quality, ts.ResultLowId, ts.ResultHighId))));

                        client.Character.Stats[StatIds.xp].Value += CalculateXP(quality, ts);
                    }
                }
            }
            else
            {
                client.Character.Playfield.Publish(
                    ChatText.CreateIM(
                        client.Character,
                        "It is not possible to assemble those two items. Maybe the order was wrong?"));
                client.Character.Playfield.Publish(ChatText.CreateIM(client.Character, "No combination found!"));
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="quality">
        /// </param>
        /// <param name="ts">
        /// </param>
        /// <returns>
        /// </returns>
        private static int CalculateXP(int quality, TradeSkillEntry ts)
        {
            int absMinQL = ItemLoader.ItemList[ts.ResultLowId].Quality;
            int absMaxQL = ItemLoader.ItemList[ts.ResultHighId].Quality;

            if (absMaxQL == absMinQL)
            {
                return(ts.MaxXP);
            }

            return
                ((int)
                 Math.Floor(
                     (double)((ts.MaxXP - ts.MinXP) / (absMaxQL - absMinQL)) * (quality - absMinQL) + ts.MinXP));
        }
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        private static void TradeSkillChanged(IZoneClient client)
        {
            TradeSkillInfo source = client.Controller.Character.TradeSkillSource;
            TradeSkillInfo target = client.Controller.Character.TradeSkillTarget;

            if ((source != null) && (target != null))
            {
                Item sourceItem = client.Controller.Character.BaseInventory.GetItemInContainer(
                    source.Container,
                    source.Placement);
                Item targetItem = client.Controller.Character.BaseInventory.GetItemInContainer(
                    target.Container,
                    target.Placement);

                TradeSkillEntry ts = TradeSkill.Instance.GetTradeSkillEntry(sourceItem.HighID, targetItem.HighID);
                if (ts != null)
                {
                    if (ts.ValidateRange(sourceItem.Quality, targetItem.Quality))
                    {
                        foreach (TradeSkillSkill tsi in ts.Skills)
                        {
                            int skillReq = (int)Math.Ceiling(tsi.Percent / 100M * targetItem.Quality);
                            if (skillReq > client.Controller.Character.Stats[tsi.StatId].Value)
                            {
                                TradeSkillPacket.SendRequirement(client.Controller.Character, tsi.StatId, skillReq);
                            }
                        }

                        int leastbump = 0;
                        int maxbump   = 0;
                        if (ts.IsImplant)
                        {
                            if (targetItem.Quality >= 250)
                            {
                                maxbump = 5;
                            }
                            else if (targetItem.Quality >= 201)
                            {
                                maxbump = 4;
                            }
                            else if (targetItem.Quality >= 150)
                            {
                                maxbump = 3;
                            }
                            else if (targetItem.Quality >= 100)
                            {
                                maxbump = 2;
                            }
                            else if (targetItem.Quality >= 50)
                            {
                                maxbump = 1;
                            }
                        }

                        foreach (TradeSkillSkill tsSkill in ts.Skills)
                        {
                            if (tsSkill.SkillPerBump != 0)
                            {
                                leastbump =
                                    Math.Min(
                                        Convert.ToInt32(
                                            (client.Controller.Character.Stats[tsSkill.StatId].Value
                                             - (tsSkill.Percent / 100M * targetItem.Quality)) / tsSkill.SkillPerBump),
                                        maxbump);
                            }
                        }

                        TradeSkillPacket.SendResult(
                            client.Controller.Character,
                            targetItem.Quality,
                            Math.Min(targetItem.Quality + leastbump, ItemLoader.ItemList[ts.ResultHighId].Quality),
                            ts.ResultLowId,
                            ts.ResultHighId);
                    }
                    else
                    {
                        TradeSkillPacket.SendOutOfRange(
                            client.Controller.Character,
                            Convert.ToInt32(
                                Math.Round((double)targetItem.Quality - ts.QLRangePercent * targetItem.Quality / 100)));
                    }
                }
                else
                {
                    TradeSkillPacket.SendNotTradeskill(client.Controller.Character);
                }
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="desiredQuality">
        /// </param>
        /// <param name="ts">
        /// </param>
        /// <param name="sourceItem">
        /// </param>
        /// <param name="targetItem">
        /// </param>
        /// <returns>
        /// </returns>
        private static bool WindowBuild(
            ZoneClient client, 
            int desiredQuality, 
            TradeSkillEntry ts, 
            Item sourceItem, 
            Item targetItem)
        {
            if (!((ts.MinTargetQL >= targetItem.Quality) || (ts.MinTargetQL == 0)))
            {
                return false;
            }

            if (!ts.ValidateRange(sourceItem.Quality, targetItem.Quality))
            {
                return false;
            }

            foreach (TradeSkillSkill tss in ts.Skills)
            {
                if (client.Character.Stats[tss.StatId].Value < Convert.ToInt32(tss.Percent / 100M * targetItem.Quality))
                {
                    return false;
                }
            }

            return true;
        }
        /// <summary>
        /// </summary>
        /// <param name="quality">
        /// </param>
        /// <param name="ts">
        /// </param>
        /// <returns>
        /// </returns>
        private static int CalculateXP(int quality, TradeSkillEntry ts)
        {
            int absMinQL = ItemLoader.ItemList[ts.ResultLowId].Quality;
            int absMaxQL = ItemLoader.ItemList[ts.ResultHighId].Quality;
            if (absMaxQL == absMinQL)
            {
                return ts.MaxXP;
            }

            return
                (int)
                    Math.Floor(
                        (double)((ts.MaxXP - ts.MinXP) / (absMaxQL - absMinQL)) * (quality - absMinQL) + ts.MinXP);
        }