random dragon colours for April Fools (Loki Day)

This commit is contained in:
Robert Paciorek 2025-03-31 09:13:23 +00:00
parent 20aa92103e
commit b8a7ef847e
4 changed files with 54 additions and 0 deletions

View File

@ -44,6 +44,7 @@ internal sealed class ServerConfiguration {
public int PingDelay { get; set; } = 17; public int PingDelay { get; set; } = 17;
public bool EnableChat { get; set; } = true; public bool EnableChat { get; set; } = true;
public bool AllowChaos { get; set; } = false; public bool AllowChaos { get; set; } = false;
public bool MakeChaos { get; set; } = false;
public AuthenticationMode Authentication { get; set; } = AuthenticationMode.Disabled; public AuthenticationMode Authentication { get; set; } = AuthenticationMode.Disabled;
public string ApiUrl { get; set; } = ""; public string ApiUrl { get; set; } = "";
public string BypassToken { get; set; } = ""; public string BypassToken { get; set; } = "";

View File

@ -1,5 +1,6 @@
using System; using System;
using sodoffmmo.Data; using sodoffmmo.Data;
using System.Timers;
namespace sodoffmmo.Core; namespace sodoffmmo.Core;
public class Room { public class Room {
@ -33,6 +34,9 @@ public class Room {
} }
AutoRemove = autoRemove; AutoRemove = autoRemove;
rooms.Add(Name, this); rooms.Add(Name, this);
if (Configuration.ServerConfiguration.MakeChaos)
SetTimer(2);
} }
public int ClientsCount => clients.Count; public int ClientsCount => clients.Count;
@ -155,4 +159,35 @@ public class Room {
} }
internal virtual NetworkArray GetRoomVars() { return RoomVariables; } internal virtual NetworkArray GetRoomVars() { return RoomVariables; }
private System.Timers.Timer timer;
private Random random = new Random();
private void SetTimer(double timeout) {
if (timer != null) {
timer.Stop();
timer.Close();
}
timer = new System.Timers.Timer(timeout * 1000);
timer.AutoReset = false;
timer.Enabled = true;
timer.Elapsed += OnTimer;
}
private void OnTimer(Object? source, ElapsedEventArgs e) {
foreach (var roomClient in Clients) {
roomClient.PlayerData.RandomizeDragon();
NetworkArray vl = new();
NetworkObject data = new();
var value = roomClient.PlayerData.GetVariable("FP");
data.Add("FP", value);
vl.Add(NetworkArray.Param("FP", value));
roomClient.SendSUV(vl, data);
}
SetTimer(random.NextDouble() * 9 + 1);
}
} }

View File

@ -171,6 +171,8 @@ public class PlayerData {
} }
} }
private string PetGeometry = "";
private string FixMountState(string value) { private string FixMountState(string value) {
// raised pet geometry - set from Fp // raised pet geometry - set from Fp
PetGeometryType GeometryType = PetGeometryType.Default; PetGeometryType GeometryType = PetGeometryType.Default;
@ -202,6 +204,11 @@ public class PlayerData {
if (keyValPairs.TryGetValue("U", out string userdata)) { if (keyValPairs.TryGetValue("U", out string userdata)) {
PetMounted = (userdata == "0" || userdata == "1"); PetMounted = (userdata == "0" || userdata == "1");
} }
if (Configuration.ServerConfiguration.MakeChaos) {
if (PetGeometry == geometry)
return variables["FP"];
PetGeometry = geometry;
}
if (PetMounted && !Configuration.ServerConfiguration.AllowChaos && if (PetMounted && !Configuration.ServerConfiguration.AllowChaos &&
(GeometryType == PetGeometryType.Default && PetAge < PetAge.Teen (GeometryType == PetGeometryType.Default && PetAge < PetAge.Teen
|| GeometryType == PetGeometryType.Terror && PetAge < PetAge.Titan) || GeometryType == PetGeometryType.Terror && PetAge < PetAge.Titan)
@ -211,6 +218,14 @@ public class PlayerData {
return value; return value;
} }
} }
private Random random = new Random();
public void RandomizeDragon() {
var s = "*C$";
for (var i=0; i<9; ++i)
s=s+random.Next(0, 255).ToString() + "$";
variables["FP"] = Regex.Replace(variables["FP"], "\\*C\\$[0-9$]*\\*", s + "*");
}
} }
public enum PetGeometryType { public enum PetGeometryType {

View File

@ -56,6 +56,9 @@
"// AllowChaos": "disable server side exploit protection", "// AllowChaos": "disable server side exploit protection",
"AllowChaos": false, "AllowChaos": false,
"// MakeChaos": "enable server-side randomize stuff",
"MakeChaos": true,
"// Authentication": "Player authentication mode: Disabled, Optional, RequiredForChat, Required", "// Authentication": "Player authentication mode: Disabled, Optional, RequiredForChat, Required",
"// Authentication Disabled": "authentication is disabled, anyone can connect to mmo", "// Authentication Disabled": "authentication is disabled, anyone can connect to mmo",
"// Authentication Optional": "authentication is required only for moderation activities", "// Authentication Optional": "authentication is required only for moderation activities",