private void onRightBtnClick(SidedEntity entity) { if (entity is UnitBase) { if (this.selectedParty.contains((UnitBase)entity)) { this.selectedParty.remove((UnitBase)entity); } else { this.selectedBuilding.clearSelected(); this.selectedParty.tryAdd((UnitBase)entity); } } else if (entity is BuildingBase) { if (entity == this.selectedBuilding) { this.selectedBuilding.clearSelected(); } else { this.selectedParty.clearSelected(); this.selectedBuilding.setSelected((BuildingBase)entity); } } }
public void setTarget(SidedEntity target) { this.target = target; this.centerAroundTarget(); this.setAlpha(1); this.f = this.timeVisible; }
private void onLeftBtnClick(SidedEntity entity) { this.getSelected().clearSelected(); if (entity is UnitBase) { this.selectedParty.tryAdd((UnitBase)entity); } else if (entity is BuildingBase) { this.selectedBuilding.setSelected((BuildingBase)entity); } this.actionButtons.closePopupButtons(); }
public Projectile fireProjectile(Vector3 position, SidedEntity shooter, int damage, LivingObject target) { GameObject obj = GameObject.Instantiate( Registry.projectileArrow.getPrefab(), position, Quaternion.identity); Projectile projectile = obj.GetComponent <Projectile>(); projectile.setProjectileInfo(shooter, damage, target); NetworkServer.Spawn(obj); return(projectile); }
public void callFunction <T>(List <T> list, LivingObject clickedObject) where T : SidedEntity { List <SidedEntity> candidates = this.getCandidates(list); if (this.entitySelecterFunctionDelayed == null) { // Call function on all. foreach (SidedEntity entity in candidates) { this.mainFunctionDelayed.Invoke(entity, clickedObject); } } else { SidedEntity e = this.entitySelecterFunctionDelayed.Invoke(candidates, clickedObject); this.mainFunctionDelayed.Invoke(e, clickedObject); } }
public virtual void callFunction <T>(List <T> list) where T : SidedEntity { List <SidedEntity> candidates = this.getCandidates(list); if (this.entitySelecterFunction == null) { // Call function on all. foreach (SidedEntity entity in candidates) { this.mainFunction.Invoke(entity); } } else { // Call function on a specific SidedEntity. SidedEntity e = this.entitySelecterFunction.Invoke(candidates); this.mainFunction.Invoke(e); } }
/// <summary> /// Returns the closest enemy object to the point, or null if there are none. /// </summary> protected T findEntityOfType <T>(Vector3 point, float maxDistance = -1, bool findEnemies = true) where T : SidedEntity { SidedEntity obj = null; float f = float.PositiveInfinity; Predicate <MapObject> predicate = (findEnemies ? unit.getTeam().predicateOtherTeam : unit.getTeam().predicateThisTeam); foreach (SidedEntity s in this.unit.map.findMapObjects(predicate)) { if (s is T && !s.isDead()) { float dis = Vector3.Distance(point, s.transform.position); if ((dis < f) && (maxDistance == -1 || dis < maxDistance)) { obj = s; f = dis; } } } return((T)obj); }
// 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); } } }
public void setProjectileInfo(SidedEntity shooter, int damage, LivingObject target) { this.shooter = shooter; this.damage = damage; this.target = target; }
public static readonly ActionButton[] BUTTON_LIST = new ActionButton[64]; // There doesn't seem to be any limit to the size. // Functions to use for this.setShouldDisableFunction() private static bool functionIsImmutable(SidedEntity entity) { return(entity.isImmutable()); }
/// <summary> /// Returns true if this ActionButton's interactability should be disabled. /// </summary> public bool shouldDisable(SidedEntity thisEntity) { return(this.shouldDisableFunction == null ? false : this.shouldDisableFunction.Invoke(thisEntity)); }
private static bool functionIsConstructing(SidedEntity entity) { return(((BuildingBase)entity).isConstructing()); }
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(); } } }