discarding proper now
This commit is contained in:
parent
c3686221aa
commit
875c3fb5bb
7 changed files with 45 additions and 40 deletions
|
|
@ -46,17 +46,33 @@ pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> {
|
|||
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
||||
let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap();
|
||||
|
||||
let dealt_tile = if let Some(drawn) = player.drawn_tile
|
||||
&& drawn.id == tile_id
|
||||
{
|
||||
drawn
|
||||
} else if let Some((i, _)) = player
|
||||
.hand
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, t)| t.id == tile_id)
|
||||
{
|
||||
player.hand.remove(i)
|
||||
let dealt_tile = if let Some(dealt) = ctx.db.tile().id().find(tile_id) {
|
||||
if let Some(drawn) = player.drawn_tile {
|
||||
if drawn.id == dealt.id {
|
||||
dealt
|
||||
} else if let Some((i, _)) = player
|
||||
.hand
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, t)| t.id == tile_id)
|
||||
{
|
||||
let dealt = player.hand.remove(i);
|
||||
player.hand.push(drawn);
|
||||
player.hand.sort_by_key(|t| t.tile);
|
||||
|
||||
dealt
|
||||
} else {
|
||||
return Err(format!(
|
||||
"player {} attempted to deal tile {} not in hand or drawn",
|
||||
player.id, tile_id
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(format!(
|
||||
"player {} attempted to deal tile {} without having drawn",
|
||||
player.id, tile_id
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(format!(
|
||||
"player {} attempted to deal nonexistant tile {}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue