void OnTriggerEnter2D(Collider2D hitInfo) { // Put proper hit detection code here if (hitInfo.transform.parent) { Rodent unknownRodent = hitInfo.transform.parent.gameObject.GetComponent <Rodent>(); PlayerStats king = hitInfo.transform.parent.gameObject.GetComponent <PlayerStats>(); BuildableObject unknownBuilding = hitInfo.transform.parent.gameObject.GetComponent <BuildableObject>(); if (unknownRodent) { if (unknownRodent.getTeam() == enemyTeam) { unknownRodent.Damage(attackDamage); Destroy(gameObject); } } else if (unknownBuilding) { if (unknownBuilding.getTeam() == enemyTeam && unknownBuilding.getType() != BuildableObject.BuildingType.TownCenter && unknownBuilding.getType() != BuildableObject.BuildingType.WoodPile && unknownBuilding.getType() != BuildableObject.BuildingType.StonePile && unknownBuilding.getType() != BuildableObject.BuildingType.GarbageCan) { unknownBuilding.Damage(attackDamage); Destroy(gameObject); } } else if (king) { if (enemyTeam == 1) { king.Damage(attackDamage); Destroy(gameObject); } } } }
/** Responsible for giving SubjectScript new Target and Updating our Status */ public void setTarget(GameObject o) { //print("set Target called"); _placeOfWork = o; //need proper getter/setter someday SubjectScript s = this.GetComponent <SubjectScript>(); if (s) { s.changeTarget(o); } if (o == null) { _Status = eStatus.Available; s.setIdle(); //Show the Exclamation for available non enemy rodents if (_Team != 2) { _NotificationObject.SetActive(true); _NotifyAnimator.SetBool("Notify", true); } return; } if (o.GetComponent <BuildableObject>()) { BuildableObject bo = o.GetComponent <BuildableObject>(); if (bo.getState() == BuildableObject.BuildingState.Building) { //Tell subject script to behave like a builder s.setBuilder(); _Status = eStatus.Building; _NotificationObject.SetActive(false); // Debug.Log("Updated State to Builder"); //OR // Tell them to defend a location when that script arrives // _Status = eStatus.Army; } else if (bo.getState() == BuildableObject.BuildingState.Built || bo.getState() == BuildableObject.BuildingState.Idle) { //Unknown if state IDLE could cause a unique problem, can a building be // idle but not built? i forget _NotificationObject.SetActive(false); // Tell Subject Script to behave like a Worker if (bo.getType() == BuildableObject.BuildingType.Outpost) { _Status = eStatus.Army; // for all intensive purposes army can behave same for player and defense structure s.setDefender(); // print("Told to be defender"); } else if (bo.getType() == BuildableObject.BuildingType.Farm) { _Status = eStatus.Working; s.setFarmer(); } else { _Status = eStatus.Working; s.setGatherer(); } } } else if (o.GetComponent <PlayerStats>()) { //Debug.Log("Was told to go to RoyalGuard"); // Tell Subject script to behave like a bodyguard _NotificationObject.SetActive(false); s.setRoyalGuard(); _Status = eStatus.Army; // for all intensive purposes army can behave same for player and defense structure } else { Debug.Log("We dont know this behavior"); s.setIdle(); } }
public void showMenu(bool cond, Vector2 loc, GameObject o, BuildableObject building) { // dont want to enable buttons if we are in override mode if (cond && _cameraController.getOverrideMode()) { return; } _active = cond; _current = o; //Tell MVC which building this is on if (cond) { MVCController.Instance.setLastClicked(o); } //Move the location up a bit? loc.y = loc.y + 30; this.transform.position = loc; // Debug.Log("The Menu loc moves to :" + loc); foreach (Button b in buttons) { b.gameObject.SetActive(cond); //Dont want to do this if were turning them off if (cond && building != null) { //When Enabling Upgrade Buttons, change the button based on the type and level of last structure clicked if (b.name == "Button_Upgrade") { UIButtonCosts buttonScript = b.GetComponent <UIButtonCosts>(); if (buttonScript != null) { BuildableObject.BuildingType type = building.getType(); int level = building.getLevel(); switch (type) { case (BuildableObject.BuildingType.House): buttonScript.ChangeButton("house", level + 1); break; case (BuildableObject.BuildingType.Farm): buttonScript.ChangeButton("farm", level + 1); break; case (BuildableObject.BuildingType.Outpost): buttonScript.ChangeButton("outpost", level + 1); break; case (BuildableObject.BuildingType.Banner): buttonScript.ChangeButton("banner", level + 1); break; case (BuildableObject.BuildingType.TownCenter): buttonScript.ChangeButton("towncenter", level + 1); break; case (BuildableObject.BuildingType.GarbageCan): buttonScript.ChangeButton("garbagecan", level + 1); break; case (BuildableObject.BuildingType.WoodPile): buttonScript.ChangeButton("woodpile", level + 1); break; case (BuildableObject.BuildingType.StonePile): buttonScript.ChangeButton("stonepile", level + 1); break; } } } //If building clicked is town hall, disable demolish button, else enable it if (b.name == "Button_Demolish") { BuildableObject.BuildingType type = building.getType(); if (type == BuildableObject.BuildingType.TownCenter || type == BuildableObject.BuildingType.GarbageCan || type == BuildableObject.BuildingType.WoodPile || type == BuildableObject.BuildingType.StonePile) { b.GetComponent <Button>().interactable = false; } else { b.GetComponent <Button>().interactable = true; } } } } }
// Handles the rat attacking an enemy IEnumerator Attack() { // Play animation //Debug.Log("Attack!Rat@" + Time.time); if (canAttack) { canAttack = false; if (anims) { // Put attack animation here anims.SetTrigger(ATK_ANIMATION_TRIGGER); } // For rodents Rodent _EnemyRodent = currentTarget.GetComponent <Rodent>(); PlayerStats king = currentTarget.GetComponent <PlayerStats>(); if (_EnemyRodent) { if (!_EnemyRodent.isDead()) {// Reduce enemy health _EnemyRodent.Damage(attackDamage); SoundManager.Instance.PlayCombat(); } else { _inRange.Remove(currentTarget); // print("Called from Dead Rodent found"); FindNextTargetInRange(); } } else if (king) { if (!king.isDead()) { king.Damage(attackDamage); SoundManager.Instance.PlayCombat(); } else { _inRange.Remove(currentTarget); FindNextTargetInRange(); } } else { BuildableObject _enemyBuilding = currentTarget.GetComponent <BuildableObject>(); if (_enemyBuilding.getHP() > 0 && _enemyBuilding.getType() != BuildableObject.BuildingType.TownCenter) { _enemyBuilding.Damage(attackDamage); SoundManager.Instance.PlayCombat(); } else { _inRange.Remove(currentTarget); // print("Called from Dead Building found"); FindNextTargetInRange(); } } yield return(new WaitForSeconds(1.16f)); //Length of attack animation canAttack = true; } }
public void AgroRadiusTrigger(Collider2D collision) { // Add a target to the list based on collisions //Debug.Log("Collided with " + collision.gameObject.ToString()); //check that it HAS a parent if (collision.transform.parent) { Rodent unknownRodent = collision.transform.parent.gameObject.GetComponent <Rodent>(); PlayerStats king = collision.transform.parent.gameObject.GetComponent <PlayerStats>(); BuildableObject unknownBuilding = collision.transform.parent.gameObject.GetComponent <BuildableObject>(); if (unknownRodent) { // Debug.LogWarning("Found Rodent" + unknownRodent.getName() + " on team: " + unknownRodent.getTeam()); // Rodent case if (unknownRodent.getTeam() == getEnemyTeam()) { _inRange.Add(unknownRodent.gameObject); //Debug.Log("Rodent added to targets in range " + unknownRodent.getName() + unknownRodent.getTeam()); // print("called from AgroRadiusTrigger"); if (_inRange.Count == 1 && royalGuard) { print("Newest target added to queue: " + unknownRodent.gameObject); currentTarget = unknownRodent.gameObject; } } } else if (unknownBuilding) { if (unknownBuilding.getTeam() == getEnemyTeam()) { // Ensure this isn't a natural resource if (unknownBuilding.getType() != BuildableObject.BuildingType.WoodPile && unknownBuilding.getType() != BuildableObject.BuildingType.StonePile && unknownBuilding.getType() != BuildableObject.BuildingType.GarbageCan) { _inRange.Add(unknownBuilding.gameObject); if (_inRange.Count == 1 && royalGuard) { print("Newest target added to queue: " + currentTarget.ToString()); currentTarget = unknownBuilding.gameObject; } } } } // Special case: Finding King as an attack target else if (team == 2 && king) { _inRange.Add(king.gameObject); if (_inRange.Count == 1) { print("Newest target added to queue: " + king.gameObject); currentTarget = king.gameObject; //Should probably update state to stop moving, and start attacking MovingInIdle = false; } } } }