Skip to content
Merged
10 changes: 5 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities
dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field
dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
Expand Down Expand Up @@ -107,15 +107,15 @@ resharper_csharp_wrap_ternary_expr_style = wrap_if_long
resharper_formatter_off_tag = @formatter:off
resharper_formatter_on_tag = @formatter:on
resharper_formatter_tags_enabled = true
resharper_instance_members_qualify_declared_in =
resharper_instance_members_qualify_declared_in =
resharper_keep_existing_attribute_arrangement = true
resharper_keep_existing_declaration_block_arrangement = true
resharper_keep_existing_embedded_block_arrangement = true
resharper_keep_existing_enum_arrangement = true
resharper_keep_existing_initializer_arrangement = false
resharper_modifiers_order = protected public override private new internal static async virtual sealed abstract extern unsafe volatile readonly required
resharper_outdent_statement_labels = true
resharper_parentheses_non_obvious_operations = none, bitwise_and, bitwise_exclusive_or, bitwise_inclusive_or, bitwise, conditional_and
resharper_parentheses_non_obvious_operations = none, bitwise_and, bitwise_exclusive_or, bitwise_inclusive_or, bitwise
resharper_parentheses_redundancy_style = remove
resharper_place_expr_accessor_on_single_line = true
resharper_place_expr_method_on_single_line = true
Expand All @@ -124,8 +124,8 @@ resharper_place_field_attribute_on_same_line = if_owner_is_single_line
resharper_place_record_field_attribute_on_same_line = true
resharper_place_simple_anonymousmethod_on_single_line = false
resharper_place_simple_embedded_statement_on_same_line = true
resharper_place_simple_initializer_on_single_line = false
resharper_space_within_single_line_array_initializer_braces = false
resharper_place_simple_initializer_on_single_line = true
resharper_space_within_single_line_array_initializer_braces = true
resharper_trailing_comma_in_multiline_lists = true
resharper_use_indent_from_vs = false
resharper_wrap_array_initializer_style = chop_always
Expand Down
4 changes: 3 additions & 1 deletion .idea/.idea.Maple2/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Maple2.Database/Context/Ms2Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public sealed class Ms2Context(DbContextOptions options) : DbContext(options) {
internal DbSet<ServerInfo> ServerInfo { get; set; } = null!;
internal DbSet<Medal> Medal { get; set; } = null!;
internal DbSet<BannerSlot> BannerSlots { get; set; } = null!;
internal DbSet<HomeLayout> HomeLayout { get; set; } = null!;
internal DbSet<HomeLayoutCube> UgcCubeLayout { get; set; } = null!;

protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
Expand Down Expand Up @@ -68,6 +70,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity<Quest>(Maple2.Database.Model.Quest.Configure);
modelBuilder.Entity<Medal>(Maple2.Database.Model.Medal.Configure);
modelBuilder.Entity<BannerSlot>(Maple2.Database.Model.BannerSlot.Configure);
modelBuilder.Entity<HomeLayout>(Maple2.Database.Model.HomeLayout.Configure);
modelBuilder.Entity<HomeLayoutCube>(Maple2.Database.Model.HomeLayoutCube.Configure);

modelBuilder.Entity<MesoListing>(MesoListing.Configure);
modelBuilder.Entity<SoldMesoListing>(SoldMesoListing.Configure);
Expand Down
47 changes: 40 additions & 7 deletions Maple2.Database/Model/Item/ItemSubType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using Maple2.Model.Enum;

namespace Maple2.Database.Model;

Expand All @@ -12,8 +13,15 @@ internal abstract record ItemSubType;

internal record ItemUgc(UgcItemLook Template, ItemBlueprint Blueprint) : ItemSubType;

internal record UgcItemLook(long Id, string FileName, string Name, long AccountId, long CharacterId, string Author,
long CreationTime, string Url) {
internal record UgcItemLook(
long Id,
string FileName,
string Name,
long AccountId,
long CharacterId,
string Author,
long CreationTime,
string Url) {
[return: NotNullIfNotNull(nameof(other))]
public static implicit operator UgcItemLook?(Maple2.Model.Game.UgcItemLook? other) {
return other == null ? null : new UgcItemLook(other.Id, other.FileName, other.Name, other.AccountId, other.CharacterId,
Expand All @@ -35,15 +43,34 @@ internal record UgcItemLook(long Id, string FileName, string Name, long AccountI
}
}

internal record ItemBlueprint {
internal record ItemBlueprint(
long BlueprintUid,
int Length,
int Width,
int Height,
DateTimeOffset CreationTime,
int Type,
long AccountId,
long CharacterId,
string CharacterName) {
[return: NotNullIfNotNull(nameof(other))]
public static implicit operator ItemBlueprint?(Maple2.Model.Game.ItemBlueprint? other) {
return other == null ? null : new ItemBlueprint();
return other == null ? null : new ItemBlueprint(other.BlueprintUid, other.Length, other.Width, other.Height, other.CreationTime, (int) other.Type, other.AccountId, other.CharacterId, other.CharacterName);
}

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator Maple2.Model.Game.ItemBlueprint?(ItemBlueprint? other) {
return other == null ? null : new Maple2.Model.Game.ItemBlueprint();
return other == null ? null : new Maple2.Model.Game.ItemBlueprint {
BlueprintUid = other.BlueprintUid,
Length = other.Length,
Width = other.Width,
Height = other.Height,
CreationTime = other.CreationTime,
Type = (BlueprintType) other.Type,
AccountId = other.AccountId,
CharacterId = other.CharacterId,
CharacterName = other.CharacterName,
};
}
}

Expand All @@ -65,8 +92,14 @@ internal record ItemPet(string Name, long Exp, int EvolvePoints, short Level, sh
}
}

internal record ItemCustomMusicScore(int Length, int Instrument, string Title, string Author, long AuthorId,
bool IsLocked, string Mml) : ItemSubType {
internal record ItemCustomMusicScore(
int Length,
int Instrument,
string Title,
string Author,
long AuthorId,
bool IsLocked,
string Mml) : ItemSubType {
[return: NotNullIfNotNull(nameof(other))]
public static implicit operator ItemCustomMusicScore?(Maple2.Model.Game.ItemCustomMusicScore? other) {
return other == null ? null : new ItemCustomMusicScore(other.Length, other.Instrument, other.Title,
Expand Down
38 changes: 5 additions & 33 deletions Maple2.Database/Model/Map/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ internal class Home {

public string? Passcode { get; set; }
public IDictionary<HomePermission, HomePermissionSetting> Permissions { get; set; } = new Dictionary<HomePermission, HomePermissionSetting>();
public List<HomeLayout> Layouts { get; set; } = [];
public List<long> Layouts { get; set; } = [];
public List<long> Blueprints { get; set; } = [];

public DateTime LastModified { get; set; }

Expand All @@ -43,7 +44,8 @@ internal class Home {
Camera = other.Camera,
Passcode = other.Passcode,
Permissions = other.Permissions,
Layouts = other.Layouts.ConvertAll(layout => (HomeLayout) layout),
Layouts = other.Layouts.Select(layout => layout.Uid).ToList(),
Blueprints = other.Blueprints.Select(layout => layout.Uid).ToList(),
Comment thread
AngeloTadeucci marked this conversation as resolved.
};
}

Expand All @@ -60,7 +62,6 @@ internal class Home {
ArchitectScore = other.ArchitectScore,
Passcode = other.Passcode,
LastModified = other.LastModified.ToEpochSeconds(),
Layouts = other.Layouts.ConvertAll(layout => (Maple2.Model.Game.HomeLayout) layout),
};

home.SetArea(other.Area);
Expand Down Expand Up @@ -88,38 +89,9 @@ public static void Configure(EntityTypeBuilder<Home> builder) {

builder.Property(home => home.Permissions).HasJsonConversion();
builder.Property(home => home.Layouts).HasJsonConversion();
builder.Property(home => home.Blueprints).HasJsonConversion();

builder.Property(map => map.LastModified)
.ValueGeneratedOnAddOrUpdate();
}
}

internal class HomeLayout {
public int Id { get; set; }
public string Name { get; set; }
public byte Area { get; set; }
public byte Height { get; set; }
public DateTimeOffset Timestamp { get; set; }
public List<UgcMapCube> Cubes { get; set; }

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator HomeLayout?(Maple2.Model.Game.HomeLayout? other) {
return other == null ? null : new HomeLayout {
Id = other.Id,
Name = other.Name,
Area = other.Area,
Height = other.Height,
Timestamp = other.Timestamp,
Cubes = other.Cubes.ConvertAll(cube => (UgcMapCube) cube),
};
}

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator Maple2.Model.Game.HomeLayout?(HomeLayout? other) {
if (other == null) {
return null;
}

return new Maple2.Model.Game.HomeLayout(other.Id, other.Name, other.Area, other.Height, other.Timestamp, other.Cubes.ConvertAll(cube => (Maple2.Model.Game.PlotCube) cube));
}
}
54 changes: 54 additions & 0 deletions Maple2.Database/Model/Map/HomeLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Diagnostics.CodeAnalysis;
using Maple2.Model.Enum;
using Maple2.Model.Game;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Maple2.Database.Model;

internal class HomeLayout {
public long Uid { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public byte Area { get; set; }
public byte Height { get; set; }
public HomeBackground Background { get; set; }
public HomeLighting Lighting { get; set; }
public HomeCamera Camera { get; set; }
public DateTimeOffset Timestamp { get; set; }
public List<HomeLayoutCube> Cubes { get; set; } = null!;
Comment thread
AngeloTadeucci marked this conversation as resolved.

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator HomeLayout?(Maple2.Model.Game.HomeLayout? other) {
return other == null ? null : new HomeLayout {
Uid = other.Uid,
Id = other.Id,
Name = other.Name,
Area = other.Area,
Height = other.Height,
Timestamp = other.Timestamp,
Cubes = other.Cubes.ConvertAll(cube => (HomeLayoutCube) cube),
Comment thread
AngeloTadeucci marked this conversation as resolved.
Background = other.Background,
Lighting = other.Lighting,
Camera = other.Camera,
};
}

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator Maple2.Model.Game.HomeLayout?(HomeLayout? other) {
if (other == null) {
return null;
}

return new Maple2.Model.Game.HomeLayout(other.Uid, other.Id, other.Name, other.Area, other.Height, other.Timestamp, other.Cubes.ConvertAll(cube => (PlotCube) cube)) {
Background = other.Background,
Lighting = other.Lighting,
Camera = other.Camera,
};
}

public static void Configure(EntityTypeBuilder<HomeLayout> builder) {
builder.ToTable("home-layout");
builder.HasKey(layout => layout.Uid);
}
Comment thread
AngeloTadeucci marked this conversation as resolved.
}
51 changes: 51 additions & 0 deletions Maple2.Database/Model/Map/HomeLayoutCube.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Diagnostics.CodeAnalysis;
using Maple2.Database.Extensions;
using Maple2.Model.Common;
using Maple2.Model.Game;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Maple2.Database.Model;

internal class HomeLayoutCube {
public long Id { get; set; }
public long HomeLayoutId { get; set; }
public sbyte X { get; set; }
public sbyte Y { get; set; }
public sbyte Z { get; set; }
Comment thread
AngeloTadeucci marked this conversation as resolved.
public float Rotation { get; set; }

public int ItemId { get; set; }
public UgcItemLook? Template { get; set; }

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator PlotCube?(HomeLayoutCube? other) {
return other == null ? null : new PlotCube(other.ItemId, other.Id, other.Template) {
Position = new Vector3B(other.X, other.Y, other.Z),
Rotation = other.Rotation,
};
}

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator HomeLayoutCube?(PlotCube? other) {
return other == null ? null : new HomeLayoutCube {
X = other.Position.X,
Y = other.Position.Y,
Z = other.Position.Z,
Rotation = other.Rotation,
ItemId = other.ItemId,
Template = other.Template,
};
}
Comment thread
AngeloTadeucci marked this conversation as resolved.
Comment thread
AngeloTadeucci marked this conversation as resolved.

public static void Configure(EntityTypeBuilder<HomeLayoutCube> builder) {
builder.ToTable("home-layout-cube");
builder.HasKey(cube => cube.Id);

builder.HasOne<HomeLayout>()
.WithMany(ugcMap => ugcMap.Cubes)
.HasForeignKey(cube => cube.HomeLayoutId);

builder.Property(cube => cube.Template).HasJsonConversion();
}
}
36 changes: 36 additions & 0 deletions Maple2.Database/Storage/Game/GameStorage.HomeLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Maple2.Database.Extensions;
using Maple2.Database.Model;
using Microsoft.EntityFrameworkCore;
using HomeLayout = Maple2.Model.Game.HomeLayout;

namespace Maple2.Database.Storage;

public partial class GameStorage {
public partial class Request {
public HomeLayout? SaveHomeLayout(HomeLayout layout) {
Model.HomeLayout homeLayout = layout;
Context.HomeLayout.Add(homeLayout);
foreach (HomeLayoutCube cubes in homeLayout.Cubes) {
Context.UgcCubeLayout.Add(cubes);
}
bool success = Context.TrySaveChanges();

return success ? homeLayout : null;
}

public void RemoveHomeLayout(HomeLayout layout) {
Model.HomeLayout homeLayout = layout;
Context.HomeLayout.Remove(homeLayout);
Context.TrySaveChanges();
}

public HomeLayout? GetHomeLayout(long layoutUid) {
HomeLayout? layout = Context.HomeLayout
.Where(homeLayout => homeLayout.Uid == layoutUid)
.Include(homeLayout => homeLayout.Cubes)
.FirstOrDefault();

return layout;
}
}
}
7 changes: 7 additions & 0 deletions Maple2.Database/Storage/Game/GameStorage.Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ public bool SaveItems(long ownerId, params Item[] items) {
return Context.TrySaveChanges();
}

public bool UpdateItem(Item item) {
Model.Item model = item;
Context.Item.Update(model);

return Context.TrySaveChanges();
Comment thread
AngeloTadeucci marked this conversation as resolved.
}
Comment thread
AngeloTadeucci marked this conversation as resolved.

public bool SaveStorageInfo(long accountId, long mesos, short expand) {
ItemStorage? info = Context.ItemStorage.Find(accountId);
if (info == null) {
Expand Down
Loading