Ejemplo n.º 1
0
    private MiniPetRetentionPet retentionScript;        // Reference to minipet logic

    public void InitializeContent(string taskID, MiniPetRetentionPet retentionScript)
    {
        this.retentionScript = retentionScript;
        rewardButton.SetActive(false);
        if (DataManager.Instance.GameData.Wellapad.CurrentTasks.ContainsKey("DailyInhaler"))
        {
            List <MutableDataWellapadTask> listTasks = WellapadMissionController.Instance.GetTaskGroup("TutorialPart1");
            task = listTasks[0];
            ImmutableDataWellapadTask missionTask = DataLoaderWellapadTasks.GetTask(task.TaskID);
            SetCheckboxSprite(true, slash1);
            task = listTasks[1];
            SetCheckboxSprite(true, slash2);
            ImmutableDataWellapadTask missionTask2 = DataLoaderWellapadTasks.GetTask(task.TaskID);
            mission1Localize.text = Localization.Localize("Task_" + missionTask.GetTaskID());
            mission2Localize.text = Localization.Localize("Task_" + missionTask2.GetTaskID());
            mission3Localize.gameObject.SetActive(false);
            mission4Localize.gameObject.SetActive(false);
            if (WellapadMissionController.Instance.GetTaskStatus(listTasks[0]) == WellapadTaskCompletionStates.Completed &&
                WellapadMissionController.Instance.GetTaskStatus(listTasks[1]) == WellapadTaskCompletionStates.Completed)
            {
                rewardButton.SetActive(true);
                GameObject peb = MiniPetManager.Instance.MiniPetTable["MiniPet0"];
                rewardButton.GetComponent <Button>().onClick.AddListener(() => peb.GetComponent <MiniPetRetentionPet>().OnTurnInButton());
            }
        }
        else
        {
//			Debug.Log(DataManager.Instance.GameData.Wellapad.CurrentTasks[taskID].RewardStatus);
            if (DataManager.Instance.GameData.Wellapad.CurrentTasks[taskID].isReward == RewardStatuses.Unclaimed ||
                DataManager.Instance.GameData.Wellapad.CurrentTasks[taskID].isReward == RewardStatuses.Unearned)
            {
                //Debug.Log(taskID);
                List <MutableDataWellapadTask> listTasks = WellapadMissionController.Instance.GetTaskGroup("Critical");
                task = listTasks[0];
                SetCheckboxSprite(true, slash1);
                ImmutableDataWellapadTask missionTask = DataLoaderWellapadTasks.GetTask(task.TaskID);
                rewardButton.GetComponent <LgWorldButtonMessage>().target = MiniPetManager.Instance.MiniPetTable["MiniPet0"];
                task = listTasks[1];
                SetCheckboxSprite(true, slash2);
                ImmutableDataWellapadTask missionTask2 = DataLoaderWellapadTasks.GetTask(task.TaskID);
                task = listTasks[2];
                SetCheckboxSprite(true, slash3);
                ImmutableDataWellapadTask missionTask3 = DataLoaderWellapadTasks.GetTask(task.TaskID);
                if (WellapadMissionController.Instance.GetTaskStatus(listTasks[0]) == WellapadTaskCompletionStates.Completed && WellapadMissionController.Instance.GetTaskStatus(listTasks[1]) == WellapadTaskCompletionStates.Completed && WellapadMissionController.Instance.GetTaskStatus(listTasks[2]) == WellapadTaskCompletionStates.Completed)
                {
                    rewardButton.SetActive(true);
                }
                mission1Localize.text = Localization.Localize("Task_" + missionTask.GetTaskID());
                mission2Localize.text = Localization.Localize("Task_" + missionTask2.GetTaskID());
                mission3Localize.text = Localization.Localize("Task_" + missionTask3.GetTaskID());
                mission4Localize.gameObject.SetActive(false);
            }
        }
    }
