Esempio n. 1
0
    static public List <Perk> GetThreeRandomPerks(int number)
    {
        List <Perk> list = new List <Perk>();

        if (PerksList == null)
        {
            PerkProperties.GetAllPerks();
        }

        if (PerkCategories == null)
        {
            PerkProperties.GetAllPerkCategories();
        }

        foreach (PerkCategory cat in PerkCategories)
        {
            bool        perkFound = false;
            List <Perk> perks     = PerksList.FindAll(p => p.category.name == cat.name);

            do
            {
                int index = new System.Random().Next(0, perks.Count);
                if (!HasPerkActivated(number, perks[index]))
                {
                    list.Add(perks[index]);
                    perkFound = true;
                }
            } while (!perkFound);
        }
        return(list);
    }
Esempio n. 2
0
    public void OpenPanel()
    {
        if (turnHandler.activePlayer == 0)
        {
            StartCoroutine(waitPanel());
        }
        else
        {
            panelAnimator.Play("OpenPerksGain");
        }

        List <Perk> list = PerkProperties.GetThreeRandomPerks(turnHandler.activePlayer);

        Destroy(firstPerk.GetComponent <Perk>());
        firstPerk.AddComponent(list[0].GetType());
        LoadImage(firstPerk, list[0]);

        Destroy(secondPerk.GetComponent <Perk>());
        secondPerk.AddComponent(list[1].GetType());
        LoadImage(secondPerk, list[1]);

        Destroy(thirdPerk.GetComponent <Perk>());
        thirdPerk.AddComponent(list[2].GetType());
        LoadImage(thirdPerk, list[2]);
    }
Esempio n. 3
0
    private void ActivatePerk()
    {
        PerkProperties.GetActivePerks(turnHandler.activePlayer);
        currentlySelected.GetComponent <Perk>().SetActivated(true);
        PerkProperties.SetActivePerk(turnHandler.activePlayer, currentlySelected.GetComponent <Perk>());
        panelAnimator.Play("ClosePerksGain");
        currentlySelected = selection[0];

        controlsHandler.SetMenuOpen(false);
        controlsHandler.ignoreOtherMenus = false;
    }
Esempio n. 4
0
    static public bool HasPerkActivated(int number, Perk perk)
    {
        List <string> activatedPerks = PerkProperties.GetActivePerks(number);

        foreach (string activatedPerk in activatedPerks)
        {
            if (activatedPerk.Equals(perk.GetName()))
            {
                return(true);
            }
        }

        return(false);
    }
    private void CreatePerkGroupOverview(PerkCategory cat, List <Perk> perks)
    {
        int j = 0;

        for (int i = 0; i < perks.Count; i++)
        {
            if (i % columnCount == 0)
            {
                j++;
            }

            //Create a new Perk from the PerkPrefab
            GameObject newPerk = Instantiate(PerkPrefab) as GameObject;
            newPerk.name = perks[i].GetName();
            newPerk.transform.SetParent(gameObject.transform);

            //Load the Image
            Image[] images = newPerk.GetComponents <Image>();
            images[0].sprite = Resources.Load <Sprite>(perks[i].GetImage());

            //Add the Specific Perk script to the object
            newPerk.AddComponent(perks[i].GetType());

            if (PerkProperties.HasPerkActivated(currentPlayer, newPerk.GetComponent <Perk>()))
            {
                newPerk.GetComponent <Perk>().SetActivated(true);
                SetOriginalColor(newPerk);
            }

            //Highlight the first Perk
            if (ActivePerk == null)
            {
                ActivePerk = newPerk;
                HighlightPerk(ActivePerk);
            }

            //Move the new Perk to the desired location
            RectTransform rectTransform = newPerk.GetComponent <RectTransform>();
            float         x             = -containerRectTransform.rect.width / 2 + width * (i % columnCount) + width * 0.1f + startPos;
            float         y             = containerRectTransform.rect.height / 2 - height * j + height * 0.1f;
            rectTransform.offsetMin = new Vector2(x, y);

            x = rectTransform.offsetMin.x + width - width * 0.1f;
            y = rectTransform.offsetMin.y + height - height * 0.1f;
            rectTransform.offsetMax = new Vector2(x, y);

            PerksGameObjects.Add(newPerk);
        }
    }
    // Use this for initialization
    void Start()
    {
        controlsHandler = GameObject.Find("ControlsHandler").GetComponent <ControlsHandling>();
        controlsHandler.SetMenuOpen(true);

        PerkCategories = new List <PerkCategory> {
            new PerkCategory("Movement"),
            new PerkCategory("Medicine"),
            new PerkCategory("Cannon")
        };

        currentPlayer = PlayerPrefs.GetInt("Player");
        List <Perk> PerksList = PerkProperties.GetAllPerks();

        PerkCategories = PerkProperties.GetAllPerkCategories();
        PerkProperties.GetActivePerks(currentPlayer);

        selectedPerkImage = GameObject.Find("PerkSelected");
        perkName          = GameObject.Find("PerkName");
        perkClass         = GameObject.Find("PerkClass");

        //Set variables for Confirm Panel
        confirmPanelAnimator = GameObject.Find("ConfirmPanel").GetComponent <Animator>();
        yesButton            = GameObject.Find("YesButton");
        noButton             = GameObject.Find("NoButton");
        activeButton         = noButton;

        //Get the necessary RectTransforms
        rowRectTransform       = PerkPrefab.GetComponent <RectTransform>();
        containerRectTransform = gameObject.GetComponent <RectTransform>();

        //Calculate the dimension of a perk by the container dimensions
        width  = containerRectTransform.rect.width / (columnCount * PerkCategories.Count);
        ratio  = width / rowRectTransform.rect.width;
        height = rowRectTransform.rect.height * ratio;

        //Render all Perks per Category
        foreach (PerkCategory cat in PerkCategories)
        {
            CreatePerkGroupOverview(cat, PerksList.FindAll(p => p.category.name == cat.name));
            startPos += width * (columnCount + 0.3f);
        }
    }
    private void ConfirmControlsListiner(float direction)
    {
        //Navigate between the Yes and No buttons
        if (direction != 0)
        {
            ConfirmNavigation();
        }

        //Handle the Submit event
        else if (Input.GetKeyDown(KeyCode.KeypadEnter))
        {
            //If the Yes button was submitted, activate the selected Perk
            if (activeButton == yesButton)
            {
                ActivePerk.GetComponent <Perk>().SetActivated(true);
                PerkProperties.SetActivePerk(currentPlayer, ActivePerk.GetComponent <Perk>());
                SetOriginalColor(ActivePerk);
            }

            CloseDialogue();
        }
    }