Beispiel #1
0
    public void Shuffle()
    {
        if (ReplayRecord.replayMode == ReplayMode.RECORD_REPLAY || ReplayRecord.replayMode == ReplayMode.NO_REPLAY)
        {
            int i = deck_chips.Count;
            while (i > 1)
            {
                int n = UnityEngine.Random.Range(0, i);
                i--;
                DeckSlot swap = deck_chips [n];
                deck_chips [n] = deck_chips [i];
                deck_chips [i] = swap;
            }
            print("SHUFFLED");
            if (ReplayRecord.replayMode == ReplayMode.RECORD_REPLAY)
            {
                SaveDeck();
            }
        }

        if (ReplayRecord.replayMode == ReplayMode.LOAD_REPLAY)
        {
            LoadDeck();
        }
    }
Beispiel #2
0
    public bool verify_chip(DeckSlot ds)
    {
        if (decksize >= 30)             // deck not at max size
        {
            warning_deck_size();
            return(false);
        }
        FolderSlot findslot = chip_in_deck(ds.cardID);

        if (findslot != null)            // at least 1 copy of this chip is already in the deck
        {
            if (findslot.numCopies >= 3) // deck cannot have more copies of this chip
            {
                warning_chip_max();
                return(false);
            }
            else                // add to folder slot instead of making new one
            {
                findslot.add_copy(ds);
                return(true);
            }
        }

        else
        {
            // TODO: verify chip is legal to add to current deck
            GameObject newslot = Instantiate(fs, list_view.transform);              // create folderslot object in scrollview
            //instantiate folderslot object with ID and color info
            newslot.GetComponent <FolderSlot>().deckbuilder = this;
            newslot.GetComponent <FolderSlot>().init(ds);
            Decklist.Add(newslot.GetComponent <FolderSlot>());
            deck_count();
            return(true);
        }
    }
Beispiel #3
0
 public void add_copy(DeckSlot ds)
 {
     numCopies++;
     this.colorcodes[numCopies - 1]           = ds.color_code;
     this.colorCode_disp[numCopies - 1].color = ChipData.color_codes[ds.color_code];
     this.colorCode_disp[numCopies - 1].gameObject.SetActive(true);
 }
        public void Populate(List <DeckSlot> deckSlots, WeaponDefinition weapon)
        {
            m_definition = weapon;
            int index = 0;
            int selectedDeckForWeapon = m_modifications.GetSelectedDeckForWeapon(weapon.get_id());

            for (int i = 0; i < deckSlots.Count; i++)
            {
                m_presets[i].ForceSelect(selected: false);
                DeckSlot deckSlot = deckSlots[i];
                if (deckSlot.DeckInfo != null && deckSlot.DeckInfo.Id.HasValue && deckSlot.DeckInfo.Id.Value == selectedDeckForWeapon)
                {
                    index = i;
                }
                DeckInfo deckInfo = deckSlot.DeckInfo;
                int      num;
                bool     isAvailableEmptyDeckSlot;
                if (deckInfo == null || !deckInfo.Id.HasValue)
                {
                    num = 1;
                }
                else
                {
                    isAvailableEmptyDeckSlot = deckSlot.isAvailableEmptyDeckSlot;
                }
                m_presets[i].Populate(deckSlot, selectedDeckForWeapon);
            }
            m_presets[index].ForceSelect();
        }
Beispiel #5
0
    public DeckSlot Draw_chip()
    {
        DeckSlot drawn = new DeckSlot(deck_chips[0].cardID, deck_chips[0].color_code);

        deck_chips.RemoveAt(0);
        used_chips.Add(drawn);
        return(drawn);
    }
 public void SetDeckSlot(DeckSlot slot, WeaponAndDeckModifications modifications)
 {
     m_wasValid      = slot.DeckInfo.IsValid();
     m_previousSlot  = slot;
     m_selectedSlot  = slot.Clone();
     m_weapon        = (slot.Weapon ?? 0);
     m_modifications = modifications;
 }
        private void OnRemoveConfirm()
        {
            DeckSlot selectedSlot = m_selectedSlot;

            if (selectedSlot.Id.HasValue)
            {
                m_ui.interactable = false;
                m_frame.SendRemoveSquadRequest(selectedSlot.Id.Value);
            }
        }
Beispiel #8
0
    void Awake()
    {
        instance = this;

        // Debug
        deckData = DeckData.GetInstance();
        deckData.LoadData();

        slotCountX = deckData.characterCardList.Count - 1;

        if (slotCountX != 0)
        {
            // indexing initialization
            for (int i = 0; i <= slotCountX; i++)
            {
                currentCardList.Add(deckData.characterCardList[i]);
            }

            curInvenWidth = (slotCountX * slotSize) + (slotCountX * slotPadding) + slotPadding;

            for (int i = 1; i <= slotCountX; i++)
            {
                GameObject slotObj = Instantiate(OriginSlot) as GameObject;
                DeckSlot   slot    = slotObj.GetComponent <DeckSlot>();
                slot.InitializeDeckSlot(readonlyCardList[i]);

                RectTransform slotRect = slot.GetComponent <RectTransform>();
                slotRect = slot.GetComponent <RectTransform>();

                // get item component
                RectTransform item = slot.GetItemGameObject().GetComponent <RectTransform>();
                slot.name             = "slot_" + i;
                slot.transform.parent = cardPanel.transform;

                slotRect.localPosition = new Vector3((slotSize * (i - 1)) + (slotPadding * i), 0, 0);

                slotRect.localScale = Vector3.one;
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 50);

                slotRect.offsetMin = new Vector2(slotRect.offsetMin.x, 0);
                slotRect.offsetMax = new Vector2(slotRect.offsetMax.x, 0);

                Image img = item.GetComponent <Image>();
                img.sprite = slot.card.ImageSprite;

                // code for test
                if (slot.card.Level == 1)
                {
                    img.color = Color.red;
                }
            }
        }
    }
Beispiel #9
0
    public void init(DeckSlot ds)       // TODO: add multi-copy handling
    {
        this.chipID           = ds.cardID;
        this.chipImage.sprite = ChipDatabase.chipDB[ds.cardID].chipimg;
        this.chipName.text    = ChipDatabase.chipDB[ds.cardID].chipName;
        this.elem.sprite      = ChipData.elems[ChipDatabase.chipDB[ds.cardID].elem];
        this.cost.text        = "" + ChipDatabase.chipDB[ds.cardID].base_cost;

        // TODO: multi-copy handling
        numCopies                    = 1;
        this.colorcodes[0]           = ds.color_code;
        this.colorCode_disp[0].color = ChipData.color_codes[ds.color_code];
        this.colorCode_disp[0].gameObject.SetActive(true);
    }
        private void SelectDeckForWeaponDeckForWeapon(DeckSlot slot)
        {
            DeckInfo deckInfo = slot.DeckInfo;

            if (deckInfo != null)
            {
                deckInfo = deckInfo.TrimCopy();
                int?id = deckInfo.Id;
                if (id.HasValue && deckInfo.IsValid())
                {
                    m_modifications.SetSelectedDeckForWeapon(deckInfo.Weapon, id.Value);
                }
            }
        }
Beispiel #11
0
 public bool chip_added(DeckSlot chdata)
 {
     if (held < 6)                                             // not full hand
     {
         chips[held] = Instantiate(chip_obj, transform, true); // adds chip into next open position
         chips[held].GetComponent <Transform>().localScale = new Vector3(1.0f, 1.0f, 1.0f);
         //DeckSlot chdata = navi.GetComponent<Navi>().deck.GetComponent<Deck>().Draw_chip();
         chips[held].GetComponent <BattleChip>().RecieveData(chdata);
         chips[held].GetComponent <BattleChip>().index = held;
         held++;
         hand_num.GetComponent <Text>().text = "x" + held;
         return(true);
     }
     return(false);
 }
    public void FreeCardIndex()
    {
        if (card != null)
        {
            DeckSlot previousSlot = DeckSlot.GetSlotByCard(card);
            previousSlot.SlotFree();
        }
        card       = null;
        item.color = new Color(0, 0, 0, 0);

        // Free -> Controller
        DeckData deckData = DeckData.GetInstance();

        dc.SetDeckData(deckData.GetNullCard(), 0, deckColIdx);
    }
Beispiel #13
0
        public void BuildDeckList()
        {
            m_emptySlot = null;
            List <DeckSlot> list = CreateDeckSlots();
            int             i    = 0;

            for (int count = list.Count; i < count; i++)
            {
                if (list[i].isAvailableEmptyDeckSlot)
                {
                    m_emptySlot = list[i];
                    break;
                }
            }
            m_createButton.set_interactable(m_emptySlot != null);
            m_presetPanel.Populate(list, m_currentWeapon);
        }
Beispiel #14
0
    public void TouchDown(ChampionData champion, DeckSlot slot)
    {
        if (!Dragging)
        {
            currentChampion = champion;
            currentDeckSlot = slot;
            Dragging        = true;

            Champion champ = null;
            switch (champion.Name)
            {
            case "Archer":
                champ = B1;
                break;

            case "Barbarian":
                champ = B2;
                break;

            case "Knight":
                champ = B3;
                break;

            case "Minion":
                champ = R1;
                break;

            case "Dragon":
                champ = R2;
                break;

            case "Troll":
                champ = R3;
                break;
            }

            Champion c = Instantiate(champ, transform);
            c.transform.localScale = Vector3.one * 0.3f;
            c.Data = currentChampion;
            c.SetColor(champion.Background);
            Target = c;
        }
    }
 private void OnCloneConfirme()
 {
     if (DeckUtility.GetRemainingSlotsForWeapon(m_weapon) != 0)
     {
         m_selectedSlot = m_selectedSlot.Clone(keepPreconstructed: false);
         RuntimeData.TryGetText(92537, out string value);
         m_selectedSlot.SetName(value);
         m_previousSlot             = null;
         m_selectedSlot.DeckInfo.Id = null;
         m_ui.interactable          = true;
         DeckInfo obj = new DeckInfo(m_selectedSlot.DeckInfo)
         {
             Name = RuntimeData.FormattedText(92537),
             Id   = null
         };
         DeckInfo deckInfo = m_selectedSlot.DeckInfo.TrimCopy();
         m_ui.OnCloneValidate(m_selectedSlot);
         m_frame.SendSaveSquadRequest(deckInfo.Id, deckInfo.Name, (Family)deckInfo.God, deckInfo.Weapon, (IReadOnlyList <int>)deckInfo.Companions, (IReadOnlyList <int>)deckInfo.Spells);
     }
 }
Beispiel #16
0
    void IEndDragHandler.OnEndDrag(PointerEventData eve)
    {
        if (dragType == "vertical")
        {
            DeckSettingUI selectedDeck;
            DeckUI        deckUI = DeckUI.GetInstance();

            if (selectedDeck = DeckSettingUI.SearchEnterMouseObject(eve.position))
            {
                selectedDeck.SetCardIndex(deckUI.readonlyCardList[selectedIndex]);
            }
            else
            {
                DeckSlot selectedSlot = DeckSlot.GetSlotByCard(deckUI.readonlyCardList[selectedIndex]);
                selectedSlot.SlotFree();
                selectedIndex = -1;
            }
            Destroy(currentSelectedItem.gameObject);
        }
        prePos   = Vector2.zero;
        dragType = "";
    }
    public void SetCardIndex(Card inputCard)
    {
        DeckUI deckUI = DeckUI.GetInstance();

        if (card != null)
        {
            DeckSlot previousSlot = DeckSlot.GetSlotByCard(card);
            previousSlot.SlotFree();
        }
        DeckSlot selectedSlot = DeckSlot.GetSlotByCard(inputCard);

        selectedSlot.SlotSelect();

        card = inputCard;
        // Image Component Copy
        Image copyImage = DeckSlot.GetSlotByCard(inputCard).GetItemGameObject().GetComponent <Image>();

        Util.CopyImage(copyImage, item);

        // regist -> Controller
        dc.SetDeckData(card, 0, deckColIdx);
    }
Beispiel #18
0
    public void RecieveData(DeckSlot d)
    {
        //ChipDatabase chipDataBase = GameObject.Find("Chip Database").GetComponent<ChipDatabase>();
        //chip_logic = chipDataBase.chipDB[d.cardID];
        chip_logic = ChipDatabase.chipDB[d.cardID];
        chip_logic.initColor(d.color_code);
        Debug.Log(chip_logic.chipName);

        //set name and image
        chip_name.text    = chip_logic.chipName;
        chip_image.sprite = chip_logic.chipimg;
        // set cost and color code
        base_cost = chip_logic.base_cost;
        cost      = chip_logic.cost;
        cost_icon.transform.GetChild(0).GetComponent <Text>().text = "" + cost;
        color_code = chip_logic.color_code;
        cost_icon.GetComponent <Image>().color = ChipData.color_codes[color_code];
        // set power and element
        elem = chip_logic.elem;
        elem_icon.GetComponent <Image>().sprite = ChipData.elems[elem];
        power           = chip_logic.power;
        power_text.text = "" + power;
    }
Beispiel #19
0
    public GameObject GetSelectedItem(int selectedIndex)
    {
        GameObject    slot     = Instantiate(OriginSlot) as GameObject;
        RectTransform slotRect = slot.GetComponent <RectTransform>();
        DeckSlot      deckSlot = slot.GetComponent <DeckSlot>();

        deckSlot.InitializeDeckSlot(readonlyCardList[selectedIndex]);

        // get item component
        RectTransform item = deckSlot.GetItemGameObject().GetComponent <RectTransform>();

        slot.name             = "selected_slot_" + selectedIndex;
        slot.transform.parent = selectedPanel.transform;

        // don't need DeckSlot in case of selected slot
        Destroy(slot.GetComponent <DeckSlot>());

        // slotSize(n-1) + k  -> StartPoint */
        slotRect.localPosition = new Vector3(slotSize * (selectedIndex - 1) + cardPanel.position.x, 0, 0);

        slotRect.localScale = Vector3.one;
        slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 50);

        slotRect.offsetMin = new Vector2(slotRect.offsetMin.x, 0);
        slotRect.offsetMax = new Vector2(slotRect.offsetMax.x, 0);

        slotRect.pivot = new Vector2(0.5f, 0.5f);

        DeckSlot seletedDeckSlot = DeckSlot.GetSlotByCard(readonlyCardList[selectedIndex]);

        // Image Component Copy
        Image selectedImg = item.GetComponent <Image>();
        Image copyImage   = seletedDeckSlot.GetItemGameObject().GetComponent <Image>();

        Util.CopyImage(copyImage, selectedImg);
        return(slot);
    }
    public void SynchronizeDeckData()
    {
        DeckData deckData = DeckData.GetInstance();
        int      cardIdx  = deckData.deck[0, deckColIdx];

        if (cardIdx <= 0)
        {
            return;
        }
        Card c = deckData.characterCardList[cardIdx];

        card = c;

        DeckUI deckUI = DeckUI.GetInstance();

        DeckSlot selectedSlot = DeckSlot.GetSlotByCard(card);

        selectedSlot.SlotSelect();

        // Image Component Copy
        Image copyImage = DeckSlot.GetSlotByCard(card).GetItemGameObject().GetComponent <Image>();

        Util.CopyImage(copyImage, item);
    }
