-
Notifications
You must be signed in to change notification settings - Fork 2
/
travel-sync.php
60 lines (47 loc) · 1.63 KB
/
travel-sync.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
<?php
/*
* travel-sync.php
*
* Synchronizes state between travel and session values
*
* Inputs:
* - ?eat -> make the party eat for a day. Returns the amount of food remaining.
* - ?getHealth -> does a kill check then averages health and returns it
* - ?progress -> progresses distance, stopping at the next landmark if need be. Set to movement rate.
* - ?nextDay -> advances to the next day, returns the date
*/
include "classes.php";
session_start();
$jsonResponse = array();
# Make party eat, adds remainingFood
if (isset($_GET["eat"]))
{
$_SESSION["playParty"]->eat();
$jsonResponse["remainingFood"] = $_SESSION["playParty"]->_supplies->_food;
}
# Health check/update, adds overallHealth, nowDead, livingMembers
if (isset($_GET["getHealth"]))
{
# Apply damage from diseases
$_SESSION["playParty"]->applyDamage();
# Get the list of the people who died
$peopleDied = $_SESSION["playParty"]->killCheck();
$_SESSION["playParty"]->health();
$jsonResponse["overallHealth"] = $_SESSION["playParty"]->_health;
$jsonResponse["nowDead"] = $peopleDied;
$jsonResponse["livingMembers"] = $_SESSION["playParty"]->_livingMembers;
}
# Make progress, adds newDistance
if (isset($_GET["progress"]))
{
$slowRate = floatval($_GET["progress"]);
$distance = $_SESSION["playerJourney"]->progress($slowRate);
$jsonResponse["newDistance"] = $distance;
}
# Advance day, adds newDay
if (isset($_GET["nextDay"]))
{
$_SESSION["playerJourney"]->incrementDay();
$jsonResponse["newDay"] = "".$_SESSION["playerJourney"]->_month." ".$_SESSION["playerJourney"]->_date.", 1848";
}
echo json_encode($jsonResponse);