public void MoveBoss(Entity boss) { var hero = _pool.GetHero(); var heroPosition = hero.position.Value; var pathToHero = _movementCalculator.CalculateMoveToTarget( boss.position.Value, LocalDirections.ToDirection(boss.rotation.Value), heroPosition); if (!pathToHero.HasStepsLeft) { return; } var nextStep = pathToHero.NextStep(); if (nextStep.Position != heroPosition) { if (Debug.isDebugBuild) { DrawBossPath(pathToHero); } boss.ReplacePosition(nextStep.Position); var knockedObjectInFront = _pool.KnockObjectsInFront(nextStep.Position, nextStep.Direction, false, 0.4f); if (knockedObjectInFront) { boss.HasBumpedIntoObject(true); } else if (_pool.GetTileAt(nextStep.Position + nextStep.Direction) == null) { boss.HasRecoveredAtEdge(true); } } else { boss.IsAttacking(true); hero.ReplaceHealth(hero.health.Value - 1); _pool.SwitchCurse(); } boss.ReplaceRotation(LocalDirections.ToRotation(nextStep.Direction)); }
public void Execute(List <Entity> entities) { var hero = entities.SingleEntity(); var moveDirection = hero.inputMove.Direction; var newPosition = moveDirection + hero.position.Value; var canMoveTo = _pool.OpenTileAt(newPosition); var stillInsideSamePuzzle = _pool.IsStillInsideSamePuzzle(hero.position.Value, newPosition); if (canMoveTo && !(hero.isSpikesCarried && !stillInsideSamePuzzle)) { hero.ReplacePosition(newPosition); hero.ReplaceRotation(LocalDirections.ToRotation(moveDirection)); } else { var hasKnockedObjectInFront = _pool.KnockObjectsInFront(hero.position.Value, moveDirection, true, 0.4f); if (hasKnockedObjectInFront) { var knockedObject = _pool.GetEntityAt(newPosition, x => x.hasKnocked); var pushableCanMove = _pool.OpenTileAt(newPosition + moveDirection); if (pushableCanMove && knockedObject.isBox) { hero.IsPushing(true); hero.ReplacePosition(newPosition); } else { hero.HasBumpedIntoObject(true); } hero.ReplaceRotation(LocalDirections.ToRotation(moveDirection)); } else { } } }