public void AttackAnimation(Unit selectedUnit, Unit goalUnit, bool isDefenderInCity, Sequencer sequencer, ref int selectedUnitCurrentHealth, ref int goalUnitCurrentHealth, bool distanceAttack) { float bonusCity = isDefenderInCity ? goalUnit.Defense * 0.5f : 0.0f; bonusCity = selectedUnit.Type == UnitStats.UnitType.CATAPULT ? 0.0f : bonusCity; float totalAttack = selectedUnit.Attack + (goalUnit.Defense + bonusCity); float probabilityVictorySelected = (float)selectedUnit.Attack / (float)totalAttack; float attackResult = UnityEngine.Random.Range(0f, 1f); Unit unitToMove = null; Unit unitToHurt = null; if (attackResult <= probabilityVictorySelected) { goalUnitCurrentHealth--; unitToMove = selectedUnit; unitToHurt = goalUnit; } else if (!distanceAttack) { selectedUnitCurrentHealth--; unitToMove = goalUnit; unitToHurt = selectedUnit; } float offsetY = unitToMove.gameObject.GetComponent <MeshFilter>().mesh.bounds.size.y *unitToMove.gameObject.transform.localScale.y * 0.5f; Vector3 newPosition = new Vector3( unitToHurt.gameObject.transform.position.x, unitToHurt.gameObject.transform.position.y + offsetY, unitToHurt.gameObject.transform.position.z); Vector3 movement = newPosition - unitToMove.gameObject.transform.position; MoveBy unitMovementAnimation = new MoveBy(movement, 0.15f, unitToMove.gameObject); sequencer.Add(unitMovementAnimation); Caller togglePunchCaller = new Caller(); togglePunchCaller.ActionFunction = () => unitToHurt.ToggleWound(true); sequencer.Add(togglePunchCaller); MoveBy reverseUnitMovementAnimation = new MoveBy(-movement, 0.15f, unitToMove.gameObject); sequencer.Add(reverseUnitMovementAnimation); Caller reverseTogglePunchCaller = new Caller(); reverseTogglePunchCaller.ActionFunction = () => unitToHurt.ToggleWound(false); sequencer.Add(reverseTogglePunchCaller); Caller caller = new Caller(); caller.ActionFunction = () => unitToHurt.CurrentHealth--; sequencer.Add(caller); }
private async Task QueueSomething(Installation installation) { var sequencer = new Sequencer(); for (int i = 0; i < 510; i++) { var falseNueve = new FalseNueve() { Al = "a", Ol = "b" }; sequencer.Add(falseNueve, installation); if (i == 499) { await Task.Delay(100); } } await Task.Delay(700); Assert.Equal(500, sequencer.Counter); sequencer.Flush(installation); await Task.Delay(700); Assert.Equal(510, sequencer.Counter); }
void MoveUnit(GameObject unitToMove, HexCell cellToMoveTo) { float offsetY = unitToMove.GetComponent <MeshFilter>().mesh.bounds.size.y *unitToMove.transform.localScale.y * 0.5f; Vector3 newPosition = new Vector3(cellToMoveTo.transform.position.x, cellToMoveTo.transform.position.y + offsetY, cellToMoveTo.transform.position.z); Vector3 movement = newPosition - unitToMove.transform.position; MoveBy moveUnitAnimationBy = new MoveBy(movement, 0.25f, unitToMove); Caller caller = new Caller(); caller.ActionFunction = () => MoveUnitCallback(unitToMove, cellToMoveTo); Sequencer sequence = new Sequencer(); sequence.Add(moveUnitAnimationBy); sequence.Add(caller); animationController.Add(sequence); }
public void Fight(Unit selectedUnit, Unit goalUnit, bool isDefenderInCity, HexCell goalCell, City goalCity = null) { selectedUnit.HasAttacked = true; selectedUnit.MovementLeft = 0.0f; var selectedUnitCurrentHealth = selectedUnit.CurrentHealth; var goalUnitCurrentHealth = goalUnit.CurrentHealth; Sequencer sequencer = new Sequencer(); while (selectedUnitCurrentHealth > 0 && goalUnitCurrentHealth > 0) { AttackAnimation(selectedUnit, goalUnit, isDefenderInCity, sequencer, ref selectedUnitCurrentHealth, ref goalUnitCurrentHealth, false); } Caller caller = new Caller(); if (selectedUnitCurrentHealth == 0) { caller.ActionFunction = () => { Debug.Log("defender winner"); scoreEvent.Invoke(ScoreManager.TypesScore.FIGHT, goalUnit.PlayerID); logic.RemoveUnit(selectedUnit); Unselect(); }; } else { caller.ActionFunction = () => { Debug.Log("attacker winner"); MoveUnit(selectedUnit.gameObject, goalCell); if (goalUnit != null) { scoreEvent.Invoke(ScoreManager.TypesScore.FIGHT, selectedUnit.PlayerID); logic.RemoveUnit(goalUnit); } if (isDefenderInCity) { ConquerCity(currentPlayerID, goalCity.PlayerID, goalCity.ID); } }; } sequencer.Add(caller); animationController.Add(sequencer); }
public void DistanceFight(Unit selectedUnit, Unit goalUnit, bool isDefenderInCity, Action winAction) { selectedUnit.HasAttacked = true; //3 attacks Sequencer sequencer = new Sequencer(); int goalUnitCurrentHealth = goalUnit.CurrentHealth; bool goalUnitIsDead = goalUnitCurrentHealth <= 0.0f; int numberOfAttacks = selectedUnit.Type != UnitStats.UnitType.CATAPULT ? 3 : 5; for (int i = 0; i < numberOfAttacks && !goalUnitIsDead; ++i) { DistanceAttackAnimation(selectedUnit, goalUnit, isDefenderInCity, sequencer, ref goalUnitCurrentHealth); goalUnitIsDead = goalUnitCurrentHealth <= 0.0f; } if (goalUnitIsDead) { Caller caller = new Caller(); caller.ActionFunction = winAction; sequencer.Add(caller); } animationController.Add(sequencer); }