public async Task ReturnCorrectViewModel_WhenCalled() { // Arrange Mock <IChampionService> championServiceMock = new Mock <IChampionService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); string validId = string.Empty; Champion validChampionResult = new Champion(); championServiceMock.Setup(mock => mock.FindAsync(validId)) .Returns(Task.FromResult(validChampionResult)); ChampionController SUT = new ChampionController( championServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act var result = await SUT.Details(validId) as ViewResult; // Assert Assert.IsInstanceOfType(result.Model, typeof(ChampionDetailsViewModel)); }
public async Task CallFindAsync_WhenCalled() { // Arrange Mock <IChampionService> championServiceMock = new Mock <IChampionService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); string validId = string.Empty; Champion validChampionResult = new Champion(); championServiceMock.Setup(mock => mock.FindAsync(validId)) .Returns(Task.FromResult(validChampionResult)); ChampionController SUT = new ChampionController( championServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act await SUT.Details(validId); // Assert championServiceMock.Verify(mock => mock.FindAsync(validId), Times.Once); }
public void ChampionSpawn() { GameObject newChampion = Instantiate(champion, spawnPoint.position, Quaternion.Euler(spawnPoint.transform.forward)) as GameObject; //Debug.Log(Quaternion.Euler(spawnPoint.transform.forward)); newChampion.transform.SetParent(championsParent.transform); if (isWhite) // for white champions { newChampion.GetComponent <SpriteRenderer>().color = Color.white; newChampion.GetComponent <CharactersController>().isWhite = true; ChampionController setNew = newChampion.GetComponent <ChampionController>(); setNew.healthBar = Instantiate(championHealthBar, newChampion.transform); setNew.home = this; CameraController main = mainCamera.GetComponent <CameraController>(); main.champion = newChampion; } else // for black champions { Vector3 tempScale = new Vector3(-newChampion.transform.localScale.x, newChampion.transform.localScale.y, newChampion.transform.localScale.z); newChampion.transform.localScale = tempScale; newChampion.GetComponent <SpriteRenderer>().color = Color.black; newChampion.GetComponent <CharactersController>().isWhite = false; ChampionController setNew = newChampion.GetComponent <ChampionController>(); setNew.healthBar = Instantiate(championHealthBar, newChampion.transform); } }
public async Task ThrowApplicationException_WhenChampionsIsNull() { // Arrange Mock <IChampionService> championServiceMock = new Mock <IChampionService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; int validPageSize = 10; IPagedList <Champion> champions = null; championServiceMock.Setup(mock => mock.FilterChampionsAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(champions)); ChampionController SUT = new ChampionController( championServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act & Assert await Assert.ThrowsExceptionAsync <ApplicationException>(() => SUT.Download(validSortOrder, validFilter, validPageNumber, validPageSize)); }
public async Task CallFilterChampionsAsync_WhenCalled() { // Arrange Mock <IChampionService> championServiceMock = new Mock <IChampionService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; int validPageSize = 10; IPagedList <Champion> champions = new PagedList <Champion>(new List <Champion>().AsQueryable(), validPageNumber, validPageSize); championServiceMock.Setup(mock => mock.FilterChampionsAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(champions)); ChampionController SUT = new ChampionController( championServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act await SUT.Filter(validSortOrder, validFilter, validPageNumber, validPageSize); // Assert championServiceMock .Verify(mock => mock.FilterChampionsAsync(validSortOrder, validFilter, validPageNumber, validPageSize), Times.Once); }
/// <summary> /// Returns true if all the champions are dead /// </summary> /// <returns></returns> private bool IsAllChampionDead() { int championCount = 0; int championDead = 0; //start own champion combat for (int x = 0; x < Map.hexMapSizeX; x++) { for (int z = 0; z < Map.hexMapSizeZ / 2; z++) { //there is a champion if (gridChampionsArray[x, z] != null) { //get character ChampionController championController = gridChampionsArray[x, z].GetComponent <ChampionController>(); championCount++; if (championController.isDead) { championDead++; } } } } if (championDead == championCount) { return(true); } return(false); }
public async Task ReturnCorrectViewModel_WhenCalled() { // Arrange Mock <IChampionService> championServiceMock = new Mock <IChampionService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); IMemoryCache memoryCacheMock = new MemoryCache(new MemoryCacheOptions()); string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; int validPageSize = 10; IPagedList <Champion> champions = new PagedList <Champion>(new List <Champion>().AsQueryable(), validPageNumber, validPageSize); championServiceMock.Setup(mock => mock.FilterChampionsAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(champions)); ChampionController SUT = new ChampionController( championServiceMock.Object, pDFServiceMock.Object, memoryCacheMock); // Act var result = await SUT.Index() as ViewResult; // Assert Assert.IsInstanceOfType(result.Model, typeof(ChampionIndexViewModel)); }
/// <summary> /// Called when a stage is finished /// </summary> /// <param name="stage"></param> public void OnGameStageComplate(GameStage stage) { if (stage == GameStage.Preparation) { //start champion combat for (int x = 0; x < Map.hexMapSizeX; x++) { for (int z = 0; z < Map.hexMapSizeZ / 2; z++) { //there is a champion if (gridChampionsArray[x, z] != null) { //get character ChampionController championController = gridChampionsArray[x, z].GetComponent <ChampionController>(); //start combat championController.OnCombatStart(); } } } } if (stage == GameStage.Combat) { //totall damage player takes int damage = 0; //iterate champions //start champion combat for (int x = 0; x < Map.hexMapSizeX; x++) { for (int z = 0; z < Map.hexMapSizeZ / 2; z++) { //there is a champion if (gridChampionsArray[x, z] != null) { //get character ChampionController championController = gridChampionsArray[x, z].GetComponent <ChampionController>(); //calculate player damage for every champion if (championController.currentHealth > 0) { damage += championDamage; } } } } //player takes damage gamePlayController.TakeDamage(damage); ResetChampions(); AddRandomChampion(); // AddRandomChampion(); } }
void Start() { GameObject theChamp = GameObject.Find("Champion"); ChampionController champController = theChamp.GetComponent <ChampionController>(); doubleAgent = champController.agent; animator = GetComponent <Animator>(); }
/// Start is called before the first frame update void Start() { //get character model characterModel = this.transform.Find("character").gameObject; //get animator animator = characterModel.GetComponent <Animator>(); championController = this.transform.GetComponent <ChampionController>(); }
public async Task CallFilterChampionsAsync_WhenCalled() { // Arrange Mock <IChampionService> championServiceMock = new Mock <IChampionService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); IList <string> validFileParameters = typeof(ChampionDownloadViewModel).GetProperties().Select(p => p.Name.ToString()).ToList(); string validCollection = "champions"; string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; int validPageSize = 10; string validFileName = string.Empty; byte[] validFileBytes = new byte[0]; IPagedList <Champion> champions = new PagedList <Champion>( new List <Champion>().AsQueryable(), validPageNumber, validPageSize); IPagedList <ChampionDownloadViewModel> championDownloadViewModels = new PagedList <ChampionDownloadViewModel>( new List <ChampionDownloadViewModel>().AsQueryable(), validPageNumber, validPageSize); championServiceMock.Setup(mock => mock.FilterChampionsAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(champions)); pDFServiceMock .Setup(mock => mock.CreatePDF(championDownloadViewModels, validFileParameters, validCollection)) .Returns(validFileName); pDFServiceMock .Setup(mock => mock.GetFileBytesAsync(validFileName)) .Returns(Task.FromResult(validFileBytes)); pDFServiceMock .Setup(mock => mock.DeleteFile(validFileName)); ChampionController SUT = new ChampionController( championServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act await SUT.Download(validSortOrder, validFilter, validPageNumber, validPageSize); // Assert championServiceMock.Verify(mock => mock.FilterChampionsAsync(validSortOrder, validFilter, validPageNumber, validPageSize), Times.Once); }
/// <summary> /// 商店购买后地图上生成战士 /// </summary> public bool BuyChampionFromShop(Champion champion) { //获取位置 int emptyIndex = -1; for (int i = 0; i < ownChampionInventoryArray.Length; i++) { if (ownChampionInventoryArray[i] == null) { emptyIndex = i; break; } } //空间不足 if (emptyIndex == -1) { return(false); } //金币不足 if (currentGold < champion.cost) { return(false); } //实例化 GameObject championPrefab = PhotonNetwork.Instantiate(champion.prefab.name, map.ownInventoryGridPositions[emptyIndex], Quaternion.Euler(0, cameraBehavior.GetCameraPoint(playerID, PointType.start).eulerAngles.y, 0)); ChampionController championController = championPrefab.GetComponent <ChampionController>(); championController.Init(champion); championController.photonView.RPC("setDisable", RpcTarget.All); //设置物体的网格属性 championController.SetGridPosition(Map.GRIDTYPE_OWN_INVENTORY, emptyIndex, -1); //设置世界坐标 championController.SetWorldPosition(); //存入数组 StoreChampionInArray(Map.GRIDTYPE_OWN_INVENTORY, map.ownTriggerArray[emptyIndex].gridX, -1, championPrefab); //扣除商品费用 currentGold -= champion.cost; //更新 photonView.RPC("UpdatePlayer", RpcTarget.All, playerID, currentHP, currentGold, currentRank); uIController.UpdateUI(); return(true); }
/// <summary> /// Calculates bonuses of a Champion when got hit /// </summary> /// <param name="champion"></param> /// <param name="damage"></param> /// <returns></returns> public float ApplyOnGotHit(ChampionController champion, float damage) { switch (championBonusType) { case ChampionBonusType.Defense: damage = ((100 - bonusValue) / 100) * damage; break; default: break; } return(damage); }
public void GetChampion_WithExisted_Found() { // Arrange var expectResult = CreateRandomChampion(); championDaoStub.Setup(stub => stub.GetChampion(It.IsAny <Guid>())).Returns(expectResult); var controller = new ChampionController(championDaoStub.Object); // Act var result = controller.GetChampion(Guid.NewGuid()); // Assert result.Value.Should().BeEquivalentTo(expectResult, options => options.ComparingByMembers <Champion>()); // Compare properties }
public void DeleteChampion_NewItem_Success() { // Arrange var existingItem = CreateRandomChampion(); championDaoStub.Setup(stub => stub.GetChampion(It.IsAny <Guid>())).Returns(existingItem); var controller = new ChampionController(championDaoStub.Object); // Act var result = controller.DeleteChampion(Guid.NewGuid()); // Assert result.Should().BeOfType <NoContentResult>(); }
public void GetChampion_WithNotExisted_NotFound() { // Arrange championDaoStub.Setup(stub => stub.GetChampion(It.IsAny <Guid>())).Returns(null as Champion); var controller = new ChampionController(championDaoStub.Object); // Act var result = controller.GetChampion(Guid.NewGuid()); // Assert result.Result.Should().BeOfType <NotFoundResult>(); //Assert.IsType<NotFoundResult>(result.Result); }
/// <summary> /// Called when attack animation finished /// </summary> public void OnAttackAnimationFinished() { isAttacking = false; if (target != null) { //get enemy target champion ChampionController targetChamoion = target.GetComponent <ChampionController>(); List <ChampionBonus> activeBonuses = null; if (teamID == TEAMID_PLAYER) { activeBonuses = gamePlayController.activeBonusList; } else if (teamID == TEAMID_AI) { activeBonuses = aIopponent.activeBonusList; } float d = 0; foreach (ChampionBonus b in activeBonuses) { d += b.ApplyOnAttack(this, targetChamoion); } //deal damage bool isTargetDead = targetChamoion.OnGotHit(d + currentDamage); //target died from attack if (isTargetDead) { TryAttackNewTarget(); } //create projectile if have one if (champion.attackProjectile != null && projectileStart != null) { GameObject projectile = Instantiate(champion.attackProjectile); projectile.transform.position = projectileStart.transform.position; projectile.GetComponent <Projectile>().Init(target); } } }
private void Start() { animator = this.gameObject.GetComponent <Animator>(); championStateAnimName = new Dictionary <ChampionState, string>() { { ChampionState.Idle, "idle" }, { ChampionState.Moving, "walk" }, { ChampionState.Attacking, "attack" }, { ChampionState.Dead, "dead" }, }; if (gameObject != null) { controller = gameObject.GetComponent <ChampionController>(); } }
/// <summary> /// Store champion gameobject in array /// </summary> /// <param name="triggerinfo"></param> /// <param name="champion"></param> private void StoreChampionInArray(int gridType, int gridX, int gridZ, GameObject champion) { //assign current trigger to champion ChampionController championController = champion.GetComponent <ChampionController>(); championController.SetGridPosition(gridType, gridX, gridZ); if (gridType == Map.GRIDTYPE_OWN_INVENTORY) { ownChampionInventoryArray[gridX] = champion; } else if (gridType == Map.GRIDTYPE_HEXA_MAP) { gridChampionsArray[gridX, gridZ] = champion; } }
/// <summary> /// Called when Game was lost /// </summary> public void RestartGame() { //remove champions for (int i = 0; i < ownChampionInventoryArray.Length; i++) { //there is a champion if (ownChampionInventoryArray[i] != null) { //get character ChampionController championController = ownChampionInventoryArray[i].GetComponent <ChampionController>(); Destroy(championController.gameObject); ownChampionInventoryArray[i] = null; } } for (int x = 0; x < Map.hexMapSizeX; x++) { for (int z = 0; z < Map.hexMapSizeZ / 2; z++) { //there is a champion if (gridChampionsArray[x, z] != null) { //get character ChampionController championController = gridChampionsArray[x, z].GetComponent <ChampionController>(); Destroy(championController.gameObject); gridChampionsArray[x, z] = null; } } } //reset stats currentHP = 100; currentGold = 5; currentGameStage = GameStage.Preparation; currentChampionLimit = 3; currentChampionCount = GetChampionCountOnHexGrid(); uIController.UpdateUI(); //restart ai aIopponent.Restart(); //show hide ui uIController.ShowGameScreen(); }
protected virtual void Die() { // Find the killer killerObj = attacker; ChampionController killer = null; if (killerObj != null) { killer = killerObj.GetComponent <ChampionController>(); } if (killer != null) { killer.experience += this.killExp; killer.money += this.killBounty; } }
/// <summary> /// Calculates bonuses of a champion when attacking /// </summary> /// <param name="champion"></param> /// <param name="targetChampion"></param> /// <returns></returns> public float ApplyOnAttack(ChampionController champion, ChampionController targetChampion) { float bonusDamage = 0; bool addEffect = false; switch (championBonusType) { case ChampionBonusType.Damage: bonusDamage += bonusValue; break; case ChampionBonusType.Stun: int rand = Random.Range(0, 100); if (rand < bonusValue) { targetChampion.OnGotStun(duration); addEffect = true; } break; case ChampionBonusType.Heal: champion.OnGotHeal(bonusValue); addEffect = true; break; default: break; } if (addEffect) { if (bonusTarget == BonusTarget.Self) { champion.AddEffect(effectPrefab, duration); } else if (bonusTarget == BonusTarget.Enemy) { targetChampion.AddEffect(effectPrefab, duration); } } return(bonusDamage); }
protected virtual void Die() { destroyerObj = attacker; ChampionController destroyer = null; if (destroyerObj != null) { destroyer = destroyerObj.GetComponent <ChampionController>(); } if (destroyer != null) { destroyer.experience += this.destroyExp; destroyer.money += this.destroyBounty; } Destroy(this.gameObject); }
/// <summary> /// Resets all champion stats and positions /// </summary> private void ResetChampions() { for (int x = 0; x < Map.hexMapSizeX; x++) { for (int z = 0; z < Map.hexMapSizeZ / 2; z++) { //there is a champion if (gridChampionsArray[x, z] != null) { //get character ChampionController championController = gridChampionsArray[x, z].GetComponent <ChampionController>(); //reset championController.Reset(); } } } }
public void GetChampions_WithExisted_Found() { // Arrange var expectedItems = new[] { CreateRandomChampion(), CreateRandomChampion(), CreateRandomChampion() }; championDaoStub.Setup(dao => dao.GetChampions()).Returns(expectedItems); var controller = new ChampionController(championDaoStub.Object); // Act var actual = controller.GetChampions(); // Assert actual.Should().BeEquivalentTo(expectedItems, options => options.ComparingByMembers <Champion>()); }
public void Start() { InitChampion(); controller = gameObject.GetComponent <ChampionController>(); controller.AttackDamage = AttackDamage; controller.AttackSpeed = AttackSpeed; controller.AttackRange = AttackRange; controller.AttackType = AttackType; controller.MovementSpeed = MovementSpeed; controller.Armor = Armor; controller._Class = _Class; controller._Race = _Race; controller.Health = Health; controller.healthBar.maxValue = Health; controller.healthBar.value = controller.healthBar.maxValue; }
public void AttackTarget() // the champion makes an attack on his current target { // play attack animation ChampionController targetController = target.GetComponent <ChampionController>(); Vector3 heading = target.transform.position - gameObject.transform.position; gameObject.transform.forward = heading; float physicalDmgReduction = ((float)targetController.Armor / 100); // physical dmg reduction from target armor int dmg = AttackDamage - (int)(AttackDamage * physicalDmgReduction); targetController.Health -= dmg; targetController.healthBar.value = targetController.Health; if (targetController.Health <= 0) { OnTargetDead(); } }
public void UpdateChampion_ExistedItem_Success() { // Arrange var itemToUpdate = new CreateChampionDto { Name = Guid.NewGuid().ToString(), Ultimate = Guid.NewGuid().ToString() }; var controller = new ChampionController(championDaoStub.Object); // Act var createdItem = controller.CreateChampion(itemToUpdate); // Assert var dto = (createdItem.Result as CreatedAtActionResult).Value as ChampionDto; itemToUpdate.Should().BeEquivalentTo( dto, options => options.ComparingByMembers <ChampionDto>().ExcludingMissingMembers()); }
/// <summary> /// Called when a game finished and needs restart /// </summary> public void Restart() { for (int x = 0; x < Map.hexMapSizeX; x++) { for (int z = 0; z < Map.hexMapSizeZ / 2; z++) { //there is a champion if (gridChampionsArray[x, z] != null) { //get character ChampionController championController = gridChampionsArray[x, z].GetComponent <ChampionController>(); Destroy(championController.gameObject); gridChampionsArray[x, z] = null; } } } AddRandomChampion(); //AddRandomChampion(); }
public void CreateChampion_NewItem_Success() { // Arrange var existingItem = CreateRandomChampion(); championDaoStub.Setup(stub => stub.GetChampion(It.IsAny <Guid>())).Returns(existingItem); var controller = new ChampionController(championDaoStub.Object); var id = existingItem.Id; var itemToUpdate = new UpdateChampionDto() { Id = Guid.NewGuid(), Name = Guid.NewGuid().ToString(), Ultimate = Guid.NewGuid().ToString() }; // Act var result = controller.UpdateChampion(itemToUpdate); // Assert result.Should().BeOfType <NoContentResult>(); }