Advertisement
ZoriaRPG

Anti-Faerie Magic Powder

Aug 26th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.26 KB | None | 0 0
  1. //Saffith, Antifairy
  2.  
  3. // import "std.zh"
  4. // import "string.zh"
  5. // import "ghost.zh"
  6.  
  7. // npc->Attributes[] indices
  8. const int WB_ATTR_TILE_WIDTH        = 2;
  9. const int WB_ATTR_TILE_HEIGHT       = 3;
  10. const int WB_ATTR_IGNORE_WATER      = 4;
  11. const int WB_ATTR_IGNORE_PITS       = 5;
  12.  
  13. //Magic powder settings.
  14. const int WEAP_MAGIC_POWDER_SPRITE  = 60; //Set this to the sprite ID that you wish to use.
  15. const int WEAP_MAGIC_POWDER_DIST    = 4; //The distance away from Link to create the weapon.
  16. const int WEAP_MAGIC_POWDER_MISC_INDEX  = 1; //The misc index to use for lweapon flag storage.
  17. const int WEAP_MAGIC_POWDER_MISC_FLAG   = 000100b; //The flag for the magic powder.
  18. const int SFX_MAGICDUST         = 63; //Sound for the Magic Powder
  19.  
  20. //The size of Link's sprite.
  21. const int WEAP_MAGIC_POWDER_LINK_TILEHEIGHT = 16;
  22. const int WEAP_MAGIC_POWDER_LINK_TILEWIDTH = 16;
  23.  
  24. item script MagicPowder
  25. {
  26.     void run()
  27.     {
  28. c       //Magic powder is a sparkle-class weapon, so we are using a flag to (later) compare for it.
  29.         Link->Action = LA_ATTACKING;
  30.         lweapon dust = Screen->CreateLWeapon(LW_SPARKLE);
  31.         if ( Link->Dir == DIR_UP )
  32.         {
  33.             dust->HitXOffset = 0; dust->HitYOffset = 0; dust->DrawXOffset = 0; dust->DrawYOffset = 0;
  34.             dust->X = Link->X;
  35.             dust->Y = (Link->Y - (WEAP_MAGIC_POWDER_LINK_TILEHEIGHT/2) - WEAP_MAGIC_POWDER_DIST);
  36.         }
  37.         else if ( Link->Dir == DIR_DOWN )
  38.         {
  39.             dust->HitXOffset = 0; dust->HitYOffset = 0; dust->DrawXOffset = 0; dust->DrawYOffset = 0;
  40.             dust->X = Link->X;
  41.             dust->Y = (Link->Y + (WEAP_MAGIC_POWDER_LINK_TILEHEIGHT/2) + WEAP_MAGIC_POWDER_DIST);
  42.         }
  43.         else if ( Link->Dir == DIR_LEFT )
  44.         {
  45.             dust->HitXOffset = 0; dust->HitYOffset = 0; dust->DrawXOffset = 0; dust->DrawYOffset = 0;
  46.             dust->X = (Link->X - (WEAP_MAGIC_POWDER_LINK_TILEWIDTH/2) - WEAP_MAGIC_POWDER_DIST);
  47.             dust->Y = Link->Y;
  48.         }
  49.         else if ( Link->Dir == DIR_RIGHT )
  50.         {
  51.             dust->HitXOffset = 0; dust->HitYOffset = 0; dust->DrawXOffset = 0; dust->DrawYOffset = 0;
  52.             dust->X = (Link->X + (WEAP_MAGIC_POWDER_LINK_TILEWIDTH/2) + WEAP_MAGIC_POWDER_DIST);
  53.             dust->Y = Link->Y;
  54.         }
  55.         else //default
  56.         {
  57.             dust->X = Link->X; dust->Y = Link->Y;
  58.         }
  59.         dust->UseSprite(WEAP_MAGIC_POWDER_SPRITE);
  60.         dust->Misc[WEAP_MAGIC_POWDER_MISC_INDEX] |= WEAP_MAGIC_POWDER_MISC_FLAG;
  61.         Game->PlaySound(SFX_MAGICDUST);
  62.     }
  63. }
  64.    
  65.  
  66. ffc script AntiFairy //Changing the script name, for this application.
  67. {
  68.     void run(int enemyID)
  69.     {
  70.         npc ghost;
  71.         int flags;
  72.         int angle;
  73.         float step;
  74.         float xStep;
  75.         float yStep;
  76.        
  77.         // Initialize
  78.         ghost=Ghost_InitAutoGhost(this, enemyID, GHF_NO_FALL);
  79.         Ghost_TileWidth=Ghost_GetAttribute(ghost, WB_ATTR_TILE_WIDTH, 1, 1, 4);
  80.         Ghost_TileHeight=Ghost_GetAttribute(ghost, WB_ATTR_TILE_HEIGHT, 1, 1, 4);
  81.         Ghost_SpawnAnimationPuff(this, ghost);
  82.        
  83.         // Set flags
  84.         flags=GHF_STUN|GHF_CLOCK;
  85.         if(ghost->Attributes[WB_ATTR_IGNORE_WATER]>0)
  86.             flags|=GHF_IGNORE_WATER;
  87.         if(ghost->Attributes[WB_ATTR_IGNORE_PITS]>0)
  88.             flags|=GHF_IGNORE_PITS;
  89.         Ghost_SetFlags(flags);
  90.        
  91.         // Get initial movement
  92.         angle=45+90*Rand(4);
  93.         step=ghost->Step/100;
  94.         ghost->Step=0; // In case it's a walker
  95.        
  96.         xStep=step*Cos(angle);
  97.         yStep=step*Sin(angle);
  98.     int become_faerie; //Using a simple var now, because the array indices were extraneous, and this is faster in run-time.
  99.        
  100.         while(true)
  101.         {
  102.             // Bounce
  103.             if(xStep<0)
  104.             {
  105.                 if(!Ghost_CanMove(DIR_LEFT, -xStep, 3))
  106.                    xStep*=-1;
  107.             }
  108.             else
  109.             {
  110.                 if(!Ghost_CanMove(DIR_RIGHT, xStep, 3))
  111.                    xStep*=-1;
  112.             }
  113.            
  114.             if(yStep<0)
  115.             {
  116.                 if(!Ghost_CanMove(DIR_UP, -yStep, 3))
  117.                    yStep*=-1;
  118.             }
  119.             else
  120.             {
  121.                 if(!Ghost_CanMove(DIR_DOWN, yStep, 3))
  122.                    yStep*=-1;
  123.             }
  124.            
  125.             // And move
  126.        
  127.         //Check for 'Magic Power' interaction:
  128.         for ( int q = Screen->NumLWeapons(); q > 0; --q )
  129.         {
  130.             lweapon lw = Screen->LoadLWeapon(q);
  131.             if ( lw->ID != LW_SPARKLE ) { continue; }
  132.             if ( lw->Misc[WEAP_MAGIC_POWDER_MISC_INDEX]&WEAP_MAGIC_POWDER_MISC_FLAG ) //matches against the magic powder flag set from the item script
  133.             {
  134.             if ( Collision(lw, this) ) { become_faerie = 1; break; }
  135.             if ( Collision(lw, ghost) ) { become_faerie = 1; break; }
  136.             }
  137.         }
  138.        
  139.         //Transformation
  140.         if ( become_faerie )
  141.         {
  142.             item fairy = Screen->CreateItem(I_FAIRY);
  143.             fairy->X = ghost->X; //These do not need to be array indices. Changing them to use the base struct members. -Z
  144.             fairy->Y = ghost->Y;
  145.             ___kill(this,ghost);
  146.            
  147.         }
  148.             Ghost_MoveXY(xStep, yStep, 3);
  149.             Ghost_Waitframe(this, ghost, true, true);
  150.         }
  151.     }
  152.     //Kills a ghosted enemy.
  153.     void ___kill(ffc a, npc b)
  154.     {
  155.         ___kill(a); ___kill(b);
  156.         Quit();
  157.     }
  158.     //Kills any npc, with no death effect.
  159.     void ___kill(npc n)
  160.     {
  161.         n->HP = HP_SILENT;
  162.         Remove(n);
  163.     }
  164.     //Clears an ffc to default system params. Note that ffc->Link was broken prior to 2.53,
  165.     //and it is not possible for a script to set *its own* script ID to 0.
  166.     void ___kill(ffc f)
  167.     {
  168.     f->Data = 0;
  169.     f->Script = 0; //This will only work if ___kill(ffc) is called from another script.  
  170.         //e.g., AntiFairy.___kill(ffc)
  171.     f->CSet = 0;
  172.     f->Delay = 0;
  173.     f->X = 0;
  174.     f->Y = 0;
  175.     f->Vx = 0;
  176.     f->Vy = 0;
  177.     f->Ax = 0;
  178.     f->Ay = 0;
  179.     f->TileWidth = 1;
  180.     f->TileHeight = 1;
  181.     f->EffectWidth = 16;
  182.     f->EffectHeight = 16;
  183.     f->Link = 0;
  184.     for ( int q = 0; q <= 15; q++ ) f->Misc[q] = 0;
  185.     for ( int q = 0; q <= 10; q++ ) f->Flags[q] = false;
  186.    
  187.     }
  188.    
  189. }
  190.  
  191. /*
  192. This will work with walking enemies so you can use their touch effects. Other attributes won't work normally.
  193.  
  194. Attribute 3 (Death Attr. 1): Tile width (1-4, default 1)
  195. Attribute 4 (Death Attr. 2): Tile Height (1-4, default 1)
  196. Attribute 5 (Death Attr. 3): Move over water (0: no, 1: yes)
  197. Attribute 6 (Extra Shots): Move over direct warps (0: no, 1: yes)
  198. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement