craztheking

Untitled

Aug 23rd, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.IO;
  5.  
  6. public class BloodMoonPvPMod : MonoBehaviour
  7. {
  8. private bool isBloodMoonActive = false;
  9. private bool pvpDisabled = false;
  10. private float pvpReenableDelayHours = 2f;
  11. private Config config;
  12.  
  13. void Start()
  14. {
  15. LoadConfig();
  16. InvokeRepeating("CheckBloodMoonStatus", 0f, 60f); // check every minute
  17. }
  18.  
  19. void LoadConfig()
  20. {
  21. string configPath = "Mods/PvPControlBloodMoon/Config/PvPControlConfig.json";
  22. if (File.Exists(configPath))
  23. {
  24. string json = File.ReadAllText(configPath);
  25. config = JsonUtility.FromJson<Config>(json);
  26. pvpReenableDelayHours = config.pvpReenableDelayInGameHours;
  27. }
  28. else
  29. {
  30. // Default config
  31. config = new Config();
  32. }
  33. }
  34.  
  35. void CheckBloodMoonStatus()
  36. {
  37. int currentDay = GameManager.Instance.World.GetWorldTime().Day;
  38.  
  39. // Blood Moon occurs on day 7, 14, 21, etc.
  40. if ((currentDay % 7) == 0)
  41. {
  42. if (!pvpDisabled && config.pvpDisableAfterBloodMoon)
  43. {
  44. DisablePvP();
  45. }
  46. isBloodMoonActive = true;
  47. }
  48. else
  49. {
  50. if (isBloodMoonActive)
  51. {
  52. isBloodMoonActive = false;
  53. StartCoroutine(ReenablePvPAfterInGameDelay());
  54. }
  55. }
  56. }
  57.  
  58. void DisablePvP()
  59. {
  60. pvpDisabled = true;
  61. GamePrefs.SetBool("PvP", false);
  62. if (config.notifyPlayers)
  63. GameManager.Instance.ChatMessage(config.disableMessage);
  64. }
  65.  
  66. IEnumerator ReenablePvPAfterInGameDelay()
  67. {
  68. float secondsPerGameHour = GameManager.Instance.World.GetWorldTime().SecondsPerHour;
  69. float delaySeconds = pvpReenableDelayHours * secondsPerGameHour;
  70.  
  71. yield return new WaitForSeconds(delaySeconds);
  72.  
  73. GamePrefs.SetBool("PvP", true);
  74. pvpDisabled = false;
  75. if (config.notifyPlayers)
  76. GameManager.Instance.ChatMessage(config.enableMessage);
  77. }
  78.  
  79. [Serializable]
  80. public class Config
  81. {
  82. public bool pvpDisableAfterBloodMoon = true;
  83. public float pvpReenableDelayInGameHours = 2f;
  84. public bool notifyPlayers = true;
  85. public string disableMessage = "PvP is now disabled for the Blood Moon!";
  86. public string enableMessage = "PvP is now enabled.";
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment