Beispiel #1
0
        /// <summary>
        /// Give ressources to an agent
        /// </summary>
        /// <param name="agent">the agent to give</param>
        /// <param name="count">number of ressources to transfert</param>
        /// <returns>Return true if success and false otherwise</returns>
        public bool Give(GameObject agent, int count)
        {
            if (Vector3.Distance(this.transform.position, agent.transform.position) > GiveDistance)
            {
                return(false);
            }

            InventoryController agent_inv = agent.GetComponent <InventoryController>();

            if (agent_inv.Full)
            {
                return(false);
            }
            if (this.current_inventory < count)
            {
                agent_inv.Add(this.current_inventory);
                this.current_inventory = 0;
            }
            else
            {
                this.Remove(count);
                agent_inv.Add(count);
            }
            return(true);
        }
 /// <summary>
 /// Raises the trigger enter event.
 /// Used to pick up resources.
 /// </summary>
 /// <param name="collision">Collision.</param>
 void OnTriggerEnter(Collider collision)
 {
     if (collision.gameObject.CompareTag("WarItem"))
     {
         InventoryController inventory = this.GetComponent <InventoryController>();
         if (!inventory.Full)
         {
             //inventory.Add(collision.gameObject.GetComponent<WarResource>().value);
             inventory.Add(InventoryController.TakeCount);
             this.DetectedItems.Remove(collision.gameObject);
             collision.gameObject.GetComponent <WarResource>().PickedUp();
         }
     }
 }
Beispiel #3
0
        /***************************************** DELEGATES AND EVENTS ***************************************************
        * This section holds all delegates and events, that we will use to notify subscribers of state changes.          *
        * For example, whenever the perception range is changed, notify the perception sphere to make it change its size.*
        ******************************************************************************************************************/


        /******************************************* UNITY FUNCTIONS ********************************************
        * This section holds all functions strictly related to Unity, such as updates, collision detection etc.*
        * In principle, every function in this section will run once per frame, except Start().                *
        ********************************************************************************************************/
        protected override void Start()
        {
            base.Start();

            HealthController health = this.GetComponent <HealthController>();

            health.max_health = MaxHealth;
            health.Init();
            InventoryController inventory = this.GetComponent <InventoryController>();

            inventory.max_inventory = MaxInventory;
            inventory.Init();
            inventory.Add(MaxInventory);
            DetectionController detection = this.GetComponent <DetectionController>();

            detection.perception_radius = PerceptionRadius;
            detection.Init();
        }