config.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @file config.c
  3. * @author 稻草人
  4. * @version 1.0
  5. * @date 2025-02-12
  6. * @copyright Copyright (c) 2025
  7. *
  8. * @brief This file contains the configuration for the custom revival suit feature.
  9. */
  10. static ref CustomRevivalSuitCfg g_CustomRevivalSuitCfg;
  11. static ref CustomRevivalSuitCfg GetCustomRevivalSuitCfg()
  12. {
  13. if ( !g_CustomRevivalSuitCfg )
  14. {
  15. g_CustomRevivalSuitCfg = new ref CustomRevivalSuitCfg();
  16. g_CustomRevivalSuitCfg.loadConfig();
  17. }
  18. return g_CustomRevivalSuitCfg;
  19. }
  20. class CustomRevivalSuitCfg
  21. {
  22. protected static string profileDir = "$profile:DcrServerModCfg\\CustomRevivalSuitCfg";
  23. protected static string profileName = "\\CustomRevivalSuitCfg.json";
  24. protected static string profilePath = profileDir + profileName;
  25. ref array< ref PlayerRevivalEquipmentData > PlayerRevivalEquipmentDataList;
  26. void loadConfig()
  27. {
  28. if ( !FileExist( profilePath ) )
  29. makeConfig();
  30. JsonFileLoader< ref CustomRevivalSuitCfg >.JsonLoadFile( profilePath, this );
  31. }
  32. void makeConfig()
  33. {
  34. PlayerRevivalEquipmentDataList = new ref array< ref PlayerRevivalEquipmentData >();
  35. ref PlayerRevivalEquipmentData playerData = new ref PlayerRevivalEquipmentData( "76561198422667486" );
  36. PlayerRevivalEquipmentDataList.Insert( playerData );
  37. MakeDirectory( "$profile:DcrServerModCfg/" );
  38. MakeDirectory( profileDir + "/" );
  39. SaveConfig();
  40. }
  41. void SaveConfig()
  42. JsonFileLoader< ref CustomRevivalSuitCfg >.JsonSaveFile( profilePath, this );
  43. ref PlayerRevivalEquipmentData GetPlayerRevivalEquipmentData( string steamid )
  44. {
  45. foreach ( ref PlayerRevivalEquipmentData playerData : PlayerRevivalEquipmentDataList )
  46. {
  47. if ( !playerData ) continue;
  48. ref TStringArray TeamMembers = playerData.TeamMembers;
  49. if ( TeamMembers && TeamMembers.Find( steamid ) > -1 )
  50. return playerData;
  51. }
  52. return NULL;
  53. }
  54. }
  55. class PlayerRevivalEquipmentData
  56. {
  57. // string SteamId;
  58. ref TStringArray TeamMembers; // 兼容个人和队伍,单人玩家 == 单人队伍
  59. ref TStringArray Equipments;
  60. ref TStringArray ItemList;
  61. ref WeaponCfg WeaponData;
  62. void PlayerRevivalEquipmentData( string steamid )
  63. {
  64. // SteamId = steamid;
  65. TeamMembers = new TStringArray();
  66. TeamMembers.Insert( steamid );
  67. Equipments = { "WoolGloves_White", "BaseballCap_Black",
  68. "Jeans_Blue", "Wellies_Black", "TShirt_Black"
  69. };
  70. ItemList = { "Apple" };
  71. WeaponData = new ref WeaponCfg();
  72. }
  73. }
  74. class WeaponCfg
  75. {
  76. string WeaponName;
  77. string Desc;
  78. ref TStringArray WeaponComponents;
  79. void WeaponCfg()
  80. {
  81. WeaponName = "FAL";
  82. Desc = "武器配件中,一级配件(比如枪托,弹夹)放在前排,二级配件(比如电池)其次 以此类推"
  83. WeaponComponents = {
  84. "Fal_FoldingBttstck",
  85. "Mag_FAL_20Rnd"
  86. };
  87. }
  88. }