Esempio n. 1
0
    public static ActivePet CreatePet(Species species, int stage, string treeName)
    {
        if (species == null)
        {
            return(null);
        }

        double timestamp = Timestamp.GetTimeStamp();

        PetSnapshot petSnapshot = new PetSnapshot();

        petSnapshot.nickname    = "";
        petSnapshot.species     = species.speciesName;
        petSnapshot.birth       = timestamp;
        petSnapshot.longetivity = Random.Range((int)species.longetivityMin, (int)species.longetivityMax + 1);

        petSnapshot.treeName   = treeName;
        petSnapshot.stage      = stage;
        petSnapshot.stageStamp = timestamp;

        petSnapshot.minWeight = species.minWeight;
        petSnapshot.maxWeight = species.maxWeight;
        petSnapshot.Weight    = species.baseWeight;

        petSnapshot.careMistakeCost = species.careMistakeCost;

        petSnapshot.hungerRate    = Random.Range(species.hungerRateMin, species.hungerRateMax + 1);
        petSnapshot.strengthRate  = Random.Range(species.strengthRateMin, species.strengthRateMax + 1);
        petSnapshot.attentionRate = Random.Range(species.attentionRateMin, species.attentionRateMax + 1);

        petSnapshot.hungerStamp    = timestamp;
        petSnapshot.strengthStamp  = timestamp;
        petSnapshot.attentionStamp = timestamp;

        petSnapshot.happiness      = 50;
        petSnapshot.happinessRate  = Random.Range(species.happinessRateMin, species.happinessRateMax + 1);
        petSnapshot.happinessStamp = timestamp;

        petSnapshot.discipline      = 50;
        petSnapshot.disciplineRate  = Random.Range(species.disciplineRateMin, species.disciplineRateMax + 1);
        petSnapshot.disciplineStamp = timestamp;

        petSnapshot.energy             = 20;
        petSnapshot.energyRecoveryRate = species.energyRecoveryRate;
        petSnapshot.energyStamp        = timestamp;

        petSnapshot.s_atk = species.atk;
        petSnapshot.s_spd = species.spd;
        petSnapshot.s_def = species.def;

        petSnapshot.g_atk = Random.Range(0, 17);
        petSnapshot.g_spd = Random.Range(0, 17);
        petSnapshot.g_def = Random.Range(0, 17);

        ActivePet pet = new ActivePet();

        pet.SetSnapshot(petSnapshot);

        return(pet);
    }
Esempio n. 2
0
    public static IEnumerator CreatePet(ActivePet newPet, string username)
    {
        string json = JsonUtility.ToJson(newPet.GetSnapshotCopy());

        byte[] data = System.Text.Encoding.Default.GetBytes(json);

        // Create a PUT request because Unity apperantly cannot
        UnityWebRequest request = new UnityWebRequest(HOST + username + "/pet", "PUT");

        request.uploadHandler   = (UploadHandler) new UploadHandlerRaw(data);
        request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");

        yield return(request.SendWebRequest());

        if (request.isNetworkError)
        {
            if (offline_mode)
            {
                yield return("0000-0000-0000");
            }
            else
            {
                Debug.Log("Error sending data to server");
            }
        }
        else
        {
            byte[]      result      = request.downloadHandler.data;
            string      resJson     = System.Text.Encoding.Default.GetString(result);
            PetSnapshot newSnapshot = JsonUtility.FromJson <PetSnapshot>(resJson);
            yield return(newSnapshot._id);
        }
    }
Esempio n. 3
0
    public void EvolutionCheck(ActivePet pet)
    {
        EvolutionTree tree = evolutionGarden.GetTree(pet.treeName);

        if (tree == null)
        {
            Debug.LogError("Didn't find tree: " + pet.treeName + " of " + pet.species);
        }
        else
        {
            if (tree.IsTimeToEvolve(pet))
            {
                Species evolveTo = tree.GetEvolution(pet);
                //Debug.Log("Evolving to " + evolveTo.name);
                if (evolveTo)
                {
                    Debug.Log("Evolving to " + evolveTo.name);
                    // Animate
                    if (onEvolutionEvent != null)
                    {
                        onEvolutionEvent(FindSheet(pet.species).idle[0], FindSheet(evolveTo.speciesName).idle[0]);
                    }

                    pet.EvolveTo(PetFactory.Evolve(pet, evolveTo));

                    if (onActivePetsChange != null)
                    {
                        onActivePetsChange(this.activePets);
                    }
                }
            }
        }
    }
Esempio n. 4
0
    public static ActivePet CreateFromSnapshot(PetSnapshot snapshot)
    {
        ActivePet pet = new ActivePet();

        pet.SetSnapshot(snapshot);
        return(pet);
    }
