Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using System.Collections;
- public class BloodMoonPvPMod : MonoBehaviour
- {
- private bool isBloodMoonActive = false;
- private bool pvpDisabled = false;
- private float pvpReenableDelay;
- void Start()
- {
- LoadConfig();
- InvokeRepeating("CheckBloodMoonStatus", 0f, 60f); // check every minute
- }
- void LoadConfig()
- {
- // Load JSON config (adjust path as necessary)
- string configPath = "Mods/PvPControlConfig.json";
- if (System.IO.File.Exists(configPath))
- {
- string json = System.IO.File.ReadAllText(configPath);
- dynamic config = JsonUtility.FromJson<Config>(json);
- pvpReenableDelay = config.pvpReenableDelayHours * 3600f;
- }
- else
- {
- pvpReenableDelay = 2 * 3600f; // default 2 hours
- }
- }
- void CheckBloodMoonStatus()
- {
- int currentDay = GameManager.Instance.World.GetWorldTime().Day;
- // Blood Moon occurs on day 7, 14, 21, etc.
- if ((currentDay % 7) == 0)
- {
- if (!pvpDisabled)
- {
- DisablePvP();
- }
- isBloodMoonActive = true;
- }
- else
- {
- if (isBloodMoonActive)
- {
- isBloodMoonActive = false;
- StartCoroutine(ReenablePvPAfterDelay());
- }
- }
- }
- void DisablePvP()
- {
- pvpDisabled = true;
- GamePrefs.SetBool("PvP", false);
- if (Config.notifyPlayers)
- GameManager.Instance.ChatMessage(Config.disableMessage);
- }
- IEnumerator ReenablePvPAfterDelay()
- {
- yield return new WaitForSeconds(pvpReenableDelay);
- GamePrefs.SetBool("PvP", true);
- pvpDisabled = false;
- if (Config.notifyPlayers)
- GameManager.Instance.ChatMessage(Config.enableMessage);
- }
- [Serializable]
- public class Config
- {
- public bool pvpDisableAfterBloodMoon = true;
- public float pvpReenableDelayHours = 2;
- public bool notifyPlayers = true;
- public string disableMessage = "PvP is now disabled for the Blood Moon!";
- public string enableMessage = "PvP is now enabled.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment