Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Library, PacketHook,Client } from './../core';
- import { UpdatePacket, AccountListPacket,TradeRequestedPacket,TradeStartPacket, TradeChangedPacket, TradeDonePacket } from './../networking/packets/incoming';
- import { RequestTradePacket,ChangeTradePacket, AcceptTradePacket,InvSwapPacket } from './../networking/packets/outgoing';
- import { Classes, AccountInfo,Account } from '../models';
- import {Storage} from './../services';
- import { CLI } from '../cli';
- import fs = require('fs');
- import './../../acc-config.json'
- import { WorldPosData, SlotObjectData } from '../networking';
- const readline = require('readline');
- @Library({
- name: 'Bot Automation',
- author: 'Gabes',
- enabled: false
- })
- class YourPluginName {
- private assigned:boolean = false;
- private server:string;
- private username:string;
- private objectType:number;
- private class:string;
- private classinfo:Map<string, number[]> = new Map<string,number[]>();
- private vaulted:boolean = false;
- private currentClass:string;
- private currentPotion:number; // matches to the potion in the array below
- private potionNumbers:string[] = ['dex','spd','wis','vit','att','def','mana','life'];
- private currentClientOffer:boolean[] = [];
- private currentPartnerOffer:boolean[] = [false,false,false,false,false,false,false,false];
- private count: number = 0;
- private accounts:string[];
- constructor() {
- //reads the accounts
- let data = fs.readFileSync('./../../Dan/nrelay/acc.txt').toString('utf-8'); {
- this.accounts = data.split("\n")
- };
- //creates a readline
- const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
- });
- rl.on('line', (this.command));
- }
- public command(input:string): void {
- //checks input
- if (input.length <= 0) {
- return;
- }
- //trade:AsiaSouthEast:LukeFlame:Warrior,0,2,0,0,0,0,0,0
- //trade:server:username:class1,amount of dex,amount of spd,wis,vit,att,def,mana,life:class2,amount of dex,spd,wis,vit,att,def,mana,life, etc.
- //assigns classes
- let command = input.split(':');
- if (command[0]!=='trade') {
- return;
- }
- let classinfo:Map<string, number[]> = new Map<string,number[]>();
- this.server = command[1];
- this.username = command[2];
- for (let i = 3;i<command.length;i++) {
- let potions = command[i].split(',');
- let classPotions:number[] = [];
- for (let j = 1;j<potions.length;j++) {
- classPotions.push(parseInt(potions[j]));
- }
- for (let i = 0;i<classPotions.length;i++) {
- console.log(classPotions[i]);
- }
- console.log(potions[0]);
- classinfo.set(potions[0],classPotions);
- }
- this.assigned = true;
- this.classinfo = classinfo;
- for (let key in this.classinfo.keys()) {
- let potInfo = this.classinfo.get(key);
- for (let i = 0;i<potInfo.length;i++) {
- if (potInfo[i] !== 0) {
- this.currentClass = key;
- this.currentPotion = i;
- this.tradeclass(this.potionNumbers[i]);
- return;
- }
- }
- }
- }
- tradeclass(potionType:string) {
- //add a client
- if (this.assigned) {
- for (let i = 0;i<this.accounts.length;i++) {
- let accountInfoSplit = this.accounts[i].split(':');
- if (accountInfoSplit[2] === potionType) {
- let account = {alias: accountInfoSplit[2],guid: accountInfoSplit[0],password: accountInfoSplit[1], serverPref: this.server} as Account;
- CLI.addClient(account);
- return;
- }
- }
- }
- }
- @PacketHook()
- onUpdate(client:Client,updatepacket:UpdatePacket):void {
- //takes item if in vault
- if (client.mapInfo.name === "Vault") {
- for (let x of updatepacket.newObjects) //looping through all newobjects your client recieves
- {
- if(x.objectType === 0x0504) //vault portals object type, found in the Objects.json
- {
- let currentVaultItemTypes: number[] = []; // saving the itemTypes temp
- for (let index = 0; index < x.status.stats.length; index++) {
- if (x.status.stats[index].statType<16 && x.status.stats[index].statType>7) {
- currentVaultItemTypes.push(x.status.stats[index].statValue);
- // item types needed for invswap packet
- }
- }
- setTimeout(() => {
- this.swap(client,currentVaultItemTypes,x.status.objectId);
- },this.calculateTime(client,x.status.pos));
- }
- }
- }
- //checks if person is here
- for (let x of updatepacket.newObjects) {
- if (this.assigned = true) {
- const temp = x.status.stats;
- for (let i = 0;i<temp.length;i++) {
- if (temp[i].statType === 31) {
- if (temp[i].stringStatValue === this.username) {
- console.log('Found: ' + this.username);
- this.objectType = x.objectType;
- this.class = Classes[x.objectType];
- for (let i = 4;i<client.playerData.inventory.length;i++) {
- if (client.playerData.inventory[i] !== -1) {
- const trade = new RequestTradePacket();
- trade.name = this.username;
- client.packetio.sendPacket(trade);
- return;
- }
- }
- if (this.vaulted) {
- this.deleteAcc(client);
- this.tradeclass(this.potionNumbers[this.currentPotion]);
- }
- else {
- setTimeout(() => {
- client.gameId = -5;
- client.connect();
- this.vaulted = true;
- },3000);
- }
- }
- }
- }
- }
- }
- }
- @PacketHook()
- onTrade(client:Client,tradestart:TradeStartPacket) {
- let offer:boolean[] = [];
- offer.push(false);
- offer.push(false);
- offer.push(false);
- offer.push(false);
- let total = this.classinfo.get(this.currentClass)[this.currentPotion];
- for (let i = 4;i<tradestart.clientItems.length;i++) {
- if (total === 0) {
- offer.push(false);
- }
- else if (tradestart.clientItems[i].item !== -1) {
- total--;
- offer.push(true);
- this.count++;
- }
- else {
- offer.push(false);
- }
- }
- const selectItems = new ChangeTradePacket();
- this.currentClientOffer = offer;
- selectItems.offer = this.currentClientOffer;
- client.packetio.sendPacket(selectItems);
- const acceptTrade = new AcceptTradePacket();
- acceptTrade.clientOffer = this.currentClientOffer;
- acceptTrade.partnerOffer = this.currentPartnerOffer;
- client.packetio.sendPacket(acceptTrade);
- }
- @PacketHook()
- onTradeChange(client:Client,tradechange:TradeChangedPacket) {
- this.currentPartnerOffer = tradechange.offer;
- const acceptTrade = new AcceptTradePacket();
- acceptTrade.clientOffer = this.currentClientOffer;
- acceptTrade.partnerOffer = this.currentPartnerOffer;
- client.packetio.sendPacket(acceptTrade);
- }
- @PacketHook()
- onTradeDone(client:Client,tradedone:TradeDonePacket) {
- /* trying to send the new trade command and check vault
- */
- if (tradedone.code === 0) {
- if (this.vaulted) {
- this.deleteAcc(client);
- }
- this.currentClientOffer = [];
- this.currentPartnerOffer = [false,false,false,false,false,false,false,false];
- let newAmount = this.classinfo.get(this.currentClass)[this.currentPotion];
- newAmount = newAmount-this.count;
- this.count = 0;
- this.classinfo.get(this.currentClass)[this.currentPotion] = newAmount;
- if (newAmount === 0 && this.currentPotion === 7) {
- this.classinfo.delete(this.currentClass);
- if (this.classinfo.size === 0) {
- this.assigned = false;
- this.class = undefined;
- this.classinfo = new Map<string,number[]>();
- this.currentClass = undefined;
- this.currentPotion = undefined;
- this.objectType = undefined;
- this.potionNumbers = [];
- this.server = undefined;
- this.username = undefined;
- }
- else if (!this.vaulted) {
- setTimeout(() => {
- client.gameId = -5;
- client.connect();
- this.vaulted = true;
- },3000);
- }
- else {
- this.nextAcc();
- }
- }
- else if (!this.vaulted) {
- setTimeout(() => {
- client.gameId = -5;
- client.connect();
- this.vaulted = true;
- },3000);
- }
- else {
- this.nextAcc();
- }
- }
- else {
- const trade = new RequestTradePacket();
- trade.name = this.username;
- client.packetio.sendPacket(trade);
- }
- }
- private nextAcc():void {
- this.vaulted = false;
- for (let key in this.classinfo.keys()) {
- let potInfo = this.classinfo.get(key);
- for (let i = 0;i<potInfo.length;i++) {
- if (potInfo[i] !== 0) {
- this.currentClass = key;
- this.currentPotion = i;
- this.tradeclass(this.potionNumbers[this.currentPotion]);
- return;
- }
- }
- }
- }
- private deleteAcc(client:Client): void {
- for (let i = 0;i<this.accounts.length;i++) {
- let accountInfo = this.accounts[i].split(':');
- if (accountInfo[2] === client.guid) {
- this.accounts.splice(i,1);
- fs.unlink("./../../Dan/nrelay/acc.txt", (err) => {
- if (err) {
- console.log(err);
- } else {
- console.log('success');
- }
- });
- setTimeout(() => {
- fs.writeFile("./../../Dan/nrelay/acc.txt", "", { flag: 'wx' }, function (err) {
- if (err) throw err;
- console.log("New Account File Created");
- });
- var stream = fs.createWriteStream("./../../Dan/nrelay/acc.txt");
- for (let i = 0;i<this.accounts.length;i++) {
- let temp = this.accounts[i].split(':');
- let email = temp[0].substring(1,temp[0].length-1);
- console.log(email);
- if (i === this.accounts.length-1) {
- var write = this.accounts[i];
- stream.write(write, function() {
- });
- }
- else {
- var write = this.accounts[i] + "\n";
- stream.write(write, function() {
- });
- }
- }
- console.log('Updated Accounts');
- stream.end();
- },500);
- return;
- }
- }
- }
- private calculateTime(client:Client,location:WorldPosData):number {
- let x = Math.sqrt(client.worldPos.squareDistanceTo(location));
- let spd = 4+5.6*(client.playerData.spd/75);
- return 1000*x/spd;
- }
- private swap(client:Client,ObjectType:number[],objectID:number) {
- let j = 0;
- let count = 0;
- while (j<8) {
- if (ObjectType[j] !== -1) {
- count+=600;
- let X = j;
- setTimeout(() => {
- let invswap = new InvSwapPacket();
- let vaultItem = new SlotObjectData;
- vaultItem.objectId = objectID;
- vaultItem.objectType = ObjectType[j];
- vaultItem.slotId = X;
- invswap.slotObject1 = vaultItem;
- let temp = new SlotObjectData();
- temp.objectType = client.playerData.inventory[j];
- temp.slotId = X;
- temp.objectId = client.objectId;
- invswap.slotObject2 = temp;
- invswap.position = client.worldPos;
- invswap.time = client.getTime();
- client.packetio.sendPacket(invswap);
- },count);
- }
- }
- for (let key in this.classinfo.keys()) {
- let potInfo = this.classinfo.get(key);
- for (let i = 0;i<potInfo.length;i++) {
- if (potInfo[i] !== 0) {
- this.currentClass = key;
- this.currentPotion = i;
- }
- }
- }
- if (client.alias === this.potionNumbers[this.currentPotion]) {
- setTimeout(() => {
- client.gameId = -2;
- client.connect();
- },count+4000);
- }
- else {
- this.deleteAcc(client);
- this.tradeclass(this.potionNumbers[this.currentPotion]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement