/* * Timed to trigger after each sequence is played for the players, allowing them to now attempt to play it back */ void SequenceTimerElapsedHandler(object source, ElapsedEventArgs args) { SequenceTimer.Stop(); State = VMEODBandStates.Performance; Lobby.Broadcast("Band_Performance", ""); SetTimer(NOTE_TIMER_DEFAULT); }
public override void OnDisconnection(VMEODClient client) { Lobby.Leave(client); State = VMEODBandStates.Idle; base.OnDisconnection(client); SetTimer(-1); }
private void EnqueueGotoState(VMEODBandStates newState) { if (State != newState) { NextState = newState; } }
void InitGame(int Timer) { ResetGame(); // PRESHOW_TIMER_DEFAULT seconds to see the player data before moving into first sequence State = VMEODBandStates.PreShow; SetTimer(Timer); }
/* * Demonstrate the sequence to be played back */ void PlayNextSequence() { SetTimer(-1); ResetRockOn(); CurrentNote = 0; State = VMEODBandStates.Rehearsal; CurrentSongLength++; SequenceTimer.Interval = MILLISECONDS_PER_NOTE_IN_SEQUENCE * (CurrentSongLength + 2); Lobby.Broadcast("Band_Sequence", GetCurrentSequence()); SequenceTimer.Start(); }
public VMEODBandPlugin(VMEODServer server) : base(server) { Lobby = new EODLobby <VMEODBandSlot>(server, 4) .BroadcastPlayersOnChange("Band_Players") .OnFailedToJoinDisconnect(); State = VMEODBandStates.Idle; SequenceTimer = new Timer(MILLISECONDS_PER_NOTE_IN_SEQUENCE); SequenceTimer.Elapsed += SequenceTimerElapsedHandler; // event listeners BinaryHandlers["Band_Decision"] = RockOnOrSellOutHandler; BinaryHandlers["Band_Note"] = NoteSelectedHandler; SimanticsHandlers[(short)VMEODBandEventTypes.NewGame] = NewGameHandler; SimanticsHandlers[(short)VMEODBandEventTypes.AnimationsFinished] = AnimationsFinishedHandler; }
/* * The object handles the payout, but the payout amount must be sent. The song length is sent for the animations of winning. */ void GameOver(bool win) { SetTimer(-1); State = VMEODBandStates.Finale; if (win) { Lobby.Broadcast("Band_Win", CumulativePayout + ""); // send the song length for the win animation Controller.SendOBJEvent(new VMEODEvent((short)VMEODBandEventTypes.NewSongLength, CurrentSongLength)); // get the prorated skill payout amount short skillPayout = (short)Math.Round(0m + (CombinedSkillAmount * SKILL_PAYOUT_MULTIPLIER * CurrentSongLength) / MAX_SONG_LENGTH); Controller.SendOBJEvent(new VMEODEvent((short)VMEODBandEventTypes.NewSkillPayout, skillPayout)); // send the win amount Controller.SendOBJEvent(new VMEODEvent((short)VMEODBandEventTypes.WinRound, (short)CumulativePayout)); } else { Controller.SendOBJEvent(new VMEODEvent((short)VMEODBandEventTypes.LoseRound)); } }
void SequenceEndHandler() { SetTimer(-1); // update payout CumulativePayout += CurrentSongLength * CurrentSongLength; if (CurrentSongLength == 25) { GameOver(true); } // if players didn't just finish a 25 note sequence, move into the decision round else { State = VMEODBandStates.Intermission; // ask players if they wish to continue, and update payout string Lobby.Broadcast("Band_Intermission", CumulativePayout + ""); SetTimer(DECISION_TIMER_DEFAULT); } }
/* * Client has pushed a valid note button */ void NoteSelectedHandler(string evt, byte[] playerChoice, VMEODClient client) { if (playerChoice == null) { return; } if (Lobby.GetPlayerSlot(client) == -1) { return; } var slot = Lobby.GetSlotData(client); if (slot == null) { return; } byte note = 9; lock (this) { if (State.Equals(VMEODBandStates.Performance)) { bool isLegal = false; note = playerChoice[0]; if (note == (byte)VMEODBandNoteTypes.Buzz) { isLegal = true; } else { // can this player even legally play this note? switch (slot.Instrument) { case VMEODBandInstrumentTypes.Trumpet: { if ((note == (byte)VMEODBandNoteTypes.Do) || (note == (byte)VMEODBandNoteTypes.Re)) { isLegal = true; } break; } case VMEODBandInstrumentTypes.Drums: { if ((note == (byte)VMEODBandNoteTypes.Mi) || (note == (byte)VMEODBandNoteTypes.Fa)) { isLegal = true; } break; } case VMEODBandInstrumentTypes.Guitar: // Creativity 2, Maxis has it backwards. I hate you, Maxis. { if ((note == (byte)VMEODBandNoteTypes.So) || (note == (byte)VMEODBandNoteTypes.La)) { isLegal = true; } break; } case VMEODBandInstrumentTypes.Keyboard: // Creativity 1, Maxis has it backwards. I hate you, Maxis. { if ((note == (byte)VMEODBandNoteTypes.Ti) || (note == (byte)VMEODBandNoteTypes.Doh)) { isLegal = true; } break; } } } if (!isLegal) { note = 9; } else { State = VMEODBandStates.BlockEvents; } } else { return; } } if (note < 9) { // play the note back to the other clients Lobby.Broadcast("Band_Note_Sync", new byte[] { note }); // check the result if (Song[CurrentNote] == note) { // note is correct but it is the buzz note if (Song[CurrentNote] == (byte)VMEODBandNoteTypes.Buzz) { Lobby.Broadcast("Band_Buzz", ""); GameOver(false); } // note is correct and players have reached the end of the sequence else if (CurrentNote == CurrentSongLength - 1) { SequenceEndHandler(); } else { // move on to the next note CurrentNote++; Lobby.Broadcast("Band_Continue_Performance", ""); State = VMEODBandStates.Performance; SetTimer(NOTE_TIMER_DEFAULT); } } else // wrong note { string failuresName = Lobby.GetSlotData(client).AvatarName; Lobby.Broadcast("Band_Fail", failuresName); GameOver(false); } } }
private void GotoState(VMEODBandStates newState) { if (!Lobby.IsFull() && !newState.Equals(VMEODBandStates.Lobby)) { EnqueueGotoState(VMEODBandStates.Lobby); } else { State = newState; switch (State) { case VMEODBandStates.Lobby: { SetTimer(-1); break; } case VMEODBandStates.PreShow: { InitGame(PRESHOW_TIMER_DEFAULT); Lobby.Broadcast("Band_Show", new byte[0]); break; } case VMEODBandStates.Rehearsal: { SetTimer(-1); ResetRockOn(); PlayNextSequence(); break; } case VMEODBandStates.Performance: { NoteState = VMEODBandStates.Performance; Lobby.Broadcast("Band_Performance", new byte[0]); SetTimer(NOTE_TIMER_DEFAULT); break; } case VMEODBandStates.Intermission: { // ask players if they wish to continue, and update payout string Lobby.Broadcast("Band_Intermission", GetPayoutData()); SetTimer(DECISION_TIMER_DEFAULT); break; } case VMEODBandStates.MinPayment: { // reduce the current song length to the closest achieved minimum CurrentSongLength -= (short)(CurrentSongLength % 5); break; } case VMEODBandStates.Electric: { SetTimer(-1); Lobby.Broadcast("Band_Electric", new byte[0]); break; } } } }
public override void Tick() { if (NextState != VMEODBandStates.Invalid) { var state = NextState; NextState = VMEODBandStates.Invalid; GotoState(state); } if (Controller != null) { if (UITimer > 0) { if (++TimerFrames >= 30) { TimerFrames = 0; UITimer--; SendTime(); } } switch (State) { case VMEODBandStates.PreShow: { if (UITimer == 0) { EnqueueGotoState(VMEODBandStates.Rehearsal); } break; } case VMEODBandStates.Performance: { if (UITimer == 0) { GameOver(false, "Band_Timeout"); } break; } case VMEODBandStates.Intermission: { if (ValidateRockOn(false)) { EnqueueGotoState(VMEODBandStates.Rehearsal); } else if (UITimer == 0) { if (ValidateRockOn(true)) { EnqueueGotoState(VMEODBandStates.Rehearsal); } else { GameOver(true, null); } } break; } case VMEODBandStates.Finale: { if (UITimer == 0) { EnqueueGotoState(VMEODBandStates.Lobby); } break; } } } }