From f8bc805dce27b832f1f7e8c0b48ce2c4f9117a2a Mon Sep 17 00:00:00 2001 From: serxoz Date: Sat, 24 Sep 2022 21:08:17 +0200 Subject: [PATCH] =?UTF-8?q?empezando=20coa=20acci=C3=B3n=20'abrir'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-09-12-175351_populate_object/up.sql | 4 +- src/models.rs | 2 +- src/objects.rs | 2 +- src/player.rs | 39 +++++++++++++++++++ src/rlib.rs | 1 + 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/migrations/2022-09-12-175351_populate_object/up.sql b/migrations/2022-09-12-175351_populate_object/up.sql index 340ad93..b1426a9 100644 --- a/migrations/2022-09-12-175351_populate_object/up.sql +++ b/migrations/2022-09-12-175351_populate_object/up.sql @@ -3,8 +3,8 @@ INSERT INTO object VALUES ('o0', 'item', 'palanca', 'Trozo de metal, servirá como palanca', '0', 0, NULL, '{}'), ('o1', 'item', 'calmantes', 'Calmantes, sirven para el dolor', '2', 0, NULL, '{}'), -('s0sn', 'salida', 'norte', 'Puerta automática.', '0', 0, '1', '{"open"}'), -('s1ss', 'salida', 'sur', 'Puerta automática.', '1', 0, '0', '{"open"}'), +('s0sn', 'salida', 'norte', 'Puerta automática.', '0', 0, '1', '{"open", "foo"}'), +('s1ss', 'salida', 'sur', 'Puerta automática.', '1', 0, '0', '{"open", "foo"}'), ('s1se', 'salida', 'este', 'Pasillo.', '1', 0, '2', '{}'), ('s2so', 'salida', 'oeste', 'Pasillo.', '2', 0, '1', '{}'); diff --git a/src/models.rs b/src/models.rs index bbbb696..ac8bf4b 100644 --- a/src/models.rs +++ b/src/models.rs @@ -10,7 +10,7 @@ pub struct RLocation { pub descripcion: String, } -#[derive(Queryable, Insertable)] +#[derive(Queryable, Insertable, Debug)] #[diesel(table_name = object)] #[diesel(primary_key(tag))] pub struct RObject { diff --git a/src/objects.rs b/src/objects.rs index ec48940..adcaea7 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -2,7 +2,6 @@ use crate::models::RObject; use diesel::prelude::*; use crate::database::establish_connection; - //get_object trae da base de datos un obxeto pola sua pegatina pub fn get_object(pegatina: String) -> Result { use crate::schema::object::dsl::*; @@ -63,3 +62,4 @@ pub fn get_salidas_here(pegatina: String, nome: String) -> Result String { output } + +//execute_open cambia a condición 'close' a 'open' de un obxeto nesta sala polo nome +pub fn execute_open(player: &mut Player, nombre: &str) -> String { + let mut output = String::from(""); + let location = &player.location; + let objeto = get_object_here(location.to_string(), nombre.to_string()); + + if objeto.is_ok() { + let obj = objeto.unwrap(); + // println!("{:?}", obj); + + if obj.tipo == "salida" { + for condicion in obj.condiciones { + if condicion.as_ref().unwrap() == "open" { + output = String::from("Ya está abierta."); + break; + } else if condicion.as_ref().unwrap() == "closed" { + // está cerrada, actualizar a open + // e actualizar a salida en sentido contrario + // implementar actualizar_condiciones() + // implementar get_salida_opuesta() + output = String::from("Está cerrada."); + + + + break; + } else { + output = String::from(""); + } + } + } else { + // é un item + output = String::from("No se puede abrir."); + } + } else { + output = String::from("No se encuentra aquí.") + } + output +} diff --git a/src/rlib.rs b/src/rlib.rs index 3ac7038..8e8e790 100644 --- a/src/rlib.rs +++ b/src/rlib.rs @@ -106,6 +106,7 @@ pub fn update_state(player: &mut Player, command: &Command) -> String { "coger" => output = execute_pick(player, command.noun.as_str()), "tirar" => output = execute_drop(player, command.noun.as_str()), "matar" => output = execute_kill(player, command.noun.as_str()), + "abrir" => output = execute_open(player, command.noun.as_str()), _ => output = format!("No se como hacer eso."), }