Ejemplo n.º 1
0
        public void ServerUpdate()
        {
            List <PlayerAction> list;

            if (recordData.action.TryGetValue(tick, out list))
            {
                using (MemoryStream mMs = new MemoryStream(), oMs = new MemoryStream())
                {
                    using (BinaryWriter mBw = new BinaryWriter(mMs), oBw = new BinaryWriter(oMs))
                    {
                        mBw.Write(PackageTag.S2C_UPDATE);

                        oBw.Write(PackageTag.S2C_UPDATE);

                        mBw.Write(tick);

                        oBw.Write(tick);

                        mBw.Write(list.Count);

                        oBw.Write(list.Count);

                        List <KeyValuePair <bool, int> > mList = null;

                        List <KeyValuePair <bool, int> > oList = null;

                        for (int i = 0; i < list.Count; i++)
                        {
                            PlayerAction action = list[i];

                            action.Write(mBw);

                            action.Write(oBw);

                            if (action.isMine)
                            {
                                if (action.uid < recordData.mCards.Length)
                                {
                                    if (oList == null)
                                    {
                                        oList = new List <KeyValuePair <bool, int> >();
                                    }

                                    oList.Add(new KeyValuePair <bool, int>(true, action.uid));

                                    oCardsShowList.Add(action.uid);
                                }

                                if (recordData.mCards.Length > mCardsShowNum)
                                {
                                    if (mList == null)
                                    {
                                        mList = new List <KeyValuePair <bool, int> >();
                                    }

                                    mList.Add(new KeyValuePair <bool, int>(true, mCardsShowNum));

                                    mCardsShowNum++;
                                }
                            }
                            else
                            {
                                if (action.uid < recordData.oCards.Length)
                                {
                                    if (mList == null)
                                    {
                                        mList = new List <KeyValuePair <bool, int> >();
                                    }

                                    mList.Add(new KeyValuePair <bool, int>(false, action.uid));

                                    mCardsShowList.Add(action.uid);
                                }

                                if (recordData.oCards.Length > oCardsShowNum)
                                {
                                    if (oList == null)
                                    {
                                        oList = new List <KeyValuePair <bool, int> >();
                                    }

                                    oList.Add(new KeyValuePair <bool, int>(false, oCardsShowNum));

                                    oCardsShowNum++;
                                }
                            }
                        }

                        if (mList != null)
                        {
                            mBw.Write(mList.Count);

                            for (int i = 0; i < mList.Count; i++)
                            {
                                KeyValuePair <bool, int> pair = mList[i];

                                mBw.Write(pair.Key);

                                mBw.Write(pair.Value);

                                if (pair.Key)
                                {
                                    mBw.Write(recordData.mCards[pair.Value]);
                                }
                                else
                                {
                                    mBw.Write(recordData.oCards[pair.Value]);
                                }
                            }
                        }
                        else
                        {
                            mBw.Write(0);
                        }

                        if (oList != null)
                        {
                            oBw.Write(oList.Count);

                            for (int i = 0; i < oList.Count; i++)
                            {
                                KeyValuePair <bool, int> pair = oList[i];

                                oBw.Write(pair.Key);

                                oBw.Write(pair.Value);

                                if (pair.Key)
                                {
                                    oBw.Write(recordData.mCards[pair.Value]);
                                }
                                else
                                {
                                    oBw.Write(recordData.oCards[pair.Value]);
                                }
                            }
                        }
                        else
                        {
                            oBw.Write(0);
                        }

                        if (processBattle || recordData.isVsAi)
                        {
                            mBw.Write(battle.GetData());

                            oBw.Write(battle.GetData());
                        }

                        serverSendDataCallBack(true, true, mMs);

                        serverSendDataCallBack(false, true, oMs);
                    }
                }
            }
            else
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    using (BinaryWriter bw = new BinaryWriter(ms))
                    {
                        bw.Write(PackageTag.S2C_UPDATE);

                        bw.Write(tick);

                        bw.Write(0);

                        if (processBattle || recordData.isVsAi)
                        {
                            bw.Write(battle.GetData());
                        }

                        serverSendDataCallBack(true, true, ms);

                        serverSendDataCallBack(false, true, ms);
                    }
                }
            }

            tick++;

            if (processBattle || recordData.isVsAi)
            {
                SuperEnumerator <ValueType> superEnumerator = new SuperEnumerator <ValueType>(battle.Update());

                superEnumerator.Done();

                BattleResult result = ((BattleResultVO)superEnumerator.Current).result;

                if (result == BattleResult.NOT_OVER)
                {
                    if (recordData.isVsAi)
                    {
                        int uid;

                        int pos;

                        BattleAi.Start(battle, false, random.Next, out uid, out pos);

                        if (uid != -1)
                        {
                            List <PlayerAction> tmpList = new List <PlayerAction>();

                            recordData.action.Add(tick, tmpList);

                            tmpList.Add(new PlayerAction(false, uid, pos));

                            battle.AddAction(false, uid, pos);
                        }
                    }
                }
                else
                {
                    Reset();

                    battleOverCallBack(result);
                }
            }
        }
Ejemplo n.º 2
0
        private void RefreshData(BinaryReader _br)
        {
            Reset();

            clientIsMine = _br.ReadBoolean();

            serverProcessBattle = _br.ReadBoolean();

            int num = _br.ReadInt32();

            int[] mCards = new int[num];

            num = _br.ReadInt32();

            int[] oCards = new int[num];

            int mBase = _br.ReadInt32();

            int oBase = _br.ReadInt32();

            int maxTime = _br.ReadInt32();

            Init(mCards, oCards, mBase, oBase, maxTime);

            int nowTick = _br.ReadInt32();

            num = _br.ReadInt32();

            for (int i = 0; i < num; i++)
            {
                bool isMine = _br.ReadBoolean();

                int uid = _br.ReadInt32();

                int id = _br.ReadInt32();

                SetCard(isMine, uid, id);
            }

            num = _br.ReadInt32();

            for (int i = 0; i < num; i++)
            {
                int tmpTick = _br.ReadInt32();

                for (int m = tick; m < tmpTick; m++)
                {
                    SuperEnumerator <ValueType> superEnumerator = new SuperEnumerator <ValueType>(Update());

                    superEnumerator.Done();
                }

                int num2 = _br.ReadInt32();

                for (int m = 0; m < num2; m++)
                {
                    bool isMine = _br.ReadBoolean();

                    int uid = _br.ReadInt32();

                    int pos = _br.ReadInt32();

                    AddAction(isMine, uid, pos);
                }
            }

            for (int i = tick; i < nowTick; i++)
            {
                SuperEnumerator <ValueType> superEnumerator = new SuperEnumerator <ValueType>(Update());

                superEnumerator.Done();
            }

            clientRefreshDataCallBack();
        }