Beispiel #1
0
    void RandomState(MJStateManager stateManager)
    {
        stateManager.animator.SetBool("isDancing", false);
        //stateManager.otherIsLeader = false;
        RoleManager role = stateManager.gameObject.GetComponent <RoleManager>();
        int         rand = UnityEngine.Random.Range(0, 100);

        if (rand <= 10 && role.GetCurrentRole() == 0)
        {
            stateManager.RandomState();
        }

        if (rand <= 10 && role.GetCurrentRole() == 2)
        {
            stateManager.RandomSoldierState();
        }

        if (rand <= 10 && (role.GetCurrentRole() == 3 || role.GetCurrentRole() == 4))
        {
            stateManager.RandomFarmerState();
        }

        if (role.GetCurrentRole() == 5 && !stateManager.hasFood)
        {
            stateManager.curState = 16; //forage action
        }

        if (role.GetCurrentRole() == 5 && stateManager.hasFood)
        {
            stateManager.curState = 17;
        }
    }
Beispiel #2
0
    private void Hide(MJStateManager stateManager)
    {
        Destroy(stateManager.food);
        stateManager.hasFood = false;
        onDestination        = stateManager.onDestination;
        if (onDestination)
        {
            target = GetTarget(stateManager);
            // Debug.Log(target);
            stateManager.navMeshAgent.SetDestination(target);
            // Debug.Log(stateManager.navMeshAgent.destination);
            stateManager.onDestination      = false;
            stateManager.navMeshAgent.speed = 0.2f;
            //Debug.Log("test");
        }

        if (Vector3.Distance(stateManager.transform.position, target) <= .1f)
        {
            stateManager.onDestination      = true;
            stateManager.navMeshAgent.speed = 0.1f;
            stateManager.curState           = 0;
            stateManager.hide = true;
        }
        //Debug.Log(onDestination);
    }
Beispiel #3
0
    private void GoToFood(MJStateManager stateManager)
    {
        timer += Time.deltaTime;
        if (timer >= 10)
        {
            if (!stateManager.hasFood)
            {
                target = FindFood(stateManager);
                stateManager.navMeshAgent.SetDestination(target);
            }
            timer = 0;
        }
        //onDestination = stateManager.onDestination;
        if (Vector3.Distance(stateManager.transform.position, target) > .2f)
        {
            target = FindFood(stateManager);
            stateManager.navMeshAgent.SetDestination(target);
            //Debug.Log(stateManager.navMeshAgent.destination);
            //stateManager.onDestination = false;
        }

        if (stateManager.food == null)
        {
            target = FindFood(stateManager);
            stateManager.navMeshAgent.SetDestination(target);
        }

        if (Vector3.Distance(stateManager.transform.position, target) <= .125f)
        {
            //stateManager.onDestination = true;
            FoodPickup(stateManager);
            stateManager.curState = 17;
        }
    }
Beispiel #4
0
 void MakeGreeting(MJStateManager stateManager)
 {
     if (!stateManager.soundCommunication.sourceNear.isPlaying)
     {
         stateManager.AudioAction("greeting");
     }
 }
Beispiel #5
0
 void Alerting(MJStateManager stateManager)
 {
     if (!stateManager.soundCommunication.sourceNear.isPlaying)
     {
         stateManager.AudioAction("alert");
     }
 }
Beispiel #6
0
    public void BringToHouse(MJStateManager stateManager)
    {
        wanderTimer  += Time.deltaTime;
        onDestination = stateManager.onDestination;

        if (wanderTimer >= limit && !onDestination)
        {
            target = GetTarget(stateManager);
            stateManager.navMeshAgent.SetDestination(target);
            wanderTimer = 0;
        }

        if (onDestination)
        {
            target = GetTarget(stateManager);
            stateManager.navMeshAgent.SetDestination(target);
            stateManager.onDestination = false;
        }

        if (Vector3.Distance(stateManager.transform.position, target) <= .1f)
        {
            stateManager.onDestination = true;
            Destroy(stateManager.food.gameObject);
            stateManager.hasFood = false;
            stateManager.animator.SetBool("holding", false);
            stateManager.curState = 16;
        }
    }