Beispiel #21
0
    IEnumerator SpawnAction()
    {
        //Create deck slot
        GameObject newSlot = new GameObject();

        newSlot.transform.parent        = transform;
        newSlot.transform.localPosition = new Vector3(0, -6f, 0);
        DeckSlot slot = newSlot.AddComponent <DeckSlot> ();

        slot.speed = slidingSpeed;

        //Choose at random in the deck and instantiate
        int             r       = Random.Range(0, deck.Count - 1);
        GameObject      spawned = Instantiate(deck [r], newSlot.transform);
        ActionContainer aC      = spawned.GetComponent <ActionContainer> ();

        aC.deckMan = this;
        aC.prefab  = deck [r];
        deck.RemoveAt(r);

        yield return(new WaitForSeconds(spawnDelay));

        StartCoroutine(SpawnAction());
    }
 private void OnEditDeckRequest(DeckSlot obj)
 {
     m_subState.SetDeckSlot(obj, m_modifications);
     m_ui.GotoEditAnim();
 }
 private void OnSelectionChanged(DeckSlot deckSlot)
 {
     m_selectedSlot = deckSlot;
     this.OnSelectionChange?.Invoke(deckSlot);
 }
Beispiel #24
0
 void Start()
 {
     Image = GetComponent <Image>();
     slot  = GetComponent <DeckSlot>();
 }
 private void OnCloneCanceld()
 {
     m_selectedSlot = m_ui.OnCloneCanceled();
 }
Beispiel #26
0
 private void OpenDeckEditState(DeckSlot slot)
 {
     this.OnEditRequest?.Invoke(slot);
 }
Beispiel #27
0
        public void EditDeck()
        {
            DeckSlot selectedSlot = this.selectedSlot;

            OpenDeckEditState(selectedSlot);
        }
Beispiel #28
0
 public void SelectDeckForWeapon(DeckSlot slot)
 {
     this.OnSelectDeckForWeaponRequest?.Invoke(slot);
 }
Beispiel #29
0
    void IDragHandler.OnDrag(PointerEventData eve)
    {
        Vector2 moveOffset = eve.position - prePos;

        if (dragType == "horizon")
        {
            cardPanel.Translate(Vector2.right * moveOffset.x, 0);
            prePos = eve.position;
        }
        else if (dragType == "vertical")
        {
            DeckUI deckUI = DeckUI.GetInstance();
            currentSelectedItem.GetComponent <RectTransform>().Translate(moveOffset);
            prePos = eve.position;
        }

        if (dragType == "" && Vector2.Distance(eve.position, prePos) > 1.0f)
        {
            if (Math.Abs(moveOffset.x) > Math.Abs(moveOffset.y))
            {
                dragType = "horizon";
            }
            else
            {
                // drage vertical
                DeckUI deckUI  = DeckUI.GetInstance();
                Camera _camera = Camera.main;

                float screenWidth = _camera.pixelWidth;

                if (eve.position.x < 20 || eve.position.x > screenWidth - 20)
                {
                    return;
                }

                // n <= ( mouse position - k - widthPad ) / slotSize + 1
                if (selectedIndex <= 0 || selectedIndex > deckData.characterCardList.Count - 1)
                {
                    return;
                }

                if (DeckSlot.GetSlotByCard(deckUI.readonlyCardList[selectedIndex]).slotSelected == true)
                {
                    return;
                }

                //select marking
                DeckSlot selectedSlot = DeckSlot.GetSlotByCard(deckUI.readonlyCardList[selectedIndex]);
                selectedSlot.SlotSelect();

                //Selected Screen correction
                /* slotSize(n-1) + k + 20 -> StartPoint */
                if (deckUI.slotSize * (selectedIndex - 1) + cardPanel.position.x < deckUI.horizonPad)
                {
                    cardPanel.localPosition = new Vector2(0 - (50 * (selectedIndex - 1)) + deckUI.horizonPad, cardPanel.localPosition.y);
                }
                if (deckUI.slotSize * (selectedIndex - 1) + cardPanel.position.x + deckUI.slotSize > screenWidth - deckUI.horizonPad)
                {
                    cardPanel.Translate(-1 * Vector2.right * (deckUI.slotSize * selectedIndex + cardPanel.position.x - screenWidth + deckUI.horizonPad));
                }

                currentSelectedItem = deckUI.GetSelectedItem(selectedIndex);
                dragType            = "vertical";
            }
        }
    }
