Ejemplo n.º 1
0
 private void generateMap()
 {
     for (int x = 0; x < width; x++)
     {
         for (int z = 0; z < length; z++)
         {
             if ((z == 0) || (z == length - 1))
             {
                 generatedLandscape       = landscapeList[generateRandomLandscapeNum(true)];
                 generatedLandscape       = Instantiate(generatedLandscape, new Vector3(x, readonlyY, z), Quaternion.identity);
                 generatedLandscapeScript = generatedLandscape.GetComponent <LandscapeValues>();
                 if (generatedLandscapeScript != null)
                 {
                     generatedMapJSON.map[x, z] = generatedLandscapeScript.FieldType.ToString();
                 }
             }
             else
             {
                 generatedLandscape       = landscapeList[generateRandomLandscapeNum(false)];
                 generatedLandscape       = Instantiate(generatedLandscape, new Vector3(x, readonlyY, z), Quaternion.identity);
                 generatedLandscapeScript = generatedLandscape.GetComponent <LandscapeValues>();
                 if (generatedLandscapeScript != null)
                 {
                     generatedMapJSON.map[x, z] = generatedLandscapeScript.FieldType.ToString();
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
    private void MoveUnitAfterWait(float x, float z)
    {
        if (Physics.Raycast(new Vector3(x, -1f, z), Vector3.up, out landscapeHit, 120))
        {
            LandscapeCheck = landscapeHit.transform.GetComponent <LandscapeValues>();

            if (!LandscapeCheck.Taken)
            {
                EventHandler.OnClearUnitOnField(transform.position.x, transform.position.z, gameObject);
                transform.position = new Vector3(x, transform.position.y, z);
                UnitScript.preparingDefense.SetActive(false);
                UnitScript.defenseReady.SetActive(false);
                UnitScript.isOnDefense = false;

                if (UnitScript.DuringFiring)
                {
                    UnitScript.CurrentOperation = UnitOperation.Firing;
                }
                else
                {
                    UnitScript.CurrentOperation = UnitOperation.Waiting;
                }
                EventHandler.OnWasUnitMoved(true);
            }
        }
    }
Ejemplo n.º 3
0
 void WasUnitMoved(bool wasMoved)
 {
     if (wasMoved)
     {
         landscapeValuesScript = hit.transform.GetComponent <LandscapeValues>();
     }
 }
Ejemplo n.º 4
0
    void Update()
    {
        if (!initalFieldSet)
        {
            EventHandler.OnSetUnitOnField(transform.position.x, transform.position.z, gameObject);
            initalFieldSet = true;
        }

        if (selectIndicator.activeInHierarchy)
        {
            if (Input.GetMouseButtonDown(2))
            {
                //Way for getting info about what landscape was hit
                //Debug.DrawRay(new Vector3(0, -1f, 0), Vector3.up, Color.cyan);

                /* if(Physics.Raycast(new Vector3(0, -1f, 0), Vector3.up, out landscapeHit, 120)) {
                 *   Debug.Log(landscapeHit.transform.tag); //This will be used instead of out landscapeHit down there
                 * } */
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out landscapeHit, 100) && !keepFiring)
                {
                    standingGround = landscapeHit.transform.gameObject.GetComponent <LandscapeValues>();
                }

                if (!keepFiring)
                {
                    keepFiring = true;
                }
                else if (keepFiring)
                {
                    keepFiring = false;
                }
            }

            //invoking defence
            if (Input.GetKeyDown(KeyCode.H))
            {
                StartCoroutine(DefenseDelay(5f));
            }
        }

        if (keepFiring)
        {
            DuringFiring = true;
            //Debug.Log(landscapeHit.transform.position);
            //EventHandler.OnProcedureAttack(gameObject.transform.position, landscapeHit.transform.position, UnitType, standingGround, Amount, HitChance);
            if (!coroutineStarted)
            {
                StartCoroutine(ProcessFiring(3f, landscapeHit.transform.position, UnitType, standingGround, Amount, HitChance));
            }
        }
        else if (!keepFiring)
        {
            DuringFiring = false;
        }

        if (DuringFiring && isOnDefense)
        {
            CurrentOperation = UnitOperation.FiringDefence;
        }
    }
Ejemplo n.º 5
0
    private IEnumerator ProcessFiring(float waitTime, Vector3 attackCoordinates, UnitType unitType,
                                      LandscapeValues currentLandscape, int amount, float hitChance)
    {
        coroutineStarted = true;
        yield return(new WaitForSeconds(waitTime));

        if (!defenseDuringPreparing)
        {
            EventHandler.OnProcedureAttack(gameObject.transform.position, attackCoordinates, UnitType, currentLandscape, amount, hitChance);
        }
        coroutineStarted = false;
    }
    void ProcessHit(Vector3 attackUnitPosition, Vector3 attackCoordinates, UnitType unitType, LandscapeValues currentLandscape, int amount, float hitChance)
    {
        if (attackCoordinates.x == gameObject.transform.position.x && attackCoordinates.z == gameObject.transform.position.z)
        {
            calculatedDistance  = CalculateDistance(attackUnitPosition, attackCoordinates);
            hitChanceByDistance = Mathf.Pow(0.80f, calculatedDistance);
            if (unitScript.UnitType == UnitType.Riffle)
            {
                //Program.environment.HitChanceByOperation.TryGetValue(CurrentOperation, out float operationHitChance);
                hitChance *= 0.75f * hitChanceByDistance; //0.75 is a temproray environment.HitChanceByOperation

                switch (unitType)
                {
                case UnitType.Riffle:
                    hitChance *= currentLandscape.MultiplierOfHitChanceByRiffle;
                    Debug.Log("hitChance: " + hitChance + " :: " + "hitChanceByDistance: " + hitChanceByDistance);
                    for (int i = 1; i <= amount; i++)
                    {
                        double hit = random.NextDouble();
                        if (hitChance > (float)hit)
                        {
                            loss++;
                        }
                    }
                    break;

                case UnitType.Cannon:
                    hitChance *= currentLandscape.MultiplierOfHitChanceByCannon * Mathf.Log(amount);
                    for (int i = 1; i <= unitScript.Amount; i++)
                    {
                        double hit = random.NextDouble();
                        if (hitChance > (float)hit)
                        {
                            loss++;
                        }
                    }
                    break;
                }
            }

            Debug.Log("UNIT: " + gameObject.transform.name + " WAS HIT BY: " + unitType + " CURRENT LANDSCAPE " + currentLandscape.tag + " DISTANCE: " + calculatedDistance + " LOST: " + loss);
            if (unitScript.Amount - loss > 0)
            {
                unitScript.Amount -= loss;
            }
            else
            {
                unitScript.Amount = 0;
            }
            amountText.text = unitScript.Amount.ToString();
            loss            = 0;
        }
    }
Ejemplo n.º 7
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
            {
                EventHandler.OnSelectUnit(hit.transform.position.x, hit.transform.position.z);
                landscapeValuesScript = hit.transform.GetComponent <LandscapeValues>();
                if (landscapeValuesScript.Taken)
                {
                    Debug.Log("TAKEN");
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            //testing selected unit information
            if (selectedUnit != null)
            {
                Debug.Log(selectedUnit.tag);
            }
            else
            {
                Debug.Log("Empty");
            }

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
            {
                //delay added
                if (hit.transform.tag == "Water")
                {
                    EventHandler.OnMoveUnit(hit.transform.position.x, hit.transform.position.z, landscapeValuesScript.CannonMovingTime, landscapeValuesScript.InfantryMovingTime, false);
                }
                else
                {
                    EventHandler.OnMoveUnit(hit.transform.position.x, hit.transform.position.z, landscapeValuesScript.CannonMovingTime, landscapeValuesScript.InfantryMovingTime, true);
                }

                Debug.DrawRay(hit.transform.position, Vector3.up, Color.cyan);

                if (Physics.Raycast(hit.transform.position, Vector3.up, out unitHit, 100))
                {
                    Debug.Log("HIT: " + unitHit.transform.tag);
                }
            }
        }

        //Need to add % chances depending on the field and distance

        /* if(Input.GetMouseButtonDown(2))
         * {
         *
         *   if (selectedUnit != null)
         *   {
         *       if (selectedUnit.transform.tag == "Infantry")
         *       {
         *           currentUnit = UnitType.Riffle;
         *       }
         *       else
         *       {
         *           currentUnit = UnitType.Cannon;
         *       }
         *
         *       //Way for getting info about what landscape was hit
         *       //Debug.DrawRay(new Vector3(0, -1f, 0), Vector3.up, Color.cyan);
         *
         *       if(Physics.Raycast(new Vector3(0, -1f, 0), Vector3.up, out landscapeHit, 120)) {
         *           Debug.Log(landscapeHit.transform.tag);
         *       }
         *
         *       if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out landscapeHit, 100))
         *       {
         *           Debug.Log(landscapeHit.transform.position);
         *           EventHandler.OnProcedureAttack(selectedUnit.transform.position, landscapeHit.transform.position, currentUnit, landscapeHit.transform.gameObject);
         *       }
         *
         *
         *
         *   }
         *
         * } */
    }
Ejemplo n.º 8
0
 public static void OnProcedureAttack(Vector3 selectedUnit, Vector3 attackCoordinates, UnitType unitType, LandscapeValues currentLandscape, int amount, float hitChance)
 {
     InvokeProcedureAttack(selectedUnit, attackCoordinates, unitType, currentLandscape, amount, hitChance);
 }