Add vendor NPC type
This commit is contained in:
parent
e93573f3a0
commit
45bedf11d2
@ -265,7 +265,7 @@
|
|||||||
"power": 4
|
"power": 4
|
||||||
},
|
},
|
||||||
"vision_range": 4,
|
"vision_range": 4,
|
||||||
"ai": "bystander"
|
"ai": "vendor"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Shady Salesman",
|
"name": "Shady Salesman",
|
||||||
@ -283,7 +283,7 @@
|
|||||||
"power": 4
|
"power": 4
|
||||||
},
|
},
|
||||||
"vision_range": 4,
|
"vision_range": 4,
|
||||||
"ai": "bystander"
|
"ai": "vendor"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Patron",
|
"name": "Patron",
|
||||||
@ -355,7 +355,7 @@
|
|||||||
"power": 4
|
"power": 4
|
||||||
},
|
},
|
||||||
"vision_range": 4,
|
"vision_range": 4,
|
||||||
"ai": "bystander"
|
"ai": "vendor"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Clothier",
|
"name": "Clothier",
|
||||||
@ -373,7 +373,7 @@
|
|||||||
"power": 4
|
"power": 4
|
||||||
},
|
},
|
||||||
"vision_range": 4,
|
"vision_range": 4,
|
||||||
"ai": "bystander"
|
"ai": "vendor"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Alchemist",
|
"name": "Alchemist",
|
||||||
@ -391,7 +391,7 @@
|
|||||||
"power": 4
|
"power": 4
|
||||||
},
|
},
|
||||||
"vision_range": 4,
|
"vision_range": 4,
|
||||||
"ai": "bystander"
|
"ai": "vendor"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Mom",
|
"name": "Mom",
|
||||||
|
@ -240,6 +240,9 @@ pub struct Door {
|
|||||||
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct Bystander {}
|
pub struct Bystander {}
|
||||||
|
|
||||||
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Vendor {}
|
||||||
|
|
||||||
// Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an
|
// Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an
|
||||||
// Entity.
|
// Entity.
|
||||||
|
|
||||||
|
@ -534,6 +534,7 @@ fn main() -> ::rltk::BError {
|
|||||||
BlocksVisibility,
|
BlocksVisibility,
|
||||||
Door,
|
Door,
|
||||||
Bystander,
|
Bystander,
|
||||||
|
Vendor,
|
||||||
);
|
);
|
||||||
|
|
||||||
gs.ecs.insert(SimpleMarkerAllocator::<SerializeMe>::new());
|
gs.ecs.insert(SimpleMarkerAllocator::<SerializeMe>::new());
|
||||||
|
@ -5,7 +5,7 @@ use ::specs::prelude::*;
|
|||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
BlocksTile, BlocksVisibility, CombatStats, Door, EntityMoved, HungerClock, HungerState, Item,
|
BlocksTile, BlocksVisibility, CombatStats, Door, EntityMoved, HungerClock, HungerState, Item,
|
||||||
Monster, Player, Position, Renderable, Viewshed, WantsToMelee, WantsToPickupItem,
|
Monster, Player, Position, Renderable, Vendor, Viewshed, WantsToMelee, WantsToPickupItem,
|
||||||
};
|
};
|
||||||
use crate::game_log::GameLog;
|
use crate::game_log::GameLog;
|
||||||
use crate::{Bystander, Map, RunState, State, TileType};
|
use crate::{Bystander, Map, RunState, State, TileType};
|
||||||
@ -24,6 +24,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
|
|||||||
let mut blocks_movement = ecs.write_storage::<BlocksTile>();
|
let mut blocks_movement = ecs.write_storage::<BlocksTile>();
|
||||||
let mut renderables = ecs.write_storage::<Renderable>();
|
let mut renderables = ecs.write_storage::<Renderable>();
|
||||||
let bystanders = ecs.read_storage::<Bystander>();
|
let bystanders = ecs.read_storage::<Bystander>();
|
||||||
|
let vendors = ecs.read_storage::<Vendor>();
|
||||||
|
|
||||||
let mut swap_entities: Vec<(Entity, i32, i32)> = Vec::new();
|
let mut swap_entities: Vec<(Entity, i32, i32)> = Vec::new();
|
||||||
|
|
||||||
@ -40,7 +41,9 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
|
|||||||
let destination_idx = map.xy_idx(pos.x + delta_x, pos.y + delta_y);
|
let destination_idx = map.xy_idx(pos.x + delta_x, pos.y + delta_y);
|
||||||
|
|
||||||
for potential_target in map.tile_content[destination_idx].iter() {
|
for potential_target in map.tile_content[destination_idx].iter() {
|
||||||
if bystanders.get(*potential_target).is_some() {
|
let bystander = bystanders.get(*potential_target);
|
||||||
|
let vendor = vendors.get(*potential_target);
|
||||||
|
if bystander.is_some() || vendor.is_some() {
|
||||||
// Note that we want to move the bystander
|
// Note that we want to move the bystander
|
||||||
swap_entities.push((*potential_target, pos.x, pos.y));
|
swap_entities.push((*potential_target, pos.x, pos.y));
|
||||||
|
|
||||||
|
@ -215,6 +215,7 @@ pub fn spawn_named_mob(
|
|||||||
match mob_template.ai.as_ref() {
|
match mob_template.ai.as_ref() {
|
||||||
"melee" => eb = eb.with(Monster {}),
|
"melee" => eb = eb.with(Monster {}),
|
||||||
"bystander" => eb = eb.with(Bystander {}),
|
"bystander" => eb = eb.with(Bystander {}),
|
||||||
|
"vendor" => eb = eb.with(Vendor {}),
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ pub fn save_game(ecs: &mut World) {
|
|||||||
BlocksVisibility,
|
BlocksVisibility,
|
||||||
Door,
|
Door,
|
||||||
Bystander,
|
Bystander,
|
||||||
|
Vendor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,6 +183,7 @@ pub fn load_game(ecs: &mut World) {
|
|||||||
BlocksVisibility,
|
BlocksVisibility,
|
||||||
Door,
|
Door,
|
||||||
Bystander,
|
Bystander,
|
||||||
|
Vendor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user