AIP Actions

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

Re: AIP Actions

Postby PurpleYouko on Thu May 30, 2019 8:33 pm

AIP_REWD_010

  1. //Spawn Monster at my current location
  2. AIP_REWD_010
  3.     uint16 wMonster         //Byte 0
  4.     CMap* map = GServer->MapList.Index[entity->Position->Map]                   //Get the map
  5.     fPoint position = Rose::Math::RandInCircle( entity->Position->current, 1 )  //Select a random location in a circle around me with radius 1
  6.     map->AddMonster( wMonster, position, 0)                                     // Spawn the monster
  7.     return AI_SUCCESS


Basic bog standard monster spawn.
Creates a monster of type wMonster in a 1m circle around the entity
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Thu May 30, 2019 8:47 pm

AIP_REWD_011

  1. //Call for backup
  2. //force iNumOfMonster of same team within iDistance to attack my target
  3. AIP_REWD_011
  4.     uint32 iDistance            //Byte 0
  5.     uint32 iNumberOfMonsters    //Byte 4
  6.    
  7.     CCharacter* target = entity->getCharTarget( )       //get my current target
  8.     if ( target == NULL )       //If target does not exist then return without doing anything
  9.         return AI_SUCCESS
  10.     //Set up a couple of counters
  11.     int chrCount = 0
  12.     dword eCount = 0
  13.  
  14.     CMap* map = GServer->MapList.Index[entity->Position->Map]   //get the current map
  15.     for(uint32 j = 0; j < map->MonsterList.size(); j++)         //Scan the monsterlist in this map for allied monsters.    
  16.         CMonster* other = map->MonsterList.at(j)                //cast "other" as a monster from the list
  17.         if(other == NULL) continue                              //if "other" doesn't exist move on
  18.         eCount++                                                //Increment a counter to keep track
  19.         if(other == entity) continue                            //OOPs that monster is me. better ignore it
  20.         if ( other->team != entity->team ) continue             //Not on my team so can't influence its actions
  21.         // if we got to this point then the monster must be on my team
  22.         int iDistance = (int)Rose::Math::Distance( other->Position->current, entity->Position->current ) //How far away is it?
  23.         if(iDistance > iDistance) continue                      //Too far. move on to the next one
  24.         chrCount++;                                             //OK this one is a keeper so increment counter
  25.         if ( !other->Status->isTaunted)                         //Better make sure it isn't currently taunted
  26.             other->CurrentAction->targetID = entity->CurrentAction->targetID    //Set its target to match mine
  27.             other->StartAction( target )                        //Initialize combat with new target
  28.         if(chrCount >= iNumberOfMonsters) return AI_SUCCESS     //Stop recruiting monsters if we reach the limit
  29.     return AI_SUCCESS


This one checks for all allied monsters within radius iDistance and forces them to switch targets to MY target. HAHA. My buddies are coming to the rescue.
Can't make a monster change targets if it is currently under the influence of a TAUNT from another player though
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Thu May 30, 2019 8:52 pm

AIP_REWD_012

  1. //start attack. Run and attack "nearChar" Character found from conditions
  2. AIP_REWD_012
  3.     CCharacter* target = GServer->GetClientByID ( entity->nearChar, entity->Position->Map ) //Get my target
  4.     if ( target == NULL )                                       //Doesn't exist so return
  5.         return AI_SUCCESS
  6.     entity->thisnpc->stance = 1                                 //Set stance to run
  7.     if ( !entity->Status->isTaunted)                            //I'm not currently taunted so i can attack
  8.         entity->CurrentAction->targetID = entity->nearChar      //Set target to "nearChar" which we set earlier in conditions
  9.         entity->StartAction ( target )                          //Start attacking it
  10.     else                                                        //Guess i was taunted by somebody else so i can't attack nearChar
  11.         return AI_SUCCESS
  12.     return AI_SUCCESS


Initiate attack against "nearChar" who we found earlier in conditions
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Fri May 31, 2019 5:12 pm

