This repository has moved! Please check out the latest version at the new location https://git.exmods.org/NGnius/GameSDKcraft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

PlayerCountEngine.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GamecraftModdingAPI.Tasks;
  7. using GamecraftModdingAPI.Engines;
  8. using Svelto.ECS;
  9. using RobocraftX.Character;
  10. using RobocraftX.Physics;
  11. namespace GamecraftRPC.Engines
  12. {
  13. class PlayerCountEngine : IApiEngine
  14. {
  15. public string Name => "GamecraftRPCPlayerCountGameEngine";
  16. public EntitiesDB entitiesDB { set; private get; }
  17. public bool isRemovable => false;
  18. private Discord.Discord discordRPC = null;
  19. private bool Ok = false;
  20. public void Dispose()
  21. {
  22. Ok = false;
  23. PresenceUtility.PlayerCount = 0;
  24. PresenceUtility.Activity.Party.Size.CurrentSize = 0;
  25. PresenceUtility.Activity.Party.Size.MaxSize = 0;
  26. PresenceUtility.Activity.Party.Id = "";
  27. }
  28. public void Ready()
  29. {
  30. Ok = true;
  31. Scheduler.Schedule(new Repeatable(updatePlayerCount, () => { return Ok; }, delay: 5f));
  32. PresenceUtility.Activity.Party.Size.CurrentSize = 1;
  33. PresenceUtility.Activity.Party.Size.MaxSize = 1;
  34. PresenceUtility.Activity.Party.Id = "";//PresenceUtility.PartyId.ToString();
  35. }
  36. private void updatePlayerCount()
  37. {
  38. if (entitiesDB == null) return;
  39. uint count = 0;
  40. for (uint i = 0; i < CharacterExclusiveGroups.AllCharacters.count; i++)
  41. {
  42. count += entitiesDB.Count<RigidBodyEntityStruct>(CharacterExclusiveGroups.AllCharacters[i]);
  43. }
  44. if ((int)count != PresenceUtility.PlayerCount && count > 0)
  45. {
  46. PresenceUtility.PlayerCount = (int)count;
  47. PresenceUtility.Activity.Party.Size.CurrentSize = (int)count;
  48. PresenceUtility.Activity.Party.Size.MaxSize = (int)count;
  49. Plugin.SetDiscordActivity(discordRPC, debug: "PlayerCountEngine-updatePlayerCount");
  50. #if DEBUG
  51. GamecraftModdingAPI.Utility.Logging.MetaLog($"Player Count: {count}");
  52. #endif
  53. }
  54. }
  55. public PlayerCountEngine(Discord.Discord discordRPC)
  56. {
  57. this.discordRPC = discordRPC;
  58. }
  59. }
  60. }