PDA

View Full Version : Small code change help


Slaymore
01-22-2016, 01:19 PM
HI :)

Sorry if this is not the right forum. Please feel free to move as needed.

I would like to make a change where the necro pet reverts back 15 years lol

By this I mean, once upon a time, a necro could give his pet 2 noobie daggers and the pet would use the attack speed from the daggers but still retain the pet innate damage.

Just looking to be pointed in the right direction on where I might find the necro pet code etc.

I have a linux install up and running and everything seems to be working fine.

I am not a programmer but I can normally figure things out with a little google fu.

Why do I want this you ask? Well, way back, i can remember watching a necro kill freeport guards. He then entertained me for a few minutes while his pet talked to me and he did all kinds of wonderful things ( I had no idea what was going on at that time in the game). Anyway, I instantly logged out and made a necro of course.. and within a few days they patched that weapon speed feature out of the game lol .. It is still one of my best memories from eq when everything was new and magical..

The butcherblock dwarves were a common target as well.. and they dropped a 25pp axe .. I was so envious and couldn't wait to do those things lol

I know how to change the guards hp back in the db .. I even think i have logs from back then lol.

Just looking for a pointer in the right direction or if this is even possible.

Thanks in advance :)

Uleat
01-22-2016, 02:12 PM
I doubt that it was a 'feature' .. but, rather an honest to goodness bug.


There's nothing keeping you from changing combat behavior - or any behavior for that matter - to anything that you wish :)

That's the whole point of customization!


There is no specific code for necro pet melee combat. All pets (mobs?) share the same basic code.

You would need to add special checks to account for the pet class and (probably) just add an empty-handed damage check to whatever weapon damage is reported.

This is the attack processing code: https://github.com/EQEmu/Server/blob/master/zone/attack.cpp

That would be a good place to start and just follow the calls backwards as needed.


Just remember..unless you explicitly specify to only check for client-owned pets, all pets - including mob-owned - will receive this modifier.

Slaymore
01-22-2016, 04:15 PM
Thank you so much, Uleat, for pointing me in the right direction. HEHE you caught my use of the word "feature" right away lol

Having said that I think what I was asking about might already be the default .. reading through the attack.cpp i found this:

// Technically NPCs should do some logic for weapons, but the effect is minimal
// What they do is take the lower of their set delay and the weapon's
// ex. Mob's delay set to 20, weapon set to 19, delay 19
// Mob's delay set to 20, weapon set to 21, delay 20

This is assuming that pets are using NPC melee code.. I'm sill looking lol

But, taking a look in the database, i see this pet for example:

566 SumAirR16 attack_speed -19 / attack_delay 29

Im not sure what attack_speed -19 does but a quick google and I found a post that said it was no longer used and replaced by attack_delay (not sure if true or not). But according to the comment in the attack.cpp file if i give any weapon to this air pet (or any pet with a attack_delay higher than the weapon delay) with a delay lower than 29 it should use the lower delay of the weapon.

I can honestly say that I never tried it (parsed) lol, and if this is true than it is defiantly not live like for 15 years or so ..

I am totally new to this so if I am way off base here please cut me some slack lol.. Im fragile :)

Freshmaker
01-26-2016, 12:50 PM
I've honestly never touched the eqemu codebase before, so everything is still entirely foreign to me.

I'm confident in most of the logic here other than how I attempt to grab the weapon(s) equipped by the pet. Random shot in the dark, untested, likely won't work. But, I can't test this right now.


diff --git a/zone/attack.cpp b/zone/attack.cpp
index 85ee29e..003acb3 100644
--- a/zone/attack.cpp
+++ b/zone/attack.cpp
@@ -4586,17 +4586,6 @@ void NPC::SetAttackTimer()
attack_timer.SetAtTrigger(4000, true);

Timer *TimerToUse = nullptr;
- int hhe = itembonuses.HundredHands + spellbonuses.HundredHands;
-
- // Technically NPCs should do some logic for weapons, but the effect is minimal
- // What they do is take the lower of their set delay and the weapon's
- // ex. Mob's delay set to 20, weapon set to 19, delay 19
- // Mob's delay set to 20, weapon set to 21, delay 20
- int speed = 0;
- if (RuleB(Spells, Jun182014HundredHandsRevamp))
- speed = static_cast<int>(((attack_delay / haste_mod) + ((hhe / 1000.0f) * (attack_delay / haste_mod))) * 100);
- else
- speed = static_cast<int>(((attack_delay / haste_mod) + ((hhe / 100.0f) * attack_delay)) * 100);

