예제 #1
0
 IEnumerator DeployCoroutine(int unitIndex, GameObject player, int spendingPerUnit, int unitCount, int gridX, int gridY)
 {
     for (int i = 0; i < unitCount; i++)
     {
         Vector3 deployPosition = GRWInterface.GetGridToRW(gridX, gridY, odin.GetComponent <AStarMap>());
         CmdDeployUnit(unitIndex, player, deployPosition, spendingPerUnit);
         yield return(new WaitForSeconds(0.2f));
         //yield return null;
     }
 }
예제 #2
0
    public void GetMovingGrid(int _xGrid, int _yGrid)
    {
        Vector2 tempTarget = GRWInterface.GetGridToRW(_xGrid, _yGrid, unit.odin.GetComponent <AStarMap>());

        if (tempTarget.x == -1f)
        {
            //FIX ME PLS
            Debug.Log("grid full");
        }
        GetMovingRW(tempTarget);
    }
예제 #3
0
    public override int Execute()
    {
        if (unit.transform.position == firstChargePos)
        {
            firstChargePos = new Vector3(-1f, -1f, -1f);
            unit.charging  = false;
            return(0);
        }
        if (unit.charging && !unit.chargeFail)
        {
            return(1);
        }
        if (unit.charging && unit.chargeFail)
        {
            unit.chargeFail = false;
            firstChargePos  = new Vector3(-1f, -1f, -1f);
        }

        //currentPos = unit.gameObject.transform.position;
        unit.ClearEnemyList();
        unit.UpdateEnemyPositions();

        for (int i = 0; i < unit.enemies.Count; i++)
        {
            if (unit.enemies[i].canShootMe)
            {
                unitsThatCanShootMe.Add(unit.enemies[i]);
            }
        }

        Enemy   targetEnemy = unit.enemies[Random.Range(0, unitsThatCanShootMe.Count)];
        Vector2 target      = GRWInterface.GetRWToGrid((int)(targetEnemy.position.x), (int)(targetEnemy.position.y));

        if (firstChargePos != new Vector3(-1f, -1f, -1f))
        {
            return(1);
        }

        firstChargePos = target;
        unit.mover.GetMovingRW(target);
        unit.charging = true;
        return(1);
    }
예제 #4
0
    void CmdExecute(string ISOpCode, string ISUnits, int targetX, int targetY, GameObject player)
    {
        if (ISOpCode == "deploy")
        {
            GameObject newUnit;
            Vector3    deployPosition = GRWInterface.GetGridToRW(targetX, targetY, odin.GetComponent <AStarMap>());
            if (ISUnits == "marine")
            {
                if (player.GetComponent <CommandHub>().resource >= 20)
                {
                    newUnit = Instantiate(deployableUnits[0], deployPosition, Quaternion.identity);
                    player.GetComponent <CommandHub>().RpcSpendResource(20);
                }
                else
                {
                    errorText.GenerateErrorText();
                    return;
                }
            }
            else if (ISUnits == "sniper")
            {
                if (player.GetComponent <CommandHub>().resource >= 45)
                {
                    newUnit = Instantiate(deployableUnits[1], deployPosition, Quaternion.identity);
                    player.GetComponent <CommandHub>().RpcSpendResource(45);
                }
                else
                {
                    errorText.GenerateErrorText();
                    return;
                }
            }
            else if (ISUnits == "spotter")
            {
                if (player.GetComponent <CommandHub>().resource >= 15)
                {
                    newUnit = Instantiate(deployableUnits[2], deployPosition, Quaternion.identity);
                    player.GetComponent <CommandHub>().RpcSpendResource(15);
                }
                else
                {
                    errorText.GenerateErrorText();
                    return;
                }
            }
            //replace bomber -> explosives
            else if (ISUnits == "bomber")
            {
                if (player.GetComponent <CommandHub>().resource >= 30)
                {
                    newUnit = Instantiate(deployableUnits[3], deployPosition, Quaternion.identity);
                    player.GetComponent <CommandHub>().RpcSpendResource(30);
                }
                else
                {
                    errorText.GenerateErrorText();
                    return;
                }
            }
            else
            {
                errorText.GenerateErrorText();
                return;
            }

            newUnit.GetComponent <GCS>().client = client;
            //NetworkServer.SpawnWithClientAuthority(newUnit, conn);
            NetworkServer.Spawn(newUnit);
        }
        else if (ISOpCode == "move")
        {
            ClearDeployedUnitsList();
            List <int> unitIDs = ParseISUnits(ISUnits);
            for (int i = 0; i < unitIDs.Count; i++)
            {
                //Debug.Log(deployedUnits[unitIDs[i]].GetComponent<GCS>().moveSpeed);
                //deployedUnits[unitIDs[i]].GetComponent<GCS>().mover.GetMoving(targetX, targetY);
                GCS unitCommanded = deployedUnits[unitIDs[i]].GetComponent <GCS>();
                unitCommanded.currentCommand = ISOpCode;
                unitCommanded.gridTarget     = new Vector2(targetX, targetY);
                //unitCommanded.currentTarget = new Vector3(targetX, targetY);
                //unitCommanded.originalTarget = new Vector3(targetX, targetY);
            }
        }
        else if (ISOpCode == "hold_position")
        {
            ClearDeployedUnitsList();
            List <int> unitIDs = ParseISUnits(ISUnits);
            for (int i = 0; i < unitIDs.Count; i++)
            {
                //Debug.Log(deployedUnits[unitIDs[i]].GetComponent<GCS>().moveSpeed);
                //deployedUnits[unitIDs[i]].GetComponent<GCS>().mover.GetMoving(targetX, targetY);
                GCS unitCommanded = deployedUnits[unitIDs[i]].GetComponent <GCS>();
                unitCommanded.currentCommand = ISOpCode;
                unitCommanded.currentTarget  = new Vector3(targetX, targetY);
                unitCommanded.originalTarget = new Vector3(targetX, targetY);
            }
        }
        else
        {
            errorText.GenerateErrorText();
        }
    }
예제 #5
0
    public static Vector2 GetGridToRW(int gridCoordX, int gridCoordY, AStarMap mapHook)
    {
        Vector2 gridStartRW = new Vector2(gridCoordX * 5f, gridCoordY * 5f);

        return(GRWInterface.GetVacantPoint((int)(gridStartRW.x), (int)(gridStartRW.y), mapHook));
    }