Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { add_handler, remove_handler } = require(`${global.__SRC}/dofus/handler`);
- const { get_map_from_id } = require(`${global.__SRC}/dofus/d2p/map_getter`);
- const Pathfinding = require(`${global.__SRC}/dofus/pathfinding`);
- const WAITING_TIME_MS = 600;
- const move_character = (socket, map, cell_end) => {
- try {
- const dynamicObstacle = socket.current_map_info.actors.map(x => x.disposition.cellId).filter((v,i,a) => a.indexOf(v) === i);
- const movement_message = new Pathfinding(map).createMovementMessage(socket.current_character.disposition.cellId, cell_end, dynamicObstacle);
- socket.send_dofus_message(movement_message, true);
- return true;
- } catch {
- return false;
- }
- }
- const get_map_transition_cells = (map, direction) => {
- switch(direction.toLowerCase()){
- case 'top': return map.cells.filter(x => x.map_change_data > 0 && x.map_change_data === 224 && x.mov);
- case 'right': return map.cells.filter(x => x.map_change_data > 0 && x.map_change_data === 131 && x.mov);
- case 'bottom': return map.cells.filter(x => x.map_change_data > 0 && x.map_change_data === 14 && x.mov);
- case 'left': return map.cells.filter(x => x.map_change_data > 0 && x.map_change_data === 56 && x.mov);
- default: return [0];
- }
- }
- const change_map = (socket, map, direction) => {
- let index = 0;
- const transition_cells = get_map_transition_cells(map, direction);
- while(!move_character(socket, map, transition_cells[index++].id) && index < transition_cells.length){
- }
- const tmp_handler_name = `change map temporary handler - ${socket.current_character.id}-${socket.current_character.name} - ${new Date().getTime()}`;
- add_handler('GameMapMovementConfirmMessage', {
- name: tmp_handler_name,
- handle: async (server, _socket, informations) => {
- if(socket.current_character.id === _socket.current_character.id &&
- _socket.current_character.disposition.cellId === transition_cells[index - 1].id){
- const map_id = map[`${direction.toLowerCase()}_neighbour_id`];
- const timeout = setTimeout(() => {
- socket.send_dofus_message({
- __name: 'ChangeMapMessage',
- mapId: map_id,
- autopilot: false
- }, true);
- clearTimeout(timeout);
- }, WAITING_TIME_MS);
- }
- remove_handler('GameMapMovementConfirmMessage', x => x.name !== tmp_handler_name);
- },
- error: async (server, _socket, informations, error) => {
- console.error(error);
- }
- });
- }
- const start_path = (server, socket, path) => {
- socket.current_path = path;
- const current_move = path.move[socket.current_map_info.mapId];
- if(path && current_move && current_move.length > 0){
- const current_map = get_map_from_id(socket.current_map_info.mapId, server.dofus_map);
- const tmp_map_info_handler_name = `map info temporary handler - ${socket.current_character.id}-${socket.current_character.name} - ${new Date().getTime()}`;
- change_map(socket, current_map, current_move[parseInt(Math.random() * current_move.length)]);
- }
- }
- add_handler('ChatClientMultiMessage', {
- name: 'test - chat command message',
- handle: async (server, socket, informations) => {
- const splitted = informations.message_data_decoded.content.split(' ');
- if(splitted[0] === '_move_'){
- const test_path = {
- name: 'Ahem',
- move: {
- 153879810: ['top']
- }
- }
- start_path(server, socket, test_path);
- }
- },
- error: async (server, socket, informations, error) => {
- console.error(error);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement