//COLLISION private void OnTriggerEnter2D(Collider2D collision) { if (_OnPlayer && _OnBuilding) { Debug.LogWarning("Cant have a collider set to building and player!..."); } if (_OnPlayer) { if (this.transform.parent) { Transform t = this.transform.parent; //This all gets double checked in PM, but not refactoring till this is final. if (collision.gameObject == _MoveDummy && !_DigCollider) { t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision); } else if (collision.transform.GetComponent <Searchable>() && !_DigCollider) { t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision); } else if (collision.transform.GetComponent <DiggableTile>() && _DigCollider) { t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision); } else if (collision.transform.parent && !_DigCollider) { // handle if collider is agro range or base range if (collision.transform.GetComponent <BaseHitBox>()) { if (collision.transform.parent.GetComponent <BuildableObject>()) { //Add to our list of interactable things in range t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision); } else if (collision.transform.parent.GetComponent <Rodent>()) { //Add to our list of interactable things in range t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision); } } } } } else if (_OnBuilding) { if (this.transform.parent) { Transform t = this.transform.parent; if (t) { bBanner banner = t.GetComponent <bBanner>(); if (banner) { // handle if collider is agro range or base range if (collision.transform.GetComponent <AttackRadius>()) { Transform colliderParent = collision.gameObject.transform.parent; if (colliderParent) { // Debug.Log(banner.gameObject.name // + " Collided with :" + colliderParent.gameObject); Rodent r = colliderParent.GetComponent <Rodent>(); if (r) { //Set Max HP //Debug.Log("HP was:" + r.getHpMax()); r.setHpMax(r.getHpMax() * banner.getHPBonus()); // Debug.Log("HP now:" + r.getHpMax()); // Set HP r.setHp(r.getHp() * banner.getHPBonus()); //set Gathering Bonuses // print(r.name + " gather was: " + r.getGatherRate()); r.setGatherRate((int)(r.getGatherRate() * banner.getGatherBonus())); // print(r.name + " gather is now: " + r.getGatherRate()); } } } } } } } }
// Called from MVC controller public void DemolishSomething() { //Dismiss all workers dismissCurrentWorker(); SoundManager.Instance.PlayDemolish(); SoundManager.Instance.PlayDemolish(); // Debug.Log("Time to Destroy Something" ); switch (eType) { case (BuildingType.House): bHouse house = this.GetComponent <bHouse>(); house.DemolishAction(_level); Destroy(house); eType = BuildingType.Vacant; eState = BuildingState.Available; _sr.sprite = _sStateConstruction; // Debug.Log("Destroyed a house"); break; case (BuildingType.Farm): bFarm farm = this.GetComponent <bFarm>(); farm.DemolishAction(); Destroy(farm); eType = BuildingType.Vacant; eState = BuildingState.Building; _sr.sprite = _sStateConstruction; // Debug.Log("Destroyed a Farm"); break; case (BuildingType.Banner): bBanner banner = this.GetComponent <bBanner>(); Destroy(banner); eType = BuildingType.Vacant; eState = BuildingState.Building; _sr.sprite = _sStateConstruction; Destroy(this.GetComponent <Animator>()); // Debug.Log("Destroyed a Banner"); break; case (BuildingType.Outpost): bOutpost outpost = this.GetComponent <bOutpost>(); outpost.DemolishAction(); Destroy(outpost); eType = BuildingType.Vacant; eState = BuildingState.Building; _sr.sprite = _sStateConstruction; //Need to Reset Worker Object to Base // tell UI menu RemoveOutpostWorkers UIAssignmentMenu.Instance.RemoveOutpostWorkers(_Workers); // tell game manager PlayerOutpostDestroyed GameManager.Instance.PlayerOutpostDestroyed(this); ResetWorkers(); // Debug.Log("Destroyed an Outpost"); break; case (BuildingType.TownCenter): bTownCenter btc = this.GetComponent <bTownCenter>(); Destroy(btc); eType = BuildingType.Vacant; eState = BuildingState.Building; _sr.sprite = _sStateConstruction; // Debug.Log("Destroyed a TownCenter"); break; case (BuildingType.GarbageCan): bGarbageCan garbagecan = this.GetComponent <bGarbageCan>(); Destroy(garbagecan); eType = BuildingType.Vacant; eState = BuildingState.Building; _sr.sprite = _sStateConstruction; break; case (BuildingType.WoodPile): bWoodPile wp = this.GetComponent <bWoodPile>(); Destroy(wp); eType = BuildingType.Vacant; eState = BuildingState.Building; _sr.sprite = _sStateConstruction; break; case (BuildingType.StonePile): bStonePile sp = this.GetComponent <bStonePile>(); Destroy(sp); eType = BuildingType.Vacant; eState = BuildingState.Building; _sr.sprite = _sStateConstruction; break; } //Drop Demolished Resources GameObject pickup = Resources.Load <GameObject>("ResourceIcons/Collectable_Resource"); if (pickup) { if (_level >= 1) { GameObject ppp = GameObject.Instantiate(pickup, this.transform.position, this.transform.rotation); CoinResource cr = ppp.GetComponent <CoinResource>(); cr.setResourceType(ResourceManagerScript.ResourceType.Trash); cr.setResourceAmount(2 * _level); } if (_level >= 2) { GameObject ppp = GameObject.Instantiate(pickup, this.transform.position, this.transform.rotation); CoinResource cr = ppp.GetComponent <CoinResource>(); cr.setResourceType(ResourceManagerScript.ResourceType.Wood); cr.setResourceAmount(2 * _level); } if (_level >= 3) { GameObject ppp = GameObject.Instantiate(pickup, this.transform.position, this.transform.rotation); CoinResource cr = ppp.GetComponent <CoinResource>(); cr.setResourceType(ResourceManagerScript.ResourceType.Stone); cr.setResourceAmount(2 * _level); } } UpdateState(); _DestroyMenu.showMenu(false, Vector3.zero, null, this); _level = 0; // handle the other stuff in demolish complete i guess StartCoroutine(DemolishCoroutine()); }
private void OnTriggerExit2D(Collider2D collision) { if (_OnPlayer) { if (this.transform.parent) { Transform t = this.transform.parent; if (collision.transform.GetComponent <Searchable>() && !_DigCollider) { t.GetComponent <PlayerMovement>().OnTriggerExit2D(collision); } else if (collision.transform.GetComponent <DiggableTile>() && _DigCollider) { t.GetComponent <PlayerMovement>().OnTriggerExit2D(collision); } else if (collision.transform.parent && !_DigCollider) { // handle if collider is agro range or base range if (collision.transform.GetComponent <BaseHitBox>()) { if (collision.transform.parent.GetComponent <BuildableObject>()) { //Add to our list of interactable things in range t.GetComponent <PlayerMovement>().OnTriggerExit2D(collision); } else if (collision.transform.parent.GetComponent <Rodent>()) { //Add to our list of interactable things in range t.GetComponent <PlayerMovement>().OnTriggerExit2D(collision); } } } } } else if (_OnBuilding) { if (this.transform.parent) { Transform t = this.transform.parent; if (t) { bBanner banner = t.GetComponent <bBanner>(); if (banner) { // handle if collider is agro range or base range if (collision.transform.GetComponent <AttackRadius>()) { Transform colliderParent = collision.gameObject.transform.parent; if (colliderParent) { // Debug.Log(banner.gameObject.name // + " Collided with :" + colliderParent.gameObject); Rodent r = colliderParent.GetComponent <Rodent>(); if (r) { //Set Max HP // Debug.Log("HP was:" + r.getHpMax()); r.setHpMax(r.getHpMax() / banner.getHPBonus()); // Debug.Log("HP now:" + r.getHpMax()); // Set HP r.setHp(r.getHp() / banner.getHPBonus()); //Undo Gather bonus r.setGatherRate((int)(r.getGatherRate() / banner.getGatherBonus())); } } } } } } } }