How do you assign random properties to an item without a player?

I’ve been messing around with blipi’s patch for implementing the MaNGOS AHBot in Trinity. One of the issues I noticed with it is that any item that requires a random property/suffix for its bonuses doesn’t receive one. Notched Shortswords are just that, for example, and not Notched Shortswords of Stamina. I’ve tried direct assignation of the property, but that runs afoul of the assert on line 720 in item.ccp, the AddToUpdateQueueOf function. The issue is that Player is null. Is it possible to assign a random property id to an item without using SetItemRandomProperties which triggers the aforementioned problem function?

In order to make sure that the item properties weren’t showing up due to a deeper issue I worked on the matter some myself. I finally ended up importing some of the code from the old Trinity AHBot. Specifically the sections involving AHBplayer and generating a WorldSession using a pre-existing character. While this proved unstable, no doubt due to my inexperience and ignorance, it resulted in random property items being properly generated. Is there a better way of doing this? By a better way I mean something like creating a fake player strictly for the purpose of passing the ASSERT(player != NULL) without resulting in the server crashing along the way.

If neither is really possible at the moment then so be it, but it strikes me that unless there’s some overriding reason, a reason I would like to hear if it exists, not to there ought to be a better way of doing this than what I’ve got so far. I’ll be continuing to work with it to try and hammer out the stability issues, but I’d really prefer something cleaner and simpler.

There has been some discussion about making a fake player because of other issues that have been pointed out, but, I don’t know anything about the status of it. Long ago, I suggested creating some sort of fake player to make this and the Playerbots patch work better, and, also to make general bot creating easier, and have not taken the time to work on it lately, maybe I’ll get around to it…

Well, I figured out something workable with regards to the AHBot issue. This is what I ripped off from the old Trinity AHBot code, and the problem was I didn’t follow on to the next logical step in the code which was the subsequent, and necessary, sObjectAccessor->RemoveObject(&_AHBplayer); . /emoticons/default_dry.png

WorldSession _session(AHBaccount, NULL, SEC_PLAYER, true, 0, LOCALE_enUS, 0, 0); Player _AHBplayer(&_session); _AHBplayer.Initialize(AHBguid); sObjectAccessor->AddObject(&_AHBplayer);
The server doesn’t seem to have a problem with using that to create a player with an account/guid of 0 thereby allowing a “fake” player for the purpose of random property generation, though my first experience with it actually generated a guid of 3,452,816,845 which rather surprised me.

I’d still be interested in finding out if there are any ways to bypass the need for a player to generate the random properties though, but based on the fact that the old AHBot code didn’t do it I’m not going to hold my breath.

Just an update for anyone who might be interested in generating random properties for an item without having to deal with creating a temporary Player instance to accompany it. The problem, as noted in my OP, is that if you don’t do anything you’ll hit ASSERT(player != NULL); in an UpdateQueue function sooner or later. Edit: Everything else after this point was deleted due to the fix below being better.

item.cpp

[CODE]void Item::SetState(ItemUpdateState state, Player* forplayer)

{

if (uState == ITEM_NEW && state == ITEM_REMOVED)

{

    // pretend the item never existed
  •   if (forplayer || GetOwnerGUID())
    
  •   {
    
          RemoveFromUpdateQueueOf(forplayer);
    
          forplayer->DeleteRefundReference(GetGUIDLow());
    
  •   }
    
      delete this;
    
      return;
    

    }

    if (state != ITEM_UNCHANGED)

    {

      // new items must stay in new state until saved
    
      if (uState != ITEM_NEW)
    
          uState = state;
    
  •   if (forplayer || GetOwnerGUID())
    
          AddToUpdateQueueOf(forplayer);
    

    }

    else

    {

      // unset in queue
    
      // the item must be removed from the queue manually
    
      uQueuePos = -1;
    
      uState = ITEM_UNCHANGED;
    

    }

}[/CODE]