Esempio n. 1
0
		private void CharModButtonPress(object sender, EventArgs e)
		{
			//click delete once: pop up initial dialog, set that initial dialog has been shown
			//Character_take: delete clicked, then dialog pops up
			//Character_remove: click ok in yes/no dialog

			//click login: send WELCOME_REQUEST, get WELCOME_REPLY
			//Send WELCOME_AGREE for map/pubs if needed
			//Send WELCOME_MSG, get WELCOME_REPLY
			//log in if all okay

			int index;
			if (loginCharButtons.Contains(sender))
			{
				index = loginCharButtons.ToList().FindIndex(x => x == sender);
				if (World.Instance.MainPlayer.CharData == null || World.Instance.MainPlayer.CharData.Length <= index)
					return;

				WelcomeRequestData data;
				if (!m_packetAPI.SelectCharacter(World.Instance.MainPlayer.CharData[index].id, out data))
				{
					LostConnectionDialog();
					return;
				}

				//handles the WelcomeRequestData object
				World.Instance.ApplyWelcomeRequest(m_packetAPI, data);

				//shows the connecting window
				EOConnectingDialog dlg = new EOConnectingDialog(m_packetAPI);
				dlg.DialogClosing += (dlgS, dlgE) =>
				{
					switch (dlgE.Result)
					{
						case XNADialogResult.OK:
							doStateChange(GameStates.PlayingTheGame);
							
							World.Instance.ApplyWelcomeMessage(dlg.WelcomeData);
							
							Hud = new HUD(this, m_packetAPI);
							Components.Add(Hud);
							Hud.SetNews(dlg.WelcomeData.News);
							Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_WARNING, DATCONST2.LOADING_GAME_HINT_FIRST);
							
							if(data.FirstTimePlayer)
								EODialog.Show(DATCONST1.WARNING_FIRST_TIME_PLAYERS, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader);
							break;
						case XNADialogResult.NO_BUTTON_PRESSED:
						{
							EODialog.Show(DATCONST1.CONNECTION_SERVER_BUSY);
							if (World.Instance.Client.ConnectedAndInitialized)
								World.Instance.Client.Disconnect();
							doStateChange(GameStates.Initial);
						}
							break;
					}
				};
			}
			else if (deleteCharButtons.Contains(sender))
			{
				index = deleteCharButtons.ToList().FindIndex(x => x == sender);
				if (World.Instance.MainPlayer.CharData.Length <= index)
					return;

				if (charDeleteWarningShown != index)
				{
					EODialog.Show("Character \'" + World.Instance.MainPlayer.CharData[index].name + "\' ", DATCONST1.CHARACTER_DELETE_FIRST_CHECK);
					charDeleteWarningShown = index;
					return;
				}

				//delete character at that index, if it exists
				int takeID;
				if (!m_packetAPI.CharacterTake(World.Instance.MainPlayer.CharData[index].id, out takeID))
				{
					LostConnectionDialog();
					return;
				}

				if (takeID != World.Instance.MainPlayer.CharData[index].id)
				{
					EODialog.Show("The server did not respond properly for deleting the character. Try again.", "Server error");
					return;
				}

				EODialog.Show("Character \'" + World.Instance.MainPlayer.CharData[index].name + "\' ",
					DATCONST1.CHARACTER_DELETE_CONFIRM, XNADialogButtons.OkCancel, EODialogStyle.SmallDialogLargeHeader,
					(dlgS, dlgE) =>
					{
						if (dlgE.Result == XNADialogResult.OK) //user clicked ok to delete their character. do the delete here.
						{
							CharacterRenderData[] dataArray;
							if (!m_packetAPI.CharacterRemove(World.Instance.MainPlayer.CharData[index].id, out dataArray))
							{
								LostConnectionDialog();
								return;
							}

							World.Instance.MainPlayer.ProcessCharacterData(dataArray);
							doShowCharacters();
						}
					});
			}
		}