for (int i = MainRange; i <= MainSecondary; i++) {
//pick a timer
@@ -4609,6 +4598,13 @@ void NPC::SetAttackTimer()
else //invalid slot (hands will always hit this)
continue;

+ const Item_Struct *ItemToUse = nullptr;
+
+ //find our item
+ ServerLootItem_Struct* item_data = GetItem(i);
+ if (item_data)
+ ItemToUse = database.GetItem(item_data->item_id);
+
//special offhand stuff
if (i == MainSecondary) {
// SPECATK_QUAD is uncheesable
@@ -4618,6 +4614,50 @@ void NPC::SetAttackTimer()
}
}

+ //see if we have a valid weapon
+ if (ItemToUse != nullptr) {
+ //check type and damage/delay
+ if (ItemToUse->ItemClass != ItemClassCommon
+ || ItemToUse->Damage == 0
+ || ItemToUse->Delay == 0) {
+ //no weapon
+ ItemToUse = nullptr;
+ }
+ // Check to see if skill is valid
+ else if ((ItemToUse->ItemType > ItemTypeLargeThrowing) &&
+ (ItemToUse->ItemType != ItemTypeMartial) &&
+ (ItemToUse->ItemType != ItemType2HPiercing)) {
+ //no weapon
+ ItemToUse = nullptr;
+ }
+ }
+
+ int hhe = itembonuses.HundredHands + spellbonuses.HundredHands;
+
+ // Client pets do some logic for weapons, but the effect is minimal
+ // What they do is take the lower of their set delay and the weapon's
+ // ex. Pet's delay set to 20, weapon set to 19, delay 19
+ // Pet's delay set to 20, weapon set to 21, delay 20
+ int speed = 0;
+ int delay = 100 * attack_delay;
+
+ // Only apply the weapon-based delay modifications to Client pets. Otherwise,
+ // this change would affect all NPCs and their pets
+ bool clientpet = false;
+ if ((IsPet() || IsTempPet()) && IsPetOwnerClient())
+ clientpet = true;
+
+ // Apply weapon delay only if it's faster than the pet's default attack_delay
+ if (clientpet && (ItemToUse != nullptr) && (ItemToUse->Delay < attack_delay))
+ delay = 100 * ItemToUse->Delay;
+
+ speed = delay / haste_mod;
+
+ if (RuleB(Spells, Jun182014HundredHandsRevamp))
+ speed = static_cast<int>(speed + ((hhe / 1000.0f) * speed));
+ else
+ speed = static_cast<int>(speed + ((hhe / 100.0f) * delay));
+
TimerToUse->SetAtTrigger(std::max(RuleI(Combat, MinHastedDelay), speed), true, true);
}
}


It at least compiles, but that means little. If you care to give 'er a whirl, let me know. I may be able to test this tonight.

Freshmaker
01-27-2016, 09:54 AM
As I anticipated, I tested this last night and it doesn't work. Going to need to brush up more on the codebase and, having come from the land of Perl, I'm at a disadvantage. In theory all that needs to be fixed is the correct way of nabbing the pet's equipped weapons to read in their delay. The rest of the logic to only apply it if it's faster and only if it's a Client/PC pet should work. Maybe this weekend I'll try and expand my mind on the eqemu codebase and revisit.

But, should you be more versed in eqemu's codebase, the above should at least give you a great starting point to accomplish what you want.

image
01-27-2016, 10:55 AM
Doing this off the top of my head, but the NPC use-case could be something like this to get the weapon delay:

const Item_Struct* ItemToUse = NULL;
int itemID = CastToNPC()->GetEquipment(MATERIAL_PRIMARY);
if (itemID > 0)
ItemToUse = database.GetItem(itemID);

then you can check if ItemToUse isn't null and use ItemToUse->Delay

Freshmaker
02-10-2016, 09:35 PM
Got bored enough to give this another look see tonight. Thanks, image. That helped. I've cobbled together something that gives you the functionality you want, Slaymore.

Tested this by confirming that NEC's "Invoke Death" pet (base 33 delay) gets appropriately set to 19 when given a Lamentation. I didn't thoroughly test all scenarios, but weapons should NOT be able to make a pet hit slower. If the delay is worse, it ignores the delay. If it's faster, it uses it.


diff --git a/zone/attack.cpp b/zone/attack.cpp
index 2fdf5f1..9b7a1b9 100644
--- a/zone/attack.cpp
+++ b/zone/attack.cpp
@@ -4584,17 +4584,6 @@ void NPC::SetAttackTimer()
attack_timer.SetAtTrigger(4000, true);

Timer *TimerToUse = nullptr;
- int hhe = itembonuses.HundredHands + spellbonuses.HundredHands;
-
- // Technically NPCs should do some logic for weapons, but the effect is minimal
- // What they do is take the lower of their set delay and the weapon's
- // ex. Mob's delay set to 20, weapon set to 19, delay 19
- // Mob's delay set to 20, weapon set to 21, delay 20
- int speed = 0;
- if (RuleB(Spells, Jun182014HundredHandsRevamp))
- speed = static_cast<int>(((attack_delay / haste_mod) + ((hhe / 1000.0f) * (attack_delay / haste_mod))) * 100);
- else
- speed = static_cast<int>(((attack_delay / haste_mod) + ((hhe / 100.0f) * attack_delay)) * 100);

for (int i = MainRange; i <= MainSecondary; i++) {
//pick a timer
@@ -4607,6 +4596,16 @@ void NPC::SetAttackTimer()
else //invalid slot (hands will always hit this)
continue;

+ const Item_Struct *ItemToUse = nullptr;
+
+ // Identify the material from the slot to determine the weapon
+ uint8 materialFromSlot = _MaterialInvalid;
+ materialFromSlot = Inventory::CalcMaterialFromSlot(i);
+
+ int itemID = GetEquipment(materialFromSlot);
+ if (itemID > 0)
+ ItemToUse = database.GetItem(itemID);;
+
//special offhand stuff
if (i == MainSecondary) {
// SPECATK_QUAD is uncheesable
@@ -4616,6 +4615,50 @@ void NPC::SetAttackTimer()
}
}

+ //see if we have a valid weapon
+ if (ItemToUse != nullptr) {
+ //check type and damage/delay
+ if (ItemToUse->ItemClass != ItemClassCommon
+ || ItemToUse->Damage == 0
+ || ItemToUse->Delay == 0) {
+ //no weapon
+ ItemToUse = nullptr;
+ }
+ // Check to see if skill is valid
+ else if ((ItemToUse->ItemType > ItemTypeLargeThrowing) &&
+ (ItemToUse->ItemType != ItemTypeMartial) &&
+ (ItemToUse->ItemType != ItemType2HPiercing)) {
+ //no weapon
+ ItemToUse = nullptr;
+ }
+ }
+
+ int hhe = itembonuses.HundredHands + spellbonuses.HundredHands;
+
+ // Client pets do some logic for weapons, but the effect is minimal
+ // What they do is take the lower of their set delay and the weapon's
+ // ex. Pet's delay set to 20, weapon set to 19, delay 19
+ // Pet's delay set to 20, weapon set to 21, delay 20
+ int speed = 0;
+ int delay = 100 * attack_delay;
+
+ // Only apply the weapon-based delay modifications to Client pets. Otherwise,
+ // this change would affect all NPCs and their pets
+ bool clientpet = false;
+ if ((IsPet() || IsTempPet()) && IsPetOwnerClient())
+ clientpet = true;
+
+ // Apply weapon delay only if it's faster than the pet's default attack_delay
+ if (clientpet && (ItemToUse != nullptr) && (ItemToUse->Delay < attack_delay))
+ delay = 100 * ItemToUse->Delay;
+
+ speed = delay / haste_mod;
+
+ if (RuleB(Spells, Jun182014HundredHandsRevamp))
+ speed = static_cast<int>(speed + ((hhe / 1000.0f) * speed));
+ else
+ speed = static_cast<int>(speed + ((hhe / 100.0f) * delay));
+
TimerToUse->SetAtTrigger(std::max(RuleI(Combat, MinHastedDelay), speed), true, true);
}
}

Slaymore
02-12-2016, 10:38 AM
Wow That is awesome thank you so much, Freshmaker!!

lol having said that let me see if I can figure out how to apply this.

So, my directory structure is like so:

:~/eqemu$ ls
bin CMakeLists.txt loginserver ucs
changelog.txt common luabind utils
client_files dependencies Makefile world
cmake eqlaunch queryserv zone
CMakeCache.txt freshmaker_petattackspeed_patch.diff README.md
CMakeFiles GPL.txt shared_memory
cmake_install.cmake LICENSE.md tests


I created the file freshmaker_petattackspeed_patch.diff , pasted in your code.

Now i believe i will need to edit this part of the file:

diff --git a/zone/attack.cpp b/zone/attack.cpp
index 2fdf5f1..9b7a1b9 100644
--- a/zone/attack.cpp
+++ b/zone/attack.cpp

to this:

