Example #1
0
 /**
  * Runs a location specific interaction between
  * this location and a human unit.
  *
  * Interactions may affect the state of both the unit
  * and the location.
  */
 public virtual void RunHumanInteraction(HumanUnit humanUnit)
 {
     foreach (string statName in this.unitStatBuffs.Keys)
     {
         humanUnit.ApplyStatBuff(statName, this.unitStatBuffs[statName]);
     }
 }
Example #2
0
 protected override void OnTriggerEnter2D(Collider2D other)
 {
     base.OnTriggerEnter2D(other);
     if (other.tag == ennemyTag && other.gameObject.GetComponent <HumanUnit>())
     {
         HumanUnit humanUnit = other.gameObject.GetComponent <HumanUnit>();
         attackEnnemy(humanUnit);
     }
 }
Example #3
0
    public override void RunHumanInteraction(HumanUnit humanUnit)
    {
        if (humanUnit.cash >= this.interactionCost)
        {
            base.RunHumanInteraction(humanUnit);

            humanUnit.cash -= this.interactionCost;
        }
    }
Example #4
0
    /**
     * Deselects the currently selected human unit.
     */
    public void DeselectHuman()
    {
        if (this.selectedHuman != null)
        {
            this.selectedHuman.DeselectUnit();
            this.selectedHuman = null;
        }

        this.guiManager.HideHumanUnitGUI();
    }
 /**
  * Increases the cash property of the human unit
  * and decreases the cash property of this location
  * by the current cashPerInteraction value.
  */
 public override void RunHumanInteraction(HumanUnit humanUnit)
 {
     if (this.activeLocation)
     {
         if (this.cash >= this.cashPerInteraction)
         {
             humanUnit.cash += this.cashPerInteraction;
             this.cash -= this.cashPerInteraction;
         }
         else
         {
             this.activeLocation = false;
         }
     }
 }
Example #6
0
 public void ShowHumanUnitGUI(HumanUnit human)
 {
     this.humanUnitGUI.human = human;
     this.humanUnitGUI.gameObject.SetActive(true);
 }
Example #7
0
 public override void RunHumanInteraction(HumanUnit humanUnit)
 {
     base.RunHumanInteraction(humanUnit);
 }
    // Update is called once per frame
    void Update()
    {
        // Press left mouse button down
        if (Input.GetMouseButtonDown(0))
        {
            selectionAreaTransform.gameObject.SetActive(true);
            startPositionMouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            // Unselect all units if command is not pressed down
            if (!(Input.GetKey(controls.leftCommand) || Input.GetKey(controls.rightCommand)))
            {
                foreach (HumanUnit unit in selectedUnits)
                {
                    unit.setSelectedVisible(false);
                }
                selectedUnits.Clear();
            }
        }

        // Hold down left mouse button
        if (Input.GetMouseButton(0))
        {
            // get current mouse position
            Vector3 currentMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            // Identify position of lowerLeft of select area
            Vector3 lowerLeft = new Vector3(
                Mathf.Min(startPositionMouse.x, currentMousePosition.x),
                Mathf.Min(startPositionMouse.y, currentMousePosition.y)
                );

            // Identify position of uperRight of select area
            Vector3 upperRight = new Vector3(
                Mathf.Max(startPositionMouse.x, currentMousePosition.x),
                Mathf.Max(startPositionMouse.y, currentMousePosition.y)
                );

            // Posititon and scale area selection area
            selectionAreaTransform.position   = lowerLeft;
            selectionAreaTransform.localScale = upperRight - lowerLeft;
        }

        // Lift left mouse button up
        if (Input.GetMouseButtonUp(0))
        {
            selectionAreaTransform.gameObject.SetActive(false);

            // Identify all units covered by draggin area
            Collider2D[] collider2DArray = Physics2D.OverlapAreaAll(startPositionMouse, Camera.main.ScreenToWorldPoint(Input.mousePosition));

            // Select all units within collider
            foreach (Collider2D collider2D in collider2DArray)
            {
                HumanUnit unit = collider2D.GetComponent <HumanUnit>();
                if (unit != null)
                {
                    unit.setSelectedVisible(true);
                    selectedUnits.Add(unit);
                }
            }

            // if command is pressed, make sure that after adding the new units, we delete all duplicates!
            if (Input.GetKey(controls.leftCommand) || Input.GetKey(controls.rightCommand))
            {
                selectedUnits = selectedUnits.Distinct().ToList();
            }
        }

        // Press right mouse button down
        if (Input.GetMouseButtonDown(1))
        {
            // get current mouse position
            Vector3 currentMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            Collider2D collider2D = Physics2D.OverlapArea(currentMousePosition, currentMousePosition);
            if (collider2D)
            {
                Entity entity = collider2D.GetComponent <Entity>();

                if (entity != null && entity.gameObject.tag == ennemyTag)
                {
                    //attack
                    attackEntity(entity);
                }
            }
            else
            {
                //moveToPosition
                // list of positions for my group of units
                List <Vector3> targetPositionList = GetMultipleCirclesPositionListAround(currentMousePosition, new float[] { 1f, 2f, 3f, 4f, 5f }, new int[] { 5, 10, 15, 20, 25 });
                // make units move to their respective position
                int targetPositionListIndex = 0;
                foreach (HumanUnit selectedUnit in selectedUnits)
                {
                    selectedUnit.moveToPosition(targetPositionList[targetPositionListIndex]);
                    targetPositionListIndex++;
                }
            }
        }
    }
Example #9
0
    /**
     * Selected a given human unit.
     */
    public void SelectHuman(HumanUnit human)
    {
        this.selectedHuman = human;

        this.guiManager.ShowHumanUnitGUI(human);
    }