swing speed code

swing speed code

Postby Batlin on Mon Sep 28, 2009 10:31 am

Code: Select all
// EIP = 0x00445901
int PLAYER::GetPlayerWeaponSpeed(void)
{
  // part 1: determine speed
  WEAPON weapon = this->GetWeaponInHand();
  int WeaponSpeed = 50; // wrestling speed
  if(weapon != NULL)
    weaponSpeed = weapon->GetSpeed();

  // part 2: math
  int dividor = weaponSpeed;
  dividor = dividor * (GetRealDexterity() + 100);
  if(dividor < 2000)
    return 20;
  return 40000 / dividor;
}

// EIP=0x00445981
void PLAYER::AdvanceSwingState(void)
{
  // EIP=0x0044598A
  WEAPON weapon = this->GetWeaponInHand();

  // EIP=0x00445995
  int SwingDuration = this->GetPlayerWeaponSpeed() * 2;

  // EIP=0x004459A2
  int DurationSecondState= (weapon != NULL) && weapon->ISRanged() ? 4 : 6; // archery 4, otherwise 6
 
  // EIP=0x004459C4
  DurationSecondState= SwingDuration <= DurationSecondState? 0 : SwingDuration - DurationSecondState;
 
  // EIP=0x004459E7
  int InitialDuration= DurationSecondState<= 4 ? 0 : DurationSecondState- 4;

  // EIP=0x00445A02
  int SwingState= this->SwingState;
  switch(SwingState)
  {
    case 0: if(this->SwingCounter >= InitialDuration)
            {
              this->SwingState = 1; // advance to next SwingState
              this->SwingCounter = InitialDuration;
            }
            break;
    case 1: if(this->SwingCounter >= DurationSecondState)
            {
              this->SwingState = 2; // advance to next SwingState
              this->SwingCounter = DurationSecondState;
            }
            break;
    default: if(this->SwingCounter > SwingDuration)
             {
               this->SwingState = 0; // begin a new swing
               this->SwingCounter = 0;
               return 3;
             }           
  }
  return this->SwingState; // 0 or 1 or 2
}

// EIP=0x00445AB0
void PLAYER::ResetSwingState(int TargetState)
{
  if(TargetState == 0)
  {
    this->SwingCounter = 0;
    this->SwingState = 0x318 = TargetState; // will be 0
  }
  else
  {
    this->SwingState = TargetState - 1; // will be 0 too
                                              // (TargetState is always 1)
    this->AdvanceSwingState(); // this->SwingState will now be 1...
  }
}
DoMove will call "ResetSwingState(1)" for archery; for any other melee type the timer/state continues to advance.

Inside the Attack function "ResetSwingState(0)" is called, exact conditions are currently unknown

The mobile variable at address 0x314 (SwingCounter) (integer) gets increased, 1 by 1 per tick up to 1000, regardless your combat mode!

"AdvanceSwingState()" is called from inside the CombatHearBeat function too.

EDIT: code clean-up & bug-fix with "return 3" in AdvanceSwingState
<Derrick> RunUO AI is kind of a functional prototype, which i have hacked into something resembling OSI behavior, but only by complitcating everything
Batlin
Site Admin
 
Posts: 306
Joined: Wed Apr 08, 2009 6:35 am


Re: swing speed code

Postby Derrick on Mon Sep 28, 2009 1:41 pm

Wow, great code.

A few observations from this right off the bat:
The slowest possible wepon swing is 20 ticks/swing (5 secs)
The swing state is stored in the mobile, not the weapon
This is very very different from the RunUO swingtimer system, but definately implementable.
Derrick
Site Admin
 
Posts: 250
Joined: Tue Jun 17, 2008 2:33 pm


Re: swing speed code

Postby Batlin on Mon Sep 28, 2009 1:43 pm

Screenshots of the Walk Packet handler reaching the swing state reset for archery

The Packet Handler will call FUNC_HandleWalk
FUNC_HandleIncomingPacket02.jpg
FUNC_HandleIncomingPacket02.jpg (84.65 KiB) Viewed 860 times


FUNC_HandleWalk will call FUNC_DoMove, I should have called this FUNC_DoWalk, but I didn't :)
FUNC_DoMove.jpg
FUNC_DoMove.jpg (22.63 KiB) Viewed 856 times


FUNC_DoMove will in its turn call FUNC_DoMoveInternal, this internal function starts using the map to verify if you can walk or not.
FUNC_DoMoveInternal.jpg
FUNC_DoMoveInternal.jpg (44.36 KiB) Viewed 852 times


This is inside FUNC_DoMoveInternal, after the map checks, where I saw a reference to weapon function I decoded earlier on, this find was the root/basis for the decompilation above:
LOCAL_DoSomethingWithWeaon.jpg
LOCAL_DoSomethingWithWeaon.jpg (39.5 KiB) Viewed 853 times

Decompilation:
Code: Select all
weaponinhand = this->GetWeaponInHand()
if(weaponinhand != NULL && weaponinhand->IsRanged())
  this->ResetSwingState(1);
<Derrick> RunUO AI is kind of a functional prototype, which i have hacked into something resembling OSI behavior, but only by complitcating everything
Batlin
Site Admin
 
Posts: 306
Joined: Wed Apr 08, 2009 6:35 am


Re: swing speed code

Postby Batlin on Mon Sep 28, 2009 1:53 pm

The slowest possible wepon swing is 20 ticks/swing (5 secs)

I'm not sure for now.

The value returned by GetPlayerWeaponSpeed is multiplied by 2. Making it 40 ticks or 10 secs, kind of slow, no?
<Derrick> RunUO AI is kind of a functional prototype, which i have hacked into something resembling OSI behavior, but only by complitcating everything
Batlin
Site Admin
 
Posts: 306
Joined: Wed Apr 08, 2009 6:35 am


Re: swing speed code

Postby Derrick on Mon Sep 28, 2009 2:01 pm

Batlin wrote:
The slowest possible wepon swing is 20 ticks/swing (5 secs)

I'm not sure for now.

The value returned by GetPlayerWeaponSpeed is multiplied by 2. Making it 40 ticks or 10 secs, kind of slow, no?

I see now.
50 wrestling speed equates to 4 in return value at 100 dex, and is then multiplied by 2 in the AdvanceSwingRate. The resultant wrestle rate would be swing/2 secs.

I'll verify this in demo
Derrick
Site Admin
 
Posts: 250
Joined: Tue Jun 17, 2008 2:33 pm


Re: swing speed code

Postby Batlin on Mon Jan 11, 2010 12:33 pm

Update:
I've replaced the variable this.0xXXX with their correct names aka SwingState and SwingCounter.
I also fixed a decompilation bug regarding when "return 3" was done inside the AdvanceSwingState function.
<Derrick> RunUO AI is kind of a functional prototype, which i have hacked into something resembling OSI behavior, but only by complitcating everything
Batlin
Site Admin
 
Posts: 306
Joined: Wed Apr 08, 2009 6:35 am


Re: swing speed code

Postby blazz on Mon Sep 13, 2010 7:37 pm

thanks for posting these codes, these could be a great help because I really like archery.
blazz
 
Posts: 1
Joined: Mon Sep 13, 2010 7:32 pm



Return to UO Demo

Who is online

Users browsing this forum: No registered users and 1 guest