Exemple #1
0
        internal void ServerDoSummon(int _tmpCardUid, int _pos)
        {
            Dictionary <int, int> handCards = isMineAction ? mHandCards : oHandCards;

            if (!mapDic.ContainsKey(_pos) || mapDic[_pos] != isMineAction || !handCards.ContainsKey(_tmpCardUid))
            {
                Log.Write("ServerDoSummon  违规操作  uid:" + _tmpCardUid + "  pos:" + _pos);

                return;
            }

            int cardID = handCards[_tmpCardUid];

            IHeroSDS heroSDS = heroDataDic[cardID];

            if (heroSDS.GetCost() > (isMineAction ? mMoney : oMoney))
            {
                Log.Write("ServerDoSummon  违规操作  oMoney:" + oMoney);

                return;
            }

            handCards.Remove(_tmpCardUid);

            DoSummon(cardID, _pos);

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.Write(PackageTag.S2C_DOACTION);

                    bw.Write((int)ActionType.SUMMON);

                    bw.Write(cardID);

                    bw.Write(_pos);

                    serverSendDataCallBack(true, ms);

                    if (!isVsAi)
                    {
                        serverSendDataCallBack(false, ms);
                    }
                    else
                    {
                        if (!isMineAction)
                        {
                            BattleAi2.Action(this);
                        }
                    }
                }
            }
        }
Exemple #2
0
        public int ClientDoSummonMyHero(BinaryReader _br)
        {
            Dictionary <int, int> summonAction = clientIsMine ? mSummonAction : oSummonAction;

            int summonNum = summonAction.Count;

            if (summonNum > 0)
            {
                Dictionary <int, int> tmpCards = clientIsMine ? mHandCards : oHandCards;

                Dictionary <int, int> .Enumerator enumerator = summonAction.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    int tmpCardUid = enumerator.Current.Key;

                    int pos = enumerator.Current.Value;

                    int heroID = tmpCards[tmpCardUid];

                    IHeroSDS sds = heroDataDic[heroID];

                    if (clientIsMine)
                    {
                        mMoney -= sds.GetCost();
                    }
                    else
                    {
                        oMoney -= sds.GetCost();
                    }

                    tmpCards.Remove(tmpCardUid);

                    AddHero(clientIsMine, heroID, sds, pos);
                }

                summonAction.Clear();
            }

            return(summonNum);
        }
Exemple #3
0
        private void DoSummon(int _cardID, int _pos)
        {
            IHeroSDS heroSDS = heroDataDic[_cardID];

            if (isMineAction)
            {
                mMoney -= heroSDS.GetCost();
            }
            else
            {
                oMoney -= heroSDS.GetCost();
            }

            AddHero(heroUid, isMineAction, _cardID, heroSDS, _pos);

            heroUid++;

            isSkip = false;

            isMineAction = !isMineAction;
        }
Exemple #4
0
        private void DoSummonAction(BinaryWriter _mBw, BinaryWriter _oBw)
        {
            _oBw.Write(mSummonAction.Count);

            Dictionary <int, int> .Enumerator enumerator = mSummonAction.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int tmpCardUid = enumerator.Current.Key;
                int pos        = enumerator.Current.Value;

                _oBw.Write(pos);

                if (mapDic.ContainsKey(pos) && mapDic[pos] && !mapBelongDic.ContainsKey(pos) && !heroMapDic.ContainsKey(pos))
                {
                    int heroID = mHandCards[tmpCardUid];

                    _oBw.Write(heroID);

                    IHeroSDS sds = heroDataDic[heroID];

                    if (sds.GetCost() > mMoney)
                    {
                        throw new Exception("b");
                    }
                    else
                    {
                        mMoney -= sds.GetCost();
                    }

                    mHandCards.Remove(tmpCardUid);

                    AddHero(true, heroID, sds, pos);
                }
                else
                {
                    throw new Exception("d");
                }
            }

            mSummonAction.Clear();

            _mBw.Write(oSummonAction.Count);

            enumerator = oSummonAction.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int uid = enumerator.Current.Key;
                int pos = enumerator.Current.Value;

                _mBw.Write(pos);

                if (mapDic.ContainsKey(pos) && !mapDic[pos] && !mapBelongDic.ContainsKey(pos) && !heroMapDic.ContainsKey(pos))
                {
                    int heroID = oHandCards[uid];

                    _mBw.Write(heroID);

                    IHeroSDS sds = heroDataDic[heroID];

                    if (sds.GetCost() > oMoney)
                    {
                        throw new Exception("b");
                    }
                    else
                    {
                        oMoney -= sds.GetCost();
                    }

                    oHandCards.Remove(uid);

                    AddHero(false, heroID, sds, pos);
                }
                else
                {
                    throw new Exception("d");
                }
            }

            oSummonAction.Clear();
        }
Exemple #5
0
        private static void DoSummon(Battle _battle, bool _isMine, double _wrongValue)
        {
            //---summon
            int money;
            Dictionary <int, int> handCards;
            int oppBasePos;

            if (_isMine)
            {
                oppBasePos = _battle.mapData.oBase;
                money      = _battle.mMoney;
                handCards  = _battle.mHandCards;
            }
            else
            {
                oppBasePos = _battle.mapData.mBase;
                money      = _battle.oMoney;
                handCards  = _battle.oHandCards;
            }

            List <int>    cards       = new List <int>();
            List <double> randomList2 = new List <double>();

            Dictionary <int, int> .Enumerator enumerator4 = handCards.GetEnumerator();

            while (enumerator4.MoveNext())
            {
                KeyValuePair <int, int> pair = enumerator4.Current;

                int cardID = pair.Value;

                IHeroSDS heroSDS = Battle.GetHeroData(cardID);

                if (heroSDS.GetCost() <= money)
                {
                    cards.Add(pair.Key);

                    randomList2.Add(1);
                }
            }

            if (cards.Count > 0)
            {
                List <int> resultList = new List <int>();

                List <int> resultList2 = new List <int>();

                List <int> nowCheckPos = new List <int>()
                {
                    oppBasePos
                };

                Dictionary <int, bool> checkedPos = new Dictionary <int, bool>();

                checkedPos.Add(oppBasePos, false);

                while (nowCheckPos.Count > 0)
                {
                    int nowPos = nowCheckPos[0];

                    nowCheckPos.RemoveAt(0);

                    List <int> posList = BattlePublicTools.GetNeighbourPos(_battle.mapData.neighbourPosMap, nowPos);

                    for (int i = 0; i < posList.Count; i++)
                    {
                        int pos = posList[i];

                        if (!checkedPos.ContainsKey(pos))
                        {
                            checkedPos.Add(pos, false);

                            bool b = _battle.GetPosIsMine(pos);

                            if (b == _isMine)
                            {
                                if (!_battle.heroMapDic.ContainsKey(pos))
                                {
                                    resultList.Add(pos);
                                }
                            }
                            else
                            {
                                nowCheckPos.Add(pos);
                            }
                        }
                    }
                }

                for (int i = 0; i < resultList.Count; i++)
                {
                    int nowPos = resultList[i];

                    List <int> posList = BattlePublicTools.GetNeighbourPos(_battle.mapData.neighbourPosMap, nowPos);

                    for (int m = 0; m < posList.Count; m++)
                    {
                        int pos = posList[m];

                        if (!_battle.heroMapDic.ContainsKey(pos) && !resultList.Contains(pos) && !resultList2.Contains(pos))
                        {
                            bool b = _battle.GetPosIsMine(pos);

                            if (b == _isMine)
                            {
                                resultList2.Add(pos);
                            }
                        }
                    }
                }

                PublicTools.ShuffleList(cards, Battle.random);

                while (Battle.random.NextDouble() < 0.8 && cards.Count > 0 && (resultList.Count > 0 || resultList2.Count > 0))
                {
                    int cardUid = cards[0];

                    cards.RemoveAt(0);

                    randomList2.RemoveAt(0);

                    int cardID = handCards[cardUid];

                    IHeroSDS heroSDS = Battle.GetHeroData(cardID);

                    if (heroSDS.GetCost() <= money)
                    {
                        List <int> summonPosList;

                        if (resultList.Count > 0 && resultList2.Count > 0)
                        {
                            if (Battle.random.NextDouble() < 0.6)
                            {
                                summonPosList = resultList;
                            }
                            else
                            {
                                summonPosList = resultList2;
                            }
                        }
                        else if (resultList.Count > 0)
                        {
                            summonPosList = resultList;
                        }
                        else
                        {
                            summonPosList = resultList2;
                        }

                        int index = (int)(Battle.random.NextDouble() * summonPosList.Count);

                        int summonPos = summonPosList[index];

                        summonPosList.RemoveAt(index);

                        _battle.summon.Add(cardUid, summonPos);

                        money -= heroSDS.GetCost();
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Exemple #6
0
        public static void Action(Battle2 _battle)
        {
            Random random = new Random();

            bool canMove;

            bool canSummon = false;

            Dictionary <Hero2, List <int> > myHeros = new Dictionary <Hero2, List <int> >();

            Dictionary <int, Hero2> .ValueCollection.Enumerator enumerator = _battle.heroMapDic.Values.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Hero2 hero = enumerator.Current;

                if (!hero.isMine && !hero.isSummon && hero.nowPower > 0)
                {
                    List <int> tmpList = new List <int>();

                    int[] tmpArr = _battle.mapData.neighbourPosMap[hero.pos];

                    for (int i = 0; i < 6; i++)
                    {
                        if (tmpArr[i] != -1)
                        {
                            if (!_battle.heroMapDic.ContainsKey(tmpArr[i]))
                            {
                                tmpList.Add(i);
                            }
                        }
                    }

                    if (tmpList.Count > 0)
                    {
                        myHeros.Add(hero, tmpList);
                    }
                }
            }

            canMove = myHeros.Count > 0;

            List <int> summonPosList = new List <int>();

            Dictionary <int, IHeroSDS> myCards = new Dictionary <int, IHeroSDS>();

            Dictionary <int, bool> .Enumerator enumerator3 = _battle.mapDic.GetEnumerator();

            while (enumerator3.MoveNext())
            {
                if (!enumerator3.Current.Value)
                {
                    int pos = enumerator3.Current.Key;

                    if (!_battle.heroMapDic.ContainsKey(pos))
                    {
                        summonPosList.Add(pos);
                    }
                }
            }

            if (summonPosList.Count > 0)
            {
                Dictionary <int, int> .Enumerator enumerator2 = _battle.oHandCards.GetEnumerator();

                while (enumerator2.MoveNext())
                {
                    int uid = enumerator2.Current.Key;

                    int id = enumerator2.Current.Value;

                    IHeroSDS hero = Battle2.heroDataDic[id];

                    if (hero.GetCost() <= _battle.oMoney)
                    {
                        myCards.Add(uid, hero);
                    }
                }

                canSummon = myCards.Count > 0;
            }

            if (canSummon && canMove)
            {
                double r = random.NextDouble();

                if (r < 1 / 3)
                {
                    DoSummon(_battle, random, summonPosList, myCards);
                }
                else if (r < 2 * 3)
                {
                    DoMove(_battle, random, myHeros);
                }
                else
                {
                    _battle.ServerDoSkip();
                }
            }
            else if (canSummon)
            {
                double r = random.NextDouble();

                if (r < 0.5)
                {
                    DoSummon(_battle, random, summonPosList, myCards);
                }
                else
                {
                    _battle.ServerDoSkip();
                }
            }
            else if (canMove)
            {
                double r = random.NextDouble();

                if (r < 0.5)
                {
                    DoMove(_battle, random, myHeros);
                }
                else
                {
                    _battle.ServerDoSkip();
                }
            }
            else
            {
                _battle.ServerDoSkip();
            }
        }