Пример #1
0
        public bool SuspendGuard()
        {
            if (!FindGuardNode())
            {
                BarrierCollider.enabled = false;
                return(false);
            }
            if (!FindSuccessNode())
            {
                BarrierCollider.enabled = false;
                return(false);
            }
            if (!FindGuardCharacter())
            {
                BarrierCollider.enabled = false;
                return(false);
            }

            Motile motile = null;

            if (GuardCharacter.worlditem.Is <Motile> (out motile))
            {
                GuardNode.VacateNode(GuardCharacter.worlditem);
                MotileAction goToNodeAction = MotileAction.GoTo(SuccessNode.State);
                motile.PushMotileAction(goToNodeAction, MotileActionPriority.ForceTop);
            }
            //do this second so the guard occupies the node first, then pays attention to the player
            if (!string.IsNullOrEmpty(State.DTSOnSuccess))
            {
                Talkative talkative = null;
                if (GuardCharacter.worlditem.Is <Talkative> (out talkative))
                {
                    Speech dts = null;
                    if (Mods.Get.Runtime.LoadMod <Speech> (ref dts, "Speech", State.DTSOnSuccess))
                    {
                        talkative.SayDTS(dts);
                    }
                }
            }
            BarrierCollider.enabled           = false;
            GetComponent <Collider>().enabled = false;
            return(true);
        }
Пример #2
0
        public bool ResumeGuard(bool sayDTS)
        {
            if (!FindGuardNode())
            {
                Debug.Log("Couldn't find guard node");
                BarrierCollider.enabled = false;
                return(false);
            }
            if (!FindSuccessNode())
            {
                Debug.Log("Couldn't find success node");
                BarrierCollider.enabled = false;
                return(false);
            }
            if (!FindGuardCharacter())
            {
                Debug.Log("Couldn't find guard");
                BarrierCollider.enabled = false;
                return(false);
            }

            if (GuardCharacter.IsStunned || GuardCharacter.IsSleeping || GuardCharacter.IsDead)
            {
                Debug.Log("Guard is stunned, sleeping or dead");
                BarrierCollider.enabled = false;
                return(true);
            }

            //Debug.Log ("Player isn't wearing uniform");
            if (!GuardNode.HasOccupant)
            {
                Motile motile = null;
                if (GuardCharacter.worlditem.Is <Motile> (out motile))
                {
                    GuardNode.VacateNode(SuccessNode.worlditem);
                    MotileAction goToNodeAction = MotileAction.GoTo(GuardNode.State);
                    motile.PushMotileAction(goToNodeAction, MotileActionPriority.ForceTop);
                }
            }
            else
            {
                GuardCharacter.LookAtPlayer();
            }
            GuardCharacter.worlditem.GetOrAdd <Guard> ();
            //do this second so the guard occupies the node first, then pays attention to the player
            if (sayDTS && !string.IsNullOrEmpty(State.DTSOnFailure))
            {
                Talkative talkative = null;
                if (GuardCharacter.worlditem.Is <Talkative> (out talkative))
                {
                    Speech dts = null;
                    if (Mods.Get.Runtime.LoadMod <Speech> (ref dts, "Speech", State.DTSOnFailure))
                    {
                        talkative.SayDTS(dts);
                    }
                }
            }

            bool isOnBarrierSide = false;
            //use the node + barrier to determine direction
            Vector3 barrierPosition = BarrierCollider.bounds.center;

            barrierPosition.y = Player.Local.Position.y;
            Vector3 barrierDirection = (GuardNode.Position - barrierPosition).normalized;
            Vector3 playerDirection  = (Player.Local.Position - barrierPosition).normalized;
            float   dot = Vector3.Dot(barrierDirection, playerDirection);

            Debug.Log("Dot: " + dot.ToString());
            if (dot < 0f)
            {
                isOnBarrierSide = true;
            }

            //push the player away
            if (State.PushPlayer)
            {
                Player.Local.Audio.GetPushed();
                if (isOnBarrierSide && State.EjectFromOppositeEnd)
                {
                    mMovingPlayerToOtherSide = true;
                    StartCoroutine(MovePlayerToOtherSide());
                }
                else
                {
                    Player.Local.FPSController.AddForce(Vector3.Normalize(GuardCharacter.worlditem.Position - Player.Local.Position) * -0.1f);
                }
            }
            BarrierCollider.enabled           = true;
            GetComponent <Collider>().enabled = true;
            return(true);
        }