public ObjetosInventario(string paquete) { string[] separador = paquete.Split('~'); id_inventario = Convert.ToUInt32(separador[0], 16); id_modelo = Convert.ToInt32(separador[1], 16); cantidad = Convert.ToInt32(separador[2], 16); if (!string.IsNullOrEmpty(separador[3])) { posicion = (InventarioPosiciones)Convert.ToSByte(separador[3], 16); } FileInfo archivo_item = new FileInfo("items/" + id_modelo + ".xml"); if (archivo_item.Exists) { archivo_objeto = XElement.Load(archivo_item.FullName); nombre = archivo_objeto.Element("NOMBRE").Value; pods = short.Parse(archivo_objeto.Element("PODS").Value); tipo = byte.Parse(archivo_objeto.Element("TIPO").Value); nivel = short.Parse(archivo_objeto.Element("NIVEL").Value); tipo_inventario = InventarioUtiles.get_Objetos_Inventario(tipo); archivo_objeto = null; } archivo_item = null; }
public bool equipar_Objeto(ObjetosInventario objeto) { if (objeto == null) { return(false); } if (objeto.nivel > cuenta.juego.personaje.nivel) { cuenta.logger.log_Error("INVENTARIO", $"El nivel del objeto {objeto.nombre} es superior al nivel actual."); return(false); } if (objeto.posicion != InventarioPosiciones.NO_EQUIPADO)//objeto ya esta equipado { return(false); } List <InventarioPosiciones> possibles_posiciones = InventarioUtiles.get_Posibles_Posiciones(objeto.tipo); if (possibles_posiciones?.Count == 0)//objeto no equipable { return(false); } foreach (InventarioPosiciones posicion in possibles_posiciones) { if (get_Objeto_en_Posicion(posicion) == null) { cuenta.conexion.enviar_Paquete("OM" + objeto.id_inventario + "|" + (sbyte)posicion); cuenta.logger.log_informacion("INVENTARIO", $"{objeto.nombre} equipado."); objeto.posicion = posicion; inventario_actualizado?.Invoke(true); return(true); } } //desequipa X objeto si ya esta equipado (antibot) if (_objetos.TryGetValue(get_Objeto_en_Posicion(possibles_posiciones[0]).id_inventario, out ObjetosInventario objeto_equipado)) { objeto_equipado.posicion = InventarioPosiciones.NO_EQUIPADO; cuenta.conexion.enviar_Paquete("OM" + objeto_equipado.id_inventario + "|" + (sbyte)InventarioPosiciones.NO_EQUIPADO); } cuenta.conexion.enviar_Paquete("OM" + objeto.id_inventario + "|" + (sbyte)possibles_posiciones[0]); objeto.posicion = possibles_posiciones[0]; cuenta.logger.log_informacion("INVENTARIO", $"{objeto.nombre} equipado."); inventario_actualizado?.Invoke(true); return(true); }