forked from Raphael/SCHALE.GameServer
154 lines
5.1 KiB
C#
154 lines
5.1 KiB
C#
namespace SCHALE.Common.Database.ModelExtensions
|
|
{
|
|
public static class AccountExtensions
|
|
{
|
|
public static List<CharacterDB> AddCharacters(this AccountDB account, SCHALEContext context, params CharacterDB[] characters)
|
|
{
|
|
foreach (var character in characters)
|
|
{
|
|
character.AccountServerId = account.ServerId;
|
|
character.ServerId = 0; // just in case if this key was set (like from pcaps)
|
|
context.Characters.Add(character);
|
|
}
|
|
|
|
return [.. characters];
|
|
}
|
|
|
|
public static List<EquipmentDB> AddEquipment(this AccountDB account, SCHALEContext context, params EquipmentDB[] equipmentDB)
|
|
{
|
|
foreach (var equipment in equipmentDB)
|
|
{
|
|
equipment.AccountServerId = account.ServerId;
|
|
|
|
var existingEquipment = account.Equipment.FirstOrDefault(x => x.UniqueId == equipment.UniqueId);
|
|
|
|
if (existingEquipment != null && equipment.BoundCharacterServerId == default)
|
|
existingEquipment.StackCount += equipment.StackCount;
|
|
else
|
|
{
|
|
equipment.ServerId = 0;
|
|
context.Equipment.Add(equipment);
|
|
}
|
|
}
|
|
|
|
return [.. equipmentDB];
|
|
}
|
|
|
|
public static List<WeaponDB> AddWeapons(this AccountDB account, SCHALEContext context, params WeaponDB[] weapons)
|
|
{
|
|
foreach (var weapon in weapons)
|
|
{
|
|
weapon.AccountServerId = account.ServerId;
|
|
context.Weapons.Add(weapon);
|
|
}
|
|
|
|
return [.. weapons];
|
|
}
|
|
|
|
public static List<ItemDB> AddItems(this AccountDB account, SCHALEContext context, params ItemDB[] items)
|
|
{
|
|
foreach (var item in items)
|
|
{
|
|
item.AccountServerId = account.ServerId;
|
|
|
|
var existingItem = account.Items.FirstOrDefault(x => x.UniqueId == item.UniqueId);
|
|
|
|
if (existingItem != null)
|
|
{
|
|
existingItem.StackCount += item.StackCount;
|
|
item.ServerId = existingItem.ServerId;
|
|
} else
|
|
{
|
|
item.ServerId = 0;
|
|
context.Items.Add(item);
|
|
}
|
|
|
|
context.SaveChanges();
|
|
}
|
|
|
|
return [.. items];
|
|
}
|
|
|
|
public static List<GearDB> AddGears(this AccountDB account, SCHALEContext context, params GearDB[] gears)
|
|
{
|
|
foreach (var gear in gears)
|
|
{
|
|
gear.AccountServerId = account.ServerId;
|
|
gear.ServerId = 0;
|
|
|
|
context.Gears.Add(gear);
|
|
|
|
var targetCharacter = account.Characters.FirstOrDefault(x => x.ServerId == gear.BoundCharacterServerId);
|
|
targetCharacter.EquipmentServerIds.Add(gear.ServerId);
|
|
}
|
|
|
|
return [.. gears];
|
|
}
|
|
|
|
public static List<EchelonDB> AddEchelons(this AccountDB account, SCHALEContext context, params EchelonDB[] echelons)
|
|
{
|
|
foreach (var echelon in echelons)
|
|
{
|
|
echelon.AccountServerId = account.ServerId;
|
|
context.Echelons.Add(echelon);
|
|
}
|
|
|
|
return [.. echelons];
|
|
}
|
|
|
|
public static List<MemoryLobbyDB> AddMemoryLobbies(this AccountDB account, SCHALEContext context, params MemoryLobbyDB[] memoryLobbies)
|
|
{
|
|
foreach (var lobby in memoryLobbies)
|
|
{
|
|
lobby.AccountServerId = account.ServerId;
|
|
context.MemoryLobbies.Add(lobby);
|
|
}
|
|
|
|
return [.. memoryLobbies];
|
|
}
|
|
|
|
public static List<ScenarioHistoryDB> AddScenarios(this AccountDB account, SCHALEContext context, params ScenarioHistoryDB[] scenarios)
|
|
{
|
|
foreach (var scenario in scenarios)
|
|
{
|
|
scenario.AccountServerId = account.ServerId;
|
|
context.Scenarios.Add(scenario);
|
|
}
|
|
|
|
return [.. scenarios];
|
|
}
|
|
|
|
public static List<CafeDB> AddCafes(this AccountDB account, SCHALEContext context, params CafeDB[] cafes)
|
|
{
|
|
foreach (var cafe in cafes)
|
|
{
|
|
cafe.AccountServerId = account.ServerId;
|
|
cafe.CafeDBId = 0;
|
|
context.Cafes.Add(cafe);
|
|
}
|
|
|
|
return [.. cafes];
|
|
}
|
|
|
|
public static List<FurnitureDB> AddFurnitures(this AccountDB account, SCHALEContext context, params FurnitureDB[] furnitures)
|
|
{
|
|
foreach (var furniture in furnitures)
|
|
{
|
|
furniture.AccountServerId = account.ServerId;
|
|
furniture.ServerId = 0;
|
|
account.Furnitures.Add(furniture);
|
|
}
|
|
|
|
return [.. furnitures];
|
|
}
|
|
|
|
public static List<FurnitureDB> RemoveFurnitures(this AccountDB account, SCHALEContext context, params FurnitureDB[] furnitures)
|
|
{
|
|
context.Furnitures.RemoveRange(furnitures);
|
|
|
|
return [.. furnitures];
|
|
}
|
|
|
|
}
|
|
}
|