Ejemplo n.º 1
0
        public GameObject UpdateItemObject()
        {
            if (!ItemNameIsValid || IsNotional || Amount == 0 || ItemUpdateRequired || (MountPointTransform != null && m_ItemObject != null && m_ItemObject.transform.IsChildOf(MountPointTransform) == false))
            {
                if (m_ItemObject != null)
                {
                    CreatureRegister.Remove(m_ItemObject);
                }

                m_ItemObject = null;
            }

            if (ItemNameIsValid && !IsNotional && Amount > 0 && m_ItemObject == null)
            {
                m_ItemObject = FindItemObject();
                if (m_ItemObject == null)
                {
                    m_ItemObject = SpawnItemObject(MountPointTransform.position, MountPointTransform.rotation);
                    AttachToSlot(m_ItemObject);
                }
                else
                {
                    m_ItemObject.transform.position = MountPointTransform.position;
                    m_ItemObject.transform.rotation = MountPointTransform.rotation;
                    m_ItemObject.SetActive(true);
                }
            }

            return(m_ItemObject);
        }
        public CreatureReferenceObject(GameObject _creature)
        {
            Creature = _creature;
            Enabled  = true;

            m_Group = CreatureRegister.AddCreatureGroup(Creature.name);
        }
        public void Sense()
        {
            InteractorObject _best_interactor = null;
            GameObject       _best_creature   = null;
            int _best_priority = 0;

            float _best_distance = Mathf.Infinity;

            for (int i = 0; i < Interactors.Count; ++i)
            {
                InteractorObject _interactor = Interactors[i];

                if (!_interactor.Enabled)
                {
                    continue;
                }

                GameObject _creature = CreatureRegister.FindNearestCreature(_interactor.Name, m_Owner.transform.position, _interactor.GetStartDistance());

                if (_creature != null)
                {
                    float _creature_distance = Tools.GetHorizontalDistance(m_Owner.transform.position, _creature.transform.position);

                    if (_creature_distance <= _best_distance)
                    {
                        int _priority = GetPriority(_creature, _interactor.Selectors.Priority);

                        if (_priority >= _best_priority)
                        {
                            _best_priority   = _priority;
                            _best_creature   = _creature;
                            _best_distance   = _creature_distance;
                            _best_interactor = _interactor;
                        }
                    }
                }
            }


            if (_best_creature != null && _best_interactor != null)
            {
                if (m_Interactor == null || m_Interactor.Target.TargetGameObject != _best_creature)
                {
                    m_Interactor = _best_interactor;

                    m_Interactor.Target = new TargetObject(TargetType.INTERACTOR);
                    m_Interactor.Target.TargetGameObject = _best_creature;


                    PrepareTarget();
                }
            }
            else
            {
                m_Interactor = null;
            }
        }
Ejemplo n.º 4
0
 public void SetSpawnPointGameObjectByTag(string _tag)
 {
     if (!string.IsNullOrEmpty(_tag))
     {
         SpawnPointGameObject = CreatureRegister.GetReferenceGameObjectByTag(_tag);
     }
     else
     {
         SpawnPointGameObject = null;
     }
 }
Ejemplo n.º 5
0
 public void SetSpawnPointGameObjectByName(string _name)
 {
     if (!string.IsNullOrEmpty(_name))
     {
         SpawnPointGameObject = CreatureRegister.GetReferenceGameObjectByName(_name);
     }
     else
     {
         SpawnPointGameObject = null;
     }
 }
Ejemplo n.º 6
0
                public void Respawn()
                {
                    if (!m_RespawnRequired || !IsDead)
                    {
                        return;
                    }

                    m_RespawnTimer    = 0.0f;
                    m_RespawnRequired = false;

                    CreatureRegister.DeathNotice(m_Owner);
                }
