as you forced me to work on my own "engine", i came up with one of my latest problems.
Imagine you play a game, in wich one of the main leveling part is doing quests and there are two types of quests (history based, random daylies). For leveling, the random daylies are more important because you can do them everywhere and in an larger amount. To make it more interesting, you can choose between three quests wich take some time between 2,5 and 10 minutes. Here is an example:
A wild problem appears
10 minutes
4 gold
62 xp
Talk with your dog
7,5 minutes
2 gold
174 xp
Help yo ol grandma
5 minutes
4 gold
33 xp
As a player, i start deciding what quests will be the most worth for me. Do i need more gold or more xp? Is my guild need money for upgrading the xp-house, from where i get more quest-xp later?
As programer, i have problems: http://www.abload.de/img/mewofmkzl.png
Explain the picture pls...
In the header, you can see a placeholder name and the main navigation.
In the left, you can see a sidebar with some player informations (money, name, stats) and an additional navigation.
In the content, you can see the random daily quests. three of them.
What i want...
Display three different quests with different values.
What i have...
Three same quests are showed with random values.
If i click the button, i get the values but AGAIN RANDOM.
On the picture we see 1312 xp and 32 gold, what we will get is random again, but not that amount.
Here is the code...
(gold reward not included yet, $quest_duration and questBegin(xx) are placeholders)
Code: Select all
<?php
/**
* Questhandling
*/
// global quest vars
$quest_duration = 60; //Placeholder
$quest_duration_left = getCharacters('questDuration') - time();
$quest_experience = getCharacters('levelID') * rand(50,200);
$quest_gold = getCharacters('levelID') * rand(1,4);
if(isset($_POST['quest1_accept'])) {
questBegin(15);
}
if(isset($_POST['quest2_accept'])) {
questBegin(30);
}
if(isset($_POST['quest3_accept'])) {
questBegin(45);
}
if(isset($_POST['quest4_accept'])) {
questBegin(60);
}
function questBegin($var) {
global $db, $characterID;
if(getCharacters('questDuration') == 0) {
$quest_duration = time() + $var;
mysqli_query($db,
"UPDATE
characters
SET
questDuration = $quest_duration
WHERE
characterID = $characterID"
);
}
}
function questDone() {
global $db, $characterID, $quest_duration_left, $quest_experience, $quest_gold;
if(getCharacters('questDuration') > 0) {
if($quest_duration_left < 0) {
mysqli_query(
$db,
"UPDATE
characters
SET
experiencePoints = experiencePoints + $quest_experience,
questDuration = 0
WHERE
characterID = $characterID"
);
}
}
}
?>
Can you help me here?
How and where to safe the values from three quests temporarily, how to make it injection safe and how to generate new quests after the countdown?