public void ApplyWalkingDamage(IGameUnit unit, int mapX, int mapY, int areaWidth, int areaHeight, MoveUnitChangeContainer moveUnitChangeContainer) { var damage = unit.GetAttribute(UnitAttribute.WalkingDamage); if (damage == 0) { return; } // Collect the tiles we're checking for (var x = mapX; x < mapX + areaWidth; x++) { for (var y = mapY; y < mapY + areaHeight; y++) { // Get the tile group in question var tileIndex = y * GameMapWidth + x; if (tileIndex < 0 || tileIndex >= GameMapTiles.Length || GameMapTiles[tileIndex] == null) { Debug.Log(String.Format("MovementCostForUnit tile index out of bounds or null: {0}. Map tile length: {1}", tileIndex, GameMapTiles.Length)); continue; } var tileGroup = GameMapTiles[tileIndex]; foreach (var tile in tileGroup.Tiles.Where(z => z != null)) { tile.TakeDamage(damage, unit, moveUnitChangeContainer); } } } }
public ulong GetInhibitionScore(IGameUnit unit) { if (unit.GetAttribute(UnitAttribute.WalkingDamage) > TileHealth) { return(DestructionValue); } return(0); }
//public async Task MoveUnitAsync(IGameUnit unit, IGameMapMovementRoute route) //{ // await MoveUnitCoroutine(unit, route); //} /// <summary> /// /// </summary> /// <param name="unit"></param> /// <param name="route"></param> /// <returns></returns> public IEnumerator MoveUnitCoroutine(IGameUnit unit, IGameMapMovementRoute route) { // Create a container for our move unit var moveUnitChangeContainer = new MoveUnitChangeContainer(unit); // Quick pre-calculation if we need to do walking damage var hasWalkingDamage = unit.GetAttribute(UnitAttribute.WalkingDamage) > 0; // Move the unit each step in the given route, excluding None direction steps foreach (var routeStep in route.Route.Where(x => x != Direction.None)) { var startPosition = unit.WorldPosition; var directionVector = DirectionHelper.GetDirectionVector(routeStep); var targetPosition = unit.WorldPosition + directionVector; // Animate the unit moving this step var duration = 0.15f; // 0.15f seconds var stepTime = 0f; while (stepTime < duration) { stepTime += Time.deltaTime; unit.WorldPosition = Vector3.Lerp(startPosition, targetPosition, stepTime / duration); yield return(null); } // Animation complete, set the unit position to be the end location unit.WorldPosition = targetPosition; var newX = unit.MapX; var newY = unit.MapY; DirectionHelper.ApplyDirection(routeStep, ref newX, ref newY); unit.MapX = newX; unit.MapY = newY; // Apply walking damage to the tiles the unit now occupies if (hasWalkingDamage) { ApplyWalkingDamage(unit, newX, newY, unit.TileWidth, unit.TileHeight, moveUnitChangeContainer); } } // Final snap the unit to their end map & unity location unit.MapX = route.EndX; unit.MapY = route.EndY; unit.WorldPosition = TranslateMapXYToUnityXY(unit.MapX, unit.MapY); // And tell them to consume movement for this route unit.AddRouteCost(route); // Trigger the MoveCompleted event now that we're done animating the move OnUnitMoveCompleted(moveUnitChangeContainer); }
public static int RepeatCount(IAbility ability, IGameUnit attacker, IGameUnit target) { if (ability.RepeatCount <= 1) { return(1); } var attackerSpeed = attacker.GetAttribute(UnitAttribute.Speed); var defenderSpeed = target.GetAttribute(UnitAttribute.Speed); var speedDiff = attackerSpeed - defenderSpeed; if (speedDiff < 0) { return(1); } var repeatThreshold = ability.RepeatThreshold <= 0 ? DefaultRepeatThreshold : ability.RepeatThreshold; return(Math.Min(speedDiff / repeatThreshold + 1, ability.RepeatCount)); }