Example #1
0
 /*
  * This Simantics event happens after a win or a loss and each time a new player joins.
  */
 void NewGameHandler(short evt, VMEODClient client)
 {
     if (State.Equals(VMEODBandStates.Finale))
     {
         InitGame(FINALE_TIMER_DFEAULT);
     }
 }
 /*
  * This Simantics event only happens after a win or a loss and after each sequence round.
  */
 private void AnimationsFinishedHandler(short evt, VMEODClient client)
 {
     if (State.Equals(VMEODBandStates.MinPayment))
     {
         EnqueueGotoState(VMEODBandStates.Finale);
         Lobby.Broadcast("Band_Win", Data.VMEODGameCompDrawACardData.SerializeStrings(CumulativePayout + "", "" + CurrentSongLength));
         // 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 if (State.Equals(VMEODBandStates.Electric))
     {
         if (Lobby.IsFull())
         {
             EnqueueGotoState(VMEODBandStates.Intermission);
         }
     }
     else
     {
         if (Lobby.IsFull())
         {
             EnqueueGotoState(VMEODBandStates.PreShow);
         }
     }
 }
        /*
         * Client has pushed a valid note button
         */
        private void NoteSelectedHandler(string evt, byte[] playerChoice, VMEODClient client)
        {
            if (client == null || Lobby.GetPlayerSlot(client) == -1 || playerChoice.Length == 0 || !State.Equals(VMEODBandStates.Performance))
            {
                return;
            }
            var slot = Lobby.GetSlotData(client);

            if (slot == null)
            {
                return;
            }

            byte note = 9;

            lock (NoteDecision)
            {
                if (State.Equals(VMEODBandStates.Performance) && NoteState.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:
                            isLegal = (note == (byte)VMEODBandNoteTypes.Do) || (note == (byte)VMEODBandNoteTypes.Re); break;

                        case VMEODBandInstrumentTypes.Drums:
                            isLegal = (note == (byte)VMEODBandNoteTypes.Mi) || (note == (byte)VMEODBandNoteTypes.Fa); break;

                        case VMEODBandInstrumentTypes.Guitar:      // Creativity 2, Maxis has it backwards. I hate you, Maxis.
                            isLegal = (note == (byte)VMEODBandNoteTypes.So) || (note == (byte)VMEODBandNoteTypes.La); break;

                        case VMEODBandInstrumentTypes.Keyboard:     // Creativity 1, Maxis has it backwards. I hate you, Maxis.
                            isLegal = (note == (byte)VMEODBandNoteTypes.Ti) || (note == (byte)VMEODBandNoteTypes.Doh); break;
                        }
                    }
                    if (!isLegal)
                    {
                        note = 9; // not legal, do nothing below
                    }
                    else
                    {
                        NoteState = VMEODBandStates.BlockEvents;
                    }
                }
            }
            // handle the legal note
            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)
                    {
                        GameOver(false, "Band_Buzz");
                    }
                    // note is correct and players have reached the end of the sequence
                    else if (CurrentNote == CurrentSongLength - 1)
                    {
                        SequenceEndHandler(slot.Instrument);
                    }
                    else
                    {
                        // move on to the next note
                        CurrentNote++;
                        NoteState = VMEODBandStates.Performance;
                        Lobby.Broadcast("Band_Continue_Performance", new byte[0]);
                        SetTimer(NOTE_TIMER_DEFAULT);
                    }
                }
                else // wrong note
                {
                    string failuresName = Lobby.GetSlotData(client).AvatarName;
                    if (failuresName != null && failuresName.Length > 0)
                    {
                        Lobby.Broadcast("Band_Fail", failuresName);
                    }
                    GameOver(false, null);
                }
            }
        }
        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;
                }
                }
            }
        }