diff options
| author | troido <troido@protonmail.com> | 2020-04-15 12:23:06 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-15 12:23:06 +0200 |
| commit | 43bde225ebbadd0b917ca87f3164a50455a2b588 (patch) | |
| tree | c9c2bb0c6839af01a02acba1c338b2d8c59cfcb5 | |
| parent | 30a5688010bf07a9e0807ed0c2dc7c51f0e9dae4 (diff) | |
visit other players
| -rw-r--r-- | content/encyclopediae/default_encyclopedia.json | 7 | ||||
| -rw-r--r-- | content/maps/smallview.json | 5 | ||||
| -rw-r--r-- | src/components/interactable.rs | 14 | ||||
| -rw-r--r-- | src/components/mod.rs | 7 | ||||
| -rw-r--r-- | src/room.rs | 2 | ||||
| -rw-r--r-- | src/systems/interact.rs | 23 |
6 files changed, 47 insertions, 11 deletions
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json index ac25482..d3d0507 100644 --- a/content/encyclopediae/default_encyclopedia.json +++ b/content/encyclopediae/default_encyclopedia.json @@ -80,6 +80,13 @@ ], "flags": ["Floor"] }, + "homeportal": { + "components": [ + ["RoomExit", {"destination": "_home+{player}", "dest_pos": ""}], + ["Interactable", {"action": ["interaction", ["visit", "_home+{player}"]]}] + ], + "flags": ["Floor"] + }, "img": { "arguments": [["sprite", "string", ""], ["height", "float", 1.0]], "components": [ diff --git a/content/maps/smallview.json b/content/maps/smallview.json index bcfd1f4..e9699a6 100644 --- a/content/maps/smallview.json +++ b/content/maps/smallview.json @@ -70,10 +70,7 @@ "type": "portal", "kwargs": {"destination": "town", "destpos": "gate"} }, "floor"], - "3": [{ - "type": "portal", - "kwargs": {"destination": "_home+{player}"} - }, "floor"], + "3": ["homeportal", "floor"], "4": [{ "type": "portal", "kwargs": {"destination": "room"} diff --git a/src/components/interactable.rs b/src/components/interactable.rs index 1787a33..3432f33 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -8,7 +8,8 @@ use specs::{ use crate::{ exchange::Exchange, ItemId, - components::Trigger + components::Trigger, + RoomId }; #[derive(Component, Debug, Clone, PartialEq)] @@ -17,7 +18,8 @@ pub enum Interactable { Trigger(Trigger), Say(String), Reply(String), - Exchange(String, HashMap<String, Exchange>) + Exchange(String, HashMap<String, Exchange>), + Visit(RoomId) } use Interactable::*; @@ -44,6 +46,7 @@ impl Interactable { }) .collect::<Option<HashMap<String, Exchange>>>()? ), + "visit" => Visit(RoomId::from_str(arg.as_str()?)), _ => None? }) } @@ -60,6 +63,13 @@ impl Interactable { true } } + Visit(_) => { + if let Some(txt) = arg { + txt.starts_with("visit") + } else { + false + } + } } } } diff --git a/src/components/mod.rs b/src/components/mod.rs index 6692445..ae50edc 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -29,6 +29,8 @@ pub use ear::{ Ear }; +use std::collections::HashMap; + use specs::{ DenseVecStorage, VecStorage, @@ -225,6 +227,11 @@ pub struct Build { pub obj: Template } +#[derive(Component, Debug, Clone)] +pub struct Whitelist{ + pub allowed: HashMap<String, PlayerId> +} + diff --git a/src/room.rs b/src/room.rs index dbdb46f..c9fb525 100644 --- a/src/room.rs +++ b/src/room.rs @@ -118,7 +118,7 @@ impl <'a, 'b>Room<'a, 'b> { world.insert(NewEntities::new(encyclopedia)); register_insert!( world, - (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, Equipment, TimeOffset, Flags, Ear, Build), + (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, Equipment, TimeOffset, Flags, Ear, Build, Whitelist), (Ground, Input, Output, Size, Spawn, Players, Emigration, Time) ); diff --git a/src/systems/interact.rs b/src/systems/interact.rs index 6df0066..c3cd0d2 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -20,10 +20,13 @@ use crate::{ Notification, Ear, Inventory, - Visible + Visible, + Player }, controls::{Control}, - resources::{Ground, NewEntities} + resources::{Ground, NewEntities, Emigration}, + hashmap, + playerstate::RoomPos }; pub struct Interact; @@ -39,10 +42,12 @@ impl <'a> System<'a> for Interact { Write<'a, NewEntities>, WriteStorage<'a, Ear>, WriteStorage<'a, Inventory>, - ReadStorage<'a, Visible> + ReadStorage<'a, Visible>, + ReadStorage<'a, Player>, + Write<'a, Emigration> ); - fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut triggerbox, new, mut ears, mut inventories, visibles): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut triggerbox, new, mut ears, mut inventories, visibles, players, mut emigration): Self::SystemData) { for (entity, controller, position) in (&entities, &controllers, &positions).join(){ let mut target = None; let ear = ears.get_mut(entity); @@ -101,6 +106,16 @@ impl <'a> System<'a> for Interact { ); } } + Interactable::Visit(dest) => { + if let Some(player) = players.get(entity){ + let argument = arg.unwrap(); + if argument.starts_with("visit") { + let playername = argument.split_at("visit ".len()).1; + let destination = dest.format(hashmap!("{player}" => playername)); + emigration.emigrants.push((player.id.clone(), destination, RoomPos::Unknown)); + } + } + } } cooldowns.insert(entity, ControlCooldown{amount: 2}).unwrap(); } |
