Exemple #1
0
        void TowerData_Response_Handler(BinaryReader br)
        {
            TowerData td = new TowerData();

            td.Tower = br.ReadInt32();
            int floors = br.ReadInt32();

            td.Floors = new TowerFloorRecord[floors];
            for (int i = 0; i < floors; i++)
            {
                TowerFloorRecord record = new TowerFloorRecord();
                record.Floor       = br.ReadInt32();
                record.BestTime    = br.ReadInt32();
                record.RankFriends = br.ReadInt32();
                record.RankGlobal  = br.ReadInt32();
                td.Floors[i]       = record;
            }

            OnTowerDataResponse(this, td);
        }
Exemple #2
0
        void LoadTowerData(BinaryReader br, int version)
        {
            int towerCount = br.ReadInt32();

            _towerData = new TowerData[towerCount];
            for (int i = 0; i < towerCount; i++)
            {
                _towerData[i]       = new TowerData();
                _towerData[i].Tower = br.ReadInt32();

                int floorCount = br.ReadInt32();
                _towerData[i].Floors = new TowerFloorRecord[floorCount];
                for (int j = 0; j < floorCount; j++)
                {
                    TowerFloorRecord tfr = new TowerFloorRecord();
                    tfr.Floor               = br.ReadInt32();
                    tfr.BestTime            = br.ReadInt32();
                    _towerData[i].Floors[j] = tfr;
                }
            }
        }
Exemple #3
0
        private void M_Client_OnTowerDataResponse(object sender, TowerData e)
        {
            // tower data from server is not in order, re-order it now

            // find the highest floor and move into a dictionary
            int highestFloor = 0;
            Dictionary<int, TowerFloorRecord> map = new Dictionary<int, TowerFloorRecord>();
            foreach (TowerFloorRecord floor in e.Floors)
            {
                if( floor.Floor > highestFloor )
                    highestFloor = floor.Floor;
                map[floor.Floor] = floor;
            }

            e.Floors = new TowerFloorRecord[highestFloor + 1];
            e.Floors[0] = new TowerFloorRecord();
            e.Floors[0].Floor = highestFloor + 1;
            foreach (KeyValuePair<int, TowerFloorRecord> kvp in map)
            {
                int index = (highestFloor - kvp.Key) + 1;
                e.Floors[index] = kvp.Value;
            }

            // Fix any nulls that might exist
            for (int i = 1; i < e.Floors.Length; i++)
            {
                TowerFloorRecord r = e.Floors[i];
                if (r == null)
                {
                    r = new TowerFloorRecord();
                    r.Floor = e.Floors[i - 1].Floor - 1;
                    e.Floors[i] = r;
                }
            }

            // store the data
            m_TowerData = e;
        }
Exemple #4
0
        void LoadStaticTowerData(int tower)
        {
            string file = s_TowerDataFile + tower;
            TowerData td = new TowerData();
            td.Tower = tower;
            List<TowerFloorRecord> floorRecords = new List<TowerFloorRecord>();
            if (File.Exists(file))
            {
                BinaryReader br = new BinaryReader(File.OpenRead(file));
                int floorCount = br.ReadInt32();
                if (floorCount > 0)
                {
                    for (int i = 0; i < floorCount; i++)
                    {
                        TowerFloorRecord tfr = new TowerFloorRecord();
                        tfr.Floor = i + 1;
                        tfr.BestTime = br.ReadInt32();
                        tfr.RankFriends = 0;
                        tfr.RankGlobal = 0;
                        floorRecords.Add(tfr);
                    }
                }
                br.Close();
            }

            // Add 'next' floor
            TowerFloorRecord nextFloor = new TowerFloorRecord();
            nextFloor.Floor = floorRecords.Count + 1;
            floorRecords.Add(nextFloor);
            floorRecords.Reverse();
            td.Floors = floorRecords.ToArray();

            m_TowerData = td;
        }
Exemple #5
0
        public void PuzzleComplete(int tower, int floor, double completionTime)
        {
            if (m_bDisabled)
            {
                StoreStaticData();
                int floorIndex = m_TowerData.Floors.Length - floor;
                if (floorIndex < m_TowerData.Floors.Length)
                {
                    if (m_TowerData.Floors[floorIndex].BestTime == 0 || m_TowerData.Floors[floorIndex].BestTime > completionTime)
                        m_TowerData.Floors[floorIndex].BestTime = (int)completionTime;
                }
                SaveStaticTowerData(tower, m_TowerData);
            }
            else
            {
                // Tell the server
                m_Client.PuzzleComplete(tower, floor, (float)completionTime);
            }

            int maxFloor = m_GameData.TowerFloors[tower];
            if (maxFloor == floor)
            {
                // Unlock the next floor
                m_GameData.TowerFloors[tower]++;

                if (m_TowerData.Floors.Length == floor)
                {
                    List<TowerFloorRecord> records = new List<TowerFloorRecord>(m_TowerData.Floors);
                    TowerFloorRecord nf = new TowerFloorRecord();
                    nf.Floor = floor + 1;
                    records.Insert(0, nf);
                    m_TowerData.Floors = records.ToArray();
                }
            }
        }
Exemple #6
0
        void TowerData_Response_Handler(BinaryReader br)
        {
            TowerData td = new TowerData();
            td.Tower = br.ReadInt32();
            int floors = br.ReadInt32();
            td.Floors = new TowerFloorRecord[floors];
            for (int i = 0; i < floors; i++)
            {
                TowerFloorRecord record = new TowerFloorRecord();
                record.Floor = br.ReadInt32();
                record.BestTime = br.ReadInt32();
                record.RankFriends = br.ReadInt32();
                record.RankGlobal = br.ReadInt32();
                td.Floors[i] = record;
            }

            OnTowerDataResponse(this, td);
        }
Exemple #7
0
        public void SendTowerData(int tower, TowerFloorRecord[] floors)
        {
            BeginPacket(HPacketType.TowerData_Response);

            _outgoingBW.Write(tower);
            _outgoingBW.Write(floors.Length);
            foreach (TowerFloorRecord floor in floors)
            {
                _outgoingBW.Write(floor.Floor);
                _outgoingBW.Write(floor.BestTime);
                _outgoingBW.Write(floor.RankFriends);
                _outgoingBW.Write(floor.RankGlobal);
            }

            SendPacket();
        }
Exemple #8
0
        void TowerData_Process_Handler(Task t)
        {
            HTask task = (HTask)t;
            TowerDataRequstArgs args = (TowerDataRequstArgs)t.Args;

            // get the records
            List<TowerFloorRecord> floors = new List<TowerFloorRecord>();
            foreach (object[] row in t.Query.Rows)
            {
                // 0: account_id
                // 1: tower
                // 2: floor
                // 3: best_time
                // 4: friend_rank
                // 5: global_rank

                TowerFloorRecord record = new TowerFloorRecord();
                record.Floor = (int)row[2];
                record.BestTime = (int)row[3];
                record.RankFriends = (int)row[4];
                record.RankGlobal = (int)row[5];
                floors.Add(record);
            }
            task.Client.SendTowerData(args.Tower, floors.ToArray());
        }