What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

[Tutorial]: Understanding how to customize Armory Plugin!

Status
Not open for further replies.

Mojoguy01

Member
Joined
Mar 28, 2014
Messages
217
Reaction score
0
Hello there!

So if you haven't already seen this plugin, it is a MUST for gearing your bots AS they bot. It's a plugin made by rrrix, and all praise should be given to him for making such a straight forward plugin.


Q: What does it do?
A: This plugin will automatically equip a looted item based on the % stats given by the in-game menu when inspecting an item. In other words, if it is an "upgrade" based on loot rules you set then it will replace any item you're currently wearing with this one.

Q: Can I trust this to NOT get rid of items I actually want to keep?
A: This depends 100% on your understanding of C#, of which I'm making this thread to help you out with!

Q: Where can I get said Plugin?
A: Go back out one (Forum->Demonbuddy Forum -> Plugins) and you should see a thread near the top? Otherwise, if you're lazy: Boop





To the meat:

What we're interested in here is a small section of code that tells the bot what YOU consider to be an "upgrade". This section of code is found inside ItemEvaluator.cs inside your Armorery plugin folder. I recommend using NotePad++ (google it) for editing purposes. Make sure that NotePad++ is set to "C#" under language options at the top on your toolbar.


The code block we're looking for starts on line 161, or simply search for "0.05" and you'll find the CalculateUpgrade() boolean method. (This means anything calling this method is expecting a true/false return statement).


So what does all this jibberish mean? Let me lay it out for ya!

Default: Concentrates more on toughness over damage, and has a lower limit threshold of -15% damage for an upperlimit of 15% toughness.
Code:
private static bool CalculateUpgrade(float damage, float toughness, float healing)
        {
            bool isUpgrade = false;

            if (damage > -0.05 && damage + toughness > 0)
                isUpgrade = true;
            if (damage > -0.15 && damage + toughness > 0 && healing > 0)
                isUpgrade = true;
            return isUpgrade;
        }

Ok, so what does any of that mean? It means that if you look an item with -9.3% damage the bot will ONLY consider it an upgrade IF the Toughness you get out of the item is greater than +9.3%.

Math:
if (damage > -0.15 && damage + toughness > 0 && healing > 0)

This is saying that so long as the damage is GREATER than -15%, then as long as the toughness + damage is GREATER than 0 do we consider this an upgrade. The healing > 0 is only for the second fall-through if statement to ensure you aren't completing gimping yourself in surviveability as a whole just for some damage.

This is where the FIRST "If" statement comes in:
Code:
if (damage > -0.05 && damage + toughness > 0)

This is the statement that checks to see if the damage is GREATER than -5% so long as the Toughness you gain is GREATER than 5 so when you add them together you get > 0.



Ok, that all sounds....interesting....can you give me some examples?

Sure :D!


Let's say a sword drops that is -4.3% damage, but has +5.6% toughness and -1.6% healing. We see that the damage is GREATER than -5%, so the FIRST "if" statement will be checked first. We then ADD damage + toughness together and we get +1.3% difference. This means this sword is an UPGRADE and it will be swapped out with your current weapon. "Healing" is not taken into consideration here because it fit the first conditional statement.


Another example, is that a helmet drops with -4.9% damage, but only gives +1.9% toughness. Since the difference here is -3% it is NOT greater than 0 (dmg + tough) so we do NOT consider this an upgrade. Additionally, since the FIRST conditional failed the SECOND statement is then used. Albeit since they're not in an "else if" configuration both statements are always checked, but most likely if the first is true, then we really don't care about the second one.

Ok, so what happens to this helmet with the second statement? Well, again it doesn't matter because in the second statement we're still checking to see that dmg+tough > 0, so this will also fail. Thus, said helmet is NOT an upgrade and normal trinity salvage/sell rules are applied when your bot does a townrun.





OK COOL, I GOT IT, CAN YOU JUST HELP ME WITH SOME EXAMPLE TEMPLATES?

Coo, coo, calm down little buddy! I got you, we can't all be programmers :)!

--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------

Default: Concentrates on toughness over damage for survivability. Good for early game gearing of a new bot, but bad for mid/late game farming and/or leveling.
Code:
private static bool CalculateUpgrade(float damage, float toughness, float healing)
        {
            bool isUpgrade = false;

            if (damage > -0.05 && damage + toughness > 0)
                isUpgrade = true;
            if (damage > -0.15 && damage + toughness > 0 && healing > 0)
                isUpgrade = true;
            return isUpgrade;
        }

--------------------------------------------------------------------------------------------

Damage: Concentrates on damage over toughness. Essentially here we're just swapping damage for toughness in priority.
Code:
private static bool CalculateUpgrade(float damage, float toughness, float healing)
        {
            bool isUpgrade = false;

            if (toughness > -0.05 && damage + toughness > 0)
                isUpgrade = true;
            if (toughness > -0.15 && damage + toughness > 0 && healing > 0)
                isUpgrade = true;
            return isUpgrade;
        }

--------------------------------------------------------------------------------------------

