Example #1
0
 private void RespawnDummyPlayer(RecyclablePrefab unused)
 {
     CleanupDummyPlayer(recycle: false);
     CoroutineWrapper.DoAfterDelay(3.0f, () => {
         SpawnDummyPlayer();
     });
 }
        // PRAGMA MARK - IRecycleSetupSubscriber Implementation
        public void OnRecycleSetup()
        {
            float segmentSize     = 1.0f / kSegments;
            float halfSegmentSize = segmentSize / 2.0f;

            for (float x = -0.5f + halfSegmentSize; x <= 0.5f; x += segmentSize)
            {
                for (float y = -0.5f + halfSegmentSize; y <= 0.5f; y += segmentSize)
                {
                    for (float z = -0.5f + halfSegmentSize; z <= 0.5f; z += segmentSize)
                    {
                        GameObject partObject = ObjectPoolManager.Create(partPrefab_, parent: this.gameObject);
                        partObject.transform.localScale    = new Vector3(segmentSize, segmentSize, segmentSize);
                        partObject.transform.localPosition = new Vector3(x, y, z);
                    }
                }
            }

            if (InGameConstants.BattlePlayerPartsFade)
            {
                coroutine_ = CoroutineWrapper.DoAfterDelay(GameConstants.Instance.BattlePlayerPartFadeDuration, () => {
                    ObjectPoolManager.Recycle(this);
                });
            }
        }
Example #3
0
        protected override void OnStateEntered()
        {
            if (!PlayerScores.HasPendingScores)
            {
                HandleScoringFinished();
                return;
            }

            InGameConstants.AllowChargingLasers = false;
            InGameConstants.EnableQuacking      = true;

            GameModesProgressionNextUnlockView.ShowIfPossible();
            ActionHintTrackerUtil.ShowIfNecessary(HintKey.CelebrateAction, HintKey.ReflectAction);
            celebrateActionAccumulator_.BeginAccumulating();

            if (InGameConstants.ZoomInOnSurvivors)
            {
                BattleCamera.Instance.SetSurvivingPlayersAsTransformsOfInterest();
            }

            if (InGameConstants.ShowScoringView)
            {
                CoroutineWrapper.DoAfterDelay(kShowDelay, () => {
                    InGamePlayerScoringView.Show(HandleScoringFinished);
                });
            }
            else
            {
                CoroutineWrapper.DoAfterDelay(kShowDelay + 2.0f, () => {
                    HandleScoringFinished();
                });
            }
        }
Example #4
0
        // PRAGMA MARK - Public Interface
        public void Init(string title, GameObject detailPrefab, Action allPlayersReadyCallback)
        {
            titleText_.Text = title;

            ObjectPoolManager.Create(detailPrefab, parent: detailContainer_);

            views_.Clear();
            allPlayersReadyCallback_ = allPlayersReadyCallback;

            foreach (Player player in RegisteredPlayers.AllPlayers.Where(p => !p.IsAI))
            {
                var view = ObjectPoolManager.Create <InstructionPlayerReadyView>(GamePrefabs.Instance.InstructionPlayerReadyViewPrefab, parent: playersReadyContainer_);
                view.Init(player);
                view.OnReady += CheckIfAllPlayersReady;

                views_.Add(view);
            }

            transition_.AnimateIn(() => {
                // NOTE (darren): don't allow players to ready up until transition is finished
                foreach (var view in views_)
                {
                    view.StartChecking();
                }

                CoroutineWrapper.DoAfterDelay(kNoPlayersCheckDuration, () => {
                    // NOTE (darren): if all AI players then this will pass inspection
                    CheckIfAllPlayersReady();
                });
            });
        }
 private void KeepBeakOpenFor(float duration)
 {
     keepBeakOpen_ = true;
     CoroutineWrapper.DoAfterDelay(duration, () => {
         keepBeakOpen_ = false;
     });
 }
