Esempio n. 1
0
    public void InitMission()
    {
        missionList = new ArrayList();
        //12 mission
        PassAreaMission passArea1 = new PassAreaMission("Pass Area 1");

        missionList.Add(passArea1);

        PassAreaMission passArea2 = new PassAreaMission("Pass Area 2");

        missionList.Add(passArea2);

        PassAreaMission passArea3 = new PassAreaMission("Pass Area 3");

        missionList.Add(passArea3);

        KillMission killMission4 = new KillMission("Kill 10 Soldier", 10);

        missionList.Add(killMission4);

        KillMission killMission5 = new KillMission("Kill 50 Soldier", 50);

        missionList.Add(killMission5);

        KillMission killMission6 = new KillMission("Kill 100 Soldier", 100);

        missionList.Add(killMission6);

        KillMission killMission7 = new KillMission("Kill 10 Sniper", 10);

        missionList.Add(killMission7);

        KillMission killMission8 = new KillMission("Kill 50 Sniper", 50);

        missionList.Add(killMission8);

        KillMission killMission9 = new KillMission("Kill 100 Sniper", 100);

        missionList.Add(killMission9);

        KillMission killMission10 = new KillMission("Kill 10 Sandbag Sniper", 10);

        missionList.Add(killMission10);

        KillMission killMission11 = new KillMission("Kill 50 Sandbag Sniper", 50);

        missionList.Add(killMission11);

        KillMission killMission12 = new KillMission("Kill 100 Sandbag Sniper", 100);

        missionList.Add(killMission12);
    }
