Advertisement
Venrob

Deku Stick Script [2.55]

Jun 10th, 2020
2,246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.14 KB | None | 0 0
  1. // Deku Stick Script
  2. #option SHORT_CIRCUIT on
  3. #option BINARY_32BIT off
  4.  
  5. typedef const int DEFINE; //Don't change DEFINE constants
  6. typedef const int CONFIG; //Change CONFIG constants however you like
  7. typedef const bool CONFIGB; //CONFIGB are only true/false
  8.  
  9. CONFIG LW_DEKUSTICK = LW_SCRIPT1;
  10. CONFIG CT_TORCH_UNLIT = CT_SCRIPT1;
  11. CONFIG CT_TORCH_LIT = CT_SCRIPT2;
  12. CONFIG DEFAULT_LIT_SECONDS = 20;
  13. CONFIG DEFAULT_TORCH_LIGHT_SFX = 0; //Default SFX if the unlit torch combo has none specified
  14. CONFIG MIN_STAB_FRAMES = 10; //A stab will last at least this many frames
  15. CONFIG TORCH_MAX_LAYER = 2;
  16.  
  17. CONFIG ENERGYBAR_WIDTH = 30; //1px border added to both sides
  18. CONFIG ENERGYBAR_HEIGHT = 6; //1px border added to both sides
  19. CONFIGB ENERGYBAR_RELATIVE_TO_PLAYER = true;
  20. CONFIG ENERGYBAR_X = -8; //If 'ENERGYBAR_RELATIVE_TO_PLAYER', this is an offset; otherwise it's absolute
  21. CONFIG ENERGYBAR_Y = -8; //If 'ENERGYBAR_RELATIVE_TO_PLAYER', this is an offset; otherwise it's absolute
  22. CONFIG ENERGYBAR_LAYER = 7;
  23. CONFIGB ENERGYBAR_ONLY_WHEN_DEKUSTICK_EQUIPPED = false; //Only show while stick is on A or B
  24.  
  25. CONFIG COLOR_ENERGYBAR_BORDER = 0x01;
  26. CONFIG COLOR_ENERGYBAR_FILLED = 0x05;
  27. CONFIG COLOR_ENERGYBAR_EMPTY = 0x0F;
  28.  
  29. untyped torch_data[TD_SZ];
  30. enum
  31. {
  32.     TD_TIMER, //Current timer for the torch
  33.     TD_MAX_TIMER, //Last amount the torch was lit for, for drawing the bar
  34.     TD_SCRIPTSLOT, //Script slot, stored in buffer
  35.     TD_WEAPSCRIPTSLOT, //Script slot, stored in buffer
  36.     TD_SZ
  37. };
  38.  
  39. /** start Combo setup instructions
  40.  * Torch Combos (Lit):
  41.  *     Type: CT_TORCH_LIT
  42.  *     Attribyte 1: Seconds for stick to be lit by torch. 0 to use default.
  43.  *
  44.  * Torch Combos (Unlit):
  45.  *     Type: CT_TORCH_UNLIT
  46.  *     Attribyte 1: SFX for lighting
  47.  *     The next combo in the combo list should be the lit combo
  48.  */
  49. //end Combo setup instructions
  50.  
  51. /**
  52.  * Sprite: 'Sprites[0]'
  53.  *         Up-facing, then right-facing. Will be flipped.
  54.  *         On fire tiles exactly one row below the normal tiles.
  55.  * Damage, and default weapon defense, are set in the editor.
  56.  */
  57. itemdata script DekuStick //start
  58. {
  59.     void run(int light_sfx) //start
  60.     {
  61.         int btn = (this->ID == GetEquipmentA()) ? CB_A : CB_B;
  62.         int cntr = 0;
  63.         bool held = true;
  64.         int dir = Hero->Dir;
  65.         bool lit = torch_data[TD_TIMER] > 0;
  66.         lweapon weap = CreateDekuStick(this, dir, lit);
  67.         Hero->Action = LA_ATTACKING;
  68.         Waitdraw();
  69.         while(true)
  70.         {
  71.             if(weap->isValid())
  72.             {
  73.                 weap->X = Hero->X;
  74.                 weap->Y = Hero->Y;
  75.                 checkTorchCombos(weap);
  76.                 if(lit ^^ torch_data[TD_TIMER] > 0)
  77.                 {
  78.                     lit = torch_data[TD_TIMER] > 0;
  79.                     if(lit) Audio->PlaySound(light_sfx);
  80.                     weap->OriginalTile += (lit ? 20 : -20);
  81.                     weap->Tile = weap->OriginalTile;
  82.                 }
  83.             }
  84.             stopQuickSwap();
  85.             Hero->Dir = dir;
  86.             Waitframe();
  87.             held = held && Input->Button[btn];
  88.             unless(++cntr < MIN_STAB_FRAMES || held)
  89.             {
  90.                 weap->Misc[0] = 0;
  91.                 Remove(weap);
  92.                 return;
  93.             }
  94.             unless(weap->isValid())
  95.             {
  96.                 weap = CreateDekuStick(this, dir, lit);
  97.             }
  98.             else if(weap->DeadState == WDS_DEAD)
  99.             {
  100.                 weap->Misc[0] = 0;
  101.                 Remove(weap);
  102.                 weap = CreateDekuStick(this, dir, lit);
  103.             }
  104.             Waitdraw();
  105.         }
  106.     } //end
  107.    
  108.     void checkTorchCombos(lweapon weap) //start
  109.     {
  110.         int x = weap->X + weap->HitXOffset;
  111.         int y = weap->Y + weap->HitYOffset;
  112.         int combos[4] = {ComboAt(x, y), ComboAt(x + 15, y),
  113.                         ComboAt(x, y + 15), ComboAt(x + 15, y + 15)};
  114.         if(x < 0 || x > 255)
  115.         {
  116.             combos[0] = -1;
  117.             combos[2] = -1;
  118.         }
  119.         if(x+15 < 0 || x+15 > 255)
  120.         {
  121.             combos[1] = -1;
  122.             combos[3] = -1;
  123.         }
  124.         if(y < 0 || y > 175)
  125.         {
  126.             combos[0] = -1;
  127.             combos[1] = -1;
  128.         }
  129.         if(y+15 < 0 || y+15 > 175)
  130.         {
  131.             combos[2] = -1;
  132.             combos[3] = -1;
  133.         }
  134.         for(int lyr = 0; lyr <= (TORCH_MAX_LAYER <= 6 ? TORCH_MAX_LAYER : 6); ++lyr)
  135.         {
  136.             mapdata md = Game->LoadTempScreen(lyr);
  137.             for(int q = 0; q < 4; ++q)
  138.             {
  139.                 if(combos[q] < 0) continue;
  140.                 combodata cd = Game->LoadComboData(md->ComboD[combos[q]]);
  141.                 switch(cd->Type)
  142.                 {
  143.                     case CT_TORCH_LIT:
  144.                     {
  145.                         int dur = cd->Attribytes[0];
  146.                         unless(dur) dur = DEFAULT_LIT_SECONDS;
  147.                         dur *= 60;
  148.                         if(torch_data[TD_TIMER] < dur)
  149.                         {
  150.                             torch_data[TD_TIMER] = dur;
  151.                             torch_data[TD_MAX_TIMER] = dur;
  152.                         }
  153.                         break;
  154.                     }
  155.                     case CT_TORCH_UNLIT:
  156.                     {
  157.                         if(torch_data[TD_TIMER])
  158.                         {
  159.                             ++md->ComboD[combos[q]];
  160.                             Audio->PlaySound(cd->Attribytes[0] ? cd->Attribytes[0] : DEFAULT_TORCH_LIGHT_SFX);
  161.                         }
  162.                         break;
  163.                     }
  164.                 }
  165.             }
  166.         }
  167.     } //end
  168.    
  169.     void stopQuickSwap() //start
  170.     {
  171.         unless(Game->FFRules[qr_NO_L_R_BUTTON_INVENTORY_SWAP])
  172.         {
  173.             Input->Press[CB_L] = false;
  174.             Input->Button[CB_L] = false;
  175.             Input->Press[CB_R] = false;
  176.             Input->Button[CB_R] = false;
  177.         }
  178.         if(Game->FFRules[qr_USE_EX1_EX2_INVENTORYSWAP])
  179.         {
  180.             Input->Press[CB_EX1] = false;
  181.             Input->Button[CB_EX1] = false;
  182.             Input->Press[CB_EX2] = false;
  183.             Input->Button[CB_EX2] = false;
  184.         }
  185.     } //end
  186.    
  187.     int WeapX(int dir)
  188.     {
  189.         switch(dir)
  190.         {
  191.             case DIR_UP: return -1;
  192.             case DIR_DOWN: return 1;
  193.             case DIR_LEFT: return -9;
  194.             default: case DIR_RIGHT: return 9;
  195.         }
  196.     }
  197.     int WeapY(int dir)
  198.     {
  199.         switch(dir)
  200.         {
  201.             case DIR_UP: return -6;
  202.             case DIR_DOWN: return 11;
  203.             case DIR_LEFT: return 3;
  204.             default: case DIR_RIGHT: return 3;
  205.         }
  206.     }
  207.     lweapon CreateDekuStick(itemdata id, int dir, bool lit)
  208.     {
  209.         lweapon weap = Screen->CreateLWeapon(LW_DEKUSTICK);
  210.         weap->UseSprite(id->Sprites[0]);
  211.         weap->Dir = Hero->Dir;
  212.         weap->Defense = id->Defense;
  213.         weap->Damage = id->Power * 2;
  214.         unless(weap->NumFrames) weap->NumFrames = 1;
  215.         weap->DrawXOffset = WeapX(dir);
  216.         weap->DrawYOffset = WeapY(dir);
  217.         weap->HitXOffset = weap->DrawXOffset;
  218.         weap->HitYOffset = weap->DrawYOffset;
  219.         switch(dir)
  220.         {
  221.             case DIR_DOWN: weap->Flip = FLIP_VERTICAL; break;
  222.             case DIR_LEFT: weap->Flip = FLIP_HORIZONTAL; //Fallthrough
  223.             case DIR_RIGHT: weap->OriginalTile += weap->NumFrames; break;
  224.         }
  225.         if(lit) weap->OriginalTile += 20;
  226.         weap->Tile = weap->OriginalTile;
  227.         weap->X = Hero->X;
  228.         weap->Y = Hero->Y;
  229.         weap->Script = torch_data[TD_WEAPSCRIPTSLOT];
  230.         return weap;
  231.     }
  232. } //end DekuStick
  233.  
  234. lweapon script undying_lw
  235. {
  236.     void run()
  237.     {
  238.         this->Misc[0] = 1;
  239.         while(this->Misc[0])
  240.         {
  241.             this->DeadState = WDS_ALIVE;
  242.             Waitframe();
  243.         }
  244.     }
  245. }
  246.  
  247. void DekuStick_Init()
  248. {
  249.     torch_data[TD_TIMER] = 0;
  250.     torch_data[TD_MAX_TIMER] = 0;
  251.     torch_data[TD_SCRIPTSLOT] = Game->GetItemScript("DekuStick");
  252.     torch_data[TD_WEAPSCRIPTSLOT] = Game->GetLWeaponScript("undying_lw");
  253. }
  254. void DekuStick_Update()
  255. {
  256.     if(torch_data[TD_TIMER] > 0)
  257.     {
  258.         --torch_data[TD_TIMER];
  259.         if(ENERGYBAR_ONLY_WHEN_DEKUSTICK_EQUIPPED)
  260.         {
  261.             itemdata a = Game->LoadItemData(GetEquipmentA());
  262.             itemdata b = Game->LoadItemData(GetEquipmentB());
  263.             unless(a->Script == torch_data[TD_SCRIPTSLOT] || b->Script == torch_data[TD_SCRIPTSLOT]) return;
  264.         }
  265.         int x = (ENERGYBAR_RELATIVE_TO_PLAYER ? Hero->X + Game->Scrolling[SCROLL_NX] : 0) + ENERGYBAR_X;
  266.         int y = (ENERGYBAR_RELATIVE_TO_PLAYER ? Hero->Y + Game->Scrolling[SCROLL_NY] : 0) + ENERGYBAR_Y;
  267.         float perc = torch_data[TD_TIMER] / torch_data[TD_MAX_TIMER];
  268.         int litwid = Ceiling(ENERGYBAR_WIDTH * perc);
  269.         Screen->Rectangle(ENERGYBAR_LAYER, x, y, x+ENERGYBAR_WIDTH+1, y+ENERGYBAR_HEIGHT+1, COLOR_ENERGYBAR_BORDER, 1, 0, 0, 0, true, OP_OPAQUE);
  270.         Screen->Rectangle(ENERGYBAR_LAYER, x+1, y+1, x+ENERGYBAR_WIDTH, y+ENERGYBAR_HEIGHT, COLOR_ENERGYBAR_EMPTY, 1, 0, 0, 0, true, OP_OPAQUE);
  271.         Screen->Rectangle(ENERGYBAR_LAYER, x+1, y+1, x+litwid, y+ENERGYBAR_HEIGHT, COLOR_ENERGYBAR_FILLED, 1, 0, 0, 0, true, OP_OPAQUE);
  272.     }
  273. }
  274.  
  275. global script ExampleDekuStickActive
  276. {
  277.     void run()
  278.     {
  279.         DekuStick_Init();
  280.         while(true)
  281.         {
  282.             Waitdraw();
  283.             DekuStick_Update();
  284.             Waitframe();
  285.         }
  286.     }
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement