示例#1
0
 // Update is called once per frame
 public void UpdateState()
 {
     if (!isSleeping)
     {
         isSleeping  = true;
         currentTime = Time.fixedTime;
     }
     else
     {
         if (survivor.getSurvivorTiredness() < 90)
         {
             if (Time.fixedTime - currentTime >= 0.5f)
             {
                 survivor.setSurvivorTiredness(survivor.getSurvivorTiredness() + 10);
                 if (survivor.getSurvivorHealth() + 1 < 100)
                 {
                     survivor.setSurvivorHealth(survivor.getSurvivorHealth() + 1);
                 }
                 currentTime = Time.fixedTime;
             }
         }
         else
         {
             isSleeping = false;
             survivor.home.GetComponent <House>().setSign(0);
             ToHomeState();
         }
     }
 }
示例#2
0
    // Update is called once per frame
    public void UpdateState()
    {
        survivor.GetComponent <Statistics>().AgentVisible(false);

        if (survivor.getSurvivorHunger() < 15 || survivor.getSurvivorThirst() < 15)
        {
            Debug.Log("MANGER");
            ToNourrishState();
        }

        else if (survivor.getSurvivorHealth() <= 50)
        {
            Debug.Log("SOIN");
            ToHealState();
        }

        else if (survivor.getSurvivorTiredness() < 15)
        {
            Debug.Log("DODO");
            survivor.home.GetComponent <House>().setSign(1);
            ToSleepState();
        }

        else if (survivor.collectState.getNoResources() && (!survivor.home.GetComponent <House>().haveFarm ||
                                                            !survivor.home.GetComponent <House>().haveWell) && survivor.home.GetComponent <House>().LowResources())
        {
            survivor.home.GetComponent <House>().setSign(0);
            survivor.GetComponent <Statistics>().AgentVisible(true);
            survivor.sword.enabled = true;
            Debug.Log("A LA BATAILLE!");
            ToFightState();
        }

        else if ((!survivor.home.GetComponent <House>().haveWell || !survivor.home.GetComponent <House>().haveFarm) && survivor.home.GetComponent <House>().getScrap() >= 2)
        {
            survivor.home.GetComponent <House>().setSign(3);
            Debug.Log("BUILDING");
            ToBuildState();
        }

        else if (survivor.home.GetComponent <House>().getSafety() < 10 && survivor.home.GetComponent <House>().getScrap() >= 1)
        {
            survivor.home.GetComponent <House>().setSign(2);
            Debug.Log("REPARO!");
            ToRepairState();
        }

        else
        {
            survivor.home.GetComponent <House>().setSign(0);
            survivor.GetComponent <Statistics>().AgentVisible(true);
            ToCollectState();
        }
    }