Beispiel #30
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UIManager.Instance.QuitGame();
        }

        if (State == GameState.Playing)
        {
            if (Dragging)
            {
                Ray        r = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit dragHit;
                bool       onSlot   = false;
                bool       canPlace = false;

                if (Physics.Raycast(r, out dragHit, 20))
                {
                    if (dragHit.collider != null)
                    {
                        if (dragHit.collider.tag == "Slot")
                        {
                            GridSlot slot = dragHit.collider.GetComponent <GridSlot>();
                            if (slot != null && slot.ParentRow.Side == Turn)
                            {
                                if (slot.IsEmpty)
                                {
                                    canPlace    = true;
                                    onSlot      = true;
                                    currentSlot = slot;
                                    currentSlot.Highlight(true);
                                    highlightedSlot           = currentSlot;
                                    Target.transform.position = new Vector3(slot.transform.position.x, 0.25f, slot.transform.position.z);
                                }
                            }
                        }
                        else
                        {
                            Vector3 pos = dragHit.point;
                            Target.transform.position = new Vector3(pos.x, 0.25f, pos.z);
                        }
                    }
                }

                Target.transform.localScale = canPlace ? Vector3.one * 0.5f : Vector3.one * 0.3f;

                if (canPlace)
                {
                    if (highlightedSlot != null)
                    {
                        highlightedSlot.Highlight(true);
                    }
                }
                else
                {
                    if (highlightedSlot != null)
                    {
                        highlightedSlot.Highlight(false);
                    }
                    highlightedSlot = null;
                }

                if (!onSlot)
                {
                    currentSlot = null;
                }

                if (Input.GetMouseButtonUp(0))
                {
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    bool       placed = false;

                    if (currentSlot != null)
                    {
                        if ((Turn == Player.Blue && Data.BlueMana >= currentChampion.Cost) || (Turn == Player.Red && Data.RedMana >= currentChampion.Cost))
                        {
                            Target.transform.parent        = currentSlot.transform;
                            Target.transform.localPosition = Vector3.up * 0.25f;
                            Target.Slot          = currentSlot;
                            currentSlot.Champion = Target;
                            currentSlot.Highlight(false);
                            HealthBar bar = Instantiate(HealthBarPrefab, WorldSpace.transform);
                            Target.Bar = bar;
                            Target.Spawn();
                            currentDeckSlot.LoadNewCard(Turn);
                            placed = true;

                            if (Turn == Player.Blue)
                            {
                                Data = Data.Add(Player.Blue, StatType.Mana, -currentChampion.Cost);
                            }
                            else
                            {
                                Data = Data.Add(Player.Red, StatType.Mana, -currentChampion.Cost);
                            }
                        }
                    }

                    //if (Physics.Raycast(ray, out hit, 100))
                    //{
                    //    if (hit.collider != null)
                    //    {
                    //        GridSlot slot = hit.collider.GetComponent<GridSlot>();
                    //        if (slot != null)
                    //        {
                    //            if (slot.IsEmpty)
                    //            {
                    //                Debug.Log("Clicked on slot: Side: " + slot.Position.Side + " | X: " + slot.Position.X + " | Y: " + slot.Position.Y);
                    //                Target.transform.parent = slot.transform;
                    //                Target.transform.localPosition = Vector3.up * 0.25f;
                    //                slot.Champion = Target;
                    //                placed = true;
                    //            }
                    //        }
                    //    }
                    //}
                    if (!placed)
                    {
                        Destroy(Target.gameObject);
                    }
                    Dragging        = false;
                    currentChampion = null;
                    currentDeckSlot = null;
                }
            }
        }
    }