using MessagePack; using OECS; namespace Game.Blackjack; /// /// Starts a new round after the previous one ended. /// [MessagePackObject] public struct NewRoundCommand : ICommand { public void Execute(World world) { ref var state = ref world.GetSingleton(); if (state.Phase != GamePhase.RoundOver) return; // Clear hands from previous round. var singletonEntity = World.SingletonEntity; var handEntities = new List(); using (var iter = world.Select()) { while (iter.MoveNext()) { if (iter.CurrentEntity != singletonEntity) handEntities.Add(iter.CurrentEntity); } } using (var iter = world.Select()) { while (iter.MoveNext()) { if (iter.CurrentEntity != singletonEntity) handEntities.Add(iter.CurrentEntity); } } foreach (var hand in handEntities) { var cards = world.GetSources(hand); var deckEntity = HitCommand.FindEntity(world, singletonEntity); foreach (var card in cards) { world.RemoveComponent(card); world.AddComponent(card, new InDeck { Source = card, Target = deckEntity }); } } state.Phase = GamePhase.Betting; state.Result = RoundResult.None; world.MarkModified(World.SingletonEntity); } }