Example #6
0
        private void FixedUpdate()
        {
            if (!enabled_)
            {
                return;
            }

            int  resultCount = GetRaycastPositions().Sum(pos => CollisionsAtPosition(pos));
            bool isOffGround = resultCount <= 0;

            if (checkDeath_ && isOffGround)
            {
                enabled_ = false;

                GameNotifications.OnBattlePlayerFellOffGround.Invoke(Player_);

                Player_.InputController.DisableInput(BattlePlayerInputController.PriorityKey.OffGround);
                Player_.InputController.CancelAnyAnimatedMovements();
                Player_.Rigidbody.constraints = RigidbodyConstraints.None;
                Player_.Rigidbody.drag        = 0.0f;
                dustParticleSystem_.SetEmissionRateOverDistance(0.0f);
                coroutine_ = CoroutineWrapper.DoAfterDelay(kDeathDelay, () => {
                    Player_.Health.Kill();
                });
            }
        }
Example #7
0
        void ITransition.Animate(TransitionType transitionType, float delay, Action <ITransition> callback)
        {
            CurrentTransitionType_ = transitionType;

            EaseType easeType   = (transitionType == TransitionType.In) ? inEaseType_ : outEaseType_;
            T        startValue = (transitionType == TransitionType.In) ? GetOutValue() : GetInValue();

            if (currentCoroutine_ != null)
            {
                currentCoroutine_.Cancel();
                currentCoroutine_ = null;

                // If interrupted - start from current value
                startValue = GetCurrentValue();
            }

            T endValue = (transitionType == TransitionType.In) ? GetInValue() : GetOutValue();

            SetValue(startValue, endValue, 0.0f);
            currentCoroutine_ = CoroutineWrapper.DoAfterDelay(baseDelay_ + delay, () => {
                currentCoroutine_ = CoroutineWrapper.DoEaseFor(duration_, easeType, (float p) => {
                    SetValue(startValue, endValue, p);
                }, () => {
                    currentCoroutine_ = null;
                    callback.Invoke(this);
                });
            });
        }
Example #8
0
 protected override void OnStateUpdated()
 {
     if (coroutine_ == null && InGameConstants.IsAllowedToChargeLasers(StateMachine_.Player))
     {
         coroutine_ = CoroutineWrapper.DoAfterDelay(GetRandomCheckAttackDelay(), () => {
             StateMachine_.SwitchState(AIStateMachine.State.Attack);
         });
     }
 }
Example #9
0
        private void HandleFullyChargedLaser()
        {
            delayedAttackAction_ = CoroutineWrapper.DoAfterDelay(StateMachine_.AIConfiguration.RandomReactionTime(), () => {
                StateMachine_.InputState.LaserPressed = false;

                // NOTE (darren): why delay here? to simulate AI watching laser hit / miss target :)
                delayedAttackAction_ = CoroutineWrapper.DoAfterDelay(StateMachine_.AIConfiguration.RandomReactionTime(), () => {
                    StateMachine_.SwitchState(AIStateMachine.State.Idle);
                });
            });
        }
Example #10
0
        private static void RemovePlayer(AISpawnPoint spawnPoint)
        {
            spawnPointMap_.Remove(spawnPoint);

            if (ShouldRespawn)
            {
                respawnCoroutines_.Add(CoroutineWrapper.DoAfterDelay(kRespawnDelay, () => {
                    SpawnAIPlayerFor(spawnPoint);
                }));
            }
        }
Example #11
0
        private void SetReflectiveFor(float time)
        {
            CancelReflectCoroutine();

            reflect_ = true;
            Player_.Health.HandleCollisions = false;

            reflectCoroutine_ = CoroutineWrapper.DoAfterDelay(time, () => {
                RemoveReflect();
            });
        }
Example #12
0
        protected override void OnStateEntered()
        {
            movementAction_.Init(StateMachine_);

            CoroutineWrapper.DoAfterDelay(StateMachine_.AIConfiguration.RandomReactionTime(), () => {
                StateMachine_.InputState.LaserPressed = false;
                if (UnityEngine.Random.Range(0.0f, 1.0f) <= kCluckChance)
                {
                    coroutine_ = CoroutineWrapper.StartCoroutine(DoCluckCoroutine());
                }
            });
        }
Example #13
0
        protected override void OnStateEntered()
        {
            Vector2 dashDirection = StateMachine_.DashDirection;

            StateMachine_.InputState.LerpMovementVectorTo(dashDirection, () => {
                StateMachine_.InputState.Dash();

                coroutine_ = CoroutineWrapper.DoAfterDelay(StateMachine_.AIConfiguration.RandomReactionTime(), () => {
                    StateMachine_.SwitchState(AIStateMachine.State.Idle);
                });
            });
        }
