public static void GetMonsters(List <Monster> List)
    {
        FirebaseDatabase.DefaultInstance.GetReference("monstros").GetValueAsync().ContinueWith(Task =>
        {
            if (Task.IsFaulted)
            {
            }
            else if (Task.IsCompleted)
            {
                DataSnapshot Snapshot = Task.Result;

                foreach (var ChildSnapshot in Snapshot.Children)
                {
                    var NewMonster = new Monster();

                    NewMonster.MonsterID = ChildSnapshot.Key;

                    NewMonster.MonsterName  = ChildSnapshot.Child("nome").Value.ToString();
                    NewMonster.MonsterLevel = ChildSnapshot.Child("nivel").Value.ToString();

                    List.Add(NewMonster);
                }
            }
        });
    }
Exemple #2
0
        public static void ListGallery(List <ImageItem> List, string Type, string Value)
        {
            FirebaseDatabase.DefaultInstance.GetReference("galeria-publica").GetValueAsync().ContinueWith(Task =>
            {
                if (Task.IsFaulted)
                {
                }
                else if (Task.IsCompleted)
                {
                    DataSnapshot Snapshot = Task.Result;

                    foreach (var ChildSnapshot in Snapshot.Children)
                    {
                        if (ChildSnapshot.Child(Type).Value.ToString() == Value)
                        {
                            var NewGallery = new ImageItem();

                            NewGallery.ImageID = ChildSnapshot.Key;

                            Debug.Log("Imagem obtida com sucesso.");

                            NewGallery.Link    = ChildSnapshot.Child("link").Value.ToString();
                            NewGallery.Local   = ChildSnapshot.Child("local").Value.ToString();
                            NewGallery.Mission = ChildSnapshot.Child("missao").Value.ToString();
                            NewGallery.User    = ChildSnapshot.Child("usuario").Value.ToString();
                            NewGallery.Format  = ChildSnapshot.Child("formato").Value.ToString();
                            NewGallery.Level   = ChildSnapshot.Child("nivel").Value.ToString();

                            ImageItem.Add(NewGallery);
                            Debug.Log("Imagem obtida com sucesso.");
                        }
                    }
                }
            });
        }
 public static void ObservingChatMessages(Channel CurrentChannel)
 {
     FirebaseDatabase.DefaultInstance.GetReference("canais").Child(CurrentChannel.ChanneId).Child("mensagens").ValueChanged += (object Sender, ValueChangedEventArgs EventArgs) =>
     {
         if (EventArgs.DatabaseError != null)
         {
             Debug.LogError(EventArgs.DatabaseError.Message);
             return;
         }
         if (EventArgs.Snapshot != null && EventArgs.Snapshot.ChildrenCount > 0)
         {
             foreach (var ChildSnapshot in EventArgs.Snapshot.Children)
             {
                 if (CurrentChannel.Messages.Any(contentMessage => contentMessage.MessageID == ChildSnapshot.Key))
                 {
                     continue;
                 }
                 var NewMessage = new Messages();
                 NewMessage.MessageID = ChildSnapshot.Key;
                 NewMessage.SenderID  = ChildSnapshot.Child("criador").Value.ToString();
                 NewMessage.Text      = ChildSnapshot.Child("mensagem").Value.ToString();
                 CurrentChannel.Messages.Add(NewMessage);
             }
             TecWolf.Chat.ChatInterface.SpawnChatMessages();
         }
     };
 }
    public static void GetChannelsDatabase(List <Channel> List)
    {
        FirebaseDatabase.DefaultInstance.GetReference("canais").GetValueAsync().ContinueWith(Task =>
        {
            if (Task.IsFaulted || !Task.IsCompleted || Task.IsCanceled)
            {
                return;
            }

            DataSnapshot Snapshot = Task.Result;

            if (Snapshot != null && Snapshot.ChildrenCount > 0)
            {
                foreach (var ChildSnapshot in Snapshot.Children)
                {
                    if (List.Any(channelNew => channelNew.ChanneId == ChildSnapshot.Key))
                    {
                        continue;
                    }
                    var NewChannel = new Channel();

                    NewChannel.ChanneId = ChildSnapshot.Key;
                    NewChannel.Creator  = ChildSnapshot.Child("criador").Value.ToString();
                    NewChannel.Date     = ChildSnapshot.Child("timestamp").Value.ToString();
                    NewChannel.Title    = ChildSnapshot.Child("titulo").Value.ToString();

                    NewChannel.Messages = new List <Messages>();
                    List.Add(NewChannel);
                }
                TecWolf.Chat.ChatInterface.SpawnChannelsButtons();
            }
        });
    }
