示例#1
0
    //Sends request to GM's Game Party screen to join game with the made character.
    protected void submitJoinButton_Click(object sender, EventArgs e)
    {
        int         gameID   = 0;
        RadioButton selected = null;

        foreach (RadioButton button in gameTable.RadioButtons)
        {
            if (button.Checked)
            {
                selected = button;
            }
        }
        if (selected == null)
        {
            angryLabel.ForeColor = Color.Red;
            angryLabel.Text      = "You must select a game to join!";
            return;
        }
        else
        {
            gameID = Int32.Parse(selected.Attributes["value"]);
        }


        Int32.TryParse(perceptionTextBox.Text, out int perception);
        Int32.TryParse(hpTextBox.Text, out int hp);

        PartyMember pc = new PartyMember();

        if (nameTextBox.Text == "")
        {
            pc.Name = "No Name";
        }
        else
        {
            pc.Name = nameTextBox.Text;
        }
        pc.Race       = raceTextBox.Text;
        pc.Perception = perception;
        pc.CurrentHP  = hp;
        pc.MaxHP      = hp;
        pc.UserID     = (int)Session["userID"];
        if (sizeTextBox.Text == "")
        {
            pc.Size = 'M';
        }
        else
        {
            pc.Size = sizeTextBox.Text.ElementAtOrDefault(0);
        }
        pc.IsNpc = false;

        PartyMembersTable partyMembersTable = new PartyMembersTable(new DatabaseConnection());
        UsersTable        userTable         = new UsersTable(new DatabaseConnection());
        //partyMember.GameID = game.GameID;
        int partyMemberID = partyMembersTable.insertPartyMember(pc);

        if (partyMemberID > 0)
        {
            pc.PartyMemberID = partyMemberID;
        }
        pc.EntityID = partyMembersTable.getPartyMemberEntityID(pc.PartyMemberID);

        userTable.insertJoinRequest((int)Session["userID"], gameID, partyMemberID);

        //Load Home page
        angryLabel.ForeColor = Color.Green;
        angryLabel.Text      = "A join request has been sent to the game's Dungeon Master.";

        //Reset Stuff
        nameTextBox.Text       = "";
        raceTextBox.Text       = "";
        sizeTextBox.Text       = "";
        perceptionTextBox.Text = "";
        hpTextBox.Text         = "";
        selected.Checked       = false;
    }
示例#2
0
    //Saves changes to the party
    protected void saveButton_Click(object sender, EventArgs e)
    {
        PartyMembersTable partyMembersTable = new PartyMembersTable(new DatabaseConnection());

        partyTable.saveContentChanges();
        party.PartyMembers      = partyTable.getContent();
        Session["savedContent"] = party;

        //Foreach tableRow if its a monster, do the applicable database command (update/insert/delete) to mirror what the user has done in the table.
        Dictionary <int, int> userChoppingBlock = new Dictionary <int, int>();

        foreach (ObjectTableRow objRow in partyTable.ObjectRows)
        {
            //Only care about PartyMembers
            if (objRow.Obj.GetType() == typeof(PartyMember))
            {
                PartyMember partyMember = (PartyMember)objRow.Obj;
                //Add to character count of users
                if (partyMember.UserID != 0 && userChoppingBlock.ContainsKey(partyMember.UserID))
                {
                    userChoppingBlock[partyMember.UserID]++;
                }
                else if (partyMember.UserID != 0)
                {
                    userChoppingBlock.Add(partyMember.UserID, 1);
                }

                if (objRow.Visible == false)            //delete partyMember
                {
                    if (partyMember.PartyMemberID != 0) //Remove from database
                    {
                        partyMembersTable.deletePartyMember(partyMember);

                        //if is owned by a user, subtract from counter so we can see later if they should still have access to the game
                        if (partyMember.UserID != 0)
                        {
                            userChoppingBlock[partyMember.UserID]--;
                        }
                    }
                    party.PartyMembers.Remove(partyMember);
                }
                else if (objRow.Visible == true && partyMember.PartyMemberID != 0)
                {
                    partyMembersTable.updatePartyMember(partyMember);              //update partyMember
                }
                else if (objRow.Visible == true && partyMember.PartyMemberID == 0) //create partyMember
                {
                    partyMember.GameID = game.GameID;
                    int partyMemberID = partyMembersTable.insertPartyMember(partyMember);
                    if (partyMemberID > 0)
                    {
                        partyMember.PartyMemberID = partyMemberID;
                    }
                    partyMember.EntityID = partyMembersTable.getPartyMemberEntityID(partyMember.PartyMemberID);
                }
            }
        }
        //Remove users who should no longer have access because they have no characters
        UsersTable userTable = new UsersTable(new DatabaseConnection());

        foreach (KeyValuePair <int, int> user in userChoppingBlock)
        {
            if (user.Value <= 0)
            {
                userTable.deleteUserPlayerGame(user.Key, game.GameID);
            }
        }

        //Save to savedContent w/ new IDs
        Session["savedContent"] = party;
        Session["message"]      = new Message("Party Saved!", System.Drawing.Color.Green);

        //Reload page to clear any nonsense before loading
        Response.Redirect("GamePartyGM");
    }