コード例 #1
0
        public void CloneTest001()
        {
            CardInstance ci = new CardInstance();

            PopulateObject(ci, StartProp);

            ci.PropertyChanged += (s, e) => { };

            CardInstance clone = ci.Clone() as CardInstance;

            foreach (PropertyInfo p in typeof(CardInstance).GetProperties())
            {
                if (p.CanWrite)
                {
                    TestContext.WriteLine("Checking prop:{0}.{1};{2}", p.Name, p.GetValue(ci), p.GetValue(clone));

                    if ((p.Name == nameof(CardInstance.Card)) ||//skip do not clone as this will never change anyway! (read from DB)
                        (p.Name == nameof(CardInstance.BorderBrush)))    //brush wont be modified
                    {
                        continue;
                    }
                    Assert.IsFalse(Object.ReferenceEquals(p.GetValue(ci), p.GetValue(clone)));
                }
            }

            foreach (EventInfo ev in typeof(CardInstance).GetEvents())
            {
                FieldInfo fieldTheEvent = GetAllFields(typeof(CardInstance)).Where(f => f.Name == ev.Name).First();
                Assert.IsNull(fieldTheEvent.GetValue(clone));
            }
        }
コード例 #2
0
ファイル: BattleManager.cs プロジェクト: tiance7/XianCard
    //使用技能卡
    internal void UseSkillCard(CardInstance cardInstance, CardTemplate template, int targetInstId = 0)
    {
        _battleModel.effectStat = new EffectStatistics();

        Debug.Log("card used:" + cardInstance.tplId);
        int iCost = template.iCost;

        if (-1 == iCost)
        {
            iCost = _battleModel.curCost;
        }

        _battleModel.ReduceCost(iCost);
        _battleModel.effectStat.consumeCost += (uint)iCost;

        HandleCardEffect(cardInstance, template.nEffectId, targetInstId);

        _battleModel.roundStat.lstUsedCard.Add(cardInstance.Clone());
        _battleModel.battleStat.useCardCount += 1;

        //处理卡牌去向
        if (template.bExhaust)
        {
            //消耗
            _battleModel.ExhaustHandCard(cardInstance);
        }
        else
        {
            switch (template.nType)
            {
            case CardType.ATTACK:
            case CardType.SKILL:
                _battleModel.MoveHandCardToUsed(cardInstance);
                break;

            case CardType.FORMATION:
                _battleModel.ConsumeHandCard(cardInstance);
                break;

            default:
                Debug.LogError("unhandle card type:" + template.nType);
                break;
            }
        }
    }
コード例 #3
0
ファイル: BattleModel.cs プロジェクト: tiance7/XianCard
    /// <summary>
    /// 抽一张牌
    /// </summary>
    internal CardInstance DrawOneCard(bool bRoundStartDraw)
    {
        CardInstance drawCard = _lstDeck[0];

        if (drawCard == null)
        {
            Debug.LogError("no card for draw!");
            return(null);
        }
        _lstDeck.RemoveAt(0);
        SendEvent(BattleEvent.DECK_NUM_UPDATE);
        _lstHand.Add(drawCard);
        SendEvent(BattleEvent.DRAW_ONE_CARD, drawCard);

        if (!bRoundStartDraw)
        {
            CardInstance cloneCard = drawCard.Clone();
            effectStat.lstDrawCard.Add(cloneCard);
            roundStat.lstDrawCard.Add(cloneCard);
        }

        return(drawCard);
    }