Exemple #5
0
    private void GetDB()
    {
        FirebaseDatabase.DefaultInstance
        .GetReference("MindCar")     //Competition
        .GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                // Handle the error...
                Debug.Log("Failed");
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot = task.Result;
                // Do something with snapshot...

                int count = 0;
                UserCount = task.Result.ChildrenCount;
                user      = new User[UserCount];

                // Store user's name & score in the array of the class 'User'
                foreach (DataSnapshot ChildSnapshot in task.Result.Children)
                {
                    string json = ChildSnapshot.GetRawJsonValue();
                    user[count] = JsonUtility.FromJson <User>(json);
                    count++;
                }

                SortScoreDB();
            }
        });
    }
    public static void GetMission(List <Mission> List, int MonsterID)
    {
        FirebaseDatabase.DefaultInstance.GetReference("missoes").GetValueAsync().ContinueWith(Task =>
        {
            if (Task.IsFaulted)
            {
            }
            else if (Task.IsCompleted)
            {
                DataSnapshot Snapshot = Task.Result;

                foreach (var ChildSnapshot in Snapshot.Children)
                {
                    if (Convert.ToInt32(ChildSnapshot.Child("nivel").Value) == MonsterID && Convert.ToInt32(ChildSnapshot.Child("dificuldade").Value) == TecWolf.Player.PlayerMission.Difficulty)
                    {
                        var NewMission = new Mission();

                        NewMission.MissionID = FirebaseDatabase.DefaultInstance.GetReference("missoes").Push().Key;

                        NewMission.Name    = ChildSnapshot.Child("objetivo").Value.ToString();
                        NewMission.Type    = ChildSnapshot.Child("tipo").Value.ToString();
                        NewMission.Value   = ChildSnapshot.Child("valor").Value.ToString();
                        NewMission.Monster = ChildSnapshot.Child("nivel").Value.ToString();


                        Debug.Log("Missão 1");

                        NewMission.AchievementOne = ChildSnapshot.Child("conquista").Value.ToString();
                        NewMission.AchievementTwo = ChildSnapshot.Child("conquista_final").Value.ToString();

                        NewMission.Difficulty = ChildSnapshot.Child("dificuldade").Value.ToString();

                        Debug.Log("Missão 2");

                        List.Add(NewMission);
                        Debug.Log("Missão obtida com sucesso.");
                    }
                }
            }
        });
    }
