private void OnClickHarvest(AiController aiController, SmartObject smartObject)
        {
            smartObject.activeAction = this;

            switch (((ResourceNode)((Node)smartObject).nodeData).resourceSettings.resourceType)
            {
            case ResourceNode.ResourceSettings.ResourceType.Bush:
                smartObject.animationTrigger = "GatherBush";

                break;

            case ResourceNode.ResourceSettings.ResourceType.Stone:
                smartObject.animationTrigger = "GatherStone";

                break;

            case ResourceNode.ResourceSettings.ResourceType.Wood:
                smartObject.animationTrigger = "GatherWood";

                break;

            case ResourceNode.ResourceSettings.ResourceType.Variety:

                break;
            }

            smartObject.actionLength = Mathf.Infinity;

            aiController.StartAction(smartObject, true);
        }
Ejemplo n.º 2
0
        private void PopulateActionButtonsData(AiController aiController, SmartObject smartObject)
        {
            var collectionOfActions = SelectionManager.HoveringObject.GetComponentInChildren <SmartObject>().smartActionDictionary;

            var collectionIndex = 0;

            foreach (var action in collectionOfActions)
            {
                var button = _actionButtons[collectionIndex].GetComponent <UI_SmartActionButton>();
                button.gameObject.SetActive(true);

                foreach (var sprites in GameManager.Instance.globalSpriteContainer.spriteCollection)
                {
                    if (sprites.Value == action.Key)
                    {
                        button.actionName.text = sprites.Key; //fix
                    }
                }

                button.actionButton.onClick.AddListener(delegate { action.Value(aiController, smartObject); });
                button.actionImage.sprite = action.Key;

                collectionIndex++;
            }
        }
Ejemplo n.º 3
0
        private void EquipItem(AiController controller, Item item)
        {
            _controller = controller;

            for (int i = 0; i < equipmentSlots.Length; i++)
            {
                if (controller == null)
                {
                    break;
                }

                var slot = equipmentSlots[i];

                //make sure equipment types match between slot and item
                if (slot.equipmentType.Equals(item.itemTypeData.itemData.equipmentType))
                {
                    if (slot.equippedItem != null) //if another item equipped, un equip old item first
                    {
                        controller.equipment.UnEquipItem(controller, slot.equippedItem);
                    }

                    slot.equippedItem = item;
                    item.equipped     = true;

                    //creates item model from the items type model reference,
                    //if the item has a modelReference, stays null if item is not
                    slot.modelReference = CreateWeaponModel(item);

                    /*
                     * UI_Controller.Instance.inventoryPanelController.UpdateEquipmentUi(item, slot, true);
                     * UI_Controller.Instance.inventoryPanelController.UpdateInventoryUi(controller, item, false);
                     */
                }
            }
        }
        public override bool perform(AiController controller)
        {
            if (_startTime == 0)
            {
                _targetItem = target.GetComponent <Item>();

                //Debug.Log("Starting to pick up item.");

                _startTime = Time.time;
                controller.animator.SetTrigger(pickUpItem);
            }

            if ((Time.time - _startTime > controller.animator.GetCurrentAnimatorStateInfo(1).length + extraWaitTime)) //wait til animation is over
            {
                //use event
                //Debug.Log("Picked up item.");

                //controller.inventory.AddItemToInventory(_targetItem);

                //controller.pickUpAvailable = false; //reset
                _completed = true;
            }

            return(true);
        }
