mirror of
https://github.com/rafi1212122/PemukulPaku
synced 2025-12-14 11:44:35 +01:00
at least you can end the stage
This commit is contained in:
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.
|
||||
}
|
||||
Reference in New Issue
Block a user