|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- using GamecraftModdingAPI.Tasks;
- using GamecraftModdingAPI.Engines;
- using Svelto.ECS;
-
- using RobocraftX.Character;
- using RobocraftX.Physics;
-
- namespace GamecraftRPC.Engines
- {
- class PlayerCountEngine : IApiEngine
- {
- public string Name => "GamecraftRPCPlayerCountGameEngine";
-
- public EntitiesDB entitiesDB { set; private get; }
-
- public bool isRemovable => false;
-
- private Discord.Discord discordRPC = null;
-
- private bool Ok = false;
-
- public void Dispose()
- {
- Ok = false;
- PresenceUtility.PlayerCount = 0;
- PresenceUtility.Activity.Party.Size.CurrentSize = 0;
- PresenceUtility.Activity.Party.Size.MaxSize = 0;
- PresenceUtility.Activity.Party.Id = "";
- }
-
- public void Ready()
- {
- Ok = true;
- Scheduler.Schedule(new Repeatable(updatePlayerCount, () => { return Ok; }, delay: 5f));
- PresenceUtility.Activity.Party.Size.CurrentSize = 1;
- PresenceUtility.Activity.Party.Size.MaxSize = PresenceUtility.LobbySize;
- PresenceUtility.Activity.Party.Id = "";//PresenceUtility.PartyId.ToString();
- }
-
- private void updatePlayerCount()
- {
- if (entitiesDB == null) return;
- uint count = 0;
- for (uint i = 0; i < CharacterExclusiveGroups.AllCharacters.Length; i++)
- {
- count += entitiesDB.Count<RigidBodyEntityStruct>(CharacterExclusiveGroups.AllCharacters[i]);
- }
- #if DEBUG
- GamecraftModdingAPI.Utility.Logging.MetaLog($"Player Count: {count}");
- #endif
- if ((int)count != PresenceUtility.PlayerCount && count > 0)
- {
- PresenceUtility.PlayerCount = (int)count;
- PresenceUtility.Activity.Party.Size.CurrentSize = (int)count;
- Plugin.SetDiscordActivity(discordRPC, debug: "PlayerCountEngine-updatePlayerCount");
- }
- }
-
- public PlayerCountEngine(Discord.Discord discordRPC)
- {
- this.discordRPC = discordRPC;
- }
- }
- }
|