diff options
| author | metamuffin <metamuffin@disroot.org> | 2024-06-18 21:56:03 +0200 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:21:22 +0200 | 
| commit | fe0dd480d6e93098cddc71d596a8d7e61fec68ed (patch) | |
| tree | ce86d206f8862c6a3360a412781299c5bcc567e1 /server/src/interaction.rs | |
| parent | f4bc78d9dffda792cde848e0ae8040a98959591b (diff) | |
| download | hurrycurry-fe0dd480d6e93098cddc71d596a8d7e61fec68ed.tar hurrycurry-fe0dd480d6e93098cddc71d596a8d7e61fec68ed.tar.bz2 hurrycurry-fe0dd480d6e93098cddc71d596a8d7e61fec68ed.tar.zst | |
active recipes
Diffstat (limited to 'server/src/interaction.rs')
| -rw-r--r-- | server/src/interaction.rs | 64 | 
1 files changed, 59 insertions, 5 deletions
| diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 75cd0c84..d43c71da 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -66,15 +66,69 @@ pub fn interact(      tile: &mut Tile,      player: &mut Player,  ) -> Option<InteractEffect> { +    if player.item.is_none() { +        if let Some(item) = &mut tile.item { +            if let Some(active) = &mut item.active { +                let recipe = &data.recipes[active.recipe]; +                if recipe.supports_tile(tile.kind) { +                    if let Recipe::Active { outputs, .. } = recipe { +                        if edge { +                            active.working += 1; +                        } else { +                            active.working -= 1; +                            if active.progress >= 1. { +                                player.item = outputs[0].map(|kind| Item { kind, active: None }); +                                tile.item = outputs[1].map(|kind| Item { kind, active: None }); +                                return Some(InteractEffect::Produce); +                            } +                        } +                    } +                } +            } +        } +    }      if !edge {          return None;      } -    for recipe in &data.recipes { +    for (ri, recipe) in data.recipes.iter().enumerate() {          if !recipe.supports_tile(tile.kind) {              continue;          }          match recipe { +            Recipe::Active { input, .. } => { +                if player.item.is_none() { +                    if let Some(item) = &mut tile.item { +                        if item.kind == *input { +                            if item.active.is_none() { +                                item.active = Some(Involvement { +                                    recipe: ri, +                                    working: 1, +                                    progress: 0., +                                }); +                            } +                        } +                    } +                } +                if tile.item.is_none() { +                    if let Some(item) = &player.item { +                        if item.kind == *input { +                            let mut item = player.item.take().unwrap(); +                            if let Some(active) = &mut item.active { +                                active.working += 1; +                            } else { +                                item.active = Some(Involvement { +                                    recipe: ri, +                                    working: 1, +                                    progress: 0., +                                }); +                            } +                            tile.item = Some(item); +                            return Some(InteractEffect::Put); +                        } +                    } +                } +            }              Recipe::Instant {                  inputs, outputs, ..              } => { @@ -119,11 +173,11 @@ pub fn tick_tile(dt: f32, data: &Gamedata, tile: &mut Tile) -> Option<TickEffect              if r.supports_tile(tile.kind) {                  a.progress += a.working as f32 * dt / r.duration().unwrap();                  if a.progress >= 1. { -                    let Recipe::Passive { output, .. } = &data.recipes[a.recipe] else { -                        unreachable!() +                    if let Recipe::Passive { output, .. } = &data.recipes[a.recipe] { +                        tile.item = output.map(|kind| Item { kind, active: None }); +                        return Some(TickEffect::Produce);                      }; -                    tile.item = output.map(|kind| Item { kind, active: None }); -                    return Some(TickEffect::Produce); +                    a.progress = 1.;                  }                  return Some(TickEffect::Progress);              } | 
