home · contact · privacy
Add basic non-player things system.
[plomrogue2] / rogue_chat_nocanvas_monochrome.html
index e699a96efee25a3f51970df37916bc3e69eba425..d9732dad32cb3d9e28e97fc8036bdcef3f39c335 100644 (file)
@@ -177,7 +177,9 @@ let server = {
         this.websocket = new WebSocket(this.url);
         this.websocket.onopen = function(event) {
             server.connected = true;
+            game.thing_types = {};
             server.send(['TASKS']);
+            server.send(['THING_TYPES']);
             tui.log_msg("@ server connected! :)");
             tui.switch_mode(mode_login);
         };
@@ -202,12 +204,19 @@ let server = {
             game.things = {};
             game.portals = {};
             game.turn = parseInt(tokens[1]);
-        } else if (tokens[0] === 'THING_POS') {
-            game.get_thing(tokens[1], true).position = parser.parse_yx(tokens[2]);
+        } else if (tokens[0] === 'THING') {
+            let t = game.get_thing(tokens[3], true);
+            t.position = parser.parse_yx(tokens[1]);
+            t.type_ = tokens[2];
         } else if (tokens[0] === 'THING_NAME') {
-            game.get_thing(tokens[1], true).name_ = tokens[2];
+            let t = game.get_thing(tokens[1], false);
+            if (t) {
+                t.name_ = tokens[2];
+            };
         } else if (tokens[0] === 'TASKS') {
             game.tasks = tokens[1].split(',')
+        } else if (tokens[0] === 'THING_TYPE') {
+            game.thing_types[tokens[1]] = tokens[2]
         } else if (tokens[0] === 'MAP') {
             game.map_geometry = tokens[1];
             tui.init_keys();
@@ -441,7 +450,8 @@ let tui = {
     if (this.map_mode == 'terrain') {
         for (const thing_id in game.things) {
             let t = game.things[thing_id];
-            map_lines_split[t.position[0]][t.position[1]] = '@';
+            let symbol = game.thing_types[t.type_];
+            map_lines_split[t.position[0]][t.position[1]] = symbol;
         };
     }
     if (tui.mode.shows_info) {
@@ -691,9 +701,9 @@ let explorer = {
         for (let t_id in game.things) {
              let t = game.things[t_id];
              if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) {
-                 info += "PLAYER @";
+                 info += "THING: " + t.type_;
                  if (t.name_) {
-                     info += ": " + t.name_;
+                     info += " (name: " + t.name_ + ")";
                  }
                  info += "\n";
              }