Esempio n. 5
0
    public bool IsTimeToEvolve(ActivePet pet)
    {
        if (pet.stageTime >= stagesEvolveAt[pet.stage])
        {
            return(true);
        }

        return(false);
    }
Esempio n. 6
0
    void UpdateCard()
    {
        if (viewingPet > GameManager.instance.activePets.Count - 1 || GameManager.instance.activePets[viewingPet] == null)
        {
            sprite.enabled = false;
            species.text   = "?????";
            //nickname.text = "?????";

            atk.fillAmount = 0;
            spd.fillAmount = 0;
            def.fillAmount = 0;

            atkVal.text = "?";
            spdVal.text = "?";
            defVal.text = "?";

            weightVal.text = "???G";


            return;
        }

        ActivePet pet = GameManager.instance.activePets[viewingPet];

        sprite.sprite  = GameManager.instance.FindSheet(GameManager.instance.activePets[viewingPet].species).idle[0];
        sprite.enabled = true;

        species.text = pet.species.ToUpper();
        //nickname.text = pet.nickname.ToUpper();

        atk.fillAmount = pet.atk / 255f;
        spd.fillAmount = pet.spd / 255f;
        def.fillAmount = pet.def / 255f;

        atkVal.text = pet.atk.ToString();
        spdVal.text = pet.spd.ToString();
        defVal.text = pet.def.ToString();

        weightVal.text = +pet.weight + "g";

        int weightStatus = pet.GetWeightStatus();

        switch (weightStatus)
        {
        case -1:
            weightIcon.sprite = weightIcons[0];     // Under
            break;

        case 0:
            weightIcon.sprite = weightIcons[1];     // Normal
            break;

        case 1:
            weightIcon.sprite = weightIcons[2];     // Over
            break;
        }
    }
Esempio n. 7
0
    public void RemoveActive(ActivePet pet)
    {
        activePets.Remove(pet);

        StartCoroutine(UpdateActive());

        if (onActivePetsChange != null)
        {
            onActivePetsChange(this.activePets);
        }
    }
Esempio n. 8
0
 /// <summary>
 /// Get Species the pet will evolve to.
 /// </summary>
 /// <param name="pet">Pet we check evolution for.</param>
 /// <returns>If no evolution that meets all conditions was found returns Null. Otherwise, returns Species object.</returns>
 public Species GetEvolution(ActivePet pet)
 {
     if (pet.stage == 0)
     {
         return(GetEvolutionFromStage(pet, evolutions)); // We don't need to check nested EvolutionPaths
     }
     else
     {
         return(GetEvolutionFromStage(pet, FindEvolutions(pet.species, evolutions))); // We need to find the current EvolutionPath so we check nested paths.
     }
 }
Esempio n. 9
0
 private void Skills_SkillExperienceAdd(object sender, SkillExperienceAddedEventArgs e)
 {
     if (ActivePet != null)
     {
         if (ActivePet.messageManager == null)
         {
             ActivePet.messageManager = MessageManager;
         }
         ActivePet.GainExperience(e.Skill.Name, e.Amount / 10);
         e.Skill.Experience += (long)(e.Amount * Skills.GetExperienceGainBonus(e.Skill) * ActivePet.GetSkillBoost(e.Skill));
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Get first evolution that meets all conditions from an array of EvolutionPaths.
 /// Does not check nested paths.
 /// </summary>
 /// <param name="pet">Pet we check conditions for.</param>
 /// <param name="paths">EvolutionPaths that contain the conditions.</param>
 /// <returns>Species object to evolve to.</returns>
 private Species GetEvolutionFromStage(ActivePet pet, EvolutionPath[] paths)
 {
     // Return the species of the first path that meets all conditions or no conditions exist
     foreach (EvolutionPath path in paths)
     {
         if (path.CheckConditions(pet))
         {
             return(path.species);
         }
     }
     // No Path met all conditions
     return(null);
 }
Esempio n. 11
0
    public bool CheckConditions(ActivePet pet)
    {
        bool allConditionsMet = true;

        foreach (EvolutionCondition condition in conditions)
        {
            if (condition.Check(pet) == false)
            {
                allConditionsMet = false;
            }
        }

        return(allConditionsMet);
    }
Esempio n. 12
0
    public IEnumerator SaveSnapshot(ActivePet pet, PetSnapshot snapshot, PetSnapshot backup)
    {
        UIManager.instance.SetLoading(true, "Syncing", true);

        Coroutine <bool> routine = this.StartCoroutine <bool>(DataService.UpdatePet(snapshot));

        yield return(routine.coroutine);

        UIManager.instance.SetLoading(false, "", true);

        if (routine.returnVal == false)
        {
            Debug.Log("No response from server: Aborting save and restoring backup.");
            pet.SetSnapshot(backup);
        }
    }
Esempio n. 13
0
    public IEnumerator CreateEgg(ActivePet pet)
    {
        Coroutine <string> routine = this.StartCoroutine <string>(DataService.CreatePet(pet, user.username));

        yield return(routine.coroutine);

        if (routine.returnVal != null)
        {
            pet.SetId(routine.returnVal);
            AddActive(pet);
        }
        else
        {
            Debug.Log("No _id from server: Aborting creation.");
        }
    }
Esempio n. 14
0
    public bool PickupEgg(EvolutionTree tree)
    {
        if (activePets.Count >= maxActive)
        {
            return(false);
        }

        ActivePet pet = PetFactory.CreateEgg(tree);

        if (pet != null)
        {
            StartCoroutine(CreateEgg(pet));
        }

        return(true);
    }
Esempio n. 15
0
    void UpdateStrengthBars()
    {
        if (viewingPet > GameManager.instance.activePets.Count - 1 || GameManager.instance.activePets[viewingPet] == null)
        {
            for (int i = 0; i < strength.Length; i++)
            {
                strength[i].enabled = false;
            }
            return;
        }

        ActivePet pet = GameManager.instance.activePets[viewingPet];

        for (int i = 0; i < strength.Length; i++)
        {
            strength[i].enabled = i <= pet.strength - 1;
        }
    }
Esempio n. 16
0
    void UpdateHungerBars()
    {
        if (viewingPet > GameManager.instance.activePets.Count - 1 || GameManager.instance.activePets[viewingPet] == null)
        {
            for (int i = 0; i < hunger.Length; i++)
            {
                hunger[i].enabled = false;
            }
            return;
        }

        ActivePet pet = GameManager.instance.activePets[viewingPet];

        for (int i = 0; i < hunger.Length; i++)
        {
            hunger[i].enabled = i <= pet.hunger - 1;
        }
    }
Esempio n. 17
0
    void UpdateAttentionBars()
    {
        if (viewingPet > GameManager.instance.activePets.Count - 1 || GameManager.instance.activePets[viewingPet] == null)
        {
            for (int i = 0; i < attention.Length; i++)
            {
                attention[i].enabled = false;
            }
            return;
        }

        ActivePet pet = GameManager.instance.activePets[viewingPet];

        for (int i = 0; i < attention.Length; i++)
        {
            attention[i].enabled = i <= pet.attention - 1;
        }
    }
Esempio n. 18
0
    void UpdateSpriteSheets(List <ActivePet> pets)
    {
        // Find out how much space to dedicate each pet
        float horizontalSegmentPerPet = (horizontalRange * 2) / pets.Count;

        while (visualPets.Count < pets.Count)
        {
            CreatePrefab();
        }

        for (int i = 0; i < visualPets.Count; i++)
        {
            if (i < pets.Count)
            {
                visualPets[i].SetIndex(i);
                ActivePet   pet   = GameManager.instance.activePets[i];
                Spritesheet sheet = GameManager.instance.FindSheet(pet.species);

                if (sheet != null)
                {
                    visualPets[i].SetSpriteSheet(sheet);
                }
                else
                {
                    visualPets[i].SetSpriteSheet(null);
                }

                if (pet.isDead)
                {
                    visualPets[i].state = AIBrain.AIState.DEAD;
                }

                visualPets[i].SetSleep(pet.IsSleeping());
                Debug.Log(pet.IsSleeping());

                visualPets[i].transform.localPosition = new Vector3(-horizontalRange + (i * horizontalSegmentPerPet) + horizontalSegmentPerPet / 2, 0, 0);
            }
            else
            {
                visualPets[i].SetSpriteSheet(null);
                visualPets[i].SetIndex(-1);
            }
        }
    }
Esempio n. 19
0
    void UpdateEnergyBars()
    {
        if (viewingPet > GameManager.instance.activePets.Count - 1 || GameManager.instance.activePets[viewingPet] == null)
        {
            for (int i = 0; i < energy.Length; i++)
            {
                energy[i].enabled = false;
            }

            return;
        }

        ActivePet pet = GameManager.instance.activePets[viewingPet];

        for (int i = 0; i < energy.Length; i++)
        {
            energy[i].enabled = i <= pet.energy - 1;
        }
    }
Esempio n. 20
0
    public static PetSnapshot Evolve(ActivePet from, Species to)
    {
        double timestamp = Timestamp.GetTimeStamp();

        PetSnapshot snapshot = from.GetSnapshotCopy();

        snapshot.species     = to.speciesName;
        snapshot.longetivity = Random.Range((int)to.longetivityMin, (int)to.longetivityMax + 1);
        snapshot.stage       = from.stage + 1;
        snapshot.stageStamp  = timestamp;

        snapshot.minWeight = to.minWeight;
        snapshot.maxWeight = to.maxWeight;
        if (from.maxWeight - from.minWeight == 0)
        {
            snapshot.Weight = to.baseWeight;
        }
        else
        {
            snapshot.Weight = Mathf.FloorToInt(((from.weight - from.minWeight) / (from.maxWeight - from.minWeight)) * (to.maxWeight - to.minWeight) + to.minWeight);
        }

        snapshot.careMistakeCost = to.careMistakeCost;

        snapshot.hungerRate    = Random.Range(to.hungerRateMin, to.hungerRateMax + 1);
        snapshot.strengthRate  = Random.Range(to.strengthRateMin, to.strengthRateMax + 1);
        snapshot.attentionRate = Random.Range(to.attentionRateMin, to.attentionRateMax + 1);

        snapshot.happinessRate  = Random.Range(to.happinessRateMin, to.happinessRateMax + 1);
        snapshot.disciplineRate = Random.Range(to.disciplineRateMin, to.disciplineRateMax + 1);

        snapshot.energy             = 20;
        snapshot.energyRecoveryRate = to.energyRecoveryRate;
        snapshot.energyStamp        = timestamp;

        snapshot.s_atk = to.atk;
        snapshot.s_spd = to.spd;
        snapshot.s_def = to.def;

        return(snapshot);
    }
Esempio n. 21
0
    void UpdateIndicators()
    {
        if (GameManager.instance.activePets.Count == 0 || GameManager.instance.activePets[viewingPet] == null)
        {
            return;
        }

        ActivePet pet = GameManager.instance.activePets[viewingPet];

        // Update Mood Icon
        int m_icon = Mathf.FloorToInt(pet.happiness / 100f * (moodIcons.Length - 1));

        if (m_icon < 0)
        {
            mood.enabled = false;
        }
        else
        {
            mood.enabled = true;
            mood.sprite  = moodIcons[m_icon];
        }

        // Update Discipline Icon
        int d_icon = Mathf.FloorToInt(pet.discipline / 100f * (disciplineIcons.Length - 1));

        if (d_icon < 0)
        {
            discipline.enabled = false;
        }
        else
        {
            discipline.enabled = true;
            discipline.sprite  = disciplineIcons[d_icon];
        }

        injury.enabled   = pet.isInjured;
        sickness.enabled = false;
    }
Esempio n. 22
0
    private void UpdatePet(ActivePet pet)
    {
        if (pet == null || SceneManager.GetActiveScene().name != "Main")
        {
            return;
        }

        // Care mistakes affect evolution so we check for them before evolving
        if (pet.hunger < 1)
        {
            // Check if enough time passed for pet to starve
            double starveTime = pet.GetStarvingTime();
            if (pet.isStarving == false &&
                starveTime > pet.starveAt)
            {
                pet.isStarving = true;
                Debug.Log("Pet is starving");
                pet.AddCareMistake();
            }
        }

        EvolutionCheck(pet);
    }
Esempio n. 23
0
 public void Popup(ActivePet pet)
 {
     petName.text = pet.nickname;
     petAge.text  = "AGE " + pet.age;
     window.Show();
 }
Esempio n. 24
0
    public bool Check(ActivePet pet)
    {
        int prop1 = -1;
        int prop2 = -1;

        // Get 1st property from pet
        if (property1 == Property.Weather)
        {
        }
        else if (property1 == Property.TimeOfDay)
        {
        }
        else if (property1 == Property.CustomValue)
        {
            prop1 = customValue;
        }
        else
        {
            string propName = property1.ToString("g");
            try
            {
                prop1 = (int)pet.GetType().GetProperty(propName).GetValue(pet, null);
            }
            catch (System.Exception error)
            {
                Debug.Log(error.ToString());
            }
        }

        // Get 2nd property from pet
        if (property2 == Property.Weather)
        {
        }
        else if (property2 == Property.TimeOfDay)
        {
        }
        else if (property2 == Property.CustomValue)
        {
            prop2 = customValue;
        }
        else
        {
            string propName2 = property2.ToString("g");
            Debug.Log(propName2);
            try
            {
                prop2 = (int)pet.GetType().GetProperty(propName2).GetValue(pet, null);
            }
            catch (System.Exception error)
            {
                Debug.LogError(error.ToString());
            }
        }

        if (prop1 == -1 || prop2 == -1)
        {
            Debug.LogError("Error: One or more properties are -1 (Unassigned)");
            return(false);
        }

        switch (compare)
        {
        case Compare.BiggerThan:
            return(prop1 > prop2);

        case Compare.Equal:
            return(prop1 == prop2);

        case Compare.LessThan:
            return(prop1 < prop2);
        }

        return(false);
    }