Skip to content

Commit 11c5368

Browse files
committed
severely improved debug logs and minor tweaks
1 parent ca08219 commit 11c5368

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

Common Utilities/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public class Config : IConfig
138138
};
139139

140140
[Description("The list of custom 914 recipies. Original is the item being upgraded, New is the item to upgrade to, and Chance is the percent chance of the upgrade happening. You can specify multiple upgrade choices for the same item. For custom items use the item's name.")]
141+
// This should be named Scp914ItemChanGes instead of ChanCes (capitalized to show the difference), consider changing at some point (breaking change)
141142
public Dictionary<Scp914KnobSetting, List<ItemUpgradeChance>> Scp914ItemChances { get; set; } = new()
142143
{
143144
{

Common Utilities/EventHandlers/MapHandlers.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@ public class MapHandlers
2222

2323
public void OnUpgradingPickup(UpgradingPickupEventArgs ev)
2424
{
25-
if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List<ItemUpgradeChance> outItemUpgradeChances))
25+
if (config.Scp914ItemChances != null && config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List<ItemUpgradeChance> outItemUpgradeChances))
2626
{
27+
Log.Debug($"{nameof(OnUpgradingPickup)}: Found valid config entries, filtering...");
28+
2729
List<ItemUpgradeChance> itemUpgradeChances = outItemUpgradeChances
2830
.Where(x =>
2931
x.Original == ev.Pickup.Type.ToString()
30-
|| (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item!.Name == x.Original))
32+
|| (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item.Name == x.Original))
3133
.ToList();
3234

35+
Log.Debug($"{nameof(OnUpgradingPickup)}: Fnished filtering, found {itemUpgradeChances.Count} match(es).");
36+
3337
double rolledChance = Utils.RollChance(itemUpgradeChances);
3438

3539
foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChances)
3640
{
37-
Log.Debug($"{nameof(OnUpgradingPickup)}: SCP-914 is trying to upgrade a {ev.Pickup.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})");
41+
Log.Debug($"{nameof(OnUpgradingPickup)}: SCP-914 is trying to upgrade a {ev.Pickup.Type}. {sourceItem} -> {destinationItem} (x{count}); {rolledChance} <= {chance} ({rolledChance <= chance})");
3842

3943
if (rolledChance <= chance)
4044
{
@@ -66,19 +70,23 @@ public void OnUpgradingPickup(UpgradingPickupEventArgs ev)
6670

6771
public void OnUpgradingInventoryItem(UpgradingInventoryItemEventArgs ev)
6872
{
69-
if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List<ItemUpgradeChance> outItemUpgradeChances))
73+
if (config.Scp914ItemChances != null && config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List<ItemUpgradeChance> outItemUpgradeChances))
7074
{
75+
Log.Debug($"{nameof(OnUpgradingInventoryItem)}: Found valid config entries, filtering...");
76+
7177
List<ItemUpgradeChance> itemUpgradeChances = outItemUpgradeChances
7278
.Where(x =>
7379
x.Original == ev.Item.Type.ToString()
74-
|| (CustomItem.TryGet(ev.Item, out CustomItem item) && item!.Name == x.Original))
80+
|| (CustomItem.TryGet(ev.Item, out CustomItem item) && item.Name == x.Original))
7581
.ToList();
7682

83+
Log.Debug($"{nameof(OnUpgradingInventoryItem)}: Finished filtering, found {itemUpgradeChances.Count} match(es).");
84+
7785
double rolledChance = Utils.RollChance(itemUpgradeChances);
7886

7987
foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChances)
8088
{
81-
Log.Debug($"{nameof(OnUpgradingInventoryItem)}: {ev.Player.Nickname} is attempting to upgrade hit {ev.Item.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})");
89+
Log.Debug($"{nameof(OnUpgradingInventoryItem)}: {ev.Player.Nickname} is attempting to upgrade an inventory item(s) {ev.Item.Type}. {sourceItem} -> {destinationItem} (x{count}); {rolledChance} <= {chance} ({rolledChance <= chance})");
8290

8391
if (rolledChance <= chance)
8492
{
@@ -110,20 +118,20 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev)
110118
{
111119
if (config.Scp914ClassChanges != null && config.Scp914ClassChanges.TryGetValue(ev.KnobSetting, out var outPlayerUpgradeChances))
112120
{
113-
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914ClassChanges)} found valid config entries, filtering....");
121+
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914ClassChanges)}: Found valid config entries, filtering...");
114122
List<PlayerUpgradeChance> playerUpgradeChances = outPlayerUpgradeChances
115123
.Where(x =>
116124
x.Original == ev.Player.Role.Type.ToString()
117125
|| (CustomRole.TryGet(ev.Player, out IReadOnlyCollection<CustomRole> customRoles) && customRoles.Select(r => r.Name).Contains(x.Original)))
118126
.ToList();
119127

120-
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914ClassChanges)} filtered entries. Found {playerUpgradeChances.Count} matches.");
128+
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914ClassChanges)}: Finished filtering, found {playerUpgradeChances.Count} match(es).");
121129

122130
double rolledChance = Utils.RollChance(playerUpgradeChances);
123131

124132
foreach ((string sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChances)
125133
{
126-
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914ClassChanges)} {ev.Player.Nickname} ({ev.Player.Role}) is trying to upgrade his class. sourceRole: {sourceRole}; destinationRole: {destinationRole}; chance: {chance}; rolledChance: {rolledChance}; keepInventory: {keepHealth}; keepHealth: {keepHealth};");
134+
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914ClassChanges)}: {ev.Player.Nickname} ({ev.Player.Role.Type}) is trying to upgrade his class. {sourceRole} -> {destinationRole}; keepInventory: {keepHealth}; keepHealth: {keepHealth}; {rolledChance} <= {chance} ({rolledChance <= chance})");
127135
if (rolledChance <= chance)
128136
{
129137
float originalHealth = ev.Player.Health;
@@ -177,15 +185,15 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev)
177185

178186
if (config.Scp914EffectChances != null && config.Scp914EffectChances.ContainsKey(ev.KnobSetting) && (ev.Player.Role.Side != Side.Scp || !config.ScpsImmuneTo914Effects))
179187
{
180-
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914EffectChances)} found valid config entries.");
188+
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914EffectChances)}: Found valid config entries.");
181189

182190
IEnumerable<Scp914EffectChance> scp914EffectChances = config.Scp914EffectChances[ev.KnobSetting];
183191

184192
double rolledChance = Utils.RollChance(scp914EffectChances);
185193

186194
foreach ((EffectType effect, double chance, float duration) in scp914EffectChances)
187195
{
188-
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914EffectChances)} {ev.Player.Nickname} is trying to gain an effect through SCP-914. effect: {effect}; chance: {chance}; rolledChance: {rolledChance};");
196+
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914EffectChances)}: {ev.Player.Nickname} is trying to gain an effect through SCP-914 {effect} ({duration}s); {rolledChance} <= {chance} ({rolledChance <= chance})");
189197

190198
if (rolledChance <= chance)
191199
{
@@ -201,15 +209,15 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev)
201209

202210
if (config.Scp914TeleportChances != null && config.Scp914TeleportChances.ContainsKey(ev.KnobSetting))
203211
{
204-
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914TeleportChances)} found valid config entries.");
212+
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914TeleportChances)}: Found valid config entries.");
205213

206214
IEnumerable<Scp914TeleportChance> scp914TeleportChances = config.Scp914TeleportChances[ev.KnobSetting];
207215

208216
double rolledChance = Utils.RollChance(scp914TeleportChances);
209217

210218
foreach ((RoomType roomType, List<RoomType> ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in config.Scp914TeleportChances[ev.KnobSetting])
211219
{
212-
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914TeleportChances)} {ev.Player.Nickname} is trying to be teleported by 914. zone: {zone}; room: {roomType}; offset: {offset}; chance: {chance}; rolledChance: {rolledChance};");
220+
Log.Debug($"{nameof(OnUpgradingPlayer)} : {nameof(config.Scp914TeleportChances)}: {ev.Player.Nickname} is trying to be teleported by 914. {roomType} + {offset}; {zone} + {ignoredRooms.Count} ignored rooms; damage: {damage}; {rolledChance} <= {chance} ({rolledChance <= chance})");
213221

214222
if (rolledChance <= chance)
215223
{

Common Utilities/EventHandlers/PlayerHandlers.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Collections.Specialized;
2+
13
namespace Common_Utilities.EventHandlers;
24

35
#pragma warning disable IDE0018
@@ -36,6 +38,7 @@ public void OnChangingRole(ChangingRoleEventArgs ev)
3638
}
3739

