|
@ -91,11 +91,64 @@ impl PostgresGateway { |
|
|
mag::MagModifier::OwnerChange(class, section_id) => {
|
|
|
mag::MagModifier::OwnerChange(class, section_id) => {
|
|
|
mag.change_owner(class, section_id)
|
|
|
mag.change_owner(class, section_id)
|
|
|
},
|
|
|
},
|
|
|
|
|
|
mag::MagModifier::WrapPresent => {mag.apply_modifier(&modifier)},
|
|
|
|
|
|
mag::MagModifier::UnwrapPresent => {mag.apply_modifier(&modifier)},
|
|
|
}
|
|
|
}
|
|
|
}).await;
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
ItemDetail::Mag(mag)
|
|
|
ItemDetail::Mag(mag)
|
|
|
},
|
|
|
},
|
|
|
|
|
|
ItemDetail::Armor(mut armor) => {
|
|
|
|
|
|
let q = r#"select armor, modifier
|
|
|
|
|
|
from armor_modifier
|
|
|
|
|
|
where armor = $1
|
|
|
|
|
|
order by created_at"#;
|
|
|
|
|
|
let armor_modifiers = sqlx::query_as::<_, PgArmorModifier>(q)
|
|
|
|
|
|
.bind(id.0 as i32)
|
|
|
|
|
|
.fetch(&self.pool);
|
|
|
|
|
|
|
|
|
|
|
|
armor_modifiers.for_each(|modifier| {
|
|
|
|
|
|
if let Ok(modifier) = modifier {
|
|
|
|
|
|
armor.apply_modifier(&modifier.modifier);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
|
|
|
ItemDetail::Armor(armor)
|
|
|
|
|
|
},
|
|
|
|
|
|
ItemDetail::Shield(mut shield) => {
|
|
|
|
|
|
let q = r#"select shield, modifier
|
|
|
|
|
|
from shield_modifier
|
|
|
|
|
|
where shield = $1
|
|
|
|
|
|
order by created_at"#;
|
|
|
|
|
|
let shield_modifiers = sqlx::query_as::<_, PgShieldModifier>(q)
|
|
|
|
|
|
.bind(id.0 as i32)
|
|
|
|
|
|
.fetch(&self.pool);
|
|
|
|
|
|
|
|
|
|
|
|
shield_modifiers.for_each(|modifier| {
|
|
|
|
|
|
if let Ok(modifier) = modifier {
|
|
|
|
|
|
shield.apply_modifier(&modifier.modifier);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
|
|
|
ItemDetail::Shield(shield)
|
|
|
|
|
|
},
|
|
|
|
|
|
ItemDetail::Unit(mut unit) => {
|
|
|
|
|
|
let q = r#"select unit, modifier
|
|
|
|
|
|
from unit_modifier
|
|
|
|
|
|
where unit = $1
|
|
|
|
|
|
order by created_at"#;
|
|
|
|
|
|
let unit_modifiers = sqlx::query_as::<_, PgUnitModifier>(q)
|
|
|
|
|
|
.bind(id.0 as i32)
|
|
|
|
|
|
.fetch(&self.pool);
|
|
|
|
|
|
|
|
|
|
|
|
unit_modifiers.for_each(|modifier| {
|
|
|
|
|
|
if let Ok(modifier) = modifier {
|
|
|
|
|
|
unit.apply_modifier(&modifier.modifier);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
|
|
|
ItemDetail::Unit(unit)
|
|
|
|
|
|
},
|
|
|
item @ _ => item
|
|
|
item @ _ => item
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
@ -416,6 +469,30 @@ impl EntityGateway for PostgresGateway { |
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_armor_modifier(&mut self, item_id: &ItemEntityId, modifier: armor::ArmorModifier) -> Result<(), GatewayError> {
|
|
|
|
|
|
sqlx::query("insert into armor_modifier (armor, modifier) values ($1, $2);")
|
|
|
|
|
|
.bind(item_id.0)
|
|
|
|
|
|
.bind(sqlx::types::Json(modifier))
|
|
|
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_shield_modifier(&mut self, item_id: &ItemEntityId, modifier: shield::ShieldModifier) -> Result<(), GatewayError> {
|
|
|
|
|
|
sqlx::query("insert into shield_modifier (shield, modifier) values ($1, $2);")
|
|
|
|
|
|
.bind(item_id.0)
|
|
|
|
|
|
.bind(sqlx::types::Json(modifier))
|
|
|
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_unit_modifier(&mut self, item_id: &ItemEntityId, modifier: unit::UnitModifier) -> Result<(), GatewayError> {
|
|
|
|
|
|
sqlx::query("insert into unit_modifier (unit, modifier) values ($1, $2);")
|
|
|
|
|
|
.bind(item_id.0)
|
|
|
|
|
|
.bind(sqlx::types::Json(modifier))
|
|
|
|
|
|
.execute(&self.pool).await?;
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
async fn get_items_by_character(&self, char_id: &CharacterEntityId) -> Result<Vec<ItemEntity>, GatewayError> {
|
|
|
async fn get_items_by_character(&self, char_id: &CharacterEntityId) -> Result<Vec<ItemEntity>, GatewayError> {
|
|
|
let q = r#"select * from (
|
|
|
let q = r#"select * from (
|
|
@ -528,7 +605,6 @@ impl EntityGateway for PostgresGateway { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn set_character_inventory(&mut self, char_id: &CharacterEntityId, inventory: &InventoryEntity) -> Result<(), GatewayError> {
|
|
|
async fn set_character_inventory(&mut self, char_id: &CharacterEntityId, inventory: &InventoryEntity) -> Result<(), GatewayError> {
|
|
|
println!("postgres.rs::set_character_inventory - received inventory entity: {:?}", inventory);
|
|
|
|
|
|
let inventory = inventory.items.iter()
|
|
|
let inventory = inventory.items.iter()
|
|
|
.map(|item| {
|
|
|
.map(|item| {
|
|
|
match item {
|
|
|
match item {
|
|
@ -541,8 +617,6 @@ impl EntityGateway for PostgresGateway { |
|
|
}
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
.collect::<Vec<_>>();
|
|
|
.collect::<Vec<_>>();
|
|
|
println!("postgres.rs::set_character_inventory - collected new inventory: {:?}", inventory);
|
|
|
|
|
|
println!("postgres.rs::set_character_inventory - updating pchar: {:?}", char_id.0);
|
|
|
|
|
|
sqlx::query("insert into inventory (pchar, items) values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
sqlx::query("insert into inventory (pchar, items) values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
.bind(char_id.0)
|
|
|
.bind(char_id.0)
|
|
|
.bind(sqlx::types::Json(inventory))
|
|
|
.bind(sqlx::types::Json(inventory))
|
|
|