Skip to content

Commit

Permalink
Adding an auto answer for distress signal + small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim committed Mar 18, 2021
1 parent aafb38c commit c7f4ee9
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 18 deletions.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion dbmodel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ ALTER TABLE `player` ADD `comm_token` varchar(16) NOT NULL DEFAULT 'middle' COMM
ALTER TABLE `player` ADD `comm_pending` smallint(1) NOT NULL DEFAULT '0' COMMENT 'want to communicate next time is possible';

ALTER TABLE `player` ADD `comm_card_id` int(10) DEFAULT NULL COMMENT 'id of the communicated card';
ALTER TABLE `player` ADD `distress_choice` smallint(1) DEFAULT 0 COMMENT 'unset, clockwise, anticlockwise or dontuse';
ALTER TABLE `player` ADD `distress_choice` smallint(1) DEFAULT 0 COMMENT 'unset, clockwise, anticlockwise, dontuse, agree';
ALTER TABLE `player` ADD `distress_card_id` int(10) unsigned NULL COMMENT 'id of the card to pass with distress';
ALTER TABLE `player` ADD `reply_choice` int(10) unsigned NULL COMMENT 'id of the chosen reply';
ALTER TABLE `player` ADD `distress_auto` smallint(1) DEFAULT 0 COMMENT 'none, autono, autoyes';



