Commit acfd6c8d authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

New Oracle score…

parent d5cb24ff
......@@ -78,9 +78,10 @@ CREATE TABLE IF NOT EXISTS `enregistrement` (
`validation` enum('valid','invalid','limbo','given up') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'limbo',
`nbSucces` smallint(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Combien de fois l''enregistrement a permis de trouver le mot',
`nbTentatives` smallint(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Combien de fois l''enregistrement a été passé à un devin',
`mise` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'La mise calculée en fonction du niveau de la carte du joueur et de la difficulté choisie',
`miseD` tinyint(4) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'La mise en cas de défaite calculée en fonction du niveau de la carte du joueur et de la difficulté choisie',
`miseV` tinyint(4) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'La mise calculée en cas de victoire en fonction du niveau de la carte du joueur et de la difficulté choisie',
PRIMARY KEY (`enregistrementID`),
UNIQUE KEY `no_replay` (`OracleLang`,`carteID`) USING BTREE,
UNIQUE KEY `no_replay` (`OracleLang`,`carteID`,`idOracle`) USING BTREE,
UNIQUE KEY `cheminEnregistrement` (`cheminEnregistrement`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
......@@ -107,16 +108,16 @@ CREATE TABLE IF NOT EXISTS `mots_interdits` (
CREATE TABLE IF NOT EXISTS `notif` (
`userid` int(11) NOT NULL,
`type` TINYINT UNSIGNED NULL DEFAULT NULL COMMENT 'type of the message',
`message` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`type` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'type of the message',
`message` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`emetteur` int(11) NOT NULL DEFAULT '0',
`id` int(11) NOT NULL AUTO_INCREMENT,
`state` int(11) NOT NULL,
`game` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
KEY `type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
......
......@@ -7,7 +7,6 @@ require_once('./sys/load_iso.php');
require_once('./models/userlvl.class.php');
require_once("./controllers/notificationMessage.php");
/**/require_once("./controllers/update_score_coeff.php");/**///transition to new scoreHandler
/**/require_once("./debug.php");
class TracesHandler{
private $db;
......@@ -45,24 +44,24 @@ class TracesHandler{
}
//once a card is seen it is stored in db for score and next play
$queries = array();
$stakes = $this->sv->get_stake($gameLevel, $card->get_level(), $user_level);
$stakes = array("V" => $this->sv->get_stake($gameLevel, $card->get_level(), $user_level, true),
"D" => $this->sv->get_stake($gameLevel, $card->get_level(), $user_level, false));
//create recording
array_push($queries, "INSERT INTO `enregistrement` (`idOracle`, `OracleLang`, `carteID`, `nivcarte`, `nivpartie`, `validation`, `mise`)
array_push($queries, "INSERT INTO `enregistrement` (`idOracle`, `OracleLang`, `carteID`, `nivcarte`, `nivpartie`, `validation`, `miseD`, `miseV`)
VALUES ('".$this->user->id."','".
$lang."', '".
$card->get_id()."', '".
$card->get_level()."', '".
$gameLevel."','given up', '$stakes');");
$gameLevel."','given up', '".$stakes['D']."', '".$stakes['V']."');");
//score
array_push($queries, "SET @recording_id = LAST_INSERT_ID();");
array_push($queries, "UPDATE `stats` SET `score_oracle`=`score_oracle`+(SELECT ".$this->sv->get_recording_score_sql_formula()." FROM `enregistrement` WHERE `enregistrementID`=@recording_id), `nbAbandons_oracle`=`nbAbandons_oracle`+1, `nbJeux_oracle`=`nbJeux_oracle`+1 WHERE `userid`='".$this->user->id."' AND `langue`='$lang';");
//notification
array_push($queries, $this->notif->addNotifGAME(
$this->user->id,$this->messages['Oracle_started'].$stakes." pts.",
$this->user->id,$this->messages['Oracle_started'].$stakes["V"]." pts.",
$this->messages['img_oracle'],
$this->messages['notif']['Oracle_started']
));
/**/myLog("<h2>see card</h2><pre>".print_r($queries,true)."</pre>");
if(!$this->db->transaction($queries)){
$res = false;
throw new Exception("“".print_r($queries,true)."” could not be performed.\n".$this->db->get_error());
......@@ -76,11 +75,13 @@ class TracesHandler{
public function post_record($cardId, $rec_path, $rec_length){
$queries = array();
//update recording
//prepare score
array_push($queries, "SELECT @previous_recording_score := ".$this->sv->get_recording_score_sql_formula().", @recording_id := `enregistrementID`, @lang := `OracleLang` FROM `enregistrement` WHERE `enregistrement`.`idOracle` = ".$this->user->id." AND `enregistrement`.`carteID`='$cardId';");
//actual recording update
array_push($queries, "UPDATE `enregistrement` SET `cheminEnregistrement` = '$rec_path', `duration`='$rec_length', `tpsEnregistrement`=CURRENT_TIMESTAMP, `validation` = 'limbo' WHERE `enregistrementID`=@recording_id;");
//score
//score update
array_push($queries, "UPDATE `stats` SET `score_oracle`=`score_oracle`+(SELECT ".$this->sv->get_recording_score_sql_formula()." FROM `enregistrement` WHERE `enregistrementID`=@recording_id)-(@previous_recording_score), `nbAbandons_oracle`=`nbAbandons_oracle`-1, `nbEnregistrements_oracle`=`nbEnregistrements_oracle`+1 WHERE `userid`='".$this->user->id."' AND `langue`=@lang;");
//notification
//notifications
array_push($queries, $this->notif->cancelLastNotifOfType(
$this->user->id,
$this->messages['notif']['Oracle_started']));
......@@ -90,7 +91,6 @@ class TracesHandler{
$this->messages['img_oracle'],
$this->messages['notif']['Oracle_posted']
));
/**/myLog("<h2>post</h2><pre>".print_r($queries,true)."</pre>");
if(!$this->db->transaction($queries)){
$res = false;
throw new Exception("“".print_r($queries,true)."” could not be performed.\n".$this->db->get_error());
......@@ -102,15 +102,27 @@ class TracesHandler{
}
public function abort_record($recording_path){
//TODO ICITE
$query = "UPDATE `enregistrement` SET `validation` = 'given up', `tpsEnregistrement`=CURRENT_TIMESTAMP WHERE `enregistrement`.`cheminEnregistrement` = '$recording_path'; ";
if(!$this->db->query($query)){
$res = false;
throw new Exception("“".$query."” could not be performed.\n".$this->db->get_error());
}
elseif ($this->db->affected_rows != 1) {
$queries = array();
//update recording
//prepare score
array_push($queries, "SELECT @previous_recording_score := ".$this->sv->get_recording_score_sql_formula().", @recording_id := `enregistrementID`, @lang := `OracleLang` FROM `enregistrement` WHERE `enregistrement`.`cheminEnregistrement` = '$recording_path';");
//actual recording update
array_push($queries, "UPDATE `enregistrement` SET `validation` = 'given up', `tpsEnregistrement`=CURRENT_TIMESTAMP WHERE `enregistrement`.`cheminEnregistrement` = '$recording_path'; ");
//score update
array_push($queries, "UPDATE `stats` SET `score_oracle`=`score_oracle`+(SELECT ".$this->sv->get_recording_score_sql_formula()." FROM `enregistrement` WHERE `enregistrementID`=@recording_id)-(@previous_recording_score), `nbAbandons_oracle`=`nbAbandons_oracle`+1, `nbEnregistrements_oracle`=`nbEnregistrements_oracle`-1 WHERE `userid`='".$this->user->id."' AND `langue`=@lang;");
//notifications
array_push($queries, $this->notif->cancelLastNotifOfType(
$this->user->id,
$this->messages['notif']['Oracle_posted']));
array_push($queries, $this->notif->addNotifGAME(
$this->user->id,
$this->messages['Oracle_abort'],
$this->messages['img_oracle'],
$this->messages['notif']['Oracle_abort']
));
if(!$this->db->transaction($queries)){
$res = false;
throw new Exception("“".$query."” affected ".$this->db->affected_rows.".\nDatabase consistence jeopardized");
throw new Exception("“".print_r($queries,true)."” could not be performed.\n".$this->db->get_error());
}
else{
$res = true;
......@@ -158,6 +170,5 @@ class TracesHandler{
array_push($queries, "UPDATE `stats` SET `nbErrArbitrage_druide` = `nbErrArbitrage_druide`+1, `score_druide` = IF()`score_druide`+".$this->sv->get_druid_verification_error_score()." WHERE `stats`.`userid` IN (SELECT `idDruide` FROM `arbitrage` WHERE `enregistrementID`='$recordingID' AND `arbitrageID` < @arbitrage_id AND 'validation'='".
$this->sv->get_druid_string($validate)."');");
}
/**/myLog("<pre>".print_r($queries,true)."</pre>");
}
}?>
<?php
session_start();
require('./sys/config.php');
require_once("./controllers/traces.handler.class.php");
$ext = ".mp3";
......
......@@ -216,6 +216,7 @@ $lang['Oracle_verif'][true] = " verified your recording and thinks you didn't us
$lang['Oracle_verif'][false] = " verified your recording and thinks you used forbidden words";
$lang['Oracle_started'] = "Oracle game started, if you give up the recording you'll lose ";
$lang['Oracle_posted'] = "You took the risk of posting your description, you, brave Oracle!";
$lang['Oracle_abort'] = "Recording deleted. Small penalty, but nothing like the one you would have got with forbidden words…";
$lang['Oracle_devin'][false] = " listened to your recording and didn't find the word…";
$lang['Oracle_devin'][true] = " listened to your recording and found the word!";
$lang['Devin_played'] = "You listened to a recording by ";
......
......@@ -210,6 +210,7 @@ $lang['Oracle_verif'][true] = " a vérifié votre enregistrement et pense que vo
$lang['Oracle_verif'][false] = " a vérifié votre enregistrement et pense que vous n'avez pas utilisé de mot interdit";
$lang['Oracle_started'] = "Partie “Oracle” commencée, sans dépôt du fichier, vous perdrez ";
$lang['Oracle_posted'] = "Vous avez osé valider votre description, courageux…";
$lang['Oracle_abort'] = "Enregistrement supprimé. Petite pénalité, mais moins lourde qu'en envoyant un enregistrement avec mots interdits…";
$lang['Oracle_devin'][false] = " a écouté votre enregistrement et n'a pas trouvé le mot…";
$lang['Oracle_devin'][true] = ' a écouté votre enregistrement et a trouvé&nbsp;!';
$lang['Devin_played'] = 'Vous avez écouté un enregistrement de ';
......
......@@ -14,6 +14,9 @@ if(isset($lang)){
$lang['notif']['languePlay'] = 12;
$lang['notif']['Oracle_started'] = 13;
$lang['notif']['Oracle_posted'] = 14;
$lang['notif']['Oracle_abort'] = 15;
//images
$lang['img_augur'] = "./profil/diviner.jpg";
$lang['img_druid'] = "./profil/druide.jpg";
$lang['img_oracle'] = "./profil/oracle.jpg";
......
......@@ -40,11 +40,11 @@ class ScoreValues{
const DRUID_CREATE_CARD = 40;
const RECORDING_SCORE_FORMULA =
"IF(`validation`='given up',
-ROUND(`mise`/3),
-ROUND(`miseD`/3),
IF(`validation`='invalid',
-ROUND(1.5*`mise`),
-ROUND(1.5*`miseD`),
IF(`validation`='valid',
ROUND(`mise`*(0.5+`nbSucces`/`nbTentatives`)),
ROUND(`miseV`*(0.5+`nbSucces`/`nbTentatives`)),
0
)
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment