aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/maps/junior.yaml1
-rw-r--r--server/src/data.rs4
-rw-r--r--server/src/game.rs8
-rw-r--r--test-client/main.ts7
-rw-r--r--test-client/protocol.ts3
5 files changed, 22 insertions, 1 deletions
diff --git a/data/maps/junior.yaml b/data/maps/junior.yaml
index 5807eb70..9acd4dd1 100644
--- a/data/maps/junior.yaml
+++ b/data/maps/junior.yaml
@@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
+score_baseline: 200
map:
- "*''''*'''*'''''*''*'''*''"
- "'''*''''*'*'**'''''**'''*"
diff --git a/server/src/data.rs b/server/src/data.rs
index 7f5ed9a6..408ea736 100644
--- a/server/src/data.rs
+++ b/server/src/data.rs
@@ -80,6 +80,8 @@ pub struct InitialMap {
entities: Vec<EntityDecl>,
#[serde(default)]
tile_entities: HashMap<char, EntityDecl>,
+ #[serde(default)]
+ score_baseline: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -112,6 +114,7 @@ pub struct Gamedata {
pub initial_map: HashMap<IVec2, (TileIndex, Option<ItemIndex>)>,
pub chef_spawn: Vec2,
pub customer_spawn: Vec2,
+ pub score_baseline: i64,
pub entities: Vec<Entity>,
}
@@ -322,6 +325,7 @@ impl Gamedata {
map_name,
tile_interact,
recipes,
+ score_baseline: map_in.score_baseline,
map: HashMap::new(),
initial_map,
item_names,
diff --git a/server/src/game.rs b/server/src/game.rs
index 21bb5f33..89ea7dfc 100644
--- a/server/src/game.rs
+++ b/server/src/game.rs
@@ -301,6 +301,7 @@ impl Game {
name: name.clone(),
},
);
+ self.score.players = self.score.players.max(self.players.len());
packet_out.push_back(PacketC::AddPlayer {
id: player,
name,
@@ -586,6 +587,13 @@ impl Game {
if let Some(end) = self.end {
self.score.time_remaining = (end - Instant::now()).as_secs_f64();
if end < Instant::now() {
+ let relative_score = (self.score.points * 100) / self.data.score_baseline.max(1);
+ self.score.stars = match relative_score {
+ 100.. => 3,
+ 70.. => 2,
+ 40.. => 1,
+ _ => 0,
+ };
packet_out.push_back(PacketC::Menu(Menu::Score(self.score.clone())));
true
} else {
diff --git a/test-client/main.ts b/test-client/main.ts
index b497ee36..db474784 100644
--- a/test-client/main.ts
+++ b/test-client/main.ts
@@ -235,6 +235,13 @@ function packet(p: PacketC) {
case "movement_sync":
players.get(my_id)!.position = last_server_sent_position
break;
+ case "menu":
+ switch (p.menu) {
+ case "book": open("https://s.metamuffin.org/static/hurrycurry/book.pdf"); break
+ case "score": alert("Your score: " + JSON.stringify(p.data)); break
+ default: console.warn("unknown menu");
+ }
+ break;
default:
console.warn("unknown packet", p);
}
diff --git a/test-client/protocol.ts b/test-client/protocol.ts
index 376ebd58..432f30e2 100644
--- a/test-client/protocol.ts
+++ b/test-client/protocol.ts
@@ -64,7 +64,7 @@ export type PacketC =
export type Menu =
{ menu: "book" }
- | { menu: "score" } & Score
+ | { menu: "score", data: Score }
export interface Score {
points: number,
@@ -75,6 +75,7 @@ export interface Score {
active_recipes: number,
passive_recipes: number,
instant_recipes: number,
+ stars: number,
}
export type Message =