Advertisement
cram0

Test

Jul 29th, 2021
1,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { add_handler, remove_handler } = require(`${global.__SRC}/dofus/handler`);
  2. const { get_map_from_id } = require(`${global.__SRC}/dofus/d2p/map_getter`);
  3. const Pathfinding = require(`${global.__SRC}/dofus/pathfinding`);
  4.  
  5. const WAITING_TIME_MS = 600;
  6.  
  7. const move_character = (socket, map, cell_end) => {
  8.     try {
  9.         const dynamicObstacle = socket.current_map_info.actors.map(x => x.disposition.cellId).filter((v,i,a) => a.indexOf(v) === i);
  10.         const movement_message = new Pathfinding(map).createMovementMessage(socket.current_character.disposition.cellId, cell_end, dynamicObstacle);
  11.         socket.send_dofus_message(movement_message, true);
  12.         return true;
  13.     } catch {
  14.         return false;
  15.     }
  16. }
  17.  
  18. const get_map_transition_cells = (map, direction) => {
  19.     switch(direction.toLowerCase()){
  20.         case 'top': return map.cells.filter(x => x.map_change_data > 0 && x.map_change_data === 224 && x.mov);
  21.         case 'right': return map.cells.filter(x => x.map_change_data > 0 && x.map_change_data === 131 && x.mov);
  22.         case 'bottom': return map.cells.filter(x => x.map_change_data > 0 && x.map_change_data === 14 && x.mov);
  23.         case 'left': return map.cells.filter(x => x.map_change_data > 0 && x.map_change_data === 56 && x.mov);
  24.         default: return [0];
  25.     }
  26. }
  27.  
  28. const change_map = (socket, map, direction) => {
  29.     let index = 0;
  30.     const transition_cells = get_map_transition_cells(map, direction);
  31.     while(!move_character(socket, map, transition_cells[index++].id) && index < transition_cells.length){
  32.  
  33.     }
  34.  
  35.     const tmp_handler_name = `change map temporary handler - ${socket.current_character.id}-${socket.current_character.name} - ${new Date().getTime()}`;
  36.  
  37.     add_handler('GameMapMovementConfirmMessage', {
  38.         name: tmp_handler_name,
  39.         handle: async (server, _socket, informations) => {
  40.             if(socket.current_character.id === _socket.current_character.id &&
  41.                 _socket.current_character.disposition.cellId === transition_cells[index - 1].id){
  42.                 const map_id = map[`${direction.toLowerCase()}_neighbour_id`];
  43.  
  44.                 const timeout = setTimeout(() => {
  45.                     socket.send_dofus_message({
  46.                         __name: 'ChangeMapMessage',
  47.                         mapId: map_id,
  48.                         autopilot: false
  49.                     }, true);
  50.                     clearTimeout(timeout);
  51.                 }, WAITING_TIME_MS);
  52.             }
  53.  
  54.             remove_handler('GameMapMovementConfirmMessage', x => x.name !== tmp_handler_name);
  55.         },
  56.         error: async (server, _socket, informations, error) => {
  57.             console.error(error);
  58.         }
  59.     });
  60. }
  61.  
  62. const start_path = (server, socket, path) => {
  63.     socket.current_path = path;
  64.     const current_move = path.move[socket.current_map_info.mapId];
  65.     if(path && current_move && current_move.length > 0){
  66.         const current_map = get_map_from_id(socket.current_map_info.mapId, server.dofus_map);
  67.  
  68.         const tmp_map_info_handler_name = `map info temporary handler - ${socket.current_character.id}-${socket.current_character.name} - ${new Date().getTime()}`;
  69.  
  70.         change_map(socket, current_map, current_move[parseInt(Math.random() * current_move.length)]);
  71.     }
  72. }
  73.  
  74. add_handler('ChatClientMultiMessage', {
  75.     name: 'test - chat command message',
  76.     handle: async (server, socket, informations) => {
  77.         const splitted = informations.message_data_decoded.content.split(' ');
  78.         if(splitted[0] === '_move_'){
  79.             const test_path = {
  80.                 name: 'Ahem',
  81.                 move: {
  82.                     153879810: ['top']
  83.                 }
  84.             }
  85.  
  86.             start_path(server, socket, test_path);
  87.         }
  88.     },
  89.     error: async (server, socket, informations, error) => {
  90.         console.error(error);
  91.     }
  92. });
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement