public async void AvailableCharacterSelected()
        {
            var buildingMetaId = "Test_AvailableCharacterSelected";
            var classMetaId    = "Test_AvailableCharacterSelected";
            var playerId       = "Test_AvailableCharacterSelected";
            var characterIndex = 0;

            // Create test class meta if it doesn't exist.
            var classMeta = await new ClassMeta(classMetaId).LoadAsync();

            if (classMeta == null)
            {
                classMeta             = new ClassMeta(classMetaId);
                classMeta.Requirement = new Requirement()
                {
                    BuildingMetaIds = new List <string> {
                        buildingMetaId
                    }
                };
                await classMeta.InsertAsync();
            }

            // Create test player, character and required building.
            var building = new Building(buildingMetaId);

            building.IsConstructed = true;
            var character = new Character(classMetaId);
            var player    = await Helpers.CreateTestPlayer(playerId, building : building, character : character);

            // Auth player.
            var sessionToken = Helpers.GetSessionToken(playerId);

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{playerId}',
                'SessionToken':'{sessionToken}',
                'CharacterIndex':{characterIndex}
            }}");

            // Execute controller.
            var controller    = new SelectCharacterController();
            var responseToken = await controller.HandleHttpRequestAsync(data);

            // Assert controller response status is OK.
            Assert.Equal(responseToken["Status"], JStatus.Ok.JToken["Status"]);

            // Make sure char is selected for the first time (req-free).
            player = await player.LoadAsync();

            Assert.True(player.SelectedCharacterIndex == characterIndex);

            // Make sure char is selected for the second time (with req checked).
            responseToken = await controller.HandleHttpRequestAsync(data);

            Assert.Equal(responseToken["Status"], JStatus.Ok.JToken["Status"]);
        }
        public async void LevelIncreased()
        {
            var classMetaId = "Test_LevelIncreased2";
            var playerId    = "Test_LevelIncreased2";
            var expToAdd    = 700;
            var charIndex   = 0;

            // Create test class meta if it doesn't exist.
            var classMeta = await new ClassMeta(classMetaId).LoadAsync();

            if (classMeta == null)
            {
                classMeta = new ClassMeta(classMetaId);
                classMeta.ExpToLevelUp = new List <int>()
                {
                    0, 100, 200, 300, 500
                };
                await classMeta.InsertAsync();
            }

            // Create test player.
            var player = await Helpers.CreateTestPlayer(playerId);

            player.Characters.Add(new Character(classMetaId));
            await player.ReplaceAsync();

            // Auth player.
            var sessionToken = Helpers.GetSessionToken(playerId);

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{playerId}',
                {Helpers.JsonServerCredentials},
                'Experience':'{expToAdd}',
                'CharacterIndex':'{charIndex}'
            }}");

            // Execute controller.
            var controller    = new AddExperienceController();
            var responseToken = await controller.HandleHttpRequestAsync(data);

            // Assert controller response status is OK.
            Assert.Equal(responseToken["Status"], JStatus.Ok.JToken["Status"]);

            // Assert new level is set in response.
            Assert.Equal(responseToken["NewLevel"], 3);

            // Make sure level is added to character.
            player = await player.LoadAsync();

            Assert.Equal(player.Characters[0].Level, 3);

            // Make sure talent points are added to character.
            Assert.Equal(player.Characters[0].TalentPoints, 3);
        }
示例#3
0
        public async void PlayerCreatedWithDefaultParams()
        {
            var playerId       = "Test_PlayerCreatedWithDefaultParams";
            var itemMetaId     = "Test_PlayerCreatedWithDefaultParams";
            var classMetaId    = "Test_PlayerCreatedWithDefaultParams";
            var playerPassword = "******";

            // Create test class meta if it doesn't exist.
            var classMeta = await new ClassMeta(classMetaId).LoadAsync();

            if (classMeta == null)
            {
                classMeta = new ClassMeta(classMetaId);
                classMeta.DefaultItems = new List <string> {
                    itemMetaId
                };
                classMeta.IsInitiallyAvailable = true;
                await classMeta.InsertAsync();
            }

            // Delete existing test player.
            var existingPlayer = await new Player(playerId).LoadAsync();

            if (existingPlayer != null)
            {
                await existingPlayer.DeleteAsync();
            }

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{playerId}',
                'Password':'******'
            }}");

            // Execute controller.
            var createPlayerController = new CreatePlayerController();
            var responseToken          = await createPlayerController.HandleHttpRequestAsync(data);

            // Assert controller response status is OK.
            Assert.Equal(responseToken, JStatus.Ok);

            // Load new player.
            var createdPlayer = await new Player(playerId).LoadAsync();

            // Make sure default character is added.
            Assert.True(createdPlayer.Characters.Exists(character => character.ClassMetaId == classMetaId));

            // Make sure default item is added.
            Assert.True(createdPlayer.HasItemOfMeta(itemMetaId));
        }
示例#4
0
        public async void AvailableItemEquipped()
        {
            var itemMetaId  = "Test_AvailableItemEquipped";
            var itemSlot    = "Test_AvailableItemEquipped";
            var classMetaId = "Test_AvailableItemEquipped";
            var playerId    = "Test_AvailableItemEquipped";

            // Create test class meta if it doesn't exist.
            var classMeta = await new ClassMeta(classMetaId).LoadAsync();

            if (classMeta == null)
            {
                classMeta = new ClassMeta(classMetaId);
                await classMeta.InsertAsync();
            }

            // Create test item meta if it doesn't exist.
            var itemMeta = await new ItemMeta(itemMetaId).LoadAsync();

            if (itemMeta == null)
            {
                itemMeta               = new ItemMeta(itemMetaId);
                itemMeta.ClassMetaId   = classMetaId;
                itemMeta.EquipmentSlot = itemSlot;
                await itemMeta.InsertAsync();
            }

            // Create test player with a character and item.
            var player = await Helpers.CreateTestPlayer(playerId);

            var character = new Character(classMetaId);

            player.Characters.Add(character);
            var item = new Item(itemMetaId);

            player.AddItem(item);
            await player.ReplaceAsync();

            // Auth player.
            var sessionToken = Helpers.GetSessionToken(playerId);

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{playerId}',
                'SessionToken':'{sessionToken}',
                'CharacterId':'{character.Id}',
                'ItemId':'{item.Id}'
            }}");

            // Execute controller.
            var controller    = new EquipItemController();
            var responseToken = await controller.HandleHttpRequestAsync(data);

            // Assert controller response status is OK.
            Assert.Equal(responseToken["Status"], JStatus.Ok.JToken["Status"]);

            // Make sure item is equiped.
            player = await player.LoadAsync();

            Assert.True(player.GetItemById(item.Id).IsOwnedByCharacter);
            Assert.True(player.GetItemById(item.Id).OwningCharacterId == character.Id);
        }
示例#5
0
        public async void TalentNotLearnedWhenNotEnoughPoints()
        {
            string testId         = $"Test_TalentNotLearnedWhenNotEnoughPoints";
            var    talentsToLearn = new List <string> {
                testId
            };

            // Create test ability meta if it doesn't exist.
            var abilityMeta = await new AbilityMeta(testId).LoadAsync();

            if (abilityMeta == null)
            {
                abilityMeta = new AbilityMeta(testId);
                await abilityMeta.InsertAsync();
            }

            // Create test class meta if it doesn't exist.
            var classMeta = await new ClassMeta(testId).LoadAsync();

            if (classMeta == null)
            {
                classMeta = new ClassMeta(testId);
                classMeta.Abilities.Add(abilityMeta.Id);
                await classMeta.InsertAsync();
            }

            // Create test talent meta if it doesn't exist.
            await CreateTestTalentMetaOfTier(testId, testId, 1);

            // Create test player with zero talent points.
            var player = await Helpers.CreateTestPlayer(testId);

            var character = new Character(testId);

            character.TalentPoints = 0;
            player.Characters.Add(character);
            await player.ReplaceAsync();

            // Auth player.
            var sessionToken = Helpers.GetSessionToken(testId);

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{testId}',
                'SessionToken':'{sessionToken}',
                'TalentMetaIds':'{JsonConvert.SerializeObject(talentsToLearn)}',
                'CharacterId':'{character.Id}'
            }}");

            // Execute controller.
            var controller    = new LearnTalentsController();
            var responseToken = await controller.HandleHttpRequestAsync(data);

            // Assert controller response status is RequirementNotFulfilled.
            Assert.Equal(responseToken["Status"], JStatus.RequirementNotFulfilled.JToken["Status"]);

            // Make sure talent is not learned.
            player = await player.LoadAsync();

            Assert.False(player.GetCharacterById(character.Id).IsTalentLearned(testId));
        }
示例#6
0
        private async Task PerformAccessibleTalentLearnedTestForTier(int tier)
        {
            string testId         = $"Test_Accessible{tier}TierTalentLearned";
            var    talentsToLearn = new List <string> {
                testId
            };

            // Create test ability meta if it doesn't exist.
            var abilityMeta = await new AbilityMeta(testId).LoadAsync();

            if (abilityMeta == null)
            {
                abilityMeta = new AbilityMeta(testId);
                await abilityMeta.InsertAsync();
            }

            // Create test class meta if it doesn't exist.
            var classMeta = await new ClassMeta(testId).LoadAsync();

            if (classMeta == null)
            {
                classMeta = new ClassMeta(testId);
                classMeta.Abilities.Add(abilityMeta.Id);
                await classMeta.InsertAsync();
            }

            // Create test talent meta if it doesn't exist.
            await CreateTestTalentMetaOfTier(testId, testId, tier);

            // Create test player.
            var player = await Helpers.CreateTestPlayer(testId);

            var character = new Character(testId);

            character.TalentPoints = 1;
            // Create prereq metas for and add talents from previous tiers.
            if (tier > 0)
            {
                for (int i = 1; i < tier; i++)
                {
                    var ic = i;
                    var prereqTalentMetaId = testId + ic;
                    await CreateTestTalentMetaOfTier(prereqTalentMetaId, testId, ic);

                    character.LearnedTalentMetaIds.Add(prereqTalentMetaId);
                }
            }
            else if (tier < 0)
            {
                for (int i = -1; i > tier; i--)
                {
                    var ic = i;
                    var prereqTalentMetaId = testId + ic;
                    await CreateTestTalentMetaOfTier(prereqTalentMetaId, testId, ic);

                    character.LearnedTalentMetaIds.Add(prereqTalentMetaId);
                }
            }
            player.Characters.Add(character);
            await player.ReplaceAsync();

            // Auth player.
            var sessionToken = Helpers.GetSessionToken(testId);

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{testId}',
                'SessionToken':'{sessionToken}',
                'TalentMetaIds':'{JsonConvert.SerializeObject(talentsToLearn)}',
                'CharacterId':'{character.Id}'
            }}");

            // Execute controller.
            var controller    = new LearnTalentsController();
            var responseToken = await controller.HandleHttpRequestAsync(data);

            // Assert controller response status is OK.
            Assert.Equal(responseToken["Status"], JStatus.Ok.JToken["Status"]);

            // Make sure talent is learned.
            player = await player.LoadAsync();

            Assert.True(player.GetCharacterById(character.Id).IsTalentLearned(testId));
        }