Player.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using Domain.Weapons;
  2. using Infrastructure;
  3. using System.Xml.Linq;
  4. namespace Domain;
  5. public class Player : BaseEntity
  6. {
  7. public string? Name { get; set; }
  8. public string? CharacterName { get; set; }
  9. public string? Background { get; set; }
  10. public int Experience { get; set; }
  11. public int CC { get; set; }
  12. public int CT { get; set; }
  13. public int F { get; set; }
  14. public int E { get; set; }
  15. public int AG { get; set; }
  16. public int INT { get; set; }
  17. public int PER { get; set; }
  18. public int FM { get; set; }
  19. public int SOC { get; set; }
  20. public int MF { get; set; }
  21. public ICollection<Weapon> Weapons { get; set; }
  22. public int Initiative()
  23. {
  24. return DiceService.RollDices(1, 10) + DiceService.Bonus(AG);
  25. }
  26. public bool TestCC()
  27. {
  28. return DiceService.RollDices(1, 100) <= CC;
  29. }
  30. public bool TestCT()
  31. {
  32. return DiceService.RollDices(1, 100) <= CT;
  33. }
  34. public bool TestF()
  35. {
  36. return DiceService.RollDices(1, 100) <= F;
  37. }
  38. public bool TestE()
  39. {
  40. return DiceService.RollDices(1, 100) <= E;
  41. }
  42. public bool TestAG()
  43. {
  44. return DiceService.RollDices(1, 100) <= AG;
  45. }
  46. public bool TestINT()
  47. {
  48. return DiceService.RollDices(1, 100) <= INT;
  49. }
  50. public bool TestPER()
  51. {
  52. return DiceService.RollDices(1, 100) <= PER;
  53. }
  54. public bool TestFM()
  55. {
  56. return DiceService.RollDices(1, 100) <= FM;
  57. }
  58. public bool TestSOC()
  59. {
  60. return DiceService.RollDices(1, 100) <= SOC;
  61. }
  62. public bool TestMF()
  63. {
  64. return DiceService.RollDices(1, 100) <= MF;
  65. }
  66. public static List<Player> LoadPlayersFromXml(string filePath)
  67. {
  68. XDocument xdoc = XDocument.Load(filePath);
  69. var players = from player in xdoc.Descendants("Player")
  70. select new Player
  71. {
  72. Name = (string)player.Element("Name"),
  73. CharacterName = (string)player.Element("CharacterName"),
  74. Background = (string)player.Element("Background"),
  75. Experience = (int)player.Element("Experience"),
  76. CC = (int)player.Element("CC"),
  77. CT = (int)player.Element("CT"),
  78. F = (int)player.Element("F"),
  79. E = (int)player.Element("E"),
  80. AG = (int)player.Element("AG"),
  81. INT = (int)player.Element("INT"),
  82. PER = (int)player.Element("PER"),
  83. FM = (int)player.Element("FM"),
  84. SOC = (int)player.Element("SOC"),
  85. MF = (int)player.Element("MF"),
  86. CreatedDate = (DateTime)player.Element("CreatedDate"),
  87. ModifiedDate = (DateTime)player.Element("ModifiedDate")
  88. };
  89. return players.ToList();
  90. }
  91. }