/// <summary>
    /// Button action to use a pill
    /// </summary>
    /// <param name="position">Position of the button, from 0 to 2</param>
    public void UsePill(int position)
    {
        PillData pill = pillManager.ConsumePill(position);

        if (playerManager.EatPill(pill))
        {
            InitTurn();
        }
    }
Exemple #2
0
 /// <summary>
 /// Generate description based on pill data, in case there is an effect to apply before
 /// </summary>
 /// <param name="pill">Pill</param>
 /// <returns>Pill description</returns>
 private string GetPillDescription(PillData pill)
 {
     if (PlayerHealth.IsBlind())
     {
         return(randomPillDescriptions[UnityEngine.Random.Range(0, randomPillDescriptions.Count - 1)]);
     }
     else
     {
         return(pill.description);
     }
 }
Exemple #3
0
 /// <summary>
 /// Generate name based on pill data, in case there is an effect to apply before
 /// </summary>
 /// <param name="pill">Pill</param>
 /// <returns>Pill name</returns>
 private string GetPillName(PillData pill)
 {
     if (PlayerHealth.IsBlind())
     {
         return("???");
     }
     else
     {
         return(pill.displayName);
     }
 }
Exemple #4
0
 public bool EatPill(PillData pill)
 {
     level++;
     if (!player.ApplyPillStat(pill.bodyEffect, ref player.currentEffects, player.effectList))
     {
         return(false);
     }
     if (pill.secondaryEffect != null)
     {
         player.AddEffects(pill.secondaryEffect);
     }
     player.currency += pill.cost;
     return(true);
 }
Exemple #5
0
    private PillData PillEffectDecorator(PillData pill, int effectLevel)
    {
        List <string> possibleEffectTypes = new List <string>();

        foreach (KeyValuePair <string, int> organValue in new Dictionary <string, int>()
        {
            { "brain", pill.brain },
            { "heart", pill.heart },
            { "lungs", pill.pulmon },
            { "stomac", pill.intestine },
            { "muscles", pill.muscles }
        })
        {
            for (int i = 0; i < Mathf.Abs(organValue.Value); i++)
            {
                possibleEffectTypes.Add(organValue.Key);
            }
        }
        string            possibleOrgan   = (possibleEffectTypes.Count > 0) ? possibleEffectTypes[UnityEngine.Random.Range(0, possibleEffectTypes.Count - 1)] : "";
        List <EffectData> possibleEffects = GameContext.effects.Effects.FindAll(e => e.type == possibleOrgan);
        EffectData        randomEffect    = (possibleEffects.Count > 0) ? possibleEffects[UnityEngine.Random.Range(0, possibleEffects.Count - 1)] : null;

        if (randomEffect != null && randomEffect.baseValue <= Mathf.Abs(effectLevel))
        {
            if (randomEffect.permanent)
            {
                nonUsedLevelPoints = effectLevel - Mathf.Abs(randomEffect.baseValue);
            }
            else
            {
                int divider = effectLevel != 0 ? effectLevel : 1;
                randomEffect.duration = Mathf.Abs(randomEffect.baseValue) / divider;
                nonUsedLevelPoints    = Mathf.Abs(randomEffect.baseValue) % divider;
            }
        }
        pill.secondaryEffect = new List <EffectData>();
        if (randomEffect != null)
        {
            pill.secondaryEffectID    = new string[1];
            pill.secondaryEffectID[0] = randomEffect.name;
            pill.secondaryEffect.Add(randomEffect);
        }
        else
        {
            pill.secondaryEffectID = new string[0];
        }
        return(pill);
    }
Exemple #6
0
    private PillData PillNameDecorator(PillData pill)
    {
        string        displayName = "", name = "";
        PillNameParts pillNames = GameContext.pillsNameParts;

        do
        {
            string prefix = pillNames.pillPrefixes[UnityEngine.Random.Range(0, pillNames.pillPrefixes.Count - 1)];
            string suffix = pillNames.pillSuffixs[UnityEngine.Random.Range(0, pillNames.pillSuffixs.Count - 1)];
            displayName = prefix + suffix;
            name        = displayName.Replace(" ", "");
        } while (alreadyCreatedPills.Exists(p => p.name == name));
        pill.displayName = displayName;
        pill.name        = name;
        return(pill);
    }
Exemple #7
0
    public PillData GeneratePill(int playerLevel)
    {
        PillData pill;

        do
        {
            pill       = new PillData();
            pill.level = playerLevel;
            int effectLevel = UnityEngine.Random.Range(0, (int)((float)pill.level));
            pill = PillStatDecorator(pill, pill.level - effectLevel);
            pill = PillEffectDecorator(pill, effectLevel);
        } while (Mathf.Abs(pill.brain) + Mathf.Abs(pill.heart) + Mathf.Abs(pill.pulmon) + Mathf.Abs(pill.muscles) + Mathf.Abs(pill.intestine) == 0);
        pill.cost = playerLevel * UnityEngine.Random.Range(100, 200);
        pill      = PillImageDecorator(pill);
        pill      = PillNameDecorator(pill);
        pill      = PillDescriptionDecorator(pill);
        return(pill);
    }