Expand Down
Binary file modified img/sprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion modules/css/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ html,body {
&[data-choice="1"] { background-position: 20% 100%; }
&[data-choice="2"] { background-position: 70% 50%; }
&[data-choice="3"] { background-position: 10% 100%; filter: drop-shadow(0 0 2px #FFF);}
&[data-choice="4"] { background-position: 90% 100%;}

@for $i from 0 through 4 {
&[data-no="#{$i}"] { order:$i; }
Expand Down Expand Up @@ -304,6 +305,11 @@ html,body {
font-size:18px;
}

&#agree-button {
width:auto;
padding:0px 5px;
}

&#clockwise-button div, &#anticlockwise-button div {
background-image: url('img/sprites.png');
background-size: 1100%;
Expand Down Expand Up @@ -371,7 +377,7 @@ html,body {
display: flex;
align-items: center;
font-weight: bold;

.thecrew-arrow-down {
transform:rotate(-90deg);
margin:0;
Expand Down
10 changes: 10 additions & 0 deletions modules/css/playerPanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@
@for $i from 0 through 5 {
#overall-content[data-commander="#{$i}"] .panel-container[data-no="#{$i}"] .panel-commander { display:block; }
}


#player_config {
#autopick-selector {
display:flex;
flex-flow: column;
justify-content: center;
align-items: center;
}
}
5 changes: 4 additions & 1 deletion modules/js/States/DistressTrait.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(["dojo", "dojo/_base/declare"], (dojo, declare) => {
const CLOCKWISE = 1, DONT_USE = 2, ANTICLOCKWISE = 3;
const CLOCKWISE = 1, DONT_USE = 2, ANTICLOCKWISE = 3, AGREE = 4;
return declare("thecrew.distressTrait", null, {
constructor(){
this._notifications.push(
Expand All @@ -18,6 +18,9 @@ define(["dojo", "dojo/_base/declare"], (dojo, declare) => {
this.connect($('clockwise-button'), 'click', () => this.onChooseDistressDirection(CLOCKWISE) );
this.connect($('dont-use-button'), 'click', () => this.onChooseDistressDirection(DONT_USE) );
this.connect($('anticlockwise-button'), 'click', () => this.onChooseDistressDirection(ANTICLOCKWISE) );
this.connect($('agree-button'), 'click', () => this.onChooseDistressDirection(AGREE) );

Object.keys(args.players).forEach(pId => dojo.attr('distress-choice-' + pId, 'data-choice', args.players[pId]) );
},

onChooseDistressDirection(dir){
Expand Down
11 changes: 10 additions & 1 deletion modules/php/Game/Players.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ public function clearDistressCards()

public function getNextToCommunicate()
{
return self::DB()->where('comm_pending', 1)->where('comm_token', '<>', 'used')->limit(1)->get(true);
return self::DB()->where('comm_pending', 1)->where('comm_token', '<>', 'used')->whereNull('comm_card_id')->limit(1)->get(true);
}

public function getAllDistressChoices() {
return array_unique(self::getAll()->map(function($player){ return $player->getDistressChoice(); }));
}

public function getAllDistressChoicesAssoc() {
return self::getAll()->assocMap(function($player){ return $player->getDistressChoice(); });
}

}
5 changes: 4 additions & 1 deletion modules/php/LogBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public static function loadCampaign()
$json = substr($json, 1, strlen($json)-2);
$logs = json_decode ($json, true);
foreach($logs as $log_id => $log){
self::insert($log['mission'], $log['attempt'], $log['success'], $log['distress']);
if(\array_key_exists('mission', $log))
self::insert($log['mission'], $log['attempt'], $log['success'], $log['distress']);
else
self::insert($log[0], $log[1], $log[2], $log[3]);
}
}
else {
Expand Down
9 changes: 9 additions & 0 deletions modules/php/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct($row)
$this->distressChoice = $row['distress_choice'];
$this->distressCard = $row['distress_card_id'];
$this->reply = $row['reply_choice'];
$this->distressAuto = $row['distress_auto'];
}

private $id;
Expand Down Expand Up @@ -60,6 +61,7 @@ public function getTricksWon(){ return $this->nTricks; }
public function isCommander() { return $this->id == Globals::getCommander(); }
public function isSpecial() { return $this->id == Globals::getSpecial(); }
public function isSpecial2() { return $this->id == Globals::getSpecial2(); }
public function getDistressAuto(){ return $this->distressAuto; }

public function getUiData($pId)
{
Expand All @@ -80,6 +82,7 @@ public function getUiData($pId)
'canCommunicate' => $this->canCommunicate(),
'distressChoice' => $this->distressChoice,
'distressCard' => $pId == $this->id? $this->distressCard : null,
'distressAuto' => $this->distressAuto,
'reply' => $this->reply,
];
}
Expand Down Expand Up @@ -176,4 +179,10 @@ public function reply($i)
{
self::DB()->update(['reply_choice' => $i], $this->id);
}


public function setAutoPick($mode)
{
self::DB()->update(['distress_auto' => $mode], $this->id);
}
}
4 changes: 2 additions & 2 deletions modules/php/States/CommunicationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function stBeforeComm()

$player = Players::getNextToCommunicate();
$mission = Missions::getCurrent();
if(!$mission->isDisrupted() && !is_null($player)){
if(!$mission->isDisrupted() && !is_null($player) && $player->canCommunicate()){
$player->toggleComm();
Notifications::startComm($player);
$nextPlayer = $player;
Expand All @@ -44,7 +44,7 @@ function actToggleComm()

$mission = Missions::getCurrent();
$stateName = $this->gamestate->state()['name'];
if(!$mission->isDisrupted() && $player->isCommPending() && $stateName == 'playerTurn' && Cards::countOnTable() == 0){
if(!$mission->isDisrupted() && $player->isCommPending() && $stateName == 'playerTurn' && Cards::countOnTable() == 0 && $player->canCommunicate()){
$this->gamestate->nextState('startComm');
}
}
Expand Down
46 changes: 42 additions & 4 deletions modules/php/States/DistressTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,31 @@
*/
trait DistressTrait
{
function stPreDistress()
{
foreach(Players::getAll() as $player){
$player->chooseDirection($player->getDistressAuto());
}

$choices = Players::getAllDistressChoices();
$choices = array_values(array_diff($choices, [WHATEVER]));
$needVote = (count($choices) > 1 || $choices[0] == 0);
$this->gamestate->nextState($needVote? 'setup' : 'turn');
}



function stDistressSetup()
{
$this->gamestate->setAllPlayersMultiactive();
}

function argDistressSetup()
{
return [
'players' => Players::getAllDistressChoicesAssoc()
];
}

function actChooseDirection($dir)
{
Expand All @@ -25,9 +45,11 @@ function actChooseDirection($dir)
Notifications::chooseDirection($player, $dir);

// Get other players choice that differs from mine
$choices = Players::getAll()->assocMap(function($player){ return $player->getDistressChoice(); });
$otherChoices = array_diff($choices, [$dir]);
if(empty($otherChoices)){
$choices = Players::getAllDistressChoices();
$choices = array_values(array_diff($choices, [WHATEVER]));
if(empty($choices) || (count($choices) == 1 && $choices[0] != 0)){
$dir = empty($choices)? DONT_USE : $choices[0];

// Everyone agrees on same direction, let's go!
Notifications::chooseDistressDirection($dir);
Globals::setDistressDirection($dir);
Expand All @@ -39,7 +61,13 @@ function actChooseDirection($dir)
$this->gamestate->nextState('turn');
}
} else {
$this->gamestate->setPlayersMultiactive(array_keys($otherChoices), '', true);
if($dir == WHATEVER){
$this->gamestate->setPlayerNonMultiactive($player->getId(), '');
} else {
$choices = Players::getAllDistressChoicesAssoc();
$otherChoices = array_diff($choices, [$dir, WHATEVER]);
$this->gamestate->setPlayersMultiactive(array_keys($otherChoices), '', true);
}
}
}

Expand Down Expand Up @@ -93,4 +121,14 @@ function stDistressExchange()
$this->gamestate->changeActivePlayer(Globals::getCommander());
$this->gamestate->nextState('next');
}


/***********************
******* AUTOPICK *******
***********************/
public function actSetAutopick($mode)
{
$player = Players::getCurrent();
$player->setAutoPick($mode);
}
}
6 changes: 5 additions & 1 deletion modules/php/States/MissionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ function stSave()
{
if(Globals::isCampaign()) {
$logs = self::getCollectionFromDb("SELECT mission, attempt, success, distress FROM logbook");
$json = json_encode ($logs);
$result = [];
foreach($logs as $log)
$result[] = [$log['mission'], $log['attempt'], $log['success'], $log['distress']];

$json = json_encode($result);
$this->storeLegacyTeamData($json);
}
$this->gamestate->nextState('next');
Expand Down
8 changes: 8 additions & 0 deletions modules/php/constants.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

define("STATE_NEW_TRICK",4);


define("STATE_PRE_DISTRESS",35);
define("STATE_DISTRESS_SETUP",14);
define("STATE_DISTRESS",15);
define("STATE_DISTRESS_EXCHANGE",16);
Expand Down Expand Up @@ -55,6 +57,12 @@
define('CLOCKWISE', 1);
define('DONT_USE', 2);
define('ANTICLOCKWISE', 3);
define('WHATEVER', 4);


define('DISABLED', 0);
define('ALWAYS_NO', 2);
define('ALWAYS_AGREE', 4);

/*
* COLORS
Expand Down
20 changes: 16 additions & 4 deletions states.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"action" => "stNewTrick",
"transitions" => [
"next" => STATE_BEFORE_COMM,
"distress" => STATE_DISTRESS_SETUP,
"distress" => STATE_PRE_DISTRESS,
"giveTask" => STATE_GIVE_TASK,
]
],
Expand All @@ -160,7 +160,7 @@
"args" => "argGiveTask",
"possibleactions" => ["actGiveTask", "actPassGiveTask"],
"transitions" => [
'pass' => STATE_DISTRESS_SETUP,
'pass' => STATE_PRE_DISTRESS,
'askConfirmation' => STATE_GIVE_TASK_CONFIRMATION,
"zombiePass" => STATE_CHANGE_MISSION
]
Expand All @@ -187,20 +187,32 @@
"description" => "",
"type" => "game",
"action" => "stGiveTaskExchange",
"transitions" => ["next" => STATE_DISTRESS_SETUP],
"transitions" => ["next" => STATE_PRE_DISTRESS],
],



/***********************
****** DISTRESS *******
***********************/
STATE_PRE_DISTRESS => [
"name" => "preDistress",
"description" => "",
"type" => "game",
"action" => "stPreDistress",
"transitions" => [
"setup" => STATE_DISTRESS_SETUP,
"turn" => STATE_BEFORE_COMM,
],
],

STATE_DISTRESS_SETUP => [
"name" => "distressSetup",
"description" => clienttranslate('The distress signal might be used'),
"descriptionmyturn" => clienttranslate('${you} may use the distress signal'),
"type" => "multipleactiveplayer",
"action" => "stDistressSetup",
"args" => "argDistressSetup",
"possibleactions" => ["actChooseDirection"],
"transitions" => [
"next" => STATE_DISTRESS,
Expand Down Expand Up @@ -276,7 +288,7 @@
"transitions" => [
"next" => STATE_NEXT_PLAYER,
"startComm" => STATE_BEFORE_COMM,
"distress" => STATE_DISTRESS_SETUP,
"distress" => STATE_PRE_DISTRESS,
"zombiePass" => STATE_CHANGE_MISSION
]
],
Expand Down
10 changes: 10 additions & 0 deletions thecrew.action.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public function __default()
}


public function setAutopick()
{
self::setAjaxMode();
$mode = self::getArg("autopick", AT_posint, true);
$this->game->actSetAutopick($mode);
self::ajaxResponse();
}



public function actMoveTile()
{
self::setAjaxMode();
Expand Down
12 changes: 12 additions & 0 deletions thecrew.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion thecrew.css.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion thecrew.game.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ public function upgradeTableDb($from_version)
self::testBigMerge();
}

if($frow_version <= 2103171142){
if($from_version <= 2103171142){
self::applyDbUpgradeToAllDB("DELETE FROM DBPREFIX_card WHERE `color` = 6");
}

if($from_version <= 2103172308){
self::applyDbUpgradeToAllDB("ALTER TABLE DBPREFIX_player ADD `distress_auto` smallint(1) DEFAULT 0 COMMENT 'none, autono, autoyes'");
}
}

public function testBigMerge()
Expand Down
Loading

0 comments on commit c7f4ee9

Please sign in to comment.