Beispiel #1
0
        public CardGameObject InitCard(VEntity e)
        {
            CardGameObject newCard = Instantiate <CardGameObject>(cardPrefab);

            newCard.InitializeFromEntity(e);
            newCard.transform.parent = this.transform;
            return(newCard);
        }
Beispiel #2
0
 public void ClickCard(CardGameObject cardSelected)
 {
     if (cardSelected.GetComponent <Cantrip>() == null)
     {
         cardSelected.TargetPosition = cardSelected.CardViewController.selectLocation.position;
     }
     cardSelected.locked = true;
 }
Beispiel #3
0
 void Start()
 {
     deck              = new List <CardGameObject>();
     hand              = new List <CardGameObject>();
     discardPile       = new List <CardGameObject>();
     board             = FindObjectOfType <VEntityComponentSystemManager>();
     cardMover         = FindObjectOfType <CardMover>();
     cantrip           = GameObject.FindWithTag("cantrip").GetComponent <CardGameObject>();
     handControlSystem = VEntityComponentSystemManager.Instance.GetSystem <HandControlSystem>();
 }
Beispiel #4
0
        internal void CardMove(Zone source, Zone destination, CardGameObject cardGameObject)
        {
            if (destination == Zone.INPLAY)
            {
                return;
            }

            if (source == Zone.INPLAY)
            {
                source = Zone.HAND;
            }

            if (source != Zone.NULL)
            {
                getZoneList(source).Remove(cardGameObject);
            }

            if (source == Zone.HAND)
            {
                cardGameObject.inHand = false;
            }

            if (destination != Zone.NULL)
            {
                getZoneList(destination).Add(cardGameObject);
            }

            if (destination == Zone.HAND)
            {
                cardGameObject.inHand = true;
            }

            if (source == Zone.HAND || destination == Zone.HAND)
            {
                RecalculateHandAppearance();
            }

            if (destination == Zone.DISCARD)
            {
                cardMover.MoveCardToDiscard(cardGameObject);
            }

            if (destination == Zone.DECK)
            {
                cardMover.MoveCardToDeck(cardGameObject);
            }
        }
Beispiel #5
0
        public void SetCardHovering(CardGameObject c)
        {
            cardHovering = c;
            if (cardController.MyHandState != HandState.SELECTED)
            {
                if (cardHovering != null && cardController.IsPlayable(cardHovering.cardEntityId))
                {
                    cardController.MyHandState = HandState.HOVER;
                }
                else
                {
                    cardController.MyHandState = HandState.IDLE;
                }
            }

            SendEventToBoard();
        }
Beispiel #6
0
 void HandleRightClick()
 {
     if (State == InputState.SELECTCARD)
     {
     }
     else if (State == InputState.SELECTSPACE)
     {
         cardMover.ResetCard(cardSelected);
         cardSelected = null;
         cardController.MyHandState = HandState.IDLE;
         State = InputState.SELECTCARD;
     }
     else if (State == InputState.CONFLICTRESOLUTION)
     {
         spaceSelected = Coord.nullCoord;
         State         = InputState.SELECTSPACE;
     }
 }
Beispiel #7
0
        void FinishPlayingCard(CardGameObject card, Coord space, VEntity caster)
        {
            Debug.Log("Finish playing card");
            cardSelected.locked = false;
            cardSelected        = null;

            VEntity            cardPlayed = boardState.GetVEntityById(card.cardEntityId);
            TargetingComponent targeting  = VEntityComponentSystemManager.GetVComponent <TargetingComponent>(cardPlayed);
            Dictionary <CardEffectType, List <Coord> > mapping = new Dictionary <CardEffectType, List <Coord> >();

            foreach (GroupTargetingMethod m in targeting.groupTargetingMethods)
            {
                if (!mapping.ContainsKey(m.effectType))
                {
                    mapping[m.effectType] = new List <Coord>();
                }
                mapping[m.effectType].AddRange(m.SelectGroupCoords(space, caster.GetVComponent <PositionComponent>().position, boardState));
            }
            foreach (CardEffectType t in mapping.Keys)
            {
                Debug.Log("Type Key: " + t);
            }

            boardState.CreateEvent("playCard", component: new CardPlayEvent {
                cardId               = card.cardEntityId,
                targetSpace          = space,
                casterId             = caster.id,
                groupTargetingSpaces = mapping
            });

            if (card.cantrip)
            {
                boardState.CreateEvent("cantripUsed", component: new CantripUseEvent
                {
                });
            }

            spaceSelected = Coord.nullCoord;
            State         = InputState.SELECTCARD;
            cardController.MyHandState = HandState.IDLE;
        }
Beispiel #8
0
 public void MoveCardToDiscard(CardGameObject card)
 {
     card.TargetPosition = discardLocation.position;
 }
Beispiel #9
0
 public void MoveCardToDeck(CardGameObject card)
 {
     card.TargetPosition = deckLocation.position;
 }
Beispiel #10
0
        public void RecalculateHandAppearance(HandState handState, List <CardGameObject> hand, CardGameObject cantrip, int maxHandSize)
        {
            int handSize = hand.Count;

            if (handState == HandState.IDLE)
            {
                for (int i = 0; i < handSize; i++)
                {
                    hand[i].handPosition   = handLocation.position + (i - (float)handSize / 2) * Vector3.right * Mathf.Lerp(cardWidth, 1, ((float)handSize) / (float)maxHandSize);
                    hand[i].handPosition  += Vector3.back * i;
                    hand[i].TargetPosition = hand[i].handPosition;
                    hand[i].targetScale    = baseScale;
                }
                //cantrip.TargetPosition = cantripLocation.position;
                cantrip.targetScale = cantrip.transform.localScale;
                cantrip.GetComponent <Cantrip>().Hover(false);
            }
            else if (handState == HandState.HOVER)
            {
                int hoverIndex = -1;
                for (int i = 0; i < handSize; i++)
                {
                    if (hand[i] == inputController.cardHovering)
                    {
                        hoverIndex = i;
                    }
                    hand[i].handPosition   = handLocation.position + (i - (float)handSize / 2) * Vector3.right * Mathf.Lerp(cardWidth, 1, ((float)handSize) / (float)maxHandSize);
                    hand[i].handPosition  += Vector3.back * i;
                    hand[i].TargetPosition = hand[i].handPosition;
                }
                if (hoverIndex == -1)
                {
                    cantrip.GetComponent <Cantrip>().Hover(true);
                    //cantrip.TargetPosition += Vector3.right;
                }
                else
                {
                    for (int i = 0; i < handSize; i++)
                    {
                        if (i != hoverIndex)
                        {
                            hand[i].TargetPosition += Vector3.left * (1.5f / (hoverIndex - i));
                        }
                        else
                        {
                            hand[i].TargetPosition += Vector3.up * upDistance; //+ Vector3.back * 3;
                            hand[i].targetScale     = baseScale * scaleChange;
                        }
                    }
                }
            }

            float averageXPos = 0;

            for (int i = 0; i < handSize; i++)
            {
                averageXPos += hand[i].transform.position.x;
            }
            averageXPos = averageXPos / handSize;

            for (int i = 0; i < handSize; i++)
            {
                hand[i].targetAngle = new Vector3(0, 0, ((5 * (averageXPos - hand[i].transform.position.x)) + 360) % 360);
            }
        }
Beispiel #11
0
 public void ResetCard(CardGameObject cardSelected)
 {
     cardSelected.locked         = false;
     cardSelected.TargetPosition = cardSelected.handPosition;
 }
Beispiel #12
0
 void HandleLeftClick()
 {
     if (State == InputState.SELECTCARD)
     {
         if (cardHovering != null)
         {
             //cardController.AttemptPlayCard(cardHovering);
             if (cardController.IsPlayable(cardHovering.cardEntityId))
             {
                 cardSelected = cardHovering;
                 cardMover.ClickCard(cardSelected);
                 State = InputState.SELECTSPACE;
                 cardController.MyHandState = HandState.SELECTED;
             }
         }
     }
     else if (State == InputState.SELECTSPACE)
     {
         IEnumerable <VEntity> playableUnitIds = boardState.GetSystem <UnitFinderSystem>().GetAllPlayerUnits();
         if (boardSpaceHovering != Coord.nullCoord)
         {
             Debug.Log("Clicking space");
             int             belongs       = 0;
             IList <VEntity> belongingList = new List <VEntity>();
             foreach (VEntity v in playableUnitIds)
             {
                 if (boardState.GetAnimationSystem <PlayCardSystem>().IsSpaceInRange(boardSpaceHovering, v.id))
                 {
                     belongs++;
                     belongingList.Add(v);
                 }
             }
             Debug.Log(belongs);
             if (belongs == 0)
             {
                 //invalid space
             }
             else
             {
                 spaceSelected = boardSpaceHovering;
                 if (belongs > 1)
                 {
                     State = InputState.CONFLICTRESOLUTION;
                 }
                 else if (belongs == 1)
                 {
                     FinishPlayingCard(cardSelected, spaceSelected, belongingList[0]);
                 }
             }
         }
     }
     else if (State == InputState.CONFLICTRESOLUTION)
     {
         if (boardSpaceHovering != Coord.nullCoord)
         {
             VEntity selectedChar = boardState.GetSystem <UnitFinderSystem>().GetUnitAtCoord(boardSpaceHovering);
             if (selectedChar != null)
             {
                 CharacterClassComponent charClass = selectedChar.GetVComponent <CharacterClassComponent>();
                 if (charClass != null)
                 {
                     FinishPlayingCard(cardSelected, spaceSelected, selectedChar);
                 }
             }
         }
     }
 }
