Ejemplo n.º 1
0
    /**
     *
     * This method adds the recommended games to the events list and unlocks the necessary characters
     *
     * */
    private void createEvents(List<PackagedNextActivity> pna)
    {
        if(pna!=null){

            gbMang.clearEventList();

            List<ApplicationID> recommendedGames = new List<ApplicationID>();

            for(int i_recommendation = 0; i_recommendation< pna.Count;i_recommendation++)
            {

                int nextApp = -1;

                if(pna[i_recommendation].getActivities().Length==0){
                    Debug.LogError("Empty recommendation: "+pna[i_recommendation].getLanguageArea()+" "+ pna[i_recommendation].getDifficulty());
                    continue;
                }

                List<int> candidateGames = new List<int>();

                for (int j = 0; j<pna[i_recommendation].getActivities().Length;j++){//Find first game on the activity that is currently enabled

                    if(gbMang.getContactStatus(  LocalisationMang.getOwnerNpcOfActivity(pna[i_recommendation].getActivities()[j]))==CharacterStatus.UNLOCKED){
                        candidateGames.Add(j);

                    }

                }

                if(candidateGames.Count==0){//If nothing is unlocked, go for the first app

                    nextApp = 0;

                    Debug.LogWarning("TODO: Unlock a new location!");
                    //unlockingLocation = true;
                    int newMainCharacter = LocalisationMang.getOwnerNpcOfActivity(pna[i_recommendation].getActivities()[nextApp]);
                    gbMang.unlockCharacterForLocation(newMainCharacter);
                    worldView.displayWorldCharacters(new List<int>{newMainCharacter});
                }else{

                    foreach(int i in candidateGames){
                        if(!recommendedGames.Contains(  pna[i_recommendation].getActivities()[i]   )){
                                nextApp = i;
                                break;
                            }
                    }
                    if(nextApp==-1)//all candidates are repated
                        nextApp = candidateGames[0];
                }

                ApplicationID selectedAppID = pna[i_recommendation].getActivities()[nextApp];

                //string eventDescription = LocalisationMang.getActivityShorthand(selectedAppID);

                Encounter e = new Encounter(selectedAppID,
                                            pna[i_recommendation].getLevel()[nextApp],
                                            pna[i_recommendation].getLanguageArea(),
                                            pna[i_recommendation].getDifficulty(),
                                            "",
                                            wvServCom.language);

                int acOwnerID = LocalisationMang.getOwnerNpcOfActivity(e.getLocation());
                int questGiverID = gbMang.getNpcIDForLangAreaDifficulty(e.getLanguageArea(),e.getDifficulty());

                gbMang.addEvent(questGiverID, acOwnerID,e.getLocation(),e);

                recommendedGames.Add(selectedAppID);

                wvServCom.activityProposed(pna[i_recommendation].getDifficulty(),pna[i_recommendation].getLanguageArea(),selectedAppID,pna[i_recommendation].getLevel()[nextApp]);

                List<int[]> difficultiesUnlocked = gbMang.unlockAllRelatedDifficulties(pna[i_recommendation].getLanguageArea(),pna[i_recommendation].getDifficulty());

                List<int> popUpCharacters = new List<int>();
                List<int[]> popUpDifficulties = new List<int[]>();

                foreach(int[] newPair in difficultiesUnlocked){
                    int charID = gbMang.getNpcIDForLangAreaDifficulty(newPair[0],newPair[1]);
                    if(gbMang.unlockCharacter(charID)){
                        popUpCharacters.Add(charID);
                    }else{
                        if(!popUpCharacters.Contains(charID)){
                            popUpDifficulties.Add(newPair);
                        }
                    }
                }

                if(popUpCharacters.Count>0){

                    unlockingCharacters = true;
                    worldView.displayWorldCharacters(popUpCharacters);
                    List<string> charNames = new List<string>();

                    foreach(int id in popUpCharacters)
                        charNames.Add(LocalisationMang.getNPCnames()[id]);

                    unlockingCharacters = true;

                    ActivityExternalDebriefer aed = transform.gameObject.AddComponent<ActivityExternalDebriefer>();
                    aed.unlockCharacters(
                        popUpCharacters,
                        charNames,
                        this);

                }

                if(popUpDifficulties.Count>0){
                    Debug.LogWarning("TODO: new difficulties for known characters have been unlocked");
                    //unlockingDifficulty
                }
            }
        }
    }