Esempio n. 1
0
        public void ActivateAbility(int zoneId, int cardInstanceId, int abilityIndex)
        {
            var card = playerInfo.zones[zoneId].cards.Find(x => x.instanceId == cardInstanceId);

            if (card != null)
            {
                var libraryCard        = GameManager.Instance.config.GetCard(card.cardId);
                var activatedAbilities = libraryCard.abilities.FindAll(x => x is ActivatedAbility);
                if (activatedAbilities.Count > 0 && abilityIndex < activatedAbilities.Count)
                {
                    var activatedAbility = activatedAbilities[abilityIndex] as ActivatedAbility;
                    var cost             = activatedAbility.costs[0];
                    if (cost != null)
                    {
                        var payResourceCost = cost as PayResourceCost;
                        var statCost        = payResourceCost.value;
                        if (playerInfo.stats[payResourceCost.statId].effectiveValue >= statCost)
                        {
                            playerInfo.stats[payResourceCost.statId].baseValue -= statCost;
                            effectSolver.ActivateAbility(playerInfo, card, 0);
                            var msg = new ActivateAbilityMessage();
                            msg.playerNetId    = playerInfo.netId;
                            msg.zoneId         = zoneId;
                            msg.cardInstanceId = cardInstanceId;
                            msg.abilityIndex   = abilityIndex;
                            client.Send(NetworkProtocol.ActivateAbility, msg);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public virtual void OnActivateAbility(NetworkMessage netMsg)
        {
            var msg          = netMsg.ReadMessage <ActivateAbilityMessage>();
            var sourcePlayer = server.gameState.players.Find(x => x.netId == msg.playerNetId);

            if (sourcePlayer != null)
            {
                var card = sourcePlayer.zones[msg.zoneId].cards.Find(x => x.instanceId == msg.cardInstanceId);
                if (card != null)
                {
                    var libraryCard = GameManager.Instance.config.GetCard(card.cardId);
                    var cost        = libraryCard.costs.Find(x => x is PayResourceCost);
                    if (cost != null)
                    {
                        var payResourceCost = cost as PayResourceCost;
                        var statCost        = payResourceCost.value;
                        if (sourcePlayer.stats[payResourceCost.statId].effectiveValue >= statCost)
                        {
                            sourcePlayer.stats[payResourceCost.statId].baseValue -= statCost;
                            server.effectSolver.ActivateAbility(sourcePlayer, card, 0);
                        }
                    }
                }

                var broadcastMsg = new ActivateAbilityMessage();
                broadcastMsg.playerNetId    = msg.playerNetId;
                broadcastMsg.zoneId         = msg.zoneId;
                broadcastMsg.cardInstanceId = msg.cardInstanceId;
                broadcastMsg.abilityIndex   = msg.abilityIndex;
                foreach (var player in server.gameState.players.FindAll(x => x != sourcePlayer))
                {
                    NetworkServer.SendToAll(NetworkProtocol.ActivateAbility, broadcastMsg);
                }
            }
        }
Esempio n. 3
0
        public virtual void OnActivateAbility(ActivateAbilityMessage msg)
        {
            var card = opponentInfo.zones[msg.zoneId].cards.Find(x => x.instanceId == msg.cardInstanceId);

            if (card != null)
            {
                var libraryCard = GameManager.Instance.config.GetCard(card.cardId);
                var cost        = libraryCard.costs.Find(x => x is PayResourceCost);
                if (cost != null)
                {
                    var payResourceCost = cost as PayResourceCost;
                    var statCost        = payResourceCost.value;
                    if (opponentInfo.stats[payResourceCost.statId].effectiveValue >= statCost)
                    {
                        opponentInfo.stats[payResourceCost.statId].baseValue -= statCost;
                        effectSolver.ActivateAbility(opponentInfo, card, 0);
                    }
                }
            }
        }