コード例 #1
0
ファイル: missionMgr.cs プロジェクト: rosco-y/Geography-Quest
    public bool Validate(mission m)
    {
        bool missionComplete = true;

        // a mission with zero tokens is always false
        if (m.tokens.Count <= 0)
        {
            missionComplete = false;
        }

        // for all tokens in the mission
        for (int i = 0; i < m.tokens.Count; i++)
        {
            // search for each one in the cache
            // if it is not in the cache, then abort->this mission is not complete yet
            bool tokenFound = false;
            for (int j = 0; j < missionTokens.Count; j++)
            {
                if (missionTokens[j] != null && (m.tokens[i].id == missionTokens[j].id))
                {
                    tokenFound = true;
                    break;
                }
            }

            // searched the entire token cache and didn't find the mission token, so mission must be incomplete
            // lets abort now
            if (tokenFound == false)
            {
                missionComplete = false;
                break;
            }
        }

        // award points one time if mission is finished.  We won't do this again because the mission's state will change
        // to MS_COMPLETE and we will no longer evaluate it.
        if (missionComplete == true)
        {
            // get the playerData and add score the player's score
            GameObject go = GameObject.Find("Player");
            if (go == null)
            {
                go = GameObject.Find("Player1");
            }
            if (go)
            {
                playerData pd = go.GetComponent <playerData>();
                if (pd)
                {
                    pd.AddScore(m.points);
                }
            }
        }

        return(missionComplete);
    }
コード例 #2
0
    void Dispatch()
    {
        for (int i = 0; i < actions.Count; i++)
        {
            popupResponse resp = actions[i];
            switch (resp.action)
            {
            case (popupAction.LoadLevel1):
            {
                if (gm)
                {
                    gm.ChangeState(gameMgr.eGameState.eGS_Level1);
                    //this.gameObject.SetActive(false);//enabled = false;
                }
                break;
            }

            case (popupAction.LoadLevel2):
            {
                if (gm)
                {
                    gm.ChangeState(gameMgr.eGameState.eGS_Level2);
                    //this.gameObject.SetActive(false);//enabled = false;
                }
                break;
            }

            case (popupAction.LoadLevel3):
            {
                if (gm)
                {
                    gm.ChangeState(gameMgr.eGameState.eGS_Level3);
                    //this.gameObject.SetActive(false);//enabled = false;
                }
                break;
            }

            case (popupAction.LoadLevelMainMenu):
            {
                if (gm)
                {
                    gm.ChangeState(gameMgr.eGameState.eGS_MainMenu);
                }
                break;
            }

            case (popupAction.AwardPoints):
            {
                GameObject player = GameObject.Find("Player1");
                if (player)
                {
                    playerData pd = player.GetComponent <playerData>();
                    if (pd)
                    {
                        pd.AddScore(resp.data.id);
                    }
                }
                break;
            }

            case (popupAction.Instantiate):
            {
                if (gm)
                {
                    GameObject go = (GameObject)Instantiate(resp.data.obj);
                    Vector3    p  = go.transform.position;
                    Quaternion q  = go.transform.rotation;
                    go.transform.position      = Vector3.zero;
                    go.transform.rotation      = Quaternion.identity;
                    go.transform.parent        = GameObject.Find(resp.data.name).transform;
                    go.transform.localPosition = p;
                    go.transform.localRotation = q;
                }
                break;
            }

            case (popupAction.EnableObject):
            {
                resp.data.obj.SetActive(true);
                break;
            }

            case (popupAction.DisableObject):
            {
                resp.data.obj.SetActive(false);
                break;
            }

            case (popupAction.HideGameObject):
            {
                resp.data.obj.SetActive(false);
                break;
            }

            case (popupAction.ShowGameObject):
            {
                resp.data.obj.SetActive(true);
                break;
            }

            case (popupAction.QuitApplication):
            {
                Application.Quit();
                break;
            }

            case (popupAction.CameraLookUp):
            {
                Camera.main.gameObject.GetComponent <GameCam>().LookUp();
                break;
            }

            case (popupAction.CameraLookPlayer):
            {
                Camera.main.gameObject.GetComponent <GameCam>().LookPlayer();
                break;
            }

            case (popupAction.SelfDestruct):
            {
                Destroy(this.transform.parent.gameObject);
                break;
            }

            case (popupAction.MakeNpcDance):
            {
                // loop over all QuizNpcHelpers, and find the one with id same as r.data.id
                Object[] QuizNpcHelperObjects = Object.FindObjectsOfType(typeof(QuizNpcHelper));
                foreach (Object item in QuizNpcHelperObjects)
                {
                    if ((item as QuizNpcHelper).GetQuizNpcId() == resp.data.id)
                    {
                        (item as QuizNpcHelper).doSuccess = true;
                    }
                }
                break;
            }

            case (popupAction.ClearInventory):
            {
                GameObject player = GameObject.Find("Player1");
                if (player == null)
                {
                    player = GameObject.Find("Player");
                }
                if (player)
                {
                    inventoryMgr im = player.GetComponent <inventoryMgr>();
                    if (im)
                    {
                        im.inventoryObjects.Clear();
                    }
                }
                break;
            }

            case (popupAction.ResetScore):
            {
                GameObject go = GameObject.Find("setupLevel3");
                if (go)
                {
                    floatData initialScore = go.GetComponent <floatData>();
                    if (initialScore)
                    {
                        GameObject player = GameObject.Find("Player1");
                        if (player == null)
                        {
                            player = GameObject.Find("Player");
                        }
                        if (player)
                        {
                            player.GetComponent <playerData>().score = (int)initialScore._floatData;
                        }
                    }
                }
                break;
            }

            case (popupAction.AddMissionToken):
            {
                GameObject mm = GameObject.Find("Game");
                if (mm)
                {
                    missionMgr mmgr = mm.GetComponent <missionMgr>();
                    if (mmgr)
                    {
                        missionToken mt = this.GetComponent <missionToken>();
                        if (mt != null)
                        {
                            mmgr.add(mt);
                        }
                    }
                }
                break;
            }
            }
        }
    }