Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulty / Demon type VOTE system #604

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/difVote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
//Minimum number of votes required for difficulty or demon type update.
$minimumVotes = 3;

//Enter how many votes the Power Rate will have in one vote. (Power Rate is need roles in "actionRateDifficulty" permission)
$powerRate = 3;
?>
22 changes: 22 additions & 0 deletions database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ CREATE TABLE `dailyfeatures` (

-- --------------------------------------------------------

--
-- Table structure for table `difvote`
--

CREATE TABLE `difvote` (
`id` int(11) NOT NULL,
`levelID` int(11) NOT NULL,
`userID` int(11) NOT NULL,
`difficulty` int(11) NOT NULL,
`demon` int(11) NOT NULL,
`timestamp` int(11) NOT NULL,
`isPower` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `friendreqs`
--
Expand Down Expand Up @@ -808,6 +824,12 @@ ALTER TABLE `cpshares`
ALTER TABLE `dailyfeatures`
MODIFY `feaID` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `difvote`
--
ALTER TABLE `dailyfeatures`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `friendreqs`
--
Expand Down
37 changes: 5 additions & 32 deletions incl/levels/rateGJDemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,10 @@
$id = $ep->remove($_POST["accountID"]);
$GJPCheck = new GJPCheck();
$gjpresult = $GJPCheck->check($gjp,$id);
if($gs->checkPermission($id, "actionRateDemon") == false){
exit("-1");
}
$auto = 0;
$demon = 0;
switch($rating){
case 1:
$dmn = 3;
$dmnname = "Easy";
break;
case 2:
$dmn = 4;
$dmnname = "Medium";
break;
case 3:
$dmn = 0;
$dmnname = "Hard";
break;
case 4:
$dmn = 5;
$dmnname = "Insane";
break;
case 5:
$dmn = 6;
$dmnname = "Extreme";
break;
if($gjpresult == 1){
$gs->voteLevel($id, $levelID, 50, ((int) $rating)*10);
echo $levelID;
return;
}
$timestamp = time();
$query = $db->prepare("UPDATE levels SET starDemonDiff=:demon WHERE levelID=:levelID");
$query->execute([':demon' => $dmn, ':levelID'=>$levelID]);
$query = $db->prepare("INSERT INTO modactions (type, value, value3, timestamp, account) VALUES ('10', :value, :levelID, :timestamp, :id)");
$query->execute([':value' => $dmnname, ':timestamp' => $timestamp, ':id' => $id, ':levelID' => $levelID]);
echo $levelID;
echo "-1";
?>
9 changes: 1 addition & 8 deletions incl/levels/rateGJStars.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
$GJPCheck = new GJPCheck();
$gjpresult = $GJPCheck->check($gjp,$accountID);
if($gjpresult == 1){
$permState = $gs->checkPermission($accountID, "actionRateStars");
if($permState){
$difficulty = $gs->getDiffFromStars($stars);
$gs->rateLevel($accountID, $levelID, 0, $difficulty["diff"], $difficulty["auto"], $difficulty["demon"]);
echo 1;
}else{
echo -1;
}
$gs->voteLevel($accountID, $levelID, $difficulty["auto"] == 1 ? 0 : $difficulty["diff"], 0);
}else{echo -1;}
}else{echo -1;}
79 changes: 79 additions & 0 deletions incl/lib/mainLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,4 +815,83 @@ public function suggestLevel($accountID, $levelID, $difficulty, $stars, $feat, $
$query = $db->prepare($query);
$query->execute([':account' => $accountID, ':level' => $levelID, ':diff' => $difficulty, ':stars' => $stars, ':feat' => $feat, ':auto' => $auto, ':demon' => $demon, ':timestamp' => time()]);
}

public function voteLevel($accountID, $levelID, $difficulty, $demon){
include __DIR__ . "/connection.php";
include __DIR__ . "/../../config/difVote.php";

$permState = $this->checkPermission($accountID, "actionRateDifficulty");
$power = 0;
if ($permState) {
$power = 1;
}

$query = $db->prepare("SELECT starDemon, starDemonDiff FROM levels WHERE levelID = :level");
$query->execute([':level' => $levelID]);
$result1 = $query->fetch();
if ($query->rowCount() > 0) {
$isDemon = $result1['starDemon'];
if ($power == 0 && $isDemon == 1 && ($result1['starDemonDiff']-$demon >= 30 || $result1['starDemonDiff']-$demon <= -30)) {
return;
}
} else {
$isDemon = 0;
}

$query = $db->prepare("INSERT INTO difvote (levelID, userID, difficulty, demon, timestamp) VALUES (:level, :account, :diff, :demon, :timestamp)");
$query->execute([':account' => $accountID, ':level' => $levelID, ':diff' => $difficulty, ':demon' => $demon, ':timestamp' => time()]);
if ($power == 1) {
for ($loop = 1; $loop < $powerRate; $loop++) {
$query = $db->prepare("INSERT INTO difvote (levelID, userID, difficulty, demon, timestamp, isPower) VALUES (:level, :account, :diff, :demon, :timestamp, 1)");
$query->execute([':account' => $accountID, ':level' => $levelID, ':diff' => $difficulty, ':demon' => $demon, ':timestamp' => time()]);
}
}

if ($isDemon == 0 || $demon == 0) {
$query = $db->prepare("SELECT Count(*) as count FROM difvote WHERE levelID = :level");
$query->execute([':level' => $levelID]);
$isVoted = $query->fetchColumn();
if ($isVoted >= $minimumVotes) {
$query = $db->prepare("SELECT AVG(difficulty) AS diff FROM difvote WHERE levelID = :level");
$query->execute([':level' => $levelID]);
$result = $query->fetchColumn();
$diff = round($result, -1);
$auto = 0;
if ($diff == 0) {
$auto = 1;
}

$query = $db->prepare("UPDATE levels SET starAuto=:auto, starDifficulty=:diff WHERE levelID=:levelID");
$query->execute([':auto' => $auto, ':diff' => $diff, ':levelID'=>$levelID]);
}
} else {
$query = $db->prepare("SELECT Count(*) as count FROM difvote WHERE demon != 0 AND levelID = :level");
$query->execute([':level' => $levelID]);
$isVoted = $query->fetchColumn();
if ($isVoted >= $minimumVotes) {
$query = $db->prepare("SELECT AVG(demon) AS diff FROM difvote WHERE demon != 0 AND levelID = :level");
$query->execute([':level' => $levelID]);
$result = $query->fetchColumn();
$demon_face = 0;
if ($result >= 10 && $result < 18) {
$demon_face = 3;
}
else if ($result >= 18 && $result < 26) {
$demon_face = 4;
}
else if ($result >= 26 && $result < 34) {
$demon_face = 2;
}
else if ($result >= 34 && $result < 42) {
$demon_face = 5;
}
else if ($result >= 42 && $result <= 50) {
$demon_face = 6;
}

$query = $db->prepare("UPDATE levels SET starDemonDiff=:diff WHERE levelID=:levelID");
$query->execute([':diff' => $demon_face, ':levelID'=>$levelID]);
}
}
}
}