AIP_REWD_013

  1. //start attack. Run and attack "findChar" Character found from conditions
  2. AIP_REWD_013
  3.     CCharacter* target = GServer->GetClientByID ( entity->findChar, entity->Position->Map )     //Get target (findChar)
  4.     if ( target == NULL )                                       //Doesn't exist so return
  5.         return AI_SUCCESS
  6.     entity->thisnpc->stance = 1                                 //Set stance to run
  7.     if ( !entity->Status->isTaunted)                            //NOT Taunted, so we are free to change the target
  8.         entity->CurrentAction->targetID = target->clientid      //Set target in CurrentAction (Battle equivalent)
  9.         entity->StartAction( target )                           //Start the attack
  10.     else                                                        //Guess i was taunted by somebody else so i can't attack findChar
  11.         return AI_SUCCESS
  12.     return AI_SUCCESS


Another attack initializer
The only difference between this one and AIP_REWD_012 is that 12 attacked nearChar and 13 attacks findChar
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Fri May 31, 2019 5:38 pm

AIP_REWD_014

  1. // Start attack. Run and attack FindChar but only if it is still in range
  2. AIP_REWD_014
  3.     CCharacter* target = GServer->GetClientByID ( entity->findChar, entity->Position->Map )     //get Target (findChar)
  4.     if ( target == NULL )                                       //Doesn't exist so return
  5.         return AI_SUCCESS
  6.     uint32 iDistance                                            //Byte 0
  7.     uint32 iDist = ( int ) Rose::Math::Distance ( target->Position->current, entity->Position->current ) //Calculate distance to target
  8.     if ( iDist > iDistance )                                    //Too far away. return success
  9.         return AI_SUCCESS
  10.     entity->thisnpc->stance = 1                                 //Set stance to run
  11.     if ( !entity->Status->isTaunted)                            // NOT Taunted, so we are free to change the target
  12.         entity->CurrentAction->targetID = target->clientid
  13.         entity->StartAction( target )                           //Start the attack
  14.     else                                                        //Guess i was taunted by somebody else so i can't attack findChar
  15.         return AI_SUCCESS
  16.     return AI_SUCCESS


Another attack starter.
Exactly the same as 13 except for one small difference.
This time we have to be within a specified range of the target before the attack can be started.

In the SHO server it's a little bit more complex since it uses a dynamic finder routine rather than the saved version of findChar

Effectively it runs and attack the first available enemy within the specified distance then checks stuff like taunt and if any check fails then it iterates the whole process and moves on to the next enemy.
I have not got around to fixing this function fully yet but I will at some point. For now my code just uses the saved findChar value
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Fri May 31, 2019 5:44 pm

AIP_REWD_015

  1. //Retaliate against the last character that hit me
  2. AIP_REWD_015
  3.     entity->thisnpc->stance = 1                                 //Set run mode
  4.     if ( !entity->Status->isTaunted)                            //NOT Taunted, so we are free to change the target
  5.         entity->CurrentAction->targetID = entity->CurrentAction->LastHitBy //select the last enemy who hit me and set it as my target
  6.     else                                                        //Guess I am still taunted by somebody else so can't do anything
  7.         return AI_SUCCESS
  8.     CCharacter* target = entity->CurrentAction->getLastHitBy()  //Get the actual enemy that hit me
  9.     if(target == NULL)                                          //Doesn't exist so return
  10.         return AI_SUCCESS
  11.     entity->StartAction( target )                               //Attack it
  12.     return AI_SUCCESS


Run and attack the last enemy who hit me.
This will usually only be done after some pretty extensive checks and random chances in the conditions section or else the monster would change targets all the time.
It is the code that is responsible for making any monster retaliate against a player when they are first hit
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Fri May 31, 2019 5:50 pm

