//Set this agent to idle status public void SetIdle() { this.animator.SetInteger("animation", 0); this.currentActivity = EActivity.Idle; this.bInActivity = false; if (navControl) { //this.navControl.agent.speed = this.navControl.originalSpeed; //this.navControl.agent.angularSpeed = this.navControl.originalAngularSpeed; navControl.agent.isStopped = false; //navControl.agent.velocity = navControl.recordVelocity; } else { GetComponent <CharacterController>().enabled = true; } //Test stop move and immediatly resume moving currentActivityCoolDown = activityCoolDown; }
//Group activity: trade public void Trade() { //stop StopMove(); meetAnimalCharacter.StopMove(); this.agreeCommunication = true; this.bInActivity = true; //meetAnimalCharacter.bInActivity = true; this.animator.SetInteger("animation", 0); this.currentActivity = EActivity.Trade; //if already in trade event if (meetAnimalCharacter.agreeCommunication) { return; } //Debug.LogError("Trade: " + name + " look at " + meetAnimalCharacter.name); //Wait another animalcharacter's response StartCoroutine(WaitTradeRequest(tradeWaitTime)); IEnumerator WaitTradeRequest(float waitTime) { float accumulatedWaitTime = 0f; while (accumulatedWaitTime < waitTime) { accumulatedWaitTime += Time.deltaTime; Debug.Log("Trade look at movement " + this.name + " : " + meetAnimalCharacter.name); this.transform.LookAt(meetAnimalCharacter.transform.position); meetAnimalCharacter.transform.LookAt(this.transform.position); if (meetAnimalCharacter.agreeCommunication) { break; } yield return(null); } //yield return new WaitForSeconds(.1f); //just for delay //if both two agents agree to trade if (this.agreeCommunication && meetAnimalCharacter.agreeCommunication) { Debug.Log("Animal Character !!!Trade!!!: " + this.name + " with " + meetAnimalCharacter.name); APickupObject myObject = this.holdObject; APickupObject hisObject = meetAnimalCharacter.holdObject; //Trade event if (myObject && hisObject) //case 1: exchange goods { //Debug.Log("Animal Character Trade case 1"); myObject.Drop(this); myObject.occupied = true; hisObject.Drop(meetAnimalCharacter); hisObject.occupied = true; myObject.Pickup(meetAnimalCharacter); hisObject.Pickup(this); } else if (myObject == null && hisObject == null) //case 2: nothing happens { //Debug.Log("Animal Character Trade case 2"); } else if (myObject != null && hisObject == null) //case 3: sell { //Debug.Log("Animal Character Trade case 3"); if (meetAnimalCharacter.money > myObject.price) { myObject.Drop(this); myObject.occupied = true; myObject.Pickup(meetAnimalCharacter); this.money += myObject.price; meetAnimalCharacter.money -= myObject.price; } } else if (myObject == null && hisObject != null) //case 4: buy { //Debug.Log("Animal Character Trade case 4"); if (this.money > hisObject.price) { hisObject.Drop(meetAnimalCharacter); hisObject.occupied = true; hisObject.Pickup(this); this.money -= hisObject.price; meetAnimalCharacter.money += hisObject.price; } } } else { //Debug.LogError("Animal Character No trade"); } if (meetAnimalCharacter) { meetAnimalCharacter.SetIdle(); meetAnimalCharacter.agreeCommunication = false; //Debug.LogError("Trade Complete 1"); meetAnimalCharacter.meetAnimalCharacter = null; meetAnimalCharacter = null; //Debug.LogError("Trade Complete 2"); } this.SetIdle(); this.agreeCommunication = false; } }