Beispiel #7
0
 private void DoActions(MJStateManager stateManager)
 {
     for (int i = 0; i < actions.Length; i++)
     {
         actions[i].Act(stateManager);
     }
 }
Beispiel #8
0
 void SmallTalk(MJStateManager stateManager)
 {
     if (!stateManager.soundCommunication.sourceNear.isPlaying && UnityEngine.Random.Range(0, 100) < 1)
     {
         stateManager.AudioAction("smalltalk");
     }
 }
Beispiel #9
0
 private bool CheckNeighbor(MJStateManager stateManager)
 {
     stateManager.otherIsLeader = false;
     GameObject[] mojili = GameObject.FindGameObjectsWithTag("Mojili");
     for (int i = 0; i < mojili.Length; i++)
     {
         float tempfriendDistance = Vector3.Distance(stateManager.transform.position, mojili[i].transform.position);
         //Debug.Log(tempfriendDistance);
         if ((tempfriendDistance <= friendDistance) && (mojili[i].name != stateManager.gameObject.name) && stateManager.waitIsOver)
         {
             //Debug.Log("test");
             stateManager.interactionTarget = mojili[i];
             Debug.Log(mojili[i].GetComponent <RoleManager>().GetCurrentRole() + mojili[i].name);
             if (mojili[i].GetComponent <RoleManager>().GetCurrentRole() == 1)
             {
                 stateManager.otherIsLeader = true;
             }
             mojili[i].GetComponent <MJStateManager>().isInteracting = true;
             stateManager.isInteracting = true;
             stateManager.onDestination = true;
             return(true);
         }
     }
     return(false);
 }
 public bool CheckWander(MJStateManager stateManager)
 {
     if (stateManager.curState == 6 )
     {
         return true;
     }
     else return false;
 }
Beispiel #11
0
 void TestTalk(MJStateManager stateManager)
 {
     if (!stateManager.soundCommunication.sourceNear.isPlaying && UnityEngine.Random.Range(0, 100) < 10)
     {
         stateManager.AudioAction("smalltalk");
     }
     stateManager.StartInteractiontimer();
 }
Beispiel #12
0
 void PlayMusic(MJStateManager stateManager)
 {
     stateManager.isMakingMusic = true;
     if (!stateManager.soundCommunication.sourceNear.isPlaying)
     {
         stateManager.AudioAction("music");
     }
 }
Beispiel #13
0
 void FollowSound(MJStateManager stateManager)
 {
     if (!stateManager.soundCommunication.sourceNear.isPlaying)
     {
         stateManager.AudioAction("followme");
     }
     stateManager.StartInteractiontimer();
 }
Beispiel #14
0
 void ActTimer(MJStateManager stateManager)
 {
     stateManager.waitIsOver = false;
     timer += Time.deltaTime;
     if (timer >= 1)
     {
         stateManager.waitIsOver = true;
         timer = 0;
     }
 }
Beispiel #15
0
 public bool CheckForage(MJStateManager stateManager)
 {
     if (stateManager.curState == 17)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #16
0
 private bool CheckCurrentState(MJStateManager stateManager)
 {
     if (stateManager.isInteracting && stateManager.otherIsLeader)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #17
0
 private bool CheckCurrentState(MJStateManager stateManager)
 {
     if (stateManager.curState == 10)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #18
0
 bool CheckState(MJStateManager stateManager)
 {
     if (stateManager.curState == 14)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #19
0
 public bool InHiding(MJStateManager stateManager)
 {
     testTimer += Time.deltaTime;
     if (stateManager.hide && testTimer >= endTimer)
     {
         testTimer             = 0;
         stateManager.curState = 0;
         return(true);
     }
     return(false);
 }
Beispiel #20
0
 public bool CheckWander(MJStateManager stateManager)
 {
     if (!stateManager.hide)
     {
         stateManager.curState = 1;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #21
0
 private bool CheckCurrentState(MJStateManager stateManager)
 {
     if (stateManager.isInteracting && stateManager.gameObject.GetComponent <RoleManager>().GetCurrentRole() != 1 && !stateManager.otherIsLeader && stateManager.onIntDestination && stateManager.isInteractee)
     {
         stateManager.onDestination = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #22
0
 private bool CheckCurrentState(MJStateManager stateManager)
 {
     if (stateManager.curState == 1)
     {
         stateManager.onDestination = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #23
0
 void FoodPickup(MJStateManager stateManager)
 {
     if (stateManager.food != null)
     {
         stateManager.food.transform.rotation = stateManager.transform.rotation;
         Vector3 targetPos = stateManager.transform.position + stateManager.transform.forward * stateManager.offset.z + stateManager.transform.right * stateManager.offset.x + stateManager.transform.up * stateManager.offset.y;
         stateManager.food.transform.position = targetPos;
         stateManager.food.GetComponent <Rigidbody>().isKinematic = true;
         stateManager.food.GetComponent <FoodDecay>().pickedUp    = true;
         stateManager.animator.SetBool("holding", true);
     }
 }
Beispiel #24
0
    void FollowTarget(MJStateManager stateManager)
    {
        if (stateManager.followTarget != null)
        {
            stateManager.navMeshAgent.SetDestination(stateManager.followTarget.transform.position);
            stateManager.StartInteractiontimer();
        }

        if (stateManager.followTarget == null)
        {
            stateManager.coolDown = true;
        }
    }
Beispiel #25
0
 bool CheckInteraction(MJStateManager stateManager)
 {
     if (stateManager.isInteracting && !stateManager.coolDown && stateManager.interactionTarget != null && stateManager.curState != 5)
     {
         //Debug.Log("interaction");
         if (stateManager.interactionTarget.GetComponent <RoleManager>().GetCurrentRole() == 1)
         {
             stateManager.otherIsLeader = true;
         }
         return(true);
     }
     return(false);
 }
Beispiel #26
0
 public bool Timer(MJStateManager stateManager)
 {
     testTimer += Time.deltaTime;
     if (testTimer >= endTimer)
     {
         stateManager.curState = 0;
         testTimer             = 0;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #27
0
 private bool CheckCurrentState(MJStateManager stateManager)
 {
     if (stateManager.curState == 5)
     {
         stateManager.isMakingMusic = true;
         //stateManager.isInteracting = false;
         stateManager.onDestination = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #28
0
    public bool SafetyTest(MJStateManager stateManager)
    {
        Camera mainCamera = Camera.main;

        if (Vector3.Distance(mainCamera.transform.position, stateManager.transform.position) <= .25f)
        {
            Debug.Log("Panic!!");
            stateManager.inDanger = true;
            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #29
0
    public Vector3 RandomNavmeshLocation(float radius, MJStateManager stateManager)
    {
        Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * radius;

        //randomDirection += stateManager.transform.position;
        randomDirection += Vector3.zero;
        UnityEngine.AI.NavMeshHit hit;
        Vector3 finalPosition = Vector3.zero;

        if (UnityEngine.AI.NavMesh.SamplePosition(randomDirection, out hit, radius, 1))
        {
            finalPosition = hit.position;
        }
        return(finalPosition);
    }
Beispiel #30
0
    private void GoHome(MJStateManager stateManager)
    {
        onDestination = stateManager.onDestination;
        if (onDestination)
        {
            target = GetTarget(stateManager);
            stateManager.navMeshAgent.SetDestination(target);
            stateManager.onDestination = false;
        }

        if (Vector3.Distance(stateManager.transform.position, target) <= .1f)
        {
            stateManager.onDestination = true;
        }
    }