Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
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
MyCard
Neos
Commits
680f4298
Commit
680f4298
authored
Dec 02, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle selfType and player correctly
parent
426b4473
Pipeline
#18322
passed with stages
in 2 minutes and 40 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
32 deletions
+63
-32
src/reducers/duel/initInfoSlice.ts
src/reducers/duel/initInfoSlice.ts
+13
-13
src/reducers/duel/mod.ts
src/reducers/duel/mod.ts
+9
-6
src/reducers/duel/util.ts
src/reducers/duel/util.ts
+23
-0
src/service/duel/start.ts
src/service/duel/start.ts
+18
-13
No files found.
src/reducers/duel/initInfoSlice.ts
View file @
680f4298
import
{
PayloadAction
,
CaseReducer
}
from
"
@reduxjs/toolkit
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
judgeSelf
}
from
"
./util
"
;
export
interface
InitInfo
{
playerType
?:
string
;
masterRule
?:
string
;
life
:
number
;
deckSize
:
number
;
...
...
@@ -10,17 +10,17 @@ export interface InitInfo {
}
// 更新自己的初始生命值,卡组信息
export
const
meInfoInitImpl
:
CaseReducer
<
DuelState
,
PayloadAction
<
InitInfo
>>
=
(
state
,
action
)
=>
{
state
.
meInitInfo
=
action
.
payload
;
};
export
const
infoInitImpl
:
CaseReducer
<
DuelState
,
PayloadAction
<
[
number
,
InitInfo
]
>
>
=
(
state
,
action
)
=>
{
const
player
=
action
.
payload
[
0
];
const
initInfo
=
action
.
payload
[
1
];
const
selfType
=
state
.
selfType
;
// 更新对手的初始生命值,卡组信息
export
const
opInfoInitImpl
:
CaseReducer
<
DuelState
,
PayloadAction
<
InitInfo
>>
=
(
state
,
action
)
=>
{
state
.
opInitInfo
=
action
.
payload
;
if
(
judgeSelf
(
player
,
selfType
))
{
state
.
meInitInfo
=
initInfo
;
}
else
{
state
.
opInitInfo
=
initInfo
;
}
};
src/reducers/duel/mod.ts
View file @
680f4298
...
...
@@ -3,8 +3,8 @@
*
* */
import
{
createSlice
}
from
"
@reduxjs/toolkit
"
;
import
{
InitInfo
,
meInfoInitImpl
,
opI
nfoInitImpl
}
from
"
./initInfoSlice
"
;
import
{
createSlice
,
PayloadAction
}
from
"
@reduxjs/toolkit
"
;
import
{
InitInfo
,
i
nfoInitImpl
}
from
"
./initInfoSlice
"
;
import
{
Hands
,
meAddHandsImpl
,
...
...
@@ -16,6 +16,7 @@ import { newPhaseImpl } from "./phaseSlice";
import
{
RootState
}
from
"
../../store
"
;
export
interface
DuelState
{
selfType
?:
number
;
meInitInfo
?:
InitInfo
;
// 自己的初始状态
opInitInfo
?:
InitInfo
;
// 对手的初始状态
meHands
?:
Hands
;
// 自己的手牌
...
...
@@ -30,8 +31,10 @@ const duelSlice = createSlice({
name
:
"
duel
"
,
initialState
,
reducers
:
{
meInfoInit
:
meInfoInitImpl
,
opInfoInit
:
opInfoInitImpl
,
setSelfType
:
(
state
,
action
:
PayloadAction
<
number
>
)
=>
{
state
.
selfType
=
action
.
payload
;
},
infoInit
:
infoInitImpl
,
meAddHands
:
meAddHandsImpl
,
opAddHands
:
opAddHandsImpl
,
updateTurn
:
newTurnImpl
,
...
...
@@ -43,8 +46,8 @@ const duelSlice = createSlice({
});
export
const
{
meInfoInit
,
opI
nfoInit
,
setSelfType
,
i
nfoInit
,
meAddHands
,
opAddHands
,
updateTurn
,
...
...
src/reducers/duel/util.ts
0 → 100644
View file @
680f4298
/*
* 对局内状态更新逻辑的一些共用函数
*
* */
/*
* 通过`player`和`selfType`判断是应该处理自己还是对手
* */
export
function
judgeSelf
(
player
:
number
,
selfType
:
number
|
undefined
):
boolean
{
if
(
selfType
===
1
)
{
// 自己是先攻
return
player
===
0
;
}
else
if
(
selfType
===
2
)
{
// 自己是后攻
return
player
===
1
;
}
else
{
// currently never reach
return
false
;
}
}
src/service/duel/start.ts
View file @
680f4298
import
{
ygopro
}
from
"
../../api/ocgcore/idl/ocgcore
"
;
import
{
AppDispatch
}
from
"
../../store
"
;
import
{
meInfoInit
,
opInfoInit
}
from
"
../../reducers/duel/mod
"
;
import
{
infoInit
,
setSelfType
}
from
"
../../reducers/duel/mod
"
;
export
default
(
start
:
ygopro
.
StocGameMessage
.
MsgStart
,
dispatch
:
AppDispatch
)
=>
{
dispatch
(
setSelfType
(
start
.
playerType
));
dispatch
(
meInfoInit
({
playerType
:
start
.
playerType
.
toString
(),
life
:
start
.
life1
,
deckSize
:
start
.
deckSize1
,
extraSize
:
start
.
extraSize1
,
})
infoInit
([
0
,
{
life
:
start
.
life1
,
deckSize
:
start
.
deckSize1
,
extraSize
:
start
.
extraSize1
,
},
])
);
dispatch
(
opInfoInit
({
life
:
start
.
life2
,
deckSize
:
start
.
deckSize2
,
extraSize
:
start
.
extraSize2
,
})
infoInit
([
1
,
{
life
:
start
.
life2
,
deckSize
:
start
.
deckSize2
,
extraSize
:
start
.
extraSize2
,
},
])
);
};
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