Example #1
0
 public SingleCraftDialog(Character character, InteractiveObject interactive, Skill skill)
     : base(interactive, skill, character.Jobs[skill.SkillTemplate.ParentJobId])
 {
     Crafter  = new Crafter(this, character);
     Receiver = Crafter;
     Clients  = new WorldClientCollection(character.Client);
 }
Example #2
0
 public MultiCraftDialog(Character crafter, Character customer, InteractiveObject interactive, Skill skill)
     : base(interactive, skill, crafter.Jobs[skill.SkillTemplate.ParentJobId])
 {
     Crafter  = new Crafter(this, crafter);
     Receiver = new CraftCustomer(this, customer);
     Clients  = new WorldClientCollection(new [] { crafter.Client, customer.Client });
 }
Example #3
0
        public bool Craft()
        {
            var ingredients = GetIngredients().ToArray();
            var recipe      = FindMatchingRecipe(ingredients);

            if (recipe == null)
            {
                InventoryHandler.SendExchangeCraftResultMessage(Clients, ExchangeCraftResultEnum.CRAFT_FAILED);
                return(false);
            }

            if (recipe.ResultLevel > Job.Level && Job.Id != (int)JobEnum.BASE)
            {
                InventoryHandler.SendExchangeCraftResultWithObjectIdMessage(Clients, ExchangeCraftResultEnum.CRAFT_FAILED, recipe.ItemTemplate);
                return(false);
            }

            if (ingredients.Any(x => x.Owner.Inventory[x.Guid]?.Stack < x.Stack * Amount))
            {
                InventoryHandler.SendExchangeCraftResultMessage(Clients, ExchangeCraftResultEnum.CRAFT_FAILED);
                return(false);
            }

            foreach (var item in ingredients)
            {
                var playerItem = item.Owner.Inventory[item.Guid];
                item.Owner.Inventory.RemoveItem(playerItem, (int)item.Stack * Amount);

                if (item.Owner == Crafter.Character)
                {
                    Crafter.MoveItem(item.Guid, 0);
                }
                else
                {
                    Receiver.MoveItem(item.Guid, 0);
                }
            }

            var xp = Job.GetCraftXp(recipe, Amount);

            if (xp > 0)
            {
                Job.Experience += xp;
            }

            if (!ItemManager.Instance.HasToBeGenerated(recipe.ItemTemplate))
            {
                var createdItem = Receiver.Character.Inventory.AddItem(recipe.ItemTemplate, Amount);
                InventoryHandler.SendExchangeCraftResultWithObjectDescMessage(Clients,
                                                                              ExchangeCraftResultEnum.CRAFT_SUCCESS, createdItem, Amount);
                InventoryHandler.SendExchangeCraftInformationObjectMessage(Crafter.Character.Map.Clients, createdItem, Receiver.Character, ExchangeCraftResultEnum.CRAFT_SUCCESS);
            }
            else
            {
                var dict = new Dictionary <List <EffectBase>, int>(new EffectsListComparer());
                for (int i = 0; i < Amount; i++)
                {
                    var effects = ItemManager.Instance.GenerateItemEffects(recipe.ItemTemplate);
                    if (dict.ContainsKey(effects))
                    {
                        dict[effects] += 1;
                    }
                    else
                    {
                        dict.Add(effects, 1);
                    }
                }

                foreach (var keyPair in dict)
                {
                    var createdItem = Receiver.Character.Inventory.AddItem(recipe.ItemTemplate, keyPair.Key, keyPair.Value);
                    InventoryHandler.SendExchangeCraftResultWithObjectDescMessage(Clients,
                                                                                  ExchangeCraftResultEnum.CRAFT_SUCCESS, createdItem, keyPair.Value);
                    InventoryHandler.SendExchangeCraftInformationObjectMessage(Crafter.Character.Map.Clients, createdItem, Receiver.Character, ExchangeCraftResultEnum.CRAFT_SUCCESS);
                }
            }

            ChangeAmount(1);

            return(true);
        }