| 1 | package Exobrain::Agent::HabitRPG::Sink; | ||
| 2 | use Method::Signatures; | ||
| 3 | use Moose; | ||
| 4 | |||
| 5 | with 'Exobrain::Agent::HabitRPG'; | ||
| 6 | with 'Exobrain::Agent::Run'; | ||
| 7 | |||
| 8 | # ABSTRACT: Send personal log events to iDoneThis | ||
| 9 | our $VERSION = '0.01'; # VERSION | ||
| 10 | |||
| 11 | method run() { | ||
| 12 | $self->exobrain->watch_loop( | ||
| 13 | class => 'Intent::HabitRPG', | ||
| 14 | then => sub { | ||
| 15 | my $event = shift; | ||
| 16 | my $hrpg = $self->habitrpg; | ||
| 17 | |||
| 18 | my $task = $event->task; | ||
| 19 | my $direction = $event->direction; | ||
| 20 | |||
| 21 | my $stats = $hrpg->user->{stats}; | ||
| 22 | |||
| 23 | my $result = $hrpg->updown($task, $direction); | ||
| 24 | |||
| 25 | my $name = $hrpg->get_task($task)->{text}; | ||
| 26 | |||
| 27 | my $msg; | ||
| 28 | |||
| 29 | if ($direction eq "up") { | ||
| 30 | $msg = sprintf( | ||
| 31 | "Congrats! You gained %+.2f XP and %+.2f GP for completing: $name", | ||
| 32 | $result->{exp} - $stats->{exp}, | ||
| 33 | $result->{gp} - $stats->{gp}, | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | else { | ||
| 37 | # Must be down | ||
| 38 | $msg = sprintf( | ||
| 39 | "Oh no! You lost %+.2f HP for: $name", | ||
| 40 | $result->{hp} - $stats->{hp}, | ||
| 41 | ) | ||
| 42 | } | ||
| 43 | |||
| 44 | $event->exobrain->notify($msg); | ||
| 45 | } | ||
| 46 | ); | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ |