Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------------------

        #region Constructor

        protected UiBaseCardState(IUiCard handler, BaseStateMachine fsm, UiCardParameters parameters)
        {
            Fsm           = fsm;
            Handler       = handler;
            Parameters    = parameters;
            IsInitialized = true;
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------------------------------------------

        #region Operations

        /// <summary>
        ///     Select the card in the parameter.
        /// </summary>
        /// <param name="card"></param>
        public void SelectCard(IUiCard card)
        {
            SelectedCard = card ?? throw new ArgumentNullException("Null is not a valid argument.");

            //disable all cards
            DisableCards();
            OnCardSelected?.Invoke(SelectedCard);
        }
Esempio n. 3
0
        public UiCardTarget(IUiCard handler, Camera camera, BaseStateMachine fsm, UiCardParameters parameters)
            : base(handler, fsm, parameters)
        {
            var screenCenter = new Vector2(Screen.width, Screen.height) / 2;

            WorldCenter = camera.ScreenToWorldPoint(screenCenter).WithZ(0);
            Speed       = 8;
        }
Esempio n. 4
0
 /// <summary>
 ///     Discard the card in the parameter.
 /// </summary>
 /// <param name="card"></param>
 public void DiscardCard(IUiCard card)
 {
     if (card == null)
     {
         return;
     }
     RemoveCard(card);
     OnCardDiscarded?.Invoke(card);
 }
Esempio n. 5
0
        /// <summary>
        ///     Removes a card from the graveyard or discard pile.
        /// </summary>
        /// <param name="card"></param>
        public override void RemoveCard(IUiCard card)
        {
            if (card == null)
            {
                throw new ArgumentNullException("Null is not a valid argument.");
            }

            Cards.Remove(card);
            NotifyPileChange();
        }
Esempio n. 6
0
        //--------------------------------------------------------------------------------------------------------------

        #region Operations

        /// <summary>
        ///     Adds a card to the graveyard or discard pile.
        /// </summary>
        /// <param name="card"></param>
        public override void AddCard(IUiCard card)
        {
            if (card == null)
            {
                throw new ArgumentNullException("Null is not a valid argument.");
            }

            Cards.Add(card);
            card.transform.SetParent(graveyardPosition);
            card.Discard();
            NotifyPileChange();
        }
Esempio n. 7
0
        /// <summary>
        ///     Unselect the card in the parameter.
        /// </summary>
        /// <param name="card"></param>
        public void UnselectCard(IUiCard card)
        {
            if (card == null)
            {
                return;
            }

            SelectedCard = null;
            card.Unselect();
            NotifyPileChange();
            EnableCards();
        }
Esempio n. 8
0
        /// <summary>
        ///     Play the card in the parameter.
        /// </summary>
        /// <param name="card"></param>
        public void PlayCard(IUiCard card)
        {
            if (card == null)
            {
                throw new ArgumentNullException("Null is not a valid argument.");
            }

            SelectedCard = null;
            RemoveCard(card);
            OnCardPlayed?.Invoke(card);
            EnableCards();
            NotifyPileChange();
        }
Esempio n. 9
0
        /// <summary>
        ///     Add a card to the pile.
        /// </summary>
        /// <param name="card"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public virtual void AddCard(IUiCard card)
        {
            if (card == null)
            {
                throw new ArgumentNullException("Null is not a valied argument.");
            }

            Cards.Add(card);
            card.transform.SetParent(transform);
            card.Initialize();
            NotifyPileChange();
            card.Draw();
        }
Esempio n. 10
0
        //--------------------------------------------------------------------------------------------------------------

        #region Operations

        /// <summary>
        ///     Select the card in the parameter.
        /// </summary>
        /// <param name="card"></param>
        public void SelectCard(IUiCard card)
        {
            if (card == null)
            {
                return;
            }

            SelectedCard = card;

            //disable all cards
            DisableCards();
            NotifyCardSelected();
        }
Esempio n. 11
0
        public IEnumerator ResolveTargets(IUiCard uiCard, EffectTriggerType trigger)
        {
            if (uiCard == null)
            {
                yield return(0);
            }

            var card = uiCard.Data.RuntimeData;

            //grab all effects from the card
            var effects = GetEffects(card);

            //return if the specified trigger is not present
            if (!effects.Any(eff => eff.Key.tType == trigger))
            {
                yield return(0);
            }

            var effectsByTrigger = effects[effects.First(eff => eff.Key.tType == trigger).Key].Effects;

            //register them in the card with their respective targets
            foreach (var effect in effectsByTrigger)
            {
                var targetType = effect.Target;
                var targets    = targetType.GetTargets(card, GameData.RuntimeGame);

                if (targetType.IsDynamic)
                {
                    uiCard.Target();

                    targetType.Subscribe(this);

                    //keep checking the amount of targets until they are completely filled
                    yield return(new WaitWhile(() =>
                                               targetType.GetTargets(card, GameData.RuntimeGame).Length != targetType.TargetAmount));

                    targets = targetType.GetTargets(card, GameData.RuntimeGame);
                    effect.Target.Unsubscribe(this);
                }

                card.AddTargets(effect, targets);
            }

            //resolve the spell
            Controller.PlayerController.Player.Play(card);

            OnTargetsResolve.Invoke(uiCard);
        }
Esempio n. 12
0
        public void RemoveUiCard(CardHand card)
        {
            IUiCard removed = null;

            foreach (var key in _registry.Keys)
            {
                if (_registry[key] == card)
                {
                    removed = key;
                }
            }

            if (removed != null)
            {
                _registry.Remove(removed);
            }

            Pooler.Release(removed?.gameObject);
        }
Esempio n. 13
0
        /// <summary>
        ///     Play the card in the parameter. If can't unselect it.
        /// </summary>
        /// <param name="uiCard"></param>
        public void PlayCard(IUiCard uiCard)
        {
            if (uiCard == null)
            {
                return;
            }

            var isMyTurn    = Controller.PlayerController.IsMyTurn;
            var canPlayCost = Controller.PlayerController.Player.CanPlay(uiCard.Data.RuntimeData);

            if (!isMyTurn || !canPlayCost)
            {
                Unselect();
                return;
            }

            SelectedCard = null;
            RemoveCard(uiCard);
            OnCardPlayed?.Invoke(uiCard);
        }
Esempio n. 14
0
        //--------------------------------------------------------------------------------------------------------------

        #region Constructor

        public UiCardHandFsm(Camera camera, UiCardParameters cardConfigsParameters, IUiCard handler = null) :
            base(handler)
        {
            CardConfigsParameters = cardConfigsParameters;

            IdleState    = new UiCardIdle(handler, this, CardConfigsParameters);
            DisableState = new UiCardDisable(handler, this, CardConfigsParameters);
            DragState    = new UiCardDrag(handler, camera, this, CardConfigsParameters);
            HoverState   = new UiCardHover(handler, this, CardConfigsParameters);
            DrawState    = new UiCardDraw(handler, this, CardConfigsParameters);
            DiscardState = new UiCardDiscard(handler, this, CardConfigsParameters);

            RegisterState(IdleState);
            RegisterState(DisableState);
            RegisterState(DragState);
            RegisterState(HoverState);
            RegisterState(DrawState);
            RegisterState(DiscardState);

            Initialize();
        }
Esempio n. 15
0
 public UiMotionMovementCard(IUiCard handler) : base(handler)
 {
 }
Esempio n. 16
0
 public UiCardDrag(IUiCard handler, Camera camera, BaseStateMachine fsm, UiCardParameters parameters) : base(
         handler, fsm, parameters)
 {
     MyCamera = camera;
 }
Esempio n. 17
0
        //--------------------------------------------------------------------------------------------------------------

        protected UiMotionBaseCard(IUiCard handler) => Handler = handler;
Esempio n. 18
0
        //--------------------------------------------------------------------------------------------------------------

        public UiCardScale(IUiCard handler) : base(handler)
        {
        }
Esempio n. 19
0
 public UiCardDiscard(IUiCard handler, BaseStateMachine fsm, UiCardParameters parameters) : base(handler, fsm,
                                                                                                 parameters)
 {
 }
        //--------------------------------------------------------------------------------------------------------------

        public UiMotionRotationCard(IUiCard handler) : base(handler)
        {
        }
Esempio n. 21
0
 public UiCardMovement(IUiCard handler) : base(handler)
 {
 }
Esempio n. 22
0
        //--------------------------------------------------------------------------------------------------------------

        protected UiCardBaseTransform(IUiCard handler)
        {
            Handler = handler;
        }
Esempio n. 23
0
        //--------------------------------------------------------------------------------------------------------------

        public UiCardRotation(IUiCard handler) : base(handler)
        {
        }
Esempio n. 24
0
 private void SelectCard(IUiCard uiCard)
 {
     SelectedCard = _registry[uiCard];
 }
Esempio n. 25
0
        //--------------------------------------------------------------------------------------------------------------

        public UiCardHover(IUiCard handler, BaseStateMachine fsm, UiCardParameters parameters) : base(handler, fsm,
                                                                                                      parameters)
        {
            HoverParticleSystem = handler.gameObject.GetComponentInChildren <UiHoverParticleSystem>();
        }
Esempio n. 26
0
 void SelectCard(IUiCard uiCard) => SelectedCard = _registry[uiCard];
Esempio n. 27
0
        //--------------------------------------------------------------------------------------------------------------

        public UiCardIdle(IUiCard handler, BaseStateMachine fsm, UiCardParameters parameters) : base(handler, fsm,
                                                                                                     parameters)
        {
            DefaultSize = Handler.transform.localScale;
        }
Esempio n. 28
0
        //--------------------------------------------------------------------------------------------------------------

        public UiMotionScaleCard(IUiCard handler) : base(handler)
        {
        }
Esempio n. 29
0
        void RequestPlayCard(IUiCard uiCardPlayed)
        {
            var cardHand = _registry[uiCardPlayed];

            GameData.CurrentGameInstance.PlayCard(PlayerId.User, cardHand);
        }
Esempio n. 30
0
        //--------------------------------------------------------------------------------------------------------------

        public UiCardIdle(IUiCard handler, BaseStateMachine fsm, UiCardParameters parameters) : base(handler, fsm,
                                                                                                     parameters) =>