Ejemplo n.º 2
0
    private void CreateMiniPet(string miniPetId)
    {
        GameObject goMiniPet = null;

        // Unlock in data manager
        DataManager.Instance.GameData.MiniPets.UnlockMiniPet(miniPetId);
        DataManager.Instance.GameData.MiniPetLocations.UnlockMiniPet(miniPetId);
        ImmutableDataMiniPet data   = DataLoaderMiniPet.GetData(miniPetId);
        GameObject           prefab = Resources.Load(data.PrefabName) as GameObject;

        switch (data.Type)
        {
        case MiniPetTypes.Retention:
            // Check if mp needs new locations
            if (isSpawnNewLocations)
            {
                DataManager.Instance.GameData.Wellapad.ResetMissions();
            }

            // Only spawn the retention pet in the bedroom
            if (SceneManager.GetActiveScene().name == SceneUtils.BEDROOM)
            {
                // Calculate the MP location
                LgTuple <Vector3, string> retentionLocation = PartitionManager.Instance.GetBasePositionInBedroom();
                Vector3 locationPosition = retentionLocation.Item1;
                string  locationId       = retentionLocation.Item2;
                int     partitionNumber  = 0;

                DataManager.Instance.GameData.MiniPets.SetIsHatched(miniPetId, true);
                DataManager.Instance.GameData.MiniPetLocations.SaveLocationId(miniPetId, locationId);   // locationId from tuple
                DataManager.Instance.GameData.MiniPets.SaveHunger(miniPetId, true);                     // Set to always full

                goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partitionNumber).gameObject, prefab);
                goMiniPet.transform.localPosition = locationPosition;                   // vector3 from tuple
                goMiniPet.name = prefab.name;

                MiniPetRetentionPet retentionScript = goMiniPet.GetComponent <MiniPetRetentionPet>();
                retentionScript.Init(data);
                retentionScript.FigureOutMissions();
                if (!DataManager.Instance.GameData.Wellapad.CurrentTasks.ContainsKey("DailyInhaler"))
                {
                    retentionScript.GiveOutMission();
                }

                // Add the pet into the dictionary to keep track
                MiniPetTable.Add(miniPetId, goMiniPet);
            }
            break;

        case MiniPetTypes.GameMaster:
            // Check if mp needs new locations
            ImmutableDataGate latestGate = GatingManager.Instance.GetLatestLockedGate();

//			if(latestGate == null)
//				Debug.Log("-----Spawning GameMaster: " + (latestGate == null) + " gate null");
//			else
//				Debug.Log("-----Spawning GameMaster: " + (latestGate.AbsolutePartition - 1 >= 1) + " || latest gate " + latestGate.AbsolutePartition);

            if (latestGate == null || (latestGate.AbsolutePartition - 1 >= 1))
            {
                // NOTE: Besides spawning new locations, there may not be any data for a minipet when coming back to same PP, do or check
                if (isSpawnNewLocations || GetPartitionNumberForMinipet(miniPetId) == -1)
                {
                    // Calculate the MP location
                    MinigameTypes             type = PartitionManager.Instance.GetRandomUnlockedMinigameType();
                    LgTuple <Vector3, string> gameMasterLocation = PartitionManager.Instance.GetPositionNextToMinigame(type);
                    Vector3 locationPosition = gameMasterLocation.Item1;
                    string  locationId       = gameMasterLocation.Item2;
                    int     partitionNumber  = DataLoaderPartitionLocations.GetAbsolutePartitionNumberFromLocationId(locationId);

                    // Save information for minipet
                    DataManager.Instance.GameData.MiniPetLocations.SaveLocationId(miniPetId, locationId);
                    DataManager.Instance.GameData.MiniPets.SaveHunger(miniPetId, false);

                    // Spawn the minipet if it is in current scene
                    if (PartitionManager.Instance.IsPartitionInCurrentZone(partitionNumber))
                    {
                        goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partitionNumber).gameObject, prefab);
                        goMiniPet.transform.localPosition = locationPosition;
                        goMiniPet.name = prefab.name;

                        MiniPetGameMaster gameMasterScript = goMiniPet.GetComponent <MiniPetGameMaster>();
                        gameMasterScript.minigameType = type;
                        gameMasterScript.Init(data);
                        gameMasterScript.isFinishEating = false;

                        // Add the pet into the dictionary to keep track
                        MiniPetTable.Add(miniPetId, goMiniPet);
                    }
                }
                // Spawn based on its saved location
                else
                {
                    // If the saved minipet location is in the current zone
                    if (PartitionManager.Instance.IsPartitionInCurrentZone(GetPartitionNumberForMinipet(miniPetId)))
                    {
                        string locationId = DataManager.Instance.GameData.MiniPetLocations.GetLocationId(miniPetId);

                        // Get relevant info to populate with given saved location ID
                        int           partition    = DataLoaderPartitionLocations.GetAbsolutePartitionNumberFromLocationId(locationId);
                        Vector3       pos          = DataLoaderPartitionLocations.GetOffsetFromLocationId(locationId);
                        MinigameTypes minigameType = DataLoaderPartitionLocations.GetMinigameTypeFromLocationId(locationId);

                        goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partition).gameObject, prefab);
                        goMiniPet.transform.localPosition = pos;
                        goMiniPet.name = prefab.name;

                        MiniPetGameMaster gameMasterScript = goMiniPet.GetComponent <MiniPetGameMaster>();
                        gameMasterScript.minigameType = minigameType;
                        gameMasterScript.Init(data);

                        // Add the pet into the dictionary to keep track
                        MiniPetTable.Add(miniPetId, goMiniPet);
                    }
                }
            }
            break;

        case MiniPetTypes.Merchant:
            ImmutableDataGate latestGate2 = GatingManager.Instance.GetLatestLockedGate();

//			if(latestGate2 == null)
//				Debug.Log("-----Spawning merchant: " + (latestGate2 == null) + " gate null");
//			else
//				Debug.Log("-----Spawning merchant: " + (latestGate2.AbsolutePartition - 1 >= 2) + " || latest gate " + latestGate2.AbsolutePartition);
            if (DataManager.Instance.GameData.MiniPetLocations.IsMerchantSpawning())
            {
                if (latestGate2 == null || (latestGate2.AbsolutePartition - 1 >= 2))
                {
                    // Check if mp needs new locations
                    // NOTE: Besides spawning new locations, there may not be any data for a minipet when coming back to same PP, do or check
                    if (isSpawnNewLocations || GetPartitionNumberForMinipet(miniPetId) == -1)
                    {
                        // Calculate the MP location
                        LgTuple <Vector3, string> merchantLocation = PartitionManager.Instance.GetRandomUnusedPosition();
                        Vector3 locationPosition = merchantLocation.Item1;
                        string  locationId       = merchantLocation.Item2;
                        int     partitionNumber  = DataLoaderPartitionLocations.GetAbsolutePartitionNumberFromLocationId(locationId);

                        // Save information for minipet
                        DataManager.instance.GameData.MiniPetLocations.SaveLocationId(miniPetId, locationId);
                        DataManager.Instance.GameData.MiniPets.SaveHunger(miniPetId, false);

                        // Set new merchant item here only
                        List <ImmutableDataMerchantItem> merchantItemsList = DataLoaderMerchantItem.GetDataList();
                        int rand = UnityEngine.Random.Range(0, merchantItemsList.Count);
                        DataManager.Instance.GameData.MiniPets.SetItem(miniPetId, rand);
                        DataManager.Instance.GameData.MiniPets.SetItemBoughtInPP(miniPetId, false);

                        // Spawn the minipet if it is in current scene
                        if (PartitionManager.Instance.IsPartitionInCurrentZone(partitionNumber))
                        {
                            goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partitionNumber).gameObject, prefab);
                            goMiniPet.transform.localPosition = locationPosition;
                            goMiniPet.name = prefab.name;

                            MiniPetMerchant merchantScript = goMiniPet.GetComponent <MiniPetMerchant>();
                            merchantScript.Init(data);
                            merchantScript.isFinishEating = false;

                            // Add the pet into the dictionary to keep track
                            MiniPetTable.Add(miniPetId, goMiniPet);
                        }
                    }

                    // Spawn based on its saved location
                    else
                    {
                        // If the saved minipet location is in the current zone
                        if (PartitionManager.Instance.IsPartitionInCurrentZone(GetPartitionNumberForMinipet(miniPetId)))
                        {
                            string locationId = DataManager.Instance.GameData.MiniPetLocations.GetLocationId(miniPetId);

                            // Get relevant info to populate with given saved location ID
                            int     partition = DataLoaderPartitionLocations.GetAbsolutePartitionNumberFromLocationId(locationId);
                            Vector3 pos       = DataLoaderPartitionLocations.GetOffsetFromLocationId(locationId);
                            //MinigameTypes minigameType = DataLoaderPartitionLocations.GetMinigameTypeFromLocationId(locationId);

                            goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partition).gameObject, prefab);
                            goMiniPet.transform.localPosition = pos;
                            goMiniPet.name = prefab.name;

                            MiniPetMerchant merchantScript = goMiniPet.GetComponent <MiniPetMerchant>();
                            merchantScript.Init(data);

                            // Add the pet into the dictionary to keep track
                            MiniPetTable.Add(miniPetId, goMiniPet);
                        }
                    }
                }
            }
            break;

        default:
            Debug.LogError("Bad minipet type specified: " + data.Type.ToString());
            break;
        }
    }