Example #14
0
        // PRAGMA MARK - IRecycleSetupSubscriber Implementation
        public void OnRecycleSetup()
        {
            RemoveCollidersEvent += RemoveColliders;
            foreach (var collider in colliders_)
            {
                collider.enabled = true;
            }

            if (InGameConstants.BattlePlayerPartsFade)
            {
                CoroutineWrapper.DoAfterDelay(GameConstants.Instance.BattlePlayerPartFadeDuration * 0.8f, RemoveColliders);
            }
        }
        private void SetInvulnerableFor(float time)
        {
            if (invulnerableCoroutine_ != null)
            {
                invulnerableCoroutine_.Cancel();
                invulnerableCoroutine_ = null;
            }

            invulnerable_          = true;
            invulnerableCoroutine_ = CoroutineWrapper.DoAfterDelay(time, () => {
                invulnerable_ = false;
            });
        }
Example #16
0
        private void HandleScoringFinished()
        {
            BattleCamera.Instance.ClearTransformsOfInterest();
            BattlePlayerPart.RemoveCollidersFromAll();

            CoroutineWrapper.DoAfterDelay(kResetCameraDelay, () => {
                if (PlayerScores.HasWinner)
                {
                    StateMachine_.HandleGameFinished();
                }
                else
                {
                    StateMachine_.Continue();
                }
            });
        }
Example #17
0
        private static void RemovePlayer(Player player)
        {
            if (!playerMap_.ContainsKey(player))
            {
                return;
            }

            playerMap_.Remove(player);
            OnSpawnedPlayerRemoved.Invoke();

            if (ShouldRespawn)
            {
                respawnCoroutines_.Add(CoroutineWrapper.DoAfterDelay(kRespawnDelay, () => {
                    SpawnPlayer(player);
                }));
            }
        }
        private void OnTriggerEnter(Collider collider)
        {
            if (!HandleCollisions)
            {
                return;
            }

            Laser laser = collider.gameObject.GetComponentInParent <Laser>();

            if (laser == null)
            {
                return;
            }

            if (lasersHit_.Contains(laser))
            {
                return;
            }

            lasersHit_.Add(laser);
            CoroutineWrapper.DoAfterDelay(kClearLaserHitTime, () => {
                lasersHit_.Remove(laser);
            });

            int damage = LaserDamage;

            // laser only does damage if not on same team
            // HACK (darren): BattlePlayer needs to be refactored in things like Laser / Teams
            // because BattlePlayer can be recycled it's not a good thing to keep track of
            // should instead make a HashCode-like thing
            if (laser.BattlePlayer != null && BattlePlayerTeams.AreOnSameTeam(laser.BattlePlayer, Player_))
            {
                damage = 0;
            }

            GameNotifications.OnBattlePlayerLaserHit.Invoke(laser, Player_);

            Vector3 forward = laser.transform.forward;

            TakeDamage(damage, forward, damageSource: laser);
            laser.HandleHit();
        }
        // PRAGMA MARK - Public Interface
        public static void MoveTo(this BattlePlayerInputController controller, BattlePlayer player, Vector3 endPosition, float duration, EaseType easeType, Action onFinishedCallback = null)
        {
            Vector3 startPosition = player.Rigidbody.position;
            float   oldDrag       = player.Rigidbody.drag;

            controller.DisableInput(BattlePlayerInputController.PriorityKey.Movement);
            player.Rigidbody.drag = BattlePlayer.kBaseDrag;
            player.Rigidbody.AddForce((endPosition - startPosition) * 10, ForceMode.Impulse);
            var coroutine = CoroutineWrapper.DoAfterDelay(duration, () => {
                player.Rigidbody.drag = oldDrag;
                controller.EnableInput(BattlePlayerInputController.PriorityKey.Movement);
                controller.CancelAnyAnimatedMovements();
                if (onFinishedCallback != null)
                {
                    onFinishedCallback.Invoke();
                }
            });

            controller.RegisterAnimatedMovement(coroutine);
        }
        public void Knockback(Vector3 forward, object damageSource = null)
        {
            if (knockbackClearCoroutine_ != null)
            {
                knockbackClearCoroutine_.Cancel();
                knockbackClearCoroutine_ = null;
            }

            OnBattlePlayerKnockbacked.Invoke(Player_);

            knockbackDamageSource_ = damageSource;
            Vector3 endPosition = Player_.Rigidbody.position + (KnockbackMultiplier * kDamageKnockbackDistance * forward);

            Player_.InputController.MoveTo(Player_, endPosition, kDamageKnockbackDuration * KnockbackMultiplier, EaseType.CubicEaseOut, onFinishedCallback: () => {
                // why do we have another delay? Because dashing pauses checking if off ground,
                // we need to persist the source of knockback for a little bit
                knockbackClearCoroutine_ = CoroutineWrapper.DoAfterDelay(0.1f, () => {
                    knockbackDamageSource_ = null;
                });
            });
        }
        private static void VibrateInputDevice(IInputWrapper input, float vibrationAmount, float duration)
        {
            var inputWrapperDevice = input as InputWrapperDevice;

            if (inputWrapperDevice == null)
            {
                return;
            }

            InputDevice inputDevice = inputWrapperDevice.InputDevice;

            if (vibrationCoroutineMap_.ContainsKey(inputDevice))
            {
                vibrationCoroutineMap_[inputDevice].Cancel();
            }

            inputDevice.Vibrate(vibrationAmount);
            vibrationCoroutineMap_[inputDevice] = CoroutineWrapper.DoAfterDelay(duration, () => {
                inputDevice.StopVibration();
            });
        }
        // PRAGMA MARK - Public Interface
        public GhostModePlayerAddOn(BattlePlayer battlePlayer)
        {
            battlePlayer_                = battlePlayer;
            recyclablePrefab_            = battlePlayer_.GetComponentInParent <RecyclablePrefab>();
            recyclablePrefab_.OnCleanup += HandleCleanup;

            battlePlayer_.DustParticleSystem.gameObject.SetActive(false);
            SetAlpha(1.0f);
            foreach (Renderer r in battlePlayer_.BodyRenderers)
            {
                Color diffuseColor = r.material.GetColor("_DiffuseColor");
                r.material = GameConstants.Instance.PlayerTransparentMaterial;
                r.material.SetColor("_DiffuseColor", diffuseColor);
                r.shadowCastingMode = ShadowCastingMode.Off;
            }

            CoroutineWrapper.DoAfterDelay(kFadeAwayDelay, () => {
                CoroutineWrapper.DoEaseFor(kFadeAwayDuration, EaseType.QuadraticEaseOut, (p) => {
                    SetAlpha(Mathf.Lerp(1.0f, 0.0f, p));
                });
            });
        }
Example #23
0
        private void Animate()
        {
            image_.material.SetFloat("_SegmentLength", segmentLength_);
            image_.material.SetFloat("_AngleOffset", angleOffset_);

            // animate color in
            CoroutineWrapper.DoEaseFor(kAnimateColorDuration, EaseType.CubicEaseInOut, (float p) => {
                image_.color = ColorUtil.LerpWhiteBlack(1.0f - p);
            });

            // animate color out
            CoroutineWrapper.DoAfterDelay(kAnimateDuration - kAnimateColorDuration, () => {
                CoroutineWrapper.DoEaseFor(kAnimateColorDuration, EaseType.CubicEaseInOut, (float p) => {
                    image_.color = ColorUtil.LerpWhiteBlack(p);
                });
            });

            CoroutineWrapper.DoEaseFor(kAnimateDuration, EaseType.CubicEaseOut, (float p) => {
                image_.material.SetFloat("_SegmentLength", segmentLength_ + (p * segmentLengthChange_));
                image_.material.SetFloat("_AngleOffset", angleOffset_ + (p * angleOffsetChange_));
            });
        }
Example #24
0
 // PRAGMA MARK - IRecycleSetupSubscriber Implementation
 public void OnRecycleSetup()
 {
     CoroutineWrapper.DoAfterDelay(duration_, () => {
         ObjectPoolManager.Recycle(this);
     });
 }