Exemple #1
0
		public User(string userId, string password, Random random)
		{
			this.userId = userId;
            this.password = password;
            this.random = random;
            playerData = null;
            registeredCount = 0;
            updateRequestCount = 0;
		}
Exemple #2
0
		public async void Start()
		{
            // 가입
			{
				bool chk = await Network.SignUp(this.userId, this.password, this.userId + "_1");
				Console.WriteLine("SignIn : {0}", chk);
			}

            // 로그인
			{
				this.token = await Network.LogIn(userId, password);
				Console.WriteLine("Login Token : {0}", this.token);
			}

            // 로그인 확인
			{
				bool chk = await Network.IsLogIn(this.token);
				Console.WriteLine("Login Status : {0}", chk);
			}

            // 플레이어 데이터 받아오기
            {
                string data = await Network.GetPlayerData( this.token );

                if ( !string.IsNullOrEmpty(data) )
                {
                    // playerData = Json.JsonParser.Deserialize<ClientPlayerData>( data );
                    // playerData = JsonConvert.DeserializeObject<ClientPlayerData>( data );
                    playerData = JsonMapper.ToObject<ClientPlayerData>( data );
                
                    Console.WriteLine( "player data updated" );
                }
                else
                {
                    Console.WriteLine( "failed to get player data" );
                    return;
                }
            }

            Task.Delay( TestResult.REGISTER_DELAY ).GetAwaiter().OnCompleted( () => this.Register() );
		}
Exemple #3
0
        private async void UpdateResult()
        {
            // 결과 확인
            {
                string result = await Network.GetSimulationResult( this.token );
                ++updateRequestCount;

                if ( result.CompareTo("nothing") == 0 )
                {
                    Console.WriteLine( "not yet" );
                    Task.Delay( TestResult.SIMULATION_UPDATE_DELAY ).GetAwaiter().OnCompleted( () => this.UpdateResult() );
                    return;
                }
                else if ( result.CompareTo( "error") == 0 )
                {
                    return;
                }
                else
                {
                    Console.WriteLine( "game result updated" );
                }
            }

            // 플레이어 데이터 받아오기
            {
                string data = await Network.GetPlayerData( this.token );

                if ( !string.IsNullOrEmpty( data ) )
                {
                    // playerData = Json.JsonParser.Deserialize<ClientPlayerData>( data );
                    // playerData = JsonConvert.DeserializeObject<ClientPlayerData>( data );
                    playerData = JsonMapper.ToObject<ClientPlayerData>( data );
                
                    Console.WriteLine( "player data updated" );
                }
                else
                {
                    Console.WriteLine( "failed to get player data" );
                    return;
                }
            }

            // 레벨업
            {
                string result = "";
                do
                {
                    result = await Network.LevelUp( this.token );
                    if ( result.CompareTo( "level up" ) == 0 )
                        Console.WriteLine( "level up!" );
                    else
                        break;
                } while ( true );
            }

            // 스탯 상승
            {
                int totalStats = ( playerData.Stat[(int)StatType.Lev] - 1 ) * Config.BONUS_STAT_PER_LEVEL + Config.CHARACTER_BASE_STATS.Skip( 1 ).Take( 6 ).Sum( i => i );
                int curStats = playerData.Stat.Skip( 1 ).Take( 6 ).Sum( i => i );
                
                int bonusStat = totalStats - curStats;

                if ( bonusStat > 0 )
                {
                    ushort[] stats = new ushort[] { 0, 0, 0, 0, 0, 0, 0, 0 };
                    for ( int i = bonusStat; i > 0; --i )
                    {
                        ++stats[random.Next( (int)StatType.Str, (int)StatType.Mov )];
                    }

                    string result = await Network.IncreaseStats( this.token, stats );

                    if ( result.CompareTo( "failed" ) == 0 )
                        Console.WriteLine( "failed to increase player stats" );
                    else
                        Console.WriteLine( "increase stats" );
                }
            }

            if ( registeredCount < TestResult.MAX_SIMULATION_COUNT )
                Task.Delay( TestResult.REGISTER_DELAY ).GetAwaiter().OnCompleted( () => this.Register() );
            else
            {
                // finished
                // update test result
                
                // registered count
                Interlocked.Add(ref TestResult.registeredCount, registeredCount);
                
                // request count
                Interlocked.Add(ref TestResult.updateRequestCount, updateRequestCount);
                
                // user count
                int currentFinished = Interlocked.Add(ref TestResult.finishedUsers, 1);

                // all is finished
                if ( currentFinished == TestResult.totalUsers )
                    TestResult.PrintResult();
            }
        }