Exemple #7
0
        public static void ListMission(List <MissionItem> List, int MonsterID)
        {
            FirebaseDatabase.DefaultInstance.GetReference("/usuarios/" + FirebaseController.UserId + "/missoes/").GetValueAsync().ContinueWith(Task =>
            {
                if (Task.IsFaulted)
                {
                }
                else if (Task.IsCompleted)
                {
                    DataSnapshot Snapshot = Task.Result;

                    foreach (var ChildSnapshot in Snapshot.Children)
                    {
                        if (Convert.ToInt32(ChildSnapshot.Child("nivel").Value) == MonsterID)
                        {
                            var NewMission = new MissionItem();

                            NewMission.MissionID = ChildSnapshot.Key;

                            Debug.Log(ChildSnapshot.Child("objetivo").Value.ToString());

                            NewMission.Name     = ChildSnapshot.Child("objetivo").Value.ToString();
                            NewMission.Type     = ChildSnapshot.Child("tipo").Value.ToString();
                            NewMission.Value    = ChildSnapshot.Child("valor").Value.ToString();
                            NewMission.Total    = ChildSnapshot.Child("total").Value.ToString();
                            NewMission.Verify   = ChildSnapshot.Child("verificada").Value.ToString();
                            NewMission.Complete = ChildSnapshot.Child("concluida").Value.ToString();

                            NewMission.AchievementOne = ChildSnapshot.Child("conquista").Value.ToString();
                            NewMission.AchievementTwo = ChildSnapshot.Child("conquista_final").Value.ToString();

                            NewMission.Difficulty = ChildSnapshot.Child("dificuldade").Value.ToString();

                            MissionItem.Add(NewMission);
                            Debug.Log("Missão adicionada a Lista de Missões.");
                        }
                    }
                }
            });
        }
    public static void CheckMission(int MonsterID)
    {
        int VerifiedMissions = 0;
        int TotalMissions    = 0;

        int LevelID = 0;

        FirebaseDatabase.DefaultInstance.GetReference("/usuarios/" + UserId + "/missoes/").GetValueAsync().ContinueWith(Task =>
        {
            if (Task.IsFaulted)
            {
            }
            else if (Task.IsCompleted)
            {
                DataSnapshot Snapshot = Task.Result;

                foreach (var ChildSnapshot in Snapshot.Children)
                {
                    if (Convert.ToInt32(ChildSnapshot.Child("nivel").Value) == MonsterID)
                    {
                        if (Convert.ToBoolean(ChildSnapshot.Child("concluida").Value) == true)
                        {
                            // PlayGames.ReportProgress(ChildSnapshot.Child("conquista").ToString());

                            if (ChildSnapshot.Child("conquista").Value.ToString() != "" || ChildSnapshot.Child("conquista").Value.ToString() != null)
                            {
                                ManagerStatic.UnlockAchievement((AchievementID)System.Enum.Parse(typeof(AchievementID), ChildSnapshot.Child("conquista").Value.ToString()));
                            }

                            TecWolf.Player.PlayerMission.FinalAchievement = ChildSnapshot.Child("conquista_final").Value.ToString();
                        }

                        if (Convert.ToBoolean(ChildSnapshot.Child("verificada").Value) == true)
                        {
                            VerifiedMissions = VerifiedMissions + 1;
                        }
                        else
                        {
                            if (Convert.ToInt32(ChildSnapshot.Child("tipo").Value) == 2)
                            {
                                if (Convert.ToInt32(ChildSnapshot.Child("total").Value) >= Convert.ToInt32(ChildSnapshot.Child("valor").Value))
                                {
                                    WriteDataBool("/usuarios/" + UserId + "/missoes/" + ChildSnapshot.Key, "verificada", true);
                                    WriteDataBool("/usuarios/" + UserId + "/missoes/" + ChildSnapshot.Key, "concluida", true);

                                    // TecWolf.Player.PlayerController.UpdateDistance = false;
                                }
                                else
                                {
                                    /*
                                     * if (!TecWolf.Player.PlayerController.UpdateDistance)
                                     * {
                                     *  TecWolf.Player.PlayerController.TotalDistance = Convert.ToInt32(ChildSnapshot.Child("total").Value);
                                     *
                                     *  TecWolf.Player.PlayerController.UpdateDistance = true;
                                     * }
                                     *
                                     * if (TecWolf.Player.PlayerController.Distance <= 100)
                                     * {
                                     *  TecWolf.Player.PlayerController.TotalDistance = TecWolf.Player.PlayerController.TotalDistance + Convert.ToInt32(TecWolf.Player.PlayerController.Distance);
                                     *
                                     *  WriteDataInt("/usuarios/" + UserId + "/missoes/" + ChildSnapshot.Key, "total", TecWolf.Player.PlayerController.TotalDistance);
                                     * }
                                     */

                                    if (TecWolf.Player.PlayerController.Distance <= 100)
                                    {
                                        WriteDataInt("/usuarios/" + UserId + "/missoes/" + ChildSnapshot.Key, "total", Convert.ToInt32(ChildSnapshot.Child("total").Value) + Convert.ToInt32(TecWolf.Player.PlayerController.Distance));
                                    }
                                }
                            }
                        }

                        TotalMissions = TotalMissions + 1;

                        // Debug.Log("Nível Missões: " + LevelID);
                        // Debug.Log("Nível Monstro: " + MonsterID);
                    }
                }

                // Debug.Log("Total: " + (TotalMissions).ToString());
                // Debug.Log("Verificadas: " + (VerifiedMissions).ToString());

                // Debug.Log(TecWolf.Player.PlayerMission.LevelChange);

                if ((VerifiedMissions == TotalMissions) && (TotalMissions > 0 && VerifiedMissions > 0) && (TecWolf.Player.PlayerMission.Level == MonsterID))
                {
                    Debug.Log("Escrita 1: " + WritedInt);

                    TecWolf.Monster.MonsterFinalInterface.StaticMonsterUI.SetActive(true);
                    TecWolf.Monster.MonsterFinalInterface.Show();

                    TecWolf.System.SystemSound.Effect.PlayOneShot(TecWolf.System.SystemSound.MonsterSoundsStatic[0]);

                    // PlayGames.ReportProgress(TecWolf.Player.PlayerMission.FinalAchievement);

                    TecWolf.Player.PlayerMission.Level = TecWolf.Player.PlayerMission.Level + 1;
                    TecWolf.System.SystemInterface.Alert("Você passou para o Nível " + (TecWolf.Player.PlayerMission.Level + 1).ToString());

                    if (TecWolf.Player.PlayerMission.Level == 1)
                    {
                        TecWolf.System.SystemSound.Effect.PlayOneShot(TecWolf.System.SystemSound.SoundsStatic[3]);
                    }

                    if (!WritedInt)
                    {
                        WriteDataInt("/usuarios/" + UserId + "/personagem/", "nivel", TecWolf.Player.PlayerMission.Level);
                    }

                    Debug.Log("Escrita 2: " + WritedInt);

                    TecWolf.Player.PlayerMission.LevelChange = false;

                    if (TecWolf.Player.PlayerMission.FinalAchievement != "" || TecWolf.Player.PlayerMission.FinalAchievement != null)
                    {
                        ManagerStatic.UnlockAchievement((AchievementID)System.Enum.Parse(typeof(AchievementID), TecWolf.Player.PlayerMission.FinalAchievement));
                    }

                    Debug.Log("Escrita 3: " + WritedInt);
                }

                if (TotalMissions > 0)
                {
                    TecWolf.Player.PlayerMission.InMission = true;
                }
                else
                {
                    TecWolf.Player.PlayerMission.InMission = false;
                }

                TotalMissions    = 0;
                VerifiedMissions = 0;
            }

            if (WritedInt)
            {
                WritedInt = false;
                Debug.Log("Escrita 4: " + WritedInt);
            }
        });
    }