Rolisteam / DiceParser

Powerful dice Roller is used as discord bot, irc bot, cli tool and inside Rolisteam : 1d20+4, 1L[head,arm,leg,belly,chest], 1d6+1d8, 8+5*3
http://www.rolisteam.org/
GNU General Public License v3.0
125 stars 31 forks source link

Feature request or Workaround for Qin game : Math.Abs(1D10 - 1D10) #136

Closed Echtelion closed 2 years ago

Echtelion commented 3 years ago

Hi,

For the Qin RPG, I have to make a difference between two D10, get the math.abs(difference) as output in order to add it to a base score, and also display the rolled diced in the original order for damage computing. Ideally, I would also like to be notified when the substraction result is 0 (or the rolls are even), which represent a critical score in this game. This dice system is named "yin yang"

Exemple :

!7+ABS(1D10-1D10)
RESULT : #3, #5 = 9

detail = 7 + ABS(3-5)

For now, I'm just using a macro with 1D10-1D10. I have seen a sort method in a 2D10, but this way I can't substract the results.

Did you know if there is a way to have this behaviour in the current code ? If no, please consider it a feature request.

If implenting the parenthesis and math.abs logique is too complicated, it's possible to simplify the call with a keyword "yinyang", for exemple !7+yinyang. The keyword would trigger the Math.Abs(D10-D10) and the custom output.

Thanks.

Echtelion commented 3 years ago

Exemple for critical strike :

!7+ABS(1D10-1D10)
RESULT : #7, #7 = CRITICAL STRIKE ON #7
!7+ABS(1D10-1D10)
RESULT : #0, #0 = CRITICAL FAIL ON #0
obiwankennedy commented 2 years ago

Hello, I worked on that in order to make it work without abs function but to make it with if. I finally make it work but I discover a bug about it. I have to deploy this bug fix in order to make the if replacement a working command.

It should work with this:

!1d10;1d10;$1-$2;$3i:[<0]{$3*-1}{$3};$1S[=7]{"Critical Strike"}[=0]{"Critical Fail"}{" "};7+$4;"Result: $5 #$1, #$2 = $6 [details: $4]"

But due to a bug the $3*-1 does not work. I fixed it but it is not deploy yet. It will be done soon. Adding the abs function can be done but function are not manage like that in the diceparser. I have to check that.

Echtelion commented 2 years ago

Thanks for your answer. I may be misreading your expression, but I understand that you output a "critical strike" when diff=0 & roll=7. That's not how critical strike work : any even result except 0 is a critical strike

you can also sort it this way if easier to write :

Also the 7 is hardcoded in your expression, while it's an input for me (7 is carac + talent as a base, on which I'll add the dice result). Note we can ignore this input for simplification sake.

Echtelion commented 2 years ago

Ok, I found a workaround for your *-1 bug, : just make the substraction the other way instead of negativing the result

Here is my workaround : !1d10;1d10;$1-$2;$3i:[<0]{$2-$1}{$3};$3S[=0]{$1S[=0]{"CRITICAL FAIL"}{"CRITICAL STRIKE"}}{$3S[<0]{"NEGATIVE STRIKE"}{"POSITIVE STRIKE"}};"Result: $5 #$1, #$2 = $4"

I also added the positive/negative result for damage bonus (negative result make no dmg bonus, while positive make it)

Echtelion commented 2 years ago

mfffff, the command work fine, but now I'm unable to add it into a macro.

Here is the command : !macro add yy !1d10;1d10;$1-$2;$3i:[<0]{$2-$1}{$3};$3S[=0]{$1S[=0]{"CRITICAL FAIL"}{"CRITICAL STRIKE"}}{$3S[<0]{"NEGATIVE STRIKE"}{"POSITIVE STRIKE"}};"Result: $5 #$1 - #$2 = $4" False The bot acknowledge the command, and I can see it in !macro list, but it doesn't run on !yy (others macro works)

Me : !macro list
DiceParser BOT
id: 0 Pattern: yy Command: !1d10;1d10;$1-$2;$3i:[<0]{$2-$1}{$3};$3S[=0]{$1S[=0]{"CRITICAL FAIL"}{"CRITICAL STRIKE"}}{$3S[<0]{"NEGATIVE STRIKE"}{"POSITIVE STRIKE"}};"Result: $5 #$1 - #$2 = $4" Regexp: False
Me : !yy
(nothing)
obiwankennedy commented 2 years ago

No need of leading ! on the command part (before the 1d10).

This should works:

!macro add yy 1d10;1d10;$1-$2;$3i:[<0]{$2-$1}{$3};$3S[=0]{$1S[=0]{"CRITICAL FAIL"}{"CRITICAL STRIKE"}}{$3S[<0]{"NEGATIVE STRIKE"}{"POSITIVE STRIKE"}};"Result: $5 #$1 - #$2 = $4" False
Echtelion commented 2 years ago

Hi @obiwankennedy I'm sorry to revive this thread but I didn't try the macro earlier. I don't see any error in the macro, but I got this error messages : Error: No value fits the Switch/Case operator Supposedly when getting dice1 == dice2

I have decomposed/documented the macro and really didn't see any switch error :

!macro add yy 
1d10;   //1 YIN dice
1d10;   //2 YANG dice
$1-$2;  //3 DIFF
$3i:[<0]{$2-$1}{$3};    //4: always positive diff
$3S[=0]{                //5: if diff is 0, it's a critital
    $1S[=0]{"CRITICAL FAIL"}{"CRITICAL STRIKE"} // if YIN(&YANG) equals 0 then it's a crit fail. else crit are successes
}
{$3S[<0]{"NEGATIVE STRIKE"}{"POSITIVE STRIKE"}};            //5 : else if diff is inf to 0, there will be no damage bonus. Else a positive YIN-YANG will give bonus damage
"Result: $5 #$1 - #$2 = $4" False                           // echo TEXT, YIN - YANG = POSITIVEDIFF
obiwankennedy commented 2 years ago

I believe this is the issue: $1S[=0]{"CRITICAL FAIL"}{"CRITICAL STRIKE"} I don't get why using $1 = 0 it can't be. As $1 refers to the result of 1d10. Perhaps it is recommended to defined a condition for the other part.