Esempio n. 1
0
        public void ResetActiveTarget()
        {
            // handle previous target
            m_PreviousTarget           = m_ActiveTarget;
            m_PreviousTargetGameObject = m_ActiveTargetGameObject;
            m_PreviousTargetID         = m_ActiveTargetID;
            m_PreviousTargetName       = m_ActiveTargetName;
            m_PreviousTargetKey        = m_ActiveTargetName + m_ActiveTargetID.ToString();

            if (m_PreviousTarget != null)
            {
                m_PreviousTarget.SetActive(false);

                if (m_PreviousTarget.EntityComponent != null)
                {
                    m_PreviousTarget.EntityComponent.RemoveActiveCounterpart(OwnerComponent as ICECreatureEntity);
                }

                if (m_PreviousTarget.GroupMessage.Type != BroadcastMessageType.NONE)
                {
                    BroadcastMessageDataObject _data = new BroadcastMessageDataObject();
                    _data.Type             = m_PreviousTarget.GroupMessage.Type;
                    _data.TargetGameObject = m_PreviousTargetGameObject;
                    _data.Command          = "";

                    ICECreatureEntity _entity = OwnerComponent as ICECreatureEntity;
                    if (_entity != null)
                    {
                        _entity.Message.SendGroupMessage(_data);
                    }
                }
            }

            m_ActiveTarget           = null;
            m_ActiveTargetGameObject = null;
            m_ActiveTargetID         = 0;
            m_ActiveTargetName       = "";
            m_ActiveTargetKey        = "";
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the active target.
        /// </summary>
        /// <param name="_target">_target.</param>
        public void SetActiveTarget(TargetObject _target)
        {
            if (Status.IsDead)
            {
                return;
            }

            if (Move.Deadlocked)
            {
                Move.ResetDeadlock();
                if (Move.DeadlockAction == DeadlockActionType.BEHAVIOUR)
                {
                    Behaviour.SetBehaviourModeByKey(Move.DeadlockBehaviour);
                    return;
                }
                else if (Move.DeadlockAction == DeadlockActionType.UPDATE && m_ActiveTarget != null)
                {
                    m_ActiveTarget.UpdateOffset();
                }
                else
                {
                    Status.Kill();
                    return;
                }
            }


            if (_target == null || Status.RecreationRequired)
            {
                _target = Essentials.Target;
            }

            if (_target == null || !_target.IsValid)
            {
                Debug.LogError(m_Owner.name + " have no target!");
                return;
            }

            if (IsTargetUpdatePermitted(_target))
            {
                if (m_ActiveTarget != _target)
                {
                    m_PreviousTarget = m_ActiveTarget;

                    if (m_PreviousTarget != null)
                    {
                        m_PreviousTarget.SetActive(false);
                    }

                    m_ActiveTarget = _target;

                    if (m_ActiveTarget != null)
                    {
                        m_ActiveTarget.SetActive(true);
                    }

                    m_TargetChanged = true;
                }

                if (m_ActiveTarget != null)
                {
                    Behaviour.SetBehaviourModeByKey(ActiveTarget.BehaviourModeKey);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Sets the active target.
        /// </summary>
        /// <param name="_target">_target.</param>
        public void SetActiveTarget(TargetObject _target)
        {
            if (Status.IsDead || Status.IsSpawning)
            {
                return;
            }

            if (Move.Deadlock.Deadlocked)
            {
                Move.Deadlock.Reset(Owner.transform);
                if (Move.Deadlock.Action == DeadlockActionType.BEHAVIOUR)
                {
                    SetActiveBehaviourModeByKey(Move.Deadlock.Behaviour);
                    return;
                }
                else if (Move.Deadlock.Action == DeadlockActionType.UPDATE && m_ActiveTarget != null)
                {
                    m_ActiveTarget.Move.UpdateRandomOffset();
                }
                else
                {
                    Status.Kill();
                    return;
                }
            }

            if (_target == null || !_target.IsValidAndReady || Status.RecreationRequired)
            {
                _target = Essentials.PrepareTarget(OwnerComponent);
            }

            if (_target == null || !_target.IsValidAndReady)
            {
                if (DebugLogIsEnabled)
                {
                    PrintDebugLog(this, "Sorry, the creature have no valid target!");
                }
                return;
            }

            m_TargetChanged = false;
            if (IsTargetUpdatePermitted(_target))
            {
                // update target
                if (!_target.CompareTarget(m_ActiveTarget, m_ActiveTargetID))
                {
                    // handle previous target
                    ResetActiveTarget();

                    // handle new target
                    m_ActiveTarget           = _target;
                    m_ActiveTargetGameObject = _target.TargetGameObject;
                    m_ActiveTargetID         = _target.TargetID;
                    m_ActiveTargetName       = _target.TargetName;
                    m_ActiveTargetKey        = _target.TargetName + _target.TargetID.ToString();

                    if (m_ActiveTarget != null)
                    {
                        m_ActiveTarget.SetActive(OwnerComponent);

                        if (m_ActiveTarget.EntityComponent != null)
                        {
                            m_ActiveTarget.EntityComponent.AddActiveCounterpart(OwnerComponent as ICECreatureEntity);
                        }

                        if (m_ActiveTarget.GroupMessage.Type != BroadcastMessageType.NONE)
                        {
                            /*
                             * BroadcastMessageDataObject _data = new BroadcastMessageDataObject();
                             *
                             * _data.Type = m_ActiveTarget.GroupMessage.Type;
                             * _data.TargetGameObject = m_ActiveTarget.TargetGameObject;
                             * _data.Command = m_ActiveTarget.GroupMessage.Command;*/

                            ICECreatureEntity _entity = OwnerComponent as ICECreatureEntity;
                            if (_entity != null)
                            {
                                _entity.Message.SendGroupMessage(new BroadcastMessageDataObject(m_ActiveTarget.GroupMessage.Type, m_ActiveTarget.TargetGameObject, m_ActiveTarget.GroupMessage.Command));
                            }
                        }
                    }

                    if (DebugLogIsEnabled)
                    {
                        string _previus = (m_PreviousTargetName != "" ? m_PreviousTargetName + " (" + m_PreviousTargetID + ")": "unknown");
                        string _active  = (m_ActiveTargetName != "" ? m_ActiveTargetName + " (" + m_ActiveTargetID + ")": "unknown");

                        PrintDebugLog(this, "SetActiveTarget - creature changed active target from " + _previus + " to " + _active + ".");
                    }

                    Move.UpdateTargets(m_ActiveTarget, Essentials.Target);

                    m_TargetChanged = true;
                }


                // update target behaviour
                if (m_ActiveTarget != null)
                {
                    string _key = ActiveTarget.Behaviour.CurrentBehaviourModeKey;

                    if (string.IsNullOrEmpty(_key))
                    {
                        // if the active target is not a HOME or if the creature outside the max range it have to travel to reach its target
                        if (!ActiveTarget.TargetInMaxRange(Owner.transform.position))
                        {
                            _key = Essentials.BehaviourModeRun;
                        }

                        // if the creature reached the TargetMovePosition it should do the rendezvous behaviour
                        else if (ActiveTarget.TargetMoveComplete)
                        {
                            _key = Essentials.BehaviourModeIdle;
                        }

                        // in all other case the creature should be standby and do some leisure activities
                        else                         //if( Target.TargetRandomRange > 0 )
                        {
                            _key = Essentials.BehaviourModeWalk;
                        }
                    }

                    SetActiveBehaviourModeByKey(_key);
                }
            }
        }