Author Topic: Bonus using SetSkill. Equip and Unequip Stacking Issue  (Read 2180 times)

Offline Lash

  • Acquaintance
  • *
  • Posts: 42
    • View Profile
Bonus using SetSkill. Equip and Unequip Stacking Issue
« on: October 26, 2009, 04:59:21 PM »
I was trying to implement an armor item that enabled a bonus of +2 to "melee attack" using SetSkills with the LIB_BONUS feature.

When the item was equipped the bonus applied. However, when quickly equipping and unequipping the item the bonus started stacking. Initially melee attack was set at a value of 1 then after wearing the item melee attack was set to 3 as expected. If I removed and re-wore the item quickly the bonus started stacking - so 1 to 3, 3 to5, 5 to 7 , etc.

Interestingly, if I waited a few seconds after observing this stacking phenomenon then removed and rewore the item the skill and bonus went back to baseline. It seems that the mud needs some time to reset the bonus after unequipping the item. Here's the relevant code after SetWear( (:check_morality:) ) in the armor item file

Code: [Select]

varargs int check_morality(object who, string where){
    int x, y, morality;
    object env = environment(who);

    morality = who->GetMorality();
   
    x=who->GetSkillLevel("melee attack");
    who->eventPrint("Melee attack before skill bonus = "+x+".");
             
    //only less than 'good' chars can use

    if( morality <=200 ){
    object ob=new(LIB_BONUS);
    ob->SetSkills( (["melee attack" : 2]) );
    ob->eventMove(who);
   
    x=who->GetSkillLevel("melee attack");
    who->eventPrint("Melee attack after skill bonus = "+x+".");
   
    who->eventPrint("You can feel an increase in your fighting "+
           "prowess as you put on the gloves.");
        if(env) tell_room(env, who->GetName()+" wears "+
          GetShort()+".", ({who})); 
     
    return 1; 

    }

    else {
       who->eventPrint("You cannot seem to get your hands in "+
            "the gloves.");
       
        x=who->GetSkillLevel("melee attack");
        who->eventPrint("Melee attack not wearing gloves = "+x+"."); 
    return 0;

    }
       
}


Here's the output I received - wearing and removing is in quick succesion:

(Morality is too high)

wear gloves
Melee attack before skill bonus = 1.
You cannot seem to get your hands in the gloves.
Melee attack not wearing gloves = 1.

(Reset morality)

call me->SetMorality(200)
OBJ(lash /secure/save/creators/l/lash) -> SetMorality( 200 ) = 200
wear gloves
Melee attack before skill bonus = 1.
Melee attack after skill bonus = 3.
You can feel an increase in your fighting prowess as you put on the gloves.
remove gloves
You remove a pair of swordsman gloves.

wear gloves
Melee attack before skill bonus = 3.
Melee attack after skill bonus = 5.
You can feel an increase in your fighting prowess as you put on the gloves.
remove gloves
You remove a pair of swordsman gloves.

wear gloves
Melee attack before skill bonus = 5.
Melee attack after skill bonus = 7.
You can feel an increase in your fighting prowess as you put on the gloves.
remove gloves
You remove a pair of swordsman gloves.

(After waiting about 5 seconds after removing the gloves)

wear gloves
Melee attack before skill bonus = 1.
Melee attack after skill bonus = 3.
You can feel an increase in your fighting prowess as you put on the gloves.

I was wondering if having a check for "if not worn" every heartbeat to do something like:

Code: [Select]

int check_gloves(string skill) {
    write("Check gloves called");
    if( !GetWorn() ) {
        previous_object()->RemoveSkillBonus("melee attack", this_object());
        return 0;
    }


I had the above function called before checking for the morality condition but it did not make a difference in the stacking behaviour.




Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Bonus using SetSkill. Equip and Unequip Stacking Issue
« Reply #1 on: October 26, 2009, 05:51:21 PM »
Ah.

LIB_BONUS is meant mostly to be used as something conjured by a
spell or a potion, which is why it does well as "something invisible
added to the player" and not so well as "something whose function is
invoked through wearing and dispelled through removing".

I'll take a look at refining it for that purpose.

-Crat

Offline Lash

  • Acquaintance
  • *
  • Posts: 42
    • View Profile
Re: Bonus using SetSkill. Equip and Unequip Stacking Issue
« Reply #2 on: October 27, 2009, 04:01:48 PM »
Thanks for looking at my question  :)

I got around it by getting rid of LIB_BONUS and modifying the code by directly adding the bonus to the skill and removing it after un-equiping the object.

Here's the code if anyone is interested:

Code: [Select]
varargs int check_morality(object who){
    int x, y, morality;
    
    object env = environment(who);

    morality = who->GetMorality();

  
    x=who->GetSkillLevel("melee attack");
    who->eventPrint("Melee attack before skill bonus = "+x+".");
      
    //only less than 'good' chars can use

    if( morality <=200 ){
    
    who->eventPrint("You can feel an increase in your fighting "+
           "prowess as you put on the gloves.");
        if(env) tell_room(env, who->GetName()+" wears "+
          GetShort()+".", ({who}));
        
        who->AddSkillBonus("melee attack", 2);
        x=who->GetSkillLevel("melee attack");
        who->eventPrint("Melee attack after skill bonus = "+x+".");  
      
        return 1;
    

    }

    else {
        who->eventPrint("You cannot seem to get your hands in "+

            "the gloves.");
        x=who->GetSkillLevel("melee attack");
        who->eventPrint("Melee attack not wearing gloves = "+x+".");  
        return 0;

    }
    
      
}

mixed eventUnequip(){
   int x;
   this_player()->RemoveSkillBonus("melee attack");
   armor::eventUnequip(this_player());
   x=this_player()->GetSkillLevel("melee attack");
   this_player()->eventPrint("Melee attack bonus is now "+x+".");

}

Essentially, this tells the player what his melee attack value is before and after wearing the gloves and after removing them. There's no stacking and no delay in bonus removal.