コード例 #1
0
ファイル: GameState.cs プロジェクト: riQQ/HearthSim.Common
 public GameState(IGameDataProvider gameDataProvider, GameStateEvents gameStateEvents)
 {
     gameDataProvider.Reset();
     _gameDataProvider = gameDataProvider;
     _gameStateEvents  = gameStateEvents;
     Entities          = new Dictionary <int, Entity>();
     PlayerEntities    = new Dictionary <int, PlayerEntity>();
     _modifiers        = new List <IGameStateModifier>();
     _creationTags     = new Queue <IGameStateModifier>();
     _initialQueue     = new Queue <IGameStateModifier>();
     _powerLog         = new List <string>();
     CreatedAt         = DateTime.Now;
     Modified         += gameStateEvents.OnGameStateChanged;
     SecretsManager    = new SecretsManager(this, gameStateEvents);
     LocalPlayer       = new Player(this, true);
     OpposingPlayer    = new Player(this, false);
     GameTime          = new GameTime();
     Task.Run(async() =>
     {
         while (MatchInfo == null || ServerInfo == null)
         {
             await Task.Delay(500);
         }
     });
 }
コード例 #2
0
ファイル: GameState.cs プロジェクト: riQQ/HearthSim.Common
        private bool TryResolveEntityName(string name, out int entityId, bool retry = true)
        {
            entityId = -1;
            if (name == null)
            {
                return(false);
            }
            if (name == "GameEntity")
            {
                entityId = GameEntity.Id;
                return(true);
            }
            var matchInfo = MatchInfo;

            if (matchInfo == null)
            {
                return(false);
            }

            bool IsPlayer(MatchInfo.Player player)
            => player.BattleTag != null &&
            ($"{player.BattleTag.Name}#{player.BattleTag.Number}" == name ||
             player.BattleTag.Name == name) ||
            player.Name == name;

            if (IsPlayer(matchInfo.LocalPlayer))
            {
                entityId = PlayerEntities[matchInfo.LocalPlayer.Id].Id;
                return(true);
            }
            if (IsPlayer(matchInfo.OpposingPlayer))
            {
                entityId = PlayerEntities[matchInfo.OpposingPlayer.Id].Id;
                return(true);
            }

            if (retry)
            {
                Log.Debug($"Could not resolve entity \"{name}\", retrying");
                _matchInfo = null;
                _gameDataProvider.Reset();
                return(TryResolveEntityName(name, out entityId, false));
            }
            return(false);
        }