Esempio n. 1
0
        public ActionResult getMovementLogbook(string _data, bool player = false)
        {
            string[] data         = _data.Split('|');
            var      country1     = 0;
            var      country2     = 0;
            string   troopsNumber = data[2];
            string   values       = "";


            if (player)
            {
                for (int i = 1; i <= manager.Countries.Count; i++)
                {
                    //get deployer's country id
                    if (manager.Countries[i].CountryName == data[0])
                    {
                        manager.Countries[i].TroopsCount -= int.Parse(data[2]);
                        country1 = manager.Countries[i].CountryID;
                    }
                    //get receiver's country id
                    if (manager.Countries[i].CountryName == data[1])
                    {
                        country2 = manager.Countries[i].CountryID;
                    }
                }
            }
            else
            {
                country1 = int.Parse(data[0]);
                country2 = int.Parse(data[2]);
            }

            // look if the countries are neighbors
            int[] troops = manager.getNeighborsTroopsCount(country1, manager.Countries[country1].Owner);
            if (manager.Countries[country1].Owner == 1)
            {
                rowNumbers[1]++;
            }
            else
            {
                rowNumbers[2]++;
            }
            if (manager.getNeighborsAlly(country1, manager.Countries[country1].Owner).Contains(country2))
            {
                manager.Countries[country2].TroopsCount += int.Parse(data[2]);
                values = "1";
            }
            // neutral or enemies
            else
            {
                // condition if the country was conquered
                if (manager.Countries[country2].TroopsCount < int.Parse(data[2]))
                {
                    manager.Countries[country2].Owner = manager.Countries[country1].Owner;
                    values = "1";
                }
                // still neutral or enemy
                else
                {
                    values = "0";
                }

                manager.Countries[country2].TroopsCount = Math.Abs(int.Parse(data[2]) - manager.Countries[country2].TroopsCount);
                //manager.Countries[country2].TroopsCount = Math.Abs(manager.Countries[country2].TroopsCount - int.Parse(data[2]));
            }
            // values = one if the country was conquered + id deployer + deployer remaining troops + id receiver + receiver remaining troops + player
            values += "|" + country1 + "|" + manager.Countries[country1].TroopsCount + "|" + country2 + "|" +
                      manager.Countries[country2].TroopsCount + "|" + manager.Countries[country1].Owner;


            return(Json(new { _values = values }));
        }