Skip to content

Commit

Permalink
Merge pull request #19 from Tsunder/Legendaries
Browse files Browse the repository at this point in the history
add doctor legendaries
  • Loading branch information
Tsunder authored Nov 8, 2018
2 parents a5435c3 + 0e4e72d commit dc5ad78
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 41 deletions.
59 changes: 42 additions & 17 deletions chrome/combat.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,30 +411,50 @@ function addStimTimer() {
}
}

//returns the amount of drugs effectively taken, reduces drug intake in ratio, which is the conservative method.
function compensateDoctor( amount, ukey, doctorType, extraConsumable) {
var doctorFactor = 0;
if (doctorType == "Primary") {
doctorFactor = 2;
} else if (doctorType == "Secondary") {
doctorFactor = 4;
}

if (doctorFactor > 1) {
var leftOverConsumables = (amount + extraConsumable) % doctorFactor; // the leftover amount of consumables to be stored for next time.
amount -= Math.floor( (amount + extraConsumable) * (1/doctorFactor) ) // negate this amount of consumables, the amount that is the "effective" amount taken and the reduction factor
return [amount, leftOverConsumables];
} else {
return [amount, extraConsumable];
}
}

function usedDrugs( tr ) {
var input = doc.evaluate(
"//tr/td/input[@name = 'resid' and @value = 51]",
doc, null, XPathResult.ANY_UNORDERED_NODE_TYPE,
null ).singleNodeValue;

var amount = parseInt(input.nextElementSibling.value);
if (!(amount > 0 )) {
return;
}
var ukey = Universe.getServer ( document ).substr( 0, 1 );
if (amount > 1) {
var ukey = Universe.getServer ( document ).substr( 0, 1 );

chrome.storage.sync.get(
[ ukey + 'drugTimerLast', ukey + 'drugTimerClear'],
usedDrugs2.bind(null, amount, ukey) );
chrome.storage.sync.get(
[ukey + 'drugTimerLast', ukey + 'drugTimerClear', ukey + 'doctor', ukey + 'extraDrug'],
usedDrugs2.bind(null, amount, ukey) );
}
}

