Beispiel #1
0
        public IActionResult UnitUpdate(UnitUpdate model)
        {
            var updateResult   = false;
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://localhost:44354/api/unit/update");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "PUT";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                var json = JsonConvert.SerializeObject(model);

                streamWriter.Write(json);
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                updateResult = bool.Parse(result);
            }
            if (updateResult)
            {
                TempData["Success"] = "Unit has been update successfully";
            }
            return(RedirectToAction("UnitIndex", "Unit"));
        }
Beispiel #2
0
        public IActionResult UnitUpdate(int id)
        {
            TempData["Success"] = null;
            var            updateunit     = new UnitUpdate();
            var            url            = "https://localhost:44354/api/unit/get/" + id;
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            httpWebRequest.Method = "GET";
            var response = httpWebRequest.GetResponse();

            {
                string responseData;
                Stream responseStream = response.GetResponseStream();
                try
                {
                    StreamReader streamReader = new StreamReader(responseStream);
                    try
                    {
                        responseData = streamReader.ReadToEnd();
                    }
                    finally
                    {
                        ((IDisposable)streamReader).Dispose();
                    }
                }
                finally
                {
                    ((IDisposable)responseStream)?.Dispose();
                }

                updateunit = JsonConvert.DeserializeObject <UnitUpdate>(responseData);
            }
            return(View(updateunit));
        }
Beispiel #3
0
    private void SendIncreaseMoneyCommand()
    {
        UnitUpdate update = new UnitUpdate();

        update.command = UnitUpdateCommand.INCOME;
        update.moving  = this.unitIndex;
        NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
    }
Beispiel #4
0
    public virtual void SendMoveInformation(Cell newCell)
    {
        UnitUpdate update = new UnitUpdate();

        update.command      = UnitUpdateCommand.MOVE;
        update.moving       = this.unitIndex;
        update.newLocationX = newCell.transform.position.x;
        update.newLocationY = newCell.transform.position.y;
        NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
    }
Beispiel #5
0
 public void EndTurn()
 {
     if (DarkRift.DarkRiftAPI.isConnected &&
         DarkRift.DarkRiftAPI.id - 1 == GameObject.Find("CellGrid").GetComponent <CellGrid>().CurrentPlayerNumber ||
         Unit.debugoverride)
     {
         UnitUpdate update = new UnitUpdate();
         update.command = UnitUpdateCommand.END_TURN;
         NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
         cellGrid.EndTurn();//User ends hit turn by pressing the N key
     }
 }
Beispiel #6
0
 public static void SendData(byte tag, ushort subject, object data)
 {
     if (DarkRiftAPI.isConnected)
     {
         if (data is UnitUpdate)
         {
             (data as UnitUpdate).index = ++messageIndex;
             prevUpdate = currUpdate;
             currUpdate = (data as UnitUpdate);
         }
         DarkRiftAPI.SendMessageToOthers(tag, subject, data);
     }
 }
Beispiel #7
0
 public bool UnitUpdate(UnitUpdate request)
 {
     try
     {
         DynamicParameters parameters = new DynamicParameters();
         parameters.Add("@ID", request.Id);
         parameters.Add("@Name", request.Name);
         SqlMapper.Execute(con, "Unit_Update", param: parameters, commandType: CommandType.StoredProcedure);
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #8
0
    public void SpawnUnitWithButton(int unitType, int factionIndexMod)
    {
        UnitType  type = (UnitType)(unitType);
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).selected)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        Debug.Log(unitType.ToString() + " + " + factionIndexMod.ToString());
        GameObject newUnit = CreateNewUnit(factionIndexMod, site, type);

        //GameObject newUnit = Instantiate(aStarUnits[unitType - factionIndexMod], site.transform.position, Quaternion.identity);
        type           = (UnitType)(unitType + factionIndexMod);
        site.spawnUnit = true;

        if (!site.Cell.IsTaken && site.spawnUnit && site.selected && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = site.transform.position.x;
            update.newLocationY = site.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.moving       = site.unitIndex;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
Beispiel #9
0
    public override void OnUnitClicked(Unit unit)
    {
        if (_unit != null)
        {
            if (unit.Equals(_unit) || unit.isMoving)
            {
                return;
            }

            if (_unitsInRange.Contains(unit) && _unit.ActionPoints > 0 && _unit.PlayerNumber != unit.PlayerNumber && _unit.typeOfTargets == Target.ENEMY)
            {
                _unit.DealDamage(unit);
                UnitUpdate update = new UnitUpdate();
                update.command = UnitUpdateCommand.ATTACK;
                update.moving  = _unit.unitIndex;
                update.target  = unit.unitIndex;
                NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
                _cellGrid.CellGridState = new CellGridStateUnitSelected(_cellGrid, _unit);
            }
            else if (_unitsInRange.Contains(unit) && _unit.ActionPoints > 0 && _unit.PlayerNumber == unit.PlayerNumber && _unit.typeOfTargets == Target.FRIENDLY)
            {
                _unit.DealDamage(unit);
                UnitUpdate update = new UnitUpdate();
                update.command = UnitUpdateCommand.ATTACK;
                update.moving  = _unit.unitIndex;
                update.target  = unit.unitIndex;
                NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
                _cellGrid.CellGridState = new CellGridStateUnitSelected(_cellGrid, _unit);
            }

            if (unit.PlayerNumber.Equals(_unit.PlayerNumber) && (unit.PlayerNumber == NetManager.GetIDIfConnected() - 1 || Unit.debugoverride))
            {
                if (_unit.hasMoved)
                {
                    _unit.ActionPoints = 0;
                    _unit.GetComponent <Renderer>().material.color = _unit.LeadingColor / 6.0f;
                }
                _cellGrid.CellGridState = new CellGridStateUnitSelected(_cellGrid, unit);
            }
        }
        else
        {
            _cellGrid.CellGridState = new CellGridStateUnitSelected(_cellGrid, unit);
        }
    }
Beispiel #10
0
    public void SpawniFactionWithButton(int unitType)
    {
        UnitType  type = (UnitType)unitType;
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).selected)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        GameObject newUnit = Instantiate(iFactionUnits[unitType - iFactIndexMod], site.transform.position, Quaternion.identity);

        site.spawnUnit             = true;
        newUnit.transform.position = new Vector3(newUnit.transform.position.x, newUnit.transform.position.y, -1.0f);

        if (!site.Cell.IsTaken && site.spawnUnit && site.selected && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = site.transform.position.x;
            update.newLocationY = site.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.moving       = site.unitIndex;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
Beispiel #11
0
    public void HandleBuildAction(int index)
    {
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).selected)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        //handle cost
        if ((DarkRift.DarkRiftAPI.isConnected && !site.CanAffordToBuild(NetManager.buildCosts[index - 1])))
        {
            return;
        }

        site.grid.Players[site.PlayerNumber].Money -= NetManager.buildCosts[index - 1];
        PlayerController.currTurnMoney              = site.grid.Players[site.PlayerNumber].Money;
        SetAvailableFundsText(GameObject.Find("Canvas").GetComponentsInChildren <Text>(), site);
        //GameObject.Find("Canvas").GetComponentsInChildren<Text>()[site.PlayerNumber].text = PlayerController.currTurnMoney.ToString() + "G" + "(+" + site.grid.Players[site.PlayerNumber].income.ToString() + "G)";

        site.buildingType = (MatIndex)index;
        site.GetComponent <ChangeMaterial>().SetNewMaterial((MatIndex)index);

        UnitUpdate update = new UnitUpdate();

        update.command      = UnitUpdateCommand.BUILDSITE;
        update.moving       = site.unitIndex;
        update.buildingType = (MatIndex)index;
        NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);

        site.OnUnitDeselected();
    }
Beispiel #12
0
 // Update is called once per frame
 void Update()
 {
     if ((DarkRift.DarkRiftAPI.isConnected && DarkRift.DarkRiftAPI.id - 1 == GameObject.Find("CellGrid").GetComponent <CellGrid>().CurrentPlayerNumber || Unit.debugoverride) &&
         Input.GetKeyDown(KeyCode.N))
     {
         UnitUpdate update = new UnitUpdate();
         update.command = UnitUpdateCommand.END_TURN;
         NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
         cellGrid.EndTurn();//User ends hit turn by pressing the N key
     }
     //else if(Input.GetKeyDown(KeyCode.U))
     //{
     //    var o = Instantiate(redUnit, cellGrid.Cells[0].transform.position, Quaternion.identity);
     //    ((SampleUnit2)(o)).transform.parent = GameObject.Find("Units Parent").transform;
     //    //cellGrid.SpawnMoreUnits();
     //    List<Cell> cells = new List<Cell>();
     //    cells.Add(cellGrid.Cells[0]);
     //    cellGrid.GetComponent<CustomUnitGenerator>().SpawnUnit((Unit)o, cellGrid.Cells[0]);
     //    cellGrid.GetComponent<CustomUnitGenerator>().SnapToGrid() ;
     //}
 }