The previous two above have one issue however. What if, for the damage oriented one, that the damage is NOT > 0.01? Well, say a sword drops that has +4.9% toughness but -4.9% damage? Or vise versa, with the toughness concentrated DEFAULT if, what happens if a -4.9% toughness sword drops with +6% damage? It will succeed as an upgrade as 6+(-4.9) == +1.1%. So if you want to force the bot to ONLY consider it an upgrade for damage OR toughness OR healing then you have to do the following:

--------------------------------------------------------------------------------------------

Forced: Damage Upgrade Focus, only consider something an upgrade for damage IF damage is GREATER than +1% to begin with.
Code:
private static bool CalculateUpgrade(float damage, float toughness, float healing)
        {
            bool isUpgrade = false;
			if (damage > 0.01)
			{
				if (toughness > -0.05 && damage + toughness > 0)
					isUpgrade = true;
				if (toughness > -0.15 && damage + toughness > 0 && healing > 0)
					isUpgrade = true;
			}
            return isUpgrade;
        }

--------------------------------------------------------------------------------------------

Forced: Toughness Upgrade Focus, only consider something an upgrade for Toughness IF Toughness is GREATER than +1% to begin with.
Code:
private static bool CalculateUpgrade(float damage, float toughness, float healing)
        {
            bool isUpgrade = false;
			if (toughness > 0.01)
			{
				if (damage > -0.05 && damage + toughness > 0)
					isUpgrade = true;
				if (damage > -0.15 && damage + toughness > 0 && healing > 0)
					isUpgrade = true;
			}
            return isUpgrade;
        }


--------------------------------------------------------------------------------------------


Finally, perhaps you want only everything to be in the green to be considered an upgrade?

Code:
private static bool CalculateUpgrade(float damage, float toughness, float healing)
        {
            bool isUpgrade = false;

            if (toughness > 0 && damage > 0 && healing > 0)
                isUpgrade = true;

            return isUpgrade;
        }

--------------------------------------------------------------------------------------------


Don't forget that you can also "tighten" these ranges to better fit a more specific upgrade pattern. At higher tiers of gear all I care about are lower limits on the negatives for positives. Meaning, if a weapon is +2.5% damage i'm only willing to part with a 1% difference versus toughness, etc etc. So this would look like:

Code:
private static bool CalculateUpgrade(float damage, float toughness, float healing)
        {
            bool isUpgrade = false;
			if (damage > 0.01)
			{
				if (toughness > -0.01 && damage + toughness > 0)
					isUpgrade = true;
				if (toughness > -0.05 && damage + toughness > 0 && healing > 0)
					isUpgrade = true;
			}
            return isUpgrade;
        }

--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------

Do NOT forget to restart DB completely after changing an item ruleset in Armory. I've tried refreshing the plugin when the bot is paused, but it doesn't take the new rules into consideration. ALWAYS RESTART OR HAVE DEMONBUDDY OFF WHEN MAKING CHANGES TO UPGRADE RULES!

Hope this helps D:!

-Mojo
 
Last edited:
Wow this is a miracle, I was just going to ask for help about this haha
Thank you :) Reading it

Is there anyway I could make it so it doesn't swap a specific item slot? Say I want to keep wearing my leoric's signet (pretty much anything can beat it in term of stats), how would I proceed? Thank you
 
Last edited:
Wow this is a miracle, I was just going to ask for help about this haha
Thank you :) Reading it

Is there anyway I could make it so it doesn't swap a specific item slot? Say I want to keep wearing my leoric's signet (pretty much anything can beat it in term of stats), how would I proceed? Thank you

Just skimming over the code I notice that the class "Inventory" does not contain a "LeftFinger", but does contain a "RightFinger". So I'm assuming that Inventory.Ring == left finger (please someone correct me if I am wrong on this)?

So if you put leoric's signet in your left ring slot and add
Code:
if (slot == InventorySlot.Ring)
			{
				return false;
			}

above
Code:
if (slot == InventorySlot.RightFinger)

That should ignore any possible "upgrades" for your left finger slot. That being said, you should test this first with a REALLY crappy ring that would almost always be replaced by the bot whenever it is updated for latest D3 patch.

Alternatively you could just modify the RightFinger code to always return false like so:
Code:
if (slot == InventorySlot.RightFinger)
            {
                // Alt item slot for Right Ring finger
                return false;
            }

and put the ring in the right finger?
 
Would it be easy to edit so it stashes the "possible upgrade" instead so you can check your self?
 
Would it be easy to edit so it stashes the "possible upgrade" instead so you can check your self?

Armory doesn't deal with stashing, it defaults that to Trinity's perview.

I'd recommend looking into specific trinity loot rules for that kind of behavior if Armory skips it as an upgrade, otherwise Trinity will trash it.
 
You should add the possibility to secure some slots, obviously rrrix will add it in the future but for the moment, you have to do it manually,

The purpose :

Protect some slots, for example protect a Leoric's Signet to be replaced with another upgrade (there's a lot...) or your Legendary Quiver, your 50% MF ring or whatever

The fast is it's pretty simple, just needs a bit of knowledge :

- Implementing protected Slots

1) First, you'll have to set up your protected slots somewhere, hardcoded (GUI will resolve this problem in the future)