Exemple #8
0
    private PillData PillStatDecorator(PillData pill, int statLevel)
    {
        float        amplitude = (float)statLevel / AMPLITUDE_DENOMINATEUR;
        List <float> values    = new List <float>();

        LOCATIONS.ForEach(l => values.Add(Mathf.Cos(l * FREQUENCY) * amplitude));
        for (int i = 0; i < values.Count; i++)
        {
            values[i] = values[i] + UnityEngine.Random.Range(-amplitude, amplitude);
            values[i] = Mathf.Round(values[i]);
            if (values[i] > MAX_VALUE)
            {
                values[i] = MAX_VALUE;
            }
            else if (values[i] < MIN_VALUE)
            {
                values[i] = MIN_VALUE;
            }
        }
        RandomizeArray(values);

        int valuesSum = 0;

        values.ForEach(v => valuesSum += (int)v);
        while (valuesSum > amplitude)
        {
            valuesSum -= (int)values[0];
            values[0]  = values[0] > 0 ? -values[0] : values[0];
            valuesSum += (int)values[0];
            RandomizeArray(values);
        }
        if (valuesSum > 3)
        {
            InvertArray(values);
        }

        pill.brain     = (int)values[0];
        pill.heart     = (int)values[1];
        pill.pulmon    = (int)values[2];
        pill.intestine = (int)values[3];
        pill.muscles   = (int)values[4];
        return(pill);
    }
Exemple #9
0
    // Use this for initialization
    void Start()
    {
        float fMinutes, fSeconds;
        if (data == null) {
            data = new PillData("Dexedrine", "00:30", 3);
        }
        initialTime = data.frequency;
           // initialTime = "0:10";

        nameText.text = data.name;
        string[] sTimeUnits = initialTime.Split(":".ToCharArray());
        if (float.TryParse(sTimeUnits[0], out fMinutes) && float.TryParse(sTimeUnits[1], out fSeconds))
        {
          //  fSeconds = 10;
            fMinutes *= 60;
            fTimer = fMinutes + fSeconds;
            fCountDownTime = fTimer;
            Debug.Log("In Start" + string.Format("Timer=" + timerText));
        }
    }
Exemple #10
0
    /// <summary>
    /// Consume a given pill and updates other pills requirements
    /// </summary>
    /// <param name="position">Position of the eaten pill</param>
    /// <returns>Pill consumed</returns>
    public PillData ConsumePill(int position)
    {
        PillData pill = possiblePillChoices[position];

        pill.alreadyTaken = true;
        Debug.Log("Taken pill " + pill.name);
        // Old unlock system

        /*for (int i = 0; i < lockedPills.Count; i++)
         * {
         *  PillData lockedPill = lockedPills[i];
         *  if (lockedPill.requirements != null && lockedPill.requirements.Contains(pill.name))
         *  {
         *      lockedPill.requirements.Remove(pill.name);
         *      if (lockedPill.requirements.Count == 0)
         *      {
         *          UnlockPill(lockedPill.name);
         *      }
         *  }
         * }*/
        return(pill);
    }
Exemple #11
0
    /// <summary>
    /// Fetch three pills and put them into available pills pool
    /// </summary>
    public void FetchPills(int level)
    {
        List <PillData> newPills = generator.GenerateTwoPills(level);

        newPills.ForEach(p => p.Build());
        pillPool.AddRange(newPills);
        possiblePillChoices = new List <PillData>();
        if (pillPool.Count <= 3)
        {
            newPills = generator.GenerateTwoPills(level);
            newPills.ForEach(p => p.Build());
            pillPool.AddRange(newPills);
        }
        while (possiblePillChoices.Count < 3)
        {
            int      randomPillIndex = UnityEngine.Random.Range(0, pillPool.Count - 1);
            PillData randomPill      = pillPool[randomPillIndex];
            if (!string.IsNullOrEmpty(randomPill.name) && !possiblePillChoices.Contains(randomPill))
            {
                possiblePillChoices.Add(randomPill);
            }
        }
    }
Exemple #12
0
    /// <summary>
    /// Update a pill GUI
    /// </summary>
    private void UpdatePillGUI(GameObject pillObject, PillData pillData, List <CurrentEffect> effects, bool disabled)
    {
        Debug.Log(pillData);
        // Search Animator
        Animator animatorPillsSelection = GameObject.FindGameObjectWithTag("Pills").GetComponent <Animator>();

        animatorPillsSelection.SetTrigger("Apparate");
        // get all textures

        // Get ours
        Sprite ours = (effects.Exists(e => e.effectData.name == "severeHallucination")) ? fruitImages.textures[UnityEngine.Random.Range(0, fruitImages.textures.Length - 1)] : pillImages.textures[pillData.image];

        // I take my component
        pillObject.GetComponentInChildren <UnityEngine.UI.Image>().sprite = ours;

        // Disabling button if needed
        pillObject.GetComponentInChildren <UnityEngine.UI.Button>().interactable = !disabled;
        // Changing pill texts
        TextMeshProUGUI[] pillTexts = pillObject.GetComponentsInChildren <TextMeshProUGUI>();

        foreach (TextMeshProUGUI pillText in pillTexts)
        {
            if (pillText.gameObject.tag == "PillName")
            {
                pillText.SetText(GetPillName(pillData));
            }
            else if (pillText.gameObject.tag == "PillDescription")
            {
                pillText.SetText(GetPillDescription(pillData));
            }
        }
        // Changing pill bonus/malus icons colors
        foreach (OrganIconChanger iconChanger in pillObject.transform.GetComponentsInChildren <OrganIconChanger>())
        {
            iconChanger.GetComponent <UnityEngine.UI.Image>().enabled = pillData.alreadyTaken;
            switch (iconChanger.name)
            {
            case "HeartIcon":
                iconChanger.GetComponent <UnityEngine.UI.Image>().enabled = pillData.heart != 0;
                iconChanger.ChangeColor(pillData.alreadyTaken ? pillData.heart : 0);
                break;

            case "LungsIcon":
                iconChanger.GetComponent <UnityEngine.UI.Image>().enabled = pillData.pulmon != 0;
                iconChanger.ChangeColor(pillData.alreadyTaken ? pillData.pulmon : 0);
                break;

            case "BrainIcon":
                iconChanger.GetComponent <UnityEngine.UI.Image>().enabled = pillData.brain != 0;
                iconChanger.ChangeColor(pillData.alreadyTaken ? pillData.brain : 0);
                break;

            case "IntestineIcon":
                iconChanger.GetComponent <UnityEngine.UI.Image>().enabled = pillData.intestine != 0;
                iconChanger.ChangeColor(pillData.alreadyTaken ? pillData.intestine : 0);
                break;

            case "MuscleIcon":
                iconChanger.GetComponent <UnityEngine.UI.Image>().enabled = pillData.muscles != 0;
                iconChanger.ChangeColor(pillData.alreadyTaken ? pillData.muscles : 0);
                break;
            }
        }
    }
Exemple #13
0
    private PillData PillDescriptionDecorator(PillData pill)
    {
        List <string> possibleDescriptionTypes = new List <string>();

        foreach (KeyValuePair <string, int> organValue in new Dictionary <string, int>()
        {
            { "brain", pill.brain },
            { "heart", pill.heart },
            { "lungs", pill.pulmon },
            { "stomac", pill.intestine },
            { "muscles", pill.muscles }
        })
        {
            for (int i = 0; i < Mathf.Abs(organValue.Value); i++)
            {
                possibleDescriptionTypes.Add(organValue.Key + ((organValue.Value > 0) ? "+" : "-"));
            }
        }
        string possibleOrgan = (possibleDescriptionTypes.Count > 0) ? possibleDescriptionTypes[UnityEngine.Random.Range(0, possibleDescriptionTypes.Count - 1)] : "";
        List <DescriptionData> possibleDescriptions = new List <DescriptionData>();

        Debug.Log("possibleType : " + possibleOrgan);
        switch (possibleOrgan)
        {
        case "brain+":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.brain > 0);
            break;

        case "heart+":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.heart > 0);
            break;

        case "lungs+":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.pulmon > 0);
            break;

        case "stomac+":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.intestine > 0);
            break;

        case "muscles+":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.muscles > 0);
            break;

        case "brain-":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.brain < 0);
            break;

        case "heart-":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.heart < 0);
            break;

        case "lungs-":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.pulmon < 0);
            break;

        case "stomac-":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.intestine < 0);
            break;

        case "muscles-":
            possibleDescriptions = GameContext.descriptions.FindAll(d => d.muscles < 0);
            break;
        }
        pill.description = (possibleDescriptions.Count > 0) ? possibleDescriptions[UnityEngine.Random.Range(0, possibleDescriptions.Count - 1)].description : "What could possibly go wrong ?";
        return(pill);
    }
Exemple #14
0
 private PillData PillImageDecorator(PillData pill)
 {
     pill.image = UnityEngine.Random.Range(0, textures.Length - 1);
     return(pill);
 }