mirror of
https://github.com/rafi1212122/BLHX.Server.git
synced 2025-12-13 06:54:51 +01:00
attempt to add ShipBagMax
This commit is contained in:
@@ -6,10 +6,8 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace BLHX.Server.Common.Database
|
namespace BLHX.Server.Common.Database {
|
||||||
{
|
public sealed class PlayerContext : DbContext, IBLHXDBContext<PlayerContext> {
|
||||||
public sealed class PlayerContext : DbContext, IBLHXDBContext<PlayerContext>
|
|
||||||
{
|
|
||||||
SavingState savingState;
|
SavingState savingState;
|
||||||
public static string DbPath => "Databases/players.db";
|
public static string DbPath => "Databases/players.db";
|
||||||
public DbSet<Player> Players { get; set; }
|
public DbSet<Player> Players { get; set; }
|
||||||
@@ -18,8 +16,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
public DbSet<PlayerShip> Ships { get; set; }
|
public DbSet<PlayerShip> Ships { get; set; }
|
||||||
public DbSet<ChapterInfo> ChapterInfoes { get; set; }
|
public DbSet<ChapterInfo> ChapterInfoes { get; set; }
|
||||||
|
|
||||||
public PlayerContext()
|
public PlayerContext() {
|
||||||
{
|
|
||||||
if (Database.GetPendingMigrations().Any())
|
if (Database.GetPendingMigrations().Any())
|
||||||
Database.Migrate();
|
Database.Migrate();
|
||||||
|
|
||||||
@@ -29,13 +26,11 @@ namespace BLHX.Server.Common.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Thread-safe method pls
|
// Thread-safe method pls
|
||||||
public void Save()
|
public void Save() {
|
||||||
{
|
if (savingState == SavingState.Attempting)
|
||||||
if (savingState == SavingState.Attempting)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (savingState != SavingState.None)
|
while (savingState != SavingState.None) {
|
||||||
{
|
|
||||||
savingState = SavingState.Attempting;
|
savingState = SavingState.Attempting;
|
||||||
Task.Delay(1).Wait();
|
Task.Delay(1).Wait();
|
||||||
}
|
}
|
||||||
@@ -43,8 +38,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
SaveChanges();
|
SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player Init(string token, uint shipId, string name)
|
public Player Init(string token, uint shipId, string name) {
|
||||||
{
|
|
||||||
var player = new Player(token, new Displayinfo() { Icon = shipId }, name);
|
var player = new Player(token, new Displayinfo() { Icon = shipId }, name);
|
||||||
|
|
||||||
Players.Add(player);
|
Players.Add(player);
|
||||||
@@ -66,8 +60,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayerRoutine(Player player)
|
public void PlayerRoutine(Player player) {
|
||||||
{
|
|
||||||
if (!ResourceFields.Any(x => x.Type == ResourceFieldType.Gold))
|
if (!ResourceFields.Any(x => x.Type == ResourceFieldType.Gold))
|
||||||
ResourceFields.Add(new() { Type = ResourceFieldType.Gold, PlayerUid = player.Uid });
|
ResourceFields.Add(new() { Type = ResourceFieldType.Gold, PlayerUid = player.Uid });
|
||||||
if (!ResourceFields.Any(x => x.Type == ResourceFieldType.Oil))
|
if (!ResourceFields.Any(x => x.Type == ResourceFieldType.Oil))
|
||||||
@@ -76,11 +69,9 @@ namespace BLHX.Server.Common.Database
|
|||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder) {
|
||||||
{
|
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
modelBuilder.Entity<Player>(e =>
|
modelBuilder.Entity<Player>(e => {
|
||||||
{
|
|
||||||
e.Property(b => b.DisplayInfo)
|
e.Property(b => b.DisplayInfo)
|
||||||
.HasJsonConversion();
|
.HasJsonConversion();
|
||||||
e.Property(b => b.Fleets)
|
e.Property(b => b.Fleets)
|
||||||
@@ -109,8 +100,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
.HasForeignKey(e => e.PlayerUid)
|
.HasForeignKey(e => e.PlayerUid)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
});
|
});
|
||||||
modelBuilder.Entity<PlayerShip>(e =>
|
modelBuilder.Entity<PlayerShip>(e => {
|
||||||
{
|
|
||||||
e.Property(b => b.Id)
|
e.Property(b => b.Id)
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
e.Property(b => b.State)
|
e.Property(b => b.State)
|
||||||
@@ -128,8 +118,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
e.Property(b => b.CoreLists)
|
e.Property(b => b.CoreLists)
|
||||||
.HasJsonConversion();
|
.HasJsonConversion();
|
||||||
});
|
});
|
||||||
modelBuilder.Entity<ChapterInfo>(e =>
|
modelBuilder.Entity<ChapterInfo>(e => {
|
||||||
{
|
|
||||||
e.Property(x => x.EscortLists)
|
e.Property(x => x.EscortLists)
|
||||||
.HasJsonConversion();
|
.HasJsonConversion();
|
||||||
e.Property(x => x.AiLists)
|
e.Property(x => x.AiLists)
|
||||||
@@ -163,14 +152,14 @@ namespace BLHX.Server.Common.Database
|
|||||||
|
|
||||||
[PrimaryKey(nameof(Uid))]
|
[PrimaryKey(nameof(Uid))]
|
||||||
[Index(nameof(Token), IsUnique = true)]
|
[Index(nameof(Token), IsUnique = true)]
|
||||||
public class Player
|
public class Player {
|
||||||
{
|
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
public uint Uid { get; set; }
|
public uint Uid { get; set; }
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
// Aka. manifesto
|
// Aka. manifesto
|
||||||
public string Adv { get; set; } = string.Empty;
|
public string Adv { get; set; } = string.Empty;
|
||||||
|
public uint ShipBagMax { get; set; } = 9990;
|
||||||
public uint Level { get; set; }
|
public uint Level { get; set; }
|
||||||
// TODO: Exp add setter to recalculate cap and set level
|
// TODO: Exp add setter to recalculate cap and set level
|
||||||
public uint Exp { get; set; }
|
public uint Exp { get; set; }
|
||||||
@@ -186,8 +175,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
public virtual ICollection<PlayerShip> Ships { get; set; } = [];
|
public virtual ICollection<PlayerShip> Ships { get; set; } = [];
|
||||||
public virtual ICollection<ChapterInfo> ChapterInfoes { get; set; } = [];
|
public virtual ICollection<ChapterInfo> ChapterInfoes { get; set; } = [];
|
||||||
|
|
||||||
public Player(string token, Displayinfo displayInfo, string name)
|
public Player(string token, Displayinfo displayInfo, string name) {
|
||||||
{
|
|
||||||
DisplayInfo = displayInfo;
|
DisplayInfo = displayInfo;
|
||||||
Token = token;
|
Token = token;
|
||||||
Name = name;
|
Name = name;
|
||||||
@@ -195,11 +183,9 @@ namespace BLHX.Server.Common.Database
|
|||||||
CreatedAt = DateTime.Now;
|
CreatedAt = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoResource(uint id, int num)
|
public void DoResource(uint id, int num) {
|
||||||
{
|
|
||||||
var res = Resources.SingleOrDefault(x => x.Id == id);
|
var res = Resources.SingleOrDefault(x => x.Id == id);
|
||||||
if (res is null)
|
if (res is null) {
|
||||||
{
|
|
||||||
res = new() { Id = id, PlayerUid = Uid };
|
res = new() { Id = id, PlayerUid = Uid };
|
||||||
DBManager.PlayerContext.Resources.Add(res);
|
DBManager.PlayerContext.Resources.Add(res);
|
||||||
}
|
}
|
||||||
@@ -210,13 +196,11 @@ namespace BLHX.Server.Common.Database
|
|||||||
res.Num = Math.Min(res.Num + (uint)num, uint.MaxValue);
|
res.Num = Math.Min(res.Num + (uint)num, uint.MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddShip(uint shipTemplateId)
|
public void AddShip(uint shipTemplateId) {
|
||||||
{
|
|
||||||
if (!Data.Data.ShipDataTemplate.TryGetValue((int)shipTemplateId, out var shipTemplate))
|
if (!Data.Data.ShipDataTemplate.TryGetValue((int)shipTemplateId, out var shipTemplate))
|
||||||
throw new InvalidDataException($"Ship template {shipTemplateId} not found!");
|
throw new InvalidDataException($"Ship template {shipTemplateId} not found!");
|
||||||
|
|
||||||
var ship = new PlayerShip()
|
var ship = new PlayerShip() {
|
||||||
{
|
|
||||||
TemplateId = shipTemplateId,
|
TemplateId = shipTemplateId,
|
||||||
Level = 1,
|
Level = 1,
|
||||||
EquipInfoLists = [
|
EquipInfoLists = [
|
||||||
@@ -238,15 +222,11 @@ namespace BLHX.Server.Common.Database
|
|||||||
DBManager.PlayerContext.Ships.Add(ship);
|
DBManager.PlayerContext.Ships.Add(ship);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HarvestResourceField(ResourceFieldType type)
|
public void HarvestResourceField(ResourceFieldType type) {
|
||||||
{
|
foreach (var resourceField in ResourceFields) {
|
||||||
foreach (var resourceField in ResourceFields)
|
if (resourceField.Type == type) {
|
||||||
{
|
|
||||||
if (resourceField.Type == type)
|
|
||||||
{
|
|
||||||
var amount = resourceField.Flush();
|
var amount = resourceField.Flush();
|
||||||
switch (type)
|
switch (type) {
|
||||||
{
|
|
||||||
case ResourceFieldType.Gold:
|
case ResourceFieldType.Gold:
|
||||||
DoResource(1, (int)amount);
|
DoResource(1, (int)amount);
|
||||||
break;
|
break;
|
||||||
@@ -262,8 +242,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PrimaryKey(nameof(Id), nameof(PlayerUid))]
|
[PrimaryKey(nameof(Id), nameof(PlayerUid))]
|
||||||
public class PlayerResource
|
public class PlayerResource {
|
||||||
{
|
|
||||||
[Key]
|
[Key]
|
||||||
public uint Id { get; set; }
|
public uint Id { get; set; }
|
||||||
public uint Num { get; set; }
|
public uint Num { get; set; }
|
||||||
@@ -274,8 +253,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PrimaryKey(nameof(Id))]
|
[PrimaryKey(nameof(Id))]
|
||||||
public class PlayerShip
|
public class PlayerShip {
|
||||||
{
|
|
||||||
[Key]
|
[Key]
|
||||||
public uint Id { get; set; }
|
public uint Id { get; set; }
|
||||||
public uint TemplateId { get; set; }
|
public uint TemplateId { get; set; }
|
||||||
@@ -307,10 +285,8 @@ namespace BLHX.Server.Common.Database
|
|||||||
public DateTime CreatedAt { get; set; } = DateTime.Now;
|
public DateTime CreatedAt { get; set; } = DateTime.Now;
|
||||||
public DateTime? LastChangeName { get; set; }
|
public DateTime? LastChangeName { get; set; }
|
||||||
|
|
||||||
public Shipinfo ToProto()
|
public Shipinfo ToProto() {
|
||||||
{
|
return new() {
|
||||||
return new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
Id = Id,
|
||||||
TemplateId = TemplateId,
|
TemplateId = TemplateId,
|
||||||
Level = Level,
|
Level = Level,
|
||||||
@@ -340,15 +316,13 @@ namespace BLHX.Server.Common.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ResourceFieldType
|
public enum ResourceFieldType {
|
||||||
{
|
|
||||||
Gold = 1,
|
Gold = 1,
|
||||||
Oil = 2
|
Oil = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
[PrimaryKey(nameof(Type), nameof(PlayerUid))]
|
[PrimaryKey(nameof(Type), nameof(PlayerUid))]
|
||||||
public class ResourceField
|
public class ResourceField {
|
||||||
{
|
|
||||||
[Key]
|
[Key]
|
||||||
public ResourceFieldType Type { get; set; }
|
public ResourceFieldType Type { get; set; }
|
||||||
public uint Level { get; set; } = 1;
|
public uint Level { get; set; } = 1;
|
||||||
@@ -359,14 +333,11 @@ namespace BLHX.Server.Common.Database
|
|||||||
public uint PlayerUid { get; set; }
|
public uint PlayerUid { get; set; }
|
||||||
public virtual Player Player { get; set; } = null!;
|
public virtual Player Player { get; set; } = null!;
|
||||||
|
|
||||||
public void CalculateYield()
|
public void CalculateYield() {
|
||||||
{
|
|
||||||
// TODO: Take UpgradeTime into acccount of the reward
|
// TODO: Take UpgradeTime into acccount of the reward
|
||||||
switch (Type)
|
switch (Type) {
|
||||||
{
|
|
||||||
case ResourceFieldType.Gold:
|
case ResourceFieldType.Gold:
|
||||||
if (Data.Data.GoldFieldTemplate.TryGetValue((int)Level, out var goldTemplate))
|
if (Data.Data.GoldFieldTemplate.TryGetValue((int)Level, out var goldTemplate)) {
|
||||||
{
|
|
||||||
var res = Player.Resources.FirstOrDefault(x => x.Id == 7);
|
var res = Player.Resources.FirstOrDefault(x => x.Id == 7);
|
||||||
var num = (goldTemplate.HourTime * goldTemplate.Production) / 3600f * LastHarvestTime.GetSecondsPassed();
|
var num = (goldTemplate.HourTime * goldTemplate.Production) / 3600f * LastHarvestTime.GetSecondsPassed();
|
||||||
|
|
||||||
@@ -375,8 +346,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ResourceFieldType.Oil:
|
case ResourceFieldType.Oil:
|
||||||
if (Data.Data.OilFieldTemplate.TryGetValue((int)Level, out var oilTemplate))
|
if (Data.Data.OilFieldTemplate.TryGetValue((int)Level, out var oilTemplate)) {
|
||||||
{
|
|
||||||
var res = Player.Resources.FirstOrDefault(x => x.Id == 5);
|
var res = Player.Resources.FirstOrDefault(x => x.Id == 5);
|
||||||
var num = (oilTemplate.HourTime * oilTemplate.Production) / 3600f * LastHarvestTime.GetSecondsPassed();
|
var num = (oilTemplate.HourTime * oilTemplate.Production) / 3600f * LastHarvestTime.GetSecondsPassed();
|
||||||
|
|
||||||
@@ -387,15 +357,12 @@ namespace BLHX.Server.Common.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint Flush()
|
public uint Flush() {
|
||||||
{
|
|
||||||
uint amount = 0;
|
uint amount = 0;
|
||||||
// TODO: Take UpgradeTime into acccount of the reward
|
// TODO: Take UpgradeTime into acccount of the reward
|
||||||
switch (Type)
|
switch (Type) {
|
||||||
{
|
|
||||||
case ResourceFieldType.Gold:
|
case ResourceFieldType.Gold:
|
||||||
if (Data.Data.GoldFieldTemplate.TryGetValue((int)Level, out var goldTemplate))
|
if (Data.Data.GoldFieldTemplate.TryGetValue((int)Level, out var goldTemplate)) {
|
||||||
{
|
|
||||||
var goldField = Player.Resources.First(x => x.Id == 7);
|
var goldField = Player.Resources.First(x => x.Id == 7);
|
||||||
amount = goldField.Num;
|
amount = goldField.Num;
|
||||||
|
|
||||||
@@ -403,8 +370,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ResourceFieldType.Oil:
|
case ResourceFieldType.Oil:
|
||||||
if (Data.Data.OilFieldTemplate.TryGetValue((int)Level, out var oilTemplate))
|
if (Data.Data.OilFieldTemplate.TryGetValue((int)Level, out var oilTemplate)) {
|
||||||
{
|
|
||||||
var oilField = Player.Resources.First(x => x.Id == 5);
|
var oilField = Player.Resources.First(x => x.Id == 5);
|
||||||
amount = oilField.Num;
|
amount = oilField.Num;
|
||||||
|
|
||||||
@@ -419,8 +385,7 @@ namespace BLHX.Server.Common.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PrimaryKey(nameof(Id), nameof(PlayerUid))]
|
[PrimaryKey(nameof(Id), nameof(PlayerUid))]
|
||||||
public class ChapterInfo
|
public class ChapterInfo {
|
||||||
{
|
|
||||||
[Key]
|
[Key]
|
||||||
public uint Id { get; set; }
|
public uint Id { get; set; }
|
||||||
public DateTime Time { get; set; }
|
public DateTime Time { get; set; }
|
||||||
@@ -449,17 +414,15 @@ namespace BLHX.Server.Common.Database
|
|||||||
public uint PlayerUid { get; set; }
|
public uint PlayerUid { get; set; }
|
||||||
public virtual Player Player { get; set; } = null!;
|
public virtual Player Player { get; set; } = null!;
|
||||||
|
|
||||||
public Currentchapterinfo ToProto()
|
public Currentchapterinfo ToProto() {
|
||||||
{
|
return new Currentchapterinfo() {
|
||||||
return new Currentchapterinfo()
|
|
||||||
{
|
|
||||||
Id = Id,
|
Id = Id,
|
||||||
AiLists = AiLists,
|
AiLists = AiLists,
|
||||||
BattleStatistics = BattleStatistics,
|
BattleStatistics = BattleStatistics,
|
||||||
BuffLists = BuffLists,
|
BuffLists = BuffLists,
|
||||||
CellFlagLists = CellFlagLists,
|
CellFlagLists = CellFlagLists,
|
||||||
CellLists = CellLists,
|
CellLists = CellLists,
|
||||||
ChapterHp = ChapterHp,
|
ChapterHp = ChapterHp,
|
||||||
ChapterStrategyLists = ChapterStrategyLists,
|
ChapterStrategyLists = ChapterStrategyLists,
|
||||||
ContinuousKillCount = ContinuousKillCount,
|
ContinuousKillCount = ContinuousKillCount,
|
||||||
EscortLists = EscortLists,
|
EscortLists = EscortLists,
|
||||||
@@ -478,10 +441,8 @@ namespace BLHX.Server.Common.Database
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChapterInfo FromProto(Currentchapterinfo chapterInfo, uint uid)
|
public static ChapterInfo FromProto(Currentchapterinfo chapterInfo, uint uid) {
|
||||||
{
|
return new() {
|
||||||
return new()
|
|
||||||
{
|
|
||||||
Id = chapterInfo.Id,
|
Id = chapterInfo.Id,
|
||||||
AiLists = chapterInfo.AiLists,
|
AiLists = chapterInfo.AiLists,
|
||||||
BattleStatistics = chapterInfo.BattleStatistics,
|
BattleStatistics = chapterInfo.BattleStatistics,
|
||||||
|
|||||||
@@ -3,42 +3,36 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace BLHX.Server.Common.Migrations.Player
|
namespace BLHX.Server.Common.Migrations.Player {
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class Init_PlayerContext : Migration
|
public partial class Init_PlayerContext : Migration {
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder) {
|
||||||
{
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Players",
|
name: "Players",
|
||||||
columns: table => new
|
columns: table => new {
|
||||||
{
|
|
||||||
Uid = table.Column<uint>(type: "INTEGER", nullable: false)
|
Uid = table.Column<uint>(type: "INTEGER", nullable: false)
|
||||||
.Annotation("Sqlite:Autoincrement", true),
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
Token = table.Column<string>(type: "TEXT", nullable: false),
|
Token = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
Level = table.Column<uint>(type: "INTEGER", nullable: false),
|
Level = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||||
Exp = table.Column<uint>(type: "INTEGER", nullable: false),
|
Exp = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||||
|
ShipBagMax = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||||
DisplayInfo = table.Column<string>(type: "jsonb", nullable: false),
|
DisplayInfo = table.Column<string>(type: "jsonb", nullable: false),
|
||||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false)
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table => {
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Players", x => x.Uid);
|
table.PrimaryKey("PK_Players", x => x.Uid);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Resources",
|
name: "Resources",
|
||||||
columns: table => new
|
columns: table => new {
|
||||||
{
|
|
||||||
Id = table.Column<uint>(type: "INTEGER", nullable: false),
|
Id = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||||
PlayerUid = table.Column<uint>(type: "INTEGER", nullable: false),
|
PlayerUid = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||||
Num = table.Column<uint>(type: "INTEGER", nullable: false)
|
Num = table.Column<uint>(type: "INTEGER", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table => {
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Resources", x => new { x.Id, x.PlayerUid });
|
table.PrimaryKey("PK_Resources", x => new { x.Id, x.PlayerUid });
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Resources_Players_PlayerUid",
|
name: "FK_Resources_Players_PlayerUid",
|
||||||
@@ -50,8 +44,7 @@ namespace BLHX.Server.Common.Migrations.Player
|
|||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Ships",
|
name: "Ships",
|
||||||
columns: table => new
|
columns: table => new {
|
||||||
{
|
|
||||||
Id = table.Column<uint>(type: "INTEGER", nullable: false)
|
Id = table.Column<uint>(type: "INTEGER", nullable: false)
|
||||||
.Annotation("Sqlite:Autoincrement", true),
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
TemplateId = table.Column<uint>(type: "INTEGER", nullable: false),
|
TemplateId = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||||
@@ -79,8 +72,7 @@ namespace BLHX.Server.Common.Migrations.Player
|
|||||||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
LastChangeName = table.Column<DateTime>(type: "TEXT", nullable: false)
|
LastChangeName = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table => {
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Ships", x => x.Id);
|
table.PrimaryKey("PK_Ships", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Ships_Players_PlayerUid",
|
name: "FK_Ships_Players_PlayerUid",
|
||||||
@@ -108,8 +100,7 @@ namespace BLHX.Server.Common.Migrations.Player
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder) {
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Resources");
|
name: "Resources");
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ namespace BLHX.Server.Game.Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Unlock.Equals("all", StringComparison.CurrentCultureIgnoreCase)) {
|
if (Unlock.Equals("all", StringComparison.CurrentCultureIgnoreCase)) {
|
||||||
int amount = 500; // not sure why but if you add more than this amount the client crashes
|
int amount = 585; // not sure why but if you add more than this amount the client crashes
|
||||||
List<int> all_ship_ids = Data.ShipDataTemplate.Where(x => x.Value.Star == x.Value.StarMax && x.Value.Star >= 5).ToDictionary().Keys.ToList();
|
List<int> all_ship_ids = Data.ShipDataTemplate.Where(x => x.Value.Star == x.Value.StarMax && x.Value.Star >= 5).ToDictionary().Keys.ToList();
|
||||||
List<PlayerShip> all_ships = all_ship_ids.Select(ship_id => CreateShipFromId((uint)ship_id, connection.player.Uid)).Take(amount).ToList();
|
List<PlayerShip> all_ships = all_ship_ids.Select(ship_id => CreateShipFromId((uint)ship_id, connection.player.Uid)).ToList();
|
||||||
|
|
||||||
all_ships.AddRange(GetDefaultShips(connection.player.Ships)); // add the defaults
|
all_ships.AddRange(GetDefaultShips(connection.player.Ships)); // add the defaults
|
||||||
connection.player.Ships = all_ships;
|
connection.player.Ships = all_ships;
|
||||||
|
|||||||
@@ -2,16 +2,12 @@
|
|||||||
using BLHX.Server.Common.Proto;
|
using BLHX.Server.Common.Proto;
|
||||||
using BLHX.Server.Common.Proto.p11;
|
using BLHX.Server.Common.Proto.p11;
|
||||||
|
|
||||||
namespace BLHX.Server.Game.Handlers
|
namespace BLHX.Server.Game.Handlers {
|
||||||
{
|
internal static class P11 {
|
||||||
internal static class P11
|
|
||||||
{
|
|
||||||
[PacketHandler(Command.Cs11001)]
|
[PacketHandler(Command.Cs11001)]
|
||||||
static void ServerTimeHandler(Connection connection, Packet packet)
|
static void ServerTimeHandler(Connection connection, Packet packet) {
|
||||||
{
|
|
||||||
connection.InitClientData();
|
connection.InitClientData();
|
||||||
connection.Send(new Sc11002()
|
connection.Send(new Sc11002() {
|
||||||
{
|
|
||||||
Timestamp = (uint)DateTimeOffset.Now.ToUnixTimeSeconds(),
|
Timestamp = (uint)DateTimeOffset.Now.ToUnixTimeSeconds(),
|
||||||
Monday0oclockTimestamp = Connection.Monday0oclockTimestamp,
|
Monday0oclockTimestamp = Connection.Monday0oclockTimestamp,
|
||||||
ShipCount = connection.player is null ? 0 : (uint)connection.player.Ships.Count
|
ShipCount = connection.player is null ? 0 : (uint)connection.player.Ships.Count
|
||||||
@@ -20,8 +16,7 @@ namespace BLHX.Server.Game.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PacketHandler(Command.Cs11009, SaveDataAfterRun = true)]
|
[PacketHandler(Command.Cs11009, SaveDataAfterRun = true)]
|
||||||
static void ChangeManifestoHandler(Connection connection, Packet packet)
|
static void ChangeManifestoHandler(Connection connection, Packet packet) {
|
||||||
{
|
|
||||||
var req = packet.Decode<Cs11009>();
|
var req = packet.Decode<Cs11009>();
|
||||||
connection.player.Adv = req.Adv;
|
connection.player.Adv = req.Adv;
|
||||||
|
|
||||||
@@ -29,8 +24,7 @@ namespace BLHX.Server.Game.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PacketHandler(Command.Cs11013, SaveDataAfterRun = true)]
|
[PacketHandler(Command.Cs11013, SaveDataAfterRun = true)]
|
||||||
static void HarvestResourceHandler(Connection connection, Packet packet)
|
static void HarvestResourceHandler(Connection connection, Packet packet) {
|
||||||
{
|
|
||||||
var req = packet.Decode<Cs11013>();
|
var req = packet.Decode<Cs11013>();
|
||||||
connection.player.HarvestResourceField((ResourceFieldType)req.Type);
|
connection.player.HarvestResourceField((ResourceFieldType)req.Type);
|
||||||
|
|
||||||
@@ -38,55 +32,43 @@ namespace BLHX.Server.Game.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PacketHandler(Command.Cs11601)]
|
[PacketHandler(Command.Cs11601)]
|
||||||
static void GetEmojiInfoHandler(Connection connection, Packet packet)
|
static void GetEmojiInfoHandler(Connection connection, Packet packet) {
|
||||||
{
|
|
||||||
connection.Send(new Sc11602());
|
connection.Send(new Sc11602());
|
||||||
}
|
}
|
||||||
|
|
||||||
[PacketHandler(Command.Cs11603)]
|
[PacketHandler(Command.Cs11603)]
|
||||||
static void FetchSecondaryPasswordHandler(Connection connection, Packet packet)
|
static void FetchSecondaryPasswordHandler(Connection connection, Packet packet) {
|
||||||
{
|
|
||||||
connection.Send(new Sc11604());
|
connection.Send(new Sc11604());
|
||||||
}
|
}
|
||||||
|
|
||||||
[PacketHandler(Command.Cs11017)]
|
[PacketHandler(Command.Cs11017)]
|
||||||
static void StageDropListHandler(Connection connection, Packet packet)
|
static void StageDropListHandler(Connection connection, Packet packet) {
|
||||||
{
|
|
||||||
connection.Send(new Sc11018());
|
connection.Send(new Sc11018());
|
||||||
}
|
}
|
||||||
|
|
||||||
[PacketHandler(Command.Cs11401)]
|
[PacketHandler(Command.Cs11401)]
|
||||||
static void ChangeChatRoomHandler(Connection connection, Packet packet)
|
static void ChangeChatRoomHandler(Connection connection, Packet packet) {
|
||||||
{
|
|
||||||
var req = packet.Decode<Cs11401>();
|
var req = packet.Decode<Cs11401>();
|
||||||
|
|
||||||
connection.Send(new Sc11402()
|
connection.Send(new Sc11402() {
|
||||||
{
|
|
||||||
Result = 0,
|
Result = 0,
|
||||||
RoomId = req.RoomId
|
RoomId = req.RoomId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class P11ConnectionNotifyExtensions
|
static class P11ConnectionNotifyExtensions {
|
||||||
{
|
public static void NotifyResourceList(this Connection connection) {
|
||||||
public static void NotifyResourceList(this Connection connection)
|
if (connection.player is not null) {
|
||||||
{
|
connection.Send(new Sc11004() {
|
||||||
if (connection.player is not null)
|
|
||||||
{
|
|
||||||
connection.Send(new Sc11004()
|
|
||||||
{
|
|
||||||
ResourceLists = connection.player.Resources.Select(x => new Resource() { Num = x.Num, Type = x.Id }).ToList()
|
ResourceLists = connection.player.Resources.Select(x => new Resource() { Num = x.Num, Type = x.Id }).ToList()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void NotifyPlayerData(this Connection connection)
|
public static void NotifyPlayerData(this Connection connection) {
|
||||||
{
|
if (connection.player is not null) {
|
||||||
if (connection.player is not null)
|
connection.Send(new Sc11003() {
|
||||||
{
|
|
||||||
connection.Send(new Sc11003()
|
|
||||||
{
|
|
||||||
Id = connection.player.Uid,
|
Id = connection.player.Uid,
|
||||||
Name = connection.player.Name,
|
Name = connection.player.Name,
|
||||||
Level = connection.player.Level,
|
Level = connection.player.Level,
|
||||||
@@ -94,7 +76,7 @@ namespace BLHX.Server.Game.Handlers
|
|||||||
Adv = connection.player.Adv,
|
Adv = connection.player.Adv,
|
||||||
ResourceLists = connection.player.Resources.Select(x => new Resource() { Num = x.Num, Type = x.Id }).ToList(),
|
ResourceLists = connection.player.Resources.Select(x => new Resource() { Num = x.Num, Type = x.Id }).ToList(),
|
||||||
Characters = [1],
|
Characters = [1],
|
||||||
ShipBagMax = 150,
|
ShipBagMax = connection.player.ShipBagMax,
|
||||||
EquipBagMax = 350,
|
EquipBagMax = 350,
|
||||||
GmFlag = 1,
|
GmFlag = 1,
|
||||||
Rank = 1,
|
Rank = 1,
|
||||||
@@ -109,13 +91,11 @@ namespace BLHX.Server.Game.Handlers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void NotifyRefluxData(this Connection connection)
|
public static void NotifyRefluxData(this Connection connection) {
|
||||||
{
|
|
||||||
connection.Send(new Sc11752());
|
connection.Send(new Sc11752());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void NotifyActivityData(this Connection connection)
|
public static void NotifyActivityData(this Connection connection) {
|
||||||
{
|
|
||||||
connection.Send(new Sc11200());
|
connection.Send(new Sc11200());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user