private void ComprarMochila(int valor, string item) { if (UserCache.UsuarioLogado.Moeda >= valor) { bool resposta = util.MensagemDeConfirmacao("Deseja comprar ?", "Compra"); if (resposta) { if (telaPrincipal.itensEspeciais.Count == 1) { UserCache.Mochila = ItemCache.ListaItensEspeciais.Find(l => l.Nome == item); telaPrincipal.itensEspeciais.Add(new ItemEspecialView(UserCache.Mochila)); telaPrincipal.AbrirTela(telaPrincipal.itensEspeciais[1], telaPrincipal.lbEspeciais[1]); UserCache.UsuarioLogado.Moeda -= valor; telaPrincipal.money.Text = UserCache.UsuarioLogado.Moeda + " $"; try { itemController.AtribuirItem(UserCache.Mochila.Id); } catch (MySqlException exce) { util.MensagemDeTeste("Erro ao atribuir itens, falha na conexão ao banco de dados", "Erro!"); throw exce; } catch (Exception ex) { util.MensagemDeTeste("Erro não esperado ao atribuir itens: " + ex.Message, "Erro!"); throw ex; } UserCache.Mochila.CalcularPeso(); if (UserCache.UsuarioLogado.Peso < UserCache.UsuarioLogado.Capacidade) { ItemCache.Carregado = false; } else { ItemCache.Carregado = true; } } else if (UserCache.Mochila.Nome == item) { util.MensagemDeTeste("Você já possui está bolsa.", "Atenção!"); } else { double capacidadeAntiga = UserCache.Mochila.Peso * 100; try { itemController.DeletarItem(UserCache.Mochila.Id); } catch (MySqlException exce) { util.MensagemDeTeste("Erro ao excluir itens, falha na conexão ao banco de dados", "Erro!"); throw exce; } catch (Exception ex) { util.MensagemDeTeste("Erro não esperado ao excluir itens: " + ex.Message, "Erro!"); throw ex; } UserCache.Mochila = ItemCache.ListaItensEspeciais.Find(l => l.Nome == item); UserCache.UsuarioLogado.Moeda -= valor; telaPrincipal.AbrirTela(new ItemEspecialView(UserCache.Mochila), telaPrincipal.lbEspeciais[1]); telaPrincipal.money.Text = UserCache.UsuarioLogado.Moeda + " $"; try { itemController.AtribuirItem(UserCache.Mochila.Id); } catch (MySqlException exce) { util.MensagemDeTeste("Erro ao atribuir itens, falha na conexão ao banco de dados", "Erro!"); throw exce; } catch (Exception ex) { util.MensagemDeTeste("Erro não esperado ao atribuir itens: " + ex.Message, "Erro!"); throw ex; } UserCache.Mochila.CalcularPeso(); UserCache.UsuarioLogado.Capacidade -= capacidadeAntiga; if (UserCache.UsuarioLogado.Peso < UserCache.UsuarioLogado.Capacidade) { ItemCache.Carregado = false; } else { ItemCache.Carregado = true; } } } } else { util.MensagemDeTeste("Dinheiro Insuficiente", "Vai minerar mais!!"); } }