mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
finally works
This commit is contained in:
1 parent
160d424707
commit
246e40539c
3 files changed
+44
-29
No files matched your search
@@ -255,4 +255,24 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
return AddModifier(typeof(T)) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a player has an active or queued modifier by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The Modifier ID.</param>
|
||||
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||
public bool HasModifier(uint id)
|
||||
{
|
||||
return ActiveModifiers.Exists(x => x.ModifierId == id) || _toAdd.Exists(x => x.ModifierId == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a player has an active or queued modifier by its type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The Type of the Modifier.</typeparam>
|
||||
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||
public bool HasModifier<T>()
|
||||
{
|
||||
return ActiveModifiers.Exists(x => x is T) || _toAdd.Exists(x => x is T);
|
||||
}
|
||||
}
|
||||
@@ -78,73 +78,68 @@ public static class ModifierManager
|
||||
|
||||
internal static void AssignModifiers(List<PlayerControl> plrs)
|
||||
{
|
||||
foreach (var player in plrs)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Message(player.Data.PlayerName);
|
||||
}
|
||||
|
||||
var rand = new Random();
|
||||
var sequence = PrioritiesToIdsMap.Keys.OrderByDescending(x => x);
|
||||
|
||||
foreach (var priority in sequence)
|
||||
foreach (var priority in PrioritiesToIdsMap.Keys.OrderByDescending(x => x))
|
||||
{
|
||||
var filteredModifiers = new List<uint>();
|
||||
Logger<MiraApiPlugin>.Message(priority);
|
||||
|
||||
foreach (var id in PrioritiesToIdsMap[priority])
|
||||
{
|
||||
var mod = Activator.CreateInstance(IdToTypeModifierMap[id]) as GameModifier;
|
||||
var chance = Math.Clamp(mod!.GetAssignmentChance(), 0, 100);
|
||||
var maxCount = plrs.Count(x => IsGameModifierValid(x, mod!, id));
|
||||
Logger<MiraApiPlugin>.Message(maxCount);
|
||||
|
||||
if (chance == 0 || mod!.GetAmountPerGame() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (maxCount == 0)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Warning("No players are valid for modifier: " + mod!.ModifierName);
|
||||
Logger<MiraApiPlugin>.Warning($"No players are valid for {mod!.ModifierName}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var num = Math.Clamp(mod!.GetAmountPerGame(), 0, maxCount);
|
||||
var chance = mod.GetAssignmentChance();
|
||||
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
var randomNum = rand.Next(100);
|
||||
|
||||
if (randomNum < Math.Clamp(chance, 0, 100))
|
||||
if (randomNum < chance)
|
||||
{
|
||||
filteredModifiers.Add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var shuffledList = filteredModifiers.ToList().Randomize();
|
||||
if (filteredModifiers.Count == 0)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Warning($"No filtered modifiers for priority {priority}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var shuffledList = filteredModifiers.Randomize();
|
||||
|
||||
if (shuffledList.Count > plrs.Count)
|
||||
{
|
||||
shuffledList = shuffledList.GetRange(0, plrs.Count)!;
|
||||
}
|
||||
|
||||
while (shuffledList.Count > 0)
|
||||
foreach (var id in shuffledList)
|
||||
{
|
||||
var id = shuffledList[0];
|
||||
var mod = Activator.CreateInstance(IdToTypeModifierMap[id]) as GameModifier;
|
||||
var plr = plrs.Where(x => IsGameModifierValid(x, mod!, id)).Random();
|
||||
|
||||
if (!plrs.Exists(x => IsGameModifierValid(x, mod!, id)))
|
||||
if (plr == null)
|
||||
{
|
||||
shuffledList.RemoveAt(0);
|
||||
continue;
|
||||
Logger<MiraApiPlugin>.Warning($"Somehow valid players for modifier {mod!.ModifierName} disappeared");
|
||||
}
|
||||
|
||||
var plr = plrs.Random();
|
||||
|
||||
if (plr == null || !IsGameModifierValid(plr, mod!, id))
|
||||
else
|
||||
{
|
||||
shuffledList.RemoveAt(0); // Just some insurance
|
||||
continue;
|
||||
plr.RpcAddModifier(id);
|
||||
}
|
||||
|
||||
shuffledList.RemoveAt(0);
|
||||
plr.RpcAddModifier(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public static class Extensions
|
||||
public static bool HasModifier<T>(this PlayerControl? player) where T : BaseModifier
|
||||
{
|
||||
return player?.GetModifierComponent() != null &&
|
||||
player.GetModifierComponent()!.ActiveModifiers.Exists(x => x is T);
|
||||
player.GetModifierComponent()!.HasModifier<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -206,7 +206,7 @@ public static class Extensions
|
||||
public static bool HasModifier(this PlayerControl? player, uint id)
|
||||
{
|
||||
return player?.GetModifierComponent() != null &&
|
||||
player.GetModifierComponent()!.ActiveModifiers.Exists(x => x.ModifierId == id);
|
||||
player.GetModifierComponent()!.HasModifier(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user