Skip to content

Commit

Permalink
Make it possible to only get items newer than a specified timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
zerratar committed Aug 2, 2023
1 parent d6bc300 commit 1631c3b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/RavenNest.Blazor/Controllers/ItemsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public async Task<ActionResult<ItemCollection>> Get()
return itemCollection;
}

[HttpGet("delta/{timestamp}")]
public async Task<ActionResult<ItemCollection>> Get(DateTime timestamp)
{
if (itemManager == null)
{
return new ItemCollection();
}

var itemCollection = itemManager.GetAllItems(timestamp);
return itemCollection;
}

/// <summary>
/// Get all redeemable items
/// </summary>
Expand Down
30 changes: 26 additions & 4 deletions src/RavenNest.BusinessLogic/Game/Managers/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ public ItemCollection GetAllItems()
return InvalidateCache();
}

public ItemCollection GetAllItems(DateTime timestamp)
{
var items = gameData.GetItems();
var collection = new ItemCollection();
foreach (var item in items)
{
if (item.Hidden || item.Modified < timestamp)
{
continue;
}

collection.Add(ModelMapper.Map(gameData, item));
}
return collection;
}

public Item GetItem(Guid itemId)
{
var dataItem = gameData.GetItem(itemId);
Expand Down Expand Up @@ -96,6 +112,8 @@ private void AddItem(Item item)
item.RequiredCraftingLevel = GameMath.MaxLevel + 1;
}

entity.Modified = DateTime.UtcNow;

gameData.Add(entity);
InvalidateCache();
}
Expand Down Expand Up @@ -166,6 +184,13 @@ private void UpdateItem(Item item, DataModels.Item dataItem)

dataItem.Level = item.Level;
dataItem.ArmorPower = item.ArmorPower;
dataItem.WeaponAim = item.WeaponAim;
dataItem.WeaponPower = item.WeaponPower;
dataItem.MagicPower = item.MagicPower;
dataItem.MagicAim = item.MagicAim;
dataItem.RangedPower = item.RangedPower;
dataItem.RangedAim = item.RangedAim;

dataItem.Category = (int)item.Category;
dataItem.Craftable = item.Craftable;
dataItem.FemaleModelId = item.FemaleModelId;
Expand All @@ -188,11 +213,8 @@ private void UpdateItem(Item item, DataModels.Item dataItem)
dataItem.ShopSellPrice = item.ShopSellPrice;
dataItem.Soulbound = item.Soulbound;
dataItem.Type = (int)item.Type;
dataItem.WeaponAim = item.WeaponAim;
dataItem.WeaponPower = item.WeaponPower;
dataItem.WoodCost = item.WoodCost;


dataItem.Modified = DateTime.UtcNow;

InvalidateCache();
}
Expand Down
1 change: 1 addition & 0 deletions src/RavenNest.DataModels/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ public partial class Item : Entity<Item>
public long ShopSellPrice { get => shopSellPrice; set => Set(ref shopSellPrice, value); }
private bool soulbound; public bool Soulbound { get => soulbound; set => Set(ref soulbound, value); }
private bool hidden; public bool Hidden { get => hidden; set => Set(ref hidden, value); }
private DateTime? modified; public DateTime? Modified { get => modified; set => Set(ref modified, value); }
}
}
1 change: 1 addition & 0 deletions src/RavenNest.Models/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public class Item
public long ShopSellPrice { get; set; }
public List<ItemCraftingRequirement> CraftingRequirements { get; set; }
public bool Soulbound { get; set; }
public DateTime? Modified { get; set; }
}
}

0 comments on commit 1631c3b

Please sign in to comment.