Example #1
0
        private void TriggerIfDifferent(GameStatus oldStatus, GameStatus newStatus)
        {
            foreach (PropertyInfo propA in oldStatus.GetType().GetProperties().Where(x => x.PropertyType == typeof(bool)))
            {
                PropertyInfo propB = newStatus.GetType().GetProperty(propA.Name);

                dynamic A = (dynamic)propA.GetValue(oldStatus);
                dynamic B = (dynamic)propB.GetValue(newStatus);

                if (A != B)
                {
                    try
                    {
                        StatusEvent e = new StatusEvent("Status." + propA.Name, B);

                        api.Logger.LogDebugEvent($"Processing status event '{propA.Name}' ({B}).", e);

                        api.Events.InvokeAllEvent(new StatusEvent("Status." + propA.Name, B));

                        try { api.Events.GetType().GetMethod("InvokeStatus" + propA.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).Invoke(api.Events, new object[] { e }); }
                        catch (Exception ex) { api.Logger.LogError($"Could not invoke status event '{propA.Name}', it might not have been added yet.", ex); }
                    }
                    catch (Exception ex) { api.Logger.LogError("Could not do status.", ex); }
                }
            }
        }
Example #2
0
 private void TriggerIfDifferent(GameStatus oldStatus, GameStatus newStatus)
 {
     foreach (PropertyInfo propA in oldStatus.GetType().GetProperties().Where(x => x.PropertyType == typeof(bool)))
     {
         PropertyInfo propB = newStatus.GetType().GetProperty(propA.Name);
         dynamic      A     = propA.GetValue(oldStatus);
         dynamic      B     = propB.GetValue(newStatus);
         if (A == B)
         {
             continue;
         }
         try
         {
             StatusEvent e = new StatusEvent("Status." + propA.Name, B);
             api.Logger.Log(Severity.Debug, $"Setting status '{propA.Name}' to {Convert.ToString(B).ToLower()}.", e);
             api.Events.InvokeAllEvent(new StatusEvent("Status." + propA.Name, B));
             try { api.Events.GetType().GetMethod("InvokeStatus" + propA.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)?.Invoke(api.Events, new object[] { e }); }
             catch (Exception ex) { api.Logger.Log(Severity.Debug, $"Could not invoke status event '{propA.Name}'.", ex); }
         }
         catch (Exception ex) { api.Logger.Log(Severity.Error, "Could not do status.", ex); }
     }
 }