Esempio n. 2
0
    public void InitMission(bool isVisible)
    {
        showLoading();
        Debug.Log("Start init misson");
        MissionManager.instance.InitMission();
        DatabaseReference missionRef = reference.Child("User").Child(PlayerPrefs.GetString("uid")).Child("Missions");

        //missionRef.
        missionRef.GetValueAsync().ContinueWith(task =>
        {
            if (task.IsCanceled || task.IsFaulted)
            {
                Debug.Log("Get missoon error");
            }
            else if (task.IsCompleted)
            {
                Debug.Log("Get missoon complete");
                DataSnapshot snapshot = task.Result;
                for (int i = 0; i < MissionManager.instance.missionList.Count; i++)
                {
                    int j = i;
                    DataSnapshot missionSnapshot = snapshot.Child(j.ToString());
                    bool isComplete = (bool)missionSnapshot.Child("Complete").Value;
                    bool isReceive  = (bool)missionSnapshot.Child("Receive").Value;
                    if (j <= 2)
                    {
                        //pass misson
                        ((PassAreaMission)MissionManager.instance.missionList[j]).Complete = isComplete;
                        ((PassAreaMission)MissionManager.instance.missionList[j]).Receive  = isReceive;
                        Debug.Log("Pass Area Mission " + j + isComplete + " " + isReceive);
                    }
                    else
                    {
                        //kill mission
                        int process = System.Int32.Parse(missionSnapshot.Child("Process").Value.ToString());
                        ((KillMission)MissionManager.instance.missionList[j]).Complete = isComplete;
                        ((KillMission)MissionManager.instance.missionList[j]).Receive  = isReceive;
                        ((KillMission)MissionManager.instance.missionList[j]).Process  = process;
                        Debug.Log("Kill Mission " + j + isComplete + " " + isReceive + " " + process);
                    }
                }


                for (int i = 0; i < 3; i++)
                {
                    PassAreaMission m     = ((PassAreaMission)MissionManager.instance.missionList[i]);
                    GameObject receiveBtn = missionGameObjects[i].transform.Find("RightPanel").Find("ReceiveButton").gameObject;
                    GameObject statusText = missionGameObjects[i].transform.Find("RightPanel").Find("StatusText").gameObject;
                    if (m.Complete)
                    {
                        if (m.Receive)
                        {
                            statusText.GetComponent <Text>().text = "Complete";
                            SetActivePanel(receiveBtn, false);
                            SetActivePanel(statusText, true);
                        }
                        else
                        {
                            SetActivePanel(receiveBtn, true);
                            SetActivePanel(statusText, false);
                        }
                    }
                    else
                    {
                        statusText.GetComponent <Text>().text = "Incomplete";
                        SetActivePanel(receiveBtn, false);
                        SetActivePanel(statusText, true);
                    }
                }
                for (int i = 3; i < 12; i++)
                {
                    KillMission m         = ((KillMission)MissionManager.instance.missionList[i]);
                    GameObject receiveBtn = missionGameObjects[i].transform.Find("RightPanel").Find("ReceiveButton").gameObject;
                    GameObject statusText = missionGameObjects[i].transform.Find("RightPanel").Find("StatusText").gameObject;
                    if (m.Complete)
                    {
                        if (m.Receive)
                        {
                            statusText.GetComponent <Text>().text = "Complete";
                            SetActivePanel(receiveBtn, false);
                            SetActivePanel(statusText, true);
                        }
                        else
                        {
                            SetActivePanel(receiveBtn, true);
                            SetActivePanel(statusText, false);
                        }
                    }
                    else
                    {
                        statusText.GetComponent <Text>().text = m.Process + " / " + m.killMustDo;
                        SetActivePanel(receiveBtn, false);
                        SetActivePanel(statusText, true);
                    }
                }
                if (isVisible)
                {
                    SetActivePanel(missionPanel, true);
                }
                disableLoading();
            }
        });
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        setEnablePanel(textPanel, false);
        setEnablePanel(loadingPanel, true);
        int score;

        GameManager.instance.gameResult.TryGetValue(RefDefinition.SCORE, out score);
        scoreText.text = score + "";

        if (GameManager.instance.isGameOver || (GameManager.instance.currentArea == 2))
        {
            Destroy(continueBtn);
        }

        int areaIndex = GameManager.instance.currentArea + 1;

        if (GameManager.instance.isGameOver)
        {
            //game over
            title.text = "Area " + areaIndex + " Failed";
        }
        else
        {
            title.text = "Area " + areaIndex + " Complete";
        }

        if (PlayerPrefs.GetString(RefDefinition.UID).Equals(""))
        {
            //offline mode, just get score,  area
            setEnablePanel(loadingPanel, false);
            setEnablePanel(textPanel, true);

            //init for next area
        }
        else
        {
            //online mode
            //update misson list
            FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://super-contra-20171.firebaseio.com/");
            reference = FirebaseDatabase.DefaultInstance.RootReference.Child("User").Child(PlayerPrefs.GetString(RefDefinition.UID));
            int count   = 0;
            int taskNum = 0;
            if (!GameManager.instance.isGameOver)
            {
                PassAreaMission m = (PassAreaMission)MissionManager.instance.missionList[GameManager.instance.currentArea];
                if (!m.Complete)
                {
                    //chua hoan thanh, update hoan thanh
                    m.Complete = true;
                    m.Receive  = false;
                    string json = JsonUtility.ToJson(m);
                    taskNum++;
                    reference.Child("Missions").Child(GameManager.instance.currentArea.ToString()).SetRawJsonValueAsync(json).ContinueWith(task =>
                    {
                        count++;
                        checkTask(count, taskNum);
                    });
                }
            }
            int soldierKill;
            GameManager.instance.gameResult.TryGetValue(RefDefinition.SOLDIER, out soldierKill);
            if (soldierKill > 0)
            {
                for (int i = 3; i < 6; i++)
                {
                    int j = i;
                    Debug.Log("UPDATE SOLDIER " + j);
                    KillMission m = (KillMission)MissionManager.instance.missionList[j];
                    if (!m.Complete)
                    {
                        Debug.Log("UPDATE SOLDIER2 " + j);
                        m.Process += soldierKill;
                        if (m.Process >= m.killMustDo)
                        {
                            m.Process  = m.killMustDo;
                            m.Complete = true;
                            m.Receive  = false;
                        }
                        taskNum++;
                        string json = JsonUtility.ToJson(m);
                        reference.Child("Missions").Child(j.ToString()).SetRawJsonValueAsync(json).ContinueWith(task =>
                        {
                            Debug.Log("UPDATE SOLDIER3 " + j + " " + json);
                            count++;
                            checkTask(count, taskNum);
                        });
                    }
                }
            }
            int sniperKill;
            GameManager.instance.gameResult.TryGetValue(RefDefinition.SNIPER, out sniperKill);
            if (sniperKill > 0)
            {
                for (int i = 6; i < 9; i++)
                {
                    int j = i;
                    Debug.Log("UPDATE SNIPER " + j);
                    KillMission m = (KillMission)MissionManager.instance.missionList[j];
                    if (!m.Complete)
                    {
                        Debug.Log("UPDATE SNIPER2 " + j);
                        m.Process += sniperKill;
                        if (m.Process >= m.killMustDo)
                        {
                            m.Process  = m.killMustDo;
                            m.Complete = true;
                            m.Receive  = false;
                        }
                        taskNum++;
                        string json = JsonUtility.ToJson(m);
                        reference.Child("Missions").Child(j.ToString()).SetRawJsonValueAsync(json).ContinueWith(task =>
                        {
                            Debug.Log("UPDATE SNIPER3 " + j + " " + json);
                            count++;
                            checkTask(count, taskNum);
                        });
                    }
                }
            }
            int sandbagKill;
            GameManager.instance.gameResult.TryGetValue(RefDefinition.SANDBAG_SNIPER, out sandbagKill);
            if (sandbagKill > 0)
            {
                for (int i = 9; i < 12; i++)
                {
                    int j = i;
                    Debug.Log("UPDATE SANDBAG " + j);
                    KillMission m = (KillMission)MissionManager.instance.missionList[j];
                    if (!m.Complete)
                    {
                        Debug.Log("UPDATE SANDBAG2 " + j);
                        m.Process += sandbagKill;
                        if (m.Process >= m.killMustDo)
                        {
                            m.Process  = m.killMustDo;
                            m.Complete = true;
                            m.Receive  = false;
                        }
                        taskNum++;
                        string json = JsonUtility.ToJson(m);
                        reference.Child("Missions").Child(j.ToString()).SetRawJsonValueAsync(json).ContinueWith(task =>
                        {
                            Debug.Log("UPDATE Sandbag3 " + j + " " + json);
                            count++;
                            checkTask(count, taskNum);
                        });
                    }
                }
            }
        }
    }