Example #1
0
    void Start()
    {
        // plan = gameObject.GetComponent<GoapPlanner>().plan; //i do this in goapplanner
        // UIcontent = GameObject.Find("Content");
        gp = GetComponent <GoapPlanner>();
        Node start = new Node(GameM.caravanState, GameM.inventoryState, -1, null);

        plan = gp.buildPlan(start);
        //  planCopy = new Stack<Node>();
        thief         = th.GetComponent <NavMeshAgent>();
        textInventory = new GameObject[] { TuInv, SaInv, CaInv, CiInv, ClInv, PeInv, SuInv };
        textCaravan   = new GameObject[] { TuCar, SaCar, CaCar, CiCar, ClCar, PeCar, SuCar };

        buildScroll();



        // plan = gp.plan();
        // velocity = player.velocity;
        // int count = 0;


        // if (p1== null) Debug.Log("hi");

        List <GameObject> ptexts = new List <GameObject> {
            p1, p2, p3, p4, p5, p6, p7, p8
        };
        //if(ptexts.Count == 0) Debug.Log("hi");
        List <Vector3> posStatic = new List <Vector3> {
            GameM.pos1, GameM.pos2, GameM.pos3, GameM.pos4, GameM.pos5, GameM.pos6, GameM.pos7, GameM.pos8
        };

        pos = new List <Vector3> {
            GameM.pos1, GameM.pos2, GameM.pos3, GameM.pos4, GameM.pos5, GameM.pos6, GameM.pos7, GameM.pos8
        };
        Shuffle(pos);
        pos.Add(GameM.caravanPos);
        pos.Add(GameM.caravanPos);

        // int count = 0;
        for (int i = 0; i < ptexts.Count; i++)
        {
            tm      = ptexts[i].GetComponent <TextMesh>();
            tm.text = "T" + (pos.IndexOf(posStatic[i]) + 1);
            //count++;
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (wait && !gameEnded)
        {
            StartCoroutine(waitPause());
        }
        if (stolenFrom && !gameEnded)
        {
            // pause = true;
            //change plan
            // Debug.Log("hi");

            // currentAction.inventory = GameM.inventoryState;
            //currentAction.caravan = GameM.caravanState;
            //updateStupidGrid(currentAction);
            Node start = new Node(clone(GameM.caravanState), clone(GameM.inventoryState), -1, null);
            updateStupidGrid(start);
            plan = gp.buildPlan(start);
            // Destroy
            GameObject[] rows = GameObject.FindGameObjectsWithTag("row");
            foreach (GameObject row in rows)
            {
                Destroy(row);
            }
            buildScroll();
            performingAction = false;
            Debug.Log("CHANGE OF PLANS");
            // plan.Pop(); //pop the start node as it is useless
            stolenFrom = false;
            wait       = true;
            if (pause)
            {
                //pause = false;
                //wait = true;
                //resume();
            }
        }



        else if (!pause && !gameEnded)
        {
            if (!performingAction && !stolenFrom && !gameEnded)
            {
                performingAction = true;
                if (plan.Count == 0) //game has ended
                {
                    currentAction = null;
                    gameEnded     = true;
                    return;
                }
                if (plan.Count > 0)
                {
                    currentAction = plan.Pop();
                }

                // Debug.Log(currentAction.ToString());

                Ray        ray = cam.ScreenPointToRay(cam.WorldToScreenPoint(pos[currentAction.actionIndex]));
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit) && currentAction != null)
                {
                    player.SetDestination(hit.point);
                    //velocity = player.velocity;
                    //StartCoroutine(performAction());
                }
            }
            if (!player.pathPending && performingAction && !stolenFrom && !gameEnded)
            {
                if (player.remainingDistance <= player.stoppingDistance)
                {
                    if (!player.hasPath || player.velocity.sqrMagnitude == 0f)
                    {
                        // Done
                        // Debug.Log("remaining distance: " + player.remainingDistance);
                        if (currentAction != null || currentAction.actionIndex != null)
                        {
                            gp.actions[currentAction.actionIndex].updateGameState(currentAction);
                            performingAction = false;
                            updateStupidGrid(currentAction);
                            Destroy(GameObject.Find("Content").transform.GetChild(2).gameObject);
                        }

                        //Debug.Log(currentAction.ToString());
                    }
                }
            }
            if (Input.GetKeyDown(KeyCode.Equals))
            {
                Time.timeScale *= 2;

                //velocity *= 2;
                //player.speed *= 2;
            }
            if (Input.GetKeyDown("-"))
            {
                Time.timeScale *= 0.5f;
                //player.velocity *= 0.5f;
            }
        }


        if (Input.GetKeyDown("space") && !gameEnded)
        {
            pause = !pause;
            if (pause == false)
            {
                resume();
            }
            else
            {
                PauseSim();
            }

            //player.velocity *= 0.5f;
        }
    }