weapons can have tek modifiers
This commit is contained in:
parent
d9f52a73e4
commit
e4cdd2b95a
@ -81,6 +81,11 @@ pub trait EntityGateway: Send + Sync + Clone {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn add_weapon_modifier(&mut self, _item_id: &ItemEntityId, _modifier: weapon::WeaponModifier) -> Result<(), GatewayError> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
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> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
|
@ -18,6 +18,7 @@ pub struct InMemoryGateway {
|
|||||||
banks: Arc<Mutex<BTreeMap<CharacterEntityId, BankEntity>>>,
|
banks: Arc<Mutex<BTreeMap<CharacterEntityId, BankEntity>>>,
|
||||||
equips: Arc<Mutex<BTreeMap<CharacterEntityId, EquippedEntity>>>,
|
equips: Arc<Mutex<BTreeMap<CharacterEntityId, EquippedEntity>>>,
|
||||||
mag_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<mag::MagModifier>>>>,
|
mag_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<mag::MagModifier>>>>,
|
||||||
|
weapon_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<weapon::WeaponModifier>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InMemoryGateway {
|
impl InMemoryGateway {
|
||||||
@ -31,6 +32,7 @@ impl InMemoryGateway {
|
|||||||
banks: Arc::new(Mutex::new(BTreeMap::new())),
|
banks: Arc::new(Mutex::new(BTreeMap::new())),
|
||||||
equips: Arc::new(Mutex::new(BTreeMap::new())),
|
equips: Arc::new(Mutex::new(BTreeMap::new())),
|
||||||
mag_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
mag_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
||||||
|
weapon_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,9 +44,16 @@ impl InMemoryGateway {
|
|||||||
.map(|item| {
|
.map(|item| {
|
||||||
item.map_individual(|mut item| {
|
item.map_individual(|mut item| {
|
||||||
item.item = match item.item {
|
item.item = match item.item {
|
||||||
|
ItemDetail::Weapon(mut weapon) => {
|
||||||
|
if let Some(weapon_modifiers) = self.weapon_modifiers.lock().unwrap().get(&item.id) {
|
||||||
|
for weapon_modifier in weapon_modifiers.iter() {
|
||||||
|
weapon.apply_modifier(&weapon_modifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ItemDetail::Weapon(weapon)
|
||||||
|
},
|
||||||
ItemDetail::Mag(mag) => {
|
ItemDetail::Mag(mag) => {
|
||||||
let mut mag = mag::Mag::baby_mag(mag.color as u16);
|
let mut mag = mag::Mag::baby_mag(mag.color as u16);
|
||||||
println!("mag! {:?}", mag);
|
|
||||||
if let Some(mag_modifiers) = self.mag_modifiers.lock().unwrap().get(&item.id) {
|
if let Some(mag_modifiers) = self.mag_modifiers.lock().unwrap().get(&item.id) {
|
||||||
for mag_modifier in mag_modifiers.iter() {
|
for mag_modifier in mag_modifiers.iter() {
|
||||||
match mag_modifier {
|
match mag_modifier {
|
||||||
@ -69,7 +78,6 @@ impl InMemoryGateway {
|
|||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
println!("{:?} -> {:?}", mag_modifier, mag);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemDetail::Mag(mag)
|
ItemDetail::Mag(mag)
|
||||||
@ -257,6 +265,14 @@ impl EntityGateway for InMemoryGateway {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> {
|
||||||
|
self.weapon_modifiers.lock().unwrap()
|
||||||
|
.entry(*item_id)
|
||||||
|
.or_insert(Vec::new())
|
||||||
|
.push(modifier);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_character_inventory(&mut self, char_id: &CharacterEntityId) -> Result<InventoryEntity, GatewayError> {
|
async fn get_character_inventory(&mut self, char_id: &CharacterEntityId) -> Result<InventoryEntity, GatewayError> {
|
||||||
println!("getting inv");
|
println!("getting inv");
|
||||||
let inventories = self.inventories.lock().unwrap();
|
let inventories = self.inventories.lock().unwrap();
|
||||||
|
@ -320,6 +320,12 @@ impl Into<weapon::Weapon> for PgWeapon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, sqlx::FromRow)]
|
||||||
|
pub struct PgWeaponModifier {
|
||||||
|
pub weapon: i32,
|
||||||
|
pub modifier: sqlx::types::Json<weapon::WeaponModifier>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct PgArmor {
|
pub struct PgArmor {
|
||||||
armor: armor::ArmorType,
|
armor: armor::ArmorType,
|
||||||
|
@ -48,6 +48,23 @@ impl PostgresGateway {
|
|||||||
let ItemEntity {id, item, location} = item;
|
let ItemEntity {id, item, location} = item;
|
||||||
|
|
||||||
let item = match item {
|
let item = match item {
|
||||||
|
ItemDetail::Weapon(mut weapon) => {
|
||||||
|
let q = r#"select weapon, modifier
|
||||||
|
from weapon_modifier
|
||||||
|
where weapon = $1
|
||||||
|
order by created_at"#;
|
||||||
|
let weapon_modifiers = sqlx::query_as::<_, PgWeaponModifier>(q)
|
||||||
|
.bind(id.0 as i32)
|
||||||
|
.fetch(&self.pool);
|
||||||
|
|
||||||
|
weapon_modifiers.for_each(|modifier| {
|
||||||
|
if let Ok(modifier) = modifier {
|
||||||
|
weapon.apply_modifier(&modifier.modifier);
|
||||||
|
}
|
||||||
|
}).await;
|
||||||
|
|
||||||
|
ItemDetail::Weapon(weapon)
|
||||||
|
},
|
||||||
ItemDetail::Mag(mut mag) => {
|
ItemDetail::Mag(mut mag) => {
|
||||||
let q = r#"select mag, modifier, item.item -> 'Tool' as feed, item2.item -> 'Tool' as cell
|
let q = r#"select mag, modifier, item.item -> 'Tool' as feed, item2.item -> 'Tool' as cell
|
||||||
from mag_modifier
|
from mag_modifier
|
||||||
|
@ -1474,6 +1474,50 @@ impl Weapon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apply_modifier(&mut self, modifier: &WeaponModifier) {
|
||||||
|
match modifier {
|
||||||
|
WeaponModifier::Tekked{special, percents} => {
|
||||||
|
match special {
|
||||||
|
TekSpecialModifier::Plus => {
|
||||||
|
self.special = self.special.map(|special| {
|
||||||
|
special.rank_up()
|
||||||
|
});
|
||||||
|
},
|
||||||
|
TekSpecialModifier::Minus => {
|
||||||
|
self.special = self.special.map(|special| {
|
||||||
|
special.rank_down()
|
||||||
|
});
|
||||||
|
},
|
||||||
|
TekSpecialModifier::Neutral => {
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for i in 0..3 {
|
||||||
|
self.attrs[i] = self.attrs[i].map(|mut attr| {
|
||||||
|
match percents {
|
||||||
|
TekPercentModifier::PlusPlus => {
|
||||||
|
attr.value += 10;
|
||||||
|
},
|
||||||
|
TekPercentModifier::Plus => {
|
||||||
|
attr.value += 5;
|
||||||
|
},
|
||||||
|
TekPercentModifier::MinusMinus => {
|
||||||
|
attr.value -= 10;
|
||||||
|
},
|
||||||
|
TekPercentModifier::Minus => {
|
||||||
|
attr.value -= 5;
|
||||||
|
},
|
||||||
|
TekPercentModifier::Neutral => {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attr
|
||||||
|
});
|
||||||
|
}
|
||||||
|
self.tekked = true;
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn as_bytes(&self) -> [u8; 16] {
|
pub fn as_bytes(&self) -> [u8; 16] {
|
||||||
let mut result = [0u8; 16];
|
let mut result = [0u8; 16];
|
||||||
result[0..3].copy_from_slice(&self.weapon.value());
|
result[0..3].copy_from_slice(&self.weapon.value());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user