Compare commits
2 Commits
472e24a62c
...
966cafb9d9
| Author | SHA1 | Date | |
|---|---|---|---|
| 966cafb9d9 | |||
| 0f77a16a8c |
22
README.md
22
README.md
@@ -16,14 +16,18 @@ Un gestionnaire de trésors pour des joueurs de Donjon&Dragons(tm).
|
|||||||
|
|
||||||
## Base de données
|
## Base de données
|
||||||
|
|
||||||
### Objets
|
### Objets (items)
|
||||||
|
|
||||||
L'inventaire des objets qui peuvent être lootés.
|
L'inventaire des objets qui peuvent être lootés.
|
||||||
PK: id
|
PK: id
|
||||||
|
|
||||||
### Propriétaires
|
### Objets lootés (looted)
|
||||||
|
|
||||||
|
Les objets actuellement looté.
|
||||||
|
Même schéma que `items` plus une colonne supplémentaire : `owner_id` -> players(id)
|
||||||
|
|
||||||
|
### Joueurs (players)
|
||||||
|
|
||||||
Les joueurs sont des propriétaires d'objet.
|
|
||||||
Le "groupe" est un propriétaire spécial, avec un ID réservé : 0
|
Le "groupe" est un propriétaire spécial, avec un ID réservé : 0
|
||||||
|
|
||||||
La table conserve l'état actuel des finances du propriétaire. L'attribut `dette` représente la dette envers le groupe.
|
La table conserve l'état actuel des finances du propriétaire. L'attribut `dette` représente la dette envers le groupe.
|
||||||
@@ -32,16 +36,16 @@ La table conserve l'état actuel des finances du propriétaire. L'attribut `dett
|
|||||||
PK: id
|
PK: id
|
||||||
ATTRS: name, debt (in gp), pp, sp, gp, cp
|
ATTRS: name, debt (in gp), pp, sp, gp, cp
|
||||||
```
|
```
|
||||||
### Propriété
|
### Requêtes (claims)
|
||||||
|
|
||||||
Table associative entre objets et propriétaires (joueurs ou groupe)
|
Table associative entre objets lootés et joueurs.
|
||||||
L'ajout d'un objet à un propriétaire est un achat. La suppression, une vente.
|
Représente les requêtes des joueurs. La colonne `resolve` permettra d'établir un classement de détermination entre les joueurs.
|
||||||
NB: L'historique d'achat est enregistré puis effacé lors de la vente.
|
|
||||||
```
|
```
|
||||||
PK: id
|
PK: id
|
||||||
FK: objets_id, proprietaire_id
|
FK: loot_id, player_id
|
||||||
ATTRS: acquired_date, at_value
|
ATTRS: resolve
|
||||||
```
|
```
|
||||||
|
|
||||||
### Opérations
|
### Opérations
|
||||||
|
|
||||||
_Doit-on garder un historique des opérations ?_
|
_Doit-on garder un historique des opérations ?_
|
||||||
|
|||||||
Binary file not shown.
@@ -1,2 +1,3 @@
|
|||||||
DROP TABLE items;
|
DROP TABLE items;
|
||||||
|
DROP TABLE looted;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
|
-- The global inventory of items
|
||||||
CREATE TABLE items (
|
CREATE TABLE items (
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
name VARCHAR NOT NULL,
|
name VARCHAR NOT NULL,
|
||||||
base_price INTEGER NOT NULL
|
base_price INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- The items that have been looted
|
||||||
|
CREATE TABLE looted (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
name VARCHAR NOT NULL,
|
||||||
|
base_price INTEGER NOT NULL,
|
||||||
|
owner_id INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (owner_id) REFERENCES players(id)
|
||||||
|
);
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ CREATE TABLE players (
|
|||||||
gp INTEGER DEFAULT 0 NOT NULL,
|
gp INTEGER DEFAULT 0 NOT NULL,
|
||||||
pp INTEGER DEFAULT 0 NOT NULL
|
pp INTEGER DEFAULT 0 NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
INSERT INTO players (id, name) VALUES (0, 'Groupe');
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
DROP TABLE looted;
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
CREATE TABLE looted (
|
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
|
||||||
player_id INTEGER NOT NULL,
|
|
||||||
item_id INTEGER NOT NULL,
|
|
||||||
acquired_date DATE NOT NULL,
|
|
||||||
FOREIGN KEY (player_id) REFERENCES players(id),
|
|
||||||
FOREIGN KEY (item_id) REFERENCES items(id)
|
|
||||||
);
|
|
||||||
1
lootalot_db/migrations/2019-06-21-113950_claims/down.sql
Normal file
1
lootalot_db/migrations/2019-06-21-113950_claims/down.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE claims;
|
||||||
8
lootalot_db/migrations/2019-06-21-113950_claims/up.sql
Normal file
8
lootalot_db/migrations/2019-06-21-113950_claims/up.sql
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
CREATE TABLE claims (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
player_id INTEGER NOT NULL,
|
||||||
|
loot_id INTEGER NOT NULL,
|
||||||
|
resolve INTEGER NOT NULL DEFAULT 0,
|
||||||
|
FOREIGN KEY (player_id) REFERENCES players(id),
|
||||||
|
FOREIGN KEY (loot_id) REFERENCES looted(id)
|
||||||
|
);
|
||||||
@@ -23,18 +23,14 @@ impl Player {
|
|||||||
Ok(players.load::<Self>(conn)?)
|
Ok(players.load::<Self>(conn)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_chest(player: i32, conn: &SqliteConnection) -> QueryResult<Vec<Item>> {
|
pub fn fetch_chest(player_id: i32, conn: &SqliteConnection) -> QueryResult<Vec<Item>> {
|
||||||
let owned = {
|
|
||||||
use schema::looted::dsl::*;
|
use schema::looted::dsl::*;
|
||||||
looted.filter(player_id.eq(player)).select(item_id).load::<i32>(conn)?
|
let owned = looted
|
||||||
};
|
.filter(owner_id.eq(player_id))
|
||||||
|
.select((id, name, base_price))
|
||||||
|
.load::<Item>(conn)?;
|
||||||
dbg!(&owned);
|
dbg!(&owned);
|
||||||
let chest = {
|
Ok(owned)
|
||||||
use schema::items::dsl::*;
|
|
||||||
items.filter(id.eq_any(owned)).load::<Item>(conn)?
|
|
||||||
};
|
|
||||||
dbg!(&chest);
|
|
||||||
Ok(chest)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
table! {
|
||||||
|
claims (id) {
|
||||||
|
id -> Integer,
|
||||||
|
player_id -> Integer,
|
||||||
|
loot_id -> Integer,
|
||||||
|
resolve -> Integer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
items (id) {
|
items (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
@@ -9,9 +18,9 @@ table! {
|
|||||||
table! {
|
table! {
|
||||||
looted (id) {
|
looted (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
player_id -> Integer,
|
name -> Text,
|
||||||
item_id -> Integer,
|
base_price -> Integer,
|
||||||
acquired_date -> Date,
|
owner_id -> Integer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +36,13 @@ table! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
joinable!(looted -> items (item_id));
|
joinable!(claims -> looted (loot_id));
|
||||||
joinable!(looted -> players (player_id));
|
joinable!(claims -> players (player_id));
|
||||||
|
joinable!(looted -> players (owner_id));
|
||||||
|
|
||||||
allow_tables_to_appear_in_same_query!(items, looted, players,);
|
allow_tables_to_appear_in_same_query!(
|
||||||
|
claims,
|
||||||
|
items,
|
||||||
|
looted,
|
||||||
|
players,
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user