function usedDrugs2( amount, ukey, data ) {
if (!data[ ukey + 'drugTimerClear'] ) {
data = new Object();
data[ ukey + 'drugTimerClear'] = 0;
data[ ukey + 'extraDrug'] = 0;
}
var doctorCompensation = compensateDoctor(amount, ukey, data[ukey + 'doctor'], data[ukey + 'extraDrug']);
amount = doctorCompensation[0];
data[ ukey + 'extraDrug'] = doctorCompensation[1];
var now = Date.now();

if (data[ ukey + 'drugTimerClear'] > now ) {
data[ ukey + 'drugTimerClear'] += amount * oneHour;
}
Expand All @@ -455,17 +475,17 @@ function usedStims( tr ) {
null ).singleNodeValue;
if (input) {
var amount = parseInt(input.nextElementSibling.value);
if (!(amount > 0))
return;
var ukey = Universe.getServer ( document ).substr( 0, 1 );
if (amount > 1) {
var ukey = Universe.getServer ( document ).substr( 0, 1 );

//29 is the resid of green stims.
if (resid == 29)
amount *= 2;
//29 is the resid of green stims.
if (resid == 29)
amount *= 2;

chrome.storage.sync.get(
[ ukey + 'stimTimerLast', ukey + 'stimTimerClear'],
usedStims2.bind(null, amount, ukey) );
chrome.storage.sync.get(
[ ukey + 'stimTimerLast', ukey + 'stimTimerClear'],
usedStims2.bind(null, amount, ukey) );
}
}
}
}
Expand All @@ -476,8 +496,13 @@ function usedStims2( amount,ukey, data ) {
if (!data[ ukey + 'stimTimerClear'] ) {
data = new Object();
data[ ukey + 'stimTimerClear'] = 0;
data[ ukey + 'extraStim'] = 0;
}

var doctorCompensation = compensateDoctor(amount, ukey, data[ukey + 'doctor'], data[ukey + 'extraStim']);
amount = doctorCompensation[0];
data[ ukey + 'extraStim'] = doctorCompensation[1];

if (data[ ukey + 'stimTimerClear'] > now) {
data[ ukey + 'stimTimerClear'] += amount * halfHour;
}
Expand Down
55 changes: 40 additions & 15 deletions chrome/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,21 +847,43 @@ function displayStimTimer ( ukey, usebtn, data ) {

}

//returns the amount of drugs effectively taken, reduces drug intake in ratio, which is the conservative method.
function compensateDoctor( amount, ukey, doctorType, extraConsumable) {
var doctorFactor = 0;
if (doctorType == "Primary") {
doctorFactor = 2;
} else if (doctorType == "Secondary") {
doctorFactor = 4;
}

if (doctorFactor > 1) {
var leftOverConsumables = (amount + extraConsumable) % doctorFactor; // the leftover amount of consumables to be stored for next time.
amount -= Math.floor( (amount + extraConsumable) * (1/doctorFactor) ) // negate this amount of consumables, the amount that is the "effective" amount taken and the reduction factor
return [amount, leftOverConsumables];
} else {
return [amount, extraConsumable];
}
}

function usedDrugs( useform, ukey ) {
let amount = parseInt( useform.elements.amount.value );
if ( !(amount > 0) )
return;

chrome.storage.sync.get(
[ ukey + 'drugTimerLast', ukey + 'drugTimerClear'],
usedDrugs2.bind(null, amount, ukey) );
if (amount >= 0) {
amount = 4
chrome.storage.sync.get(
[ukey + 'drugTimerLast', ukey + 'drugTimerClear', ukey + 'doctor', ukey + 'extraDrug'],
usedDrugs2.bind(null, amount, ukey) );
}
}

function usedDrugs2( amount, ukey, data ) {
if (!data[ ukey + 'drugTimerClear'] ) {
data = new Object();
data[ ukey + 'drugTimerClear'] = 0;
data[ ukey + 'extraDrug'] = 0;
}
var doctorCompensation = compensateDoctor(amount, ukey, data[ukey + 'doctor'], data[ukey + 'extraDrug']);
amount = doctorCompensation[0];
data[ ukey + 'extraDrug'] = doctorCompensation[1];
var now = Date.now();
if (data[ ukey + 'drugTimerClear'] > now )
data[ ukey + 'drugTimerClear'] += amount * oneHour;
Expand All @@ -875,27 +897,30 @@ function usedDrugs2( amount, ukey, data ) {
}



function usedStims( useform, ukey ) {
let amount = parseInt( useform.elements.amount.value );
if ( !(amount > 0))
return;
if ( amount > 0 ) {

//29 is the resid of green stims.
if (useform.elements.resid.value == 29 )
amount *= 2;
//29 is the resid of green stims.
if (useform.elements.resid.value == 29 )
amount *= 2;

chrome.storage.sync.get(
[ ukey + 'stimTimerLast', ukey + 'stimTimerClear'],
usedStims2.bind(null, amount, ukey ) );
chrome.storage.sync.get(
[ ukey + 'stimTimerLast', ukey + 'stimTimerClear', ukey + 'doctor', ukey + 'extraStim'],
usedStims2.bind(null, amount, ukey ) );
}
}


function usedStims2( amount, ukey, data ) {
if (!data[ ukey + 'stimTimerClear'] ) {
data = new Object();
data[ ukey + 'stimTimerClear'] = 0;
data[ ukey + 'extraStim'] = 0;
}
var doctorCompensation = compensateDoctor(amount, ukey, data[ukey + 'doctor'], data[ukey + 'extraStim']);
amount = doctorCompensation[0];
data[ ukey + 'extraStim'] = doctorCompensation[1];

var now = Date.now();
if (data[ ukey + 'stimTimerClear'] > now)
Expand Down
45 changes: 38 additions & 7 deletions chrome/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ <h3>Ambush settings</h3>
Alliance quicklists are obtained from the in-game <em>My Alliance</em>
page; see
<a target="_blank"
href="https://github.com/valitas/Pardus-Sweetener/wiki/Quick-lists">here</a>
href="https://github.com/valitas/Pardus-Sweetener/wiki/Quick-lists">here</a>
for details.
</p>

Expand All @@ -566,7 +566,7 @@ <h3>Ambush settings</h3>
</label>
<br>
<textarea id="personalQLArtemis" rows="3" disabled
placeholder="Artemis quicklist"></textarea>
placeholder="Artemis quicklist"></textarea>
</p>

<p class="orion">
Expand Down Expand Up @@ -649,7 +649,7 @@ <h3>Clocks</h3>
computer's clock and time zone should be set correctly. Modern operating
systems can keep your clock on the correct time automatically; see
<a target="_blank"
href="http://www.ehow.com/how_7550535_sync-clock-server.html">this
href="http://www.ehow.com/how_7550535_sync-clock-server.html">this
article</a>
for a quick rundown.
</p>
Expand Down Expand Up @@ -707,7 +707,12 @@ <h3>Clocks</h3>
</p>
</div>

<div class="setting">

</section>
<section>
<h3>Drugs and Stims </h3>
<div>Controls for drugs and stim clocks</div>
<div class="setting">
<p>
<input type="checkbox" id="clockD" />
<label for="clockD">
Expand All @@ -718,10 +723,36 @@ <h3>Clocks</h3>
<label for="clockStim">
Show the time remaining to being unstimmed
</label>
<br>
Doctors:
<p class="artemis">
<select id="adoctor">
<option value="NoDoc">None</option>
<option value="Primary">Primary</option>
<option value="Secondary">Secondary</option>
</select>
<input id="aresetDrugAndStim" alt="a" type="button" value="Reset clocks">
</p>
<p class="orion">
<select id="odoctor">
<option value="NoDoc">None</option>
<option value="Primary">Primary</option>
<option value="Secondary">Secondary</option>
</select>
<input id="oresetDrugAndStim" alt="o" type="button" value="Reset clocks">
</p>
<p class="pegasus">
<select id="pdoctor">
<option value="NoDoc">None</option>
<option value="Primary">Primary</option>
<option value="Secondary">Secondary</option>
</select>
<input id="presetDrugAndStim" alt="p" universe="test" type="button" value="Reset clocks">
</p>
<br>
</p>
</div>
</section>

<section>
<h3>About</h3>

Expand All @@ -733,10 +764,10 @@ <h3>About</h3>
<p>
Please report bugs and request enhancements in the
<a href="http://forum.pardus.at/index.php?showtopic=62190"
target="_blank">Pardus Forum</a>
target="_blank">Pardus Forum</a>
or the
<a href="https://github.com/valitas/Pardus-Sweetener"
target="_blank">GitHub repository</a>.
target="_blank">GitHub repository</a>.
</p>

<p>
Expand Down
38 changes: 36 additions & 2 deletions chrome/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function onDOMContentLoaded() {

// Find all these elements in the document, save references to
// them in xControls.
keys = [ 'testAlarm', 'testNotification', 'version' ];
keys = [ 'testAlarm', 'testNotification', 'version', 'aresetDrugAndStim', 'oresetDrugAndStim', 'presetDrugAndStim' ];

for ( i = 0, end = keys.length; i < end; i++ ) {
var key = keys[ i ];
Expand Down Expand Up @@ -89,7 +89,7 @@ function onDOMContentLoaded() {
// 4. Selects
setupControls ( 'change', onControlInput,
'alarmSound', 'autobotsArtemisPreset', 'autobotsOrionPreset',
'autobotsPegasusPreset', 'miniMapPlacement' );
'autobotsPegasusPreset', 'miniMapPlacement', 'adoctor', 'odoctor', 'pdoctor' );
unis.forEach(function (e) {
setupControls('input', onNumericControlInput, 'miniMapNavigationPreset' + e);
});
Expand All @@ -115,6 +115,17 @@ function onDOMContentLoaded() {
.addEventListener( 'click', updateMiniMapControlsDisable );
controls.miniMapNavigation
.addEventListener( 'click', updateMiniMapNavigationDisable );
extraControls
.aresetDrugAndStim.addEventListener( 'click', onResetDrugAndStimClick );
extraControls
.oresetDrugAndStim.addEventListener( 'click', onResetDrugAndStimClick );
extraControls
.presetDrugAndStim.addEventListener( 'click', onResetDrugAndStimClick );

//pretty sure these doctor listeners won't do anything, remove.
controls.adoctor.addEventListener('change', doctorListener);
controls.odoctor.addEventListener('change', doctorListener);
controls.pdoctor.addEventListener('change', doctorListener);

unis.forEach(function (uni) {
var e = controls["miniMapNavigationPreset" + uni];
Expand Down Expand Up @@ -319,6 +330,29 @@ function onControlInput( event ) {
chrome.storage.local.set( items );
}

//resets the drug and stim timers to 0 for the universe.
function onResetDrugAndStimClick(inputElement) {
var u = inputElement.target.alt;
console.log("reseting for universe " + u)
var data = new Object();
data[ u + 'stimTimerLast' ] = 0;
data[ u + 'stimTimerClear' ] = 0;
data[ u + 'drugTimerLast' ] = 0;
data[ u + 'drugTimerClear' ] = 0;
data[ u + 'extraStim' ] = 0;
data[ u + 'extraDrug' ] = 0;
chrome.storage.sync.set ( data );
console.log("reset")
}

//sets the doctor legendary for the universe
function doctorListener (inputElement) {
var data = new Object();
var target = inputElement.target
data[target.id] =target.value
chrome.storage.sync.set(data);
}

// This is like the above, but only allows numeric values greater than
// 1. One day we may need more sophistication...
function onNumericControlInput( event ) {
Expand Down

0 comments on commit dc5ad78

Please sign in to comment.