AIP conditions

Tools for osRose and osiRose will be placed in here, as well as Rose file formats.

Please PM rl2171 or lmame to get them added to the list.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

AIP conditions

Postby PurpleYouko on Wed May 29, 2019 7:30 pm

I have recently seen people asking about AIP formats so I thought I would bring you all up to date on what I have discovered about how to implement them while working on project 137 files which as you may or may not be aware, includes a full set of source code for client and server from a somewhat old version of evo rose.

I have converted my code into a mix of c++ and pseudo-code and will be including one condition along with explanations as to what is required to implement it per post.

To start things off here is the very simplest one of all.
Condition 000
  1. AIP_COND_000   
  2.     //Never used
  3.     return AI_FAILURE


As you can see, It is never used in any AIP file so basically we just return failure and forget about it

AI_FAILURE is not equal to returning false in the server. It actually has a real value defined as follows

AI_SUCCESS = 7
AI_FAILURE = 8

There is no really valid reason why it's done this way. It just is and it's way too much work to recode the whole thing to use true/false so it is what it is.

NEXT....

AI_COND_001
  1. AIP_COND_001
  2.     //Checks if the Entity has dealt or recieved damage greater than iDamage
  3.     uint32  iDamage         //Byte 0
  4.     uint8   cRecvOrGive     //Byte 4
  5.  
  6.     if( cRecvOrGive == 0 )  //received damage
  7.         if( entity->damagerecieved > iDamage )
  8.             return AI_SUCCESS;
  9.     else                    //dealt damage
  10.         if( entity->damagedealt > iDamage )
  11.             return AI_SUCCESS
  12.     //Default   
  13.     return AI_FAILURE


Pretty easy. Just checks if the entity has dealt or received damage and if so is it greater than iDamage as read in from position 0 in the byte array
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 7:46 pm

AI_COND_002

  1. //Check Near (1)
  2. //  Count how many allied monsters (same team) near me with within a specified level range
  3. //  Also returns and stores NearChar and FindChar for this monster
  4. AIP_COND_002
  5.     //count how many aiobj between nLevelDiff and nLevelDiff2 who is btIsAllied within iDistance
  6.     //must be >= wChrNum
  7.     uint32 iDistance        //Byte 0
  8.     uint8 btIsAllied        //Byte 4
  9.     uint16 nLevelDiff       //0xffff - Byte 6
  10.     uint16 nLevelDiff2      //Byte 8
  11.     uint16 wChrNum          //Byte 10
  12.     uint32 chrCount = 0
  13.     uint32 eCount = 0
  14.     uint32 checkDistance = 0
  15.     uint32 nearestDistance = 9999999
  16.     CMap* map = GServer->MapList.Index[entity->Position->Map];
  17.     vector <CCharacter*> entityList = map->NearList ( entity, iDistance, entity->Position->current )    //creates a filtered list of entities less than iDistance away
  18.     uint32 entityCount = entityList.size ( )
  19.  
  20.     // Scan the list of entities to find ones that meet the criteria
  21.     for (uint16 j = 0; j < entityList.size(); j++)
  22.         eCount++;
  23.         if ( btIsAllied == ( other->team == entity->team ) )    //other is a member of my own team?
  24.             if ( other->Stats->Level >= ( entity->Stats->Level - nLevelDiff ) && other->Stats->Level <= ( entity->Stats->Level + nLevelDiff2 ) )
  25.                 checkDistance = (int)Rose::Math::Distance( other->Position->current, entity->Position->current );   //
  26.                 if (checkDistance > iDistance) continue
  27.                 chrCount++              //increment the counter
  28.                 if (checkDistance < nearestDistance)
  29.                     nearestDistance = checkDistance         // other is now the nearest
  30.                     entity->nearChar = other->clientid      // Set the global nearChar variable to point to other
  31.                 if (chrCount >= wChrNum)                    // found enough allies so return success
  32.                     entity->findChar = other->clientid      // Set the global findChar variable to point to other
  33.                     return AI_SUCCESS;
  34.     return AI_FAILURE


This one is a lot more complicated
It specifically counts Allied entities (players and monsters and NPCs) within a specific distance (defined by iDistance which is found at byte 0 in the data array of the AIP file) of the currently focused monster or NPC
When it finds the nearest Allied entity is sets a value equal to the identity of this entity in the subject entity's entity->nearChar variable. This variable will continue to hold this value to be used in later actions.
The function also sets entity->findChar. When it reaches the specified count of allys, the very last one will be remembered in this variable until set elsewhere.

What do we mean by Ally?
This means any other entity that is on the same team as the currently focused entity.
Examples of an Ally would include....
Another summon owned by my owner
Another summon owned by a player in the same party as my owner
All summons owned by clan members while in clan fields
All monsters defined as being on a specified team in special events.

Teams and allies are not well supported in standard osrose server files. The whole system will need to be overhauled in order to make this function properly

Finally the EntityList vector is something that is not supported by anything outside of project 137.
It is basically a class that contains built in filters so that simply creating such an entitylist will automatically populate it from the values passed in during creation.
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 7:51 pm

AI_COND_003

  1. //Check Distance from my spawn point. true if more than data->iDistance(defined in AIP file)
  2. AIP_COND_003
  3.     uint32 iDistance        // Byte 0
  4.     uint32 moveDistance     // calculate distance away from spawn point
  5.     if ( moveDistance > iDistance )
  6.         return AI_SUCCESS
  7.     return AI_FAILURE


Pretty easy
The only code you will need to apply is to calculate the distance that the subject entity is from it's original spawnpoint.
Both current and spawn positions are available from the entity (monster) object
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 7:58 pm

AI_COND_004

  1. //Check Distance to my current target
  2. AIP_COND_004
  3.     uint32 iDistance        //Byte 0
  4.     uint8 cMoreLess         //Byte 4
  5.     CCharacter* target = entity->getCharTarget( )  //get current target
  6.     if( target == NULL )
  7.         return AI_FAILURE
  8.     uint32 moveDistance     // calculate distance to my current target
  9.     if ( cMoreLess == 0 )
  10.         if ( distance >= iDistance )
  11.             return AI_SUCCESS
  12.     else
  13.         if ( distance <= iDistance )
  14.             return AI_SUCCESS
  15.     return AI_FAILURE

Another nice simple one
It checks whether the current distance to the entitys current target is more or less than iDistance.
Standard osrose files do not contain the getCharTarget() function so that will need to be adapted a little
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 8:03 pm

AI_COND_005

  1. //Check Ability of my Target
  2. AIP_COND_005
  3.     uint8 cAbType       //Byte 0
  4.     uint32 iDiff        //Byte 4
  5.     uint8 cMoreLess     //Byte 8
  6.     CCharacter* target = entity->getCharTarget( )
  7.     if ( target == NULL )
  8.         return AI_FAILURE
  9.     // convert cAbType into a usable value from a lookup tanle
  10.     int value = AI_GetAbility ( target, cAbType )
  11.     if ( value < 0 )
  12.         return AI_FAILURE
  13.     if( cMoreLess == 0 )
  14.         if(value > iDiff)
  15.             return AI_SUCCESS
  16.     else
  17.         if(value < iDiff)
  18.             return AI_SUCCESS
  19.     return AI_FAILURE


So this one looks at an ability that the target entity has and compares it to a specified value.
It uses cAbType to return a value from this function
  1. int AI_GetAbility ( CCharacter* entity, uint8 btAbType )
  2. {
  3.     switch ( btAbType )
  4.     {
  5.         case 0:
  6.             return entity->Stats->Level;
  7.             break;
  8.         case 1:
  9.             return entity->Stats->AttackPower;
  10.             break;
  11.         case 2:
  12.             return entity->Stats->Defense;
  13.             break;
  14.         case 3:
  15.             return entity->Stats->MagicDefense;
  16.             break;
  17.         case 4:
  18.             return entity->Stats->HP;
  19.             break;
  20.         case 5:
  21.             return 0;
  22.             //Log(MSG_WARNING, "Don't have monsters charm yet...");
  23.             //return -1;
  24.             break;
  25.         default:
  26.             //Log(MSG_ERROR, "Unknown cAbType [%d]", btAbType);
  27.             return -1;
  28.             break;
  29.     }
  30. }

If it asks for Charm at any point we are screwed since monsters don't actually have that
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 8:06 pm

AI_COND_006

  1. //Check HP percentage
  2. AIP_COND_006
  3.     //Check if hp% (cMoreLess == 0 then >= else <=) wHP
  4.     uint32 wHP          //Byte 0
  5.     uint8 cMoreLess     //Byte 4
  6.     // find the percentage that current HP makes up of Max HP
  7.     uint32 value = (uint32)(((float)entity->Stats->HP/ (float)entity->Stats->MaxHP) * 100.0f)
  8.     if(cMoreLess == 0)  //Look for more than wHP
  9.         if(value >= wHP)
  10.             return AI_SUCCESS
  11.     else
  12.         if(value <= wHP) //Look for less than wHP
  13.             return AI_SUCCESS
  14.     return AI_FAILURE

This one takes the entitys current and maximum HP then calculates the percentage of MAXHP that it is currently at.
Then it checks if the percentage is more or less than the specified amount based on the value of wHP in the AIP file
I left the math in there for this one. It required a few type conversions before it would compile. lol
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 8:08 pm

AI_COND_007

  1. //Random Chance. Roll D100 and get lower than target to succeed
  2. AIP_COND_007
  3.     uint8 cPercent      //Byte 0
  4.     byte brand = rand()%100
  5.     if(brand <= cPercent)
  6.         return AI_SUCCESS
  7.     return AI_FAILURE


Roll those D100 percentile dice....
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 8:12 pm

AI_COND_008

  1. //Check Near allies within distance and specified level range of me. Sets nearchar and findchar to the first entity found within the set
  2. //There are actually no AIP examples of this in any of the clients that i have checked so it's all just based on SHO code
  3. AIP_COND_008
  4.     //find atleast 1 allied entity within specified level range and distance
  5.     uint32 iDistance        //Byte 0
  6.     uint16 nLevelDiff       //Byte 4                    // probably need to subtract from 65535 as we did in condition 002. Hard to tell without an actual example in AIP but there are none
  7.     uint16 nLevelDiff2      //Byte 6
  8.     uint8 btIsAllied        //Byte 8
  9.     CMap* map = GServer->MapList.Index[entity->Position->Map];
  10.     vector <CCharacter*> entityList = map->NearList ( entity, iDistance, entity->Position->current )
  11.     uint32 entityCount = entityList.size()
  12.     for (uint16 j = 0; j < entityList.size(); j++)
  13.         CCharacter* other = entityList.at ( j )
  14.         if ( btIsAllied == ( other->team == entity->team ) )
  15.             if ( other->Stats->Level  >= ( entity->Stats->Level - nLevelDiff ) && other->Stats->Level  <= ( entity->Stats->Level + nLevelDiff2) )
  16.                 checkDistance = (int)Rose::Math::Distance(other->Position->current, entity->Position->current )
  17.                 if ( checkDistance < iDistance)
  18.                     entity->nearChar = other->clientid
  19.                     entity->findChar = other->clientid
  20.                     return true
  21.     return AI_FAILURE


Another of these entitys in range things.
This one finds allied entities with a set distance and within a specified level range.
It updates both findChar and nearChar
It differs from AI_COND_002 in one way. It doesn't have a variable to define the minimum number of entities. It can return true with only 1

Strangely this function is never called in any AIP file that I have ever parsed (And that is a hell of a lot of them since I have a tool that can parse all the AIP files out of a client in one go)
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 8:15 pm

AI_COND_009

  1. //check target
  2. //Compare my target with my Attacker. TRUE if they are different
  3. //i.e. I just got hit by an entity who is NOT my target
  4. AIP_COND_009
  5.     CCharacter* target = entity->getCharTarget( )       //Get my current target
  6.     if(target == NULL)                                  //Don't have a target so return fail
  7.         return AI_FAILURE
  8.     CCharacter* attacker = entity->getCharAttacker( )   //Get my current attacker
  9.     if(attacker == NULL)                                //Don't have a current attacker so return fail
  10.         return AI_FAILURE
  11.     if(target != attacker)                              //Target = Attacker so return success
  12.         return AI_SUCCESS
  13.     return AI_FAILURE;                                  //If we make it this far we definitely failed

Pretty self explanitory.
Does require a function to find the last enemy that hit the entity though.
entity->getCharAttacker( )
I don't remember if bog standard osrose has that capability.
If you don't have that capability built into whatever server you are using, you are going to need it.
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP conditions

Postby PurpleYouko on Wed May 29, 2019 8:17 pm

AI_COND_010

YAY Double figures at last

  1. //Compare my target's and my attacker's ability
  2. AIP_COND_010
  3.     uint8 cAbType       //Byte 0
  4.     uint8 cMoreLess     //Byte 1
  5.     string ability = AI_GetAbilityName(cAbType)         //lookup table
  6.     CCharacter* target = entity->getCharTarget( )       //Get my current target
  7.     if(target == NULL)                                  //Don't have a target. Returnfailure
  8.         return AI_FAILURE
  9.     CCharacter* attacker = entity->getCharAttacker( )   //Get my current attacker
  10.     if(attacker == NULL)                                //Don't have an attacker. Return failure
  11.         return AI_FAILURE
  12.     int AttackerValue = AI_GetAbility(entity, cAbType)  //Get attackers abilty
  13.     int TargetValue = AI_GetAbility(target, cAbType)    //Get target's ability
  14.     if(cMoreLess == 0)                                  //Look for atttacker greater
  15.         if(AttackerValue > TargetValue)
  16.             return AI_SUCCESS
  17.     else                                                //Look for target greater
  18.         if(AttackerValue < TargetValue)
  19.             return AI_SUCCESS
  20.     return AI_FAILURE                                   //If we make it this far we definitely failed

And we are back to checking abilitys again
This time we need to first find the last enemy that attacked us and the current enemy that we are attacking then get the defined ability value for both and finally compare them against each other

Is my attackers HP greater than my current targets level?
I really couldn't care one way or the other but this function is able to check that if you so desire
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4692
Joined: Fri Aug 10, 2007 2:05 pm

Next

Return to Tools and File Format

Who is online

Users browsing this forum: No registered users and 0 guests

cron