Esempio n. 1
0
        /// <summary>
        /// Identify to Android that this activity wants to be notified when
        /// an NFC tag is discovered.
        /// </summary>
        private void EnableForegroundDispatch()
        {
            // Create an intent filter for when an NFC tag is discovered.
            var tagDetected = new IntentFilter(NfcAdapter.ActionTagDiscovered);
            var filters     = new[] { tagDetected };

            // When an NFC tag is detected, Android will use the PendingIntent to come back to this activity.
            // The OnNewIntent method will be invoked by Android.
            var intent        = new Intent(this, this.GetType()).AddFlags(ActivityFlags.SingleTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0);

            if (_nfcAdapter == null)
            {
                //var alert = new AlertDialog.Builder(this).Create();
                //alert.SetMessage("NFC is not supported on this device.");
                //alert.SetTitle("NFC Unavailable");
                //alert.SetButton("OK", delegate
                //{
                //    _writeTagButton.Enabled = false;
                //    _nfcText.Text = "NFC is not supported on this device.";
                //});
                //alert.Show();
                Speech.Say("Sorry, this device doesn't seem to support NFC.");
            }
            else
            {
                Res.AllowNewActivities = false;
                _nfcAdapter.EnableForegroundDispatch(this, pendingIntent, filters, null);
            }
        }
Esempio n. 2
0
            protected override void abortAction()
            {
                foreach (var glyph in ValidGlyphs)
                {
                    var fx = GetFeedbackFX(glyph);
                    if (glyph == null || fx == null)
                    {
                        continue;
                    }
                    fx.Stop();
                    fx.Deactivate();
                    glyph.FeedbackSFX = null;
                }

                Speech.Say("Cancelled.");
                Plugin.Vibrate.CrossVibrate.Current.Vibration(50);

                var activity = SpellCastingActivity.Current;

                activity.adapter = new GlyphDisplayAdapter(activity, new List <Glyph>());
                activity.RunOnUiThread(() => activity.listView.Adapter = activity.adapter);

                StageCancel();
            }
Esempio n. 3
0
            public async void ResolveTriggerPull()
            {
                try
                {
                    // Both debouncing and conceptually letting the gun's mechanism cycle - two birds, one rock!
                    if (DateTime.Now < nextReadyTime)
                    {
                        return;
                    }
                    lastTriggerPull = DateTime.Now;
                    nextReadyTime   = DateTime.Now + Weapon.CooldownPeriod;

                    // Is the weapon being pointed up?
                    var AngleToGravity = Gravity.Vector.AngleTo(Weapon.vectorPointedForward);
                    if (AngleToGravity < 30)
                    {
                        Weapon.ReloadSFX?.Play(useSpeakers: true);
                        nextReadyTime += Weapon.ReloadTime;
                        while (Weapon.CurrentAmmoCount < Weapon.MaxAmmoCapacity)
                        {
                            await Task.Delay((int)(Weapon.ReloadTime.TotalMilliseconds / (Weapon.MaxAmmoCapacity + 1)));

                            //await Task.Delay((int)(Weapon.ReloadTime.TotalMilliseconds / Weapon.MaxAmmoCapacity));
                            Current.SetBulletDisplay(++Weapon.CurrentAmmoCount);
                            //Weapon.ClickEmptySFX.Play(0.5); // Stand-in for the currently null ReloadSFX.
                        }
                        return;
                    }

                    // Or... is it being pointed down?  We've coded that to be "change fire mode."
                    if (AngleToGravity > 150)
                    {
                        if (!Weapon.SupportsBurstFire && !Weapon.SupportsFullAutomatic)
                        {
                            Speech.Say("This weapon supports single shot mode only.", SoundOptions.OnHeadphones);
                            return;
                        }
                        if (Weapon.CurrentFireMode == Gun.FireMode.SingleShot)
                        {
                            if (Weapon.SupportsBurstFire)
                            {
                                Weapon.CurrentFireMode = Gun.FireMode.BurstFire;
                            }
                            else if (Weapon.SupportsFullAutomatic)
                            {
                                Weapon.CurrentFireMode = Gun.FireMode.FullAuto;
                            }
                        }
                        else if (Weapon.CurrentFireMode == Gun.FireMode.BurstFire)
                        {
                            if (Weapon.SupportsFullAutomatic)
                            {
                                Weapon.CurrentFireMode = Gun.FireMode.FullAuto;
                            }
                            else
                            {
                                Weapon.CurrentFireMode = Gun.FireMode.SingleShot;
                            }
                        }
                        else
                        {
                            Weapon.CurrentFireMode = Gun.FireMode.SingleShot;
                        }
                        Speech.Say(Weapon.CurrentFireMode.ToString(), SoundOptions.OnHeadphones);
                        return;
                    }

                    // Okay. Are they out of ammo?
                    if (Weapon.CurrentAmmoCount == 0)
                    {
                        await(Weapon.ClickEmptySFX?.PlayToCompletion(null, true) ?? Task.CompletedTask);
                        return;
                    }

                    Weapon.CurrentAmmoCount--;
                    Current.SetBulletDisplay(Weapon.CurrentAmmoCount);

                    exhaleCueHasBeenProvided = false;

                    await Task.WhenAll(Task.Delay(150).ContinueWith(_ => CrossVibrate.Current.Vibration(50)),
                                       Weapon.ShotSFX.PlayToCompletion(1.0, true));

                    await Task.Delay(random.Next(100, 400));

                    // Do the dice rolls now
                    var DidHit = DidItHit();

                    // And assess the results one way or the other
                    bool   DoResultSFX;
                    double ResultSFXVolume;
                    if (DidHit)
                    {
                        DoResultSFX     = random.Next(1, 20) < 17;
                        ResultSFXVolume = 0.25 * (3.0 + Math.Max(random.NextDouble(), random.NextDouble()));
                        Current.AddKillTallymark();
                    }
                    else
                    {
                        DoResultSFX     = random.Next(1, 20) < 11;
                        ResultSFXVolume = random.NextDouble();
                    }

                    // Play the SFX depending on hit/miss status and the odds (within each) of an audible response.  Not every wound/ricochet is audible!
                    if (DoResultSFX)
                    {
                        if (DidHit)
                        {
                            ShotHitSFX.Play(ResultSFXVolume, useSpeakers: true);
                            // Experimental!!
                            Atropos.Communications.HeyYou.MyTeammates.PlaySFX(ShotHitSFX);
                        }
                        else
                        {
                            ShotMissSFX.Play(ResultSFXVolume, useSpeakers: true);
                            // Experimental!!
                            Atropos.Communications.HeyYou.MyTeammates.PlaySFX(ShotMissSFX);
                        }
                    }

                    // Testing the new Evasion code here... for now after every third shot.
                    if (Weapon.CurrentAmmoCount % 3 == 0)
                    {
                        var Incoming = new IncomingRangedAttack();
                        EvasionMode <Vector3> Evasion = (Res.CoinFlip) ? new EvasionMode.Dodge() : new EvasionMode.Duck();
                        var EvasionStage = new IncomingAttackPrepStage <Vector3>(Current, Incoming, Evasion);
                        EvasionStage.Activate();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
 private static Action Announce(string phrase)
 {
     return(() => { Speech.Say(phrase, useSpeakerMode: true); });
 }
 private static Action Say(string phrase)
 {
     return(() => { Speech.Say(phrase); });
 }
Esempio n. 6
0
        private void SetUpSpellButtons()
        {
            var layoutpanel = FindViewById <LinearLayout>(Resource.Id.Spell_casting_layoutpane);

            foreach (var spB in spellButtons)
            {
                spB.Visibility = ViewStates.Gone;
            }
            spellButtons.Clear();

            foreach (string spellName in MasterSpellLibrary.spellNames?.DefaultIfEmpty() ?? new List <string>())
            {
                if (spellName == Spell.None.SpellName)
                {
                    continue;
                }
                var spell       = MasterSpellLibrary.Get(spellName);
                var spellButton = new Button(this);
                spellButtons.Add(spellButton);
                spellButton.SetText(spellName + " (Retrain)", TextView.BufferType.Normal);
                spellButton.SetPadding(20, 20, 20, 20);
                layoutpanel.AddView(spellButton);

                spellButton.Click += (o, e) =>
                {
                    if (SpellBeingTrained != null)
                    {
                        return;                            // Debouncing, basically.
                    }
                    SpellBeingRetrained = spell;
                    SpellBeingTrained   = new Spell(spellName);
                    foreach (Button btn in spellButtons)
                    {
                        btn.Visibility = ViewStates.Gone;
                    }
                    setSpellNameButton.Text    = "Erase spell";
                    spellNameTextbox.Text      = spellName;
                    spellNameTextbox.Focusable = false;
                    CheckGlyphCount();
                    Speech.Say($"Retraining {spellName}.");
                    CurrentStage = new Spell_Training_TutorialStage($"Retraining {spellName}", ThePlayersFocus, true);
                };
            }

            spellNameTextbox   = FindViewById <EditText>(Resource.Id.spell_name_textbox);
            setSpellNameButton = FindViewById <Button>(Resource.Id.Set_spell_name_button);
            glyphCountDisplay  = FindViewById <TextView>(Resource.Id.glyph_count_display);
            undoGlyphButton    = FindViewById <Button>(Resource.Id.undo_glyph_button);
            inscribeButton     = FindViewById <Button>(Resource.Id.inscribe_spell_button);

            spellNameTextbox.KeyPress += (object sender, View.KeyEventArgs e) =>
            {
                e.Handled = false;
                if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter && spellNameTextbox.Text.Length > 0)
                {
                    setSpellNameButton.CallOnClick();
                }
                if (spellNameTextbox.Text.Length > 0)
                {
                    setSpellNameButton.Text = "Train";
                }
                else
                {
                    setSpellNameButton.Text = "Random";
                }
            };
            spellNameTextbox.ClearFocus(); // Not working, dunno why.

            setSpellNameButton.Click += async(o, e) =>
            {
                if (SpellBeingRetrained != null)
                {
                    if (setSpellNameButton.Text == "Erase spell")
                    {
                        setSpellNameButton.Text = "Confirm erasure"; return;
                    }
                    else if (setSpellNameButton.Text == "Confirm erasure")
                    {
                        MasterSpellLibrary.Erase(SpellBeingRetrained.SpellName);
                        ThePlayersFocus.ForgetSpell(SpellBeingRetrained.SpellName);
                        CurrentStage.Deactivate();
                        await Speech.SayAllOf($"Deleting {SpellBeingRetrained.SpellName} from the master library.");

                        CurrentStage = GestureRecognizerStage.NullStage;
                        //SetUpSpellButtons();
                        Current.Finish();
                        return;
                    }
                }
                SpellBeingRetrained = null;
                if (spellNameTextbox.Text.Length == 0)
                {
                    spellNameTextbox.Text = GenerateRandomSpellName();
                }
                Current.HideKeyboard();
                await Task.Delay(100); // Let the screen update.

                SpellBeingTrained = new Spell(spellNameTextbox.Text);
                foreach (Button btn in spellButtons)
                {
                    btn.Visibility = ViewStates.Gone;
                }
                //spellNameTextbox.Focusable = false;
                CheckGlyphCount();
                await Speech.SayAllOf($"Training {SpellBeingTrained.SpellName}.");

                CurrentStage = new Spell_Training_TutorialStage($"Init training for {SpellBeingTrained.SpellName}", ThePlayersFocus, true);
            };

            FindViewById <Button>(Resource.Id.glyph_training_btn).Click += async(o, e) =>
            {
                var glyphText = Res.Storage.Get(NewGlyphTrainingStage.GlyphKey);
                if (glyphText != null)
                {
                    Log.Debug("SpellTraining", "\n" + glyphText);
                }

                Current.HideKeyboard();
                await Task.Delay(100); // Let the screen update.

                foreach (Button btn in spellButtons)
                {
                    btn.Visibility = ViewStates.Gone;
                }
                await Speech.SayAllOf($"Training core glyphs.");

                //CurrentStage = new Spell_Training_TutorialStage($"Init training for {SpellBeingTrained.SpellName}", ThePlayersFocus, true);

                var provider = new GravityOrientationProvider();
                provider.Activate();
                Task.Delay(50)
                .ContinueWith(async _ => await SensorProvider.EnsureIsReady(provider))
                .ContinueWith(_ => CurrentStage = new NewGlyphTrainingStage(0, ThePlayersFocus, provider))
                .LaunchAsOrphan();
            };

            undoGlyphButton.Click += async(o, e) =>
            {
                if (SpellBeingTrained.Glyphs.Count == 0)
                {
                    foreach (Button btn in spellButtons)
                    {
                        btn.Enabled = true;
                    }
                    spellNameTextbox.Text      = "";
                    spellNameTextbox.Focusable = true;
                    setSpellNameButton.Enabled = true;
                    setSpellNameButton.Text    = "Random";
                    SpellBeingRetrained        = null;
                    SpellBeingTrained          = null;
                    CurrentStage.Deactivate();
                    CurrentStage = GestureRecognizerStage.NullStage;
                    SetUpSpellButtons();
                    await Speech.SayAllOf("Aborting spell training.");
                }
                else
                {
                    SpellBeingTrained.UndoAddGlyph();
                    await Speech.SayAllOf("Removing most recent glyph.");
                }
                CheckGlyphCount();
            };

            var feedbackSFXbtn = FindViewById <Button>(Resource.Id.spell_feedback_sfx_button);
            var progressSFXbtn = FindViewById <Button>(Resource.Id.spell_progress_sfx_button);
            var successSFXbtn  = FindViewById <Button>(Resource.Id.spell_success_sfx_button);

            if (!MasterSpellLibrary.GetSFXReadyTask().Wait(5000))
            {
                Log.Error("Spell training", "Can't prep the buttons (as is, anyway) without our SFX loaded, which doesn't seem to be happening.");
            }
            var feedbackSFXoptions = new SimpleCircularList <string>("Magic.Ethereal",
                                                                     "Magic.Aura", "Magic.DeepVenetian", "Magic.InfiniteAubergine", "Magic.Ommm", "Magic.AfricanDrums",
                                                                     "Magic.Rommble", "Magic.MidtonePianesque", "Magic.FemReverbDSharp", "Magic.FemReverbCSharp",
                                                                     "Magic.FemReverbF", "Magic.FemReverbE", "Magic.AlienTheremin",
                                                                     "Magic.TrompingBuzzPulse", "Magic.GrittyDrone", "Magic.Galewinds", "Magic.NanobladeLoop",
                                                                     "Magic.ViolinLoop", "Magic.StrongerThanTheDark", "Magic.MelodicPad");
            var progressSFXoptions = new SimpleCircularList <string>(MasterSpellLibrary.SpellSFX.Keys.Where(sfx => !feedbackSFXoptions.Contains(sfx)).DefaultIfEmpty().ToArray());
            var successSFXoptions  = new SimpleCircularList <string>(MasterSpellLibrary.CastingResults.Keys.ToArray());

            while (progressSFXoptions.Next != MasterSpellLibrary.defaultProgressSFXName)
            {
            }                                                                                // Cycle the list to the correct starting point.
            while (successSFXoptions.Next != "Play " + MasterSpellLibrary.defaultSuccessSFXName)
            {
            }                                                                                        // Cycle the list to the correct starting point.

            inscribeButton.Click += async(o, e) =>
            {
                if (inscribeButton.Text == "Inscribe Spell")
                {
                    // Halt ongoing processeses
                    MasterSpellLibrary.SpellFeedbackSFX.Deactivate();
                    CurrentStage.Deactivate();
                    CurrentStage = GestureRecognizerStage.NullStage;

                    // Display SFX modification buttons
                    feedbackSFXbtn.Visibility = ViewStates.Visible;
                    progressSFXbtn.Visibility = ViewStates.Visible;
                    successSFXbtn.Visibility  = ViewStates.Visible;

                    IEffect sampleSFX = null;
                    Func <SimpleCircularList <string>, Button, string, EventHandler> HandlerFactory
                        = (circList, btn, label) =>
                        {
                        return((ob, ev) =>
                        {
                            sampleSFX?.Stop();
                            btn.Text = $"{label} ('{circList.Next}')";
                            if (MasterSpellLibrary.SpellSFX.ContainsKey(circList.Current.Split(' ').Last()))
                            {
                                sampleSFX = MasterSpellLibrary.SpellSFX[circList.Current.Split(' ').Last()];
                                sampleSFX.Play();
                            }
                            else
                            {
                            }
                        });
                        };
                    feedbackSFXbtn.Click += HandlerFactory(feedbackSFXoptions, feedbackSFXbtn, "Feedback SFX");
                    progressSFXbtn.Click += HandlerFactory(progressSFXoptions, progressSFXbtn, "Progress SFX");
                    successSFXbtn.Click  += HandlerFactory(successSFXoptions, successSFXbtn, "Success Func");

                    inscribeButton.Text = "Finish Inscribing";
                }
                else
                {
                    feedbackSFXbtn.Visibility = ViewStates.Gone;
                    progressSFXbtn.Visibility = ViewStates.Gone;
                    successSFXbtn.Visibility  = ViewStates.Gone;

                    SpellBeingTrained.CastingResult = MasterSpellLibrary.CastingResults[successSFXoptions.Current];
                    foreach (var glyph in SpellBeingTrained.Glyphs)
                    {
                        glyph.FeedbackSFXName = feedbackSFXoptions.Current;
                        glyph.ProgressSFXName = progressSFXoptions.Current;
                    }
                    MasterSpellLibrary.Inscribe(SpellBeingTrained);
                    ThePlayersFocus.LearnSpell(SpellBeingTrained);

                    //ResetSpell();
                    if (SpellBeingRetrained == null)
                    {
                        await Speech.SayAllOf($"Adding {SpellBeingTrained.SpellName} to the master library.");
                    }
                    else
                    {
                        await Speech.SayAllOf($"Updating spell listing for {SpellBeingTrained.SpellName}.");
                    }
                    Log.Info("SpellTraining", $"Here's the spell string for copy-and-pasting as a constant: {SpellBeingTrained.ToString()}");
                    Current.Finish();
                }
            };
        }