public void TriggerSpecificEvent(int eventIndex, InGameEventType eventType, bool isFake = false, string adminName = null, bool announceEvent = true, string serializedEventParameters = null) { List <EventScriptBase> list; if (eventType == InGameEventType.Random) { list = GetRandomEventList(); } else { list = GetListFromEnum(eventType); } if (list == null) { Logger.LogError("Event List was null shouldn't happen unless new type wasn't added to switch", Category.Event); return; } if (eventIndex == 0) { StartRandomEvent(list, true, isFake, false, adminName, announceEvent); } else { var eventChosen = list[eventIndex - 1]; eventChosen.FakeEvent = isFake; eventChosen.AnnounceEvent = announceEvent; eventChosen.TriggerEvent(serializedEventParameters); AdminCommandsManager.LogAdminAction($"{adminName}: triggered the event: {eventChosen.EventName}. Is fake: {isFake}. Announce: {announceEvent}"); } }
public void StartRandomEvent(List <EventScriptBase> eventList, bool anEventMustHappen = false, bool isFake = false, bool serverTriggered = false, string adminName = null, bool announceEvent = true, int stackOverFlowProtection = 0) { if (eventList.Count == 0) { return; } foreach (var eventInList in eventList.Shuffle()) { //If there's not enough players try to trigger a different one if (eventInList.MinPlayersToTrigger > PlayerList.Instance.InGamePlayers.Count) { continue; } var chanceToHappen = UnityEngine.Random.Range(0f, 100f); if (chanceToHappen < eventInList.ChanceToHappen) { eventInList.FakeEvent = isFake; eventInList.AnnounceEvent = announceEvent; eventInList.TriggerEvent(); if (serverTriggered) { AdminCommandsManager.LogAdminAction($"A random event, {eventInList.EventName} has been triggered by the server. Is fake: {isFake}. Announce: {announceEvent}", "[Server]"); return; } AdminCommandsManager.LogAdminAction($"{adminName}: triggered a random event, {eventInList.EventName} was chosen. Is fake: {isFake}. Announce: {announceEvent}"); return; } } stackOverFlowProtection++; if (stackOverFlowProtection > 100) { AdminCommandsManager.LogAdminAction("A random event has failed to be triggered by the server due to overflow protection.", "[Server]"); return; } if (anEventMustHappen) { StartRandomEvent(eventList, true, isFake, serverTriggered, adminName, announceEvent, stackOverFlowProtection); } }