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
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
love_飞影
Neos
Commits
b85b3cab
Commit
b85b3cab
authored
Apr 20, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: valtio store logic 50%
parent
2c415f42
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
132 additions
and
49 deletions
+132
-49
src/service/duel/attack.ts
src/service/duel/attack.ts
+5
-0
src/service/duel/attackDisable.ts
src/service/duel/attackDisable.ts
+2
-0
src/service/duel/chaining.ts
src/service/duel/chaining.ts
+5
-1
src/service/duel/draw.ts
src/service/duel/draw.ts
+2
-3
src/service/duel/flipSummoned.ts
src/service/duel/flipSummoned.ts
+2
-0
src/service/duel/flipSummoning.ts
src/service/duel/flipSummoning.ts
+5
-0
src/service/duel/gameMsg.ts
src/service/duel/gameMsg.ts
+3
-0
src/service/duel/hint.ts
src/service/duel/hint.ts
+9
-0
src/service/duel/newPhase.ts
src/service/duel/newPhase.ts
+9
-0
src/service/duel/newTurn.ts
src/service/duel/newTurn.ts
+3
-0
src/service/duel/posChange.ts
src/service/duel/posChange.ts
+7
-1
src/valtioStores/matStore/index.ts
src/valtioStores/matStore/index.ts
+66
-26
src/valtioStores/matStore/types.ts
src/valtioStores/matStore/types.ts
+14
-18
No files found.
src/service/duel/attack.ts
View file @
b85b3cab
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
fetchEsHintMeta
}
from
"
@/reducers/duel/hintSlice
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
matStore
}
from
"
@/valtioStores
"
;
export
default
(
attack
:
ygopro
.
StocGameMessage
.
MsgAttack
,
...
...
@@ -9,4 +10,8 @@ export default (
dispatch
(
fetchEsHintMeta
({
originMsg
:
"
「[?]」攻击时
"
,
location
:
attack
.
location
})
);
matStore
.
hint
.
fetchEsHintMeta
({
originMsg
:
"
「[?]」攻击时
"
,
location
:
attack
.
location
,
});
};
src/service/duel/attackDisable.ts
View file @
b85b3cab
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
fetchEsHintMeta
}
from
"
@/reducers/duel/hintSlice
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
matStore
}
from
"
@/valtioStores
"
;
export
default
(
_
:
ygopro
.
StocGameMessage
.
MsgAttackDisabled
,
dispatch
:
AppDispatch
)
=>
{
dispatch
(
fetchEsHintMeta
({
originMsg
:
"
攻击被无效时
"
}));
matStore
.
hint
.
fetchEsHintMeta
({
originMsg
:
"
攻击被无效时
"
});
};
src/service/duel/chaining.ts
View file @
b85b3cab
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
fetchEsHintMeta
}
from
"
@/reducers/duel/hintSlice
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
matStore
}
from
"
@/valtioStores
"
;
export
default
(
chaining
:
ygopro
.
StocGameMessage
.
MsgChaining
,
dispatch
:
AppDispatch
...
...
@@ -9,4 +9,8 @@ export default (
dispatch
(
fetchEsHintMeta
({
originMsg
:
"
「[?]」被发动时
"
,
cardID
:
chaining
.
code
})
);
matStore
.
hint
.
fetchEsHintMeta
({
originMsg
:
"
「[?]」被发动时
"
,
cardID
:
chaining
.
code
,
});
};
src/service/duel/draw.ts
View file @
b85b3cab
...
...
@@ -2,9 +2,7 @@ import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import
{
fetchHandsMeta
}
from
"
@/reducers/duel/handsSlice
"
;
import
{
fetchEsHintMeta
}
from
"
@/reducers/duel/hintSlice
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
valtioStore
}
from
"
@/valtioStores
"
;
const
{
matStore
}
=
valtioStore
;
import
{
matStore
}
from
"
@/valtioStores
"
;
export
default
(
draw
:
ygopro
.
StocGameMessage
.
MsgDraw
,
...
...
@@ -13,5 +11,6 @@ export default (
dispatch
(
fetchEsHintMeta
({
originMsg
:
"
玩家抽卡时
"
}));
dispatch
(
fetchHandsMeta
({
controler
:
draw
.
player
,
codes
:
draw
.
cards
}));
matStore
.
hint
.
fetchEsHintMeta
({
originMsg
:
"
玩家抽卡时
"
});
matStore
.
hands
.
add
(
draw
.
player
,
draw
.
cards
);
};
src/service/duel/flipSummoned.ts
View file @
b85b3cab
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
fetchEsHintMeta
}
from
"
@/reducers/duel/hintSlice
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
matStore
}
from
"
@/valtioStores
"
;
export
default
(
_
:
ygopro
.
StocGameMessage
.
MsgFlipSummoned
,
dispatch
:
AppDispatch
)
=>
{
dispatch
(
fetchEsHintMeta
({
originMsg
:
1608
}));
matStore
.
hint
.
fetchEsHintMeta
({
originMsg
:
1608
});
};
src/service/duel/flipSummoning.ts
View file @
b85b3cab
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
fetchEsHintMeta
}
from
"
@/reducers/duel/hintSlice
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
matStore
}
from
"
@/valtioStores
"
;
export
default
(
flipSummoning
:
ygopro
.
StocGameMessage
.
MsgFlipSummoning
,
...
...
@@ -12,4 +13,8 @@ export default (
cardID
:
flipSummoning
.
code
,
})
);
matStore
.
hint
.
fetchEsHintMeta
({
originMsg
:
"
「[?]」反转召唤宣言时
"
,
cardID
:
flipSummoning
.
code
,
});
};
src/service/duel/gameMsg.ts
View file @
b85b3cab
...
...
@@ -43,6 +43,8 @@ import onMsgUpdateHp from "./updateHp";
import
onMsgWait
from
"
./wait
"
;
import
onMsgWin
from
"
./win
"
;
import
{
matStore
}
from
"
@/valtioStores
"
;
const
ActiveList
=
[
"
select_idle_cmd
"
,
"
select_place
"
,
...
...
@@ -62,6 +64,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
if
(
ActiveList
.
includes
(
msg
.
gameMsg
))
{
dispatch
(
setWaiting
(
false
));
matStore
.
waiting
=
false
;
}
switch
(
msg
.
gameMsg
)
{
...
...
src/service/duel/hint.ts
View file @
b85b3cab
...
...
@@ -5,22 +5,31 @@ import {
fetchSelectHintMeta
,
}
from
"
@/reducers/duel/hintSlice
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
matStore
}
from
"
@/valtioStores
"
;
import
MsgHint
=
ygopro
.
StocGameMessage
.
MsgHint
;
export
default
(
hint
:
MsgHint
,
dispatch
:
AppDispatch
)
=>
{
switch
(
hint
.
hint_type
)
{
case
MsgHint
.
HintType
.
HINT_EVENT
:
{
dispatch
(
fetchEsHintMeta
({
originMsg
:
hint
.
hint_data
}));
matStore
.
hint
.
fetchEsHintMeta
({
originMsg
:
hint
.
hint_data
});
break
;
}
case
MsgHint
.
HintType
.
HINT_MESSAGE
:
{
dispatch
(
fetchCommonHintMeta
(
hint
.
hint_data
));
matStore
.
hint
.
fetchCommonHintMeta
(
hint
.
hint_data
);
break
;
}
case
MsgHint
.
HintType
.
HINT_SELECTMSG
:
{
dispatch
(
fetchSelectHintMeta
({
selectHintData
:
hint
.
hint_data
,
esHint
:
""
})
);
matStore
.
hint
.
fetchSelectHintMeta
({
selectHintData
:
hint
.
hint_data
,
esHint
:
""
,
});
break
;
}
default
:
{
...
...
src/service/duel/newPhase.ts
View file @
b85b3cab
...
...
@@ -2,6 +2,8 @@ import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import
{
updatePhase
}
from
"
@/reducers/duel/mod
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
matStore
,
type
PhaseName
}
from
"
@/valtioStores
"
;
export
default
(
newPhase
:
ygopro
.
StocGameMessage
.
MsgNewPhase
,
dispatch
:
AppDispatch
...
...
@@ -11,4 +13,11 @@ export default (
ygopro
.
StocGameMessage
.
MsgNewPhase
.
PhaseType
[
newPhase
.
phase_type
]
)
);
// ts本身还没有这么智能,所以需要手动指定类型
const
currentPhase
=
ygopro
.
StocGameMessage
.
MsgNewPhase
.
PhaseType
[
newPhase
.
phase_type
]
as
PhaseName
;
matStore
.
phase
.
currentPhase
=
currentPhase
;
};
src/service/duel/newTurn.ts
View file @
b85b3cab
...
...
@@ -2,10 +2,13 @@ import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import
{
updateTurn
}
from
"
@/reducers/duel/mod
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
{
matStore
}
from
"
@/valtioStores
"
;
export
default
(
newTurn
:
ygopro
.
StocGameMessage
.
MsgNewTurn
,
dispatch
:
AppDispatch
)
=>
{
const
player
=
newTurn
.
player
;
dispatch
(
updateTurn
(
player
));
matStore
.
currentPlayer
=
player
;
};
src/service/duel/posChange.ts
View file @
b85b3cab
...
...
@@ -3,7 +3,7 @@ import { fetchEsHintMeta } from "@/reducers/duel/hintSlice";
import
{
setMagicPosition
,
setMonsterPosition
}
from
"
@/reducers/duel/mod
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
MsgPosChange
=
ygopro
.
StocGameMessage
.
MsgPosChange
;
import
{
matStore
}
from
"
@/valtioStores
"
;
export
default
(
posChange
:
MsgPosChange
,
dispatch
:
AppDispatch
)
=>
{
const
cardInfo
=
posChange
.
card_info
;
...
...
@@ -16,6 +16,9 @@ export default (posChange: MsgPosChange, dispatch: AppDispatch) => {
position
:
posChange
.
cur_position
,
})
);
matStore
.
monsters
.
at
(
cardInfo
.
controler
)[
cardInfo
.
sequence
].
location
.
position
=
posChange
.
cur_position
;
break
;
}
...
...
@@ -27,6 +30,9 @@ export default (posChange: MsgPosChange, dispatch: AppDispatch) => {
position
:
posChange
.
cur_position
,
})
);
matStore
.
magics
.
at
(
cardInfo
.
controler
)[
cardInfo
.
sequence
].
location
.
position
=
posChange
.
cur_position
;
break
;
}
...
...
src/valtioStores/matStore/index.ts
View file @
b85b3cab
...
...
@@ -2,7 +2,7 @@ export * from "./types";
import
{
proxy
}
from
"
valtio
"
;
import
{
fetchCard
}
from
"
@/api/cards
"
;
import
{
fetchCard
,
type
CardMeta
}
from
"
@/api/cards
"
;
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
type
{
...
...
@@ -11,7 +11,7 @@ import type {
CardsBothSide
,
DuelFieldState
,
InitInfo
,
Play
MatState
,
MatState
,
}
from
"
./types
"
;
import
{
InteractType
}
from
"
./types
"
;
import
{
DESCRIPTION_LIMIT
,
fetchStrings
,
getStrings
}
from
"
@/api/strings
"
;
...
...
@@ -45,7 +45,7 @@ const genBlock = (
};
};
const
initInfo
:
Play
MatState
[
"
initInfo
"
]
=
proxy
({
const
initInfo
:
MatState
[
"
initInfo
"
]
=
proxy
({
me
:
{
masterRule
:
"
UNKNOWN
"
,
life
:
-
1
,
// 特地设置一个不可能的值
...
...
@@ -66,12 +66,13 @@ const initInfo: PlayMatState["initInfo"] = proxy({
},
});
const
hint
:
Play
MatState
[
"
hint
"
]
=
proxy
({
const
hint
:
MatState
[
"
hint
"
]
=
proxy
({
code
:
-
1
,
fetchCommonHintMeta
:
(
hintData
:
number
)
=>
{
return
fetchStrings
(
"
!system
"
,
hintData
);
fetchCommonHintMeta
:
(
code
:
number
)
=>
{
hint
.
code
=
code
;
hint
.
msg
=
fetchStrings
(
"
!system
"
,
code
);
},
fetchSelectHintMeta
:
async
(
selectHintData
:
number
,
esHint
?:
string
)
=>
{
fetchSelectHintMeta
:
async
(
{
selectHintData
,
esHint
}
)
=>
{
let
selectHintMeta
=
""
;
if
(
selectHintData
>
DESCRIPTION_LIMIT
)
{
// 针对`MSG_SELECT_PLACE`的特化逻辑
...
...
@@ -83,28 +84,41 @@ const hint: PlayMatState["hint"] = proxy({
}
else
{
selectHintMeta
=
await
getStrings
(
selectHintData
);
}
return
{
selectHintMeta
,
esHint
,
};
hint
.
code
=
selectHintData
;
if
(
hint
.
code
>
DESCRIPTION_LIMIT
)
{
// 针对`MSG_SELECT_PLACE`的特化逻辑
hint
.
msg
=
selectHintMeta
;
}
else
{
hint
.
esSelectHint
=
selectHintMeta
;
hint
.
esHint
=
esHint
;
}
},
fetchEsHintMeta
:
async
(
_originMsg
:
string
|
number
,
location
?:
ygopro
.
CardLocation
,
cardID
?:
number
)
=>
{
const
originMsg
=
typeof
_originMsg
===
"
string
"
?
_originMsg
:
fetchStrings
(
"
!system
"
,
_originMsg
);
fetchEsHintMeta
:
async
({
originMsg
,
location
,
cardID
})
=>
{
const
newOriginMsg
=
typeof
originMsg
===
"
string
"
?
originMsg
:
fetchStrings
(
"
!system
"
,
originMsg
);
if
(
cardID
)
{
const
cardMeta
=
await
fetchCard
(
cardID
);
const
cardMeta
=
cardID
?
await
fetchCard
(
cardID
)
:
undefined
;
return
{
originMsg
,
cardMeta
,
location
};
}
else
{
return
{
originMsg
,
location
};
let
esHint
=
newOriginMsg
;
if
(
cardMeta
?.
text
.
name
)
{
esHint
=
esHint
.
replace
(
"
[?]
"
,
cardMeta
.
text
.
name
);
}
if
(
location
)
{
const
fieldMeta
=
matStore
.
getZone
(
location
.
location
)
.
at
(
location
.
controler
)
.
at
(
location
.
sequence
);
if
(
fieldMeta
?.
occupant
?.
text
.
name
)
{
esHint
=
esHint
.
replace
(
"
[?]
"
,
fieldMeta
.
occupant
.
text
.
name
);
}
}
hint
.
esHint
=
esHint
;
},
});
...
...
@@ -201,11 +215,35 @@ const wrap = <T extends DuelFieldState>(
return
res
;
};
/**
* zone -> matStore
*/
const
getZone
=
(
zone
:
ygopro
.
CardZone
)
=>
{
switch
(
zone
)
{
case
ygopro
.
CardZone
.
MZONE
:
return
matStore
.
monsters
;
case
ygopro
.
CardZone
.
SZONE
:
return
matStore
.
magics
;
case
ygopro
.
CardZone
.
HAND
:
return
matStore
.
hands
;
case
ygopro
.
CardZone
.
DECK
:
return
matStore
.
decks
;
case
ygopro
.
CardZone
.
GRAVE
:
return
matStore
.
graveyards
;
case
ygopro
.
CardZone
.
REMOVED
:
return
matStore
.
banishedZones
;
case
ygopro
.
CardZone
.
EXTRA
:
return
matStore
.
extraDecks
;
default
:
console
.
error
(
"
in error
"
,
zone
);
return
matStore
.
extraDecks
;
}
};
/**
* 💡 决斗盘状态仓库,本文件核心,
* 具体介绍可以点进`PlayMatState`去看
*/
export
const
matStore
=
proxy
<
Play
MatState
>
({
export
const
matStore
:
MatState
=
proxy
<
MatState
>
({
magics
:
wrap
(
genBlock
(
ygopro
.
CardZone
.
SZONE
,
6
),
ygopro
.
CardZone
.
SZONE
),
monsters
:
wrap
(
genBlock
(
ygopro
.
CardZone
.
MZONE
,
7
),
ygopro
.
CardZone
.
MZONE
),
graveyards
:
wrap
({
me
:
[],
op
:
[]
},
ygopro
.
CardZone
.
GRAVE
),
...
...
@@ -234,6 +272,8 @@ export const matStore = proxy<PlayMatState>({
result
:
ygopro
.
StocGameMessage
.
MsgWin
.
ActionType
.
UNKNOWN
,
waiting
:
false
,
unimplemented
:
0
,
// methods
getZone
,
});
/**
...
...
src/valtioStores/matStore/types.ts
View file @
b85b3cab
...
...
@@ -44,7 +44,7 @@ export interface CardsBothSide<T extends DuelFieldState> extends BothSide<T> {
clearPlaceInteractivity
:
(
controller
:
number
,
sequence
:
number
)
=>
void
;
}
export
interface
Play
MatState
{
export
interface
MatState
{
selfType
:
number
;
initInfo
:
BothSide
<
InitInfo
>
&
{
...
...
@@ -79,7 +79,7 @@ export interface PlayMatState {
unimplemented
:
number
;
// 未处理的`Message`
// remove: (player: number, sequence: number) => void;
getZone
:
(
zone
:
ygopro
.
CardZone
)
=>
CardsBothSide
<
DuelFieldState
>
;
// 是否在某个区域
}
export
interface
InitInfo
{
...
...
@@ -164,27 +164,23 @@ export interface HintState {
}
// 和hint相关的方法
export
interface
HintMethods
{
fetchCommonHintMeta
:
(
hintData
:
number
)
=>
string
;
fetchSelectHintMeta
:
(
selectHintData
:
number
,
esHint
?:
string
)
=>
Promise
<
{
selectHintMeta
:
string
;
fetchCommonHintMeta
:
(
hintData
:
number
)
=>
void
;
fetchSelectHintMeta
:
(
args
:
{
selectHintData
:
number
;
esHint
?:
string
;
}
>
;
fetchEsHintMeta
:
(
originMsg
:
string
|
number
,
location
?:
ygopro
.
CardLocation
,
cardID
?:
number
)
=>
Promise
<
{
originMsg
:
string
;
cardMeta
?:
CardMeta
;
})
=>
Promise
<
void
>
;
fetchEsHintMeta
:
(
args
:
{
originMsg
:
string
|
number
;
location
?:
ygopro
.
CardLocation
;
}
>
;
cardID
?:
number
;
})
=>
Promise
<
void
>
;
}
export
type
PhaseName
=
keyof
typeof
ygopro
.
StocGameMessage
.
MsgNewPhase
.
PhaseType
;
export
interface
PhaseState
{
currentPhase
:
string
;
// TODO 当前的阶段 应该改成enum
currentPhase
:
PhaseName
;
// TODO 当前的阶段 应该改成enum
enableBp
:
boolean
;
// 允许进入战斗阶段
enableM2
:
boolean
;
// 允许进入M2阶段
enableEp
:
boolean
;
// 允许回合结束
...
...
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