Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Maticzpl committed Jun 30, 2021
1 parent ef1ad6e commit be36300
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions MoreHazards/MoreHazards/Doors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,18 @@ public IEnumerator<float> RandomDoorMalfunction()
continue;

//random door of the room the player is inside
var door = CollectionUtils<DoorVariant>.GetRandomElement((Map.FindParentRoom(player.GameObject).Doors));

door.NetworkTargetState = false;
Log.Debug("Door closed on player:"+player.Nickname);
try
{
var door = CollectionUtils<DoorVariant>.GetRandomElement((Map.FindParentRoom(player.GameObject).Doors));

door.NetworkTargetState = false;
Log.Debug("Door closed on player:" + player.Nickname);
}
catch (Exception e)
{
Log.Debug(e + " No doors found", MoreHazards.Instance.Config.Debug);
throw;
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions MoreHazards/MoreHazards/utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public static TValue GetRandomElement(List<TValue> collection)
public static TValue GetRandomElement(IEnumerable<TValue> enumerable)
{
var collection = (enumerable as IReadOnlyList<TValue>) ?? enumerable.ToArray();
if (collection.Count <= 0)
throw new Exception("Collection is empty");

int index = UnityEngine.Random.Range(0, collection.Count - 1);
return collection[index];
}
Expand Down

0 comments on commit be36300

Please sign in to comment.