AIP_REWD_016

  1. //Run away
  2. AIP_REWD_016
  3.     uint32 iDistance        //Byte 0
  4.                             //First some math to set up the position that we will run away to
  5.     float32 radius = (float) iDistance
  6.     float32 angle = rand()%(360)
  7.     float32 nX = ( entity->Position->source.x + ( radius * cos( angle )))
  8.     entity->Position->destiny.x = nX
  9.     float32 nY = ( entity->Position->source.y + ( radius * cos( angle )))
  10.     entity->Position->destiny.y = nY
  11.     entity->thisnpc->stance = 1                     //Set run mode
  12.     entity->CurrentAction->ActionType = SkillType::NO_ACTION //set skillType to 0 just in case we had one queued up
  13.     CPacket pak ( 0x0797 )                          //Initialize movement packet
  14.     pak.addUINT16( entity->clientid );              //my id
  15.     pak.addUINT16( 0x0000 );                        //Destination char id. This packet can be used to move to another entity's position
  16.     pak.addUINT16 ( entity->Stats->MoveSpeed )      //PY This is wrong. This should be distance to the target char if it exists. Same for every instance of 797 packet. Come back to this later
  17.     pak.addFloat32( entity->Position->destiny.x * 100 ) //Destination position X
  18.     pak.addFloat32( entity->Position->destiny.y * 100 ) //Destination position Y
  19.     pak.addUINT16 ( 0xcdcd )                        //This is a useless placeholder but if you leave it out it all goes Blehhh. Technically it is the Z position but that isn't actually used so...
  20.     pak.addUINT8( entity->thisnpc->stance )         //Walk, run or whatever. I'm sure you get that by now
  21.     GServer->SendToVisible(&pak, entity)
  22.     return AI_SUCCESS


Sometimes the entity will just want to get the hell away from the fight.
That's what this function does.
The entity will run away for a distance of iDistance in a random direction
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Fri May 31, 2019 6:16 pm

AIP_REWD_017

  1. //Drop Item
  2. AIP_REWD_017 ( CMonster* entity, uint8* raw, bool logme )
  3.     //Random drop one of item 1-5
  4.     uint16 items [ 5 ];
  5.     items [ 0 ]         //Byte 0
  6.     items [ 1 ]         //Byte 2
  7.     items [ 2 ]         //Byte 4
  8.     items [ 3 ]         //Byte 6
  9.     items [ 4 ]         //Byte 8
  10.     uint8 iToOwner      //Byte 12
  11.  
  12.     int itemRand = Rose::Support::Random ( 0, 4 )       //Random number 0 ~ 4
  13.     int nItem = items[ itemRand ];                      //Select item from the array that we just populated with those 5 shorts that we just got from the AIP data
  14.     if ( nItem == 0 )                                   //Awwww... It's an invlid item
  15.         return AI_SUCCESS
  16.                                                         //Get item type and ID from the item number
  17.     uint16 itemType =   Rose::Support::ParseItemCode ( nItem, Rose::Support::ParserOptions::ItemType )
  18.     uint16 itemNumber = Rose::Support::ParseItemCode ( nItem, Rose::Support::ParserOptions::ItemID )
  19.     CGameItem* monItem = GameData->Item ( itemType, itemNumber )    //create the Gameitem object in a temporary format
  20.     CItem newItem;                                                  //create an empty CItem holder
  21.     if ( !monItem->isValid ( ) )                                    //Awwwww.. After all that the item number was invalid
  22.         return AI_SUCCESS
  23.     monItem->Clone ( &newItem )                                     //Clone the temporary GameItem into the memory space of the CItem object
  24.     CDrop* thisdrop = new CDrop;        assert ( thisdrop )         //Create the item as a drop
  25.     thisdrop->clientid = IDPool->Obtain ( )                         //Obtain a clientID for it
  26.     thisdrop->type = 2;                                             //ITEM as opposed to Zuly
  27.     thisdrop->pos = Rose::Math::RandInCircle ( entity->Position->current, 3 ) //Randomize the new drops position in a circle
  28.     thisdrop->posMap = entity->Position->Map                        //Get the current map
  29.     thisdrop->droptime = time ( NULL )                              //Set the drop time
  30.     thisdrop->amount = 1                                            //Set number of items to 1
  31.     if ( iToOwner == 1 )
  32.         thisdrop->owner = entity->MonsterDrop->firsthit             //Standard drop
  33.     else
  34.         thisdrop->owner = 0                                         //Anybody can pick it up
  35.     thisdrop->thisparty = 0                                         //Party drop setting (non standard osrose)
  36.  
  37.     if(!thisdrop->item.isStackable())                               //finish setting up the drop
  38.         thisdrop->item.stats      = 0
  39.         thisdrop->item.durability = 40
  40.         thisdrop->item.lifespan   = 100
  41.         thisdrop->item.socketed   = 0
  42.         thisdrop->item.appraised  = 1
  43.         thisdrop->item.refine     = 0
  44.     thisdrop->item.count = 1
  45.     CMap* map = GServer->MapList.Index[ thisdrop->posMap]           //set the map for teh drop
  46.     map->AddDrop( thisdrop )                                        //Add the drop to this map
  47.     return AI_SUCCESS


