public override void Read(PacketStream stream) { var craftId = stream.ReadUInt32(); var objId = stream.ReadBc(); // no idea what this one is boys. var count = stream.ReadInt32(); _log.Debug("CSExecuteCraft, craftId : {0} , objId : {1}, count : {2}", craftId, objId, count); /* tests */ Craft craft = CraftManager.Instance.GetCraftById(craftId); List <CraftMaterial> mats = CraftManager.Instance.GetMaterialsForCraftId(craftId); CraftProduct result = CraftManager.Instance.GetResultForCraftId(craftId); //need to check that player has all the required items in inventory //TODO //this snippet adds the resulting item to player inventory Character character = Connection.ActiveChar; Item resultItem = ItemManager.Instance.Create(result.ItemId, result.Amount, 0); var res = character.Inventory.AddItem(resultItem); if (res == null) { ItemIdManager.Instance.ReleaseId((uint)resultItem.Id); return; } var tasks = new List <ItemTask>(); if (res.Id != resultItem.Id) { tasks.Add(new ItemCountUpdate(res, resultItem.Count)); } else { tasks.Add(new ItemAdd(resultItem)); } character.SendPacket(new SCItemTaskSuccessPacket(ItemTaskType.AutoLootDoodadItem, tasks, new List <ulong>())); }
public void Load() { _crafts = new Dictionary <uint, Craft>(); _craftProducts = new Dictionary <uint, CraftProduct>(); _craftMaterials = new Dictionary <uint, List <CraftMaterial> >(); _log.Info("Loading crafts..."); using (var connection = SQLite.CreateConnection()) { /* Crafts */ using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM crafts"; command.Prepare(); using (var reader = new SQLiteWrapperReader(command.ExecuteReader())) { while (reader.Read()) { var template = new Craft(); template.Id = reader.GetUInt32("id"); template.CastDelay = reader.GetInt32("cast_delay"); template.ToolId = reader.GetUInt32("tool_id", 0); template.SkillId = reader.GetUInt32("skill_id", 0); template.WiId = reader.GetUInt32("wi_id"); template.MilestoneId = reader.GetUInt32("milestone_id", 0); template.ReqDoodadId = reader.GetUInt32("req_doodad_id", 0); template.NeedBind = reader.GetBoolean("need_bind"); template.AcId = reader.GetUInt32("ac_id", 0); template.ActabilityLimit = reader.GetInt32("actability_limit"); template.ShowUpperCraft = reader.GetBoolean("show_upper_crafts"); template.RecommendLevel = reader.GetInt32("recommend_level"); template.VisibleOrder = reader.GetInt32("visible_order"); _crafts.Add(template.Id, template); } } } /* Craft products (item you get at the end) */ using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM craft_products"; command.Prepare(); using (var reader = new SQLiteWrapperReader(command.ExecuteReader())) { while (reader.Read()) { var template = new CraftProduct(); template.Id = reader.GetUInt32("id"); template.CraftId = reader.GetUInt32("craft_id"); template.ItemId = reader.GetUInt32("item_id"); template.Amount = reader.GetInt32("amount", 1); //We always want to produce at least 1 item ? template.Rate = reader.GetInt32("rate"); template.ShowLowerCrafts = reader.GetBoolean("show_lower_crafts"); template.UseGrade = reader.GetBoolean("use_grade"); template.ItemGradeId = reader.GetUInt32("item_grade_id"); _craftProducts.Add(template.CraftId, template); // Using craftID so it's easier to find in the dictionary. Need to make sure results dont have duplicates later on. they do not in my db } } } /* Craft products (item you get at the end) */ using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM craft_materials"; command.Prepare(); using (var reader = new SQLiteWrapperReader(command.ExecuteReader())) { while (reader.Read()) { var template = new CraftMaterial(); template.Id = reader.GetUInt32("id"); template.CraftId = reader.GetUInt32("craft_id"); template.ItemId = reader.GetUInt32("item_id"); template.Amount = reader.GetInt32("amount", 1); //We always want to cost at least 1 item ? template.MainGrade = reader.GetBoolean("main_grade"); if (!_craftMaterials.ContainsKey(template.CraftId)) { _craftMaterials.Add(template.CraftId, new List <CraftMaterial>()); } _craftMaterials[template.CraftId].Add(template); // Using craftID so it's easier to find in the dictionary. Need to make sure results dont have duplicates later on. they do not in my db } } } } _log.Info("Loaded crafts", _crafts.Count); }