craztheking

Untitled

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