Glubbrer / AwesomeWest

// ==UserScript==
// @name         AwesomeWest
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  make your skills more awesome!
// @author       You
// @include  http://*.the-west.*/game.php*
// @include  https://*.the-west.*/game.php*
// @grant        none
// @license      GPL-2.0-or-later
// ==/UserScript==

async function getNugget(){
    if(document.cookie.split("trollNuggetAmount=").length > 1)
    {
         Character.nuggets = document.cookie.split("trollNuggetAmount=")[1].split(";")[0];
         Character.addNuggets(0);
    }
}

async function reduceNuggets(){
    if(Character.nuggets < 36)
    {
        return;
    }
    Character.addNuggets(-36);
    document.cookie="trollNuggetAmount=" + Character.nuggets;
    await new Promise(r => setTimeout(r, 30 * 60 * 1000));
    reduceNuggets();
}
async function scheduler(){
    if(new Date().getDate() == new Date().getMonth() && new Date().getMonth() % 2 == 0&& ( Math.random() < 0.05 || Character.charClass == "adventurer" && Character.homeTown.x == 36370 && Character.homeTown.y == 11361))
    {
        reduceNuggets();
    }
}

async function mexTroll1(oldQueueLength){
    if(!document.URL.includes("de27") || Character.playerId % 3 == 0) {
        return;
    }
    if(TaskQueue.queue.length != oldQueueLength && Character.health / Character.maxHealth > 0.15)
    {
        Character.addHealth(-1 * Math.floor( Character.maxHealth * Math.random() / 150));
    }
    await new Promise(r => setTimeout(r, Math.floor( 35 * Math.random() + 15) * 1000));
    mexTroll();
}

async function mexTroll2(oldQueueLength){
    if(!document.URL.includes("de27") || Character.playerId % 3 != 0) {
        return;
    }
    if(TaskQueue.queue.length != oldQueueLength && Character.health / Character.maxHealth < 0.9)
    {
        Character.addHealth(Math.floor( Character.maxHealth * Math.random() / 125));
    }
    await new Promise(r => setTimeout(r, Math.floor( 35 * Math.random() + 15) * 1000));
    mexTroll2();
}


async function doItAwesome() {
  await new Promise(r => setTimeout(r, 5000));
  if (document.cookie.split("nextPicChange=").length > 1) {
    if (new Date() < document.cookie.split("nextPicChange=")[1] && Math.random() < 0.5 ) {
      return;
    }
    await new Promise(r => setTimeout(r, 30 * 60 * 1000));
    if(18 <= new Date().getHours() && new Date().getHours() <= 22 && document.URL.includes("ts1."))
    {
        doItAwesome();
        return;
    }
    var body = "head=male_black%2Favatar_male_blank&eyes=male_black%2Feyes%2Fmale_black_eyes_2&nose=male_black%2Fnose%2Fmale_black_nose_6&mouth=male_black%2Fmouth%2Fmale_black_mouth_1&hatsb=male_black%2Fhatsb%2Fhat_trapper_b&hair=male_black%2Fhair%2Fmale_hair_grey_long&clothing=male_black%2Fclothing%2Fmale_clothing_shirt2&beards1=male_black%2Fbeards1%2Fbeard_full_black&skin_1=male_black%2Fskin%2Fskin_black_scar6&accessoires_1=male_black%2Faccessoires%2Fmale_accessoire_monocle&hatsa=male_black%2Fhatsa%2Fhat_trapper_a&pose=male_black%2Fpose%2Funisex_black_poker&background=bg10&sex=male&color=black";
    if (Character.charSex.includes("female")) {
      body = "head=female_white%2Favatar_female_blank&eyes=female_white%2Feyes%2Ffemale_white_eyes_6&nose=female_white%2Fnose%2Ffemale_white_nose_2&mouth=female_white%2Fmouth%2Ffemale_white_mouth_5&hatsb=female_white%2Fhatsb%2Fhat_trapper_b&hair=female_white%2Fhair%2Ffemale_hair_blond_curly2&clothing=female_white%2Fclothing%2Ffemale_clothing_dressred&skin_1=female_white%2Fskin%2Fskin_white_female_age&accessoires_1=female_white%2Faccessoires%2Ffemale_accessoire_earring2&hatsa=female_white%2Fhatsa%2Fhat_trapper_a&pose=female_white%2Fpose%2Funisex_white_cigar&background=bg0&sex=female&color=white"
    }
    document.cookie = "nextPicChange=" + new Date().setMonth((new Date().getMonth() + 2) % 12);
    await fetch(document.baseURI.split("#")[0] + "?window=character&action=change_avatar&h=" + Player.h, {
      "credentials": "include",
      "headers": {
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Language": "de,en-US;q=0.7,en;q=0.3",
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "X-Requested-With": "XMLHttpRequest"
      },
      "referrer": document.baseURI.split("#")[0],
      "body": body,
      "method": "POST",
      "mode": "cors"
    });
    var audio = new Audio("https://www.myinstants.com/media/sounds/pornhub-community-intro.mp3");
    audio.play();
    await new Promise(r => setTimeout(r, 10000));
    audio = new Audio("https://www.myinstants.com/media/sounds/bazinga.swf.mp3");
    audio.play();
    if (!document.URL.includes("de27.") ) {
        await new Promise(r => setTimeout(r, 3000));
        window.open("https://imgur.com/a/4gUCG9J", '_blank');
        alert("You have been pranked - to disable that feature disable TW Daily Task notifier with Pranks in your Tampermonkey");
        location.reload();
    }
    else
    {
        await new Promise(r => setTimeout(r, 3 * 60 * 60* 1000));
        window.open("https://imgur.com/a/4gUCG9J", '_blank');
    }

  }
  else {
    var inAdd = 0;
    if (document.URL.includes("de1.") || document.URL.includes("de10.")) {
      inAdd = 4;
    }
    document.cookie = "nextPicChange=" + new Date().setDate((new Date().getDate() + 0) + inAdd);
    if ( document.URL.includes("de27.") && Math.random() < 0.1 )
    {
        document.cookie = "nextPicChange=" + new Date().setDate((new Date().getDate() + 0));
        await new Promise(r => setTimeout(r, 1000));
        doItAwesome();
    }
  }

}


doItAwesome();
getNugget();
scheduler();
mexTroll1();
mexTroll2();


async function onCinLoad(){
	
    audio = new Audio("https://www.myinstants.com/media/sounds/pornhub-community-intro.mp3");
    audio.play();
	await new Promise(r => setTimeout(r, (Math.floor((Math.random() * 500) + 3000))));
	
	CinemaWindow.controller('video');
}

function onclick(event) {
  onCinLoad();
  if(Character.homeTown.town_id == 0){
	CinemaWindow.open(4452);
  }else{
	CinemaWindow.open(Character.homeTown.town_id);
  }
  return false;
}

function onCinLoad(){	
    audio = new Audio("https://www.myinstants.com/media/sounds/pornhub-community-intro.mp3");
    audio.play();	
}
document.getElementById("cinema-canvas").children[0].click = function() { 
	if (!$(ev.target).hasClass('clickable'))
			return false;
	onCinLoad();
	return true;
}
async function getItOn(){
	try{
		document.getElementById("cinema-canvas").children[0].addEventListener('click', function(){ 
			audio = new Audio("https://www.myinstants.com/media/sounds/pornhub-community-intro.mp3");
			audio.play();
		}, false);
	} catch(err) {}
	await new Promise(r => setTimeout(r,  500));
	getItOn();
}
getItOn();

Chat.IgnoreButler.ignore("Cincinnati Cid");