diff --git freshmaker_petattackspeed_patch.diff /zone/attack.cpp
index 2fdf5f1..9b7a1b9 100644
--- freshmaker_petattackspeed_patch.diff
+++ /zone/attack.cpp

then run:

git apply freshmaker_petattackspeed_patch.diff

then:

make clean
make

How does that look? Am I in the ball park?

Freshmaker
02-12-2016, 12:44 PM
Without any modification to the snippet, you should just be able to save it and then use "git apply" against it. The diff is against the current master branch of EQEmu as of 2016-02-10, so if you get any chunk failures make sure you're up-to-date against master first.

But yeah, you'e got the right idea.

demonstar55
02-12-2016, 01:44 PM
Early on pets would use the delay of weapons if it was faster. This was patched. (it still works for normal NPCs AFAIK)

Pets damage can actually change if the weapon's base damage is higher than the pets base damage. (this is something we don't support)

Slaymore
02-12-2016, 02:13 PM
Success!! lol thank you so much!

This would have been so OP when it was on live lol.

I logged into my cleric and gave her a red dragon tooth (single use Invoke Death pet)

Gave him a Mosscovered Twig off hand (3/10) and a Revultant Whip (5/14) main hand. No other haste or buffs.

Had him attack the level 65 dummy in the arena.. he missed most of the time but check out this attack spam lol. Zenarer could open up a tattoo parlor :)

On a side note.. is there a way to see attack delay or haste as a number in GamParse?

Again thank you so much.. now that I see how to do these customizations I will have to give writing some code a try..

[Fri Feb 12 12:46:23 2016] Zenarer tells you, 'Attacking an undead training dummy Master.'
[Fri Feb 12 12:46:23 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:23 2016] Zenarer tries to crush an undead training dummy, but an undead training dummy parries!
[Fri Feb 12 12:46:23 2016] Zenarer tries to kick an undead training dummy, but misses!
[Fri Feb 12 12:46:24 2016] Zenarer tries to crush an undead training dummy, but an undead training dummy dodges!
[Fri Feb 12 12:46:24 2016] Zenarer tries to crush an undead training dummy, but an undead training dummy dodges!
[Fri Feb 12 12:46:24 2016] Zenarer tries to slash an undead training dummy, but an undead training dummy dodges!
[Fri Feb 12 12:46:25 2016] An undead training dummy hits Zenarer for 3 points of damage.
[Fri Feb 12 12:46:25 2016] Zenarer tries to crush an undead training dummy, but an undead training dummy ripostes!
[Fri Feb 12 12:46:26 2016] Zenarer slashes an undead training dummy for 59 points of damage.
[Fri Feb 12 12:46:26 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:27 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:27 2016] Zenarer tries to slash an undead training dummy, but an undead training dummy parries!
[Fri Feb 12 12:46:28 2016] Zenarer tries to crush an undead training dummy, but misses!
[Fri Feb 12 12:46:29 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:29 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:29 2016] Zenarer tries to crush an undead training dummy, but misses!
[Fri Feb 12 12:46:30 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:31 2016] Zenarer tries to crush an undead training dummy, but misses!
[Fri Feb 12 12:46:31 2016] Zenarer tries to kick an undead training dummy, but misses!
[Fri Feb 12 12:46:31 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:31 2016] Zenarer tries to slash an undead training dummy, but an undead training dummy dodges!
[Fri Feb 12 12:46:33 2016] Zenarer tries to crush an undead training dummy, but misses!
[Fri Feb 12 12:46:33 2016] Zenarer tries to crush an undead training dummy, but misses!
[Fri Feb 12 12:46:33 2016] Zenarer slashes an undead training dummy for 55 points of damage.
[Fri Feb 12 12:46:34 2016] Zenarer tries to crush an undead training dummy, but an undead training dummy dodges!
[Fri Feb 12 12:46:34 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:34 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:35 2016] Zenarer tries to crush an undead training dummy, but an undead training dummy dodges!
[Fri Feb 12 12:46:35 2016] Zenarer tries to crush an undead training dummy, but misses!
[Fri Feb 12 12:46:36 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:36 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:37 2016] Zenarer slashes an undead training dummy for 59 points of damage.
[Fri Feb 12 12:46:37 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:38 2016] Zenarer tries to slash an undead training dummy, but an undead training dummy parries!
[Fri Feb 12 12:46:39 2016] Zenarer tries to bash an undead training dummy, but misses!
[Fri Feb 12 12:46:40 2016] Zenarer tries to slash an undead training dummy, but misses!
[Fri Feb 12 12:46:40 2016] Zenarer tries to slash an undead training dummy, but misses!