Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using System.Collections;
- using System.IO;
- public class BloodMoonPvPMod : MonoBehaviour
- {
- private bool isBloodMoonActive = false;
- private bool pvpDisabled = false;
- private float pvpReenableDelayHours = 2f;
- private Config config;
- void Start()
- {
- LoadConfig();
- InvokeRepeating("CheckBloodMoonStatus", 0f, 60f); // check every minute
- }
- void LoadConfig()
- {
- string configPath = "Mods/PvPControlBloodMoon/Config/PvPControlConfig.json";
- if (File.Exists(configPath))
- {
- string json = File.ReadAllText(configPath);
- config = JsonUtility.FromJson<Config>(json);
- pvpReenableDelayHours = config.pvpReenableDelayInGameHours;
- }
- else
- {
- // Default config
- config = new Config();
- }
- }
- void CheckBloodMoonStatus()
- {
- int currentDay = GameManager.Instance.World.GetWorldTime().Day;
- // Blood Moon occurs on day 7, 14, 21, etc.
- if ((currentDay % 7) == 0)
- {
- if (!pvpDisabled && config.pvpDisableAfterBloodMoon)
- {
- DisablePvP();
- }
- isBloodMoonActive = true;
- }
- else
- {
- if (isBloodMoonActive)
- {
- isBloodMoonActive = false;
- StartCoroutine(ReenablePvPAfterInGameDelay());
- }
- }
- }
- void DisablePvP()
- {
- pvpDisabled = true;
- GamePrefs.SetBool("PvP", false);
- if (config.notifyPlayers)
- GameManager.Instance.ChatMessage(config.disableMessage);
- }
- IEnumerator ReenablePvPAfterInGameDelay()
- {
- float secondsPerGameHour = GameManager.Instance.World.GetWorldTime().SecondsPerHour;
- float delaySeconds = pvpReenableDelayHours * secondsPerGameHour;
- yield return new WaitForSeconds(delaySeconds);
- GamePrefs.SetBool("PvP", true);
- pvpDisabled = false;
- if (config.notifyPlayers)
- GameManager.Instance.ChatMessage(config.enableMessage);
- }
- [Serializable]
- public class Config
- {
- public bool pvpDisableAfterBloodMoon = true;
- public float pvpReenableDelayInGameHours = 2f;
- 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