11import re
22# list of autoscriptable psct to look for
3- cases = '''
3+ cases_list = '''
44once per turn:|
55" once per turn|
6- target |
7- destroy |
6+ target |
7+ destroy |
88then|
99and if you do|
10- also |
10+ also|
1111\(quick effect\):|
12+ from your deck to your hand|
13+ except "|
1214 '''
13- cases = str (cases .replace ('\n ' , '' ))
15+ cases_list = str (cases_list .replace ('\n ' , '' ))
1416
1517# a few templates used in many cases
1618base_target = 'function s.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n <edit target>\n end'
1719target_initial = 'e1:SetTarget(s.target)\n <expand effect>'
1820base_operation = 'function s.operation(e,tp,eg,ep,ev,re,r,rp)\n <edit operation>\n end'
1921operation_initial = 'e1:SetTarget(s.operation)\n <expand effect>'
22+ base_filter = 'function s.filter(c)\n return <filter>\n end\n <add func>'
2023
2124# func that finds the scriptable bit and returns the corresponding script
2225def scriptranslate (psct ):
23- res = re .search (cases , psct )
26+ res = re .search (cases_list , psct )
2427 # check if something is scriptable
2528 if res is None :
2629 return ('All autoscripts done.' ,'' ,'' )
@@ -32,27 +35,33 @@ def scriptranslate(psct):
3235 case 'once per turn:' :
3336 return (res [0 ],'<expand effect>' ,'e1:SetCountLimit(1)\n <expand effect>' ,'<edit settype>' ,'EFFECT_TYPE_IGNITION' ,'<edit setcode>' ,'EVENT_FREE_CHAIN' )
3437
35- case ' target ' :
36- return (res [0 ],'<add func>' ,'function s.filter(c) \n return <filter> \n end' ,'<expand effect>' ,target_initial ,'<add target>' ,base_target ,'<edit target>' ,'if chkc then return chkc:IsOnField() and s.filter(chkc) end\n if chk==0 then return Duel.IsExistingTarget(s.filter,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,nil) end\n Duel.Hint(HINT_SELECTMSG,tp,<hint>)\n local g=Duel.SelectTarget(tp,s.filter,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,1,nil)\n <edit target>' ,'<expand effect>' ,operation_initial ,'<add operation>' ,base_operation ,'<edit operation>' ,'local tc=Duel.GetFirstTarget()\n if tc:IsRelateToEffect(e) then\n <edit operation>\n end' ,'<expand effect>' ,'e1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n <expand effect>' )
38+ case 'target ' :
39+ return (res [0 ],'<add func>' ,base_filter ,'<expand effect>' ,target_initial ,'<add target>' ,base_target ,'<edit target>' ,'if chkc then return chkc:IsOnField() and s.filter(chkc) end\n if chk==0 then return Duel.IsExistingTarget(s.filter,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,nil) end\n Duel.Hint(HINT_SELECTMSG,tp,<hint>)\n local g=Duel.SelectTarget(tp,s.filter,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,1,nil)\n <edit target>' ,'<expand effect>' ,operation_initial ,'<add operation>' ,base_operation ,'<edit operation>' ,'local tc=Duel.GetFirstTarget()\n if tc:IsRelateToEffect(e) then\n <edit operation>\n end' ,'<expand effect>' ,'e1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n <expand effect>' )
3740
38- case ' destroy ' :
41+ case 'destroy ' :
3942 return (res [0 ],'<expand effect>' ,target_initial ,'<add target>' ,base_target ,'<edit target>' ,'<edit target>\n Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0)' ,'<expand effect>' ,operation_initial ,'<add operation>' ,base_operation ,'<edit operation>' ,'Duel.Destroy(tc,REASON_EFFECT)\n <edit operation>' ,'<hint>' ,'HINTMSG_DESTROY' )
4043
4144 case 'then' :
42- return (res [0 ],'<expand effect>' ,operation_initial ,'<add operation>' ,base_operation ,'<edit operation>' ,'Duel.BreakEffect()\n <edit operation>' )
45+ return (res [0 ],'<expand effect>' ,operation_initial ,'<add operation>' ,base_operation ,'<edit operation>' ,'if <condition first part effect> \n Duel.BreakEffect()\n <edit operation>\n end ' )
4346
4447 case 'and if you do' :
4548 return (res [0 ],'<expand effect>' ,operation_initial ,'<add operation>' ,base_operation ,'<edit operation>' ,'if <condition first part effect>\n <edit operation>\n end' )
4649
47- case ' also ' :
50+ case 'also' :
4851 return (res [0 ],'<expand effect>' ,operation_initial ,'<add operation>' ,base_operation )
4952
5053 case '(quick effect):' :
5154 return (res [0 ],'<edit settype>' ,'EFFECT_TYPE_QUICK_O' ,'<edit setcode>' ,'EVENT_FREE_CHAIN' )
5255
56+ case 'from your deck to your hand' :
57+ return (res [0 ],'<expand effect>' ,'e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH)\n <expand effect>' ,'<expand effect>' ,target_initial ,'<add target>' ,base_target ,'<expand effect>' ,operation_initial ,'<add operation>' ,base_operation ,'<edit target>' ,'if chk==0 then return Duel.IsExistingMatchingCard(s.filter,tp,LOCATION_DECK,0,1,nil) end\n <edit target>\n Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK)' ,'<edit operation>' ,'Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)\n local g=Duel.SelectMatchingCard(tp,s.filter,tp,LOCATION_DECK,0,1,1,nil)\n if #g>0 then\n Duel.SendtoHand(g,nil,REASON_EFFECT)\n Duel.ConfirmCards(1-tp,g)\n end\n <edit operation>' ,'<add func>' ,base_filter ,'<filter>' ,'c:IsAbleToHand() and <filter>' )
58+
59+ case 'except "' :
60+ return (res [0 ],'<filter>' ,'not c:IsCode(id) and <filter>' ,'<add func>' ,'s.listed_names={id}\n <add func>' )
61+
5362# "return" structured as follow:
5463# (case found, toreplace, replacement, toreplace, replacement,...)
55- # "case found" must be rewritten if regex characters are used
5664# as many replacements as you want (executed from left to right)
5765# put back the replacement tag at the end of each replacement
66+ # characters in cases_list that are used by regex must be escaped (see quick effect case)
5867# "base_..." are templates that are used in many but not all cards
0 commit comments