Trying to run a add_action within a function to run a woocomerce function on a ajax request

I am able to get a ajax request to work properly on a woocommerce checkout form page, now I want to update the price of the checkout in that ajax request. My add_action is in the function that is fired by the ajax request.

This is all done in a custom plugin as well

Here is my code this far, it doesn’t seem like the function request_gift_card ever fires

 function gift_card_redeem(){      if(!empty($  _SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($  _SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {     error_log("test !empty");          add_action( 'woocommerce_before_calculate_totals', 'request_gift_card', 99 );      function request_gift_card($  cart_object){       if( !WC()->session->__isset( "reload_checkout" )) {           /* Gift wrap price */           $  additionalPrice = 5;           error_log($  cart_object);           foreach ( $  cart_object->cart_contents as $  key => $  value ) {               if( isset( $  value["embossing_fee"] ) ) {                   // Turn $  value['data']->price in to $  value['data']->get_price()                   $  orgPrice = floatval( $  value['data']->get_price() );                   $  discPrice = $  orgPrice + $  additionalPrice;                   $  value['data']->set_price($  discPrice);               }           }       }     }      $  result['type'] = "success";     $  result = json_encode($  result);     echo $  result;   }   else {     error_log("test else");       header("Location: ".$  _SERVER["HTTP_REFERER"]);   }    die(); } 

If your target has an enemy within 5ft, can you sneak attack without using a finesse or ranged weapon?

A rogue and fighter are engaged in melee combat with a goblin. The rogue is unarmed. Can the rogue activate Sneak Attack?

The rules for Sneak Attack state:

Beginning at 1st level, you know how to strike subtly and exploit a foe’s distraction. Once per turn, you can deal an extra 1d6 damage to one creature you hit with an attack if you have advantage on the attack roll. The attack must use a finesse or a ranged weapon.

You don’t need advantage on the attack roll if another enemy of the target is within 5 feet of it, that enemy isn’t incapacitated, and you don’t have disadvantage on the attack roll.

The question arises from the difficulty in parsing the bolded sentence. I have heard 2 interpretations:

  1. You can sneak attack if (you have advantage and the attack is made using a finesse or ranged weapon) or (an enemy of the target is within 5ft, etc).
  2. You can sneak attack if ((you have advantage) or (an enemy of the target is within 5ft, etc)) and the attack is made using a finesse or ranged weapon.

The first interpretation hinges on the idea that when the second paragraph says "on the attack roll" it is still talking about the same "attack" as in the first paragraph. The second interpretation hinges on the idea that the first interpretation is bizarre and unnatural – if that was the intent, there are many ways that it could have been worded to be clearer.

Thematically, I am leaning towards the first – not having a finesse or ranged weapon shouldn’t stop the rogue from exploiting a distracted foe.

Considering RAW only (no twitter please), how should this feature be interpreted?

What kinds of training and research are possible within the paradises found within a Rod of Security?

The Rod of Security gives a person access to ‘any paradise one could imagine’, specifically:

‘… the rod then instantly transports you and up to 199 other willing creatures you can see to a paradise that exists in an extraplanar space. You choose the form that the paradise takes. It could be a tranquil garden, lovely glade, cheery tavern, immense palace, tropical island, fantastic carnival, or whatever else you can imagine.’

This ageless paradise has a 199 day limit, divided by the number of occupants staying within Example: a party of five gets ( 199 days / 5 people = ) 39.8 days maximum. Once out it takes ten days to regain this 199-day-persons capacity.

Plenty of rest, good times and amazing food (i.e. ‘possible weight-gain hazard’) – but so much free time… with incredible resources! Imagine gaining new tool proficiencies, catching up on some downtime stuff or whatever you like. But could one research old &/or new spells? Develop a formula / blueprint / pattern for almost any magic item? Research ancient lore in a paradise-library? Suddenly this rod is a very powerful item. Possibly derailing a campaign – or even presenting as a bit too powerful?

Given access to ‘any paradise’ – be that training &/or library-research – what limits exist for players’ gains in skills, abilities &/or knowledge?

Role of games within games

Sometimes my players want to engage in gambling or other games of chance within the role-playing game itself (I know, vaguely meta). The question is two-fold:

  1. How can I approach this without squashing their aspirations to be the next Poker King, indulge them, and not have it become an obsession or throw off game balance due to poverty and/or extreme wealth given their current place in the world?

  2. Does anybody have any good, easy/quick games that could be played in a casino/gambling-hall type locale? I’m thinking something similar to Dragon Dice, an older, briefly manufactured dice game. It should have a fantastical element but be simple enough to learn within 15-30 minutes. I’m not looking to play craps at the gaming table, but having a few alternatives should wet the party’s thirst for casino-style action.

Importantly, I want to avoid a Chocobo-racing scenario (I’m referring to Final Fantasy 7 wherein players would become immersed in breeding and racing wingless birds, rather than actually spending time winning the game).

If you’re unconscious and making death saving throws, and an attack from within 5 feet of you hits you, does it cause 2 failed death saves?

In the PHB, it says that three death saving throw failures means you die; taking any damage causes 1 failure, and a critical hit causes 2 failures. But the unconscious condition says that attacks against an unconscious character have advantage and auto-crit if they’re within 5 feet.

That seems really tough — it almost guarantees that you’ll die if hit twice if one is melee, and on top of that if you’re hit once and not stabilized on your next turn you have a 45% chance of getting your third failure from the saving throw.

Am I correctly reading the rules? If you’re unconscious and making death saving throws, and an attack from within 5 feet of you hits you, does it cause 2 failed death saves?

Does the Witch Bolt spell end if you use a bonus action, reaction, or movement (remaining within the spell’s range)?

The obvious things are:

  • ending it voluntarily
  • losing concentration
  • breaking the tether with range or cover
  • using a normal action on your turn for something other than witch bolt

What isn’t specified is whether or not the spell ends when you use a bonus action, movement or reaction. I would assume that reactions would be fine because they are quick spells and not on your turn. Movement is generally not considered an action in 5e afaik, so it seems fine too. The description is less clear about bonus actions however, because they occur on your turn and witch bolt states

On a hit, the target takes 1d12 lightning damage, and on each of your turns for the duration, you can use your action to deal 1d12 lightning damage to the target automatically. The spell ends if you use your action to do anything else. The spell also ends if the target is ever outside the spell’s range or if it has total cover from you.

BUT Bonus actions are fast and often without a somatic/verbal component, and most cases in the PHB refer to the normal action as "your action". Also, the action required for witch bolt is NOT casting a spell and so the "bonus spell + cantrip" rule is not applicable here. Witch bolt is presumably taking a mental effort to maintain, such that I wouldn’t be able to cast another normal action spell without losing focus on the beam, but for something like misty step, with only a verbal component and taking minimal effort (especially if it’s a wizard spell-mastery spell), it seems to me like it would be possible.

Anyone know if there’s an official ruling for this, or is it entirely up to the DM? If I were a DM I’d rule that it’s allowed, since it requires giving up your standard action, and you’re still limited to the 30ft tether AND line of sight, AND concentration, AND spell slots if you’re not a lvl 18 wizard. Compared to a high level blastlock hitting for 4d10+20+knockback with eblast each turn, with a cantrip that would allow a bonus spell on your turn and a reaction spell on someone else’s turn, witch bolt with bonus action and reaction (now that I think about the math) still seems underpowered at high levels. (especially now that I realize that subsequent turns don’t add the extra damage from a higher lvl spell slot. A lot of text for something not terrible useful. Still curious though.

TL:DR Can I maintain witch bolt on a target and move normally and use my bonus action to teleport around with misty step (provided I maintain line of sight and tether range), while using my reactions on enemy creature’s turns for counterspell or shield?

Does Telekinetic Projectile allow choosing both projectile and target within range even if they are further apart than 30 feet?

Telekinetic Projectile allows you to "hurl [an] object that is within range […] at the target". The spell’s range is 30 feet.

My reading of this is that both the target and the object must be picked from within 30 feet from the caster. But nothing states that the path that the projectile flies (from object to target) must be less than 30 feet.

Are my assumptions correct or have I missed any relevant rules?

Also, if so, does the path between them have to be clear as to not provide Cover for the target?

Object <- 30ft -> caster <- 30ft -> target        <-         ~60ft          -> 

Is nonce useless when user input is reflected within an inline script?

I stumbled upon a web app which is accepting user input and putting it into a variable within script tag.

The script tag does have a nonce attribute.

enter image description here

As am working on bypassing the XSS filter, I had this thought that this practice of reflecting user input within an inline script with nonce attribute beats the purpose of using it.

Is my understand correct or am I missing something here ?

Enumerating points on the integer lattice, within a sphere, sorted by angle, in O(1) space

Inspired by this StackOverflow question: https://stackoverflow.com/questions/63346135

(it was not clearly presented, and got closed)

Let’s say I wanted to enumerate all the 3D points on the integer lattice, within a sphere, in order of the angle between the vector to the point and the up vector (say z).

Could I do this in O(1) space efficiently?

All I can find is:

Remembering last point (init at (0,0,0)). (O(1) memory) while true     init best dot product to 0     going through all 3D points (three nested for's with radius range)         if this point has better dot product but least than last point             keep this point as best     if best dot product is still 0, exit      pick best point as current point (this is where the listing occurs)     update last point to best point 

Not only is this absolutely slow, it also needs the use of integer math for dot product and length so that numerical precision doesn’t mess with symmetrical points and it would also need a tweak to guarantee symmetrical points are listed in a known order.

Is there any good algorithms that would apply here?