Beispiel #13
0
 private bool IsEndTurnCommand(UnitUpdate update)
 {
     return(update.command == UnitUpdateCommand.END_TURN);
 }
Beispiel #14
0
 public bool UnitUpdate(UnitUpdate request)
 {
     return(_unitRepository.UnitUpdate(request));
 }
Beispiel #15
0
    // Update is called once per frame
    void Update()
    {
        Unit     newUnit = null;
        UnitType type    = UnitType.ERROR;

        if (!selected || faction != Faction.BASIC)
        {
            return;
        }
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            if (faction == Faction.BASIC)
            {
                newUnit   = Instantiate(unit1, Cell.transform.position, Quaternion.identity);
                spawnUnit = true;
                type      = UnitType.FIGHTER;
            }
            else if (faction == Faction.CHEAP)
            {
                newUnit   = Instantiate(unit4, Cell.transform.position, Quaternion.identity);
                spawnUnit = true;
                type      = UnitType.CAPCOPTER;
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            if (faction == Faction.BASIC)
            {
                newUnit   = Instantiate(unit2, Cell.transform.position, Quaternion.identity);
                spawnUnit = true;
                type      = UnitType.BOMBER;
            }
            else if (faction == Faction.CHEAP)
            {
                newUnit   = Instantiate(unit5, Cell.transform.position, Quaternion.identity);
                spawnUnit = true;
                type      = UnitType.AERIALACE;
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            if (faction == Faction.BASIC)
            {
                newUnit   = Instantiate(unit3, Cell.transform.position, Quaternion.identity);
                spawnUnit = true;
                type      = UnitType.COPTER;
            }
            else if (faction == Faction.CHEAP)
            {
                newUnit   = Instantiate(unit6, Cell.transform.position, Quaternion.identity);
                spawnUnit = true;
                type      = UnitType.BOMB;
            }
        }

        if (!Cell.IsTaken && spawnUnit && selected && CanSpawnUnit(newUnit))
        {
            SpawnUnit(newUnit);
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = this.transform.position.x;
            update.newLocationY = this.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        spawnUnit = false;
    }
Beispiel #16
0
    public void SpawnUnitWithButton(int intType)
    {
        Unit     newUnit = null;
        UnitType type    = (UnitType)intType;
        Airport  rax     = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b as Airport && (b as Airport).selected)
            {
                rax = b as Airport;
                break;
            }
        }
        if (rax == null)
        {
            return;
        }
        if (type == UnitType.FIGHTER)
        {
            newUnit       = Instantiate(unit1, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.FIGHTER;
        }
        if (type == UnitType.BOMBER)
        {
            newUnit       = Instantiate(unit2, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.BOMBER;
        }
        if (type == UnitType.COPTER)
        {
            newUnit       = Instantiate(unit3, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.COPTER;
        }
        if (type == UnitType.CAPCOPTER)
        {
            newUnit       = Instantiate(unit4, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.AERIALACE)
        {
            newUnit       = Instantiate(unit5, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.BOMB)
        {
            newUnit       = Instantiate(unit6, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }

        if (!rax.Cell.IsTaken && rax.spawnUnit && rax.selected && rax.CanSpawnUnit(newUnit))
        {
            rax.SpawnUnit(newUnit);
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = rax.transform.position.x;
            update.newLocationY = rax.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        rax.spawnUnit = false;
    }
Beispiel #17
0
 private bool IsMoveUnitCommand(UnitUpdate update)
 {
     return(update.command == UnitUpdateCommand.MOVE);
 }
Beispiel #18
0
    // Update is called once per frame
    void Update()
    {
        Unit     newUnit = null;
        UnitType type    = UnitType.ERROR;

        if (!selected || faction != Faction.BASIC)
        {
            return;
        }
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            newUnit   = Instantiate(unit1, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.INFANTRY;
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            newUnit   = Instantiate(unit2, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.MECH;
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            newUnit   = Instantiate(unit3, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.RECON;
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            newUnit   = Instantiate(unit4, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.TANK;
        }
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            newUnit   = Instantiate(unit5, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.MDTANK;
        }
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            newUnit   = Instantiate(unit6, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.ARTILLERY;
        }
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            newUnit   = Instantiate(unit7, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.ROCKETS;
        }
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            newUnit   = Instantiate(unit0, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.MISSILES;
        }
        if (Input.GetKeyDown(KeyCode.Alpha9))
        {
            newUnit   = Instantiate(unit8, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.APC;
        }
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            newUnit   = Instantiate(unit9, Cell.transform.position, Quaternion.identity);
            spawnUnit = true;
            type      = UnitType.ANTIAIR;
        }

        if (!Cell.IsTaken && spawnUnit && selected && CanSpawnUnit(newUnit))
        {
            SpawnUnit(newUnit);
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = this.transform.position.x;
            update.newLocationY = this.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        spawnUnit = false;
    }
Beispiel #19
0
    void ReceiveData(ushort senderID, byte tag, ushort subject, object data)
    {
        bool ignoreMessage = false;

        if (ignoreMessage)
        {
            return;
        }

        if (tag == TagIndex.Controller)
        {
            if (subject == TagIndex.ControllerSubjects.JoinMessage)
            {
                networkConnected = true;
                DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, null);
                SendData(TagIndex.Controller, TagIndex.PlayerUpdate, factions[DarkRiftAPI.id - 1]);
                if (senderID == 1)
                {
                    playerNumber = 2;
                }
                if (senderID > playerCount)
                {
                    playerCount = senderID;
                }
                //GameObject.Find("Name1").GetComponent<UnityEngine.UI.InputField>().readOnly = true;
                //GameObject.Find("Name2").GetComponent<UnityEngine.UI.InputField>().readOnly = false;

                //Handle Connect message
            }

            if (subject == TagIndex.ControllerSubjects.SpawnPlayer)
            {
                networkConnected = true;
                //Handle spawning the player into our game
            }

            if (subject == TagIndex.PlayerUpdate)
            {
                if (data is string && (data as string) == "ERROR")
                {
                    possibleDesyncOccurred = true;
                    RetrySendData();
                }
                if (data is string[])
                {
                    string[] name = data as string[];
                    if (name[0] == "name")
                    {
                        GameObject go = GameObject.Find("Name" + (senderID).ToString());
                        go.GetComponent <UnityEngine.UI.InputField>().text = name[1];
                    }
                    else if (name[0] == "StartGame")
                    {
                        DontDestroyOnLoad(transform.gameObject);
                        DontDestroyOnLoad(GameObject.Find("GameInitiator"));
                        //if (NetManager.playerCount >= 2)
                        //{
                        //    GameInit.mapName = GameInit.mapNames[NetManager.playerCount - 2];
                        //}
                        //string mapDropDownText = GameObject.Find("mapDropDown").GetComponent<Dropdown>().itemText.text;
                        //GameInit.mapName = mapDropDownText.Split(' ')[1];
                        GameInit.mapName = name[1];
                        SceneManager.LoadScene(GameInit.mapName);
                        //SceneManager.LoadScene("Main");
                    }
                    else if (name[0] == "charUpdate")
                    {
                        GameObject.Find(name[1]).GetComponent <UnityEngine.UI.Dropdown>().value = int.Parse(name[2]);
                    }
                }
                if (data is UnitUpdate /*&& messageIndex + 1 == (data as UnitUpdate).index*/)
                {
                    UnitUpdate update      = data as UnitUpdate;
                    GameObject unitsParent = GameObject.Find("Units Parent");
                    Unit[]     units       = unitsParent.GetComponentsInChildren <Unit>();
                    CellGrid   grid        = GameObject.Find("CellGrid").GetComponent <CellGrid>();
                    messageIndex = update.index;
                    if (IsEndTurnCommand(update))
                    {
                        grid.EndTurn();
                        //end turn
                    }
                    else if (IsMoveUnitCommand(update))
                    {
                        foreach (Unit u in units)
                        {
                            if (u.unitIndex == update.moving)
                            {
                                //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>();
                                foreach (Cell c in grid.Cells)
                                {
                                    if (c.transform.position.x == update.newLocationX &&
                                        c.transform.position.y == update.newLocationY)
                                    {
                                        u.AdjustCellMovementCosts();
                                        var path = u.FindPath(grid.Cells, c);
                                        u.ResetMovementPoints();
                                        u.Move(c, path);
                                        u.ResetMovementPoints();
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                    else if (IsAttackCommand(update))
                    {
                        Unit attacker = null;
                        Unit defender = null;
                        foreach (Unit u in units)
                        {
                            if (u.unitIndex == update.moving)
                            {
                                attacker = u;
                                //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>();
                            }
                            if (u.unitIndex == update.target)
                            {
                                defender = u;
                            }
                            if (attacker != null && defender != null)
                            {
                                attacker.DealDamage(defender, true);
                                //attack

                                break;
                            }
                        }
                    }
                    else if (IsSpawnUnitCommand(update))
                    {
                        foreach (Unit c in grid.Units)
                        {
                            if (c.transform.position.x == update.newLocationX && c.transform.position.y == update.newLocationY)
                            {
                                if (c is BarracksUnit)
                                {
                                    (c as BarracksUnit).InstantiateUnit(update.type);
                                }
                                else if (c is BuildSite)
                                {
                                    if (update.type >= UnitType.INFANTRY && update.type <= UnitType.ANTIAIR)
                                    {
                                        //TODO 1
                                        //guiCamRef.GetComponent<NewBarracks>().SpawnAStarFromNetwork((int)update.type, (int)update.moving);
                                        guiCamRef.GetComponent <NewBarracks>().SpawnUnitFromNetwork((int)update.type, (int)update.moving, 1);
                                        //GameObject.Find("GUICamera").GetComponent<NewBarracks>().SpawnAStarFromNetwork((int)update.type, (int)update.index);
                                    }
                                    else if (update.type >= UnitType.ANDROID && update.type <= UnitType.TURRET)
                                    {
                                        guiCamRef.GetComponent <NewBarracks>().SpawniFactionFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    else if (update.type >= UnitType.ADVERSARY && update.type <= UnitType.STASISGUN)
                                    {
                                        guiCamRef.GetComponent <NewBarracks>().SpawnusbFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    //(c as BuildSite).InstantiateUnit(update.type);
                                }
                                break;
                            }
                        }
                        foreach (Unit c in grid.Units)
                        {
                            if (c.transform.position.x == update.newLocationX && c.transform.position.y == update.newLocationY)
                            {
                                if (c is Airport)
                                {
                                    (c as Airport).InstantiateUnit(update.type);
                                }
                                else if (c is BuildSite)
                                {
                                    if (update.type >= UnitType.FIGHTER && update.type <= UnitType.COPTER)
                                    {
                                        guiCamRef.GetComponent <NewAirport>().SpawnAStarFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    else if (update.type >= UnitType.CAPCOPTER && update.type <= UnitType.BOMB)
                                    {
                                        guiCamRef.GetComponent <NewAirport>().SpawniFactionFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    else if (update.type >= UnitType.ORBITALSTRIKER && update.type <= UnitType.NULLSTAR)
                                    {
                                        guiCamRef.GetComponent <NewAirport>().SpawniFactionFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    //(c as BuildSite).InstantiateUnit(update.type);
                                }
                                break;
                            }
                        }
                        //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>()
                    }
                    else if (IsCaptureCommand(update))
                    {
                    }
                    else if (IsIncreaseMoneGenCommand(update))
                    {
                        foreach (Unit c in grid.Units)
                        {
                            if (c.unitIndex == update.moving)
                            {
                                if (c is City)
                                {
                                    (c as City).SelfIncreaseMoneyGenIfAble();
                                }
                                else if (c is BuildSite)
                                {
                                    (c as BuildSite).SelfIncreaseMoneyGenIfAble();
                                }
                            }
                        }
                    }
                    else if (IsUpgradeBuildSiteCommand(update))
                    {
                        BuildSite site = null;

                        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
                        {
                            if (b is BuildSite && b.unitIndex == update.moving)
                            {
                                site = b as BuildSite;
                                break;
                            }
                        }

                        if (site == null)
                        {
                            return;
                        }

                        //handle cost
                        Debug.Log("Site == null: " + (site == null).ToString());
                        Debug.Log("update == null: " + (update == null).ToString());
                        Debug.Log(NetManager.buildCosts[(int)update.buildingType - 1]);

                        if (!site.CanAffordToBuild(NetManager.buildCosts[(int)update.buildingType - 1]))
                        {
                            return;
                        }

                        site.grid.Players[site.PlayerNumber].Money -= NetManager.buildCosts[(int)update.buildingType - 1];
                        PlayerController.currTurnMoney              = site.grid.Players[site.PlayerNumber].Money;
                        GameObject.Find("Canvas").GetComponentsInChildren <Text>()[site.PlayerNumber].text = PlayerController.currTurnMoney.ToString() + "G" + "(+" + site.grid.Players[site.PlayerNumber].income.ToString() + "G)";

                        site.buildingType = update.buildingType;
                        site.GetComponent <ChangeMaterial>().SetNewMaterial(update.buildingType);
                    }

                    else if (data is UnitUpdate && messageIndex + 1 != (data as UnitUpdate).index)
                    {
                        possibleDesyncOccurred = true;
                        SendData(TagIndex.Controller, TagIndex.PlayerUpdate, "ERROR");
                        //send error message
                    }
                }
                else if (data is Unit.Faction)
                {
                    factions[senderID - 1] = (Unit.Faction)data;
                }
            }
        }
    }
Beispiel #20
0
 private bool IsUpgradeBuildSiteCommand(UnitUpdate update)
 {
     return(update.command == UnitUpdateCommand.BUILDSITE);
 }
Beispiel #21
0
 private bool IsIncreaseMoneGenCommand(UnitUpdate update)
 {
     return(update.command == UnitUpdateCommand.INCOME);
 }
Beispiel #22
0
 private bool IsCaptureCommand(UnitUpdate update)
 {
     return(false);
 }
Beispiel #23
0
 private bool IsSpawnUnitCommand(UnitUpdate update)
 {
     return(update.command == UnitUpdateCommand.SPAWN);
 }
Beispiel #24
0
 private bool IsAttackCommand(UnitUpdate update)
 {
     return(update.command == UnitUpdateCommand.ATTACK);
 }
Beispiel #25
0
    public void SpawnUnitWithButton(int intType)
    {
        Unit         newUnit = null;
        UnitType     type    = (UnitType)intType;
        BarracksUnit rax     = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b as BarracksUnit && (b as BarracksUnit).selected)
            {
                rax = b as BarracksUnit;
                break;
            }
        }
        if (rax == null)
        {
            return;
        }
        if (type == UnitType.INFANTRY)//Spawning units here.
        {
            newUnit       = Instantiate(unit1, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.INFANTRY;
        }
        if (type == UnitType.MECH)
        {
            newUnit       = Instantiate(unit2, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.MECH;
        }
        if (type == UnitType.RECON)
        {
            newUnit       = Instantiate(unit3, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.RECON;
        }
        if (type == UnitType.TANK)
        {
            newUnit       = Instantiate(unit4, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.TANK;
        }
        if (type == UnitType.MDTANK)
        {
            newUnit       = Instantiate(unit5, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.MDTANK;
        }
        if (type == UnitType.ARTILLERY)
        {
            newUnit       = Instantiate(unit6, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.ARTILLERY;
        }
        if (type == UnitType.ROCKETS)
        {
            newUnit       = Instantiate(unit7, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.ROCKETS;
        }
        if (type == UnitType.MISSILES)
        {
            newUnit       = Instantiate(unit0, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.MISSILES;
        }
        if (type == UnitType.APC)
        {
            newUnit       = Instantiate(unit8, rax.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.APC;
        }
        if (type == UnitType.ANTIAIR)
        {
            newUnit       = Instantiate(unit9, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
            type          = UnitType.ANTIAIR;
        }
        if (type == UnitType.ANDROID)
        {
            newUnit       = Instantiate(unit11, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.SNIPER)
        {
            newUnit       = Instantiate(unit12, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.REPAIR)
        {
            newUnit       = Instantiate(unit13, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.ROBOTANK)
        {
            newUnit       = Instantiate(unit14, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.SPEEDTANK)
        {
            newUnit       = Instantiate(unit15, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.MEGATANK)
        {
            newUnit       = Instantiate(unit16, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.CANNON)
        {
            newUnit       = Instantiate(unit17, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.AAGUN)
        {
            newUnit       = Instantiate(unit19, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }
        if (type == UnitType.TURRET)
        {
            newUnit       = Instantiate(unit18, rax.Cell.transform.position, Quaternion.identity);
            rax.spawnUnit = true;
        }

        if (!rax.Cell.IsTaken && rax.spawnUnit && rax.selected && rax.CanSpawnUnit(newUnit))
        {
            rax.hasAlreadySpawned = true;
            rax.SpawnUnit(newUnit);
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = rax.transform.position.x;
            update.newLocationY = rax.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        rax.spawnUnit = false;
    }
Beispiel #26
0
 public bool Unit_Update([FromBody] UnitUpdate request)
 {
     return(_unitService.UnitUpdate(request));
 }