Ejemplo n.º 5
0
        private void ActivateWeaponModel(AiController controller) //event being fired twice issue
        {
            if (_activeModelReference != null)
            {
                StartCoroutine(Coroutine_ToggleWeaponModel(_activeCombatEquipmentSlot.modelReference, false, _shortWait));
                _activeModelReference = null;
            }

            switch (controller.combatController.combatMode)
            {
            case Ai_CombatController.CombatMode.Melee:
                _activeCombatEquipmentSlot = controller.equipment.GetEquipmentSlot(EquipmentSlot.EquipmentType.MeleeWep);
                break;

            case Ai_CombatController.CombatMode.Ranged:
                _activeCombatEquipmentSlot = controller.equipment.GetEquipmentSlot(EquipmentSlot.EquipmentType.RangedWep);
                break;
            }

            if (_activeCombatEquipmentSlot.modelReference != null && controller.stateController.Drafted && _activeModelReference == null)
            {
                StartCoroutine(Coroutine_ToggleWeaponModel(_activeCombatEquipmentSlot.modelReference, true, _shortWait));
                _activeModelReference = _activeCombatEquipmentSlot.modelReference;
            }

            activeWeapon = GetActiveWeapon(controller);
        }
Ejemplo n.º 6
0
        public Weapon GetActiveWeapon(AiController controller)
        {
            if (!controller.stateController.Drafted)
            {
                Debug.Log("Not in drafted state.", this);
                return(null);
            }

            switch (controller.combatController.combatMode)
            {
            case Ai_CombatController.CombatMode.Melee:
                if (GetEquipmentSlot(EquipmentSlot.EquipmentType.MeleeWep).equippedItem != null)
                {
                    return(GetEquipmentSlot(EquipmentSlot.EquipmentType.MeleeWep).equippedItem
                           .itemTypeData as Weapon);
                }
                else
                {
                    return(null);
                }

            case Ai_CombatController.CombatMode.Ranged:
                return(GetEquipmentSlot(EquipmentSlot.EquipmentType.RangedWep).equippedItem.itemTypeData as Weapon);
            }

            return(null);
        }
Ejemplo n.º 7
0
 public void Update(AiController aiController)
 {
     if (stateStack.Peek() != null)
     {
         stateStack.Peek().Invoke(this, aiController);
     }
 }
        public Ai_CombatController(AiController controller)
        {
            _controller = controller;

            combatModeMelee = true;
            combatMode      = CombatMode.Melee;
        }
Ejemplo n.º 9
0
        public override bool perform(AiController controller)
        {
            /*if (_startTime == 0)
             * {
             *  //Debug.Log("Starting to un equip weapon.");
             *  _startTime = Time.time;
             *
             *  controller.iKControl.enableHandIk = false;
             *
             *  controller.animator.SetTrigger("PutAwayWeapon");
             *  controller.animator.SetBool("HasWeaponEquiped", false);
             *
             *  //controller.weaponEquiped = controller.aiInventory.GetBestWeaponFromInventory();
             * }
             *
             * if ((Time.time - _startTime > controller.animator.GetCurrentAnimatorStateInfo(2).length)) //wait til animation is over
             * {
             *  //Debug.Log("Finished un equipping weapon.");
             *
             *  controller.weaponHolder.ToggleActiveWeapon(controller.rangedWeaponEquiped, false);
             *  controller.rangedWeaponEquiped = null;
             *
             *  _completed = true;
             * }*/

            return(true);
        }
        public override bool perform(AiController controller)
        {
            if (_elapsedTime <= 0 && tempVector != transform.position)
            {
                controller.aiPath.destination = tempVector;
            }

            if (!(controller.aiPath.remainingDistance <= controller.aiPath.endReachedDistance))
            {
                return(true);
            }

            //Debug.Log("Started waiting.");
            _elapsedTime += Time.deltaTime;

            if (!(_elapsedTime >= _tempWaitTime))
            {
                return(true);
            }

            //Debug.Log("Finished waiting.");
            _completed = true;

            return(true);
        }
Ejemplo n.º 11
0
        private void ToggleSelectedObjectUi(Selectable selected)
        {
            OpenSelectedPanel();

            switch (selected)
            {
            case AiController aiController:
                SetActivePanel(selectedColonistPanel.name);

                PopulateBaseData(aiController);

                //get ai reference for the inventory updates
                _aiController = aiController;
                break;

            case Node harvestable:
                SetActivePanel(selectedResourcePanel.name);

                PopulateBaseData(harvestable);
                break;

            case Item item:
                SetActivePanel(selectedItemPanel.name);

                PopulateBaseData(item);
                break;

            case PlaceableObject placeableObject:
                SetActivePanel(selectedItemPanel.name);

                PopulateBaseData(placeableObject);
                break;
            }
        }
