2020-09-17 23:02:14 +00:00
|
|
|
use crate::persistence::character_loader::CharacterLoader;
|
2021-01-08 19:12:09 +00:00
|
|
|
use common::comp::{inventory::loadout_builder::LoadoutBuilder, Body, Inventory, Item, Stats};
|
2020-09-17 23:02:14 +00:00
|
|
|
use specs::{Entity, ReadExpect};
|
|
|
|
|
2021-03-09 23:25:36 +00:00
|
|
|
const VALID_STARTER_ITEMS: [&str; 6] = [
|
|
|
|
"common.items.weapons.hammer.starter_hammer",
|
|
|
|
"common.items.weapons.bow.starter",
|
|
|
|
"common.items.weapons.axe.starter_axe",
|
|
|
|
"common.items.weapons.staff.starter_staff",
|
|
|
|
"common.items.weapons.sword.starter",
|
|
|
|
"common.items.weapons.sceptre.starter_sceptre",
|
|
|
|
];
|
|
|
|
|
2020-09-17 23:02:14 +00:00
|
|
|
pub fn create_character(
|
|
|
|
entity: Entity,
|
|
|
|
player_uuid: String,
|
|
|
|
character_alias: String,
|
|
|
|
character_tool: Option<String>,
|
|
|
|
body: Body,
|
|
|
|
character_loader: &ReadExpect<'_, CharacterLoader>,
|
|
|
|
) {
|
2021-03-09 23:25:36 +00:00
|
|
|
// quick fix whitelist validation for now; eventually replace the
|
|
|
|
// `Option<String>` with an index into a server-provided list of starter
|
|
|
|
// items, and replace `comp::body::Body` with `comp::body::humanoid::Body`
|
|
|
|
// throughout the messages involved
|
|
|
|
let tool_id = match character_tool {
|
|
|
|
Some(tool_id) if VALID_STARTER_ITEMS.contains(&&*tool_id) => tool_id,
|
|
|
|
_ => return,
|
|
|
|
};
|
|
|
|
if !matches!(body, Body::Humanoid(_)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-22 21:12:16 +00:00
|
|
|
let stats = Stats::new(character_alias.to_string());
|
2020-09-17 23:02:14 +00:00
|
|
|
|
|
|
|
let loadout = LoadoutBuilder::new()
|
|
|
|
.defaults()
|
2021-03-09 23:25:36 +00:00
|
|
|
.active_item(Some(Item::new_from_asset_expect(&tool_id)))
|
2020-09-17 23:02:14 +00:00
|
|
|
.build();
|
|
|
|
|
2021-01-08 19:12:09 +00:00
|
|
|
let mut inventory = Inventory::new_with_loadout(loadout);
|
|
|
|
|
|
|
|
// Default items for new characters
|
|
|
|
inventory.push(Item::new_from_asset_expect(
|
|
|
|
"common.items.consumable.potion_minor",
|
|
|
|
));
|
|
|
|
inventory.push(Item::new_from_asset_expect("common.items.food.cheese"));
|
|
|
|
|
2020-11-03 00:12:49 +00:00
|
|
|
let waypoint = None;
|
2020-09-17 23:02:14 +00:00
|
|
|
|
|
|
|
character_loader.create_character(
|
|
|
|
entity,
|
|
|
|
player_uuid,
|
|
|
|
character_alias,
|
2021-01-08 19:12:09 +00:00
|
|
|
(body, stats, inventory, waypoint),
|
2020-09-17 23:02:14 +00:00
|
|
|
);
|
|
|
|
}
|