This one drops an item
The AIP file always contains a list of 5 items although in many cases they are all the same
This code selects one of those items and drops it to the current map where it will either be owned by the first hitter (standard drop) or free for all depending on the toOwner setting in the AIP file

A lot of this code will be incompatible with standard osrose since in project 137 we have a lot of new methods for safely validating items before throwing potentially risky objects into the world where they could cause crashes
The actual functionality of AIP_REWD_017 is pretty basic though so it can easily be adapted to any code base
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Fri May 31, 2019 6:26 pm

AIP_REWD_018

  1. //Make nearby monsters attack my target
  2. AIP_REWD_018
  3.     uint16 cMonster         //Byte 0
  4.     uint16 wHowMany         //Byte 2
  5.     uint32 iDistance        //Byte 4
  6.     //make wHowMany monsters of type cMonster within iDistance attack my target
  7.     CMap* map = GServer->MapList.Index[entity->Position->Map]   //Get the current map
  8.     CCharacter* target = entity->getCharTarget( )               //Get my current target
  9.     if(target == NULL)
  10.         return AI_SUCCESS
  11.     int monstercount = 0                                        //Initialize counter
  12.     for(UINT j=0;j<map->MonsterList.size();j++)                 //Scan the monsterlist of this map
  13.         CMonster* othermon = map->MonsterList.at(j)             //cast a temporary monster
  14.         if(othermon == NULL)                                    //Doesn't exist so skip this one
  15.             continue
  16.         if(othermon == entity )                                 //OOPS it's me. skip
  17.             continue
  18.         if(othermon->montype != cMonster)                       //Wrong type of monster. skip
  19.             continue
  20.         if(GServer->IsMonInCircle( entity->Position->current, othermon->Position->current, iDistance))  //is it in range?
  21.             if( !othermon->Status->isTaunted)                   //Othermon NOT taunted so allow it to change target
  22.                 othermon->StartAction( target )                 //set new target equal to my target
  23.                 monstercount++;                                 //increment counter
  24.             if(monstercount >= wHowMany)                        //OK that's enough. return now
  25.                 return AI_SUCCESS
  26.     return AI_SUCCESS


Looks at all the nearby monsters and forces some of them to attack my own target.
They have to be within range and they have to be the right kind of monster
eg. Force 23 Rackie Fighters within a range of 15 to attack my target
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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: AIP Actions

Postby PurpleYouko on Fri May 31, 2019 6:29 pm

AIP_REWD_019

For some reason that escapes me, this is an exact copy of AIP_REWD_012 so don't bother using it.
Seriously, the code in the SHO (arcturus) server is absolutely identical for both.
How lame is 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: 4733
Joined: Fri Aug 10, 2007 2:05 pm

PreviousNext

Return to Tools and File Format

Who is online

Users browsing this forum: No registered users and 23 guests

cron