Timer problem
Hey, im making a .net8 backend + ef core for my project. It's my first time using "advanced" timers and I don' know how to implement it. To begin with I have 3 models:
- Food
- User
- BoostType (modal)
User can use Food to gain boost (from BoostType) for certain amount of time - eg. for 3 min he have +20 health. After this 3min boost should have be gone. How to implement this? Cookies is way to go?
3 Replies
i wouldn't use cookies, this is a state of the character, right? (if this is a game and there is a playing character)
Yup, that's right
Here are these classes
public class Student
{
// Keys
public int Id { get; set; }
// Key fragments
[Required]
public int Money { get; set; } = 0;
[Required]
public int Energy { get; set; } = 100;
// Experience and position in ranking
[Required]
public int LevelPoints { get; set; } = 0;
[Required]
public Ranks Rank { get; set; } = Ranks.Silver_I;
[Required]
public int Level { get; set; } = 1;
[Required]
public int Experience { get; set; } = 0;
// Points used in fights, events etc.
[Required]
public int HealthPoints { get; set; } = 100; // bazowe zdrowie
[Required]
public int AttackPoints { get; set; } = 1; // bazowy atak
[Required]
public int DefensePoints { get; set; } = 1; // zwieksza procentowo hp przy ataku
[Required]
public int LuckPoints { get; set; } = 1; // pomaga przy losowaniu do ataku
[Required]
public int IntelligencePoints { get; set; } = 1;// cappuje zakladanie broni/zbroi aby nie bylo przypadku kiedy osoba na 1lvl moze zalozyc najlepszy przedmiot w grze
// Equipped items
[ForeignKey("Armour")]
[AllowNull]
public int? ArmourId { get; set; }
[ForeignKey("Weapon")]
[AllowNull]
public int? WeaponId { get; set; }
[ForeignKey("Account")]
public int AccountId { get; set; }
// Db relation
public ICollection<Student_Weapon> Student_Weapons { get; set; } = new List<Student_Weapon>();
public ICollection<Student_Armour> Student_Armours { get; set; } = new List<Student_Armour>();
public ICollection<Student_Food> Student_Foods { get; set; } = new List<Student_Food>();
public Stat? Stats{ get; set; }
//child
public Armour Armour { get; set; } = null!;
public Weapon Weapon { get; set; } = null!;
public Account Account { get; set; } = null!;
}
public class Food
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public int BoostAmount { get; set; }
[Required]
public Boost BoostType { get; set; }
[Required]
public int Duration { get; set; }
[Required]
public int Cost { get; set; }
[Required]
public Rarity Rarity{ get; set; }
// Db relation
public ICollection<Student_Food> Student_Foods { get; set; } = new List<Student_Food>();
}
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Boost
{
HealthBoost = 1,
AttackBoost = 2,
DefenseBoost = 3,
LuckBoost = 4
}
public class Student
{
// Keys
public int Id { get; set; }
// Key fragments
[Required]
public int Money { get; set; } = 0;
[Required]
public int Energy { get; set; } = 100;
// Experience and position in ranking
[Required]
public int LevelPoints { get; set; } = 0;
[Required]
public Ranks Rank { get; set; } = Ranks.Silver_I;
[Required]
public int Level { get; set; } = 1;
[Required]
public int Experience { get; set; } = 0;
// Points used in fights, events etc.
[Required]
public int HealthPoints { get; set; } = 100; // bazowe zdrowie
[Required]
public int AttackPoints { get; set; } = 1; // bazowy atak
[Required]
public int DefensePoints { get; set; } = 1; // zwieksza procentowo hp przy ataku
[Required]
public int LuckPoints { get; set; } = 1; // pomaga przy losowaniu do ataku
[Required]
public int IntelligencePoints { get; set; } = 1;// cappuje zakladanie broni/zbroi aby nie bylo przypadku kiedy osoba na 1lvl moze zalozyc najlepszy przedmiot w grze
// Equipped items
[ForeignKey("Armour")]
[AllowNull]
public int? ArmourId { get; set; }
[ForeignKey("Weapon")]
[AllowNull]
public int? WeaponId { get; set; }
[ForeignKey("Account")]
public int AccountId { get; set; }
// Db relation
public ICollection<Student_Weapon> Student_Weapons { get; set; } = new List<Student_Weapon>();
public ICollection<Student_Armour> Student_Armours { get; set; } = new List<Student_Armour>();
public ICollection<Student_Food> Student_Foods { get; set; } = new List<Student_Food>();
public Stat? Stats{ get; set; }
//child
public Armour Armour { get; set; } = null!;
public Weapon Weapon { get; set; } = null!;
public Account Account { get; set; } = null!;
}
public class Food
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public int BoostAmount { get; set; }
[Required]
public Boost BoostType { get; set; }
[Required]
public int Duration { get; set; }
[Required]
public int Cost { get; set; }
[Required]
public Rarity Rarity{ get; set; }
// Db relation
public ICollection<Student_Food> Student_Foods { get; set; } = new List<Student_Food>();
}
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Boost
{
HealthBoost = 1,
AttackBoost = 2,
DefenseBoost = 3,
LuckBoost = 4
}
so only one boost can exist at a time?
if so then if you have a service to manage the state of the character it should be pretty straightforward to add a timer