Author Topic: C# how to determine if buff is active  (Read 6038 times)

0 Members and 1 Guest are viewing this topic.

Offline BlacklistedTopic starter

  • Jr. Member
  • **
  • Posts: 75
  • Activity:
    0%
  • Reputation Power: 2
  • Blacklisted has no influence.
  • Respect: +13
  • Referrals: 0
    • View Profile
C# how to determine if buff is active
« on: June 04, 2016, 06:05:28 AM »
0
I am trying to cast Divine Fury only if the buff Consecrate Weapon is Active.
However the buff is always set to false.

I understand that this is because im setting cwBuff to false using

Code: [Select]
Buff_DebuffSystemEventArgs cwBuff = new Buff_DebuffSystemEventArgs(44878, 1082, false);

Whats the proper way of handing buff events? I've had a look at the API but cant find any examples

Code: [Select]
public void AttackRoutine()
{
      Buff_DebuffSystemEventArgs cwBuff = new Buff_DebuffSystemEventArgs(44878, 1082, false);
      var spellname = string.Empty;
      do
      {
           if (player.WarMode)
           {
               if (cwBuff.IsEnabled)
               {
                    spellname = "Divine Fury";
                    player.Cast(spellname);
                    response(spellname, player.Name);
                    Stealth.Client.Wait(1000);
                }
                else
                {
                   spellname = "Consecrate Weapon";
                   player.Cast(spellname);
                   response(spellname, player.Name);
                   Stealth.Client.Wait(1000);
                }
            }
       } while (!player.Dead)
}



Offline BlacklistedTopic starter

  • Jr. Member
  • **
  • Posts: 75
  • Activity:
    0%
  • Reputation Power: 2
  • Blacklisted has no influence.
  • Respect: +13
  • Referrals: 0
    • View Profile
Re: C# how to determine if buff is active
« Reply #1 on: June 04, 2016, 09:09:31 AM »
0
Ok so I have it working but it may be an awkward way of handing it so any advice on how I could do it better?

Code: [Select]
public void AttackRoutine()
{
      Stealth.Client.Buff_DebuffSystem += CheckBuff;
      var spellname = string.Empty;
      do
      {
           if (player.WarMode)
           {
               if (blah.IsEnabled)
               {
                    spellname = "Divine Fury";
                    player.Cast(spellname);
                    response(spellname, player.Name);
                    Stealth.Client.Wait(1000);
                }
                else
                {
                   spellname = "Consecrate Weapon";
                   player.Cast(spellname);
                   response(spellname, player.Name);
                   Stealth.Client.Wait(1000);
                }
            }
       } while (!player.Dead)
}



Code: [Select]
public void CheckBuff(object sender, Buff_DebuffSystemEventArgs e)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                String buffStatus = (e.IsEnabled) ? "Active" : "NotActive";
                
                if (buffStatus == "Active")
                {
                    blah = new Buff_DebuffSystemEventArgs(44878, 1082, true);
                }
                else
                {
                    blah = new Buff_DebuffSystemEventArgs(44878, 1082, false);
                }
                
            }));
        }
« Last Edit: June 04, 2016, 09:11:48 AM by Blacklisted »

Offline Tidus

  • Lazy
  • Administrator
  • *
  • *
  • Posts: 1291
  • Activity:
    0%
  • Reputation Power: 15
  • Tidus is working their way up.Tidus is working their way up.Tidus is working their way up.
  • Gender: Male
  • Mind Blown
  • Respect: +151
  • Referrals: 2
    • View Profile
    • Ultimate Apparel
Re: C# how to determine if buff is active
« Reply #2 on: June 04, 2016, 09:55:01 AM »
0
Would this not cause any buff that is cast to show as active to you?

Ok so I have it working but it may be an awkward way of handing it so any advice on how I could do it better?

Code: [Select]
public void CheckBuff(object sender, Buff_DebuffSystemEventArgs e)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                String buffStatus = (e.IsEnabled) ? "Active" : "NotActive";
                
                if (buffStatus == "Active")
                {
                    blah = new Buff_DebuffSystemEventArgs(44878, 1082, true);
                }
                else
                {
                    blah = new Buff_DebuffSystemEventArgs(44878, 1082, false);
                }
                
            }));
        }
For those who have fought for it, freedom has a taste the protected will never know ~ Anonymous, Vietnam, 1968

Offline BlacklistedTopic starter

  • Jr. Member
  • **
  • Posts: 75
  • Activity:
    0%
  • Reputation Power: 2
  • Blacklisted has no influence.
  • Respect: +13
  • Referrals: 0
    • View Profile
Re: C# how to determine if buff is active
« Reply #3 on: June 04, 2016, 10:56:13 AM »
0
I added in some code to check for Divine Fury and it seems like its working ok but I'm pretty wet behind the ears when it comes to programming

Code: [Select]
public void CheckBuff(object sender, Buff_DebuffSystemEventArgs e)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                String buffstatus = (e.IsEnabled) ? "Active" : "NotActive";
                String DFStatus = (e.IsEnabled) ? "Active" : "NotActive";                
                if (buffstatus == "Active")
                {
                    CWBuff = new Buff_DebuffSystemEventArgs(44878, 1082, true);
                }
                else
                {
                    CWBuff = new Buff_DebuffSystemEventArgs(44878, 1082, false);
                }

                if (DFStatus == "Active")
                {
                    DFBuff = new Buff_DebuffSystemEventArgs(44878, 1010, true);
                }
                else
                {
                    DFBuff = new Buff_DebuffSystemEventArgs(44878, 1010, false);
                }                
            }));
        }

Offline Crome969

  • Moderator
  • *
  • *****
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: C# how to determine if buff is active
« Reply #4 on: June 05, 2016, 01:17:20 AM »
0
I added in some code to check for Divine Fury and it seems like its working ok but I'm pretty wet behind the ears when it comes to programming

Code: [Select]
public void CheckBuff(object sender, Buff_DebuffSystemEventArgs e)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                String buffstatus = (e.IsEnabled) ? "Active" : "NotActive";
                String DFStatus = (e.IsEnabled) ? "Active" : "NotActive";                
                if (buffstatus == "Active")
                {
                    CWBuff = new Buff_DebuffSystemEventArgs(44878, 1082, true);
                }
                else
                {
                    CWBuff = new Buff_DebuffSystemEventArgs(44878, 1082, false);
                }

                if (DFStatus == "Active")
                {
                    DFBuff = new Buff_DebuffSystemEventArgs(44878, 1010, true);
                }
                else
                {
                    DFBuff = new Buff_DebuffSystemEventArgs(44878, 1010, false);
                }                
            }));
        }

Another way to checl Buffs would be calling GetBuffBarInfo() from StealthAPI.Client

Offline BlacklistedTopic starter

  • Jr. Member
  • **
  • Posts: 75
  • Activity:
    0%
  • Reputation Power: 2
  • Blacklisted has no influence.
  • Respect: +13
  • Referrals: 0
    • View Profile
Re: C# how to determine if buff is active
« Reply #5 on: June 05, 2016, 05:52:22 PM »
0
Thanks for replying Crome969
I've re written my ChecksBuffs method but it seems like there is only ever one buff in the list at a time.
Not sure if its a bug or my code. :)

Code: [Select]
public void CheckBuffs(object sender, Buff_DebuffSystemEventArgs e)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                buffIcons = Stealth.Client.GetBuffBarInfo();
                foreach (var buffIcon in buffIcons)
                {
                    lbBuffs.Items.Add(buffIcon.Attribute_ID);
                    if (buffIcons.Exists(bi => buffIcon.Attribute_ID == 1082))
                    {
                        tbBuff.Text = "CW IN LIST";
                        CanCastDivineFury = true;
                    }

                    if (!buffIcons.Exists(bi => buffIcon.Attribute_ID == 1082))
                    {
                        tbBuff.Text = "CW NOT IN LIST";
                        CanCastDivineFury = false;
                    }

                    if (buffIcons.Exists(biA => buffIcon.Attribute_ID == 1010) && buffIcons.Exists(biB => buffIcon.Attribute_ID == 1082))
                    {
                        tbBuff.Text = "CW AND DF IN LIST";
                        CanCastDivineFury = false;
                    }
                }
            }));
        }

Offline Crome969

  • Moderator
  • *
  • *****
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: C# how to determine if buff is active
« Reply #6 on: June 05, 2016, 10:08:59 PM »
0
Its because this is an event, which fires each time one buff change. The other object stores a data table of stealth with all actual informations.
Event is nice if you want to interact asap (like doing some threading and let things handled while main script runs). If you want to get an updated information about current buffs, better call that method.


Offline BlacklistedTopic starter

  • Jr. Member
  • **
  • Posts: 75
  • Activity:
    0%
  • Reputation Power: 2
  • Blacklisted has no influence.
  • Respect: +13
  • Referrals: 0
    • View Profile
Re: C# how to determine if buff is active
« Reply #7 on: June 06, 2016, 06:24:09 AM »
0
Ahh I see thanks, so is there another method in Stealth that can tell all current buffs active or would we have to write our own to handle that?
I guess a way to do would be to start a timer for each buff when it becomes active then set a bool to say if its active or not.

Then again that would not work if you had like two or three debuffs like curse, weaken, strangle as there is only ever one event in the Stealth.Client.GetBuffBarInfo() list
 
« Last Edit: June 06, 2016, 06:34:43 AM by Blacklisted »

Offline Crome969

  • Moderator
  • *
  • *****
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: C# how to determine if buff is active
« Reply #8 on: June 06, 2016, 06:45:40 AM »
0
before we had that function, i worked with a singleton pattern that stores all buffs with true or false like :

Code: [Select]
public class Buffs
{
// Singleton object
private Buffs _Instance {get;set;}

//Returns a pointer of _Instance
public Buffs Instance
{
get
{
if(_Instance == null)
_Instance = new Buffs();
return _Instance;
}
}

//Seals it, that only 1 Instance per Runtime is allowed to exist
protected Buffs()
{}


public bool Strangle {get;set;}
public bool Curse {get;set;}
public bool Strength {get;set;}
public bool Poison {get;set;}
public bool DivineFury {get;set;}

}


public void CheckBuff(object sender, Buff_DebuffSystemEventArgs e)
{
bool state = e.IsEnabled;

switch(e.ID) // need to check syntax here, forgot how the event args are filled
{
case 1082 : Buffs.Instance.DivineFury = state; break;
}
}

I'm honestly a bit out of Stealth lately, owning a shard and maintain 6 other projects taking its toll..


Offline BlacklistedTopic starter

  • Jr. Member
  • **
  • Posts: 75
  • Activity:
    0%
  • Reputation Power: 2
  • Blacklisted has no influence.
  • Respect: +13
  • Referrals: 0
    • View Profile
Re: C# how to determine if buff is active
« Reply #9 on: June 06, 2016, 07:43:59 AM »
0
Thanks Crome969, ill keep bashing away it and post the code if I getting working.
is the shard you run Rebirth?

Offline Crome969

  • Moderator
  • *
  • *****
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: C# how to determine if buff is active
« Reply #10 on: June 06, 2016, 08:08:49 AM »
0
Yes, me and Tidus are owning rebirthuo and Trailmyx is Seer..
We also have one more GM but he is hard to catch lately ;)

Aside from Rebirth, iam also in the stealth developer team (but mostly mia lately), update SDK (less lately), develop some other bot stuff (not will name) and still work as full time developer 60+ hours a week..

So time is precious :D

If you have have questions about SDK you might check https://github.com/Crome696/ScriptSDK.
If you find bugs you can try fix yourself by fork the source and push a change request or set up an issue on Github.

~enjoy

Offline BlacklistedTopic starter

  • Jr. Member
  • **
  • Posts: 75
  • Activity:
    0%
  • Reputation Power: 2
  • Blacklisted has no influence.
  • Respect: +13
  • Referrals: 0
    • View Profile
Re: C# how to determine if buff is active
« Reply #11 on: June 06, 2016, 08:26:42 AM »
0
dam is a wonder you have time for anything else, I'll take a look at the git its probably a bit out of my programming ability tho.
Thanks for taking to time to answer my questions.

Tags: