Monopoly — Portage moderne
0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
DiceIngress.cpp
Go to the documentation of this file.
1
#include "
DiceIngress.hpp
"
2
3
#include <utility>
4
5
namespace
monopoly::dice
6
{
7
void
PromptState::process
(
const
actions::Message
& message)
noexcept
8
{
9
switch
(message.action)
10
{
11
case
actions::Type::NotifyPleaseRollDice
:
12
ruleStartTurn =
true
;
13
diceRollNotification =
true
;
14
break
;
15
case
actions::Type::NotifyDiceRolled
:
16
case
actions::Type::NotifyStartTurn
:
17
case
actions::Type::NotifyEndTurn
:
18
ruleStartTurn =
false
;
19
break
;
20
case
actions::Type::NotifyActionCompleted
:
21
if
(message.numberB &&
22
(message.numberA ==
static_cast<
std::int64_t
>
(
actions::Type::RollDice
) ||
23
message.numberA ==
static_cast<
std::int64_t
>
(
actions::Type::EndTurn
)))
24
ruleStartTurn =
false
;
25
break
;
26
default
:
break
;
27
}
28
}
29
30
std::expected<RollRequest, IngressError>
Ingress::process
(
31
rules::GameState
&
state
,
32
const
actions::Message
& message,
33
std::uint64_t tick)
noexcept
34
{
35
if
(message.action !=
actions::Type::NotifyDiceRolled
)
36
return
std::unexpected(
IngressError::UnsupportedNotification
);
37
if
(pending_)
38
return
std::unexpected(
IngressError::Busy
);
39
40
RollRequest
request{};
41
request.
values
[0] =
static_cast<
std::uint8_t
>
(message.numberA);
42
request.values[1] =
static_cast<
std::uint8_t
>
(message.numberB);
43
request.player =
static_cast<
rules::PlayerNumber
>
(message.numberC);
44
request.lockTick = tick;
45
46
state
.dice = request.values;
47
pending_ = request;
48
return
request;
49
}
50
51
std::optional<RollRequest>
Ingress::take
()
noexcept
52
{
53
auto
result = pending_;
54
pending_.reset();
55
return
result;
56
}
57
}
DiceIngress.hpp
state
unsigned state
Definition
ModernIBarSkin.cpp:25
index
unsigned index
Definition
ModernIBarSkin.cpp:25
monopoly::dice::Ingress::process
std::expected< RollRequest, IngressError > process(rules::GameState &state, const actions::Message &message, std::uint64_t tick) noexcept
Definition
DiceIngress.cpp:30
monopoly::dice::Ingress::take
std::optional< RollRequest > take() noexcept
Definition
DiceIngress.cpp:51
monopoly::actions::Type::EndTurn
@ EndTurn
monopoly::actions::Type::NotifyDiceRolled
@ NotifyDiceRolled
monopoly::actions::Type::NotifyStartTurn
@ NotifyStartTurn
monopoly::actions::Type::NotifyPleaseRollDice
@ NotifyPleaseRollDice
monopoly::actions::Type::RollDice
@ RollDice
monopoly::actions::Type::NotifyEndTurn
@ NotifyEndTurn
monopoly::actions::Type::NotifyActionCompleted
@ NotifyActionCompleted
monopoly::dice
Definition
DiceDisplay.cpp:6
monopoly::dice::IngressError::UnsupportedNotification
@ UnsupportedNotification
monopoly::dice::IngressError::Busy
@ Busy
monopoly::rules::PlayerNumber
std::uint8_t PlayerNumber
Definition
RuleTypes.hpp:12
monopoly::actions::Message
Definition
Actions.hpp:125
monopoly::dice::PromptState::process
void process(const actions::Message &message) noexcept
Definition
DiceIngress.cpp:7
monopoly::dice::RollRequest
Definition
DiceIngress.hpp:14
monopoly::dice::RollRequest::values
std::array< std::uint8_t, 2 > values
Definition
DiceIngress.hpp:15
monopoly::rules::GameState
Definition
RuleTypes.hpp:259
DiceIngress.cpp
Generated by
1.9.8