Beispiel #13
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            CellContent[, ] _currLevel = levelToLoad.levelData;
            for (int i = 0; i < _currLevel.GetLength(0); i++)
            {
                for (int j = 0; j < _currLevel.GetLength(1); j++)
                {
                    Coord c = new Coord(j, i);
                    if (_currLevel[i, j].unitData != null)
                    {
                        EntityScriptableObject unitDataObject = _currLevel[i, j].unitData;
                        ecsManager.CreateEvent("UnitCreate", component: new UnitCreateEvent {
                            position        = c,
                            entityBlueprint = unitDataObject.entity
                        });
                    }
                }
            }

            for (int i = 0; i < _currLevel.GetLength(0); i++)
            {
                for (int j = 0; j < _currLevel.GetLength(1); j++)
                {
                    Coord c = new Coord(j, i);
                    // create events for making cells
                    ecsManager.CreateEvent("CellCreate", component: new CreateTerrainCellEvent {
                        coord        = c,
                        movementCost = _currLevel[i, j].cellStruct.MovementCost,
                        cellType     = _currLevel[i, j].cellStruct.cellType
                    });
                }
            }

            //Initialize Deck

            /* foreach(string cardEntityId in deckListObject.decklist) {
             *  //ecsManager.CreateEvent
             * }*/

            CardZoneDataComponent cardZones = ecsManager.GetVSingletonComponent <CardZoneDataComponent>();
            List <VEntity>        cards     = new List <VEntity>();

            foreach (string cardName in deckList.cardNames)
            {
                // look up card in card database

                EntityScriptableObject cardEntity = cardDatabase.Cards.Find((scriptableObject) => scriptableObject.entity.GetVComponent <CardNameComponent>().name == cardName);
                Assert.IsNotNull(cardEntity);
                VEntity newCardEntity = ecsManager.InsantiateEntityFromBlueprint(cardEntity.entity);
                newCardEntity.GetVComponent <CardDisplayComponent>().cardDisplay = CardViewController.Instance.InitCard(newCardEntity);
                cards.Add(newCardEntity);

                ecsManager.ExecuteImmediateEvent("AddCardToZone", component: new CardZoneMoveEvent {
                    source      = Zone.NULL,
                    destination = Zone.DECK,
                    card        = newCardEntity.id,
                });
            }

            CardGameObject         cantrip       = GameObject.FindGameObjectWithTag("cantrip").GetComponent <CardGameObject>();
            EntityScriptableObject cantripEntity = cardDatabase.Cards.Find((scriptableObject) => scriptableObject.entity.GetVComponent <CardNameComponent>().name == "Cantrip");

            Assert.IsNotNull(cantripEntity);
            VEntity newCantripEntity = ecsManager.InsantiateEntityFromBlueprint(cantripEntity.entity);

            newCantripEntity.GetVComponent <CardDisplayComponent>().cardDisplay = CardViewController.Instance.InitCard(newCantripEntity);
            cards.Add(newCantripEntity);
            cantrip.cardEntityId = newCantripEntity.id;
            Debug.Log("Name: " + newCantripEntity.GetVComponent <CardNameComponent>().name);
            cantrip.cantrip = true;
            DeckHelper.Shuffle(cardZones.zones[Zone.DECK]);
            //HACK
        }