// TODO is not called public override void onDamage(MapObject dealer) { // If a unit is damaged while idling, attack whatever damaged it. Debug.Log("hit!"); if (dealer is Projectile) { SidedEntity shooter = ((Projectile)dealer).getShooter(); if (this.unit.getTeam() != shooter.getTeam()) { this.setToAttack(shooter); } } else if (dealer is SidedEntity) { SidedEntity attacker = (SidedEntity)dealer; if (this.unit.getTeam() != attacker.getTeam()) { this.setToAttack(attacker); } } }
private void handlePlayerInput() { // DEBUG if (Input.GetKeyDown(KeyCode.Y)) { Vector3 mouseWorldPos = this.playerCam.ScreenToWorldPoint(Input.mousePosition); Vector2Int v = TileMaps.singleton.worldToCell(mouseWorldPos + Vector3.one * 0.5f); this.sendMessageToServer(new MessageSpawnEntity(Registry.unitGunner, new Vector3(v.x, v.y), Vector3.zero, this.teamToDebugPlace != null ? this.teamToDebugPlace : this.team)); } // End DEBUG bool leftBtnUp = Input.GetMouseButtonUp(0); bool rightBtnUp = Input.GetMouseButtonUp(1); this.selectionBox.updateRect(); if (leftBtnUp || rightBtnUp) { Vector3 mousePos = this.playerCam.ScreenToWorldPoint(Input.mousePosition); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero); if (hit.collider == null) { // Clicked nothing. if (leftBtnUp) { this.actionButtons.closePopupButtons(); bool unitMoved = this.selectedParty.moveAllTo(mousePos); if (unitMoved) { this.unitDestinationEffect.setPosition(mousePos); } } if (rightBtnUp) { // Deselect all selected Units. this.getSelected().clearSelected(); } } else { // Clicked something. LivingObject livingObject = hit.transform.GetComponent <LivingObject>(); if (livingObject != null) { // Clicked an Entity. if (this.actionButtons.getDelayedActionButton() != null) { ActionButtonRequireClick delayedButton = this.actionButtons.getDelayedActionButton(); // Check if this is a valid option to preform the action on. if (delayedButton.isValidForAction(this.team, livingObject)) { if (this.selectedBuilding.getBuilding() != null) { delayedButton.callFunction(this.selectedBuilding.getBuilding(), livingObject); } else { delayedButton.callFunction(this.selectedParty.getAllUnits(), livingObject); } } } else { if (livingObject is SidedEntity) { SidedEntity clickedEntity = (SidedEntity)livingObject; if (clickedEntity.getTeam() == this.team) { // Clicked a SidedEntity that is on our team. if (leftBtnUp) { this.onLeftBtnClick(clickedEntity); } if (rightBtnUp) { this.onRightBtnClick(clickedEntity); } } else { // Clicked a SidedEntity not on our team. // Set all of the selected units that have the AttackNearby action to attack the clicked unit, only if they are already not attacking something. int mask = ActionButton.unitAttackNearby.getMask(); bool flag = false; foreach (UnitBase unit in this.selectedParty.getAllUnits()) { if ((unit.getButtonMask() & mask) != 0) // Unit has the attack Action Button { this.sendMessageToServer(new MessageAttackSpecific(unit, clickedEntity)); flag = true; } } if (flag) { this.attackTargetEffect.setTarget(clickedEntity); } } } } } // A click happened, so if something valid was clicked the delayed action was called. // Either way, we should cancel the action becuase it was resolved or the wrong thing was clicked. this.actionButtons.cancelDelayedAction(); } } }