示例#3
0
    // Update is called once per frame
    public void UpdateState()
    {
        if (survivor.getSurvivorHunger() < 15 || survivor.getSurvivorThirst() < 15)
        {
            stateChanged = true;
            ToNourrishState();
        }

        if (survivor.getSurvivorHealth() <= 50)
        {
            if (survivor.survivorBandage > 0)
            {
                survivor.survivorBandage--;
                survivor.setSurvivorHealth(100.0f);
            }
            else
            {
                moving               = true;
                goingHome            = true;
                collectingRessources = true;
            }
        }


        if (currentTime >= 15.0f)
        {
            noResources = true;
        }
        else
        {
            currentTime += 0.01f;
        }

        if (!moving && !stateChanged)
        {
            /*
             * if (!wayPointsListInstantiated)
             * {
             *  wayPointsList = survivor.getWayPointsList();
             *  wayPointsListInstantiated = true;
             * }
             */
            survivor.getWayPointsList().Clear();

            rX = Random.Range(survivor.transform.position.x - movementRange, survivor.transform.position.x + movementRange);
            rZ = Random.Range(survivor.transform.position.z - movementRange, survivor.transform.position.z + movementRange);

            point = new Vector3(rX, survivor.transform.position.y, rZ);

            // CHECK WALL 1
            if (Physics.Linecast(new Vector3(survivor.transform.position.x, survivor.transform.position.y + 0.2f, survivor.transform.position.z),
                                 new Vector3(point.x, point.y + 0.2f, point.z), out hit))
            {
                if (hit.collider.gameObject.tag == "Wall")
                {
                    int indiceX;
                    int indiceZ;

                    if (point.x - (int)point.x <= 0.5f)
                    {
                        indiceX = (int)point.x;
                    }
                    else
                    {
                        indiceX = (int)point.x + 1;
                    }

                    if (point.z - (int)point.z <= 0.5f)
                    {
                        indiceZ = (int)point.z;
                    }
                    else
                    {
                        indiceZ = (int)point.z + 1;
                    }

                    if (indiceX < 0)
                    {
                        indiceX = 0;
                    }
                    else if (indiceX > survivor.getMap().GetComponent <Map>().getSize() - 1)
                    {
                        indiceX = survivor.getMap().GetComponent <Map>().getSize() - 1;
                    }

                    if (indiceZ < 0)
                    {
                        indiceZ = 0;
                    }
                    else if (indiceZ > survivor.getMap().GetComponent <Map>().getSize() - 1)
                    {
                        indiceZ = survivor.getMap().GetComponent <Map>().getSize() - 1;
                    }

                    if (survivor.getMap().GetComponent <Map>().getMap()[indiceX, indiceZ] == 1)
                    {
                        moving = false;
                    }
                }
            }

            //CHECK WALL 2
            if (point.x <= 0.7f || point.x >= survivor.getMap().GetComponent <Map>().getSize() - 2 || point.z <= 0.7f || point.z >= survivor.getMap().GetComponent <Map>().getSize() - 2)
            {
                moving = false;
            }
            else
            {
                moving = true;
                survivor.checkBuildingHit(point, null, moving, false);
                survivor.getWayPointsList().Insert(survivor.getWayPointsList().Count, point);
                if (survivor.destInBuilding)
                {
                    moving = false;
                    survivor.destInBuilding = false;
                }
            }
        }
        else
        {
            /*Debug.Log("#####");
             * foreach (Vector3 v in survivor.getWayPointsList())
             *  Debug.Log(v);*/

            //ROAMING
            if (!collectingRessources && !goingHome)
            {
                survivor.transform.position = Vector3.MoveTowards(survivor.transform.position, survivor.getWayPointsList()[0], survivor.speed * Time.deltaTime);
                //Debug.DrawLine(survivor.transform.position, point);

                if (Vector3.Distance(survivor.transform.position, survivor.getWayPointsList()[0]) < 0.3f)
                {
                    if (survivor.getWayPointsList().Count == 1)
                    {
                        moving = false;
                    }
                    else
                    {
                        survivor.getWayPointsList().RemoveAt(0);
                    }
                }
            }

            //COLLECTING
            else if (collectingRessources && !goingHome)
            {
                survivor.transform.position = Vector3.MoveTowards(survivor.transform.position, survivor.getWayPointsList()[0], survivor.speed * Time.deltaTime);

                if (Vector3.Distance(survivor.transform.position, survivor.getWayPointsList()[0]) < 1.3f)
                {
                    survivor.gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;

                    if (buildingCollected != null)
                    {
                        //COLLECTING FOOD
                        if (survivor.survivorFood + 1 <= 3 && buildingCollected.GetComponent <Building>().getFood() > 0)
                        {
                            survivor.survivorFood += 1;
                            buildingCollected.GetComponent <Building>().setFood(buildingCollected.GetComponent <Building>().getFood() - 1);
                            currentTime = 0.0f;
                            string s = buildingCollected.tag;
                            if ((buildingCollected.GetComponent(s) as Building).selected)
                            {
                                (buildingCollected.GetComponent(s) as Building).Details();
                            }
                        }

                        //COLLECTING WATER
                        if (survivor.survivorWater + 1 <= 3 && buildingCollected.GetComponent <Building>().getWater() > 0)
                        {
                            survivor.survivorWater += 1;
                            buildingCollected.GetComponent <Building>().setWater(buildingCollected.GetComponent <Building>().getWater() - 1);
                            currentTime = 0.0f;
                            string s = buildingCollected.tag;
                            if ((buildingCollected.GetComponent(s) as Building).selected)
                            {
                                (buildingCollected.GetComponent(s) as Building).Details();
                            }
                        }

                        //COLLECTING BANDAGE
                        if (survivor.survivorBandage + 1 <= 3 && buildingCollected.GetComponent <Building>().getBandage() > 0)
                        {
                            survivor.survivorBandage += 1;
                            buildingCollected.GetComponent <Building>().setBandage(buildingCollected.GetComponent <Building>().getBandage() - 1);
                            string s = buildingCollected.tag;
                            if ((buildingCollected.GetComponent(s) as Building).selected)
                            {
                                (buildingCollected.GetComponent(s) as Building).Details();
                            }
                        }

                        //COLLECTING SCRAP
                        if (survivor.survivorScrap + 1 <= 3 && buildingCollected.GetComponent <Building>().getScrap() > 0)
                        {
                            survivor.survivorScrap += 1;
                            buildingCollected.GetComponent <Building>().setScrap(buildingCollected.GetComponent <Building>().getScrap() - 1);
                            string s = buildingCollected.tag;
                            if ((buildingCollected.GetComponent(s) as Building).selected)
                            {
                                (buildingCollected.GetComponent(s) as Building).Details();
                            }
                        }
                    }

                    else
                    {
                        collectingRessources = false;
                        moving = false;
                    }

                    if (survivor.survivorFood == 3 || survivor.survivorWater == 3 || survivor.survivorBandage == 3 || survivor.survivorScrap == 3)
                    {
                        if (survivor.homeSet)
                        {
                            collectingRessources = false;
                            goingHome            = true;
                        }
                        else
                        {
                            collectingRessources = false;
                            moving = false;
                        }
                    }

                    else
                    {
                        collectingRessources = false;
                        moving = false;
                    }
                }
            }

            //GOING HOME
            else if (!collectingRessources && goingHome)
            {
                //if (survivor.survivorFood < 3 && survivor.survivorWater < 3 && survivor.survivorBandage < 3)
                //  moving = false;

                if (!roadHomeSet)
                {
                    survivor.getWayPointsList().Clear();
                    survivor.checkBuildingHit(survivor.home.transform.position, survivor.home, moving, true);
                    survivor.getWayPointsList().Insert(survivor.getWayPointsList().Count, survivor.home.transform.position);
                    roadHomeSet = true;
                }

                if (survivor.getWayPointsList().Count > 1)
                {
                    detectionRange = 0.3f;
                }
                else
                {
                    detectionRange = 1.3f;
                }

                survivor.transform.position = Vector3.MoveTowards(survivor.transform.position, survivor.getWayPointsList()[0], survivor.speed * Time.deltaTime);

                if (Vector3.Distance(survivor.transform.position, survivor.getWayPointsList()[0]) < detectionRange)
                {
                    if (survivor.getWayPointsList().Count == 1)
                    {
                        survivor.gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;

                        survivor.home.GetComponent <House>().setFood(survivor.home.GetComponent <House>().getFood() + survivor.survivorFood);
                        survivor.survivorFood = 0;
                        survivor.home.GetComponent <House>().setWater(survivor.home.GetComponent <House>().getWater() + survivor.survivorWater);
                        survivor.survivorWater = 0;
                        survivor.home.GetComponent <House>().setWater(survivor.home.GetComponent <House>().getBandage() + survivor.survivorBandage);
                        survivor.survivorBandage = 0;
                        survivor.home.GetComponent <House>().setWater(survivor.home.GetComponent <House>().getScrap() + survivor.survivorScrap);
                        survivor.survivorScrap = 0;

                        if (survivor.home.GetComponent <House>().selected)
                        {
                            survivor.home.GetComponent <House>().Details();
                        }

                        goingHome   = false;
                        roadHomeSet = false;
                        moving      = false;

                        ToHomeState();
                        stateChanged = true;
                    }
                    else
                    {
                        survivor.getWayPointsList().RemoveAt(0);
                    }
                }
            }
        }

        if (stateChanged)
        {
            roadHomeSet          = false;
            goingHome            = false;
            collectingRessources = false;
            moving       = false;
            stateChanged = false;
        }
    }