Ejemplo n.º 12
0
        public override bool checkProceduralPrecondition(AiController controller)
        {
            // if(!controller.target || controller.aiVitals.isDead) return false;
            //
            // target = controller.target;

            return(true);
        }
Ejemplo n.º 13
0
 public void ResetSmartObject()
 {
     usedBy           = null;
     beingUsed        = false;
     activeAction     = null;
     animationTrigger = string.Empty;
     actionLength     = 0;
 }
        public void UpdateColonistPanel(AiController aiController)
        {
            var button = Instantiate(colonistButton, transform).GetComponent <UI_ColonistButton>();

            _buttons.Add(button);
            button.nickName.text = "f*g";
            button.aiReference   = aiController;
        }
 public override bool checkProceduralPrecondition(AiController controller)
 {
     /*if(!controller.target || controller.vitals.isDead) return false;
      *
      * controller.navAgent.stoppingDistance = controller.aiArchetype.combatSettings.meleeDistance;
      *
      * target = controller.target;*/
     return(true);
 }
Ejemplo n.º 16
0
        private void OnClickInspect(AiController aiController, SmartObject smartObject)
        {
            smartObject.activeAction     = this;
            smartObject.animationTrigger = "Inspect"; //might need a ref for diff types of inspect animations later on
            Debug.Log(aiController.GetRuntimeAnimationClipInfo(smartObject.animationTrigger).length);

            smartObject.actionLength = aiController.GetRuntimeAnimationClipInfo(smartObject.animationTrigger).length; //get length of animation to be played

            aiController.StartAction(smartObject, false);                                                             //commence the action based on given data
        }
Ejemplo n.º 17
0
        private void ToggleRightClickPanel(AiController aiController, SmartObject smartObject)
        {
            ClearRightClickButtons();
            SetPanelPosToMouse(_panelOffset);

            rightClickPanel.Show();
            //rightClickPanel.gameObject.SetActive(true);

            PopulateActionButtonsData(aiController, smartObject);
        }
Ejemplo n.º 18
0
        private void OnCliCkPracticeShooting(AiController aiController, SmartObject smartObject)
        {
            smartObject.activeAction     = this;
            smartObject.animationTrigger = "Shoot";                                                                          //might need a ref for diff types of inspect animations later on

            smartObject.actionLength        = aiController.GetRuntimeAnimationClipInfo(smartObject.animationTrigger).length; //get length of animation to be played
            aiController._animationWaitTime = animationLengthModifier;

            aiController.StartAction(smartObject, true); //commence the action based on given data
        }
Ejemplo n.º 19
0
        public static void UpdateNavMesh(NavMeshSurface surface, Vector3 size, AiController aiController, float updateDistance)
        {
            if (!(Vector3.Distance(aiController.transform.position, surface.transform.position) >= updateDistance))
            {
                return;
            }

            surface.RemoveData();

            surface.size = size;

            surface.transform.position = aiController.transform.position;
            surface.BuildNavMesh();
        }
Ejemplo n.º 20
0
 public override bool perform(AiController controller)
 {
     if (startTime == 0f)
     {
         Debug.Log("Starting to range attack.");
         startTime = Time.time;
     }
     if (Time.time - startTime > attackRate /*&& controller.navAgent.remainingDistance <= controller.navAgent.stoppingDistance*/)
     {
         Debug.Log("Finished range attacking.");
         completed = true;
     }
     return(true);
 }
