-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattleplan.php
126 lines (116 loc) · 5.5 KB
/
battleplan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<script>
// var num = 0;
// function add() {
// document.getElementById('plans').innerHTML += "<select name='plans'><option value=''>Select an option</option><option value='hpbelow'>When HP is below</option><option value='noenemy'>When not next to an enemy</option></select><br>";
// battleplans[num] = document.createElement("select");
// battleplans[num].name = "battleplans[" + num + "]";
// battleplans[num].innerHTML = "<option value='asdf'>asdf</option>"
// document.body.appendChild(battleplans[num]);
// num++;
// }
function addOption(id,text,value) {
var option = document.createElement("option");
option.text = text
option.value = value;
id.add(option);
}
function change(from, row, col) {
var next = document.getElementById('plans[' + row + '][' + col + ']');
while (next.options.length > 0) {
next.remove(0);
}
switch(from.value) {
case "yourhpbelow100":
case "yourhpbelow75":
case "yourhpbelow50":
case "yourhpbelow25":
addOption(next, "Drink a health potion", "drinkhppot");
addOption(next, "Cast a healing spell", "casthealing");
break;
case "allyhpbelow100":
case "allyhpbelow75":
case "allyhpbelow50":
case "allyhpbelow25":
addOption(next, "Cast a healing spell", "casthealing");
break;
case "notnexttoenemy":
addOption(next, "Move closer to an enemy", "movecloser");
addOption(next, "Attack from afar", "rangedattack");
break;
case "nexttoenemy":
addOption(next, "Attack the enemy", "meleeattack");
addOption(next, "Move away from the enemy", "moveaway");
break;
}
}
</script>
<?php
// if not logged in, redirect to login page
require_once('Classes/Login.php');
if (\Classes\Login::isLoggedIn() === false) header('Location: login.php');
include_once('Includes/common.php');
if(isset($_GET['plans'])) {
foreach($_GET['plans'] as $plans) {
$battleplans[] = implode('|',$plans);
}
$battleplan = implode("||",$battleplans);
$conn=mysqli_connect("ucfsh.ucfilespace.uc.edu","piattjd","curtis1","piattjd");
mysqli_query($conn,"UPDATE Hero SET battleplan = '$battleplan' WHERE name = '$cookie[0]'");
mysqli_close($conn);
}
$conn=mysqli_connect("ucfsh.ucfilespace.uc.edu","piattjd","curtis1","piattjd");
$currentplans = mysqli_fetch_assoc(mysqli_query($conn,"SELECT battleplan FROM Hero WHERE name = '$cookie[0]'"));
mysqli_close($conn);
$currentplan = explode("||",$currentplans[battleplan]);
foreach($currentplan as $currents) {
$current[] = explode('|',$currents);
}
print_r($current);
echo "<form name='battleplan' action='battleplan.php' method='GET'>";
echo "<select name='plans[0][0]' id='plans[0][0]' onchange='change(this,0,1);'>
<option value=''>Select an option</option>
<option value='yourhpbelow100'>When your HP is between 75% and 100%</option>
<option value='yourhpbelow75'>When your HP is between 50% and 75%</option>
<option value='yourhpbelow50'>When your HP is between 25% and 50%</option>
<option value='yourhpbelow25'>When your HP is less than 25%</option>
<option value='allyhpbelow100'>When an ally's HP is between 75% and 100%</option>
<option value='allyhpbelow75'>When an ally's HP is between 50% and 75%</option>
<option value='allyhpbelow50'>When an ally's HP is between 25% and 50%</option>
<option value='allyhpbelow25'>When an ally's HP is less than 25%</option>
<option value='notnexttoenemy'>When not next to an enemy</option>
<option value='nexttoenemy'>When next to an enemy</option>
</select>";
echo "<select name='plans[0][1]' id='plans[0][1]'></select>";
echo "<br>";
echo "<select name='plans[1][0]' id='plans[1][0]' onchange='change(this,1,1);'>
<option value=''>Select an option</option>
<option value='yourhpbelow100'>When your HP is between 75% and 100%</option>
<option value='yourhpbelow75'>When your HP is between 50% and 75%</option>
<option value='yourhpbelow50'>When your HP is between 25% and 50%</option>
<option value='yourhpbelow25'>When your HP is less than 25%</option>
<option value='allyhpbelow100'>When an ally's HP is between 75% and 100%</option>
<option value='allyhpbelow75'>When an ally's HP is between 50% and 75%</option>
<option value='allyhpbelow50'>When an ally's HP is between 25% and 50%</option>
<option value='allyhpbelow25'>When an ally's HP is less than 25%</option>
<option value='notnexttoenemy'>When not next to an enemy</option>
<option value='nexttoenemy'>When next to an enemy</option>
</select>";
echo "<select name='plans[1][1]' id='plans[1][1]'></select>";
echo "<br>";
echo "<select name='plans[2][0]' id='plans[2][0]' onchange='change(this,2,1);'>
<option value=''>Select an option</option>
<option value='yourhpbelow100'>When your HP is between 75% and 100%</option>
<option value='yourhpbelow75'>When your HP is between 50% and 75%</option>
<option value='yourhpbelow50'>When your HP is between 25% and 50%</option>
<option value='yourhpbelow25'>When your HP is less than 25%</option>
<option value='allyhpbelow100'>When an ally's HP is between 75% and 100%</option>
<option value='allyhpbelow75'>When an ally's HP is between 50% and 75%</option>
<option value='allyhpbelow50'>When an ally's HP is between 25% and 50%</option>
<option value='allyhpbelow25'>When an ally's HP is less than 25%</option>
<option value='notnexttoenemy'>When not next to an enemy</option>
<option value='nexttoenemy'>When next to an enemy</option>
</select>";
echo "<select name='plans[2][1]' id='plans[2][1]'></select>";
echo "<br>";
echo "<button type='button' onclick='add()'>Add</button><input type='submit' value='Save'></form>";
?>