public string AttackStarted(FormCollection collection) { string id = Request.Form["PlayerId"]; string opponentid = Request.Form["opponenId"]; PlayerForDataBase PlayerData = dataBase.PlayerinDataBase.Find(id); PlayerForDataBase opponentData = dataBase.PlayerinDataBase.Find(opponentid); if (PlayerData != null && opponentData != null) { AddNew.WaitOne(); PlayerData.remaningTimeToNextAttack = Constants.TimeToNextAttackDefult; opponentData.remaningShialdInSecond = Constants.shildDefultTime; 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()); } }
public string HomeBuyingAssetRequst(FormCollection collection) { return true.ToString(); string id = Request.Form["PlayerId"]; int idOfBuyingAsset =Int32.Parse( Request.Form["idOfBuyingAsset"]); string TypOfBuyingAsset = Request.Form["TypOfBuyingAsset"]; buyableType obType = new Convertor().StringTobuyableType(TypOfBuyingAsset); string newStringOfScene = Request.Form["newStringOfScene"]; PlayerForDataBase PlayerData = dataBase.PlayerinDataBase.Find(id); Asset buyingAsset = new AssetManager().RetrunAsset(obType, idOfBuyingAsset); if (PlayerData != null) { if (PlayerData.BuyThisAssetForPlayer(buyingAsset) ){ //PlayerData. dataBase.Entry(PlayerData).State = EntityState.Modified; dataBase.SaveChanges(); return true.ToString(); } else { return false.ToString(); } } else { return false.ToString(); } }
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()); } }
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(); } }
playerData ConvertBuildingDataBaseVersionToBuilding(PlayerForDataBase newB) { playerData bForD = new playerData(); bForD.addingCoinRate = newB.addingCoinRate; bForD.addingElixirRate = newB.addingElixirRate; bForD.coin = newB.coin; bForD.elixir = newB.elixir; bForD.ID = newB.ID; bForD.lastTimeVariableUpdate = newB.lastTimeVariableUpdate; return(bForD); }
/* * public BuildingForDataBase ConvertBuildingToDataBaseVersion(Building newB) * { * BuildingForDataBase bForD = new BuildingForDataBase(); * bForD.addingCoinRate = newB.addingCoinRate; * bForD.addingElixirRate = newB.addingElixirRate; * bForD.buildingCode = Constants.DefultBuildingString; * bForD.coin = newB.coin; * bForD.elixir = newB.elixir; * bForD.ID = newB.ID; * bForD.lastTimeVariableUpdate = newB.lastTimeVariableUpdate; * * bForD.remaningShialdInSecond = newB.remaningShialdInSecond; * return bForD; * * } */ public PlayerForSerialize ConvertBuildingDataBaseToSerialize(PlayerForDataBase newB) { PlayerForSerialize bForD = new PlayerForSerialize(); bForD.addingCoinRate = newB.addingCoinRate; //bForD.PointTime = newB.PointTime; //bForD.ProductCode = newB.ProductCode; bForD.addingElixirRate = newB.addingElixirRate; bForD.buildingCode = newB.buildingCode; bForD.coin = newB.coin; bForD.elixir = newB.elixir; bForD.ID = newB.ID; bForD.remaningShialdInSecond = newB.remaningShialdInSecond; bForD.remaningTimeToNextAttack = newB.remaningTimeToNextAttack; return(bForD); }
public string UpdateBuilding(string buildst) { string id = Request.Form["PlayerId"]; string BulidngString = Request.Form["BulidngString"]; PlayerForDataBase PlayerData = dataBase.PlayerinDataBase.Find(id); if (PlayerData != null) { PlayerData.buildingCode = BulidngString; dataBase.Entry(PlayerData).State = EntityState.Modified; dataBase.SaveChanges(); return true.ToString(); } else { return false.ToString(); } }
public string UpdateProductCode(string buildst) { string id = Request.Form["PlayerId"]; string productString = Request.Form["ProductString"]; long PointTime = long.Parse(Request.Form["PointTime"]); PlayerForDataBase PlayerData = dataBase.PlayerinDataBase.Find(id); if (PlayerData != null) { PlayerData.ProductCode = productString; PlayerData.PointTime = PointTime; dataBase.Entry(PlayerData).State = EntityState.Modified; dataBase.SaveChanges(); return true.ToString(); } else { return false.ToString(); } }
public void AddPlayerInfo(PlayerForDataBase newB) { bool isFind = false; foreach (playerData bForD in playersList) { if (bForD.ID == newB.ID && !isFind) { isFind = true; } } if (isFind) { ErrorSystem.AddBigError("playerListManager.AddPlayerInfo. player is in the data base"); } else { playerData newbuilding = ConvertBuildingDataBaseVersionToBuilding(newB); playersList.Add(newbuilding); } }
public void UpdatePlayerInfo(PlayerForDataBase newB) { bool isFind = false; foreach (playerData bForD in playersList) { if (bForD.ID == newB.ID && !isFind) { bForD.addingCoinRate = newB.addingCoinRate; bForD.addingElixirRate = newB.addingElixirRate; bForD.coin = newB.coin; bForD.elixir = newB.elixir; bForD.lastTimeVariableUpdate = newB.lastTimeVariableUpdate; bForD.remaningShialdInSecond = newB.remaningShialdInSecond; isFind = true; } } if (!isFind) { ErrorSystem.AddBigError("playerListManager.UpdatePlayerInfo. player not find"); } }
public PlayerForDataBase returnDefultBulding() { PlayerForDataBase bb = new PlayerForDataBase(); return(bb); }