Ejemplo n.º 21
0
        private void AddItemToInventory(AiController controller, Item item)
        {
            if (holdingItems.ContainsKey(item.baseObjectInfo.Id) ||
                (currentWeight + item.itemTypeData.itemData.itemWeight) > weightLimit)
            {
                return;
            }

            holdingItems.Add(item.baseObjectInfo.Id, item);
            currentWeight += item.itemTypeData.itemData.itemWeight;

            SetItemTransform(item, inventoryHolder.transform, new Vector3(0, 0, 0), false);

            EventRelay.OnInventoryUpdated(controller);
        }
        private void UpdateButtonText(AiController controller)
        {
            switch (controller.combatController.combatMode)
            {
            case Ai_CombatController.CombatMode.Ranged:
                _combatButtonText = "R";
                break;

            case Ai_CombatController.CombatMode.Melee:
                _combatButtonText = "M";
                break;
            }

            combatModeText.text = _combatButtonText;
        }
        public override bool perform(AiController controller)
        {
            //Debug.Log("Started waiting.");
            _elapsedTime += Time.deltaTime;

            if (!(_elapsedTime >= _tempWaitTime))
            {
                return(true);
            }

            //Debug.Log("Finished waiting.");
            controller.navMeshAgent.ResetPath();
            _completed = true;

            return(true);
        }
Ejemplo n.º 24
0
        private void DropInventoryItem(AiController controller, Item item)
        {
            if (!holdingItems.ContainsKey(item.baseObjectInfo.Id))
            {
                return;
            }

            holdingItems.Remove(item.baseObjectInfo.Id);
            currentWeight -= item.itemTypeData.itemData.itemWeight;

            SetItemTransform(item, null, item.usedBy.transform.position + new Vector3(0, 1.4f, 0), true);
            item.GetComponent <Rigidbody>().AddForce(transform.forward + new Vector3(0, 1, 0) * 2, ForceMode.VelocityChange);

            //EventRelay.OnItemDropped(controller, item);
            EventRelay.OnInventoryUpdated(controller);
        }
        public override bool perform(AiController controller)
        {
            /*if (_startTime == 0)
             * {
             *  //Debug.Log("Starting to equip weapon.");
             *  _startTime = Time.time;
             *
             *  var bestWeapon = controller.inventory.GetBestWeaponFromInventory(); //get the best weapon based on a weapon tier check
             *
             *  if (bestWeapon.weaponSettings.ranged) //choose the correct animations based on the type of weapon we have equipped
             *  {
             *      controller.rangedWeaponEquiped = controller.inventory.GetBestWeaponFromInventory();
             *
             *      if (controller.rangedWeaponEquiped.weaponSettings.weaponTags == Weapon.WeaponSettings.WeaponTags.Pistol)
             *      {
             *          controller.weaponHolder.ToggleActiveWeapon(controller.rangedWeaponEquiped, true);
             *          controller.animator.SetTrigger(equipPistol);
             *          controller.animator.SetBool(hasWeaponEquiped, true);
             *      }
             *      else if (controller.rangedWeaponEquiped.weaponSettings.weaponTags == Weapon.WeaponSettings.WeaponTags.Rifle)
             *      {
             *          controller.weaponHolder.ToggleActiveWeapon(controller.rangedWeaponEquiped, true);
             *          controller.animator.SetTrigger(equipRifle);
             *          controller.animator.SetBool(hasWeaponEquiped, true);
             *      }
             *  }
             *  else
             *  {
             *      controller.meleeWeaponEquiped = controller.inventory.GetBestWeaponFromInventory();
             *
             *      controller.weaponHolder.ToggleActiveWeapon(controller.meleeWeaponEquiped, true);
             *      controller.animator.SetTrigger(equipMeleeWeapon);
             *      controller.animator.SetBool(hasWeaponEquiped, true);
             *  }
             * }*/

            /*if ((Time.time - _startTime > controller.animator.GetCurrentAnimatorStateInfo(2).length)) //wait til animation is over
             * {
             *  //Debug.Log("Finished equipping weapon.");
             *
             *  //controller.iKControl.enableHandIk = true; //corrects the hand ik
             *
             *  _completed = true;
             * }*/

            return(true);
        }
Ejemplo n.º 26
0
        public static GameObject CreateNavSurfaceForAgent(AiController aiController, Vector3 navMeshSize, float updateDistance)
        {
            var navMeshSurface = new GameObject("NavMeshSurface: " + aiController.name);
            var surface        = navMeshSurface.AddComponent <NavMeshSurface>();

            const int layerMask = ~(1 << 2); //everything but ignore layer

            navMeshSurface.transform.SetParent(GameManager.Instance.transform);

            surface.collectObjects = CollectObjects.Volume;
            surface.agentTypeID    = aiController.navMeshAgent.agentTypeID;
            surface.layerMask      = layerMask;

            UpdateNavMesh(surface, navMeshSize, aiController, updateDistance);

            return(navMeshSurface);
        }
Ejemplo n.º 27
0
        private void UnEquipItem(AiController controller, Item item)
        {
            foreach (var slot in equipmentSlots)
            {
                if (slot.equipmentType.Equals(item.itemTypeData.itemData.equipmentType))
                {
                    item.equipped = false;

                    /*
                     * UI_Controller.Instance.inventoryPanelController.UpdateEquipmentUi(item, slot, false);
                     * UI_Controller.Instance.inventoryPanelController.UpdateInventoryUi(controller, item, true);
                     */
                    slot.equippedItem = null;

                    ClearWeaponModel(slot);
                }
            }
        }
        //should put in draft mode if not already
        private void OnClickAttack(AiController aiController, SmartObject smartObject)
        {
            //cache, maybe
            var activeWeapon = aiController.equipment.activeWeapon;

            smartObject.activeAction = this;
            //might need a ref for diff types of inspect animations later on
            smartObject.animationTrigger = activeWeapon.animationAttackTrigger;
            smartObject.stoppingDistance = activeWeapon.attackRange;
            //set length of action, in this case infinity until target is dead or action canceled
            smartObject.actionLength = activeWeapon.attackSpeed;
            //allows a wait time between logic
            //aiController._animationWaitTime = _activeWeapon.attackSpeed;

            //commence the action based on given data
            aiController.StartAction(smartObject, true);
            //EventRelay.OnAttackInitiated(aiController);
        }
Ejemplo n.º 29
0
        protected void OnStartInitializeComponents(AiController aiController) //fix this trash
        {
            aiStats   = GetComponent <AiStats>();
            sensors   = GetComponent <AiSensors>();
            status    = GetComponent <AiStatus>();
            inventory = GetComponent <Ai_Inventory>();

            equipment = GetComponent <Ai_Equipment>();

            if (equipment != null)
            {
                equipment.weaponHolderRelay = GetComponentInChildren <WeaponHolderRelay>();
            }

            rigidBody = GetComponent <Rigidbody>();

            switch (aiType)
            {
            case AiType.Unity:
                navMeshAgent = GetComponent <NavMeshAgent>();

                break;

            case AiType.AStar:
                aiPath = GetComponent <AIPath>();

                break;
            }

            stateController  = new AiStateController(aiController);
            combatController = new Ai_CombatController(aiController);

            animator                = GetComponent <Animator>();
            animationController     = GetComponent <AnimationController>();
            selectable              = GetComponent <Selectable>();
            destinationLineRenderer = GetComponent <LineRenderer>();
            cam = SelectionManager.Instance.cam;

            animator.applyRootMotion = true;

            EventRelay.OnToggleDrafted     += stateController.UpdateCombatDrawTriggers;
            EventRelay.OnCombatModeToggled += stateController.UpdateCombatDrawTriggers;
        }
 public override bool perform(AiController controller) //activates animation which holds an event that gives all hits
 {
     /*if (startTime == 0f)
      * {
      *  Debug.Log("Starting to melee attack.");
      *
      *  controller.animator.SetTrigger(meleeAttack);
      *
      *  startTime = Time.time;
      * }
      * if (Time.time - startTime > attackRate)
      * {
      *  Debug.Log("Finished melee attacking.");
      *
      *  controller.navAgent.stoppingDistance = 0.2f; //reset stopping distance to default
      *
      *  completed = true;
      * }*/
     return(true);
 }