reverse inventory definition

This commit is contained in:
Niko Abeler 2023-01-07 09:50:09 +01:00
parent d655da0738
commit a1050c1440
4 changed files with 11 additions and 5 deletions

View File

@ -24,7 +24,6 @@ pub struct Creature {
pub birth_date: Time,
pub profession: Profession,
pub agenda: Agenda,
pub inventory: Vec<EntityId>,
pub weapon: Option<EntityId>,
pub armor: Option<EntityId>,
}
@ -50,7 +49,6 @@ impl Creature {
birth_date: birth_date,
profession: profession,
agenda: Agenda::Idle(0),
inventory: Vec::new(),
weapon: None,
armor: None,
}

View File

@ -7,7 +7,8 @@ pub struct ItemCrafted {
impl Action for ItemCrafted {
fn apply(&self, state: &mut GameState) {
state.add_item(self.item.clone());
let item_id = state.add_item(self.item.clone());
state.claim_item(self.crafter, item_id);
}
fn description(&self) -> String {

View File

@ -1,6 +1,6 @@
use std::fmt;
use crate::entity::{Entity, Location};
use crate::entity::{Entity, Location, EntityId};
#[derive(Clone)]
pub enum ItemType {
@ -11,6 +11,7 @@ pub enum ItemType {
#[derive(Clone)]
pub struct Item {
pub entity: Entity,
pub owner: Option<EntityId>,
pub name: String,
pub item_type: ItemType,
}
@ -38,6 +39,7 @@ impl ItemGenerator {
damage_dice: 1,
damage_sides: 6,
}),
owner: None,
}
}
}

View File

@ -2,7 +2,7 @@
use std::collections::HashMap;
use rand::prelude::*;
use crate::entity::{Location, EntityId};
use crate::entity::{Location, EntityId, Entity};
use crate::creature::{Creature, Profession, CreatureGenerator};
use crate::item::Item;
use crate::site::{Town, Tavern};
@ -168,6 +168,11 @@ impl GameState {
}
}
pub fn claim_item(&mut self, new_owner_id: EntityId, item_id: EntityId) {
let mut item = self.items.get_mut(&item_id).unwrap();
item.owner = Some(new_owner_id.clone());
}
}
#[cfg(test)]