public override IEnumerator SpecialAttack(FightPhase phase, MapDimensions dimensions, CombatantView receiverView, WeaponHitSeverity severity) { var receiver = phase.Receiver; var didAdvance = phase.Effects.ReceiverEffects.OfType <Advance>().Any(); if (!didAdvance) { yield return(StartCoroutine(Attack(receiver, severity))); yield break; } var attacker = phase.Initiator; var distance = MathUtils.ManhattanDistance(attacker.Position, receiver.Position); var windupClip = distance > 1 ? _farAdvanceAnimationClips[Facing] : _windupAnimationClips[Facing]; var advanceClip = _advanceAnimationClips[Facing]; _combatantAnimator.enabled = false; yield return(StartCoroutine(PlayClip(windupClip))); var advanceClipDuration = ((1000 / advanceClip.fps) * advanceClip.frames.Length / 1000); var destination = receiverView.transform.position; transform .DOMove(destination, advanceClipDuration) .SetEase(Ease.OutCubic) .Play(); yield return(StartCoroutine(PlayClip(advanceClip))); _combatantAnimator.enabled = true; }
public override IEnumerator SpecialAttack(FightPhase phase, MapDimensions dimensions, CombatantView receiverView, WeaponHitSeverity severity) { var receiver = phase.Receiver; var shoveEffects = phase.Effects.ReceiverEffects.OfType <Shove>().ToList(); if (shoveEffects.Any()) { Action <WeaponHitConnection> hitConnectedCallback = null; hitConnectedCallback = hit => { var destination = shoveEffects.First().GetDestination(receiver); var worldDestination = dimensions.GetWorldPositionForGridPosition(destination); var theirTransform = receiverView.transform; theirTransform .DOMove(worldDestination, 0.3f) .SetEase(Ease.OutCubic) .Play(); AttackConnectedSignal.RemoveListener(hitConnectedCallback); }; AttackConnectedSignal.AddListener(hitConnectedCallback); } yield return(StartCoroutine(Attack(receiver, severity))); }
public FightPointOfInterest(MapDimensions dimensions, ICombatant attacker, ICombatant defender) { var attackerPosition = dimensions.GetWorldPositionForGridPosition(attacker.Position); var defenderPosition = dimensions.GetWorldPositionForGridPosition(defender.Position); FocalPoint = MathUtils.Midpoint(attackerPosition, defenderPosition); Tolerance = 32f; }
public void Changed(string map) { map = Path.GetFileName(map); Dims = new Libs.MapDimensions(map); Sprite mapSprite = Resources.Load <Sprite>("overviews/" + map); gameObject.GetComponent <SpriteRenderer>().sprite = mapSprite; }
public bool Validate(IEnumerable <IEnumerable <MapObject> > mapObjects, MapDimensions mapDimensions) { this.mapObjects = mapObjects; this.mapDimensions = mapDimensions; return(IsHeightCurrect() && IsWidthCurrect() && IsMapBordersClosed()); }
public static List <Point> Distribute(TerrainType[] map, PoissonDiskParameters parameters, List <TerrainType> allowedTerrain) { grid = map; param = parameters; dimensions = LevelGenerator.Instance.mapDimensions; terrainsToDistributeOn = allowedTerrain; //step 0 cellSize = param.radius / Mathf.Sqrt(2); backgroundColumns = Mathf.CeilToInt(dimensions.width / cellSize); backgroundRows = Mathf.CeilToInt(dimensions.height / cellSize); backgroundGrid = new bool[backgroundColumns * backgroundRows]; List <Point> samplePoints = new List <Point>(); List <Point> activeSamplePoints = new List <Point>(); //Step 1 Point initialSamplePoint; do { initialSamplePoint = Point.GetRandomPoint(); }while (!IsProperTerrainOnPoint(initialSamplePoint)); activeSamplePoints.Add(initialSamplePoint); samplePoints.Add(initialSamplePoint); SetSampleInBackgroundGridAt(initialSamplePoint); //Step 2 while (activeSamplePoints.Count > 0) { Point index = activeSamplePoints[Random.Range(0, activeSamplePoints.Count)]; bool noSuitablePointFound = true; for (int k = 0; k < param.sampleSize; k++) { Point offset = index.GetRandomPointInCircle(param.radius); if (!activeSamplePoints.Contains(offset) && CheckPoint(offset) && !CheckNeighboursForSamples(offset)) { activeSamplePoints.Add(offset); samplePoints.Add(offset); SetSampleInBackgroundGridAt(offset); noSuitablePointFound = false; } } if (noSuitablePointFound) { activeSamplePoints.Remove(index); } } return(samplePoints); }
public bool IsInsideGrid() { MapDimensions map = LevelGenerator.Instance.mapDimensions; if (x >= 0 && x < map.width && y >= 0 && y < map.height) { return(true); } else { return(false); } }
public Maze Parse(MapTokens map) { MapDimensions mapDimensions = ParseDimensions(map.MapDimensions); IEnumerable <IEnumerable <MapObject> > mapBody = ParseMapBody(map.MapBodyValues); MapValidator mapValidator = new MapValidator(); if (!mapValidator.Validate(mapBody, mapDimensions)) { throw new Exception("Map validation has been fail"); } return(new Maze(mapBody, mapDimensions)); }
public Rect GetMapSpaceRect(MapDimensions dimensions) { var worldSpaceWidth = Width * dimensions.TileSize; var worldSpaceHeight = Height * dimensions.TileSize; var snappedPosition = dimensions.GetWorldPositionForGridPosition(dimensions.GetGridPositionForWorldPosition(transform.position)); if (Width % 2 == 0) { snappedPosition.x = snappedPosition.x + dimensions.TileSize / 2.0f; } if (Height % 2 == 0) { snappedPosition.y = snappedPosition.y + dimensions.TileSize / 2.0f; } var boundingOrigin = snappedPosition - new Vector3(worldSpaceWidth / 2.0f, worldSpaceHeight / 2.0f); var gridSpaceOrigin = dimensions.GetGridPositionForWorldPosition(boundingOrigin); return(new Rect(gridSpaceOrigin.x, gridSpaceOrigin.y, Width, Height)); }
public TilePointOfInterest(MapDimensions dimensions, Vector2 location) { FocalPoint = dimensions.GetWorldPositionForGridPosition(location); Tolerance = 1f; }
public CombatantPointOfInterest(MapDimensions dimensions, ICombatant combatant) { FocalPoint = dimensions.GetWorldPositionForGridPosition(combatant.Position); Tolerance = 1f; }
public virtual IEnumerator SpecialAttack(FightPhase phase, MapDimensions dimensions, CombatantView receiverView, WeaponHitSeverity severity) { throw new InvalidOperationException("Combatant: " + CombatantId + " has no special attack."); }
public PointOfInterestFactory(MapDimensions dimensions) { _dimensions = dimensions; }
public void HighlightPositions(IEnumerable <Vector2> positions, HighlightLevel level, MapDimensions dimensions) { var worldPositions = positions.Select(pos => dimensions.GetWorldPositionForGridPosition(pos)).ToList(); var highlights = worldPositions.Select(pos => CreateHighlight(pos, level)).ToHashSet(); _highlightsByLevel[level] = highlights; }
public IEnumerator Animate(FightPhase phase, CombatantView initiator, CombatantView receiver, MapDimensions dimensions) { if (phase.Response == DefenderResponse.Dodge) { StartCoroutine(receiver.Dodge()); } var severity = phase.Effects.Severity; if (_specialSkills.Contains(phase.Skill)) { yield return(StartCoroutine(initiator.SpecialAttack(phase, dimensions, receiver, severity))); } else { yield return(StartCoroutine(initiator.Attack(phase.Receiver, severity))); } if (phase.ReceverDies) { receiver.Die(); } }
public IEnumerator FollowPath(IList <Vector3> path, MapDimensions dimensions) { return(_controller.FollowPath(path, dimensions)); }
public static TerrainType[] PopulateGrid(TerrainType[] originalMap, SeedGrowthParameters param, MapDimensions mapSettings) { grid = originalMap; parameters = param; ExternalPlacementCondition condition; switch (param.conditionType) { case PlacementCondition.Forest: condition = ForestConditon; break; case PlacementCondition.City: condition = CityCondition; break; default: condition = null; break; } Point seedLocation; List <Point> seeds = new List <Point>(); if (parameters.amountOfSeeds > 0) { seeds = PoissonDisc.Distribute(grid, param.poissonSeedParameters, param.allowedBiomes); } for (int seed = 0; seed < param.amountOfSeeds; seed++) { seedLocation = seeds[Random.Range(0, seeds.Count)]; for (int step = 0; step < param.amountOfGrowthSteps.GetRandomValue(); step++) { int kernelSize = parameters.kernelSize.GetRandomValue(); List <Point> createdArea = new List <Point>(); for (int xOffset = -kernelSize; xOffset <= kernelSize; xOffset++) { for (int yOffset = -kernelSize; yOffset <= kernelSize; yOffset++) { Point neighbour = new Point(seedLocation.x + xOffset, seedLocation.y + yOffset); //Checking all conditions of the neighbour if (neighbour.IsInsideGrid() && IsCorrectTile(neighbour) && condition(seedLocation, neighbour)) { float chanceOffset = CalculatePlacementChance(seedLocation, neighbour, kernelSize); //Lower chance for placing a forest tile the farther you are away if (Random.Range(0f, 1f) < chanceOffset) { grid[neighbour.gridIndex] = param.desiredTerrain; createdArea.Add(neighbour); } } } } if (createdArea.Count > 0) { seedLocation = createdArea[Random.Range(0, createdArea.Count)]; } } } return(grid); }