Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
W
windbot
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
神之吹息
windbot
Commits
fabdff0e
Commit
fabdff0e
authored
Jun 22, 2016
by
mercury233
Browse files
Options
Browse Files
Download
Plain Diff
Merge
https://github.com/IceYGO/windbot
parents
5363702a
560ccf09
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
110 additions
and
81 deletions
+110
-81
Game/AI/DefaultExecutor.cs
Game/AI/DefaultExecutor.cs
+1
-1
Game/AI/Executor.cs
Game/AI/Executor.cs
+2
-0
Game/ClientCard.cs
Game/ClientCard.cs
+2
-1
Game/GameAI.cs
Game/GameAI.cs
+0
-3
Game/GameBehavior.cs
Game/GameBehavior.cs
+64
-63
Game/GameClient.cs
Game/GameClient.cs
+21
-13
Game/GamePacketFactory.cs
Game/GamePacketFactory.cs
+15
-0
Program.cs
Program.cs
+1
-0
WindBot.csproj
WindBot.csproj
+4
-0
YGOSharp.Network.dll
YGOSharp.Network.dll
+0
-0
No files found.
Game/AI/DefaultExecutor.cs
View file @
fabdff0e
...
@@ -134,7 +134,7 @@ namespace WindBot.Game.AI
...
@@ -134,7 +134,7 @@ namespace WindBot.Game.AI
protected
bool
DefaultTrap
()
protected
bool
DefaultTrap
()
{
{
return
LastChainPlayer
==
1
;
return
LastChainPlayer
==
-
1
||
LastChainPlayer
==
1
;
}
}
protected
bool
DefaultUniqueTrap
()
protected
bool
DefaultUniqueTrap
()
...
...
Game/AI/Executor.cs
View file @
fabdff0e
...
@@ -26,6 +26,8 @@ namespace WindBot.Game.AI
...
@@ -26,6 +26,8 @@ namespace WindBot.Game.AI
Duel
=
duel
;
Duel
=
duel
;
AI
=
ai
;
AI
=
ai
;
Executors
=
new
List
<
CardExecutor
>();
Executors
=
new
List
<
CardExecutor
>();
LastChainPlayer
=
-
1
;
CurrentChain
=
new
List
<
ClientCard
>();
CurrentChain
=
new
List
<
ClientCard
>();
}
}
...
...
Game/ClientCard.cs
View file @
fabdff0e
using
OCGWrapper
;
using
OCGWrapper
;
using
OCGWrapper.Enums
;
using
OCGWrapper.Enums
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
YGOSharp.Network
;
using
YGOSharp.Network
;
namespace
WindBot.Game
namespace
WindBot.Game
...
@@ -54,7 +55,7 @@ namespace WindBot.Game
...
@@ -54,7 +55,7 @@ namespace WindBot.Game
Name
=
Data
.
Name
;
Name
=
Data
.
Name
;
}
}
public
void
Update
(
GamePacket
Reader
packet
,
Duel
duel
)
public
void
Update
(
Binary
Reader
packet
,
Duel
duel
)
{
{
int
flag
=
packet
.
ReadInt32
();
int
flag
=
packet
.
ReadInt32
();
if
((
flag
&
(
int
)
Query
.
Code
)
!=
0
)
if
((
flag
&
(
int
)
Query
.
Code
)
!=
0
)
...
...
Game/GameAI.cs
View file @
fabdff0e
using
OCGWrapper.Enums
;
using
OCGWrapper.Enums
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
WindBot.Game.AI
;
using
WindBot.Game.AI
;
using
YGOSharp.Network
;
namespace
WindBot.Game
namespace
WindBot.Game
{
{
public
class
GameAI
public
class
GameAI
{
{
public
GameClient
Game
{
get
;
private
set
;
}
public
GameClient
Game
{
get
;
private
set
;
}
public
CoreClient
Connection
{
get
;
private
set
;
}
public
Duel
Duel
{
get
;
private
set
;
}
public
Duel
Duel
{
get
;
private
set
;
}
public
Executor
Executor
{
get
;
set
;
}
public
Executor
Executor
{
get
;
set
;
}
public
AIFunctions
Utils
{
get
;
private
set
;
}
public
AIFunctions
Utils
{
get
;
private
set
;
}
...
@@ -18,7 +16,6 @@ namespace WindBot.Game
...
@@ -18,7 +16,6 @@ namespace WindBot.Game
public
GameAI
(
GameClient
game
,
Duel
duel
)
public
GameAI
(
GameClient
game
,
Duel
duel
)
{
{
Game
=
game
;
Game
=
game
;
Connection
=
game
.
Connection
;
Duel
=
duel
;
Duel
=
duel
;
Utils
=
new
AIFunctions
(
duel
);
Utils
=
new
AIFunctions
(
duel
);
...
...
Game/GameBehavior.cs
View file @
fabdff0e
...
@@ -7,19 +7,20 @@ using System.Text.RegularExpressions;
...
@@ -7,19 +7,20 @@ using System.Text.RegularExpressions;
using
WindBot.Game.AI
;
using
WindBot.Game.AI
;
using
YGOSharp.Network
;
using
YGOSharp.Network
;
using
YGOSharp.Network.Enums
;
using
YGOSharp.Network.Enums
;
using
YGOSharp.Network.Utils
;
namespace
WindBot.Game
namespace
WindBot.Game
{
{
public
class
GameBehavior
public
class
GameBehavior
{
{
public
GameClient
Game
{
get
;
private
set
;
}
public
GameClient
Game
{
get
;
private
set
;
}
public
Core
Client
Connection
{
get
;
private
set
;
}
public
YGO
Client
Connection
{
get
;
private
set
;
}
public
Deck
Deck
{
get
;
private
set
;
}
public
Deck
Deck
{
get
;
private
set
;
}
private
GameAI
_ai
;
private
GameAI
_ai
;
private
IDictionary
<
StocMessage
,
Action
<
GamePacket
Reader
>>
_packets
;
private
IDictionary
<
StocMessage
,
Action
<
Binary
Reader
>>
_packets
;
private
IDictionary
<
GameMessage
,
Action
<
GamePacket
Reader
>>
_messages
;
private
IDictionary
<
GameMessage
,
Action
<
Binary
Reader
>>
_messages
;
private
Room
_room
;
private
Room
_room
;
private
Duel
_duel
;
private
Duel
_duel
;
...
@@ -29,8 +30,8 @@ namespace WindBot.Game
...
@@ -29,8 +30,8 @@ namespace WindBot.Game
Game
=
game
;
Game
=
game
;
Connection
=
game
.
Connection
;
Connection
=
game
.
Connection
;
_packets
=
new
Dictionary
<
StocMessage
,
Action
<
GamePacket
Reader
>>();
_packets
=
new
Dictionary
<
StocMessage
,
Action
<
Binary
Reader
>>();
_messages
=
new
Dictionary
<
GameMessage
,
Action
<
GamePacket
Reader
>>();
_messages
=
new
Dictionary
<
GameMessage
,
Action
<
Binary
Reader
>>();
RegisterPackets
();
RegisterPackets
();
_room
=
new
Room
();
_room
=
new
Room
();
...
@@ -46,12 +47,12 @@ namespace WindBot.Game
...
@@ -46,12 +47,12 @@ namespace WindBot.Game
return
_duel
.
IsFirst
?
player
:
1
-
player
;
return
_duel
.
IsFirst
?
player
:
1
-
player
;
}
}
public
void
OnPacket
(
GamePacket
Reader
packet
)
public
void
OnPacket
(
Binary
Reader
packet
)
{
{
StocMessage
id
=
packet
.
ReadStoc
();
StocMessage
id
=
(
StocMessage
)
packet
.
ReadByte
();
if
(
id
==
StocMessage
.
GameMsg
)
if
(
id
==
StocMessage
.
GameMsg
)
{
{
GameMessage
msg
=
(
GameMessage
)
packet
.
ReadByte
();
GameMessage
msg
=
(
GameMessage
)
packet
.
ReadByte
();
if
(
_messages
.
ContainsKey
(
msg
))
if
(
_messages
.
ContainsKey
(
msg
))
_messages
[
msg
](
packet
);
_messages
[
msg
](
packet
);
return
;
return
;
...
@@ -111,9 +112,9 @@ namespace WindBot.Game
...
@@ -111,9 +112,9 @@ namespace WindBot.Game
_messages
.
Add
(
GameMessage
.
AnnounceRace
,
OnAnnounceRace
);
_messages
.
Add
(
GameMessage
.
AnnounceRace
,
OnAnnounceRace
);
}
}
private
void
OnJoinGame
(
GamePacket
Reader
packet
)
private
void
OnJoinGame
(
Binary
Reader
packet
)
{
{
GamePacketWriter
deck
=
new
GamePacketWriter
(
CtosMessage
.
UpdateDeck
);
BinaryWriter
deck
=
GamePacketFactory
.
Create
(
CtosMessage
.
UpdateDeck
);
deck
.
Write
(
Deck
.
Cards
.
Count
+
Deck
.
ExtraCards
.
Count
);
deck
.
Write
(
Deck
.
Cards
.
Count
+
Deck
.
ExtraCards
.
Count
);
deck
.
Write
(
Deck
.
SideCards
.
Count
);
deck
.
Write
(
Deck
.
SideCards
.
Count
);
foreach
(
NamedCard
card
in
Deck
.
Cards
)
foreach
(
NamedCard
card
in
Deck
.
Cards
)
...
@@ -125,7 +126,7 @@ namespace WindBot.Game
...
@@ -125,7 +126,7 @@ namespace WindBot.Game
Connection
.
Send
(
deck
);
Connection
.
Send
(
deck
);
}
}
private
void
OnTypeChange
(
GamePacket
Reader
packet
)
private
void
OnTypeChange
(
Binary
Reader
packet
)
{
{
int
type
=
packet
.
ReadByte
();
int
type
=
packet
.
ReadByte
();
int
pos
=
type
&
0xF
;
int
pos
=
type
&
0xF
;
...
@@ -140,15 +141,15 @@ namespace WindBot.Game
...
@@ -140,15 +141,15 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
HsReady
);
Connection
.
Send
(
CtosMessage
.
HsReady
);
}
}
private
void
OnPlayerEnter
(
GamePacket
Reader
packet
)
private
void
OnPlayerEnter
(
Binary
Reader
packet
)
{
{
string
name
=
packet
.
ReadUnicode
(
20
);
string
name
=
packet
.
ReadUnicode
(
Program
.
PlayerNameSize
);
int
pos
=
packet
.
ReadByte
();
int
pos
=
packet
.
ReadByte
();
if
(
pos
<
8
)
if
(
pos
<
8
)
_room
.
Names
[
pos
]
=
name
;
_room
.
Names
[
pos
]
=
name
;
}
}
private
void
OnPlayerChange
(
GamePacket
Reader
packet
)
private
void
OnPlayerChange
(
Binary
Reader
packet
)
{
{
int
change
=
packet
.
ReadByte
();
int
change
=
packet
.
ReadByte
();
int
pos
=
(
change
>>
4
)
&
0xF
;
int
pos
=
(
change
>>
4
)
&
0xF
;
...
@@ -177,25 +178,25 @@ namespace WindBot.Game
...
@@ -177,25 +178,25 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
HsStart
);
Connection
.
Send
(
CtosMessage
.
HsStart
);
}
}
private
void
OnSelectHand
(
GamePacket
Reader
packet
)
private
void
OnSelectHand
(
Binary
Reader
packet
)
{
{
Connection
.
Send
(
CtosMessage
.
HandResult
,
(
byte
)
Program
.
Rand
.
Next
(
1
,
4
));
Connection
.
Send
(
CtosMessage
.
HandResult
,
(
byte
)
Program
.
Rand
.
Next
(
1
,
4
));
}
}
private
void
OnSelectTp
(
GamePacket
Reader
packet
)
private
void
OnSelectTp
(
Binary
Reader
packet
)
{
{
bool
start
=
_ai
.
OnSelectHand
();
bool
start
=
_ai
.
OnSelectHand
();
Connection
.
Send
(
CtosMessage
.
TpResult
,
(
byte
)(
start
?
1
:
0
));
Connection
.
Send
(
CtosMessage
.
TpResult
,
(
byte
)(
start
?
1
:
0
));
}
}
private
void
OnTimeLimit
(
GamePacket
Reader
packet
)
private
void
OnTimeLimit
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
if
(
player
==
0
)
if
(
player
==
0
)
Connection
.
Send
(
CtosMessage
.
TimeConfirm
);
Connection
.
Send
(
CtosMessage
.
TimeConfirm
);
}
}
private
void
OnReplay
(
GamePacket
Reader
packet
)
private
void
OnReplay
(
Binary
Reader
packet
)
{
{
byte
[]
replay
=
packet
.
ReadToEnd
();
byte
[]
replay
=
packet
.
ReadToEnd
();
...
@@ -213,18 +214,18 @@ namespace WindBot.Game
...
@@ -213,18 +214,18 @@ namespace WindBot.Game
Connection
.
Close
();
Connection
.
Close
();
}
}
private
void
OnDuelEnd
(
GamePacket
Reader
packet
)
private
void
OnDuelEnd
(
Binary
Reader
packet
)
{
{
Connection
.
Close
();
Connection
.
Close
();
}
}
private
void
OnChat
(
GamePacket
Reader
packet
)
private
void
OnChat
(
Binary
Reader
packet
)
{
{
packet
.
ReadInt16
();
// player
packet
.
ReadInt16
();
// player
packet
.
ReadUnicode
(
256
);
// message
packet
.
ReadUnicode
(
256
);
// message
}
}
private
void
OnStart
(
GamePacket
Reader
packet
)
private
void
OnStart
(
Binary
Reader
packet
)
{
{
int
type
=
packet
.
ReadByte
();
int
type
=
packet
.
ReadByte
();
_duel
.
IsFirst
=
(
type
&
0xF
)
==
0
;
_duel
.
IsFirst
=
(
type
&
0xF
)
==
0
;
...
@@ -241,7 +242,7 @@ namespace WindBot.Game
...
@@ -241,7 +242,7 @@ namespace WindBot.Game
_ai
.
OnStart
();
_ai
.
OnStart
();
}
}
private
void
OnWin
(
GamePacket
Reader
packet
)
private
void
OnWin
(
Binary
Reader
packet
)
{
{
int
result
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
result
=
GetLocalPlayer
(
packet
.
ReadByte
());
...
@@ -250,7 +251,7 @@ namespace WindBot.Game
...
@@ -250,7 +251,7 @@ namespace WindBot.Game
Logger
.
WriteLine
(
"Duel finished against "
+
otherName
+
", result: "
+
textResult
);
Logger
.
WriteLine
(
"Duel finished against "
+
otherName
+
", result: "
+
textResult
);
}
}
private
void
OnDraw
(
GamePacket
Reader
packet
)
private
void
OnDraw
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
count
=
packet
.
ReadByte
();
int
count
=
packet
.
ReadByte
();
...
@@ -262,14 +263,14 @@ namespace WindBot.Game
...
@@ -262,14 +263,14 @@ namespace WindBot.Game
}
}
}
}
private
void
OnShuffleDeck
(
GamePacket
Reader
packet
)
private
void
OnShuffleDeck
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
foreach
(
ClientCard
card
in
_duel
.
Fields
[
player
].
Deck
)
foreach
(
ClientCard
card
in
_duel
.
Fields
[
player
].
Deck
)
card
.
SetId
(
0
);
card
.
SetId
(
0
);
}
}
private
void
OnShuffleHand
(
GamePacket
Reader
packet
)
private
void
OnShuffleHand
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
packet
.
ReadByte
();
packet
.
ReadByte
();
...
@@ -277,20 +278,20 @@ namespace WindBot.Game
...
@@ -277,20 +278,20 @@ namespace WindBot.Game
card
.
SetId
(
packet
.
ReadInt32
());
card
.
SetId
(
packet
.
ReadInt32
());
}
}
private
void
OnNewTurn
(
GamePacket
Reader
packet
)
private
void
OnNewTurn
(
Binary
Reader
packet
)
{
{
_duel
.
Turn
++;
_duel
.
Turn
++;
_duel
.
Player
=
GetLocalPlayer
(
packet
.
ReadByte
());
_duel
.
Player
=
GetLocalPlayer
(
packet
.
ReadByte
());
_ai
.
OnNewTurn
();
_ai
.
OnNewTurn
();
}
}
private
void
OnNewPhase
(
GamePacket
Reader
packet
)
private
void
OnNewPhase
(
Binary
Reader
packet
)
{
{
_duel
.
Phase
=
(
DuelPhase
)
packet
.
ReadInt16
();
_duel
.
Phase
=
(
DuelPhase
)
packet
.
ReadInt16
();
_ai
.
OnNewPhase
();
_ai
.
OnNewPhase
();
}
}
private
void
OnDamage
(
GamePacket
Reader
packet
)
private
void
OnDamage
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
final
=
_duel
.
LifePoints
[
player
]
-
packet
.
ReadInt32
();
int
final
=
_duel
.
LifePoints
[
player
]
-
packet
.
ReadInt32
();
...
@@ -298,19 +299,19 @@ namespace WindBot.Game
...
@@ -298,19 +299,19 @@ namespace WindBot.Game
_duel
.
LifePoints
[
player
]
=
final
;
_duel
.
LifePoints
[
player
]
=
final
;
}
}
private
void
OnRecover
(
GamePacket
Reader
packet
)
private
void
OnRecover
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
_duel
.
LifePoints
[
player
]
+=
packet
.
ReadInt32
();
_duel
.
LifePoints
[
player
]
+=
packet
.
ReadInt32
();
}
}
private
void
OnLpUpdate
(
GamePacket
Reader
packet
)
private
void
OnLpUpdate
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
_duel
.
LifePoints
[
player
]
=
packet
.
ReadInt32
();
_duel
.
LifePoints
[
player
]
=
packet
.
ReadInt32
();
}
}
private
void
OnMove
(
GamePacket
Reader
packet
)
private
void
OnMove
(
Binary
Reader
packet
)
{
{
int
cardId
=
packet
.
ReadInt32
();
int
cardId
=
packet
.
ReadInt32
();
int
pc
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
pc
=
GetLocalPlayer
(
packet
.
ReadByte
());
...
@@ -354,7 +355,7 @@ namespace WindBot.Game
...
@@ -354,7 +355,7 @@ namespace WindBot.Game
}
}
}
}
private
void
OnPosChange
(
GamePacket
Reader
packet
)
private
void
OnPosChange
(
Binary
Reader
packet
)
{
{
packet
.
ReadInt32
();
// card id
packet
.
ReadInt32
();
// card id
int
pc
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
pc
=
GetLocalPlayer
(
packet
.
ReadByte
());
...
@@ -367,7 +368,7 @@ namespace WindBot.Game
...
@@ -367,7 +368,7 @@ namespace WindBot.Game
card
.
Position
=
cp
;
card
.
Position
=
cp
;
}
}
private
void
OnChaining
(
GamePacket
Reader
packet
)
private
void
OnChaining
(
Binary
Reader
packet
)
{
{
packet
.
ReadInt32
();
// card id
packet
.
ReadInt32
();
// card id
int
pcc
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
pcc
=
GetLocalPlayer
(
packet
.
ReadByte
());
...
@@ -379,18 +380,18 @@ namespace WindBot.Game
...
@@ -379,18 +380,18 @@ namespace WindBot.Game
_ai
.
OnChaining
(
card
,
cc
);
_ai
.
OnChaining
(
card
,
cc
);
}
}
private
void
OnChainEnd
(
GamePacket
Reader
packet
)
private
void
OnChainEnd
(
Binary
Reader
packet
)
{
{
_ai
.
OnChainEnd
();
_ai
.
OnChainEnd
();
}
}
private
void
OnChainSorting
(
GamePacket
Reader
packet
)
private
void
OnChainSorting
(
Binary
Reader
packet
)
{
{
GamePacketWriter
writer
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
writer
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
Connection
.
Send
(
CtosMessage
.
Response
,
-
1
);
Connection
.
Send
(
CtosMessage
.
Response
,
-
1
);
}
}
private
void
OnUpdateCard
(
GamePacket
Reader
packet
)
private
void
OnUpdateCard
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
loc
=
packet
.
ReadByte
();
int
loc
=
packet
.
ReadByte
();
...
@@ -401,10 +402,10 @@ namespace WindBot.Game
...
@@ -401,10 +402,10 @@ namespace WindBot.Game
ClientCard
card
=
_duel
.
GetCard
(
player
,
(
CardLocation
)
loc
,
seq
);
ClientCard
card
=
_duel
.
GetCard
(
player
,
(
CardLocation
)
loc
,
seq
);
if
(
card
==
null
)
return
;
if
(
card
==
null
)
return
;
card
.
Update
(
packet
,
_duel
);
card
.
Update
(
packet
,
_duel
);
}
}
private
void
OnUpdateData
(
GamePacket
Reader
packet
)
private
void
OnUpdateData
(
Binary
Reader
packet
)
{
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
CardLocation
loc
=
(
CardLocation
)
packet
.
ReadByte
();
CardLocation
loc
=
(
CardLocation
)
packet
.
ReadByte
();
...
@@ -440,14 +441,14 @@ namespace WindBot.Game
...
@@ -440,14 +441,14 @@ namespace WindBot.Game
{
{
int
len
=
packet
.
ReadInt32
();
int
len
=
packet
.
ReadInt32
();
if
(
len
==
4
)
continue
;
if
(
len
==
4
)
continue
;
long
pos
=
packet
.
Position
;
long
pos
=
packet
.
BaseStream
.
Position
;
card
.
Update
(
packet
,
_duel
);
card
.
Update
(
packet
,
_duel
);
packet
.
Position
=
pos
+
len
-
4
;
packet
.
BaseStream
.
Position
=
pos
+
len
-
4
;
}
}
}
}
}
}
private
void
OnSelectBattleCmd
(
GamePacket
Reader
packet
)
private
void
OnSelectBattleCmd
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
_duel
.
BattlePhase
=
new
BattlePhase
();
_duel
.
BattlePhase
=
new
BattlePhase
();
...
@@ -494,7 +495,7 @@ namespace WindBot.Game
...
@@ -494,7 +495,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectBattleCmd
(
battle
).
ToValue
());
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectBattleCmd
(
battle
).
ToValue
());
}
}
private
void
InternalOnSelectCard
(
GamePacket
Reader
packet
,
Func
<
IList
<
ClientCard
>,
int
,
int
,
bool
,
IList
<
ClientCard
>>
func
)
private
void
InternalOnSelectCard
(
Binary
Reader
packet
,
Func
<
IList
<
ClientCard
>,
int
,
int
,
bool
,
IList
<
ClientCard
>>
func
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
bool
cancelable
=
packet
.
ReadByte
()
!=
0
;
bool
cancelable
=
packet
.
ReadByte
()
!=
0
;
...
@@ -546,17 +547,17 @@ namespace WindBot.Game
...
@@ -546,17 +547,17 @@ namespace WindBot.Game
result
[
i
+
1
]
=
(
byte
)
id
;
result
[
i
+
1
]
=
(
byte
)
id
;
}
}
GamePacketWriter
reply
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
reply
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
reply
.
Write
(
result
);
reply
.
Write
(
result
);
Connection
.
Send
(
reply
);
Connection
.
Send
(
reply
);
}
}
private
void
OnSelectCard
(
GamePacket
Reader
packet
)
private
void
OnSelectCard
(
Binary
Reader
packet
)
{
{
InternalOnSelectCard
(
packet
,
_ai
.
OnSelectCard
);
InternalOnSelectCard
(
packet
,
_ai
.
OnSelectCard
);
}
}
private
void
OnSelectChain
(
GamePacket
Reader
packet
)
private
void
OnSelectChain
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
int
count
=
packet
.
ReadByte
();
int
count
=
packet
.
ReadByte
();
...
@@ -596,7 +597,7 @@ namespace WindBot.Game
...
@@ -596,7 +597,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectChain
(
cards
,
descs
,
forced
));
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectChain
(
cards
,
descs
,
forced
));
}
}
private
void
OnSelectCounter
(
GamePacket
Reader
packet
)
private
void
OnSelectCounter
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
int
type
=
packet
.
ReadInt16
();
int
type
=
packet
.
ReadInt16
();
...
@@ -620,17 +621,17 @@ namespace WindBot.Game
...
@@ -620,17 +621,17 @@ namespace WindBot.Game
byte
[]
result
=
new
byte
[
used
.
Count
];
byte
[]
result
=
new
byte
[
used
.
Count
];
for
(
int
i
=
0
;
i
<
quantity
;
++
i
)
for
(
int
i
=
0
;
i
<
quantity
;
++
i
)
result
[
i
]
=
(
byte
)
used
[
i
];
result
[
i
]
=
(
byte
)
used
[
i
];
GamePacketWriter
reply
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
reply
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
reply
.
Write
(
result
);
reply
.
Write
(
result
);
Connection
.
Send
(
reply
);
Connection
.
Send
(
reply
);
}
}
private
void
OnSelectDisfield
(
GamePacket
Reader
packet
)
private
void
OnSelectDisfield
(
Binary
Reader
packet
)
{
{
OnSelectPlace
(
packet
);
OnSelectPlace
(
packet
);
}
}
private
void
OnSelectEffectYn
(
GamePacket
Reader
packet
)
private
void
OnSelectEffectYn
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
...
@@ -653,7 +654,7 @@ namespace WindBot.Game
...
@@ -653,7 +654,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
}
}
private
void
OnSelectIdleCmd
(
GamePacket
Reader
packet
)
private
void
OnSelectIdleCmd
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
...
@@ -718,7 +719,7 @@ namespace WindBot.Game
...
@@ -718,7 +719,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectIdleCmd
(
main
).
ToValue
());
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectIdleCmd
(
main
).
ToValue
());
}
}
private
void
OnSelectOption
(
GamePacket
Reader
packet
)
private
void
OnSelectOption
(
Binary
Reader
packet
)
{
{
IList
<
int
>
options
=
new
List
<
int
>();
IList
<
int
>
options
=
new
List
<
int
>();
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
...
@@ -728,7 +729,7 @@ namespace WindBot.Game
...
@@ -728,7 +729,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectOption
(
options
));
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectOption
(
options
));
}
}
private
void
OnSelectPlace
(
GamePacket
Reader
packet
)
private
void
OnSelectPlace
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// min
packet
.
ReadByte
();
// min
...
@@ -792,12 +793,12 @@ namespace WindBot.Game
...
@@ -792,12 +793,12 @@ namespace WindBot.Game
if
((
filter
&
0x2
)
!=
0
)
resp
[
2
]
=
7
;
if
((
filter
&
0x2
)
!=
0
)
resp
[
2
]
=
7
;
}
}
GamePacketWriter
reply
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
reply
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
reply
.
Write
(
resp
);
reply
.
Write
(
resp
);
Connection
.
Send
(
reply
);
Connection
.
Send
(
reply
);
}
}
private
void
OnSelectPosition
(
GamePacket
Reader
packet
)
private
void
OnSelectPosition
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
int
cardId
=
packet
.
ReadInt32
();
int
cardId
=
packet
.
ReadInt32
();
...
@@ -819,7 +820,7 @@ namespace WindBot.Game
...
@@ -819,7 +820,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
(
int
)
_ai
.
OnSelectPosition
(
cardId
,
positions
));
Connection
.
Send
(
CtosMessage
.
Response
,
(
int
)
_ai
.
OnSelectPosition
(
cardId
,
positions
));
}
}
private
void
OnSelectSum
(
GamePacket
Reader
packet
)
private
void
OnSelectSum
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// mode
packet
.
ReadByte
();
// mode
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
...
@@ -878,24 +879,24 @@ namespace WindBot.Game
...
@@ -878,24 +879,24 @@ namespace WindBot.Game
result
[
index
++]
=
(
byte
)
id
;
result
[
index
++]
=
(
byte
)
id
;
}
}
GamePacketWriter
reply
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
reply
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
reply
.
Write
(
result
);
reply
.
Write
(
result
);
Connection
.
Send
(
reply
);
Connection
.
Send
(
reply
);
}
}
private
void
OnSelectTribute
(
GamePacket
Reader
packet
)
private
void
OnSelectTribute
(
Binary
Reader
packet
)
{
{
InternalOnSelectCard
(
packet
,
_ai
.
OnSelectTribute
);
InternalOnSelectCard
(
packet
,
_ai
.
OnSelectTribute
);
}
}
private
void
OnSelectYesNo
(
GamePacket
Reader
packet
)
private
void
OnSelectYesNo
(
Binary
Reader
packet
)
{
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
int
reply
=
_ai
.
OnSelectYesNo
(
packet
.
ReadInt32
())
?
(
1
)
:
(
0
);
int
reply
=
_ai
.
OnSelectYesNo
(
packet
.
ReadInt32
())
?
(
1
)
:
(
0
);
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
}
}
private
void
OnAnnounceAttrib
(
GamePacket
Reader
packet
)
private
void
OnAnnounceAttrib
(
Binary
Reader
packet
)
{
{
IList
<
CardAttribute
>
attributes
=
new
List
<
CardAttribute
>();
IList
<
CardAttribute
>
attributes
=
new
List
<
CardAttribute
>();
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
...
@@ -915,12 +916,12 @@ namespace WindBot.Game
...
@@ -915,12 +916,12 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
}
}
private
void
OnAnnounceCard
(
GamePacket
Reader
packet
)
private
void
OnAnnounceCard
(
Binary
Reader
packet
)
{
{
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnAnnounceCard
());
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnAnnounceCard
());
}
}
private
void
OnAnnounceNumber
(
GamePacket
Reader
packet
)
private
void
OnAnnounceNumber
(
Binary
Reader
packet
)
{
{
IList
<
int
>
numbers
=
new
List
<
int
>();
IList
<
int
>
numbers
=
new
List
<
int
>();
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
...
@@ -930,7 +931,7 @@ namespace WindBot.Game
...
@@ -930,7 +931,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnAnnounceNumber
(
numbers
));
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnAnnounceNumber
(
numbers
));
}
}
private
void
OnAnnounceRace
(
GamePacket
Reader
packet
)
private
void
OnAnnounceRace
(
Binary
Reader
packet
)
{
{
IList
<
CardRace
>
races
=
new
List
<
CardRace
>();
IList
<
CardRace
>
races
=
new
List
<
CardRace
>();
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// player
...
...
Game/GameClient.cs
View file @
fabdff0e
using
System.Text
;
using
System.IO
;
using
System.Net
;
using
System.Text
;
using
YGOSharp.Network
;
using
YGOSharp.Network
;
using
YGOSharp.Network.Enums
;
using
YGOSharp.Network.Enums
;
using
YGOSharp.Network.Utils
;
namespace
WindBot.Game
namespace
WindBot.Game
{
{
public
class
GameClient
public
class
GameClient
{
{
public
Core
Client
Connection
{
get
;
private
set
;
}
public
YGO
Client
Connection
{
get
;
private
set
;
}
public
string
Username
;
public
string
Username
;
public
string
Deck
;
public
string
Deck
;
...
@@ -27,40 +30,45 @@ namespace WindBot.Game
...
@@ -27,40 +30,45 @@ namespace WindBot.Game
public
void
Start
()
public
void
Start
()
{
{
Connection
=
new
CoreClient
(
_serverHost
,
_serverPort
);
Connection
=
new
YGOClient
();
Connection
.
MessageReceived
+=
OnMessageReceived
;
_behavior
=
new
GameBehavior
(
this
);
_behavior
=
new
GameBehavior
(
this
);
GamePacketWriter
packet
=
new
GamePacketWriter
(
CtosMessage
.
PlayerInfo
);
Connection
.
Connected
+=
OnConnected
;
packet
.
Write
(
Username
,
20
);
Connection
.
PacketReceived
+=
OnPacketReceived
;
Connection
.
Connect
(
IPAddress
.
Parse
(
_serverHost
),
_serverPort
);
}
private
void
OnConnected
()
{
BinaryWriter
packet
=
GamePacketFactory
.
Create
(
CtosMessage
.
PlayerInfo
);
packet
.
WriteUnicode
(
Username
,
Program
.
PlayerNameSize
);
Connection
.
Send
(
packet
);
Connection
.
Send
(
packet
);
byte
[]
junk
=
{
0xCC
,
0xCC
,
0x00
,
0x00
,
0x00
,
0x00
};
byte
[]
junk
=
{
0xCC
,
0xCC
,
0x00
,
0x00
,
0x00
,
0x00
};
packet
=
new
GamePacketWriter
(
CtosMessage
.
JoinGame
);
packet
=
GamePacketFactory
.
Create
(
CtosMessage
.
JoinGame
);
packet
.
Write
(
Program
.
ProVersion
);
packet
.
Write
(
Program
.
ProVersion
);
packet
.
Write
(
junk
);
packet
.
Write
(
junk
);
packet
.
Write
(
_roomInfos
,
30
);
packet
.
Write
Unicode
(
_roomInfos
,
30
);
Connection
.
Send
(
packet
);
Connection
.
Send
(
packet
);
}
}
public
void
Tick
()
public
void
Tick
()
{
{
Connection
.
UpdateNetwork
();
Connection
.
Update
();
Connection
.
Update
();
}
}
public
void
Chat
(
string
message
)
public
void
Chat
(
string
message
)
{
{
byte
[]
content
=
Encoding
.
Unicode
.
GetBytes
(
message
+
"\0"
);
byte
[]
content
=
Encoding
.
Unicode
.
GetBytes
(
message
+
"\0"
);
GamePacketWriter
chat
=
new
GamePacketWriter
(
CtosMessage
.
Chat
);
BinaryWriter
chat
=
GamePacketFactory
.
Create
(
CtosMessage
.
Chat
);
chat
.
Write
(
content
);
chat
.
Write
(
content
);
Connection
.
Send
(
chat
);
Connection
.
Send
(
chat
);
}
}
private
void
On
MessageReceived
(
object
sender
,
MessageEventArgs
e
)
private
void
On
PacketReceived
(
BinaryReader
reader
)
{
{
_behavior
.
OnPacket
(
e
.
Message
);
_behavior
.
OnPacket
(
reader
);
}
}
}
}
}
}
\ No newline at end of file
Game/GamePacketFactory.cs
0 → 100644
View file @
fabdff0e
using
System.IO
;
using
YGOSharp.Network.Enums
;
namespace
WindBot.Game
{
public
class
GamePacketFactory
{
public
static
BinaryWriter
Create
(
CtosMessage
message
)
{
BinaryWriter
writer
=
new
BinaryWriter
(
new
MemoryStream
());
writer
.
Write
((
byte
)
message
);
return
writer
;
}
}
}
Program.cs
View file @
fabdff0e
...
@@ -10,6 +10,7 @@ namespace WindBot
...
@@ -10,6 +10,7 @@ namespace WindBot
public
class
Program
public
class
Program
{
{
public
static
short
ProVersion
=
Int16
.
Parse
(
Environment
.
GetEnvironmentVariable
(
"YGOPRO_VERSION"
));
public
static
short
ProVersion
=
Int16
.
Parse
(
Environment
.
GetEnvironmentVariable
(
"YGOPRO_VERSION"
));
public
static
int
PlayerNameSize
=
20
;
internal
static
Random
Rand
;
internal
static
Random
Rand
;
...
...
WindBot.csproj
View file @
fabdff0e
...
@@ -31,6 +31,9 @@
...
@@ -31,6 +31,9 @@
<ErrorReport>
prompt
</ErrorReport>
<ErrorReport>
prompt
</ErrorReport>
<CodeAnalysisRuleSet>
MinimumRecommendedRules.ruleset
</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>
MinimumRecommendedRules.ruleset
</CodeAnalysisRuleSet>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup>
<StartupObject
/>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"Mono.Data.Sqlite"
>
<Reference
Include=
"Mono.Data.Sqlite"
>
<HintPath>
.\Mono.Data.Sqlite.dll
</HintPath>
<HintPath>
.\Mono.Data.Sqlite.dll
</HintPath>
...
@@ -82,6 +85,7 @@
...
@@ -82,6 +85,7 @@
<Compile
Include=
"Game\GameAI.cs"
/>
<Compile
Include=
"Game\GameAI.cs"
/>
<Compile
Include=
"Game\GameBehavior.cs"
/>
<Compile
Include=
"Game\GameBehavior.cs"
/>
<Compile
Include=
"Game\GameClient.cs"
/>
<Compile
Include=
"Game\GameClient.cs"
/>
<Compile
Include=
"Game\GamePacketFactory.cs"
/>
<Compile
Include=
"Game\MainPhase.cs"
/>
<Compile
Include=
"Game\MainPhase.cs"
/>
<Compile
Include=
"Game\MainPhaseAction.cs"
/>
<Compile
Include=
"Game\MainPhaseAction.cs"
/>
<Compile
Include=
"Game\Room.cs"
/>
<Compile
Include=
"Game\Room.cs"
/>
...
...
YGOSharp.Network.dll
View file @
fabdff0e
No preview for this file type
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