Beispiel #1
0
        static CardAIPlanData CastSkillOnece(CardAI ai, NetSkill ns, NetCard nc, CardAIPlanData data, NetBattlefield bf, IEnumerator <List <int> > targetEnumerator)
        {
            //structure makes a new copy
            CardAIPlanData result = data;
            //using previous bf allows to utilize already cached data, as well as share caching with following casts.
            //later we will use new bf to ensure we do not override the same bf.
            NetBattlefield prevBf = data.bf;

            IList <int> targets = GetPlayCardTargets(ai.FriendlyTurn, ns, nc, prevBf);

            if (targets == null || targets.Count < 1)
            {
                return(new CardAIPlanData());
            }

            if (targetEnumerator == null)
            {
                targetEnumerator = GetTargetEnumerator(ns, nc, targets, ai);
                if (targetEnumerator == null)
                {
                    return(new CardAIPlanData());
                }
            }

            targetEnumerator.MoveNext();
            List <int> selectedTargets = targetEnumerator.Current;

            if (selectedTargets == null || selectedTargets.Count == 0)
            {
                return(new CardAIPlanData());
            }

            List <int> secTargets = GetSecondaryPlayTargets(ns, nc, prevBf, selectedTargets, ai.r);
            FInt       skillDelay = ns.GetSkillDelay(prevBf);
            int        cost       = prevBf.GetCardCastingCostFast(ns.GetOwner(prevBf).CardID);
            //add cost if something need to be casted next turn by AI
            var ncp = bf.GetPlayerByPlayerID(ai.playerID);

            if (cost > ncp.ApLeft)
            {
                skillDelay += 2;
            }

            //operate from now on its own bf
            result.bf = bf;
            NetQueueItem q;

            if (ns.IsCastingSpell())
            {
                q = new NetQueueItem(bf, ns, new NetListInt(selectedTargets), new NetListInt(secTargets), skillDelay, -1);
            }
            else
            {
                q = new NetQueueItem(bf, ns, null, null, skillDelay, selectedTargets[0]);
            }



            //if ap cost were larger than current ap then we will result in negative ap.
            //because its just simulation we do not care for that now, as the sum of this and next turn ap
            //for estimating cost would be identical
            ncp.ApLeft -= nc.GetCastingCost();

            bf.PlayCard(q, ai.r);
            float value = bf.GetValueByCloneSimulation(ai.iterations, ai.r);

            result.value = value;
            result.AddCardPlay(nc.CardID, ns.SkillInBattleID, q);
            result.SetEnumerator(targetEnumerator);
            result.valid = true;

            return(result);
        }