Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cd908d7af | ||
|
|
c0dfa8ef19 | ||
|
|
fa14698115 | ||
|
|
8a73120dbb | ||
|
|
c2eca90644 | ||
|
|
bcd19c9cd0 | ||
|
|
10ade7fc41 |
No files matched your search
@@ -5,6 +5,37 @@ wire protocol, the engine message stream, the setup pairs and the Lua API. A row
|
||||
change first shipped in the Unity repo, the ticket, and the contract part it touched. Rows 0001-0024
|
||||
are the fork patches replayed into this repo as commits (`git log --oneline -- server/gframe core`).
|
||||
|
||||
## v1.6.0 — 2026-11-02
|
||||
|
||||
Tag shared Extra Deck (proposal 53): a setup pair gives a Tag team one Extra Deck, and each card keeps the partner who
|
||||
brought it. No new export or message; capability `0x4000`, protocol 11: exports 335 / 856 / 850, capabilities `0x77FF`.
|
||||
|
||||
| Date | Change | Ticket | Contract part |
|
||||
|---|---|---|---|
|
||||
| 2026-11-02 | Core: option `DUEL_TAG_SHARED_EXTRA` `0x200`: `start_duel` moves `tag_list_extra` into `list_extra` and renumbers, for both teams; `tag_swap` skips its Extra block. `card::tag_member` (0 `new_card`, 1 `new_tag_card`), `QUERY_TAG_MEMBER` `0x1000000` written last in `get_infos`. Bit `0x100000` stays unused: old flags set it with no value. | TICKET-433 | (a) `start_duel` option; (c) Query records |
|
||||
| 2026-11-02 | Server: `ygol.tag.extra=shared` is the fourth server-read pair. `TagDuel` sets the option in `opt`, sends the sum of both partners' Extra Decks in the opening `MSG_START`, runs the opening `RefreshExtra` after `start_duel`, and adds `QUERY_TAG_MEMBER` in `RefreshExtra`. `FEATURE_TAG_SHARED_EXTRA` `0x4000` advertised by Single and Tag rooms, protocol 10 -> 11; a Tag room refuses a joiner without the bit. | TICKET-433 | Wire: capability bit `0x4000`, protocol 11; (d) setup pair `ygol.tag.extra`; `0x5F` Extra count 0 in such a duel |
|
||||
| 2026-11-02 | Binding: `FeatureFlags.TagSharedExtra` (in `All`), `Capability.ProtocolVersion` 11. Probe: the tag shared Extra Deck rooms (pair present, pair absent, a Summon of the waiting partner's monster, the replay played back through the library, the Tag refusal, the Single room that keeps an old client). | TICKET-433 | (e) C# binding |
|
||||
|
||||
## v1.5.0 — 2026-10-24
|
||||
|
||||
Tag two Field slots (proposal 45): a Tag team on Master Rule 4/5 holds one Field Spell per partner. No new
|
||||
export or message; capability `0x1000`, protocol 10: exports 335 / 856 / 850, capabilities `0x37FF`.
|
||||
|
||||
| Date | Change | Ticket | Contract part |
|
||||
|---|---|---|---|
|
||||
| 2026-10-24 | Core: `field::has_two_fields()` (`DUEL_TAG_MODE` on Master Rule 4 or 5) gives each team a Field slot per partner, Spell/Trap sequence 5 for the partner who plays the team's first turn and 6 for the other (`player_info::tag_partner`, flipped in `tag_swap`; `get_szone_size` is 7 there). A Field Spell lands in the playing partner's slot (`get_fzone_landing`) and replaces only that card; a control change takes the free slot when the playing partner's is taken. A Set offers only the landing slot's bit. `LOCATION_FZONE` covers both slots in `card_state::is_location`, `filter_matching_card`, `filter_field_card`, `is_location_useable` and `Duel.IsEnvironment`; `get_field_card(p, LOCATION_FZONE, 0)` is the playing partner's field, else the other, and 1 the remaining one. Singles, Match and Master Rule 3 unchanged. | TICKET-384 | (c) `MSG_MOVE` / `MSG_RELOAD_FIELD` carry Spell/Trap sequence 6 (rules only); (d) Lua API: a second answer for `Duel.GetFieldCard` / `Duel.CheckLocation` with `LOCATION_FZONE` |
|
||||
| 2026-10-24 | Server: `FEATURE_TAG_TWO_FIELDS` `0x1000` advertised by Single and Tag rooms, protocol 9 -> 10; a Tag room answers a `CTOS_CAPABILITY` without the bit with `STOC_ERROR_MSG` `ERRMSG_VERERROR` and closes the connection (`TagDuel::Capability`). | TICKET-384 | Wire: capability bit `0x1000`, protocol 10 |
|
||||
| 2026-10-24 | Binding: `FeatureFlags.TagTwoFields` (in `All`), `Capability.ProtocolVersion` 10. Probe: the tag two Field slots rooms (a Tag room's placement on turns 1, 3 and 5 with the core's own view reported by the Probe Field's script, the Tag refusal, the Single room that keeps an old client). | TICKET-384 | (e) C# binding |
|
||||
|
||||
## v1.4.2 — 2026-10-24
|
||||
|
||||
Tag partner cards follow every change. Same message, same payload, no new export or capability bit:
|
||||
exports 335 / 856 / 850, protocol 9, capabilities `0x27FF`.
|
||||
|
||||
| Date | Change | Ticket | Contract part |
|
||||
|---|---|---|---|
|
||||
| 2026-10-24 | `STOC_TAG_PARTNER_CARDS 0x5F` has a fourth send point: after every engine batch (beside `FlushDeckLists`, not when the duel ended) `TagDuel::FlushTagPartnerCards` queries `ygol_query_tag_cards` per side and broadcasts it when the bytes differ from the last broadcast for that side (a Summon out of the waiting member's Extra Deck, Time Fusion), to the same receivers. Every broadcast (start, swap, change) records its bytes; a resync to one player does not. Server. | TICKET-424 | Wire `0x5F` |
|
||||
|
||||
## v1.4.1 — 2026-10-16
|
||||
|
||||
Tag: a card the waiting partner holds can be moved. No new export or capability bit: exports 335 / 856 /
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace YGOLegacy.Protocol.Tests
|
||||
Assert.That((int)StocCodecs.SeatResumeResult.Id, Is.EqualTo(0x57));
|
||||
Assert.That((int)StocCodecs.RestartOpened.Id, Is.EqualTo(0x58));
|
||||
Assert.That(FeatureFlags.RulesRestart, Is.EqualTo(0x10));
|
||||
Assert.That(FeatureFlags.All, Is.EqualTo(0x27FB));
|
||||
Assert.That(FeatureFlags.All, Is.EqualTo(0x77FB));
|
||||
|
||||
var id = Enumerable.Repeat((byte)0xAB, 16).ToArray();
|
||||
var token = Enumerable.Range(1, 16).Select(i => (byte)i).ToArray();
|
||||
@@ -272,13 +272,27 @@ namespace YGOLegacy.Protocol.Tests
|
||||
Assert.Throws<EndOfStreamException>(() => StocCodecs.AttackPreview.Read(Reader(new byte[] { 1 })));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TagTwoFields_Flag_IsPinned_0x1000()
|
||||
{
|
||||
Assert.That(FeatureFlags.TagTwoFields, Is.EqualTo(0x1000));
|
||||
Assert.That(FeatureFlags.All & FeatureFlags.TagTwoFields, Is.EqualTo(FeatureFlags.TagTwoFields));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TagSharedExtra_Flag_AndProtocol_ArePinned_0x4000_11()
|
||||
{
|
||||
Assert.That(FeatureFlags.TagSharedExtra, Is.EqualTo(0x4000));
|
||||
Assert.That(FeatureFlags.All & FeatureFlags.TagSharedExtra, Is.EqualTo(FeatureFlags.TagSharedExtra));
|
||||
Assert.That(Capability.ProtocolVersion, Is.EqualTo(11));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TagPartnerCards_Id_Flag_Protocol_AndRoundTrip_ArePinned_0x5F_0x2000_9()
|
||||
{
|
||||
Assert.That((int)StocCodecs.TagPartnerCards.Id, Is.EqualTo(0x5F));
|
||||
Assert.That(FeatureFlags.TagPartnerCards, Is.EqualTo(0x2000));
|
||||
Assert.That(FeatureFlags.All & FeatureFlags.TagPartnerCards, Is.EqualTo(FeatureFlags.TagPartnerCards));
|
||||
Assert.That(Capability.ProtocolVersion, Is.EqualTo(9));
|
||||
Assert.That(TagPartnerCardsCodec.HeaderSize, Is.EqualTo(7));
|
||||
|
||||
var faceUpPendulum = 0x80000000u | 16178681u;
|
||||
@@ -422,7 +436,7 @@ namespace YGOLegacy.Protocol.Tests
|
||||
{
|
||||
var bytes = Bytes(w => LobbyCodecs.Capability.Write(w, new Capability(Capability.ProtocolVersion, FeatureFlags.All)));
|
||||
|
||||
Assert.That(bytes, Is.EqualTo(Concat(Le16(9), Le32(0x27FB))));
|
||||
Assert.That(bytes, Is.EqualTo(Concat(Le16(11), Le32(0x77FB))));
|
||||
|
||||
var read = LobbyCodecs.Capability.Read(Reader(bytes));
|
||||
Assert.That(read.Protocol, Is.EqualTo(Capability.ProtocolVersion));
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
{
|
||||
public const uint Appearance = 0x1;
|
||||
public const uint Dialogue = 0x2;
|
||||
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview | TagPartnerCards;
|
||||
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview | TagTwoFields | TagPartnerCards | TagSharedExtra;
|
||||
// Server-only: the host relays setup pairs (0x43); a client never advertises it.
|
||||
public const uint SetupPairs = 0x4;
|
||||
// Server: chosen seats (0x50-0x53). Client: it renders the seat plan.
|
||||
@@ -25,8 +25,12 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
public const uint Profile = 0x200;
|
||||
// Server: attack preview (0x5E): the seat whose battle prompt is open asks for its pairs, the host's core answers. Client: it shows the badge.
|
||||
public const uint AttackPreview = 0x400;
|
||||
// Server: tag partner cards (0x5F): the waiting teammate's hand, Extra Deck and deck go to that side's two seats. Client: the partner view shows them. 0x800 and 0x1000 are reserved by proposals 44 and 45.
|
||||
// Server: Tag on Master Rule 4/5 gives each partner a Field slot (Spell/Trap sequence 5 and 6); a Tag room refuses a joiner without the bit. Client: it shows sequence 6 as the Field Zone and refuses a host without the bit. 0x800 is reserved by proposal 44.
|
||||
public const uint TagTwoFields = 0x1000;
|
||||
// Server: tag partner cards (0x5F): the waiting teammate's hand, Extra Deck and deck go to that side's two seats. Client: the partner view shows them.
|
||||
public const uint TagPartnerCards = 0x2000;
|
||||
// Server: with the setup pair ygol.tag.extra=shared a Tag team has one Extra Deck and its Extra Deck refreshes carry the partner each card came from; a Tag room refuses a joiner without the bit. Client: it reads the value and refuses a host without the bit.
|
||||
public const uint TagSharedExtra = 0x4000;
|
||||
// Client role, not a feature: set only on the room host's own line, so every peer can badge the host's seat.
|
||||
public const uint RoomHost = 0x80000000;
|
||||
}
|
||||
@@ -56,7 +60,7 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
|
||||
public readonly struct Capability
|
||||
{
|
||||
public const ushort ProtocolVersion = 9;
|
||||
public const ushort ProtocolVersion = 11;
|
||||
public const int ServerSender = 0xFF;
|
||||
|
||||
public ushort Protocol { get; }
|
||||
|
||||
+37
-13
@@ -26,8 +26,8 @@ next to the library (`out/win64/engine.json` on Windows):
|
||||
{
|
||||
"version": "v0.0.1",
|
||||
"exports": 335,
|
||||
"protocol": 9,
|
||||
"capabilities": 10239,
|
||||
"protocol": 11,
|
||||
"capabilities": 30719,
|
||||
"binding": "v0.0.1"
|
||||
}
|
||||
```
|
||||
@@ -36,8 +36,8 @@ next to the library (`out/win64/engine.json` on Windows):
|
||||
|---|---|---|
|
||||
| `version` | string | The `-Version` the build was given; `local` when none. The same string `ygol_engine_version()` returns. |
|
||||
| `exports` | integer | The library's export count after the gate passed (Windows: 335). |
|
||||
| `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (9 as of 2026-10-15). |
|
||||
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 10239 = `0x27FF` = bits `0x1` to `0x400` plus `0x2000` (`0x800` and `0x1000` are reserved by proposals 44 and 45). |
|
||||
| `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (11 as of 2026-11-02). |
|
||||
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 30719 = `0x77FF` = bits `0x1` to `0x400` plus `0x1000`, `0x2000` and `0x4000` (`0x800` is reserved by proposal 44). |
|
||||
| `binding` | string | The version of the C# binding released with this engine (section (e)); the same string as `version`. |
|
||||
|
||||
The build reads `protocol` and `capabilities` from the source every time; nothing types them in.
|
||||
@@ -93,7 +93,7 @@ The host string is space-separated tokens, in this order (`server/gframe/gframe.
|
||||
| `create_duel_v2` | `intptr_t create_duel_v2(uint32_t seed_sequence[])` | Upstream (`SEED_COUNT` = 8 words) |
|
||||
| `create_duel_ex` | `intptr_t create_duel_ex(uint_fast32_t seed, uint32_t create_flags)` | Upstream |
|
||||
| `create_duel_v2_ex` | `intptr_t create_duel_v2_ex(uint32_t seed_sequence[], uint32_t create_flags)` | Upstream |
|
||||
| `start_duel` | `void start_duel(intptr_t pduel, uint32_t options)` | Upstream |
|
||||
| `start_duel` | `void start_duel(intptr_t pduel, uint32_t options)` | Upstream. v1.6.0: option `DUEL_TAG_SHARED_EXTRA` `0x200` with `DUEL_TAG_MODE` merges each team's Extra Decks (section (b), behaviour v1.6.0). |
|
||||
| `end_duel` | `void end_duel(intptr_t pduel)` | Upstream |
|
||||
| `set_player_info` | `void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount)` | Upstream |
|
||||
| `get_log_message` | `void get_log_message(intptr_t pduel, char* buf)` | Upstream |
|
||||
@@ -165,9 +165,11 @@ the server itself speaks. The STOC form of a relayed message is always the CTOS
|
||||
stamp in front. "Stamp" in the tables below says whether the STOC message carries one.
|
||||
|
||||
**Capability.** The server sends `STOC_CAPABILITY` (stamp `0xFF`) to every connection between
|
||||
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (9) and `flags` = the OR of
|
||||
the bits below (`0x27FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a
|
||||
host without bit `0x4` as out of date.
|
||||
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (11) and `flags` = the OR of
|
||||
the bits below (`0x77FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a
|
||||
host without bit `0x4` as out of date, and without bit `0x1000` too (v1.5.0). A Tag room refuses a
|
||||
client whose `CTOS_CAPABILITY` lacks `0x1000` or `0x4000` (v1.6.0): `STOC_ERROR_MSG` `ERRMSG_VERERROR`
|
||||
(code = `FEATURE_PROTOCOL`), then the connection is closed; a Single room keeps it.
|
||||
|
||||
**Join snapshot.** A joiner gets, per occupied seat, right after that seat's `STOC_HS_PLAYER_ENTER`:
|
||||
the seat's stored capability, appearance (0006), seat state (0013) and profile (0020) when present,
|
||||
@@ -214,7 +216,7 @@ duelist's own side (v1.2.0), both sides for an observer when spectators see all
|
||||
| `0x5C` | `STOC_DECK_LIST` | `STOC_DeckList` (5): `u8 version` (1), `u8 side`, `u8 kind`, `u16 count`, then `u32 codes[count]` | No | Kind 0 (the deck's remaining cards, SORTED) to its owner (both teammates in Tag); kind 1 (real order, top first) and kind 2 (the submitted Main Deck of the duelist whose deck is in the zone, sorted) to observers only when spectators see all. Sent when a list differs from the last one that audience got; in the late-watcher snapshot | `0x100` | 6 | 0019 |
|
||||
| `0x5D` | `STOC_PROFILE` | `u16 sender` + `CTOS_Profile` (100) | Yes | Everyone; stored per seat, in the snapshot after APPEARANCE, swapped with the seat, kept across the 0014 lobby reset, cleared when the seat empties | `0x200` | 7 | 0020 |
|
||||
| `0x5E` | `STOC_ATTACK_PREVIEW` | `u8 version` (1), `u8 count`, then per pair the 4 ask bytes echoed + the 24-byte `ygol_preview_attack` answer | No | The asker only. Only attackers the open prompt listed; a pair the engine refuses is left out (the count shrinks); a valid ask whose every pair is left out still gets count 0 | `0x400` | 8 | 0023 |
|
||||
| `0x5F` | `STOC_TAG_PARTNER_CARDS` | `u8 side` + the `ygol_query_tag_cards` bytes (7 + 4 x the three counts) | No | The two seats of `side`, never the other team. Sent after `start_duel` (the waiting members' opening hands), after every `MSG_TAG_SWAP` for the side that swapped (the member that just left is the waiting one), and to a seated duelist in its field resync (`CTOS_REQUEST_FIELD`, after the `MSG_RELOAD_FIELD`). **v1.3.0 (TICKET-412): when spectators see all (no `ygol.room.spectatorview=hidden`), every observer gets the same bytes for BOTH sides at the start and after every swap, and an observer's field resync and a late watcher's snapshot carry both sides (after the deck lists); with the pair, an observer never gets one.** Tag rooms only; a Single / Match room never sends it | `0x2000` | 9 | v1.2.0, v1.3.0 |
|
||||
| `0x5F` | `STOC_TAG_PARTNER_CARDS` | `u8 side` + the `ygol_query_tag_cards` bytes (7 + 4 x the three counts) | No | The two seats of `side`, never the other team. Sent after `start_duel` (the waiting members' opening hands), after every `MSG_TAG_SWAP` for the side that swapped (the member that just left is the waiting one), and to a seated duelist in its field resync (`CTOS_REQUEST_FIELD`, after the `MSG_RELOAD_FIELD`). **v1.3.0 (TICKET-412): when spectators see all (no `ygol.room.spectatorview=hidden`), every observer gets the same bytes for BOTH sides at the start and after every swap, and an observer's field resync and a late watcher's snapshot carry both sides (after the deck lists); with the pair, an observer never gets one.** **v1.4.2 (TICKET-424): after every engine batch (beside the deck lists, not when the duel ended), a side whose bytes differ from the last ones broadcast for it is sent again to the same receivers (an effect that moves a waiting member's card mid-turn); every broadcast records its bytes, so a swap is never sent twice; a resync to one player does not record.** Tag rooms only; a Single / Match room never sends it | `0x2000` | 9 | v1.2.0, v1.3.0, v1.4.2 |
|
||||
|
||||
### Capability bits and protocol numbers
|
||||
|
||||
@@ -232,8 +234,9 @@ duelist's own side (v1.2.0), both sides for an observer when spectators see all
|
||||
| `0x200` | `FEATURE_PROFILE` | 7 | 0020 | Profile |
|
||||
| `0x400` | `FEATURE_ATTACK_PREVIEW` | 8 | 0023 | Attack preview over the wire |
|
||||
| `0x800` | reserved | - | - | Proposal 44 (agreed, not shipped) |
|
||||
| `0x1000` | reserved | - | - | Proposal 45 (agreed, not shipped) |
|
||||
| `0x1000` | `FEATURE_TAG_TWO_FIELDS` | 10 | v1.5.0 | Tag two Field slots: Spell/Trap sequence 6 is a team's second Field Zone (no message); a Tag room refuses a joiner without it |
|
||||
| `0x2000` | `FEATURE_TAG_PARTNER_CARDS` | 9 | v1.2.0 | Tag partner cards (`STOC_TAG_PARTNER_CARDS`, `ygol_query_tag_cards`) |
|
||||
| `0x4000` | `FEATURE_TAG_SHARED_EXTRA` | 11 | v1.6.0 | Tag shared Extra Deck: the setup pair `ygol.tag.extra=shared`, `QUERY_TAG_MEMBER` on Extra Deck refreshes; a Tag room refuses a joiner without it |
|
||||
|
||||
`FEATURE_PROTOCOL` is bumped by every patch that adds a message a client must understand; the join
|
||||
list hides hosts older than the client's number. Rule 4 (proposal 47): one feature, one door. Never
|
||||
@@ -252,6 +255,8 @@ carry a new feature inside another feature's message.
|
||||
| v1.1.1 | Tag: no Battle Phase on turns 1, 2 and 3 (1A, 2A, 1B); the fourth duelist (2B) is the first who can battle. `MSG_SELECT_IDLECMD` carries `to_bp` = 0 on those turns and `Duel.IsAbleToEnterBP` answers false. Single duels: turn 1 only, as stock. |
|
||||
| v1.3.0 | Tag partner cards reach observers: when spectators see all, `STOC_TAG_PARTNER_CARDS` goes to every observer for both sides at every send point, plus both sides in an observer's resync and the late-watcher snapshot. Same id, same payload, no new capability bit (TICKET-412). |
|
||||
| v1.4.0 | Life points per side: with the setup pair `ygol.side.b.lp=<n>` (section (d)) seat side B (seat 1; Tag seats 2 and 3) starts at `n` LP and side A at slot 8; without it both sides start at slot 8, as before. `set_player_info` gets each duel player its own LP, and `MSG_START` (the start and the late-watcher snapshot) carries `lp[0]`, `lp[1]` in duel player order: the side that goes first is player 0, so the two values swap when side B won the toss. `STOC_JOIN_GAME`'s `start_lp` stays side A's. Single, Match (every duel) and Tag; no new message, no capability bit. |
|
||||
| v1.5.0 | Tag two Field slots (proposal 45, TICKET-384; core `field::has_two_fields` = `DUEL_TAG_MODE` on Master Rule 4 or 5): a team has a Field slot per partner, Spell/Trap sequence 5 for the partner who plays the team's first turn and 6 for the other (`player_info::tag_partner` flips in `tag_swap`). A Field Spell that lands (activated, Set, `Duel.MoveToField` to `LOCATION_FZONE`) goes to the playing partner's slot and replaces only the card there; one that changes control while that slot is taken and the other is free takes the free one. A Set opens only the landing slot's bit in `MSG_SELECT_PLACE`. `LOCATION_FZONE` covers both slots (`Card.IsLocation`, `Duel.GetMatchingGroup` and the other filters, `Duel.IsEnvironment`, `Duel.CheckLocation(p, LOCATION_FZONE, 0/1)`), `Duel.GetFieldCard(p, LOCATION_FZONE, 0)` is the playing partner's field, else the other one, and sequence 1 the remaining one; `Duel.GetFieldCard(p, LOCATION_SZONE, 6)` works. The second field reaches a client as `MSG_MOVE` to Spell/Trap sequence 6 and in `MSG_RELOAD_FIELD`'s sixth Spell/Trap entry: no new message. Singles, Match and Master Rule 3 (where slot 6 is a Pendulum Zone) are unchanged. Scripts that name Spell/Trap sequence 5 by number see one field (the TICKET-384 closing note lists them). Capability `0x1000`, protocol 9 -> 10. |
|
||||
| v1.6.0 | Tag shared Extra Deck (proposal 53, TICKET-433): with the setup pair `ygol.tag.extra=shared` (section (d)) `TagDuel` sets the duel option `DUEL_TAG_SHARED_EXTRA` `0x200`. `start_duel` moves each team's `tag_list_extra` into `list_extra` (the first partner's cards first) and renumbers the sequences, so either partner can Summon any of the cards; `tag_swap` leaves the Extra Deck alone, `MSG_TAG_SWAP` keeps its layout and sends the one list, and `ygol_query_tag_cards` / `0x5F` report an Extra count of 0. The opening `MSG_START` carries the sum of both partners' Extra Decks, and the opening Extra Deck refreshes run after `start_duel`. The core has one `owner` per team, so each card has `card::tag_member`, set once when it is loaded (0 `new_card`, 1 `new_tag_card`), and `RefreshExtra` adds `QUERY_TAG_MEMBER` to its flag in such a duel (section (c), Query records). Replays need no format change: `opt` holds the option and every reader passes `opt` to `start_duel`; a reader that writes its own `MSG_START` before `start_duel` must add the partner's Extra count. An older engine ignores the option and plays such a replay wrongly. Without the pair every stream is unchanged. Capability `0x4000`, protocol 10 -> 11. |
|
||||
|
||||
### Replay
|
||||
|
||||
@@ -376,6 +381,21 @@ fork-related rows are marked.
|
||||
Ids 6, 7 and 34 are server-side (`network.h`); the core's `common.h` lists the rest. Any other id is
|
||||
an error for the consumer.
|
||||
|
||||
### Query records
|
||||
|
||||
`query_card`, `query_field_card` and the query buffer of `MSG_UPDATE_DATA` / `MSG_UPDATE_CARD` hold one
|
||||
record per card: `i32 length`, `u32 flag`, then one value per set `QUERY_*` bit in bit order, the bits
|
||||
in `core/common.h`. The fork adds one bit:
|
||||
|
||||
| Bit | Name | Value | Since |
|
||||
|---|---|---|---|
|
||||
| `0x1000000` | `QUERY_TAG_MEMBER` | `u32`, written LAST, after `QUERY_LINK`: the partner who brought the card, 0 from `new_card`, 1 from `new_tag_card`. It never changes when the card moves. The core writes it for any caller that sets the bit; the server sets it only on `RefreshExtra` in a duel with `ygol.tag.extra=shared` | v1.6.0 |
|
||||
|
||||
**Bit `0x100000` stays unused.** Old flags set it with no value after it: `RefreshSingle`'s default
|
||||
`0xf81fff`, the hand refresh `0x181fff` and YGOSharp's `0xFFFFFF` mask, and saved `.yrp3d` replays are
|
||||
recorded streams of them. A value for that bit would shift every later field of those records, with no
|
||||
error.
|
||||
|
||||
## (d) Setup pairs and the Lua API
|
||||
|
||||
### Setup pairs (patch 0009, TICKET-258; ADR 0004 in the Unity repo)
|
||||
@@ -387,13 +407,14 @@ never interprets a pair: it stores the ordered list (max 64 pairs, 512 bytes eac
|
||||
`0x40000000`) and sends them to every joiner as `STOC_SETUP_PAIRS` (`0x43`). Values that need `,`,
|
||||
`=`, `%` or a space are percent-encoded by the client (`MatchSetup.cs`).
|
||||
|
||||
Three pairs ARE read by the server itself:
|
||||
Four pairs ARE read by the server itself:
|
||||
|
||||
| Key | Value | Read by |
|
||||
|---|---|---|
|
||||
| `ygol.room.watchers` | `0` = no observers: every observer join and HsToObserver is refused | 0012 |
|
||||
| `ygol.room.spectatorview` | `hidden` = the stock masked observer stream; absent = spectators see all | 0018, 0019 |
|
||||
| `ygol.side.b.lp` | a positive integer: seat side B's start LP (seat 1; Tag seats 2 and 3); side A keeps slot 8. Absent, `0`, negative or not a number = both sides at slot 8 | v1.4.0 |
|
||||
| `ygol.tag.extra` | `shared` = a Tag team has one Extra Deck (option `0x200`, section (b) v1.6.0); anything else or absent = separate Extra Decks. A Single or Match room ignores it | v1.6.0 |
|
||||
|
||||
Keys the Unity client sends today (`Assets/YGOLegacy/Scripts/Core/Duel/MatchSetup.cs`,
|
||||
`SetupPairKeys`); the rules Lua reads them from the registry:
|
||||
@@ -414,7 +435,10 @@ into `contract/lua-reference/`: `api-card.md`, `api-duel.md`, `api-effect.md`, `
|
||||
the core sets). A name that is not there is not in the core; the card scripts' `library/` defines the
|
||||
rest. Regenerate with `python contract/lua-reference/generate.py` after any core change to those
|
||||
files and commit the result with it. The fork's core patches add no Lua function (0001 adds the
|
||||
setcode `0xFDF`, `SETCODE_FACEDOWN_TOKEN`, as a cdb convention, not an API).
|
||||
setcode `0xFDF`, `SETCODE_FACEDOWN_TOKEN`, as a cdb convention, not an API). v1.5.0 gives two
|
||||
existing calls a second answer in Tag on Master Rule 4/5: `Duel.GetFieldCard(p, LOCATION_FZONE, 1)`
|
||||
is the other partner's field and `Duel.CheckLocation(p, LOCATION_FZONE, 1)` asks about its slot
|
||||
(both say nothing elsewhere, as before).
|
||||
|
||||
## (e) C# binding
|
||||
|
||||
@@ -429,7 +453,7 @@ Namespaces:
|
||||
|
||||
| Namespace | What |
|
||||
|---|---|
|
||||
| `YGOLegacy.Protocol.{Contracts, Codecs, Framing, Routing}` | Section (b) in C#: the message ids and payload records, the CTOS / STOC codecs, the frame codec and the STOC router. Unchanged from the Unity repo (TICKET-397); v1.2.0 adds `StocMessage.TagPartnerCards`, `FeatureFlags.TagPartnerCards`, the `TagPartnerCards` record and `StocCodecs.TagPartnerCards`, and `Capability.ProtocolVersion` is 9; v1.4.0 adds `ReplayFlags` (`SetupPairs` = `0x40000000`, `SideLp` = `0x20000000`). |
|
||||
| `YGOLegacy.Protocol.{Contracts, Codecs, Framing, Routing}` | Section (b) in C#: the message ids and payload records, the CTOS / STOC codecs, the frame codec and the STOC router. Unchanged from the Unity repo (TICKET-397); v1.2.0 adds `StocMessage.TagPartnerCards`, `FeatureFlags.TagPartnerCards`, the `TagPartnerCards` record and `StocCodecs.TagPartnerCards`, and `Capability.ProtocolVersion` is 9; v1.4.0 adds `ReplayFlags` (`SetupPairs` = `0x40000000`, `SideLp` = `0x20000000`); v1.5.0 adds `FeatureFlags.TagTwoFields` (`0x1000`, in `All`) and `Capability.ProtocolVersion` is 10. |
|
||||
| `YGOLegacy.Engine` | The four types below (TICKET-398). |
|
||||
|
||||
| Type | What |
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
# a seat that never asks gets no 0x5E and the duel goes on. Single and Tag.
|
||||
#
|
||||
# With --dll it also gates v1.2.0 (TICKET-405, tag partner cards): the server's
|
||||
# capability says protocol 9 + flag 0x2000 (single and tag); in a Tag room each
|
||||
# capability said protocol 9 + flag 0x2000 (single and tag; 10 / 0x1000 since v1.5.0); in a Tag room each
|
||||
# seat gets TAG_PARTNER_CARDS (0x5F: side, version 1, hand count, extra count,
|
||||
# pad, u16 deck count, then the hand, Extra Deck and deck codes) for its own side
|
||||
# only -- at the start the waiting member's 5-card opening hand, its two Probe
|
||||
@@ -143,6 +143,36 @@
|
||||
# side B won the toss), and the replay has flag 0x20000000 with the same two
|
||||
# values after opt. Every other room's replay has no such flag.
|
||||
#
|
||||
# With --dll it also gates v1.4.2 (TICKET-424, tag partner cards on change): in
|
||||
# the TICKET-415 room the Fusion seat 3 picked leaves seat 3's Extra Deck in
|
||||
# seat 2's Standby Phase of turn 6, while seat 3 waits; between that
|
||||
# MSG_SPSUMMONING and the next MSG_TAG_SWAP seats 2 and 3 get exactly one
|
||||
# TAG_PARTNER_CARDS, for side 1 with an empty Extra Deck, and seats 0 and 1 none.
|
||||
#
|
||||
# With --dll it also gates v1.5.0 (proposal 45 / TICKET-384, Tag two Field slots):
|
||||
# the capability says protocol 10 + flag 0x1000 (single and tag); a Tag room
|
||||
# refuses a joiner whose CTOS_CAPABILITY lacks 0x1000 (ERROR_MSG VERERROR, then
|
||||
# disconnected) and keeps one that has it, a Single room keeps both; in a Tag room
|
||||
# seat 0's Field Spell lands in Spell/Trap sequence 5 on turn 1, seat 1's in
|
||||
# sequence 6 on turn 3 while the first stays, and seat 0's next Field on turn 5
|
||||
# sends only the sequence-5 card to the Graveyard. The Field's own script reports
|
||||
# in a HINT what the core sees: LOCATION_FZONE counts both slots,
|
||||
# Duel.GetFieldCard(tp, LOCATION_FZONE, 0) is the playing partner's field and 1
|
||||
# the other, Duel.IsEnvironment and Card.IsLocation see sequence 6.
|
||||
#
|
||||
# With --dll it also gates v1.6.0 (proposal 53 / TICKET-433, Tag shared Extra Deck):
|
||||
# the capability says protocol 11 + flag 0x4000 (single and tag); a Tag room
|
||||
# refuses a joiner whose CTOS_CAPABILITY lacks 0x4000, a Single room keeps it. With
|
||||
# ygol.tag.extra=shared MSG_START carries the sum of both partners' Extra Decks,
|
||||
# the opening Extra Deck refresh lists all of them with QUERY_TAG_MEMBER 0x1000000
|
||||
# (0 from seat 0 / 2, 1 from seat 1 / 3; the other team's masked copy has flag 0),
|
||||
# 0x5F reports an Extra count of 0, seat 0 Summons seat 1's monster on turn 1,
|
||||
# seat 1 returns it on turn 3, and the value is still 1 in the refresh after the
|
||||
# swap of turn 5; a late watcher's snapshot refresh has the values; no
|
||||
# other query carries the bit; the replay has option 0x200 and plays back through
|
||||
# the library to the same Summons. Without the pair the partners' lists stay
|
||||
# apart and no query carries the bit.
|
||||
#
|
||||
# Exit 0 only when every check passed. Stock DLL: the first check fails; the
|
||||
# 0011 DLL fails at the capability flags.
|
||||
import argparse, base64, ctypes, lzma, os, shutil, socket, sqlite3, struct, sys, tempfile, threading, time
|
||||
@@ -288,7 +318,7 @@ def check_snapshot(who, pkts, expect_seat_appearance, forbid_seat):
|
||||
check(len(server_caps) == 1 and j < server_caps[0][0] < t, "%s: the server's CAPABILITY(0xFF) sits between JOIN_GAME and TYPE_CHANGE" % who)
|
||||
if server_caps:
|
||||
proto, flags = struct.unpack_from("<HI", server_caps[0][1], 2)
|
||||
check(proto == 9 and flags == 0x27FF, "%s: server capability is protocol 9, flags 0x27FF (appearance | dialogue | setup pairs | seat plan | rules restart | seat state | lobby after match | coin toss | deck lists | profile | attack preview | tag partner cards), got %d / 0x%x" % (who, proto, flags))
|
||||
check(proto == 11 and flags == 0x77FF, "%s: server capability is protocol 11, flags 0x77FF (appearance | dialogue | setup pairs | seat plan | rules restart | seat state | lobby after match | coin toss | deck lists | profile | attack preview | tag two fields | tag partner cards | tag shared extra), got %d / 0x%x" % (who, proto, flags))
|
||||
for seat, expected in expect_seat_appearance.items():
|
||||
enters = [i for i, (p, d) in enumerate(pkts) if p == STOC_HS_PLAYER_ENTER and d[40] == seat]
|
||||
apps = [i for i, (p, d) in enumerate(pkts) if p == STOC_APPEARANCE and struct.unpack_from("<H", d, 0)[0] == seat]
|
||||
@@ -350,6 +380,8 @@ def main():
|
||||
attack_preview_suite(o.dll, port + 100)
|
||||
tag_partner_suite(o.dll, port + 110)
|
||||
tag_across_swap_suite(o.dll, port + 120)
|
||||
tag_two_fields_suite(o.dll, port + 130)
|
||||
tag_shared_extra_suite(o.dll, port + 140)
|
||||
print()
|
||||
if failures:
|
||||
print("FAILED: %d check(s)" % len(failures))
|
||||
@@ -532,6 +564,25 @@ def make_workspace():
|
||||
db.close()
|
||||
with open(os.path.join(root, "script", "c%d.lua" % PROBE_TIME_FUSION), "w", newline="\n") as f:
|
||||
f.write(TIME_FUSION_LUA)
|
||||
# proposal 45 (TICKET-384): a Field Spell, so a Tag team can hold one per partner
|
||||
db = sqlite3.connect(os.path.join(root, "cards.cdb"))
|
||||
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 524290, 0, 0, 0, 0, 0, 0)", (PROBE_FIELD,))
|
||||
db.execute("INSERT INTO texts VALUES(?, 'Probe Field', ''" + ", ''" * 16 + ")", (PROBE_FIELD,))
|
||||
db.commit()
|
||||
db.close()
|
||||
with open(os.path.join(root, "script", "c%d.lua" % PROBE_FIELD), "w", newline="\n") as f:
|
||||
f.write(FIELD_LUA)
|
||||
# proposal 53 (TICKET-433): a Fusion per seat and a Spell that Summons one or returns it
|
||||
db = sqlite3.connect(os.path.join(root, "cards.cdb"))
|
||||
for i, code in enumerate(PROBE_SEAT_FUSIONS):
|
||||
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 65, 2000, 2000, 6, 1, 16, 0)", (code,))
|
||||
db.execute("INSERT INTO texts VALUES(?, 'Probe Seat Fusion %d', ''" % i + ", ''" * 16 + ")", (code,))
|
||||
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0)", (PROBE_EXTRA_SPELL,))
|
||||
db.execute("INSERT INTO texts VALUES(?, 'Probe Extra Spell', ''" + ", ''" * 16 + ")", (PROBE_EXTRA_SPELL,))
|
||||
db.commit()
|
||||
db.close()
|
||||
with open(os.path.join(root, "script", "c%d.lua" % PROBE_EXTRA_SPELL), "w", newline="\n") as f:
|
||||
f.write(EXTRA_SPELL_LUA)
|
||||
return root
|
||||
|
||||
|
||||
@@ -1115,7 +1166,7 @@ def restart_room(dll_path, port, label, mode):
|
||||
pk = drain_all([h, g, w])
|
||||
check(not statuses(pk[g]) and not restarting(pk[h]), "%s: a non-host's Prepare is ignored" % label)
|
||||
for c in (h, g, w):
|
||||
c.send(CTOS_CAPABILITY, capability_bytes(2, 0x1F))
|
||||
c.send(CTOS_CAPABILITY, capability_bytes(2, 0x1F | FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_SHARED_EXTRA)) # a Tag room refuses a client without 0x1000 (proposal 45) or 0x4000 (proposal 53)
|
||||
drain_all([h, g, w])
|
||||
h.send(CTOS_RESTART_PREPARE, prepare_bytes(rid, 30000, seats + 1, [ta, tb], tw))
|
||||
pk = drain_all([h, g, w])
|
||||
@@ -2664,7 +2715,7 @@ def tag_partner_room(dll_path, port, label, hidden):
|
||||
everyone = seated + [w]
|
||||
check([c.seat for c in everyone] == [0, 1, 2, 3, OBSERVER], "%s: four seats and a watcher (%r)" % (label, [c.seat for c in everyone]))
|
||||
cap = server_capability(seated[0].log)
|
||||
check(cap == (9, 0x27FF), "%s: the tag server's capability is protocol 9, flags 0x27FF (got %s)" % (label, cap))
|
||||
check(cap == (11, 0x77FF), "%s: the tag server's capability is protocol 11, flags 0x77FF (got %s)" % (label, cap))
|
||||
drain_all(everyone)
|
||||
for c in seated:
|
||||
c.send(CTOS_UPDATE_DECK, deck_bytes(TAG_PARTNER_DECKS[c.seat]))
|
||||
@@ -2958,6 +3009,18 @@ def tag_across_swap_room(dll_path, port, label):
|
||||
check(state["retries"] == 0, "%s: no answer was refused (MSG_RETRY x%d)" % (label, state["retries"]))
|
||||
ok = play(lambda: state["swap8"] is not None, limit=20)
|
||||
check(ok and state["swap8"] is not None and state["swap8"][3] == 0, "%s: the swap of turn 8 brings seat 3 back with an empty Extra Deck: the Fusion left the list that held it (%s)" % (label, None if state["swap8"] is None else state["swap8"][3]))
|
||||
for c in seated:
|
||||
# TICKET-424: the waiting member's Extra Deck changed mid-turn, so its side's seats get the new bytes once
|
||||
log = c.log
|
||||
start = next((i for i, (p, d) in enumerate(log) if p == 0x01 and d and d[0] == MSG_SPSUMMONING and struct.unpack_from("<I", d, 1)[0] == PROBE_FUSION), None)
|
||||
if not check(start is not None, "%s: seat %d saw the Fusion's MSG_SPSUMMONING" % (label, c.seat)):
|
||||
continue
|
||||
end = next((i for i in range(start + 1, len(log)) if log[i][0] == 0x01 and log[i][1] and log[i][1][0] == MSG_TAG_SWAP), len(log))
|
||||
got = partner_cards(log[start + 1:end])
|
||||
if c.seat >= 2:
|
||||
check(len(got) == 1 and got[0][0] == 1 and got[0][3] == [], "%s: seat %d got exactly one TAG_PARTNER_CARDS after the Summon out of the waiting partner's Extra Deck, side 1 with an empty Extra Deck (%s)" % (label, c.seat, [(g[0], g[3]) for g in got]))
|
||||
else:
|
||||
check(not got, "%s: seat %d (the other team) got no TAG_PARTNER_CARDS for the change (%d)" % (label, c.seat, len(got)))
|
||||
check(all(not c.closed for c in seated), "%s: every seat is still connected" % label)
|
||||
marks = marks_of(seated)
|
||||
for c in seated[:2]:
|
||||
@@ -2977,5 +3040,577 @@ def tag_across_swap_suite(dll_path, port):
|
||||
print("hosting the tag card across the swap room from %s" % dll_path)
|
||||
tag_across_swap_room(dll_path, port, "tag")
|
||||
|
||||
# --- proposal 45 (TICKET-384): Tag two Field slots ---------------------------------------------
|
||||
# In Tag on Master Rule 4/5 each partner has a Field slot: Spell/Trap sequence 5 for the partner
|
||||
# who plays the team's first turn, 6 for the other. A Field Spell lands in the playing partner's
|
||||
# slot and replaces only that slot; LOCATION_FZONE covers both. Capability 0x1000, protocol 10; a
|
||||
# Tag room refuses a client whose capability lacks the bit, a Single room does not care.
|
||||
FEATURE_TAG_TWO_FIELDS = 0x1000
|
||||
PROBE_FIELD = PROBE_CARD + 800
|
||||
MSG_MOVE, MSG_HINT, HINT_CARD, LOCATION_SZONE, LOCATION_GRAVE = 50, 2, 10, 0x08, 0x10
|
||||
STOC_ERROR_MSG, ERRMSG_VERERROR = 0x02, 0x4
|
||||
FIELD_LUA = """--Probe Field (proposal 45): a Field Spell with no effect of its own. On activation it reports what the core
|
||||
--sees of its team's Field Zone in one MSG_HINT (HINT_CARD): bits 0-3 = Duel.GetFieldGroupCount(tp, LOCATION_FZONE),
|
||||
--0x10 GetFieldCard(FZONE, 0) exists, 0x20 GetFieldCard(FZONE, 1) exists, 0x40 IsEnvironment, 0x80 IsLocation(FZONE),
|
||||
--0x100 GetFieldCard(FZONE, 0) is this card, 0x200 CheckLocation(FZONE, 1), bits 12+ = this card's sequence.
|
||||
local s,id,o=GetID()
|
||||
function s.initial_effect(c)
|
||||
local e1=Effect.CreateEffect(c)
|
||||
e1:SetType(EFFECT_TYPE_ACTIVATE)
|
||||
e1:SetCode(EVENT_FREE_CHAIN)
|
||||
e1:SetOperation(s.activate)
|
||||
c:RegisterEffect(e1)
|
||||
end
|
||||
function s.activate(e,tp,eg,ep,ev,re,r,rp)
|
||||
local c=e:GetHandler()
|
||||
local f0=Duel.GetFieldCard(tp,LOCATION_FZONE,0)
|
||||
local f1=Duel.GetFieldCard(tp,LOCATION_FZONE,1)
|
||||
local v=Duel.GetFieldGroupCount(tp,LOCATION_FZONE,0)
|
||||
if f0 then v=v+0x10 end
|
||||
if f1 then v=v+0x20 end
|
||||
if Duel.IsEnvironment(id,tp,LOCATION_FZONE) then v=v+0x40 end
|
||||
if c:IsLocation(LOCATION_FZONE) then v=v+0x80 end
|
||||
if f0==c then v=v+0x100 end
|
||||
if Duel.CheckLocation(tp,LOCATION_FZONE,1) then v=v+0x200 end
|
||||
v=v+c:GetSequence()*0x1000
|
||||
Duel.Hint(10,tp,v)
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
def info_location(v):
|
||||
return (v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF)
|
||||
|
||||
|
||||
def field_hints(pkts):
|
||||
return [struct.unpack_from("<I", d, 3)[0] for p, d in pkts if p == 0x01 and len(d) >= 7 and d[0] == MSG_HINT and d[1] == HINT_CARD]
|
||||
|
||||
|
||||
def error_msgs(pkts):
|
||||
return [d[0] for p, d in pkts if p == STOC_ERROR_MSG and d]
|
||||
|
||||
|
||||
def tag_two_fields_room(dll_path, port, label):
|
||||
print("== tag two Field slots, %s (seat 0 plays a Field on turn 1, seat 1 on turn 3, seat 0 again on turn 5)" % label)
|
||||
root = make_workspace()
|
||||
here = os.getcwd()
|
||||
os.chdir(root)
|
||||
try:
|
||||
write_special(root, [])
|
||||
dll, thread = host_dll(dll_path, port, 2)
|
||||
seated = []
|
||||
for i in range(4):
|
||||
c = Client("127.0.0.1", port, "tf-seat%d" % i)
|
||||
c.log = list(c.join())
|
||||
seated.append(c)
|
||||
check([c.seat for c in seated] == [0, 1, 2, 3], "%s: four seats (%r)" % (label, [c.seat for c in seated]))
|
||||
cap = server_capability(seated[0].log)
|
||||
check(cap == (11, 0x77FF), "%s: the tag server's capability is protocol 11, flags 0x77FF (got %s)" % (label, cap))
|
||||
drain_all(seated)
|
||||
old = Client("127.0.0.1", port, "tf-old")
|
||||
old.log = list(old.join())
|
||||
old.send(CTOS_CAPABILITY, capability_bytes(9, 0x27FF))
|
||||
old.log += old.drain(quiet=0.4)
|
||||
check(old.seat == OBSERVER and error_msgs(old.log) == [ERRMSG_VERERROR] and old.closed,
|
||||
"%s: a joiner whose capability lacks 0x1000 gets ERROR_MSG VERERROR and is disconnected (seat %r, errors %r, closed %r)" % (label, old.seat, error_msgs(old.log), old.closed))
|
||||
new = Client("127.0.0.1", port, "tf-new")
|
||||
new.log = list(new.join())
|
||||
new.send(CTOS_CAPABILITY, capability_bytes(11, 0x77FB))
|
||||
new.log += new.drain(quiet=0.4)
|
||||
check(new.seat == OBSERVER and not error_msgs(new.log) and not new.closed and stamped(new.log, STOC_CAPABILITY, OBSERVER) == [capability_bytes(11, 0x77FB)],
|
||||
"%s: a joiner with 0x1000 and 0x4000 stays and its CAPABILITY is relayed (errors %r, closed %r)" % (label, error_msgs(new.log), new.closed))
|
||||
new.close()
|
||||
drain_all(seated)
|
||||
decks = {0: [PROBE_FIELD] * 40, 1: [PROBE_FIELD] * 40, 2: [PROBE_CARD] * 40, 3: [PROBE_CARD] * 40}
|
||||
for c in seated:
|
||||
c.send(CTOS_UPDATE_DECK, deck_bytes(decks[c.seat]))
|
||||
pump(seated, lambda: False, limit=0.8)
|
||||
seated[0].send(CTOS_HS_START)
|
||||
state = {"turn": 0, "acted": 0, "retries": 0, "moves": []}
|
||||
|
||||
def answer(c, payload):
|
||||
c.send(CTOS_TIME_CONFIRM)
|
||||
c.send(CTOS_RESPONSE, payload)
|
||||
|
||||
def play(until, limit):
|
||||
deadline = time.time() + limit
|
||||
while time.time() < deadline:
|
||||
for c in seated:
|
||||
for pid, d in c.drain(quiet=0.02, limit=0.2):
|
||||
c.log.append((pid, d))
|
||||
if pid == STOC_SELECT_TP:
|
||||
c.send(CTOS_TP_RESULT, bytes([1 if c.seat == 0 else 0])) # side A (seats 0 + 1) goes first
|
||||
continue
|
||||
if pid != 0x01 or not d:
|
||||
continue
|
||||
t = d[0]
|
||||
if t == MSG_NEW_TURN and c.seat == 0:
|
||||
state["turn"] += 1
|
||||
elif t == MSG_MOVE and c.seat == 0 and len(d) >= 17:
|
||||
code, prev, cur, _reason = struct.unpack_from("<IIII", d, 1)
|
||||
state["moves"].append((state["turn"], code, info_location(prev), info_location(cur)))
|
||||
elif t == MSG_RETRY:
|
||||
state["retries"] += 1
|
||||
elif t == MSG_SELECT_IDLECMD:
|
||||
n = 2
|
||||
for k in range(5):
|
||||
n += 1 + d[n] * 7
|
||||
activatable = d[n]
|
||||
if activatable and state["acted"] != state["turn"]:
|
||||
state["acted"] = state["turn"]
|
||||
answer(c, struct.pack("<i", 5)) # activate the first card: a Probe Field
|
||||
else:
|
||||
answer(c, struct.pack("<i", 7)) # to the End Phase
|
||||
elif t in (MSG_SELECT_CARD, MSG_SELECT_TRIBUTE):
|
||||
answer(c, bytes([1, 0]))
|
||||
elif t == MSG_SELECT_CHAIN:
|
||||
answer(c, struct.pack("<i", -1))
|
||||
elif t in (MSG_SELECT_PLACE, MSG_SELECT_DISFIELD):
|
||||
answer(c, first_free_zone(d))
|
||||
elif t == MSG_SELECT_POSITION:
|
||||
answer(c, struct.pack("<i", next(b for b in (1, 2, 4, 8) if d[6] & b)))
|
||||
elif t in (MSG_SELECT_EFFECTYN, MSG_SELECT_YESNO):
|
||||
answer(c, struct.pack("<i", 1))
|
||||
elif t in (MSG_SELECT_OPTION, MSG_SELECT_BATTLECMD):
|
||||
answer(c, struct.pack("<i", 0 if t == MSG_SELECT_OPTION else 3))
|
||||
if until():
|
||||
return True
|
||||
if any(c.closed for c in seated):
|
||||
return False
|
||||
return until()
|
||||
|
||||
ok = play(lambda: state["turn"] >= 6, limit=40)
|
||||
check(ok, "%s: the duel reached turn 6 (turn %d)" % (label, state["turn"]))
|
||||
check(state["retries"] == 0, "%s: no answer was refused (MSG_RETRY x%d)" % (label, state["retries"]))
|
||||
fields = [(turn, prev, cur) for turn, code, prev, cur in state["moves"] if code == PROBE_FIELD]
|
||||
to_field = [(turn, cur[2]) for turn, prev, cur in fields if cur[0] == 0 and cur[1] == LOCATION_SZONE]
|
||||
check(to_field == [(1, 5), (3, 6), (5, 5)],
|
||||
"%s: seat 0's Field lands in sequence 5 on turn 1, seat 1's in sequence 6 on turn 3, seat 0's next in sequence 5 on turn 5 (%r)" % (label, to_field))
|
||||
left = [(turn, prev[2], cur[1]) for turn, prev, cur in fields if prev[0] == 0 and prev[1] == LOCATION_SZONE]
|
||||
check(left == [(5, 5, LOCATION_GRAVE)],
|
||||
"%s: only the sequence-5 Field left, to the Graveyard on turn 5; the sequence-6 Field never moved (%r)" % (label, left))
|
||||
hints = field_hints(seated[0].log)
|
||||
check(hints == [0x53D1, 0x61F2, 0x51F2],
|
||||
"%s: the core saw it so: turn 1 seq 5, 1 field, slot 1 free; turn 3 seq 6, 2 fields, GetFieldCard(FZONE, 0) = the playing partner's, 1 = the other; turn 5 seq 5, 2 fields (%s)" % (label, ["0x%X" % h for h in hints]))
|
||||
check(all(not c.closed for c in seated), "%s: every seat is still connected" % label)
|
||||
marks = marks_of(seated)
|
||||
for c in seated[:2]:
|
||||
c.send(CTOS_SURRENDER)
|
||||
ok = pump(seated, lambda: all(match_overs(since(c, marks)) for c in seated), limit=10)
|
||||
check(ok, "%s: side 0 surrendered: MATCH_OVER reached everyone" % label)
|
||||
for c in seated:
|
||||
c.close()
|
||||
stop_dll(dll, thread, label)
|
||||
finally:
|
||||
os.chdir(here)
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
|
||||
|
||||
def tag_two_fields_single(dll_path, port, label):
|
||||
print("== tag two Field slots, %s (a Single room keeps a client without 0x1000)" % label)
|
||||
root = make_workspace()
|
||||
here = os.getcwd()
|
||||
os.chdir(root)
|
||||
try:
|
||||
write_special(root, [])
|
||||
dll, thread = host_dll(dll_path, port, 0)
|
||||
h = Client("127.0.0.1", port, "tf-host")
|
||||
h.log = list(h.join())
|
||||
cap = server_capability(h.log)
|
||||
check(cap == (11, 0x77FF), "%s: the single server's capability is protocol 11, flags 0x77FF (got %s)" % (label, cap))
|
||||
h.send(CTOS_CAPABILITY, capability_bytes(9, 0x27FF))
|
||||
h.log += h.drain(quiet=0.4)
|
||||
check(h.seat == 0 and not error_msgs(h.log) and not h.closed and stamped(h.log, STOC_CAPABILITY, 0) == [capability_bytes(9, 0x27FF)],
|
||||
"%s: a seat whose capability lacks 0x1000 stays and its CAPABILITY is relayed (errors %r, closed %r)" % (label, error_msgs(h.log), h.closed))
|
||||
h.close()
|
||||
stop_dll(dll, thread, label)
|
||||
finally:
|
||||
os.chdir(here)
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
|
||||
|
||||
def tag_two_fields_suite(dll_path, port):
|
||||
print()
|
||||
print("hosting the tag two Field slots rooms from %s" % dll_path)
|
||||
tag_two_fields_room(dll_path, port, "tag")
|
||||
tag_two_fields_single(dll_path, port + 1, "single")
|
||||
|
||||
# --- proposal 53 (TICKET-433): Tag shared Extra Deck --------------------------------------------
|
||||
# With the setup pair ygol.tag.extra=shared the server sets option 0x200 and start_duel moves the
|
||||
# waiting partner's Extra Deck into the live list; tag_swap leaves it there. Each card keeps the
|
||||
# partner who brought it, sent as QUERY_TAG_MEMBER on Extra Deck refreshes of that duel only.
|
||||
# Capability 0x4000, protocol 11. Without the pair the lists stay apart.
|
||||
FEATURE_TAG_SHARED_EXTRA = 0x4000
|
||||
QUERY_TAG_MEMBER = 0x1000000
|
||||
DUEL_TAG_SHARED_EXTRA = 0x200
|
||||
TAG_EXTRA_PAIR = "ygol.tag.extra=shared"
|
||||
PROBE_EXTRA_SPELL = PROBE_CARD + 900
|
||||
PROBE_SEAT_FUSIONS = [PROBE_CARD + 901 + seat for seat in range(4)]
|
||||
SEAT_EXTRA = {0: [PROBE_SEAT_FUSIONS[0]] * 2, 1: [PROBE_SEAT_FUSIONS[1]], 2: [PROBE_SEAT_FUSIONS[2]], 3: [PROBE_SEAT_FUSIONS[3]] * 3}
|
||||
MSG_UPDATE_DATA, MSG_UPDATE_CARD, LOCATION_EXTRA = 6, 7, 0x40
|
||||
EXTRA_SPELL_LUA = """--Probe Extra Spell (proposal 53): return your face-up Fusion Monster to the Extra Deck; with none, Special Summon 1 from it.
|
||||
local s,id,o=GetID()
|
||||
function s.initial_effect(c)
|
||||
local e1=Effect.CreateEffect(c)
|
||||
e1:SetType(EFFECT_TYPE_ACTIVATE)
|
||||
e1:SetCode(EVENT_FREE_CHAIN)
|
||||
e1:SetTarget(s.target)
|
||||
e1:SetOperation(s.activate)
|
||||
c:RegisterEffect(e1)
|
||||
end
|
||||
function s.onfield(c)
|
||||
return c:IsFaceup() and c:IsType(TYPE_FUSION)
|
||||
end
|
||||
function s.inextra(c)
|
||||
return c:IsType(TYPE_FUSION)
|
||||
end
|
||||
function s.target(e,tp,eg,ep,ev,re,r,rp,chk)
|
||||
if chk==0 then return Duel.IsExistingMatchingCard(s.onfield,tp,LOCATION_MZONE,0,1,nil) or Duel.IsExistingMatchingCard(s.inextra,tp,LOCATION_EXTRA,0,1,nil) end
|
||||
end
|
||||
function s.activate(e,tp,eg,ep,ev,re,r,rp)
|
||||
local f=Duel.GetFirstMatchingCard(s.onfield,tp,LOCATION_MZONE,0,nil)
|
||||
if f then
|
||||
Duel.SendtoDeck(f,nil,0,REASON_EFFECT)
|
||||
return
|
||||
end
|
||||
local tc=Duel.SelectMatchingCard(tp,s.inextra,tp,LOCATION_EXTRA,0,1,1,nil):GetFirst()
|
||||
if tc then Duel.SpecialSummon(tc,0,tp,tp,true,false,POS_FACEUP) end
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
def query_records(d, at):
|
||||
# (flag, code or None, value of QUERY_TAG_MEMBER or None) per record of a query buffer
|
||||
out = []
|
||||
while at + 4 <= len(d):
|
||||
(clen,) = struct.unpack_from("<i", d, at)
|
||||
if clen < 4:
|
||||
break
|
||||
if clen >= 8:
|
||||
(flag,) = struct.unpack_from("<I", d, at + 4)
|
||||
code = struct.unpack_from("<I", d, at + 8)[0] if flag & 1 and clen >= 12 else None
|
||||
member = struct.unpack_from("<I", d, at + clen - 4)[0] if flag & QUERY_TAG_MEMBER else None
|
||||
out.append((flag, code, member))
|
||||
at += clen
|
||||
return out
|
||||
|
||||
|
||||
def extra_refreshes(pkts, side):
|
||||
return [query_records(d, 3) for p, d in pkts if p == 0x01 and len(d) >= 3 and d[0] == MSG_UPDATE_DATA and d[1] == side and d[2] == LOCATION_EXTRA]
|
||||
|
||||
|
||||
def other_queries_with_bit(pkts):
|
||||
bad = 0
|
||||
for p, d in pkts:
|
||||
if p != 0x01 or len(d) < 3:
|
||||
continue
|
||||
if d[0] == MSG_UPDATE_DATA and d[2] != LOCATION_EXTRA:
|
||||
bad += sum(1 for r in query_records(d, 3) if r[0] & QUERY_TAG_MEMBER)
|
||||
elif d[0] == MSG_UPDATE_CARD:
|
||||
bad += sum(1 for r in query_records(d, 4) if r[0] & QUERY_TAG_MEMBER)
|
||||
return bad
|
||||
|
||||
|
||||
def start_extra_counts(pkts):
|
||||
# MSG_START: player, rule, i32 lp[2], u16 deck0, extra0, deck1, extra1
|
||||
return [(struct.unpack_from("<H", d, 13)[0], struct.unpack_from("<H", d, 17)[0]) for p, d in pkts if p == 0x01 and len(d) >= 19 and d[0] == MSG_START]
|
||||
|
||||
|
||||
def members_by_code(records):
|
||||
return sorted((r[1], r[2]) for r in records)
|
||||
|
||||
|
||||
def replay_duel_parts(body, flag):
|
||||
# the replay body up to the responses: (opt, start_lp, start_hand, draw_count, decks, responses)
|
||||
at = 4 + struct.unpack_from("<I", body, 0)[0] if flag & REPLAY_YGOL_SETUP_PAIRS else 0
|
||||
at += 4 * 40
|
||||
start_lp, start_hand, draw_count, opt = struct.unpack_from("<iiiI", body, at)
|
||||
at += 16
|
||||
decks = []
|
||||
for _ in range(8):
|
||||
(n,) = struct.unpack_from("<i", body, at)
|
||||
decks.append(list(struct.unpack_from("<%dI" % n, body, at + 4)))
|
||||
at += 4 + 4 * n
|
||||
responses = []
|
||||
while at < len(body):
|
||||
n = body[at]
|
||||
responses.append(body[at + 1:at + 1 + n])
|
||||
at += 1 + n
|
||||
return opt, start_lp, start_hand, draw_count, decks, responses
|
||||
|
||||
|
||||
def play_replay_back(dll, seeds, parts, pairs):
|
||||
# the library plays the recorded duel again, as a replay reader does: what start_duel made, then the Summons
|
||||
opt, start_lp, start_hand, draw_count, decks, responses = parts
|
||||
h = ctypes.c_ssize_t
|
||||
dll.create_duel_v2.restype = h
|
||||
dll.create_duel_v2.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
|
||||
dll.set_player_info.argtypes = [h, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32]
|
||||
dll.set_registry_value.argtypes = [h, ctypes.c_char_p, ctypes.c_char_p]
|
||||
dll.preload_script.argtypes = [h, ctypes.c_char_p]
|
||||
dll.new_card.argtypes = [h, ctypes.c_uint32, ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint8]
|
||||
dll.new_tag_card.argtypes = [h, ctypes.c_uint32, ctypes.c_uint8, ctypes.c_uint8]
|
||||
dll.start_duel.argtypes = [h, ctypes.c_uint32]
|
||||
dll.process.restype = ctypes.c_uint32
|
||||
dll.process.argtypes = [h]
|
||||
dll.get_message.argtypes = [h, ctypes.c_char_p]
|
||||
dll.set_responseb.argtypes = [h, ctypes.c_char_p]
|
||||
dll.query_field_count.argtypes = [h, ctypes.c_uint8, ctypes.c_uint8]
|
||||
dll.query_field_card.argtypes = [h, ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint32, ctypes.c_char_p, ctypes.c_int32]
|
||||
dll.ygol_query_tag_cards.argtypes = [h, ctypes.c_uint8, ctypes.c_char_p]
|
||||
dll.end_duel.argtypes = [h]
|
||||
d = dll.create_duel_v2((ctypes.c_uint32 * 8)(*seeds))
|
||||
for pair in pairs:
|
||||
k, v = pair.split("=", 1)
|
||||
dll.set_registry_value(d, k.encode(), v.encode())
|
||||
dll.set_player_info(d, 0, start_lp, start_hand, draw_count)
|
||||
dll.set_player_info(d, 1, start_lp, start_hand, draw_count)
|
||||
dll.preload_script(d, b"./script/init.lua")
|
||||
for i, codes in enumerate(decks):
|
||||
team, kind = i // 4, i % 4
|
||||
for code in codes:
|
||||
location = LOCATION_EXTRA if kind % 2 else 0x01
|
||||
if kind < 2:
|
||||
dll.new_card(d, code, team, team, location, 0, 0x08)
|
||||
else:
|
||||
dll.new_tag_card(d, code, team, location)
|
||||
dll.start_duel(d, opt)
|
||||
buf = ctypes.create_string_buffer(0x40000)
|
||||
out = {"counts": (dll.query_field_count(d, 0, LOCATION_EXTRA), dll.query_field_count(d, 1, LOCATION_EXTRA))}
|
||||
|
||||
def extra(team):
|
||||
n = dll.query_field_card(d, team, LOCATION_EXTRA, 0x1 | QUERY_TAG_MEMBER, buf, 0)
|
||||
return members_by_code(query_records(buf.raw[:n], 0))
|
||||
|
||||
def waiting_extra(team):
|
||||
dll.ygol_query_tag_cards(d, team, buf)
|
||||
return buf.raw[2]
|
||||
|
||||
out["opening"] = (extra(0), extra(1))
|
||||
out["waiting"] = (waiting_extra(0), waiting_extra(1))
|
||||
stream = b""
|
||||
left = list(responses)
|
||||
for _ in range(100000):
|
||||
r = dll.process(d)
|
||||
n = r & 0x0FFFFFFF
|
||||
if n:
|
||||
got = dll.get_message(d, buf)
|
||||
stream += buf.raw[:got]
|
||||
if r & 0x20000000:
|
||||
break
|
||||
if r & 0x10000000:
|
||||
if not left:
|
||||
break
|
||||
one = ctypes.create_string_buffer(left.pop(0), 256)
|
||||
dll.set_responseb(d, one)
|
||||
out["responses_left"] = len(left)
|
||||
out["summons"] = []
|
||||
at = 0
|
||||
while True:
|
||||
at = stream.find(bytes([MSG_SPSUMMONING]), at)
|
||||
if at < 0 or at + 5 > len(stream):
|
||||
break
|
||||
(code,) = struct.unpack_from("<I", stream, at + 1)
|
||||
if code in PROBE_SEAT_FUSIONS:
|
||||
out["summons"].append(code)
|
||||
at += 1
|
||||
out["end_extra"] = extra(0)
|
||||
dll.end_duel(d)
|
||||
return out
|
||||
|
||||
|
||||
def tag_shared_extra_room(dll_path, port, label, shared):
|
||||
print("== tag shared Extra Deck, %s" % label)
|
||||
F0, F1, F2, F3 = PROBE_SEAT_FUSIONS
|
||||
root = make_workspace()
|
||||
here = os.getcwd()
|
||||
os.chdir(root)
|
||||
try:
|
||||
pairs = [TAG_EXTRA_PAIR] if shared else []
|
||||
write_special(root, pairs)
|
||||
dll, thread = host_dll(dll_path, port, 2, " ".join(pairs))
|
||||
seated = []
|
||||
for i in range(4):
|
||||
c = Client("127.0.0.1", port, "se-seat%d" % i)
|
||||
c.log = list(c.join())
|
||||
seated.append(c)
|
||||
check([c.seat for c in seated] == [0, 1, 2, 3], "%s: four seats (%r)" % (label, [c.seat for c in seated]))
|
||||
cap = server_capability(seated[0].log)
|
||||
check(cap == (11, 0x77FF), "%s: the tag server's capability is protocol 11, flags 0x77FF (got %s)" % (label, cap))
|
||||
drain_all(seated)
|
||||
old = Client("127.0.0.1", port, "se-old")
|
||||
old.log = list(old.join())
|
||||
old.send(CTOS_CAPABILITY, capability_bytes(10, 0x37FF))
|
||||
old.log += old.drain(quiet=0.4)
|
||||
check(old.seat == OBSERVER and error_msgs(old.log) == [ERRMSG_VERERROR] and old.closed,
|
||||
"%s: a joiner with 0x1000 but without 0x4000 gets ERROR_MSG VERERROR and is disconnected (seat %r, errors %r, closed %r)" % (label, old.seat, error_msgs(old.log), old.closed))
|
||||
drain_all(seated)
|
||||
watcher = Client("127.0.0.1", port, "se-watch")
|
||||
watcher.log = list(watcher.join())
|
||||
drain_all(seated + [watcher])
|
||||
for c in seated:
|
||||
spell = PROBE_EXTRA_SPELL if c.seat < 2 else PROBE_KNIGHT
|
||||
c.send(CTOS_UPDATE_DECK, deck_bytes([spell] * 40 + SEAT_EXTRA[c.seat]))
|
||||
pump(seated, lambda: False, limit=0.8)
|
||||
seated[0].send(CTOS_HS_START)
|
||||
state = {"turn": 0, "acted": 0, "retries": 0, "selects": [], "summons": [], "swaps": []}
|
||||
picks = {1: F1, 5: F0} if shared else {1: F0}
|
||||
|
||||
def answer(c, payload):
|
||||
c.send(CTOS_TIME_CONFIRM)
|
||||
c.send(CTOS_RESPONSE, payload)
|
||||
|
||||
def play(until, limit):
|
||||
deadline = time.time() + limit
|
||||
while time.time() < deadline:
|
||||
watcher.log += watcher.drain(quiet=0.02, limit=0.1)
|
||||
for c in seated:
|
||||
for pid, d in c.drain(quiet=0.02, limit=0.2):
|
||||
c.log.append((pid, d))
|
||||
if pid == STOC_SELECT_TP:
|
||||
c.send(CTOS_TP_RESULT, bytes([1 if c.seat == 0 else 0])) # side A (seats 0 + 1) goes first
|
||||
continue
|
||||
if pid != 0x01 or not d:
|
||||
continue
|
||||
t = d[0]
|
||||
if t == MSG_NEW_TURN and c.seat == 0:
|
||||
state["turn"] += 1
|
||||
elif t == MSG_TAG_SWAP and c.seat == 0 and d[1] == 0:
|
||||
state["swaps"].append((state["turn"], d[3], d[4], len(c.log) - 1))
|
||||
elif t == MSG_SPSUMMONING and c.seat == 0:
|
||||
state["summons"].append((state["turn"], struct.unpack_from("<I", d, 1)[0]))
|
||||
elif t == MSG_RETRY:
|
||||
state["retries"] += 1
|
||||
elif t == MSG_SELECT_IDLECMD:
|
||||
n = 2
|
||||
for k in range(5):
|
||||
n += 1 + d[n] * 7
|
||||
activatable = d[n]
|
||||
if activatable and state["acted"] != state["turn"]:
|
||||
state["acted"] = state["turn"]
|
||||
answer(c, struct.pack("<i", 5)) # activate the first card: the Spell
|
||||
else:
|
||||
answer(c, struct.pack("<i", 7)) # to the End Phase
|
||||
elif t == MSG_SELECT_CARD:
|
||||
cards = [struct.unpack_from("<II", d, 6 + 8 * i) for i in range(d[5])]
|
||||
state["selects"].append((state["turn"], sorted((info_location(v)[2], code) for code, v in cards)))
|
||||
want = picks.get(state["turn"])
|
||||
answer(c, bytes([1, next((i for i, card in enumerate(cards) if card[0] == want), 0)]))
|
||||
elif t == MSG_SELECT_TRIBUTE:
|
||||
answer(c, bytes([1, 0]))
|
||||
elif t == MSG_SELECT_CHAIN:
|
||||
answer(c, struct.pack("<i", -1))
|
||||
elif t in (MSG_SELECT_PLACE, MSG_SELECT_DISFIELD):
|
||||
answer(c, first_free_zone(d))
|
||||
elif t == MSG_SELECT_POSITION:
|
||||
answer(c, struct.pack("<i", next(b for b in (1, 2, 4, 8) if d[6] & b)))
|
||||
elif t in (MSG_SELECT_EFFECTYN, MSG_SELECT_YESNO):
|
||||
answer(c, struct.pack("<i", 1))
|
||||
elif t in (MSG_SELECT_OPTION, MSG_SELECT_BATTLECMD):
|
||||
answer(c, struct.pack("<i", 0 if t == MSG_SELECT_OPTION else 3))
|
||||
if until():
|
||||
return True
|
||||
if any(c.closed for c in seated):
|
||||
return False
|
||||
return until()
|
||||
|
||||
last_turn = 6 if shared else 4
|
||||
ok = play(lambda: state["turn"] >= last_turn, limit=60)
|
||||
check(ok, "%s: the duel reached turn %d (turn %d)" % (label, last_turn, state["turn"]))
|
||||
check(state["retries"] == 0, "%s: no answer was refused (MSG_RETRY x%d)" % (label, state["retries"]))
|
||||
for c in seated:
|
||||
check(start_extra_counts(c.log) == [(3, 4) if shared else (2, 1)], "%s: seat %d's MSG_START gives the Extra Deck counts %s (%r)" % (label, c.seat, (3, 4) if shared else (2, 1), start_extra_counts(c.log)))
|
||||
check(other_queries_with_bit(c.log) == 0, "%s: seat %d: no other query carries QUERY_TAG_MEMBER (%d)" % (label, c.seat, other_queries_with_bit(c.log)))
|
||||
if shared:
|
||||
opening = {0: [(F0, 0), (F0, 0), (F1, 1)], 1: [(F2, 0), (F3, 1), (F3, 1), (F3, 1)]}
|
||||
for c in seated:
|
||||
own, other = c.seat // 2, 1 - c.seat // 2
|
||||
first = extra_refreshes(c.log, own)
|
||||
check(bool(first) and members_by_code(first[0]) == opening[own], "%s: seat %d's first Extra Deck refresh lists both partners' cards with the partner each came from (%r)" % (label, c.seat, members_by_code(first[0]) if first else None))
|
||||
masked = extra_refreshes(c.log, other)
|
||||
check(bool(masked) and len(masked[0]) == len(opening[other]) and all(r[0] == 0 for r in masked[0]), "%s: seat %d's copy of the other team's refresh is masked, flag 0, no value (%r)" % (label, c.seat, masked[0] if masked else None))
|
||||
cards = partner_cards(c.log, own)
|
||||
check(bool(cards) and all(g[3] == [] for g in cards) and len(cards[0][2]) == 5, "%s: seat %d's TAG_PARTNER_CARDS report an Extra count of 0, and the waiting hand stays (%r)" % (label, c.seat, [(g[3], len(g[2] or [])) for g in cards]))
|
||||
for team in (0, 1):
|
||||
first = extra_refreshes(watcher.log, team)
|
||||
check(bool(first) and members_by_code(first[0]) == opening[team], "%s: the watcher's first refresh of side %d has the values too (%r)" % (label, team, members_by_code(first[0]) if first else None))
|
||||
check(state["selects"][:1] == [(1, [(0, F0), (1, F0), (2, F1)])],
|
||||
"%s: on turn 1 seat 0 is offered both partners' Fusions, in sequences 0, 1, 2 (%r)" % (label, state["selects"][:1]))
|
||||
check(state["summons"] == [(1, F1), (5, F0)], "%s: seat 0 Summons seat 1's monster on turn 1, its own on turn 5 (%r)" % (label, state["summons"]))
|
||||
check([s[:3] for s in state["swaps"]] == [(3, 2, 0), (5, 3, 0)],
|
||||
"%s: MSG_TAG_SWAP keeps the one list: 2 cards on turn 3, 3 on turn 5 when seat 1 returned the Fusion (%r)" % (label, [s[:3] for s in state["swaps"]]))
|
||||
log = seated[0].log
|
||||
after = extra_refreshes(log[state["swaps"][1][3]:], 0) if len(state["swaps"]) > 1 else []
|
||||
check(bool(after) and members_by_code(after[0]) == [(F0, 0), (F0, 0), (F1, 1)], "%s: after the swap of turn 5 the Fusion that moved still says partner 1 (%r)" % (label, members_by_code(after[0]) if after else None))
|
||||
late = Client("127.0.0.1", port, "se-late")
|
||||
late.log = list(late.join())
|
||||
late.log += late.drain(quiet=0.6)
|
||||
snapshot = extra_refreshes(late.log, 0)
|
||||
check(bool(snapshot) and members_by_code(snapshot[0]) == [(F0, 0), (F1, 1)], "%s: a late watcher's snapshot refresh has the values (flag 0xefffff + the bit) (%r)" % (label, members_by_code(snapshot[0]) if snapshot else None))
|
||||
late.close()
|
||||
else:
|
||||
for c in seated + [watcher]:
|
||||
for team in (0, 1):
|
||||
records = [r for refresh in extra_refreshes(c.log, team) for r in refresh]
|
||||
check(bool(records) and not any(r[0] & QUERY_TAG_MEMBER for r in records), "%s: %s: no Extra Deck refresh of side %d carries the bit" % (label, c.name, team))
|
||||
cards = partner_cards(seated[0].log, 0)
|
||||
check(bool(cards) and cards[0][3] == [F1], "%s: the opening TAG_PARTNER_CARDS report the waiting partner's Extra Deck (%r)" % (label, cards[0][3] if cards else None))
|
||||
check(state["selects"][:1] == [(1, [(0, F0), (1, F0)])], "%s: on turn 1 seat 0 is offered only its own Fusions (%r)" % (label, state["selects"][:1]))
|
||||
check(state["summons"] == [(1, F0)], "%s: seat 0 Summons its own monster on turn 1 (%r)" % (label, state["summons"]))
|
||||
check([s[:3] for s in state["swaps"]] == [(3, 1, 0)], "%s: the swap of turn 3 brings seat 1's Extra Deck (%r)" % (label, [s[:3] for s in state["swaps"]]))
|
||||
marks = marks_of(seated)
|
||||
for c in seated[:2]:
|
||||
c.send(CTOS_SURRENDER)
|
||||
ok = pump(seated, lambda: all(match_overs(since(c, marks)) for c in seated), limit=10)
|
||||
check(ok, "%s: side 0 surrendered: MATCH_OVER reached everyone" % label)
|
||||
reps = replays(seated[0])
|
||||
if check(len(reps) == 1, "%s: one REPLAY arrived (%d)" % (label, len(reps))):
|
||||
flag, seeds, body = reps[0]
|
||||
parts = replay_duel_parts(body, flag)
|
||||
check(bool(parts[0] & DUEL_TAG_SHARED_EXTRA) == shared, "%s: the replay's opt %s option 0x200 (opt 0x%x)" % (label, "has" if shared else "does not have", parts[0]))
|
||||
back = play_replay_back(dll, seeds, parts, pairs)
|
||||
if shared:
|
||||
check(back["counts"] == (3, 4) and back["waiting"] == (0, 0), "%s: replay: start_duel merged: live Extra Decks 3 and 4, waiting lists 0 (%r, %r)" % (label, back["counts"], back["waiting"]))
|
||||
check(back["opening"] == ([(F0, 0), (F0, 0), (F1, 1)], [(F2, 0), (F3, 1), (F3, 1), (F3, 1)]), "%s: replay: the query gives each card its partner (%r)" % (label, back["opening"]))
|
||||
check(back["summons"] == [F1, F0], "%s: replay: the recorded answers Summon the waiting partner's monster, then seat 0's (%r)" % (label, back["summons"]))
|
||||
check(back["responses_left"] == 0 and back["end_extra"] == [(F0, 0), (F1, 1)], "%s: replay: every answer was used and the Extra Deck ends as it did live (%d left, %r)" % (label, back["responses_left"], back["end_extra"]))
|
||||
else:
|
||||
check(back["counts"] == (2, 1) and back["waiting"] == (1, 3), "%s: replay: the lists stay apart: live 2 and 1, waiting 1 and 3 (%r, %r)" % (label, back["counts"], back["waiting"]))
|
||||
check(back["summons"] == [F0] and back["responses_left"] == 0, "%s: replay: the recorded answers Summon the same monster (%r, %d left)" % (label, back["summons"], back["responses_left"]))
|
||||
for c in seated + [watcher]:
|
||||
c.close()
|
||||
stop_dll(dll, thread, label)
|
||||
finally:
|
||||
os.chdir(here)
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
|
||||
|
||||
def tag_shared_extra_single(dll_path, port, label):
|
||||
print("== tag shared Extra Deck, %s (a Single room keeps a client without 0x4000)" % label)
|
||||
root = make_workspace()
|
||||
here = os.getcwd()
|
||||
os.chdir(root)
|
||||
try:
|
||||
write_special(root, [])
|
||||
dll, thread = host_dll(dll_path, port, 0)
|
||||
h = Client("127.0.0.1", port, "se-host")
|
||||
h.log = list(h.join())
|
||||
h.send(CTOS_CAPABILITY, capability_bytes(10, 0x37FF))
|
||||
h.log += h.drain(quiet=0.4)
|
||||
check(h.seat == 0 and not error_msgs(h.log) and not h.closed, "%s: a seat whose capability lacks 0x4000 stays (errors %r, closed %r)" % (label, error_msgs(h.log), h.closed))
|
||||
h.close()
|
||||
stop_dll(dll, thread, label)
|
||||
finally:
|
||||
os.chdir(here)
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
|
||||
|
||||
def tag_shared_extra_suite(dll_path, port):
|
||||
print()
|
||||
print("hosting the tag shared Extra Deck rooms from %s" % dll_path)
|
||||
tag_shared_extra_room(dll_path, port, "pair present", True)
|
||||
tag_shared_extra_room(dll_path, port + 1, "pair absent", False)
|
||||
tag_shared_extra_single(dll_path, port + 2, "single")
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
+5
-1
@@ -67,7 +67,8 @@ uint32_t card::get_summon_info() {
|
||||
}
|
||||
|
||||
bool card_state::is_location(uint32_t loc) const {
|
||||
if((loc & LOCATION_FZONE) && location == LOCATION_SZONE && sequence == 5)
|
||||
// [YGOL] proposal 45: slot 6 is the second Field slot in Tag (Master Rule 4/5); a Master Rule 3 Pendulum Zone card there has pzone set
|
||||
if((loc & LOCATION_FZONE) && location == LOCATION_SZONE && (sequence == 5 || (sequence == 6 && !pzone)))
|
||||
return true;
|
||||
if((loc & LOCATION_PZONE) && location == LOCATION_SZONE && pzone)
|
||||
return true;
|
||||
@@ -430,6 +431,9 @@ int32_t card::get_infos(byte* buf, uint32_t query_flag, int32_t use_cache) {
|
||||
query_flag &= ~QUERY_LINK;
|
||||
}
|
||||
}
|
||||
if(query_flag & QUERY_TAG_MEMBER) {
|
||||
buffer_write<uint32_t>(p, tag_member);
|
||||
}
|
||||
byte* finalize = buf;
|
||||
buffer_write<int32_t>(finalize, (int32_t)(p - buf));
|
||||
buffer_write<uint32_t>(finalize, query_flag);
|
||||
|
||||
@@ -164,6 +164,7 @@ public:
|
||||
card_state spsummon;
|
||||
query_cache q_cache;
|
||||
uint8_t owner{ PLAYER_NONE };
|
||||
uint8_t tag_member{ 0 }; // [YGOL] proposal 53: the partner who brought it, 0 from new_card, 1 from new_tag_card
|
||||
uint8_t summon_player{ PLAYER_NONE };
|
||||
uint32_t summon_info{};
|
||||
uint32_t status{};
|
||||
|
||||
@@ -271,6 +271,7 @@ enum LuaParamType : int32_t {
|
||||
#define QUERY_LSCALE 0x200000
|
||||
#define QUERY_RSCALE 0x400000
|
||||
#define QUERY_LINK 0x800000
|
||||
#define QUERY_TAG_MEMBER 0x1000000 // [YGOL] proposal 53. Never 0x100000: old flags (0xf81fff, 0x181fff, 0xFFFFFF) set it with no value
|
||||
|
||||
//Link markers
|
||||
#define LINK_MARKER_BOTTOM_LEFT 0x001
|
||||
@@ -452,6 +453,7 @@ enum LuaParamType : int32_t {
|
||||
#define DUEL_SIMPLE_AI 0x40
|
||||
#define DUEL_RETURN_DECK_TOP 0x80
|
||||
#define DUEL_REVEAL_DECK_SEQ 0x100
|
||||
#define DUEL_TAG_SHARED_EXTRA 0x200 // [YGOL] proposal 53: one Extra Deck per Tag team
|
||||
|
||||
//Activity
|
||||
#define ACTIVITY_SUMMON 1
|
||||
|
||||
+79
-33
@@ -303,7 +303,7 @@ void field::move_card(uint8_t playerid, card* pcard, uint8_t location, uint8_t s
|
||||
if(sequence >= (int32_t)player[playerid].list_mzone.size() || player[playerid].list_mzone[sequence])
|
||||
return;
|
||||
} else {
|
||||
if(sequence >= player[playerid].szone_size || player[playerid].list_szone[sequence])
|
||||
if(sequence >= get_szone_size(playerid) || player[playerid].list_szone[sequence])
|
||||
return;
|
||||
}
|
||||
if(preplayer == playerid) {
|
||||
@@ -569,18 +569,23 @@ card* field::get_field_card(uint8_t playerid, uint32_t general_location, uint8_t
|
||||
break;
|
||||
}
|
||||
case LOCATION_SZONE: {
|
||||
if(sequence < player[playerid].szone_size)
|
||||
if(sequence < get_szone_size(playerid))
|
||||
return player[playerid].list_szone[sequence];
|
||||
else
|
||||
return nullptr;
|
||||
break;
|
||||
}
|
||||
case LOCATION_FZONE: {
|
||||
if(sequence == 0)
|
||||
return player[playerid].list_szone[5];
|
||||
else
|
||||
// [YGOL] proposal 45 Rule 3: 0 = the playing partner's field, else the other one; 1 = the remaining one
|
||||
if(sequence > 1 || (sequence == 1 && !has_two_fields()))
|
||||
return nullptr;
|
||||
break;
|
||||
card* first = player[playerid].list_szone[get_fzone_sequence(playerid, 0)];
|
||||
card* second = has_two_fields() ? player[playerid].list_szone[get_fzone_sequence(playerid, 1)] : nullptr;
|
||||
if(!first) {
|
||||
first = second;
|
||||
second = nullptr;
|
||||
}
|
||||
return sequence == 0 ? first : second;
|
||||
}
|
||||
case LOCATION_PZONE: {
|
||||
if(sequence == 0 || sequence == 1) {
|
||||
@@ -608,14 +613,14 @@ int32_t field::is_location_useable(uint8_t playerid, uint32_t general_location,
|
||||
return FALSE;
|
||||
}
|
||||
} else if (general_location == LOCATION_SZONE) {
|
||||
if (sequence >= player[playerid].szone_size)
|
||||
if (sequence >= get_szone_size(playerid))
|
||||
return FALSE;
|
||||
if(flag & (0x100U << sequence))
|
||||
return FALSE;
|
||||
} else if (general_location == LOCATION_FZONE) {
|
||||
if (sequence >= 1)
|
||||
if (sequence >= (has_two_fields() ? 2 : 1))
|
||||
return FALSE;
|
||||
if(flag & (0x100U << (5 + sequence)))
|
||||
if(flag & (0x100U << get_fzone_sequence(playerid, sequence)))
|
||||
return FALSE;
|
||||
} else if (general_location == LOCATION_PZONE) {
|
||||
if (sequence >= 2)
|
||||
@@ -625,6 +630,40 @@ int32_t field::is_location_useable(uint8_t playerid, uint32_t general_location,
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
// [YGOL] proposal 45: in Tag on Master Rule 4/5 a team has a Field slot per partner: Spell/Trap sequence 5 for the
|
||||
// partner who plays the team's first turn, 6 for the other (slot 6 is free there: Master Rule 3 alone uses it as a
|
||||
// Pendulum Zone). LOCATION_FZONE covers both; Singles, Match and Master Rule 3 keep the one slot.
|
||||
bool field::has_two_fields() const {
|
||||
return (core.duel_options & DUEL_TAG_MODE) && core.duel_rule >= NEW_MASTER_RULE;
|
||||
}
|
||||
int32_t field::get_szone_size(uint8_t playerid) const {
|
||||
return has_two_fields() ? 7 : player[playerid].szone_size;
|
||||
}
|
||||
// fseq 0 = the playing partner's slot, 1 = the other partner's
|
||||
uint8_t field::get_fzone_sequence(uint8_t playerid, uint8_t fseq) const {
|
||||
if(!has_two_fields())
|
||||
return 5;
|
||||
return (player[playerid].tag_partner ^ fseq) ? 6 : 5;
|
||||
}
|
||||
// a zone flag that names the Field Zone (callers pass 1 << 5 for "the Field Zone" and the engine picks the slot)
|
||||
bool field::is_fzone_zone(uint32_t zone) const {
|
||||
return zone == (0x1U << 5) || (has_two_fields() && zone == (0x1U << 6));
|
||||
}
|
||||
// the slot a Field Spell lands in for playerid: the playing partner's, which it replaces; a card that changes control
|
||||
// while the playing partner's slot is taken and the other is free takes the free one
|
||||
uint8_t field::get_fzone_landing(card* pcard, uint8_t playerid) const {
|
||||
if(!has_two_fields())
|
||||
return 5;
|
||||
if(pcard->current.location == LOCATION_SZONE && pcard->current.controler == playerid
|
||||
&& (pcard->current.sequence == 5 || pcard->current.sequence == 6))
|
||||
return pcard->current.sequence;
|
||||
uint8_t mine = get_fzone_sequence(playerid, 0);
|
||||
uint8_t other = get_fzone_sequence(playerid, 1);
|
||||
if(player[playerid].list_szone[mine] && !player[playerid].list_szone[other]
|
||||
&& pcard->current.location == LOCATION_SZONE && pcard->current.controler != playerid)
|
||||
return other;
|
||||
return mine;
|
||||
}
|
||||
/**
|
||||
* Return usable count in `zone` when `uplayer` moves `pcard` to the MZONE or SZONE(0~4) of `playerid` (can be negative).
|
||||
* For LOCATION_MZONE, "usable" means not used, not disabled, satisfying EFFECT_MUST_USE_MZONE, satisfying EFFECT_MAX_MZONE.
|
||||
@@ -1150,7 +1189,7 @@ void field::refresh_player_info(uint8_t playerid) {
|
||||
if (player[playerid].list_mzone[i])
|
||||
used_flag |= 0x1U << i;
|
||||
}
|
||||
for (int32_t i = 0; i < player[playerid].szone_size; ++i) {
|
||||
for (int32_t i = 0; i < get_szone_size(playerid); ++i) {
|
||||
if (player[playerid].list_szone[i])
|
||||
used_flag |= 0x100U << i;
|
||||
}
|
||||
@@ -1204,16 +1243,19 @@ void field::tag_swap(uint8_t playerid) {
|
||||
pcard->enable_field_effect(true);
|
||||
}
|
||||
//extra
|
||||
for(auto& pcard : player[playerid].list_extra) {
|
||||
pcard->enable_field_effect(false);
|
||||
pcard->cancel_field_effect();
|
||||
}
|
||||
std::swap(player[playerid].list_extra, player[playerid].tag_list_extra);
|
||||
std::swap(player[playerid].extra_p_count, player[playerid].tag_extra_p_count);
|
||||
for(auto& pcard : player[playerid].list_extra) {
|
||||
pcard->apply_field_effect();
|
||||
pcard->enable_field_effect(true);
|
||||
if(!(core.duel_options & DUEL_TAG_SHARED_EXTRA)) { // [YGOL] proposal 53: a shared Extra Deck stays live for both partners
|
||||
for(auto& pcard : player[playerid].list_extra) {
|
||||
pcard->enable_field_effect(false);
|
||||
pcard->cancel_field_effect();
|
||||
}
|
||||
std::swap(player[playerid].list_extra, player[playerid].tag_list_extra);
|
||||
std::swap(player[playerid].extra_p_count, player[playerid].tag_extra_p_count);
|
||||
for(auto& pcard : player[playerid].list_extra) {
|
||||
pcard->apply_field_effect();
|
||||
pcard->enable_field_effect(true);
|
||||
}
|
||||
}
|
||||
player[playerid].tag_partner ^= 1; // [YGOL] proposal 45: the other partner's Field slot is the live one now
|
||||
pduel->write_buffer8(MSG_TAG_SWAP);
|
||||
pduel->write_buffer8(playerid);
|
||||
pduel->write_buffer8((uint8_t)player[playerid].list_main.size());
|
||||
@@ -1565,18 +1607,20 @@ int32_t field::filter_matching_card(lua_State* L, int32_t findex, uint8_t self,
|
||||
}
|
||||
}
|
||||
if(location & LOCATION_FZONE) {
|
||||
card* pcard = player[self].list_szone[5];
|
||||
if(pcard && !pcard->is_treated_as_not_on_field()
|
||||
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
|
||||
&& pduel->lua->check_filter(L, pcard, findex, extraargs)
|
||||
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
|
||||
if(pret) {
|
||||
*pret = pcard;
|
||||
return TRUE;
|
||||
for(uint8_t fseq = 0, fzones = has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots
|
||||
card* pcard = player[self].list_szone[get_fzone_sequence(self, fseq)];
|
||||
if(pcard && !pcard->is_treated_as_not_on_field()
|
||||
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
|
||||
&& pduel->lua->check_filter(L, pcard, findex, extraargs)
|
||||
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
|
||||
if(pret) {
|
||||
*pret = pcard;
|
||||
return TRUE;
|
||||
}
|
||||
result.insert(pcard);
|
||||
if (fcount && (int32_t)result.size() >= fcount)
|
||||
return TRUE;
|
||||
}
|
||||
result.insert(pcard);
|
||||
if (fcount && (int32_t)result.size() >= fcount)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if(location & LOCATION_PZONE) {
|
||||
@@ -1700,9 +1744,11 @@ int32_t field::filter_field_card(uint8_t self, uint32_t location1, uint32_t loca
|
||||
}
|
||||
}
|
||||
if(location & LOCATION_FZONE) {
|
||||
card* pcard = player[self].list_szone[5];
|
||||
if(pcard) {
|
||||
result.insert(pcard);
|
||||
for(uint8_t fseq = 0, fzones = has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots
|
||||
card* pcard = player[self].list_szone[get_fzone_sequence(self, fseq)];
|
||||
if(pcard) {
|
||||
result.insert(pcard);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(location & LOCATION_PZONE) {
|
||||
|
||||
@@ -87,6 +87,7 @@ struct player_info {
|
||||
uint32_t extra_p_count{ 0 };
|
||||
uint32_t tag_extra_p_count{ 0 };
|
||||
int32_t szone_size{ 6 };
|
||||
uint8_t tag_partner{ 0 }; // [YGOL] proposal 45: 0 = the partner who plays the team's first turn (Field slot 5), 1 = the other (slot 6); flips in tag_swap
|
||||
card_vector list_mzone;
|
||||
card_vector list_szone;
|
||||
card_vector list_main;
|
||||
@@ -402,6 +403,12 @@ public:
|
||||
const card_vector* get_field_vector(uint8_t playerid, uint8_t location) const;
|
||||
card* get_field_card(uint8_t playerid, uint32_t general_location, uint8_t sequence) const;
|
||||
int32_t is_location_useable(uint8_t playerid, uint32_t general_location, uint8_t sequence) const;
|
||||
// [YGOL] proposal 45: Tag on Master Rule 4/5 gives each partner a Field slot (Spell/Trap sequence 5 and 6)
|
||||
bool has_two_fields() const;
|
||||
int32_t get_szone_size(uint8_t playerid) const;
|
||||
uint8_t get_fzone_sequence(uint8_t playerid, uint8_t fseq) const;
|
||||
uint8_t get_fzone_landing(card* pcard, uint8_t playerid) const;
|
||||
bool is_fzone_zone(uint32_t zone) const;
|
||||
int32_t get_useable_count(card* pcard, uint8_t playerid, uint8_t location, uint8_t uplayer, uint32_t reason, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_useable_count_fromex(card* pcard, uint8_t playerid, uint8_t uplayer, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_spsummonable_count(card* pcard, uint8_t playerid, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
|
||||
+10
-11
@@ -1575,17 +1575,16 @@ int32_t scriptlib::duel_is_environment(lua_State *L) {
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
int32_t ret = 0, fc = 0;
|
||||
if(loc & (LOCATION_FZONE + LOCATION_SZONE)) {
|
||||
card* pcard = pduel->game_field->player[0].list_szone[5];
|
||||
if(pcard && pcard->is_position(POS_FACEUP)) {
|
||||
fc = 1;
|
||||
if(code == pcard->get_code() && (playerid == 0 || playerid == PLAYER_ALL))
|
||||
ret = 1;
|
||||
}
|
||||
pcard = pduel->game_field->player[1].list_szone[5];
|
||||
if(pcard && pcard->is_position(POS_FACEUP)) {
|
||||
fc = 1;
|
||||
if(code == pcard->get_code() && (playerid == 1 || playerid == PLAYER_ALL))
|
||||
ret = 1;
|
||||
field* pfield = pduel->game_field;
|
||||
for(uint8_t p = 0; p < 2; ++p) {
|
||||
for(uint8_t fseq = 0, fzones = pfield->has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots
|
||||
card* pcard = pfield->player[p].list_szone[pfield->get_fzone_sequence(p, fseq)];
|
||||
if(pcard && pcard->is_position(POS_FACEUP)) {
|
||||
fc = 1;
|
||||
if(code == pcard->get_code() && (playerid == p || playerid == PLAYER_ALL))
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!ret && (loc & LOCATION_SZONE)) {
|
||||
|
||||
@@ -109,6 +109,18 @@ OCGCORE_API void start_duel(intptr_t pduel, uint32_t options) {
|
||||
pd->game_field->core.shuffle_hand_check[1] = FALSE;
|
||||
pd->game_field->core.shuffle_deck_check[0] = FALSE;
|
||||
pd->game_field->core.shuffle_deck_check[1] = FALSE;
|
||||
if((options & DUEL_TAG_MODE) && (options & DUEL_TAG_SHARED_EXTRA)) { // [YGOL] proposal 53: the team has one live Extra Deck
|
||||
for(uint8_t p = 0; p < 2; ++p) {
|
||||
auto& team = pd->game_field->player[p];
|
||||
for(auto& pcard : team.tag_list_extra) {
|
||||
team.list_extra.push_back(pcard);
|
||||
pcard->apply_field_effect();
|
||||
pcard->enable_field_effect(true);
|
||||
}
|
||||
team.tag_list_extra.clear();
|
||||
pd->game_field->reset_sequence(p, LOCATION_EXTRA);
|
||||
}
|
||||
}
|
||||
if(pd->game_field->player[0].start_count > 0)
|
||||
pd->game_field->draw(0, REASON_RULE, PLAYER_NONE, 0, pd->game_field->player[0].start_count);
|
||||
if(pd->game_field->player[1].start_count > 0)
|
||||
@@ -198,6 +210,7 @@ OCGCORE_API void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint
|
||||
if(owner > 1 || !(location & (LOCATION_DECK | LOCATION_EXTRA)))
|
||||
return;
|
||||
card* pcard = ptduel->new_card(code);
|
||||
pcard->tag_member = 1; // [YGOL] proposal 53
|
||||
switch(location) {
|
||||
case LOCATION_DECK:
|
||||
ptduel->game_field->player[owner].tag_list_main.push_back(pcard);
|
||||
|
||||
+11
-8
@@ -2459,7 +2459,7 @@ int32_t field::sset(uint16_t step, uint8_t setplayer, uint8_t toplayer, card * t
|
||||
return TRUE;
|
||||
uint32_t flag = 0;
|
||||
if(target->data.type & TYPE_FIELD) {
|
||||
flag = ~(0x1U << 13);
|
||||
flag = ~(0x1U << (8 + get_fzone_landing(target, toplayer))); // [YGOL] proposal 45: the partner's Field slot
|
||||
} else {
|
||||
get_useable_count(target, setplayer, LOCATION_SZONE, toplayer, LOCATION_REASON_TOFIELD, zone ? zone : 0xff, &flag);
|
||||
flag = ((flag & 0xff) << 8) | 0xffff00ff;
|
||||
@@ -2567,7 +2567,7 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group*
|
||||
card_set* set_cards = (card_set*)ptarget;
|
||||
card* target = *set_cards->begin();
|
||||
if(target->data.type & TYPE_FIELD) {
|
||||
returns.bvalue[2] = 5;
|
||||
returns.bvalue[2] = get_fzone_landing(target, toplayer); // [YGOL] proposal 45
|
||||
return FALSE;
|
||||
}
|
||||
uint32_t flag;
|
||||
@@ -2606,7 +2606,7 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group*
|
||||
target->enable_field_effect(false);
|
||||
uint32_t zone;
|
||||
if(target->data.type & TYPE_FIELD) {
|
||||
zone = 0x1U << 5;
|
||||
zone = 0x1U << get_fzone_landing(target, toplayer); // [YGOL] proposal 45
|
||||
} else {
|
||||
for(int32_t i = 0; i < 7; i++) {
|
||||
zone = 0x1U << i;
|
||||
@@ -2676,6 +2676,8 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group*
|
||||
uint8_t ct = (uint8_t)core.operated_set.size();
|
||||
if(core.set_group_used_zones & (0x1U << 5))
|
||||
--ct;
|
||||
if(core.set_group_used_zones & (0x1U << 6)) // [YGOL] proposal 45: the second Field slot
|
||||
--ct;
|
||||
if(ct <= 1)
|
||||
return FALSE;
|
||||
pduel->write_buffer8(MSG_SHUFFLE_SET_CARD);
|
||||
@@ -4602,9 +4604,10 @@ int32_t field::move_to_field(uint16_t step, card* target, uint32_t enable, uint3
|
||||
returns.ivalue[0] = FALSE;
|
||||
if((ret == RETURN_TEMP_REMOVE_TO_FIELD) && (!(target->current.reason & REASON_TEMPORARY) || (target->current.reason_effect->owner != core.reason_effect->owner)))
|
||||
return TRUE;
|
||||
if(location == LOCATION_SZONE && zone == 0x1U << 5 && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL)) {
|
||||
card* pcard = get_field_card(playerid, LOCATION_SZONE, 5);
|
||||
if(pcard) {
|
||||
if(location == LOCATION_SZONE && is_fzone_zone(zone) && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL)) {
|
||||
// [YGOL] proposal 45: the card replaces only the Field slot it lands in
|
||||
card* pcard = get_field_card(playerid, LOCATION_SZONE, get_fzone_landing(target, playerid));
|
||||
if(pcard && pcard != target) {
|
||||
if(core.duel_rule >= 3)
|
||||
send_to(pcard, 0, REASON_RULE, pcard->current.controler, PLAYER_NONE, LOCATION_GRAVE, 0, 0);
|
||||
else
|
||||
@@ -4683,8 +4686,8 @@ int32_t field::move_to_field(uint16_t step, card* target, uint32_t enable, uint3
|
||||
}
|
||||
case 1: {
|
||||
uint32_t seq = returns.bvalue[2];
|
||||
if(location == LOCATION_SZONE && zone == 0x1U << 5 && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL))
|
||||
seq = 5;
|
||||
if(location == LOCATION_SZONE && is_fzone_zone(zone) && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL))
|
||||
seq = get_fzone_landing(target, playerid); // [YGOL] proposal 45
|
||||
if(ret != RETURN_TEMP_REMOVE_TO_FIELD) {
|
||||
if(location != target->current.location) {
|
||||
uint32_t resetflag = 0;
|
||||
|
||||
@@ -800,6 +800,12 @@ int32_t SideBStartLp(int32_t fallback) { // YGOL life points per side
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
bool TagSharedExtra() { // YGOL tag shared extra
|
||||
for(const auto& pair : setup_pairs)
|
||||
if(pair == "ygol.tag.extra=shared")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
size_t WriteSetupPairsBlock(unsigned char* dst) {
|
||||
auto pdst = dst;
|
||||
BufferIO::Write<uint16_t>(pdst, (uint16_t)setup_pairs.size());
|
||||
|
||||
+10
-2
@@ -224,7 +224,7 @@ static_assert(sizeof(CTOS_Appearance) == 352, "size mismatch: CTOS_Appearance");
|
||||
check_trivially_copyable(CTOS_Dialogue);
|
||||
static_assert(sizeof(CTOS_Dialogue) == 204, "size mismatch: CTOS_Dialogue");
|
||||
constexpr int SIZE_STOC_FEATURE = sizeof(uint16_t) + sizeof(CTOS_Appearance);
|
||||
constexpr uint16_t FEATURE_PROTOCOL = 9; // YGOL host seats: 1 -> 2; YGOL seat state: 2 -> 3; YGOL lobby after match: 3 -> 4; YGOL coin toss: 4 -> 5; YGOL deck lists: 5 -> 6; YGOL profile: 6 -> 7; YGOL attack preview: 7 -> 8; YGOL tag partner cards: 8 -> 9
|
||||
constexpr uint16_t FEATURE_PROTOCOL = 11; // YGOL host seats: 1 -> 2; YGOL seat state: 2 -> 3; YGOL lobby after match: 3 -> 4; YGOL coin toss: 4 -> 5; YGOL deck lists: 5 -> 6; YGOL profile: 6 -> 7; YGOL attack preview: 7 -> 8; YGOL tag partner cards: 8 -> 9; YGOL tag two fields: 9 -> 10; YGOL tag shared extra: 10 -> 11
|
||||
constexpr uint32_t FEATURE_APPEARANCE = 0x1;
|
||||
constexpr uint32_t FEATURE_DIALOGUE = 0x2;
|
||||
constexpr uint16_t FEATURE_SENDER_SERVER = 0xff;
|
||||
@@ -464,8 +464,15 @@ constexpr uint8_t ATTACK_PREVIEW_VERSION = 1;
|
||||
constexpr uint8_t ATTACK_PREVIEW_DIRECT = 0xFF;
|
||||
constexpr int ATTACK_PREVIEW_MAX_PAIRS = 64;
|
||||
constexpr int ATTACK_PREVIEW_ANSWER_SIZE = 24; // the ygol_preview_attack answer, echoed after the pair
|
||||
// YGOL tag partner cards: the waiting teammate's hand, Extra Deck and deck (ygol_query_tag_cards), sent to that side's two seats only; 0x800 and 0x1000 are reserved by proposals 44 and 45
|
||||
// YGOL tag two fields (proposal 45): in Tag on Master Rule 4/5 each partner has a Field slot (Spell/Trap sequence 5 and 6, the core's
|
||||
// field::has_two_fields); no message, the second field reaches a client as sequence 6. A Tag room refuses a joiner without the bit
|
||||
// (ERRMSG_VERERROR), a Single room does not care; 0x800 is reserved by proposal 44
|
||||
constexpr uint32_t FEATURE_TAG_TWO_FIELDS = 0x1000;
|
||||
// YGOL tag partner cards: the waiting teammate's hand, Extra Deck and deck (ygol_query_tag_cards), sent to that side's two seats only
|
||||
constexpr uint32_t FEATURE_TAG_PARTNER_CARDS = 0x2000;
|
||||
// YGOL tag shared extra (proposal 53): with the setup pair ygol.tag.extra=shared a Tag team has one Extra Deck (option DUEL_TAG_SHARED_EXTRA)
|
||||
// and its Extra Deck refreshes carry QUERY_TAG_MEMBER; a Tag room refuses a joiner without the bit (ERRMSG_VERERROR)
|
||||
constexpr uint32_t FEATURE_TAG_SHARED_EXTRA = 0x4000;
|
||||
constexpr uint8_t TAG_PARTNER_CARDS_VERSION = 1;
|
||||
// the one-use bootstrap secret of a replacement server: a host-string token parsed apart from the ygol.* pairs, never stored anywhere else
|
||||
extern uint8_t bootstrap_secret[16];
|
||||
@@ -475,6 +482,7 @@ void SetBootstrapSecret(const char* token);
|
||||
bool WatchersAllowed();
|
||||
bool SpectatorsSeeAll(); // YGOL spectators see all
|
||||
int32_t SideBStartLp(int32_t fallback); // YGOL life points per side: ygol.side.b.lp, else fallback
|
||||
bool TagSharedExtra(); // YGOL tag shared extra: ygol.tag.extra=shared
|
||||
inline bool IsZeroId(const uint8_t* id) {
|
||||
for(int i = 0; i < 16; ++i)
|
||||
if(id[i])
|
||||
|
||||
@@ -98,7 +98,7 @@ void SingleDuel::AttackPreview(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
void SingleDuel::SendServerCapability(DuelPlayer* dp) {
|
||||
CTOS_Capability cap;
|
||||
cap.protocol = FEATURE_PROTOCOL;
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_PARTNER_CARDS; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag partner cards
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_PARTNER_CARDS | FEATURE_TAG_SHARED_EXTRA; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag two fields + tag partner cards + tag shared extra
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&cap, sizeof cap, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_CAPABILITY, buf, size);
|
||||
|
||||
@@ -50,6 +50,16 @@ void TagDuel::BroadcastFeature(unsigned char proto, unsigned char* pdata, int le
|
||||
void TagDuel::Capability(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
std::memcpy(&dp->capability, pdata, sizeof dp->capability);
|
||||
dp->has_capability = true;
|
||||
// YGOL tag two fields: a client without the bit shows the second Field slot as a Pendulum Zone, so a Tag room refuses it as out of date
|
||||
// YGOL tag shared extra: a client without the bit misreads a shared Extra Deck refresh, the same refusal
|
||||
if((dp->capability.flags & (FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_SHARED_EXTRA)) != (FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_SHARED_EXTRA)) {
|
||||
STOC_ErrorMsg scem;
|
||||
scem.msg = ERRMSG_VERERROR;
|
||||
scem.code = FEATURE_PROTOCOL;
|
||||
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
|
||||
NetServer::DisconnectAfterFlush(dp);
|
||||
return;
|
||||
}
|
||||
BroadcastFeature(STOC_CAPABILITY, pdata, len, dp->type);
|
||||
}
|
||||
void TagDuel::Appearance(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
@@ -96,7 +106,7 @@ void TagDuel::AttackPreview(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
void TagDuel::SendServerCapability(DuelPlayer* dp) {
|
||||
CTOS_Capability cap;
|
||||
cap.protocol = FEATURE_PROTOCOL;
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_PARTNER_CARDS; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag partner cards
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_PARTNER_CARDS | FEATURE_TAG_SHARED_EXTRA; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag two fields + tag partner cards + tag shared extra
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&cap, sizeof cap, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_CAPABILITY, buf, size);
|
||||
@@ -1297,6 +1307,9 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
if(host_info.no_shuffle_deck)
|
||||
opt |= DUEL_PSEUDO_SHUFFLE;
|
||||
opt |= DUEL_TAG_MODE;
|
||||
const bool shared_extra = TagSharedExtra(); // YGOL tag shared extra
|
||||
if(shared_extra)
|
||||
opt |= DUEL_TAG_SHARED_EXTRA;
|
||||
last_replay.WriteInt32(host_info.start_lp, false);
|
||||
last_replay.WriteInt32(host_info.start_hand, false);
|
||||
last_replay.WriteInt32(host_info.draw_count, false);
|
||||
@@ -1313,7 +1326,10 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
last_replay.WriteInt32((*cit)->code, false);
|
||||
}
|
||||
};
|
||||
uint16_t merged_extra[2]{}; // YGOL tag shared extra: what start_duel adds to each team's Extra Deck
|
||||
auto load_tag = [&](const std::vector<const CardDataC*>& deck_container, uint8_t p, uint8_t location) {
|
||||
if(shared_extra && location == LOCATION_EXTRA)
|
||||
merged_extra[p] = (uint16_t)deck_container.size();
|
||||
last_replay.WriteInt32(deck_container.size(), false);
|
||||
for (auto cit = deck_container.rbegin(); cit != deck_container.rend(); ++cit) {
|
||||
new_tag_card(pduel, (*cit)->code, p, location);
|
||||
@@ -1359,9 +1375,9 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[0]); // YGOL life points per side
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[1]);
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 0, LOCATION_DECK));
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 0, LOCATION_EXTRA));
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 0, LOCATION_EXTRA) + merged_extra[0]);
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 1, LOCATION_DECK));
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 1, LOCATION_EXTRA));
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 1, LOCATION_EXTRA) + merged_extra[1]);
|
||||
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, startbuf, 19);
|
||||
NetServer::ReSendToPlayer(players[1]);
|
||||
startbuf[1] = 1;
|
||||
@@ -1381,9 +1397,16 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
phase = 1;
|
||||
deck_reversed = false;
|
||||
#endif
|
||||
RefreshExtra(0);
|
||||
RefreshExtra(1);
|
||||
if(!shared_extra) {
|
||||
RefreshExtra(0);
|
||||
RefreshExtra(1);
|
||||
}
|
||||
start_duel(pduel, opt);
|
||||
if(shared_extra) { // YGOL tag shared extra: start_duel merged the lists
|
||||
RefreshExtra(0);
|
||||
RefreshExtra(1);
|
||||
}
|
||||
tag_cards_known[0] = tag_cards_known[1] = false;
|
||||
SendTagPartnerCards(0); // YGOL tag partner cards: the waiting members' opening hands
|
||||
SendTagPartnerCards(1);
|
||||
if(host_info.time_limit) {
|
||||
@@ -1420,8 +1443,10 @@ void TagDuel::Process() {
|
||||
stop = Analyze(engineBuffer.data(), engLen);
|
||||
}
|
||||
}
|
||||
if(stop != 2) // YGOL deck lists: after every engine batch, before a prompt waits
|
||||
if(stop != 2) { // YGOL deck lists + tag partner cards: after every engine batch, before a prompt waits
|
||||
FlushDeckLists();
|
||||
FlushTagPartnerCards();
|
||||
}
|
||||
if(stop == 2)
|
||||
DuelEndProc();
|
||||
}
|
||||
@@ -3050,7 +3075,9 @@ void TagDuel::FlushDeckLists() {
|
||||
}
|
||||
// YGOL tag partner cards: STOC_TAG_PARTNER_CARDS 0x5F = uint8_t side + the ygol_query_tag_cards bytes, to that side's two
|
||||
// seats (never the other team) and, when spectators see all, to every observer: after start_duel, after every
|
||||
// MSG_TAG_SWAP, in a seat's field resync (its side) and in an observer's resync / late-watcher snapshot (both sides).
|
||||
// MSG_TAG_SWAP, after any engine batch that changed the side's bytes (TICKET-424), in a seat's field resync (its side)
|
||||
// and in an observer's resync / late-watcher snapshot (both sides). A broadcast records the bytes it sent; a send to
|
||||
// one player (a resync) does not, so it never hides a change the others have not had.
|
||||
void TagDuel::SendTagPartnerCards(int side, DuelPlayer* dp) {
|
||||
if(!pduel)
|
||||
return;
|
||||
@@ -3063,6 +3090,8 @@ void TagDuel::SendTagPartnerCards(int side, DuelPlayer* dp) {
|
||||
NetServer::SendBufferToPlayer(dp, STOC_TAG_PARTNER_CARDS, buf, 1 + len);
|
||||
return;
|
||||
}
|
||||
tag_cards_sent[side].assign(buf + 1, buf + 1 + len);
|
||||
tag_cards_known[side] = true;
|
||||
for(int seat = side * 2; seat < side * 2 + 2; ++seat)
|
||||
if(players[seat])
|
||||
NetServer::SendBufferToPlayer(players[seat], STOC_TAG_PARTNER_CARDS, buf, 1 + len);
|
||||
@@ -3070,6 +3099,20 @@ void TagDuel::SendTagPartnerCards(int side, DuelPlayer* dp) {
|
||||
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
|
||||
NetServer::SendBufferToPlayer(*oit, STOC_TAG_PARTNER_CARDS, buf, 1 + len);
|
||||
}
|
||||
void TagDuel::FlushTagPartnerCards() {
|
||||
if(!pduel)
|
||||
return;
|
||||
unsigned char buf[1 + 6 + (2 * UINT8_MAX + MAINC_MAX) * sizeof(uint32_t)];
|
||||
for(int side = 0; side < 2; ++side) {
|
||||
const int len = ygol_query_tag_cards(pduel, (uint8_t)side, buf);
|
||||
if(len <= 0)
|
||||
continue;
|
||||
if(tag_cards_known[side] && tag_cards_sent[side].size() == (size_t)len
|
||||
&& std::equal(tag_cards_sent[side].begin(), tag_cards_sent[side].end(), buf))
|
||||
continue;
|
||||
SendTagPartnerCards(side);
|
||||
}
|
||||
}
|
||||
void TagDuel::TimeConfirm(DuelPlayer* dp) {
|
||||
if(host_info.time_limit == 0)
|
||||
return;
|
||||
@@ -3344,6 +3387,8 @@ void TagDuel::RefreshExtra(int player, int flag, int use_cache, DuelPlayer* dp)
|
||||
void TagDuel::RefreshExtra(int player, int flag, int use_cache)
|
||||
#endif //YGOPRO_SERVER_MODE
|
||||
{
|
||||
if(TagSharedExtra()) // YGOL tag shared extra
|
||||
flag |= QUERY_TAG_MEMBER;
|
||||
std::array<unsigned char, SIZE_QUERY_BUFFER> query_buffer;
|
||||
auto qbuf = query_buffer.data();
|
||||
auto len = WriteUpdateData(player, LOCATION_EXTRA, flag, qbuf, use_cache);
|
||||
|
||||
@@ -100,6 +100,9 @@ protected:
|
||||
CTOS_Profile profile[4]{};
|
||||
std::vector<uint16_t> preview_attackers; // YGOL attack preview: location << 8 | sequence of every attacker the open battle prompt lists
|
||||
void SendTagPartnerCards(int side, DuelPlayer* dp = nullptr); // YGOL tag partner cards: STOC 0x5F to the side's two seats (+ every observer when they see all), or to dp alone
|
||||
void FlushTagPartnerCards(); // YGOL tag partner cards: after every engine batch, a side whose bytes changed since its last broadcast sends again (TICKET-424)
|
||||
std::vector<unsigned char> tag_cards_sent[2];
|
||||
bool tag_cards_known[2]{};
|
||||
// YGOL coin toss
|
||||
void BeginChoose(int chooser, uint8_t face);
|
||||
int choose_seat{};
|
||||
|
||||
Reference in new issue
Block a user