Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
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
fallenstardust
YGOMobile
Commits
b6ec6b87
Commit
b6ec6b87
authored
May 25, 2021
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync ocgcore
parent
22a1fc86
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
0 deletions
+91
-0
Classes/ocgcore/card.cpp
Classes/ocgcore/card.cpp
+40
-0
Classes/ocgcore/card.h
Classes/ocgcore/card.h
+2
-0
Classes/ocgcore/effect.h
Classes/ocgcore/effect.h
+2
-0
Classes/ocgcore/interpreter.cpp
Classes/ocgcore/interpreter.cpp
+19
-0
Classes/ocgcore/libcard.cpp
Classes/ocgcore/libcard.cpp
+26
-0
Classes/ocgcore/scriptlib.h
Classes/ocgcore/scriptlib.h
+2
-0
No files found.
Classes/ocgcore/card.cpp
View file @
b6ec6b87
...
...
@@ -1052,6 +1052,26 @@ uint32 card::get_link_attribute(uint8 playerid) {
}
return
attribute
;
}
uint32
card
::
get_grave_attribute
(
uint8
playerid
)
{
if
(
!
(
data
.
type
&
TYPE_MONSTER
))
return
0
;
if
(
current
.
is_location
(
LOCATION_GRAVE
))
return
get_attribute
();
uint32
attribute
=
data
.
attribute
;
effect_set
eset
;
pduel
->
game_field
->
filter_player_effect
(
playerid
,
EFFECT_CHANGE_GRAVE_ATTRIBUTE
,
&
eset
);
for
(
int32
i
=
0
;
i
<
eset
.
size
();
++
i
)
{
if
(
!
eset
[
i
]
->
target
)
attribute
=
eset
[
i
]
->
get_value
(
this
);
else
{
pduel
->
lua
->
add_param
(
eset
[
i
],
PARAM_TYPE_EFFECT
);
pduel
->
lua
->
add_param
(
this
,
PARAM_TYPE_CARD
);
if
(
pduel
->
lua
->
check_condition
(
eset
[
i
]
->
target
,
2
))
attribute
=
eset
[
i
]
->
get_value
(
this
);
}
}
return
attribute
;
}
uint32
card
::
get_race
()
{
if
(
assume_type
==
ASSUME_RACE
)
return
assume_value
;
...
...
@@ -1090,6 +1110,26 @@ uint32 card::get_link_race(uint8 playerid) {
}
return
race
;
}
uint32
card
::
get_grave_race
(
uint8
playerid
)
{
if
(
!
(
data
.
type
&
TYPE_MONSTER
))
return
0
;
if
(
current
.
is_location
(
LOCATION_GRAVE
))
return
get_race
();
uint32
race
=
data
.
race
;
effect_set
eset
;
pduel
->
game_field
->
filter_player_effect
(
playerid
,
EFFECT_CHANGE_GRAVE_RACE
,
&
eset
);
for
(
int32
i
=
0
;
i
<
eset
.
size
();
++
i
)
{
if
(
!
eset
[
i
]
->
target
)
race
=
eset
[
i
]
->
get_value
(
this
);
else
{
pduel
->
lua
->
add_param
(
eset
[
i
],
PARAM_TYPE_EFFECT
);
pduel
->
lua
->
add_param
(
this
,
PARAM_TYPE_CARD
);
if
(
pduel
->
lua
->
check_condition
(
eset
[
i
]
->
target
,
2
))
race
=
eset
[
i
]
->
get_value
(
this
);
}
}
return
race
;
}
uint32
card
::
get_lscale
()
{
if
(
!
current
.
is_location
(
LOCATION_PZONE
))
return
data
.
lscale
;
...
...
Classes/ocgcore/card.h
View file @
b6ec6b87
...
...
@@ -225,8 +225,10 @@ public:
uint32
get_attribute
();
uint32
get_fusion_attribute
(
uint8
playerid
);
uint32
get_link_attribute
(
uint8
playerid
);
uint32
get_grave_attribute
(
uint8
playerid
);
uint32
get_race
();
uint32
get_link_race
(
uint8
playerid
);
uint32
get_grave_race
(
uint8
playerid
);
uint32
get_lscale
();
uint32
get_rscale
();
uint32
get_link_marker
();
...
...
Classes/ocgcore/effect.h
View file @
b6ec6b87
...
...
@@ -454,6 +454,8 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
#define EFFECT_SET_BATTLE_ATTACK 362
#define EFFECT_SET_BATTLE_DEFENSE 363
#define EFFECT_OVERLAY_RITUAL_MATERIAL 364
#define EFFECT_CHANGE_GRAVE_ATTRIBUTE 365
#define EFFECT_CHANGE_GRAVE_RACE 366
#define EVENT_STARTUP 1000
#define EVENT_FLIP 1001
...
...
Classes/ocgcore/interpreter.cpp
View file @
b6ec6b87
...
...
@@ -47,6 +47,8 @@ interpreter::~interpreter() {
}
int32
interpreter
::
register_card
(
card
*
pcard
)
{
//create a card in by userdata
luaL_checkstack
(
lua_state
,
1
,
NULL
);
luaL_checkstack
(
current_state
,
1
,
NULL
);
card
**
ppcard
=
(
card
**
)
lua_newuserdata
(
lua_state
,
sizeof
(
card
*
));
*
ppcard
=
pcard
;
pcard
->
ref_handle
=
luaL_ref
(
lua_state
,
LUA_REGISTRYINDEX
);
...
...
@@ -74,6 +76,7 @@ void interpreter::register_effect(effect *peffect) {
if
(
!
peffect
)
return
;
//create a effect in by userdata
luaL_checkstack
(
lua_state
,
3
,
NULL
);
effect
**
ppeffect
=
(
effect
**
)
lua_newuserdata
(
lua_state
,
sizeof
(
effect
*
));
*
ppeffect
=
peffect
;
peffect
->
ref_handle
=
luaL_ref
(
lua_state
,
LUA_REGISTRYINDEX
);
...
...
@@ -103,6 +106,7 @@ void interpreter::register_group(group *pgroup) {
if
(
!
pgroup
)
return
;
//create a group in by userdata
luaL_checkstack
(
lua_state
,
3
,
NULL
);
group
**
ppgroup
=
(
group
**
)
lua_newuserdata
(
lua_state
,
sizeof
(
group
*
));
*
ppgroup
=
pgroup
;
pgroup
->
ref_handle
=
luaL_ref
(
lua_state
,
LUA_REGISTRYINDEX
);
...
...
@@ -138,9 +142,11 @@ int32 interpreter::load_script(const char* script_name) {
int32
interpreter
::
load_card_script
(
uint32
code
)
{
char
class_name
[
20
];
sprintf
(
class_name
,
"c%d"
,
code
);
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_getglobal
(
current_state
,
class_name
);
//if script is not loaded, create and load it
if
(
lua_isnil
(
current_state
,
-
1
))
{
luaL_checkstack
(
current_state
,
5
,
NULL
);
lua_pop
(
current_state
,
1
);
//create a table & set metatable
lua_createtable
(
current_state
,
0
,
0
);
...
...
@@ -174,6 +180,7 @@ void interpreter::add_param(ptr param, int32 type, bool front) {
void
interpreter
::
push_param
(
lua_State
*
L
,
bool
is_coroutine
)
{
int32
pushed
=
0
;
for
(
const
auto
&
it
:
params
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
uint32
type
=
it
.
second
;
switch
(
type
)
{
case
PARAM_TYPE_INT
:
...
...
@@ -283,6 +290,7 @@ int32 interpreter::call_card_function(card* pcard, const char* f, uint32 param_c
return
OPERATION_FAIL
;
}
card2value
(
current_state
,
pcard
);
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_getfield
(
current_state
,
-
1
,
f
);
if
(
!
lua_isfunction
(
current_state
,
-
1
))
{
sprintf
(
pduel
->
strbuffer
,
"
\"
CallCardFunction
\"
(c%d.%s): attempt to call an error function"
,
pcard
->
data
.
code
,
f
);
...
...
@@ -323,6 +331,7 @@ int32 interpreter::call_code_function(uint32 code, const char* f, uint32 param_c
return
OPERATION_FAIL
;
}
load_card_script
(
code
);
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_getfield
(
current_state
,
-
1
,
f
);
if
(
!
lua_isfunction
(
current_state
,
-
1
))
{
sprintf
(
pduel
->
strbuffer
,
"
\"
CallCodeFunction
\"
: attempt to call an error function"
);
...
...
@@ -386,6 +395,7 @@ int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
return
TRUE
;
no_action
++
;
call_depth
++
;
luaL_checkstack
(
current_state
,
1
+
extraargs
,
NULL
);
lua_pushvalue
(
current_state
,
findex
);
interpreter
::
card2value
(
current_state
,
pcard
);
for
(
int32
i
=
0
;
i
<
extraargs
;
++
i
)
...
...
@@ -417,6 +427,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg
return
0
;
no_action
++
;
call_depth
++
;
luaL_checkstack
(
current_state
,
1
+
extraargs
,
NULL
);
lua_pushvalue
(
current_state
,
findex
);
interpreter
::
card2value
(
current_state
,
pcard
);
for
(
int32
i
=
0
;
i
<
extraargs
;
++
i
)
...
...
@@ -579,6 +590,7 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va
}
}
int32
interpreter
::
clone_function_ref
(
int32
func_ref
)
{
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_rawgeti
(
current_state
,
LUA_REGISTRYINDEX
,
func_ref
);
int32
ref
=
luaL_ref
(
current_state
,
LUA_REGISTRYINDEX
);
return
ref
;
...
...
@@ -586,6 +598,7 @@ int32 interpreter::clone_function_ref(int32 func_ref) {
void
*
interpreter
::
get_ref_object
(
int32
ref_handler
)
{
if
(
ref_handler
==
0
)
return
nullptr
;
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_rawgeti
(
current_state
,
LUA_REGISTRYINDEX
,
ref_handler
);
void
*
p
=
*
(
void
**
)
lua_touserdata
(
current_state
,
-
1
);
lua_pop
(
current_state
,
1
);
...
...
@@ -593,30 +606,35 @@ void* interpreter::get_ref_object(int32 ref_handler) {
}
//Convert a pointer to a lua value, +1 -0
void
interpreter
::
card2value
(
lua_State
*
L
,
card
*
pcard
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
if
(
!
pcard
||
pcard
->
ref_handle
==
0
)
lua_pushnil
(
L
);
else
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
pcard
->
ref_handle
);
}
void
interpreter
::
group2value
(
lua_State
*
L
,
group
*
pgroup
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
if
(
!
pgroup
||
pgroup
->
ref_handle
==
0
)
lua_pushnil
(
L
);
else
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
pgroup
->
ref_handle
);
}
void
interpreter
::
effect2value
(
lua_State
*
L
,
effect
*
peffect
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
if
(
!
peffect
||
peffect
->
ref_handle
==
0
)
lua_pushnil
(
L
);
else
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
peffect
->
ref_handle
);
}
void
interpreter
::
function2value
(
lua_State
*
L
,
int32
func_ref
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
if
(
!
func_ref
)
lua_pushnil
(
L
);
else
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
func_ref
);
}
int32
interpreter
::
get_function_handle
(
lua_State
*
L
,
int32
index
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
lua_pushvalue
(
L
,
index
);
int32
ref
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
return
ref
;
...
...
@@ -626,6 +644,7 @@ void interpreter::set_duel_info(lua_State* L, duel* pduel) {
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
}
duel
*
interpreter
::
get_duel_info
(
lua_State
*
L
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
3
);
duel
*
pduel
=
(
duel
*
)
lua_topointer
(
L
,
-
1
);
lua_pop
(
L
,
1
);
...
...
Classes/ocgcore/libcard.cpp
View file @
b6ec6b87
...
...
@@ -563,6 +563,18 @@ int32 scriptlib::card_get_link_attribute(lua_State *L) {
lua_pushinteger
(
L
,
pcard
->
get_link_attribute
(
playerid
));
return
1
;
}
int32
scriptlib
::
card_get_attribute_in_grave
(
lua_State
*
L
)
{
check_param_count
(
L
,
1
);
check_param
(
L
,
PARAM_TYPE_CARD
,
1
);
card
*
pcard
=
*
(
card
**
)
lua_touserdata
(
L
,
1
);
int32
playerid
=
PLAYER_NONE
;
if
(
lua_gettop
(
L
)
>
1
&&
!
lua_isnil
(
L
,
2
))
playerid
=
(
int32
)
lua_tointeger
(
L
,
2
);
else
playerid
=
pcard
->
pduel
->
game_field
->
core
.
reason_player
;
lua_pushinteger
(
L
,
pcard
->
get_grave_attribute
(
playerid
));
return
1
;
}
int32
scriptlib
::
card_get_race
(
lua_State
*
L
)
{
check_param_count
(
L
,
1
);
check_param
(
L
,
PARAM_TYPE_CARD
,
1
);
...
...
@@ -592,6 +604,18 @@ int32 scriptlib::card_get_link_race(lua_State *L) {
lua_pushinteger
(
L
,
pcard
->
get_link_race
(
playerid
));
return
1
;
}
int32
scriptlib
::
card_get_race_in_grave
(
lua_State
*
L
)
{
check_param_count
(
L
,
1
);
check_param
(
L
,
PARAM_TYPE_CARD
,
1
);
card
*
pcard
=
*
(
card
**
)
lua_touserdata
(
L
,
1
);
int32
playerid
=
PLAYER_NONE
;
if
(
lua_gettop
(
L
)
>
1
&&
!
lua_isnil
(
L
,
2
))
playerid
=
(
int32
)
lua_tointeger
(
L
,
2
);
else
playerid
=
pcard
->
pduel
->
game_field
->
core
.
reason_player
;
lua_pushinteger
(
L
,
pcard
->
get_grave_race
(
playerid
));
return
1
;
}
int32
scriptlib
::
card_get_attack
(
lua_State
*
L
)
{
check_param_count
(
L
,
1
);
check_param
(
L
,
PARAM_TYPE_CARD
,
1
);
...
...
@@ -3246,9 +3270,11 @@ static const struct luaL_Reg cardlib[] = {
{
"GetOriginalAttribute"
,
scriptlib
::
card_get_origin_attribute
},
{
"GetFusionAttribute"
,
scriptlib
::
card_get_fusion_attribute
},
{
"GetLinkAttribute"
,
scriptlib
::
card_get_link_attribute
},
{
"GetAttributeInGrave"
,
scriptlib
::
card_get_attribute_in_grave
},
{
"GetRace"
,
scriptlib
::
card_get_race
},
{
"GetOriginalRace"
,
scriptlib
::
card_get_origin_race
},
{
"GetLinkRace"
,
scriptlib
::
card_get_link_race
},
{
"GetRaceInGrave"
,
scriptlib
::
card_get_race_in_grave
},
{
"GetAttack"
,
scriptlib
::
card_get_attack
},
{
"GetBaseAttack"
,
scriptlib
::
card_get_origin_attack
},
{
"GetTextAttack"
,
scriptlib
::
card_get_text_attack
},
...
...
Classes/ocgcore/scriptlib.h
View file @
b6ec6b87
...
...
@@ -66,9 +66,11 @@ public:
static
int32
card_get_origin_attribute
(
lua_State
*
L
);
static
int32
card_get_fusion_attribute
(
lua_State
*
L
);
static
int32
card_get_link_attribute
(
lua_State
*
L
);
static
int32
card_get_attribute_in_grave
(
lua_State
*
L
);
static
int32
card_get_race
(
lua_State
*
L
);
static
int32
card_get_origin_race
(
lua_State
*
L
);
static
int32
card_get_link_race
(
lua_State
*
L
);
static
int32
card_get_race_in_grave
(
lua_State
*
L
);
static
int32
card_get_attack
(
lua_State
*
L
);
static
int32
card_get_origin_attack
(
lua_State
*
L
);
static
int32
card_get_text_attack
(
lua_State
*
L
);
...
...
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