Ejemplo n.º 1
0
        public string AttackResult(FormCollection collection)
        {
            string id             = Request.Form["PlayerId"];
            string opponentid     = Request.Form["opponenId"];
            int    gatheredCoin   = Int32.Parse(Request.Form["gatheredCoin"]);
            int    gatheredElixir = Int32.Parse(Request.Form["gatheredElixir"]);


            PlayerForDataBase PlayerData   = dataBase.PlayerinDataBase.Find(id);
            PlayerForDataBase opponentData = dataBase.PlayerinDataBase.Find(opponentid);

            if (PlayerData != null && opponentData != null)
            {
                PlayerData.UpdatePropertyByTime();
                opponentData.UpdatePropertyByTime();
                AddNew.WaitOne();
                opponentData.coin   -= gatheredCoin;
                opponentData.elixir -= gatheredElixir;
                PlayerData.coin     += gatheredCoin;
                PlayerData.elixir   += gatheredElixir;
                dataBase.Entry(PlayerData).State   = EntityState.Modified;
                dataBase.Entry(opponentData).State = EntityState.Modified;
                dataBase.SaveChanges();
                AddNew.ReleaseMutex();
                new PlayerListManager().UpdatePlayerInfo(PlayerData);
                new PlayerListManager().UpdatePlayerInfo(opponentData);
                return(true.ToString());
            }
            else
            {
                return(false.ToString());
            }
        }
Ejemplo n.º 2
0
        public string AttackRequst(FormCollection collection)
        {
            string id = Request.Form["PlayerId"];
            PlayerForDataBase thisPlayerData = dataBase.PlayerinDataBase.Find(id);
            thisPlayerData.UpdatePropertyByTime();
            if(0 < thisPlayerData.remaningTimeToNextAttack)
            {
                return false.ToString();
            }

            string enemyId = new PlayerListManager().NextIdForAtack(id);
            if (enemyId != null)
            {
                //Theif2dDataDBContext dataBase = new Theif2dDataDBContext();
                PlayerForDataBase PlayerData = dataBase.PlayerinDataBase.Find(enemyId);
                if(PlayerData != null)
                {
                    PlayerForSerialize playerDataForSerialize = new Utlities().ConvertBuildingDataBaseToSerialize(PlayerData);
                    LogSystem.AddPlayerLog(id, "player" + id.ToString() + " attacked " + PlayerData.ID + " ID");
                    string uu = new JavaScriptSerializer().Serialize(playerDataForSerialize);
                    return uu;
                }
                return false.ToString();
            }
            else
            {
                return false.ToString();
            }
        }