|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- using GamecraftModdingAPI.Tasks;
- using GamecraftModdingAPI.Utility;
- 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; }
-
- 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: 2f));
- 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]);
- }
- GamecraftModdingAPI.Utility.Logging.MetaLog($"Player Count: {count}");
- 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;
- }
- }
- }
|