private void ApplyDamage( GridPositionComponent targetPosition, IntegerComponent damage, IntegerComponent targetHealth) { ObjectPools.Instance.GetPooledObject <TextPopup>().Enable( (-damage.Value).ToString(), targetPosition.Position + Vector2.up, 1.0f); targetHealth.Value -= damage.Value; AudioPlayer.Instance.PlayAudio(AudioPlayer.Type.Damage); if (ActorCache.Instance.Player.Entity == targetHealth.Owner) { _healthDisplay.SetHealth(targetHealth.Value); } var fireImmune = targetHealth.Owner.GetComponent <FireImmuneComponent>(); if (fireImmune != null) { targetHealth.Owner.RemoveComponent(fireImmune); } var neutral = targetHealth.Owner.GetComponent <NeutralComponent>(); if (neutral != null) { targetHealth.Owner.RemoveComponent(neutral); } if (targetHealth.Value <= 0) { var render = targetHealth.Owner.GetComponent <RenderComponent>(); if (render != null) { render.Sprite = Sprites.Instance.GetDeathSprite(); render.Renderer.sortingOrder = SortOrder.DeadActor; } var turnComponent = targetHealth.Owner.GetComponent <BooleanComponent>(ComponentType.Turn); if (turnComponent != null) { targetHealth.Owner.RemoveComponent(turnComponent); } // IF Player, Game Over if (targetHealth.Owner == ActorCache.Instance.Player.Entity) { GameController.Instance.GameOver(); } } }
private void setBotPosition(GameObject bot, GridPositionComponent botPosition, GridPosition position) { if (position == null) { return; } GameGrid[position.X][position.Y].movingHere.Add(bot); Vector3 screenPosition = GameGrid[position.X][position.Y].Cell.transform.position; bot.transform.position = new Vector3(screenPosition.x, screenPosition.y, bot.transform.position.z); botPosition.position = position; }
public GameObject placeBot(GridPosition position, Nanobot nanobot) { if (nanobot.schematic == null || position == null) { return(null); } GameObject newBot = Instantiate(nanobot.gameObject); GridPositionComponent gridPosition = newBot.GetComponent <GridPositionComponent>(); setBotPosition(newBot, gridPosition, position); return(newBot); }
private void MovePosition(GridPositionComponent component) { if (IsMoving(component.Owner) || _attackSystem.IsAttacking(component.Owner)) { return; } _temp.Set(component.Position.x, component.Position.y, 0); if (component.Owner.GameObject.transform.position == _temp) { return; } _movingEntities.Add(component.Owner); MoveEntity(component.Owner, _temp); }
void OnMouseUpAsButton() { PlacementMenuHandler placementHandler = GameObject.FindObjectOfType <PlacementMenuHandler>(); if (nanobotCanBePlacedHere() && placementHandler.isNanobotDragging() && GameObject.FindObjectOfType <Resources>().trySpendPlacementResource(placementHandler.getDraggedNanobot().price)) { // Add nanobot to this cell getGameCell().Nanobot = GameObject.Instantiate(placementHandler.getDraggedNanobot()).gameObject; getGameCell().Nanobot.transform.position = transform.position; GridPositionComponent gridPosition = getGameCell().Nanobot.GetComponent <GridPositionComponent>(); gridPosition.position.X = this.GridPosition.X; gridPosition.position.Y = this.GridPosition.Y; placementHandler.stopDragging(); if (SoundManager.instance != null) { SoundManager.instance.PlaySingle(GetComponent <AudioSource>(), placeBotSound); } } }
private void UpdatePosition(GridPositionComponent component) { if (IsMoving(component.Owner) || _attackSystem.IsAttacking(component.Owner)) { return; } // Not our turn. var turnComponent = component.Owner.GetComponent <BooleanComponent>(ComponentType.Turn); if (turnComponent == null || !turnComponent.Value) { return; } // No Vision var fieldOfView = component.Owner.GetComponent <IntegerComponent>(ComponentType.FieldOfView); if (fieldOfView == null) { return; } // No Movement Defined var chaseTarget = component.Owner.GetComponent <ChaseTargetComponent>(); if (chaseTarget == null) { return; } // Neutral is Defined var neutral = component.Owner.GetComponent <NeutralComponent>(); if (neutral != null) { turnComponent.Value = false; return; } // No Target Position var targetPosition = chaseTarget.Target.GetComponent <GridPositionComponent>(); if (targetPosition == null) { return; } // Out of Range. var distance = Vector2Int.Distance(targetPosition.Position, component.Position); if (distance > fieldOfView.Value) { turnComponent.Value = false; return; } var reach = component.Owner.GetComponent <IntegerComponent>(ComponentType.Reach); if (reach != null && reach.Value >= distance) { return; } var moveDirection = MapSystem.Instance.GetMoveDirection(component.Position, targetPosition.Position); if (!MapSystem.Instance.IsWalkable(component.Position + moveDirection)) { turnComponent.Value = false; } else { component.Position += moveDirection; } }