3840
// no clue why this works while in ChangingRole instead of spawned but if it ain't broke don't fix it
41+
// answering my previous question, (obviously) it works because we're setting ev.Items which are yet to be given to the player
3942
if (config.StartingInventories.ContainsKey(ev.NewRole) && !ev.ShouldPreserveInventory)
4043
{
4144
if (ev.Items == null)
@@ -147,10 +150,13 @@ public List<ItemType> GetStartingInventory(RoleTypeId role, Player player = null
147150
{
148151
List<ItemType> items = new();
149152

153+
Log.Debug($"{nameof(GetStartingInventory)} Iterating through slots...");
150154
// iterate through slots
151155
for (int i = 0; i < config.StartingInventories[role].UsedSlots; i++)
152156
{
153-
#pragma warning disable SA1119
157+
Log.Debug($"\n{nameof(GetStartingInventory)} Iterating slot {i + 1}");
158+
Log.Debug($"{nameof(GetStartingInventory)} Checking groups...");
159+
154160
// item chances for that slot
155161
List<ItemChance> itemChances = config.StartingInventories[role][i]
156162
.Where(x =>
@@ -159,15 +165,14 @@ public List<ItemType> GetStartingInventory(RoleTypeId role, Player player = null
159165
|| x.Group == "none"
160166
|| (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group))
161167
.ToList();
162-
#pragma warning restore SA1119
163168

164-
double rolledChance = Utils.RollChance(itemChances);
169+
Log.Debug($"{nameof(GetStartingInventory)} Finished checking groups, found {itemChances.Count} valid itemChances.");
165170

166-
Log.Debug($"[StartItems] RolledChance ({rolledChance})/{itemChances.Sum(val => val.Chance)}");
171+
double rolledChance = Utils.RollChance(itemChances);
167172

168173
foreach ((string item, double chance) in itemChances)
169174
{
170-
Log.Debug($"[StartItems] Probability ({rolledChance})/{chance}");
175+
Log.Debug($"{nameof(GetStartingInventory)} Trying to assign to slot {i + 1} for {role}; item: {item}; {rolledChance} <= {chance} ({rolledChance <= chance}).");
171176

172177
if (rolledChance <= chance)
173178
{
@@ -182,18 +187,20 @@ public List<ItemType> GetStartingInventory(RoleTypeId role, Player player = null
182187
if (player != null)
183188
customItem!.Give(player);
184189
else
185-
Log.Warn($"{nameof(GetStartingInventory)}: Tried to give {customItem!.Name} to a null player.");
190+
Log.Warn($"{nameof(GetStartingInventory)} Tried to give {customItem!.Name} to a null player.");
186191

187192
break;
188193
}
189194

190-
Log.Warn($"{nameof(GetStartingInventory)}: {item} is not a valid ItemType or CustomItem! It is being skipped in inventory decisions.");
195+
Log.Warn($"{nameof(GetStartingInventory)} Skipping {item} as it is not a valid ItemType or CustomItem!");
191196
}
192197

193198
if (config.AdditiveProbabilities)
194199
rolledChance -= chance;
195200
}
196201
}
202+
203+
Log.Debug($"{nameof(GetStartingInventory)} Finished iterating slots.");
197204

198205
return items;
199206
}

Common Utilities/Utils.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
public static class Utils
88
{
9-
public static double RollChance(IEnumerable<IChanceObject> scp914EffectChances)
9+
public static int RollChance(IEnumerable<IChanceObject> scp914EffectChances)
1010
{
11-
double rolledChance;
11+
double rolledChance = Plugin.Random.NextDouble();
1212

1313
if (Plugin.Instance.Config.AdditiveProbabilities)
14-
rolledChance = Plugin.Random.NextDouble() * scp914EffectChances.Sum(x => x.Chance);
14+
rolledChance *= scp914EffectChances.Sum(x => x.Chance);
1515
else
16-
rolledChance = Plugin.Random.NextDouble() * 100;
16+
rolledChance *= 100;
1717

18-
return rolledChance;
18+
return (int)rolledChance;
1919
}
2020
}

0 commit comments

Comments
 (0)