diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index 44bc747..45173cc 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -208,6 +208,42 @@ public class ContentController : Controller { return Ok(response); } + [HttpPost] + [Produces("application/xml")] + [Route("ContentWebService.asmx/SetCommonInventoryAttribute")] + [VikingSession] + public IActionResult SetCommonInventoryAttribute(Viking viking, [FromForm] int commonInventoryID, [FromForm] string pairxml) { + InventoryItem? item = viking.InventoryItems.FirstOrDefault(e => e.Id == commonInventoryID); + + List itemAttributes; + if (item.AttributesSerialized != null) { + itemAttributes = XmlUtil.DeserializeXml(item.AttributesSerialized).Pairs.ToList(); + } else { + itemAttributes = new List(); + } + + Schema.PairData newItemAttributes = XmlUtil.DeserializeXml(pairxml); + foreach (var p in newItemAttributes.Pairs) { + var pairItem = itemAttributes.FirstOrDefault(e => e.PairKey == p.PairKey); + if (pairItem != null){ + pairItem.PairValue = p.PairValue; + } else { + itemAttributes.Add(p); + } + } + + if (itemAttributes.Count > 0) { + item.AttributesSerialized = XmlUtil.SerializeXml( + new Schema.PairData{ + Pairs = itemAttributes.ToArray() + } + ); + } + + ctx.SaveChanges(); + return Ok(true); + } + [HttpPost] [Produces("application/xml")] [Route("ContentWebService.asmx/UseInventory")] diff --git a/src/Model/InventoryItem.cs b/src/Model/InventoryItem.cs index 02a62dc..ea6c5d1 100644 --- a/src/Model/InventoryItem.cs +++ b/src/Model/InventoryItem.cs @@ -8,9 +8,11 @@ namespace sodoff.Model { public int ItemId { get; set; } public int VikingId { get; set; } - + public string? StatsSerialized { get; set; } + public string? AttributesSerialized { get; set; } + public virtual Viking Viking { get; set; } = null!; public int Quantity { get; set; } diff --git a/src/Services/InventoryService.cs b/src/Services/InventoryService.cs index 9b4e8fb..ad2c062 100644 --- a/src/Services/InventoryService.cs +++ b/src/Services/InventoryService.cs @@ -136,6 +136,9 @@ namespace sodoff.Services { uid.ItemStats = itemData.ItemStatsMap?.ItemStats; uid.ItemTier = itemData.ItemStatsMap?.ItemTier; } + if (item.AttributesSerialized != null) { + uid.UserItemAttributes = XmlUtil.DeserializeXml(item.AttributesSerialized); + } userItemData.Add(uid); } @@ -149,7 +152,7 @@ namespace sodoff.Services { ItemData itemData = itemService.GetItem(itemId); if (itemData.PossibleStatsMap != null) // dragons tactics (battle) items return true; - if (itemService.ItemHasCategory(itemData, 541)) // farm expansion + if (itemService.ItemHasCategory(itemData, new int[] {541, 657})) // farm expansion or customizable items return true; return false; }