- In ItemEvaluator, @ line 277~ or so, add this :

Code:
public static readonly List<InventorySlot> ProtectedSlots = new List<InventorySlot>()
{
	// There goes your protected inventory slots
};

2) After that, you'll have to know what's the matter with inventory slots, and what is their names (if you're not using an IDE like Visual Studio or so) those are your char's slots

Code:
Bracers
Feet
Hands
Head
LeftFinger
LeftHand
Legs
Neck
RightFinger
RightHand
Shoulders
Torso
Waist

3) Basically what you've to do after is to add under the comment "// There goes your protected inventory slots" something like that :

Code:
InventorySlot.<ENTER YOUR SLOT HERE>,

Replace the thing between <> by any slot listed above, and don't forget the comma !

Now that you've protected your shit, it's time to say to the bot that it don't have to replace them,

- Handling protected slots

1) In the ItemEvaluator.cs file, search for "ShouldEquipItem"

2) Under this line :

Code:
checkedItems.Add(new Tuple<InventorySlot, int>(slot, item.ACDGuid));

Add this :

Code:
// IGNORING SLOTS
if (ProtectedSlots.Contains(slot))
	return false;

3) Congrats you've successfully modified a plugin to do something useful :) farm hard or die tryin'

EDIT :

- DemonHunter Wrong Equip Settings

Some of you may have noticed your DH while leveling attempt to equip shields :) well I know it's ridiculous, here is how to fix it :

1) In the "Hero" folder, check the DemonHunter.cs file, and in "equippableItemTypes" List, search for this line :

Code:
ItemType.Shield,

Comment it like that :

Code:
//ItemType.Shield,

2) Enjoy.
 
Last edited:
You should add the possibility to secure some slots, obviously rrrix will add it in the future but for the moment, you have to do it manually,

The purpose :

Protect some slots, for example protect a Leoric's Signet to be replaced with another upgrade (there's a lot...) or your Legendary Quiver, your 50% MF ring or whatever

The fast is it's pretty simple, just needs a bit of knowledge :

- Implementing protected Slots

1) First, you'll have to set up your protected slots somewhere, hardcoded (GUI will resolve this problem in the future)

- In ItemEvaluator, @ line 277~ or so, add this :

Code:
public static readonly List<InventorySlot> ProtectedSlots = new List<InventorySlot>()
{
	// There goes your protected inventory slots
};

2) After that, you'll have to know what's the matter with inventory slots, and what is their names (if you're not using an IDE like Visual Studio or so) those are your char's slots

Code:
Bracers
Feet
Hands
Head
LeftFinger
LeftHand
Legs
Neck
RightFinger
RightHand
Shoulders
Torso
Waist

3) Basically what you've to do after is to add under the comment "// There goes your protected inventory slots" something like that :

Code:
InventorySlot.<ENTER YOUR SLOT HERE>,

Replace the thing between <> by any slot listed above, and don't forget the comma !

Now that you've protected your shit, it's time to say to the bot that it don't have to replace them,

- Handling protected slots

1) In the ItemEvaluator.cs file, search for "ShouldEquipItem"

2) Under this line :

Code:
checkedItems.Add(new Tuple<InventorySlot, int>(slot, item.ACDGuid));

Add this :

Code:
// IGNORING SLOTS
if (ProtectedSlots.Contains(slot))
	return false;

3) Congrats you've successfully modified a plugin to do something useful :) farm hard or die tryin'

EDIT :

- DemonHunter Wrong Equip Settings

Some of you may have noticed your DH while leveling attempt to equip shields :) well I know it's ridiculous, here is how to fix it :

1) In the "Hero" folder, check the DemonHunter.cs file, and in "equippableItemTypes" List, search for this line :

Code:
ItemType.Shield,

Comment it like that :

Code:
//ItemType.Shield,

2) Enjoy.

Keep in mind that InventorySlot.LeftFinger does not exist. Pretty sure that's what InventorySlot.Ring is for, but i haven't needed to protect a slot yet so there's that.
 
Keep in mind that InventorySlot.LeftFinger does not exist. Pretty sure that's what InventorySlot.Ring is for, but i haven't needed to protect a slot yet so there's that.

:) we need more people like you (irony is huge in this one)

PS: just a hint, Ring is an ItemType ;)
 
Im confused and Im horrible at understanding code :x can you help a noobie out please? =P

I only care about my damage, Id love to have 20mil+ damage + 0 toughness~

What code should I put in to ONLY Upgrade IF Damage is greater than current gear? and to ignore ALL toughness/healing calculations
 
:) we need more people like you (irony is huge in this one)

PS: just a hint, Ring is an ItemType ;)

You could just say i'm wrong if I am :(?

Also, I know "Ring" is considered an itemtype, however if Rightfinger is defined but LeftFinger is not that leaves questions does it not? Hence why I assume of it is InventorySlot.Ring then it must be dealing with the left ring no? Otherwise why define it differently for the RightFinger but not the left?
 
closed

Please use latest version of Armory if you want to edit anything.
 
Status
Not open for further replies.
Back
Top