Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaoye
ygopro-core
Commits
d9030579
Commit
d9030579
authored
May 31, 2023
by
IMJoyJ
Committed by
GitHub
May 31, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Duel.GetRandomNumber (#13)
Co-authored-by:
Joy J
<
316351048@qq.com
>
parent
0df2566f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
libduel.cpp
libduel.cpp
+23
-0
No files found.
libduel.cpp
View file @
d9030579
...
...
@@ -4180,6 +4180,28 @@ int32 scriptlib::duel_toss_coin(lua_State * L) {
return
count
;
});
}
int32
scriptlib
::
duel_get_random_number
(
lua_State
*
L
)
{
//check_action_permission(L); Don't check action permission
duel
*
pduel
=
interpreter
::
get_duel_info
(
L
);
return
lua_yieldk
(
L
,
0
,
(
lua_KContext
)
pduel
,
[](
lua_State
*
L
,
int32
status
,
lua_KContext
ctx
)
{
duel
*
pduel
=
(
duel
*
)
ctx
;
int32
min
=
0
;
int32
max
=
2147483647
;
//Duel.GetRandomNumber() returns a number from [0,2147483647)
if
(
lua_gettop
(
L
)
>
1
)
{
//Duel.GetRandomNumber(n,m) returns a number from [n,m]
min
=
lua_tointeger
(
L
,
1
);
max
=
lua_tointeger
(
L
,
2
)
+
1
;
}
else
if
(
lua_gettop
(
L
)
>
0
)
{
// Duel.GetRandomNumber(n) returns a number from [1,n]
min
=
1
;
max
=
lua_tointeger
(
L
,
1
)
+
1
;
}
lua_pushinteger
(
L
,
pduel
->
get_next_integer
(
min
,
max
));
return
1
;
});
}
int32
scriptlib
::
duel_toss_dice
(
lua_State
*
L
)
{
check_action_permission
(
L
);
check_param_count
(
L
,
2
);
...
...
@@ -5034,6 +5056,7 @@ static const struct luaL_Reg duellib[] = {
{
"AnnounceCoin"
,
scriptlib
::
duel_announce_coin
},
{
"TossCoin"
,
scriptlib
::
duel_toss_coin
},
{
"TossDice"
,
scriptlib
::
duel_toss_dice
},
{
"GetRandomNumber"
,
scriptlib
::
duel_get_random_number
},
{
"RockPaperScissors"
,
scriptlib
::
duel_rock_paper_scissors
},
{
"GetCoinResult"
,
scriptlib
::
duel_get_coin_result
},
{
"GetDiceResult"
,
scriptlib
::
duel_get_dice_result
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment