예제 #1
0
        public static async Task HitActionForDefault(List <HitData> hitDatas, HitMouseMachinePluginsProvider provider, int chargeSpeed = 1, bool isAdjoin = false)
        {
            var callback = new TLAutoDevicePushCallback();

            RegButtonCheckNotification(provider._pointLightButtonItems, callback);
            callback.Notify += async(sen, eve) =>
            {
                if (eve.IsError)
                {
                    return;
                }
                var switchItem = eve.Data.ToObject <SwitchItem>();
                using (var releaser = await LockAsync.LockAsync())
                {
                    if (_currentHitData?.Func != null)
                    {
                        await _currentHitData.Func(switchItem.SwitchNumber);
                    }
                }
            };
            var hitDataIndex = 0;

            foreach (var hitData in hitDatas)
            {
                var chargeSpeedIndex = 0;
ReHit:
                using (var releaser = await LockAsync.LockAsync())
                {
                    _currentHitData = hitData;
                }
                var hitResult = await hitData.CheckHit(provider._pointLightButtonItems, provider._pointLightRelayItems, provider, isAdjoin);

                if (hitResult)
                {
                    chargeSpeedIndex++;
                    if (chargeSpeedIndex == chargeSpeed)
                    {
                        await provider._chargeLightRelayItems[hitDataIndex].Control();
                    }
                    else
                    {
                        goto ReHit;
                    }
                    hitDataIndex++;
                }
                else
                {
                    //await provider.PlayTextMusicFromFirstItem("踩踏失败。");
                    goto ReHit;
                }
            }
            var buttonItem = provider._pointLightButtonItems[0];

            UnregButtonCheckNotification(buttonItem.DeviceNumber, buttonItem.ServiceAddress, callback);
            using (var releaser = await LockAsync.LockAsync())
            {
                _currentHitData = null;
            }
        }