Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of the equipment-manager #34

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions Client/Fracture.Client.csproj

This file was deleted.

20 changes: 0 additions & 20 deletions Client/Pages/Counter.razor

This file was deleted.

5 changes: 0 additions & 5 deletions Client/Program.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Client/_Imports.razor

This file was deleted.

8 changes: 0 additions & 8 deletions Client/wwwroot/appsettings.Development.json

This file was deleted.

8 changes: 0 additions & 8 deletions Client/wwwroot/appsettings.json

This file was deleted.

14 changes: 9 additions & 5 deletions Fracture.sln
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fracture.Ranking.Api", "Mod
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fracture.Tavern.Api", "Modules\Tavern\src\Fracture.Tavern.Api\Fracture.Tavern.Api.csproj", "{26494001-A893-44F2-9A97-674BD3B85D5C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fracture.Client", "Client\Fracture.Client.csproj", "{2196F216-7F95-4E36-A181-958594BD6D6B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ItemGenerator.Domain", "Modules\ItemGenerator\ItemGenerator.Domain\ItemGenerator.Domain.csproj", "{F0FD1C00-83D8-411D-ADE4-7F896108C067}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ItemGenerator", "ItemGenerator", "{3DB6FE6B-A9A9-4A63-A678-4286C4539CE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -393,10 +395,10 @@ Global
{26494001-A893-44F2-9A97-674BD3B85D5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26494001-A893-44F2-9A97-674BD3B85D5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26494001-A893-44F2-9A97-674BD3B85D5C}.Release|Any CPU.Build.0 = Release|Any CPU
{2196F216-7F95-4E36-A181-958594BD6D6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2196F216-7F95-4E36-A181-958594BD6D6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2196F216-7F95-4E36-A181-958594BD6D6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2196F216-7F95-4E36-A181-958594BD6D6B}.Release|Any CPU.Build.0 = Release|Any CPU
{F0FD1C00-83D8-411D-ADE4-7F896108C067}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0FD1C00-83D8-411D-ADE4-7F896108C067}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0FD1C00-83D8-411D-ADE4-7F896108C067}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0FD1C00-83D8-411D-ADE4-7F896108C067}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -488,6 +490,8 @@ Global
{236DFB56-0022-48B3-8FF4-14F4606EA882} = {F301866F-75D3-4E13-9878-DA3D64C0244C}
{015C6BE5-41FE-43DF-A48C-62CC273A02B4} = {D068A0C8-9656-4392-A57B-E648074DE002}
{26494001-A893-44F2-9A97-674BD3B85D5C} = {C9A7831B-4813-4161-BE5E-03B3D03BB643}
{F0FD1C00-83D8-411D-ADE4-7F896108C067} = {3DB6FE6B-A9A9-4A63-A678-4286C4539CE3}
{3DB6FE6B-A9A9-4A63-A678-4286C4539CE3} = {9941341F-1EAF-42DD-925F-7C861E823BDA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E93EB359-CDB9-425A-8064-77FF2DAE680D}
Expand Down
19 changes: 19 additions & 0 deletions Modules/ItemGenerator/ItemGenerator.Domain/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace ItemGeneratorModels
{
public class Item
{
public string Name { get; set; } = null!;
public string History { get; set; } = null!;

public ItemRarity Rarity { get; set; } = ItemRarity.Common;

public Dictionary<ItemStat, int> Statistics { get; init; } = new();

public void SetStat(ItemStat stat, int value)
{
Statistics[stat] = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
14 changes: 14 additions & 0 deletions Modules/ItemGenerator/ItemGenerator.Domain/ItemRarity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace ItemGeneratorModels
{
public enum ItemRarity
{
Common,
Uncommon,
Rare,
Insane,
Epic,
Legendary
}
}
10 changes: 10 additions & 0 deletions Modules/ItemGenerator/ItemGenerator.Domain/ItemStat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ItemGeneratorModels;

public enum ItemStat
{
Agility,
Strength,
Intelligence,
Defense,
Health
}
23 changes: 23 additions & 0 deletions Modules/ItemGenerator/ItemGenerator.Domain/RarityModifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace ItemGeneratorModels
{
public class RarityModifier
{
public float ValueBelow { get; init; } = 0f;
public ItemRarity Rarity { get; init; } = ItemRarity.Common;

public Dictionary<ItemStat, StatRange> StatRanges { get; init; } = new();

public RarityModifier(float valueBelow, ItemRarity rarity)
{
ValueBelow = valueBelow;
Rarity = rarity;
}

public void SetStatRange(ItemStat stat, StatRange range)
{
StatRanges[stat] = range;
}
}
}
12 changes: 12 additions & 0 deletions Modules/ItemGenerator/ItemGenerator.Domain/StatRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ItemGeneratorModels
{
public record StatRange(int MinValue, int MaxValue)
{
public int GenerateStat(Random rnd)
{
return rnd.Next(MinValue, MaxValue + 1);
}
}
}
19 changes: 19 additions & 0 deletions Server/Components/Layout/GameLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@inherits LayoutComponentBase

<HeadContent>
<link rel="stylesheet" href="css/game.css">
</HeadContent>

@Body

@* <div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div> *@



@code {

}
66 changes: 66 additions & 0 deletions Server/Components/Pages/GamePage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@page "/game"
@using Fracture.Server.Components.Layout
@using Fracture.Server.Components.UI
@using ItemGeneratorModels

@layout GameLayout

<div id="container">
<div class="sidebar-container">
<div class="stats-flex">
STATYSTYKI
<UserStats Equipment="equipment"></UserStats>
</div>
<div class="equipment-flex">
EKWIPUNEK

<ItemCard Item="item"></ItemCard>

Siatka aktualnie założonych
+ ostatnio zdobyte
</div>
</div>
<div class="text-container">
TEKST

<Fracture.Server.Components.Popups.EquipmentPopup></Fracture.Server.Components.Popups.EquipmentPopup>
</div>
<div class="sidebar-container">
<div class="journal-flex">
JOURNAL
</div>
<div class="map-flex">
MINIMAPA
</div>
<div class="button-container-flex">
<div class="action-button">
1
</div>
<div class="action-button">
2
</div>
<div class="action-button">
3
</div>
<div class="action-button">
4
</div>
</div>
</div>
</div>


@code {
private List<Item> equipment = new();
private Item item;

Check warning on line 55 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Non-nullable field 'item' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 55 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Non-nullable field 'item' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

protected override Task OnInitializedAsync()
{
var ItemGeneratorUrl = "http://eiga.pollub.net/item";

var hc = new HttpClient();
item = hc.GetFromJsonAsync<Item>(ItemGeneratorUrl).Result;

Check warning on line 62 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Possible null reference assignment.

Check warning on line 62 in Server/Components/Pages/GamePage.razor

View workflow job for this annotation

GitHub Actions / Checks

Possible null reference assignment.

return base.OnInitializedAsync();
}
}
2 changes: 1 addition & 1 deletion Server/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</h1>
<div class="d-grid gap-3 d-sm-flex justify-content-sm-center justify-content-xxl-start mb-3">
<NavLink class="btn btn-primary btn-lg px-5 py-3 me-sm-3 fs-6 fw-bolder"
href="counter">Go</NavLink>
href="game">Go</NavLink>
</div>
</div>
</div>
Expand Down
76 changes: 76 additions & 0 deletions Server/Components/Popups/EquipmentPopup.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@using ItemGeneratorModels
<button class="btn btn-primary" @onclick="GenerateNewItem">Generate new item </button>


<div class="row">
<div class="col-5 border border-primary overflow-scroll" style="height: 80vh">
<div class="row row-cols-2 g-4">
@foreach (var item in inventory.Where(x => !IsEquipped(x)))
{
<ItemCard Item="@item" OnEquipClicked="() => Equip(item)" IsEquipped="IsEquipped(item)" OnUnequipClicked="() => Unequip(item)"></ItemCard>

Check warning on line 10 in Server/Components/Popups/EquipmentPopup.razor

View workflow job for this annotation

GitHub Actions / Checks

Found markup element with unexpected name 'ItemCard'. If this is intended to be a component, add a @using directive for its namespace.

Check warning on line 10 in Server/Components/Popups/EquipmentPopup.razor

View workflow job for this annotation

GitHub Actions / Checks

Found markup element with unexpected name 'ItemCard'. If this is intended to be a component, add a @using directive for its namespace.
}
</div>
</div>
<div class="col-5 border border-secondary overflow-scroll" style="height: 80vh">
<div class="row row-cols-2 g-4">
@foreach (var item in equipment)
{
<ItemCard Item="@item" OnEquipClicked="() => Equip(item)" IsEquipped="IsEquipped(item)" OnUnequipClicked="() => Unequip(item)"></ItemCard>

Check warning on line 18 in Server/Components/Popups/EquipmentPopup.razor

View workflow job for this annotation

GitHub Actions / Checks

Found markup element with unexpected name 'ItemCard'. If this is intended to be a component, add a @using directive for its namespace.

Check warning on line 18 in Server/Components/Popups/EquipmentPopup.razor

View workflow job for this annotation

GitHub Actions / Checks

Found markup element with unexpected name 'ItemCard'. If this is intended to be a component, add a @using directive for its namespace.
}
</div>
</div>
<div class="col-2">
<table class="table">
@foreach (var itemStat in Enum.GetValues<ItemStat>())
{
var stat = equipment.Sum(x => x.Statistics[itemStat]);
var color = "";
@if (stat <= 0)
color = "text-danger";

<tr><td>@itemStat</td><td class="@color text-end">@stat</td></tr>
}
</table>
</div>
</div>

@code {
private List<Item> inventory = [];
private List<Item> equipment = [];
private const int slots = 6;



public async Task GenerateNewItem()
{
var hc = new HttpClient();
// localhost:5284

// var ItemGeneratorUrl = Configuration["ItemGeneratorUrl"];

// if (string.IsNullOrEmpty(ItemGeneratorUrl))

var ItemGeneratorUrl = "http://eiga.pollub.net/item";

var item = await hc.GetFromJsonAsync<Item>(ItemGeneratorUrl);

if (item is not null)
inventory.Add(item);
}

public void Equip(Item item)
{
if (equipment.Count < slots)
equipment.Add(item);
}

public void Unequip(Item item)
{
equipment.Remove(item);
}

public bool IsEquipped(Item item)
{
return equipment.Contains(item);
}
}
2 changes: 1 addition & 1 deletion Server/Components/Routes.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Client._Imports).Assembly }">
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
Expand Down
Loading