mirror of
https://github.com/rafi1212122/PemukulPaku
synced 2025-12-14 09:14:38 +01:00
at least you can end the stage
This commit is contained in:
75
Common/Database/Avatar.cs
Normal file
75
Common/Database/Avatar.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Common.Resources.Proto;
|
||||
using Common.Utils.ExcelReader;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Common.Database
|
||||
{
|
||||
public class Avatar
|
||||
{
|
||||
public static readonly IMongoCollection<AvatarScheme> collection = Global.db.GetCollection<AvatarScheme>("Avatars");
|
||||
|
||||
public static AvatarScheme[] AvatarsFromUid(uint uid)
|
||||
{
|
||||
return collection.AsQueryable().Where(collection=> collection.OwnerUid == uid).ToArray();
|
||||
}
|
||||
|
||||
public static AvatarScheme Create(int avatarId, uint uid, EquipmentScheme equipment)
|
||||
{
|
||||
AvatarScheme? tryAvatar = collection.AsQueryable().Where(collection => collection.AvatarId == avatarId && collection.OwnerUid == uid).FirstOrDefault();
|
||||
if (tryAvatar != null) { return tryAvatar; }
|
||||
|
||||
AvatarDataExcel? avatarData = AvatarData.GetInstance().FromId(avatarId);
|
||||
if(avatarData == null) { throw new ArgumentException("Invalid avatarId"); }
|
||||
|
||||
Weapon weapon = equipment.AddWeapon(avatarData.InitialWeapon);
|
||||
|
||||
AvatarScheme avatar = new()
|
||||
{
|
||||
OwnerUid = uid,
|
||||
AvatarId = (uint)avatarData.AvatarId,
|
||||
DressId = (uint)avatarData.DefaultDressId,
|
||||
DressLists = new[] { (uint)avatarData.DefaultDressId },
|
||||
Exp = 0,
|
||||
Fragment = 0,
|
||||
Level = 1,
|
||||
Star = (uint)avatarData.UnlockStar,
|
||||
StigmataUniqueId1 = 0,
|
||||
StigmataUniqueId2 = 0,
|
||||
StigmataUniqueId3 = 0,
|
||||
SubStar = 0,
|
||||
TouchGoodfeel = 0,
|
||||
TodayHasAddGoodfeel = 0,
|
||||
WeaponUniqueId = weapon.UniqueId
|
||||
};
|
||||
|
||||
if(avatarData.AvatarId == 101)
|
||||
{
|
||||
Stigmata defaultStigmata1 = equipment.AddStigmata(30007);
|
||||
Stigmata defaultStigmata2 = equipment.AddStigmata(30060);
|
||||
Stigmata defaultStigmata3 = equipment.AddStigmata(30113);
|
||||
|
||||
avatar.StigmataUniqueId1 = defaultStigmata1.UniqueId;
|
||||
avatar.StigmataUniqueId2 = defaultStigmata2.UniqueId;
|
||||
avatar.StigmataUniqueId3 = defaultStigmata3.UniqueId;
|
||||
}
|
||||
|
||||
avatar.SkillLists.AddRange(avatarData.SkillList.Select(skillId => new AvatarSkill { SkillId = (uint)skillId }));
|
||||
|
||||
collection.InsertOne(avatar);
|
||||
|
||||
return avatar;
|
||||
}
|
||||
|
||||
}
|
||||
public class AvatarScheme : Resources.Proto.Avatar
|
||||
{
|
||||
public ObjectId Id { get; set; }
|
||||
public uint OwnerUid { get; set; }
|
||||
|
||||
public void Save()
|
||||
{
|
||||
Avatar.collection.ReplaceOne(Builders<AvatarScheme>.Filter.Eq(avatar => avatar.Id, Id), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
116
Common/Database/Equipment.cs
Normal file
116
Common/Database/Equipment.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using Common.Resources.Proto;
|
||||
using Common.Utils.ExcelReader;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Common.Database
|
||||
{
|
||||
public class Equipment
|
||||
{
|
||||
public static readonly IMongoCollection<EquipmentScheme> collection = Global.db.GetCollection<EquipmentScheme>("Equipments");
|
||||
|
||||
public static EquipmentScheme FromUid(uint uid)
|
||||
{
|
||||
return collection.AsQueryable().Where(collection => collection.OwnerUid == uid).FirstOrDefault() ?? Create(uid);
|
||||
}
|
||||
|
||||
public static EquipmentScheme Create(uint uid)
|
||||
{
|
||||
EquipmentScheme? tryEquipment = collection.AsQueryable().Where(collection => collection.OwnerUid == uid).FirstOrDefault();
|
||||
if (tryEquipment != null) { return tryEquipment; }
|
||||
|
||||
EquipmentScheme Equipment = new()
|
||||
{
|
||||
OwnerUid = uid,
|
||||
MaterialList = Array.Empty<Resources.Proto.Material>(),
|
||||
WeaponList = Array.Empty<Weapon>(),
|
||||
StigmataList = Array.Empty<Stigmata>(),
|
||||
MechaList = Array.Empty<Mecha>(),
|
||||
};
|
||||
|
||||
collection.InsertOne(Equipment);
|
||||
|
||||
return Equipment;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
public class EquipmentScheme
|
||||
{
|
||||
public ObjectId Id { get; set; }
|
||||
public uint OwnerUid { get; set; }
|
||||
public Resources.Proto.Material[] MaterialList { get; set; }
|
||||
public Mecha[] MechaList { get; set; }
|
||||
public Stigmata[] StigmataList { get; set; }
|
||||
public Weapon[] WeaponList { get; set; }
|
||||
|
||||
public Weapon AddWeapon(int weaponId)
|
||||
{
|
||||
WeaponDataExcel? weaponData = WeaponData.GetInstance().FromId(weaponId);
|
||||
if (weaponData == null) { throw new ArgumentException("Invalid weaponId"); }
|
||||
|
||||
Weapon weapon = new()
|
||||
{
|
||||
UniqueId = (uint)AutoIncrement.GetNextNumber("Weapon", 100),
|
||||
Id = (uint)weaponData.Id,
|
||||
Level = 1,
|
||||
Exp = 0,
|
||||
IsExtracted = false,
|
||||
IsProtected = false
|
||||
};
|
||||
|
||||
WeaponList = WeaponList.Append(weapon).ToArray();
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public Stigmata AddStigmata(int stigmataId)
|
||||
{
|
||||
StigmataDataExcel? stigmataData = StigmataData.GetInstance().FromId(stigmataId);
|
||||
if (stigmataData == null) { throw new ArgumentException("Invalid stigmataId"); }
|
||||
|
||||
Stigmata stigmata = new()
|
||||
{
|
||||
UniqueId = (uint)AutoIncrement.GetNextNumber("Stigmata", 100),
|
||||
Id = (uint)stigmataData.Id,
|
||||
Level = 1,
|
||||
Exp = 0,
|
||||
IsProtected = false,
|
||||
SlotNum = 0,
|
||||
RefineValue = 0,
|
||||
PromoteTimes = 0
|
||||
};
|
||||
|
||||
StigmataList = StigmataList.Append(stigmata).ToArray();
|
||||
return stigmata;
|
||||
}
|
||||
|
||||
public Resources.Proto.Material AddMaterial(int materialId, int num = 1)
|
||||
{
|
||||
int MaterialIndex = Array.FindIndex(MaterialList, material => material.Id == materialId);
|
||||
|
||||
if(MaterialIndex == -1)
|
||||
{
|
||||
MaterialList = MaterialList.Append(new() { Id = (uint)materialId, Num = num < 0 ? 0 : (uint)num }).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num < 0)
|
||||
{
|
||||
MaterialList[MaterialIndex].Num -= (uint)Math.Abs(num);
|
||||
}
|
||||
else
|
||||
{
|
||||
MaterialList[MaterialIndex].Num += (uint)num;
|
||||
}
|
||||
}
|
||||
|
||||
return MaterialList.Where(material => material.Id == materialId).First();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
Equipment.collection.ReplaceOne(Builders<EquipmentScheme>.Filter.Eq(equipment => equipment.Id, Id), this);
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
}
|
||||
@@ -8,8 +8,11 @@ namespace Common.Database
|
||||
{
|
||||
public static readonly IMongoCollection<UserScheme> collection = Global.db.GetCollection<UserScheme>("Users");
|
||||
|
||||
public static UserScheme CreateUser(string name)
|
||||
public static UserScheme Create(string name)
|
||||
{
|
||||
UserScheme? tryUser = collection.AsQueryable().Where(d => d.Name == name).FirstOrDefault();
|
||||
if (tryUser != null) { return tryUser; }
|
||||
|
||||
UserScheme user = new()
|
||||
{
|
||||
Name = name,
|
||||
@@ -41,7 +44,7 @@ namespace Common.Database
|
||||
public static UserScheme FromName(string name)
|
||||
{
|
||||
UserScheme? user = collection.AsQueryable().Where(d => d.Name == name).FirstOrDefault();
|
||||
return user ?? CreateUser(name);
|
||||
return user ?? Create(name);
|
||||
}
|
||||
|
||||
public static UserScheme? FromToken(string token)
|
||||
@@ -50,27 +53,33 @@ namespace Common.Database
|
||||
return user;
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
public class UserScheme
|
||||
{
|
||||
public ObjectId Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public uint Uid { get; set; }
|
||||
public string Nick { get; set; }
|
||||
public int Exp { get; set; }
|
||||
public int Hcoin { get; set; }
|
||||
public int Stamina { get; set; }
|
||||
public string SelfDesc { get; set; }
|
||||
public bool IsFirstLogin { get; set; }
|
||||
public string Token { get; set; }
|
||||
public int WarshipId { get; set; }
|
||||
public WarshipAvatarData WarshipAvatar { get; set; }
|
||||
public int AssistantAvatarId { get; set; }
|
||||
public int BirthDate { get; set; }
|
||||
public List<AvatarTeam> AvatarTeamList { get; set; }
|
||||
public List<CustomAvatarTeam> CustomAvatarTeamList { get; set; }
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
public class UserScheme
|
||||
{
|
||||
public ObjectId Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public uint Uid { get; set; }
|
||||
public string Nick { get; set; }
|
||||
public int Exp { get; set; }
|
||||
public int Hcoin { get; set; }
|
||||
public int Stamina { get; set; }
|
||||
public string SelfDesc { get; set; }
|
||||
public bool IsFirstLogin { get; set; }
|
||||
public string Token { get; set; }
|
||||
public int WarshipId { get; set; }
|
||||
public WarshipAvatarData WarshipAvatar { get; set; }
|
||||
public int AssistantAvatarId { get; set; }
|
||||
public int BirthDate { get; set; }
|
||||
public List<AvatarTeam> AvatarTeamList { get; set; }
|
||||
public List<CustomAvatarTeam> CustomAvatarTeamList { get; set; }
|
||||
|
||||
public void Save()
|
||||
{
|
||||
User.collection.ReplaceOne(Builders<UserScheme>.Filter.Eq(user => user.Id, Id), this);
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user