예제 #1
0
        public void loadSong(Song song, int difficulty, Mods m, Replay replay, PlayType t)
        {
            for (int i = 0; i < 8; i++)
            {
                holding[i] = false;
                canHit[i] = true;
            }
            first = true;
            specFailed = false;
            scoreMod = 1;
            hp = 100;
            notAdded = true;
            mods = m;
            currentReplay = null;
            playType = t;
            currentSong = song;
            this.difficulty = difficulty;
            chart = song.Charts[difficulty];
            hitWindow = 50;
            hitWindow = hitWindow + (chart.Judgement * 20);
            keygroup = chart.Keys - 5;
            switch (t)
            {
                case PlayType.PLAY:
                    recordingReplay = true;
                    this.replay = false;
                    currentReplay = new Replay();
                    this.currentReplay.Mods = m;
                    currentReplay.Mods = mods;
                    if (Config.Spectating)
                    {
                        Config.Spectating = false;
                        try
                        {
                            PacketWriter.sendSpectateCancel(Game.conn.Bw, Config.SpectatedUser);
                        }
                        catch
                        {
                        }
                    }
                    break;
                case PlayType.REPLAY:
                    recordingReplay = false;
                    currentReplay = replay;
                    this.replay = true;
                    this.mods = replay.Mods;
                    foreach (var pair in currentReplay.PressTimings)
                    {
                        pair.value.value = false;
                    }
                    foreach (var pair in currentReplay.ReleaseTimings)
                    {
                        pair.value.value = false;
                    }
                    foreach (ReplayHit h in currentReplay.HitTimings)
                    {
                        h.Used = false;
                    }
                    break;
                case PlayType.TEST:
                    recordingReplay = false;
                    this.replay = false;
                    generateAutoReplay();
                    break;
                case PlayType.AUTO:
                    this.replay = true;
                    this.recordingReplay = false;
                    generateAutoReplay();
                    break;
                case PlayType.SPECTATE:
                    this.replay = true;
                    currentReplay = new Replay();
                    break;
            }

            Game.M.Music.stop();
            try
            {
                PacketWriter.sendSongStart(Game.conn.Bw, Account.currentAccount.AccountName, Utils.calcHash(chart.Path), song.Artist + " - " + song.SongName, (short)playType, mods.Flags, Convert.ToDouble(mods.Scroll, Config.cultureEnglish), mods.Speed);
            }
            catch
            {
            }
            try
            {
                breaksound = File.ReadAllBytes(Skin.skindict["combobreak"]);
                hitsound = File.ReadAllBytes(Skin.skindict["normal-hitnormal"]);
            }
            catch
            {
                Console.WriteLine("Error loading hitsounds, probably missing file");
            }
            if (currentSong.FileVersion == 0)
            {
                music = AudioManager.loadFromFile("songs\\" + currentSong.Dir + "\\" + currentSong.FileName);
            }
            else
            {
                music = AudioManager.loadFromFile("songs\\" + currentSong.Dir + "\\" + currentSong.FileName); //fix in future to load per chart
            }
            Music.PositionAsMilli = 0;
            Music.Volume = Config.Volume / 100.0f;
            currentOffset = -(chart.LeadInTime * 1000);
            endOffset = 0;
            startOffset = -1;
            foreach (Note n in chart.Notes)
            {
                n.Vertical = -20;
                if (n.Hold)
                {
                    n.HoldVertical = -20;
                }
                n.Enabled = true;
                n.Visible = true;
                n.setAlpha(1.0f);
                n.setColor();
                n.Texture.Fading = false;
                n.Holdbar.Fading = false;
                n.HoldEnd.Fading = false;
                if (startOffset < 0)
                    startOffset = n.Offset;
                if (n.Hold)
                {
                    if (n.HoldOffset > endOffset)
                    {
                        endOffset = n.HoldOffset;
                    }
                }
                else if (n.Offset > endOffset)
                {
                    endOffset = n.Offset;
                }
                if (n.Offset < startOffset)
                {
                    startOffset = n.Offset;
                }
            }
            endOffset += 1500;
            Dictionary<int, int> moves = new Dictionary<int, int>();
            foreach (TimingSection s in currentSong.TimingsList)
            {
                if (s.ChangeSnap)
                {
                    double move = 60 / (s.Snap / 1000);
                    if (move > 400)
                    {
                        move = 400;
                    }
                    double perc = (move / 400) * 100;
                    move = 3000 - (27 * perc);
                    try
                    {
                        moves.Add((int)s.Offset, (int)move);
                    }
                    catch { }
                }
            }
            List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>();
            list.Sort((f, s) =>
            {
                return f.Key.CompareTo(s.Key);
            });
            invert = false;
            if ((mods.Flags & 4) == 4)
            {
                invert = true;
            }
            if ((mods.Flags & 8) == 8)
            {
                scoreMod += 0.05;
            }
            List<int> keys = new List<int>(moves.Keys);
            List<int> offs = new List<int>(moves.Values);
            foreach (Note n in chart.Notes)
            {
                if (n.Offset < keys[0])
                {
                    n.MoveTime = (int)(offs[0] / (mods.Scroll > 5 ? mods.Scroll / 10 : mods.Scroll));
                }
            }
            foreach (Note n in chart.Notes)
            {
                foreach (var pair in moves)
                {
                    if (n.Offset >= pair.Key)
                    {
                        n.MoveTime = (int)(pair.Value / (mods.Scroll > 5 ? mods.Scroll / 10 : mods.Scroll));
                    }
                }
                if (invert)
                {
                    n.Location = 9 - n.Location;
                }
            }
            time1 = 0;
            time2 = 0;
            time3 = 0;
            finalScore = new Score();
        }
예제 #2
0
파일: Game.cs 프로젝트: Zhangerr/pulse
        void conn_recvPacket(short arg1, Client.RecievePacket arg2)
        {
            
            switch (arg1)
            {
                case (short)Pulse.Client.RecvHeaders.VERSION_CHECK:
                    double serverversion = (double)arg2.info[0];
                    if (serverversion > Config.Version)
                    {
                        serverVer = serverversion;
                        verRemind = true;
                    }
                    else
                    {
                        Console.WriteLine("running latest ver of pulse");
                    }
                    break;
                case (short)Pulse.Client.RecvHeaders.LOGIN_AUTH:
                    byte login = (byte)arg2.info[0];
                    if (login == 0) //successful
                    {
                        Account.currentAccount = new Account((string)arg2.info[2], (string)arg2.info[1], (string)arg2.info[3]);
                        //going to assume i can't set text from here because of gl context crap
                        //Game.game.Context.Ma
                        ((MenuScreen)screens["menuScreen"]).downloadAvatar();
                        lock (ircLock)
                        {
                            if (Game.ircl != null)
                            {
                                Game.ircl.terminate();
                                Game.ircl = null;
                            }
                            setMarquee = true;
                            Game.ircl = new Client.irc.IrcClient("pulse|" + Account.currentAccount.AccountName, Account.currentAccount.AccountName);
                            Game.ircl.realNick = Account.currentAccount.AccountName;
                            Game.pbox.setIrc(Game.ircl);
                        }
                    }
                    else
                    {
                        Game.addToast("Login failed");
                    }
                    break;
                case (short)Pulse.Client.RecvHeaders.SPECTATE_RECORD:
                    Config.Spectated = true;
                    break;
                case (short)Pulse.Client.RecvHeaders.SPECTATE_END:
                    Config.Spectated = false;
                    break;
                case (short)Pulse.Client.RecvHeaders.SPECTATE_START:
                    Config.SpectatedUser = (string)arg2.info[0];
                    Config.Spectating = true;
                    int diff = 0;
                    SongInfo song = SongLibrary.findByMD5((string)arg2.info[1], ref diff);
                    if (song != null)
                    {                        
                        stopMedia = true;
                        IngameScreen temp = (IngameScreen)game.screens["ingameScreen"];
                        try
                        {
                            if (active.Music != null)
                            {
                                active.Music.pause();
                            }
                            Mods m = new Mods()
                            {
                                Flags = (uint)((int)arg2.info[2]),
                                Scroll = (double)arg2.info[3]
                            };
                            temp.loadSong(SongLibrary.loadSong(song), diff, m, new Replay(), IngameScreen.PlayType.SPECTATE);
                            Game.setScreen(game.screens["ingameScreen"]);
                            Game.M.Music.pause();
                            Game.M.setSong(ref song);
                            Game.M.Visible = false;
                            Game.M.Enabled = false;
                            Client.PacketWriter.sendSpectateGotChart(Game.conn.Bw);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message + e.StackTrace);
                        }
                    }
                    break;
                case (short)Pulse.Client.RecvHeaders.SPECTATE_CANCEL:
                    if (active is IngameScreen)
                    {
                        if (active.Music != null)
                        {
                            active.Music.stop();
                        }
                        Config.Spectating = false;
                        Config.SpectatedUser = "";
                        Config.Specs = "";
                        Game.setScreen(game.screens["menuScreen"]);
                    }
                    break;
                case (short)Pulse.Client.RecvHeaders.SPECTATE_USERS:
                    Config.Specs = (string)arg2.info[0];
                    Console.WriteLine(arg2.info[0]);
                    break;
                case (short)Pulse.Client.RecvHeaders.SPECTATE_USERS_ME:
                    Config.SpecsOnMe = (string)arg2.info[0];
                    Console.WriteLine(arg2.info[0]);
                    break;

            }
        }