/// <summary>
        /// sealed override, responsible for most of the bulk of the work of the TimedBehaviour.
        /// </summary>
        /// <param name="toPaddle"></param>
        /// <param name="gamestate"></param>
        public override sealed void BehaviourAdded(Paddle toPaddle, BCBlockGameState gamestate)
        {
            //call base implementation
            base.BehaviourAdded(toPaddle, gamestate);
            //check if we are SingleInstance. If so, that means that there can only be one instance at a time, which may not be surprising given the name.
            if (SingleInstance())
            {
                //check for existing instances of our class. If found, add our delay time to them.
                foreach (var iterate in (from p in toPaddle.Behaviours where p != this select p))
                {
                    if (iterate.GetType() == GetType())
                    {
                        //if same type, change delay, and break from routine.
                        (iterate as TimedPaddleBehaviour).ChangeDelayTime(gamestate, _BehaviourTime, true);
                        //make sure this instance get's removed, too! we are redundant now.
                        gamestate.NextFrameCalls.Enqueue
                            (new BCBlockGameState.NextFrameStartup(() => toPaddle.Behaviours.Remove(this)));

                        return;
                    }
                }
            }

            //if we are either not singleinstance or we are single instance but there are no existing  behaviours of our type attached,
            //do the stuff to add us.
            DelayIdentifier = gamestate.DelayInvoke(_BehaviourTime, TimeDelayRoutine, new object[] {gamestate});
            //if we have ability music, we play it now. Use the SoundManager's capacity to handle temporary music, which works rather well.
            if (_AbilityMusic != "") BCBlockGameState.Soundman.PlayTemporaryMusic(_AbilityMusic, 1.0f, true);
            //hook Death function. If the paddle dies, obviously the time delay will break out early, so we will need to stop the temporary music ourself.
            toPaddle.OnDeath += new Func<Paddle, bool>(toPaddle_OnDeath);
            //call abstract method for initialization.
            TimedBehaviourInitialize(toPaddle, gamestate);
        }
Esempio n. 2
0
 public override void AbilityInit(GameCharacter gamechar, BCBlockGameState gstatem)
 {
     gamechar.OnDeath += gamechar_OnDeath;
     DelayIdentifier = gstatem.DelayInvoke(_Duration, revertroutinefunc, new object[] { gamechar, gstatem });
     AbilityStart = DateTime.Now;
     if (!String.IsNullOrEmpty(_AbilityMusic))
         //BCBlockGameState.Soundman.PushMusic(_AbilityMusic, 1.0f, true);
         BCBlockGameState.Soundman.PlayTemporaryMusic(_AbilityMusic, 1.0f, true);
 }
Esempio n. 3
0
        public override void BehaviourAdded(cBall onBall, BCBlockGameState currstate)
        {
            base.BehaviourAdded(onBall, currstate);

            //start timer...
            currstate.DelayInvoke(_TimeLength, DelayRoutine, null);
        }
Esempio n. 4
0
        public override void BehaviourAdded(cBall onBall, BCBlockGameState currstate)
        {
            base.BehaviourAdded(onBall, currstate);
                    BaseBehaviour AddedBehaviour = (BaseBehaviour)Activator.CreateInstance(useBehaviour);

                    currstate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup(() => onBall.Behaviours.Add(AddedBehaviour)));

                    currstate.DelayInvoke(_Span,delayroutine,new object[]{onBall,AddedBehaviour});
        }
Esempio n. 5
0
        public override bool PerformBlockHit(BCBlockGameState parentstate, cBall ballhit)
        {
            if (_Locked) return false;
            Active = !Active;
            _hasChanged = true;

            BCBlockGameState.Soundman.PlaySound(Active ? ActiveSound : InactiveSound);
            int IDcheck = Active ? AllActiveID : AllInactiveID;

            IEnumerable<SwitchBlock> dealblocks=null;
            bool triggered = false;
            bool? triggerbool = null;

            if ((SwitchMode & SwitchModeConstants.SwitchMode_MultipleBlock) != SwitchModeConstants.SwitchMode_MultipleBlock)
            {
                //we need to deal with only this block.
                dealblocks = new SwitchBlock[] { this};
            }
            else if ((SwitchMode & SwitchModeConstants.SwitchMode_MultipleBlock)==SwitchModeConstants.SwitchMode_MultipleBlock)
            {
                //we need to work with all blocks in the set that are SwitchBlocks and have the same ID.

                dealblocks = (from t in parentstate.Blocks where t is SwitchBlock && (t as SwitchBlock).ID(Active) == IDcheck select (SwitchBlock)t);
            }
            if (dealblocks == null || !dealblocks.Any())
            {
                //uhhh...
                return false;

            }
            // are all dealblocks activated?
            if (AllActiveID != 0)
            {
                if (dealblocks.All((t) => t.Active))
                {
                    triggered = true;
                    triggerbool = true; //all active.
                    BCBlockGameState.Soundman.PlaySound("laser2");
                    Trigger.InvokeTriggerID(AllActiveID, parentstate);

                }
            }
            if (AllInactiveID != 0)
            {
                if (dealblocks.All((t) => !t.Active))
                {
                    triggered = true;
                    triggerbool = false;
                    BCBlockGameState.Soundman.PlaySound("laser2");
                    Trigger.InvokeTriggerID(AllInactiveID, parentstate);
                }

            }
            if (triggered) //only destroy or reset if we were triggered.
            {
                if ((SwitchMode & SwitchModeConstants.SwitchMode_MultiTrigger) != SwitchModeConstants.SwitchMode_MultiTrigger)
                {
                    //we fire once. if activated, destroy all the blocks we worked with.

                    parentstate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup(() =>
                    {
                        var removethese = dealblocks.ToList();
                        foreach (var destroythis in removethese)
                        {
                            destroythis.StandardSpray(parentstate,null);
                            parentstate.Blocks.Remove(destroythis);

                        }
                        parentstate.Forcerefresh = true;
                    }));

                }
                else if ((SwitchMode & SwitchModeConstants.SwitchMode_MultiTrigger) == SwitchModeConstants.SwitchMode_MultiTrigger)
                {
                    //can fire multiple times. Set the state of all affected blocks to false.
                    //We will do this on a time delay, however, and set their "Locked" property to true, preventing
                    //this routine from changing their active state in the future until the delay expires.
                    foreach (var anullthis in dealblocks)
                    {
                        anullthis.Locked = true;
                    }
                    parentstate.DelayInvoke(new TimeSpan(0, 0, 0, 1), (a) =>
                    {
                        parentstate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup(() =>
                        {
                            foreach (var unlockit in dealblocks)
                            {
                                unlockit.Active = !(triggerbool.Value);  //invert to old value.
                                unlockit.Locked = false;

                            }
                            parentstate.Forcerefresh = true;
                        }
                        ));
                    });
                }
            }
            return false; //don't destroy.
        }