Ejemplo n.º 7
0
        /// <summary>
        /// Spawns a new item object, changes its name and sets it active.
        /// </summary>
        /// <returns>The item object.</returns>
        /// <param name="_position">Position.</param>
        /// <param name="_rotation">Rotation.</param>
        public GameObject SpawnItemObject(Vector3 _position, Quaternion _rotation)
        {
            GameObject _item = CreatureRegister.Spawn(ItemReferenceObject, _position, _rotation);

            if (_item != null)
            {
                _item.name = ItemReferenceObject.name;
                _item.SetActive(true);
            }

            return(_item);
        }
Ejemplo n.º 8
0
        public void DestroyItem(GameObject _object)
        {
            if (_object == null && EntityGameObject != _object)
            {
                return;
            }

            SuspendedObjects.Remove(_object);
            ActiveObjects.Remove(_object);

            if (!CompareByID(_object.GetInstanceID()))
            {
                CreatureRegister.Destroy(_object);
            }
        }
Ejemplo n.º 9
0
        public void Init(GameObject gameObject)
        {
            m_Owner = gameObject;

            Move.Init(m_Owner);
            Essentials.Init(m_Owner);
            Status.Init(m_Owner);
            Behaviour.Init(m_Owner);

            Missions.Init(m_Owner);
            Interaction.Init(m_Owner);
            Environment.Init(m_Owner);

            CreatureRegister.Register(m_Owner);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the best spawn point game object.
        /// </summary>
        /// <returns>The best spawn point game object.</returns>
        public GameObject GetBestSpawnPointGameObject()
        {
            GameObject _object = SpawnPointGameObject;

            if (AccessType == TargetAccessType.NAME)
            {
                _object = CreatureRegister.GetRandomTargetByName(SpawnPointName);
            }
            else if (AccessType == TargetAccessType.TAG)
            {
                _object = CreatureRegister.GetRandomTargetByTag(SpawnPointTag);
            }

            return(_object);
        }
Ejemplo n.º 11
0
        public void Start()
        {
            if (ReferenceShell == null || SpawnPoint == null)
            {
                return;
            }

            GameObject _shell = CreatureRegister.Spawn(ReferenceShell, SpawnPoint.transform.position, SpawnPoint.transform.rotation);

            Rigidbody _shell_rigidbody = _shell.GetComponent <Rigidbody>();

            if (_shell_rigidbody != null)
            {
                _shell_rigidbody.AddForce(SpawnPoint.transform.forward * EjectionSpeed);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gives an item from slot (optional attached to the specified transform).
        /// </summary>
        /// <returns>The detached item.</returns>
        /// <param name="_transform">Transform.</param>
        /// <param name="_attach">If set to <c>true</c> attach the item to the specified transform.</param>
        public GameObject GiveItem(Transform _transform, bool _attach)
        {
            if (_transform == null)
            {
                return(null);
            }

            GameObject _item = GiveItem(_transform.position, _transform.rotation);

            if (_attach)
            {
                CreatureRegister.AttachToTransform(_item, _transform);
            }

            return(_item);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Attachs to slot.
        /// </summary>
        /// <returns><c>true</c>, if to slot was attached, <c>false</c> otherwise.</returns>
        /// <param name="_object">Object.</param>
        public bool AttachToSlot(GameObject _object)
        {
            if (_object == null)
            {
                return(false);
            }

            if (!_object.transform.IsChildOf(MountPointTransform))
            {
                return(CreatureRegister.AttachToTransform(_object, MountPointTransform));
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Drops an detached item.
        /// </summary>
        public void DropItem()
        {
            GameObject _item = GiveItem();

            if (_item == null)
            {
                Quaternion _rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0);
                Vector3    _position = PositionTools.FixTransformPoint(Owner.transform, new Vector3(0, 5, 3));
                if (DropRange > 0)
                {
                    _position = ICE.World.Utilities.PositionTools.GetRandomPosition(_position, DropRange);
                }

                _item = CreatureRegister.Spawn(ItemReferenceObject, _position, _rotation);

                Amount--;
            }
        }
Ejemplo n.º 15
0
        public void DetachOnDie()
        {
            foreach (InventorySlotObject _slot in Slots)
            {
                if (_slot != null && (_slot.UseDetachOnDie == true || UseDetachOnDie == true) && _slot.Amount > 0)
                {
                    GameObject _reference = _slot.ItemReferenceObject;
                    if (_reference != null)
                    {
                        Vector3    _position = Owner.transform.TransformPoint(Vector3.zero);
                        Quaternion _rotation = Owner.transform.rotation;

                        while (_slot.Amount > 0)
                        {
                            if (_slot.DropRange > 0)
                            {
                                _position = ICE.World.Utilities.PositionTools.GetRandomPosition(_position, _slot.DropRange);
                            }

                            GameObject _item = CreatureRegister.Spawn(_reference, _position, _rotation);
                            //GameObject _item = (GameObject)GameObject.Instantiate( _reference, _position, _rotation );
                            if (_item != null)
                            {
                                _item.name = _reference.name;

                                if (_item.GetComponent <Rigidbody>() != null)
                                {
                                    _item.GetComponent <Rigidbody>().useGravity  = true;
                                    _item.GetComponent <Rigidbody>().isKinematic = false;
                                    _item.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
                                }
                            }

                            _slot.Amount--;
                        }

                        if (_slot.ItemObject)
                        {
                            WorldManager.Remove(_slot.ItemObject);
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public bool Insert(GameObject _object)
        {
            if (_object == null || !_object.activeInHierarchy)
            {
                return(false);
            }

            InventorySlotObject _slot = ForceSlotByItem(_object, 1);

            if (_slot != null)
            {
                if (_slot.SetItemObject(_object))
                {
                    if (DebugLogIsEnabled)
                    {
                        PrintDebugLog(this, "Insert - '" + _object.name + "' inserted and attached to slot (new amount : " + _slot.Amount + "/" + _slot.MaxAmount + ")");
                    }
                }
                else if (_slot.FreeCapacity >= 1)
                {
                    if (_slot.IsEmpty)
                    {
                        _slot.ItemName = _object.name;
                    }

                    _slot.Amount++;
                    CreatureRegister.Remove(_object);

                    if (DebugLogIsEnabled)
                    {
                        PrintDebugLog(this, "Insert - '" + _object.name + "' amount increased of slot (new amount : " + _slot.Amount + "/" + _slot.MaxAmount + ") and original object removed");
                    }
                }
                else
                {
                    //if( DebugLogIsEnabled ) PrintDebugLog( this, "Insert - '" + _object.name + "' amount increased of slot (new amount : " + _slot.Amount + "/" + _slot.MaxAmount + ") and original object removed" );
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
        public void Spawn()
        {
            CreatureGroupObject _group = CreatureRegister.ForceCreatureGroup(Name);

            if (_group == null)
            {
                return;
            }

            m_CreaturesCount = _group.Creatures.Count;

            if (m_CreaturesCount < MaxCreatures)
            {
                Vector3    _position = GetSpawnPosition();
                Quaternion _rotation = Random.rotation;

                _rotation.z = 0;
                _rotation.x = 0;

                GameObject _creature = (GameObject)Object.Instantiate(Creature, _position, _rotation);

                if (UseRandomScale)
                {
                    RandomScaleMin = -1;
                    RandomScaleMax = 1;
                    float _scale_multiplier = (float)Random.Range(RandomScaleMin, RandomScaleMax) / 100 * UseRandomScaleMultiplier * 0.5f;

                    _creature.transform.localScale = _creature.transform.localScale + (_creature.transform.localScale * _scale_multiplier);
                }

                _creature.name = Creature.name;

                if (UseGroupObject)
                {
                    if (m_GroupObject == null)
                    {
                        m_GroupObject = new GameObject();

                        m_GroupObject.name = Name + "(Group)";
                        m_GroupObject.transform.position = Vector3.zero;

                        if (Register != null)
                        {
                            Register.transform.position    = Vector3.zero;
                            m_GroupObject.transform.parent = Register.transform;
                        }
                    }

                    _creature.transform.parent = m_GroupObject.transform;

                    if (_creature.GetComponent <ICECreatureControl>() != null)
                    {
                        _creature.GetComponent <ICECreatureControl>().Creature.Status.Reset();
                    }

                    _creature.SetActive(true);

                    CreatureRegister.Register(_creature);
                }
            }
        }
Ejemplo n.º 18
0
        public void Action(InventoryActionDataObject _action)
        {
            if (_action == null || !_action.Enabled)
            {
                return;
            }

            if (_action.DropItemRequired())
            {
                InventorySlotObject _slot = GetSlotByItemName(_action.ItemName);
                if (_slot != null && _slot.Amount > 0)
                {
                    Transform _transform = ICE.World.Utilities.SystemTools.FindChildByName(_action.ParentName, Owner.transform);
                    _transform = (_transform != null ? _transform : Owner.transform);

                    Quaternion _rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0);
                    Vector3    _position = PositionTools.FixTransformPoint(_transform, _action.Offset);

                    GameObject _item = _slot.GiveItem(_position, _rotation);
                    if (_item == null)
                    {
                        _item = CreatureRegister.Spawn(_slot.ItemReferenceObject, _position, _rotation);
                        _slot.Amount--;
                    }
                }
            }
            else if (_action.ParentUpdateRequired())
            {
                InventorySlotObject _slot = GetSlotByItemName(_action.ItemName);
                if (_slot != null && _slot.Amount > 0)
                {
                    if (_slot.ItemObject != null)
                    {
                        _slot.MountPointName = _action.ParentName;
                    }
                }
            }
            else if (_action.CollectActiveItemRequired())
            {
                ICECreatureControl _control = OwnerComponent as ICECreatureControl;
                TargetObject       _target  = _control.Creature.ActiveTarget;

                if (_control != null && _target != null && _target.Selectors.TotalCheckIsValid)                  //&& LastCollectedObjectID != _target.TargetID  )
                {
                    GameObject _item = _target.TargetGameObject;

                    //LastCollectedObjectID = _target.TargetID;

                    if (_target.EntityComponent != null && _target.EntityComponent.IsChildEntity)
                    {
                        ICEWorldEntity _parent = _target.EntityComponent.RootEntity;
                        if (_parent != null)
                        {
                            if (DebugLogIsEnabled)
                            {
                                PrintDebugLog(this, "CollectActiveItem : take '" + _target.Name + "' from " + _parent.name + " (" + _parent.ObjectInstanceID + ")");
                            }

                            InventorySlotObject _slot = GetInventorySlot(_parent.gameObject, _target.TargetName);
                            if (_slot != null)
                            {
                                _item = _slot.GiveItem();
                            }
                        }
                    }

                    if (Insert(_item))
                    {
                        //Debug.Log( _control.Creature.ActiveTarget.TargetGameObject.name + " - " +  _control.Creature.ActiveTarget.TargetGameObject.GetInstanceID() );
                        //_target.ResetTargetGameObject();
                        _control.Creature.ResetActiveTarget();

                        //
                    }
                }
            }
        }
Ejemplo n.º 19
0
 private void SetItemReferenceObject(GameObject _item)
 {
     CreatureRegister.AddReference(_item);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Detachs from slot.
 /// </summary>
 /// <returns><c>true</c>, if from slot was detached, <c>false</c> otherwise.</returns>
 /// <param name="_object">Object.</param>
 public bool DetachFromSlot(GameObject _object)
 {
     return(CreatureRegister.DetachFromTransform(_object));
 }
Ejemplo n.º 21
0
 public void Bye()
 {
     CreatureRegister.Deregister(m_Owner);
 }