public bool equipar_Objeto(InventoryObject objeto) { if (objeto == null || objeto.cantidad == 0 || cuenta.Is_Busy()) { cuenta.Logger.LogError("INVENTAIRE", $"L'objet {objeto.nombre} ne peux être équipé"); return(false); } if (objeto.nivel > cuenta.game.character.nivel) { cuenta.Logger.LogError("INVENTAIRE", $"Le niveau de l'objet {objeto.nombre} est supérieur à ton niveau"); return(false); } if (objeto.posicion != InventorySlots.NOT_EQUIPPED)//objeto ya esta equipado { cuenta.Logger.LogError("INVENTAIRE", $"l'objet {objeto.nombre} est équipé"); return(false); } List <InventorySlots> possibles_posiciones = InventoryUtilities.get_Posibles_Posiciones(objeto.tipo); if (possibles_posiciones == null || possibles_posiciones.Count == 0)//objeto no equipable { cuenta.Logger.LogError("INVENTARIO", $"L'objet {objeto.nombre} n'est pas équipable"); return(false); } foreach (InventorySlots posicion in possibles_posiciones) { if (get_Objeto_en_Posicion(posicion) == null) { cuenta.connexion.SendPacket("OM" + objeto.id_inventario + "|" + (sbyte)posicion, true); cuenta.Logger.LogInfo("INVENTAIRE", $"{objeto.nombre} équipé."); objeto.posicion = posicion; inventario_actualizado?.Invoke(true); return(true); } } //desequipa X objeto si ya esta equipado if (_objetos.TryGetValue(get_Objeto_en_Posicion(possibles_posiciones[0]).id_inventario, out InventoryObject objeto_equipado)) { objeto_equipado.posicion = InventorySlots.NOT_EQUIPPED; cuenta.connexion.SendPacket("OM" + objeto_equipado.id_inventario + "|" + (sbyte)InventorySlots.NOT_EQUIPPED); } cuenta.connexion.SendPacket("OM" + objeto.id_inventario + "|" + (sbyte)possibles_posiciones[0]); if (objeto.cantidad == 1) { objeto.posicion = possibles_posiciones[0]; } cuenta.Logger.LogInfo("INVENTAIRE", $"{objeto.nombre} équipé."); inventario_actualizado?.Invoke(true); return(true); }
public InventoryObject(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 = (InventorySlots)Convert.ToSByte(separador[3], 16); } stats = separador[4]; string[] split = separador[4].Split(','); foreach (string stat in split) { string[] separador_stats = stat.Split('#'); string id = separador_stats[0]; if (string.IsNullOrEmpty(id)) { continue; } int stat_id = Convert.ToInt32(id, 16); if (stat_id == 110) { vida_regenerada = Convert.ToInt16(separador_stats[1], 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 = InventoryUtilities.get_Objetos_Inventario(tipo); archivo_objeto = null; } }