Random Events Manager

Presented by IRandomEventsManager interface, this system works with random events and provides such mechanisms like Bad Luck Protection and Good Luck Protection for them.

To use this system, inject IRandomEventsManager interface into your class, as shown below:

[Inject] private IRandomEventsManager randomEventsManager;

Parameters in inspector

possibleEvents – reference to scriptable object which contains a collection of possible random events.

Available methods

bool DoEventAttempt(string eventType)

This method attempts to fire random event with certain eventType. Returns true if attempt was successful and event has occurred.

Example:

if (randomEventsManager.DoEventAttempt("SuperRareItemDrop"))
{
    Debug.Log("Super rare item dropped!");
}

bool DoEventAttempt(RandomEventInfo eventInfo)

This method attempts to fire random event described in eventInfo. Returns true if attempt was successful and event has occurred.

Example:

if (randomEventsManager.DoEventAttempt(superRareEventInfo))
{
    Debug.Log("Super rare item dropped!");
}

void ResetEventChance(string eventType)

This method resets random event chance (cancels all modifiers applied by Bad Luck Protection and Good Luck Protection logics).

Example:

public void StartNewGame()
{
    randomEventsManager.ResetEventChance("SuperRareItemDrop");
}

float GetEventChance(string eventType)

This method returns current chance of eventType event occurance.

Example:

float eventChance = randomEventsManager.GetEventChance("SuperRareItemDrop");

Debug.Log($"Super rare drop chance: {eventChance}");

Last updated