Skip to content

Instantly share code, notes, and snippets.

@Stary2001
Created May 27, 2019 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stary2001/700cf2093ec4d22ae8451b624a517943 to your computer and use it in GitHub Desktop.
Save Stary2001/700cf2093ec4d22ae8451b624a517943 to your computer and use it in GitHub Desktop.
/* Original script written by Zekaonar
* Updated by Crowther
* Rewritten by UberFerret
* Maintained by digitrev */
script "UberPvPOptimizer.ash";
import <zlib.ash>;
//Declare all the variables
boolean showAllItems;
boolean buyGear;
int maxBuyPrice;
int topItems;
boolean limitExpensiveDisplay;
int defineExpensive;
// Booleans for each pvp mini
boolean letterCheck = true;
//other variables
string currentLetter = "b";
boolean dualWield = false;
item primaryWeapon; //mainhand
item secondaryWeapon; //offhand
item tertiaryWeapon; //hand
item bestOffhand;
item [string] [int] gear;
familiar[int] fams;
//return the class of an item
class getClass(item i)
{
return to_class(string_modifier(i, "Class"));
}
// Letter of the moment count source:Zekaonar
int letterCount(item gear, string letter)
{
if (gear == $item[none])
return 0;
matcher entity = create_matcher("&[^ ;]+;", gear);
string output = replace_all(entity,"");
matcher htmltag = create_matcher("\<[^\>]*\>",output);
output = replace_all(htmltag,"");
int lettersCounted=0;
for i from 0 to length(output)-1 {
if (char_at(output,i).to_lower_case()==letter.to_lower_case()) lettersCounted+=1;
}
return lettersCounted;
}
// Check if you have an item, or it is in the mall historically for a price within the budget
boolean canAcquire(item i) { //source:Zekaonar
return ((can_interact() && buyGear && maxBuyPrice >= historical_price(i) && historical_price(i) != 0)
|| available_amount(i)-equipped_amount(i) > 0);
}
//Chefstaves require a skill to equip
boolean isChefStaff(item i) {
return item_type(i) == "chefstaff";
}
//Make sure the item can be equipped
boolean canEquip(item i) {
if (can_equip(i) && (!isChefStaff(i) || my_class() == $class[Avatar of Jarlsberg] || have_skill($skill[Spirit of Rigatoni]))) {
return true;
} else {
return false;
}
}
/** generate a wiki link */
string link(String name) {
string name2 = replace_string(name, " ", "_");
name2 = replace_string(name2, "&quot;", "%5C%22");
return '<a href="http://kol.coldfront.net/thekolwiki/index.php/'+name2+'">'+name+'</a>';
}
/** function for calculating the value of a item based off the mini-game weighting */
float valuation(item i) {
float value = 0;
value += letterCount(i,currentLetter);
return value;
}
/** version that combines 2 items for 2hand compared to 1hand + offhand or dual 1hand.
Not used atm, 2hand gets -23 penality in Laconic for empty offhand, need to test Verbose */
float valuation(item i, item i2) {
float value = 0;
if (letterCheck)
value += (letterCount(i,currentLetter) + letterCount(i2,currentLetter));
return value;
}
/** equips gear, but also acquires it from the mall if it is under budget */
boolean gearup(slot s, item i) {
if(i == $item[none])
return false;
//print_html(i + " " + available_amount(i) + " " + equipped_amount(i));
if ((available_amount(i)-equipped_amount(i)) <= 0 && can_interact()
&& buyGear && maxBuyPrice >= historical_price(i) && historical_price(i) != 0)
buy(1, i, maxBuyPrice);
if (available_amount(i)-equipped_amount(i) > 0) {
if(!(get_inventory() contains i)) {
boolean raidCloset= get_property("autoSatisfyWithCloset").to_boolean() && closet_amount(i)>=1;
if(raidCloset) {
take_closet( 1, i );
}
}
return equip(s, i); //this is where the actual equipping happens
}
else
return false;
}
/** pretty print item details related to the active minigames */
string gearString(item i) {
string gearString = link(i) + " ";
if (letterCheck && letterCount(i,currentLetter) > 0)
gearString += ", " + letterCount(i,currentLetter) + " letter " + currentLetter;
gearString += ", value: " + valuation(i);
return gearString;
}
/*******
Snipped familiars
********/
/** loop through gear to find the best one you can get and equip */
int bestGear(string slotString, slot s) {
for j from 0 to Count(gear[slotString])-1 by 1 {
item g = gear[slotString][j];
if (boolean_modifier(g,"Single Equip") && equipped_amount(g) > 0)
continue;
//try to handle Barely Dressed mini
//this simultaneously checks if a piece can be equipped and tries to do so
//if (valuation(g) > 0 && ((canEquip(g) && gearup(s, g)) || (s == $slot[familiar] && canAcquire(g) && fams[j].use_familiar() && canEquip(g) && gearup(s, g)))) {
if (valuation(g) > 0 && ((canEquip(g)) || (s == $slot[familiar] && canAcquire(g) && fams[j].use_familiar() && canEquip(g)))) {
print_html("<b>Best Available " + s + ":</b> " + gearString(g));
//print_html(string_modifier(g,"Modifiers"));
return valuation(g);
}
}
return 0;
}
void main() {
int total;
/*** unequip all slots ***/
/*foreach i in $slots[hat, back, shirt, weapon, off-hand, pants, acc1, acc2, acc3, familiar]
equip(i,$item[none]);
print_html("<br/>"); */
/*******
Snipped familiars
********/
/*** create lists of all items in each slot type ***/
foreach i in $items[] { // This iterates over all items in the game
// if it's gear that you can equip, and you have it or the mall price is under threshold
string s = to_slot(i);
int price = npc_price(i);
if (price == 0)
price = historical_price(i);
if((!($slots[none, familiar] contains s.to_slot()) && can_equip(i)) &&
(showAllItems || canAcquire(i))) {
string modstring = string_modifier(i,"Modifiers");
// filter situational items that don't apply to fighting in arena
if (modstring.index_of("Unarmed") == -1) {
// create a new slot type for 2 hand and 3 hand weapons (not used atm)
if (s == $slot[weapon] && weapon_hands(i) > 1)
s = "2h weapon";
gear[s] [count(gear[s])] = i;
//length(i)
}
}
}
familiar [item] famItems;
foreach f in $familiars[]
if(f.have_familiar())
famItems[familiar_equipment(f)] = f;
string s = $slot[familiar].to_string();
foreach it in $items[] {
int price = npc_price(it);
if (price == 0)
price = historical_price(it);
if (famItems contains it || (it.to_slot().to_string() == s && string_modifier(it, "Modifiers").contains_text("Generic"))&& (showAllItems || canAcquire(it))) {
gear[s][count(gear[s])] = it;
if(famItems contains it)
fams[count(fams)] = famItems[it];
else
fams[count(fams)] = my_familiar();
}
}
/*** Top Gear display lists ***/
sort fams by -valuation(gear["familiar"][index]);
foreach i in $slots[hat, back, shirt, weapon, off-hand, pants, acc1, familiar] {
int itemCount = count(gear[to_string(i)]);
print_html("<b>Slot <i>" + i + "</i> items considered: " + itemCount + " printing top items in slot:</b>");
sort gear[to_string(i)] by -valuation(value);
if(limitExpensiveDisplay == true)
{
for j from 0 to (topItems - 1) by 1
print_html((j+1) + ".) " + gearString(gear[to_string(i)][j]) );
print_html("<br/>");
}
else
{
int dumbCounter = 0;
int dumbCounterToo = 0;
while(dumbCounter <= (topItems-1))
{
if(historical_price(gear[to_string(i)][dumbCounterToo])<= defineExpensive)
{
print_html((dumbCounter+1) + ".) " + gearString(gear[to_string(i)][dumbCounterToo]) );
dumbCounterToo = dumbCounterToo + 1;
dumbCounter = dumbCounter + 1;
}
else
{
dumbCounterToo = dumbCounterToo + 1;
}
}
print_html("<br/>");
}
}
/*** DISPLAY BEST GEAR IN SLOTS ***/
/*******
Snipped familiars
********/
/*** Display best in slot ***/
total += bestGear("hat", $slot[hat]);
total += bestGear("back", $slot[back]);
total += bestGear("shirt", $slot[shirt]);
// determine the best possible weapon combos
// 2hand / 3hand
// 1hand + offhand
// 1hand + 1hand (if skill Double-Fisted Skull Smashing)
if (have_skill($skill[Double-Fisted Skull Smashing])) {
dualWield = true;
print_html("<b>Player can dual wield 1-hand weapons.</b>");
}
int k = 0;
for j from 0 to Count(gear["weapon"])-1 by 1 {
if(canAcquire(gear["weapon"][j])) {
primaryWeapon = gear["weapon"][j];
k = j;
break;
}
}
total += bestGear("weapon", $slot[weapon]);
if (available_amount(primaryWeapon)-equipped_amount(primaryWeapon) > 1 || (historical_price(primaryWeapon) < maxBuyPrice && historical_price(primaryWeapon) > 0) && !isChefStaff(primaryWeapon))
secondaryWeapon = primaryWeapon;
else {
for j from k+1 to Count(gear["weapon"])-1 by 1 {
if(canAcquire(gear["weapon"][j]) && weapon_type(gear["weapon"][j]) == weapon_type(primaryWeapon) && !isChefStaff(primaryWeapon)) {
secondaryWeapon = gear["weapon"][j];
break;
}
}
}
for j from 0 to Count(gear["off-hand"])-1 by 1 {
if(canAcquire(gear["off-hand"][j])) {
bestOffhand = gear["off-hand"][j];
k = j;
break;
}
}
if ((!dualWield
|| valuation(primaryWeapon,bestOffhand) > valuation(primaryWeapon,secondaryWeapon))) {
//gearup($slot[off-hand],bestOffhand);
total += valuation(bestOffhand);
print_html("<b>Best Available off-hand:</b> " + gearString(bestOffhand));
//print_html(string_modifier(bestOffhand,"Modifiers"));
} else {
total += valuation(secondaryWeapon);
//gearup($slot[off-hand],secondaryWeapon);
print_html("<b>Best 2nd weapon:</b> " + gearString(secondaryWeapon));
//print_html(string_modifier(secondaryWeapon,"Modifiers"));
}
total += bestGear("pants", $slot[pants]);
total += bestGear("acc1", $slot[acc1]);
total += bestGear("acc1", $slot[acc2]);
total += bestGear("acc1", $slot[acc3]);
total += bestGear("familiar", $slot[familiar]);
print("total b:" + total);
/*******
Snipped familiars********/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment