public async Task <bool> UpdateUserGameData(UserGameData userGameData) { try { if (userGameData.UserId < 0) { await cache.SetAsync(userGameData.UserId.ToString(), userGameData, new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(5) }); return(true); } using (var db = databaseManager.GetWritableDatabase()) { db.InsertOrUpdate(userGameData, userGameData.UserId, userGameData.GameId); var result = await db.SaveChangesAsync() > 0; if (!result) { logger.LogWarning("Update user game data to db was failed"); } return(result); } } catch (Exception err) { logger.LogError(err, "UpdateUserGameData for UserGame({0}-{1}) encountered exception {2}", userGameData.UserId, userGameData.GameId, err.Message); return(false); } }
//deploy your methods here private MainController() { userGameData = new UserGameData(); userGameData.Init(); enemyGameData = new EnemyGameData(); enemyGameData.Init(); }
public void showAttack(UserGameData user) { if (!userListPanel.getTurnUser().email.Equals(user.email)) { AttackState state = attackPanel.GetComponent <AttackState>(); state.show(roomNo, user); } }
void autoSelect(List <Card> fieldList, UserGameData user) { int index = rm.Next(0, fieldList.Count); Card c = fieldList[index]; RequestSelectFieldCard req = new RequestSelectFieldCard(user.email, c.index, roomNo); SocketManager.Instance().sendMessage(req); }
private IEnumerator generateMoney(UserGameData gameData) { if (isSetGenerateMoney) { yield return new WaitForSeconds(4f); gameData.money = gameData.money + gameData.generatingMoney; StartCoroutine(generateMoney(gameData)); } }
public void setData(UserGameData data) { no = data.no; email = data.email; nickName = data.nickName; cards = data.cards; isLose = data.isLose; isInit = data.isInit; userType = data.userType; }
public void setTrun(int turnIndex) { UserGameData user = userList[turnIndex]; foreach (GameObject obj in playUserList) { UserPanel userPanel = obj.GetComponent <UserPanel>(); userPanel.setTurn(userPanel.userData.email.Equals(user.email)); } }
public void SaveUserDataForWindows(UserGameData _userGameData) { userGameData = _userGameData; // 파일 생성. BinaryFormatter bf = new BinaryFormatter(); FileStream fileStream = File.Open(fileDirectory, FileMode.OpenOrCreate); // 시리얼라이징. bf.Serialize(fileStream, userGameData); fileStream.Close(); }
public void show(int roomNo, UserGameData selectUserData) { base.show(); this.roomNo = roomNo; this.selectUser = selectUserData.email; this.cardList = selectUserData.cards; labelUserName.text = selectUserData.nickName; if (cardObj == null) { cardObj = (GameObject)Instantiate(Resources.Load("Davincicode/prefab/NumberCardPrefab")); cardObj.SetActive(false); } for (int i = 0; i < cardList.Count; i++) { GameObject itemObj = NGUITools.AddChild(grid.gameObject, cardObj); NumberCard source = itemObj.GetComponent <NumberCard>(); cardObjList.Add(itemObj); Debug.Log("cardList for : " + itemObj + " // index : " + source.info.index); source.setData(cardList[i].isOpen, cardList[i].index); source.selectCallback((int index) => { Debug.Log("selected index : " + i); selectIndex = index; foreach (GameObject obj in cardObjList) { NumberCard src = obj.GetComponent <NumberCard>(); if (src.info.index == index) { src.setSelect(true); } else { src.setSelect(false); } } setButton(true); }); } grid.Reposition(); // Canvas.ForceUpdateCanvases(); for (int i = 0; i < cardList.Count; i++) { Debug.Log("cardList : " + cardList[i].index); } Debug.Log("cardListObj count : " + cardObjList.Count); setButton(false); DavinciController.Instance().hideBlock(); }
public void ChangeUserData(UserDataChangeModel model, Action <UserGameData> resultCallback) { var request = new PostRequest <UserGameData>() .SelectMethod(NetworkConstants.Methods.USER_DATA_EDIT) .AddBodyParameters(model) .AddSuccesCallback(data => { userGameData = data; resultCallback(data); }) .Build(); networking.SendRequest(request); }
public void openCard(int turnIndex, int cardIndex, DavinciController.ActionCallback callback) { UserGameData user = userList[turnIndex]; foreach (GameObject obj in playUserList) { UserPanel userPanel = obj.GetComponent <UserPanel>(); if (userPanel.userData.email.Equals(user.email)) { userPanel.openCard(cardIndex, callback); break; } } }
private IEnumerator setMoneyGenerationDiff(UserGameData gameData) { int generatingMoney = gameData.teritoryCount; GameObject[] bases = GameObject.FindGameObjectsWithTag("base"); foreach (GameObject obj in bases) { GameObject objectMain = obj.transform.parent.gameObject; MainBase mainBase = (MainBase) objectMain.GetComponent("MainBase"); generatingMoney -= mainBase.generatingUnits; generatingMoney -= 5; } gameData.generatingMoney = generatingMoney; yield return null; StartCoroutine(setMoneyGenerationDiff(gameData)); }
public void setData(UserGameData data) { userData = data; nickName.text = userData.nickName; for (int i = 0; i < userData.cards.Count; i++) { UserPreviewCard preV = preViewList[i].GetComponent <UserPreviewCard>(); preV.setData(userData.cards[i], isMy()); } if (data.isLose == false) { spriteLoseBg.gameObject.SetActive(false); labelLose.gameObject.SetActive(false); } }
public MockUserDataAccess() { userGameData = new UserGameData { first_name = "John", last_name = "Doe", nickname = "heresjohny", email = "*****@*****.**", user_photo = "http://lorempixel.com/500/500/", level_points = 250, prestige_points = 75, }; levelsTresholds = new LevelsTresholds { level_treshold = new[] { 0, 100, 500, 1000, 5000 }, prestige_treshold = new[] { 0, 100, 500, 1000, 5000 }, }; }
public void GetUserData(Action <UserGameData> resultCallback, bool forceOverwrite = false) { if (userGameData != null && !forceOverwrite) { resultCallback(userGameData); } else { var request = new GetRequest <UserGameData>() .SelectMethod(NetworkConstants.Methods.USER_DATA) .AddSuccesCallback(data => { userGameData = data; resultCallback(data); }) .Build(); networking.SendRequest(request); } }
public void init(List <UserGameData> list, int roomNo) { this.roomNo = roomNo; attackGuide.gameObject.SetActive(false); UserGameData myData = new UserGameData(); foreach (UserGameData data in list) { if (isMyData(data)) { myData.setData(data); list.Remove(data); break; } } for (int i = 0; i < 4; i++) { GameObject itemObj = NGUITools.AddChild(grid.gameObject, userObj); userObjList.Add(itemObj); UserPanel data = itemObj.GetComponent <UserPanel>(); if (i < list.Count) { data.setData(list[i]); data.reload(); playUserList.Add(userObjList[i]); } else { if (i == 3) { data.setData(myData); data.reload(); playUserList.Add(userObjList[i]); } else { //userObjList[i].SetActive(false); data.offPanel(); } } } }
public void InitData() { userGameData = new UserGameData(); if(Application.platform == RuntimePlatform.WindowsEditor) { fileDirectory = Application.persistentDataPath + "/WatchOut_User.datas"; } else if(Application.platform == RuntimePlatform.WindowsPlayer) { fileDirectory = Application.persistentDataPath + "/WatchOut_User.datas"; } else if(Application.platform == RuntimePlatform.Android) { //fileDirectory = Application.persistentDataPath; //fileDirectory = fileDirectory.Substring(0, fileDirectory.LastIndexOf('/')); //fileDirectory = Path.Combine(fileDirectory, "Watch.data"); } }
public void LoadUserDataForWindows() { try { BinaryFormatter bf = new BinaryFormatter(); FileStream fileStream = File.Open(fileDirectory, FileMode.Open, FileAccess.Read, FileShare.Read); userGameData = (UserGameData)bf.Deserialize(fileStream); fileStream.Close(); } catch (FileNotFoundException e) { GameTime gameTime = new GameTime(); gameTime.InitTime(); userGameData.SetGameTime(gameTime); } finally { // to do } }
public void createNewUser() { BinaryFormatter bf = new BinaryFormatter(); UserGameData userData = new UserGameData(); UserProfile userProfile = new UserProfile(); loadUserList(); userProfile.userID = userList.users.Count; Debugger.printLog("NEW USER: "******"USER_" + userProfile.userID.ToString().PadLeft(3, '0')); userProfile.user = userData; userList.users.Add(userProfile); userID = userProfile.userID; bf.Serialize(file, userProfile); file.Close(); FileStream fileList = File.Open(Application.persistentDataPath + "USERLIST", FileMode.Open); bf.Serialize(fileList, userList.users); fileList.Close(); loadUserProfileAndData(userID); userData = null; userProfile = null; }
void autoAttack(List <UserGameData> userList, List <Card> filedCards, UserGameData player) { //선택가능한 렌덤 유저 선택 List <UserGameData> list = new List <UserGameData>(); foreach (UserGameData userData in userList) { if (!player.email.Equals(userData.email) && !userData.isLose) { list.Add(userData); } } int selectUserIndex = rm.Next(list.Count); UserGameData selectUser = list[selectUserIndex]; //해당 유저의 오픈되지 않은 카드 선택 Card card = null; int selectindex = 0; while (card == null) { selectindex = rm.Next(selectUser.cards.Count); if (!selectUser.cards[selectindex].isOpen) { card = new Card(); card.index = selectUser.cards[selectindex].index; card.isOpen = selectUser.cards[selectindex].isOpen; } } //선택가능한 카드 List <Card> totalSelectList = new List <Card>(); bool isHolsoo = card.index % 2 != 0; foreach (Card c in filedCards) { if (isHolsoo == (c.index % 2 != 0)) { totalSelectList.Add(c); } } foreach (UserGameData userData in userList) { if (!player.email.Equals(userData.email) && !userData.isLose) { foreach (Card c in userData.cards) { if (!c.isOpen) { if (isHolsoo == (c.index % 2 != 0)) { totalSelectList.Add(c); } } } } } var result = from c in totalSelectList orderby c.index descending select c; int min = -1; int max = 100; for (int i = 0; i < selectUser.cards.Count; i++) { Card c = selectUser.cards[i]; if (c.isOpen) { if (i < selectindex) { min = c.index; } else { max = c.index; break; } } } List <Card> selectList = new List <Card>(); foreach (Card c in result) { if (c.index > min && c.index < max) { selectList.Add(c); } } //조커 추가 // if(max < DavinciCommon.JOCKER_START_INDEX) // { // int lastIndex = totalSelectList.Count - 1; // Card lastCard = totalSelectList[lastIndex]; // if (lastCard.index >= DavinciCommon.JOCKER_START_INDEX) // { // selectList.Add(lastCard); // } // } int rmIndex = rm.Next(selectList.Count); int attackIndex = selectList[rmIndex].index; Debug.Log("autoAttack selectList count : " + selectList.Count + " // rmIndex : " + rmIndex + " // attackIndex : " + attackIndex); RequestAttack req = new RequestAttack(roomNo, selectUser.email, selectindex, attackIndex); //autoAttack(userList, filedCards, player, selectUser, index); SocketManager.Instance().sendMessage(req); }
// Update is called once per frame public override void Update() { base.Update(); if (isUpdate) { isUpdate = false; ResponseBaseDavincicode resBase = JsonUtility.FromJson <ResponseSelectFieldCard>(resString); List <UserGameData> userList = resBase.userList; List <Card> fieldCardList = resBase.fieldCardList; userListPanel.setData(resBase.userList, resBase.turnUserIndex); selectableCard.setData(fieldCardList, false); switch (resBase.identifier) { case DavinciCommon.IDENTIFIER_GAME_FINISH: { Debug.Log("finish game"); } break; case DavinciCommon.IDENTIFIER_SELECT_FIELD_CARD: { //ResponseSelectFieldCard res = JsonUtility.FromJson<ResponseSelectFieldCard>(resString); if (resBase.isSuccess() == false) { selectableCard.reload(); showAlert(resBase.identifier, resBase.message, false, false, (AlertData data, bool isOn, string fieldText) => { }); } else { //selectableCard.updateData(res.fieldCardList, res.isSuccess(), selectableCard.gameObject.activeSelf); userListPanel.reload(); if (isInit) { UserGameData player = resBase.userList[resBase.turnUserIndex]; if (player.email.Equals(UserManager.Instance().email)) { IndicatorManager.Instance().hide(); selectableCard.setData(fieldCardList, true); } else { if (player.userType == (int)Common.USER_TYPE.COMPUTER) { if (isMaster) { //autoSelectUserCard(resBase.userList, resBase.fieldCardList, player); StartCoroutine(waitAttack(resBase.userList, resBase.fieldCardList, player)); } } } } else { IndicatorManager.Instance().hide(); selectableCard.setData(fieldCardList, true); } } } break; case DavinciCommon.IDENTIFIER_SELECT_USER_CARD: { } break; case DavinciCommon.IDENTIFIER_TURN: { if (isInit == false) { isInit = true; userListPanel.reload(); } //ResponseTurn res = JsonUtility.FromJson<ResponseTurn>(resString); UserGameData player = resBase.userList[resBase.turnUserIndex]; IndicatorManager.Instance().hide(); userListPanel.attackGuide.gameObject.SetActive(false); turnMessage.gameObject.SetActive(true); turnMessage.show(() => { userListPanel.setTrun(resBase.turnUserIndex); if (player.email.Equals(UserManager.Instance().email)) { IndicatorManager.Instance().hide(); if (resBase.fieldCardList.Count > 0) { selectableCard.show(1); } else { userListPanel.attackGuide.gameObject.SetActive(true); } } else { IndicatorManager.Instance().show(player.nickName + " 님의 턴입니다."); //showTurnMsg(player.nickName); if (player.userType == (int)Common.USER_TYPE.COMPUTER) { if (isMaster) { //autoSelectFieldCard(resBase.fieldCardList, player); if (resBase.fieldCardList.Count > 0) { StartCoroutine(waitSelectFieldCard(resBase.fieldCardList, player)); } else { StartCoroutine(waitAttack(resBase.userList, resBase.fieldCardList, player)); } } } } }); } break; case DavinciCommon.IDENTIFIER_ATTACK: { ResponseAttack res = JsonUtility.FromJson <ResponseAttack>(resString); UserGameData player = res.userList[res.turnUserIndex]; if (res.isSuccess() == false) { if (player.email.Equals(UserManager.Instance().email)) { showAlert(resBase.identifier, res.message, false, false, (AlertData data, bool isOn, string fieldText) => { }); } } else { userListPanel.attack(res.selectUser, res.selectIndex, res.attackValue, (bool isSuccess) => { Debug.Log("attack result : " + isSuccess); if (isSuccess) { userListPanel.reload(); userListPanel.checkLose(res.selectUser); if (player.email.Equals(UserManager.Instance().email)) { showAlert("select", "공격을 계속 하시겠습니까?", true, false, (AlertData data, bool isOn, string fieldText) => { if (!isOn) { RequestNext req = new RequestNext(roomNo); SocketManager.Instance().sendMessage(req); } else { userListPanel.attackGuide.gameObject.SetActive(false); } }); } else { if (player.userType == (int)Common.USER_TYPE.COMPUTER) { if (isMaster) { if (rm.Next(3) > 2) { RequestNext req = new RequestNext(roomNo); SocketManager.Instance().sendMessage(req); } else { StartCoroutine(waitAttack(resBase.userList, resBase.fieldCardList, player)); } } } } } else { userListPanel.attackGuide.gameObject.SetActive(false); userListPanel.openCard(res.turnUserIndex, res.openIndex, () => { RequestNext req = new RequestNext(roomNo); SocketManager.Instance().sendMessage(req); }); } }); } } break; } } if (IndicatorManager.Instance().isShow&& IndicatorManager.Instance().gameObject.activeSelf == false) { IndicatorManager.Instance().gameObject.SetActive(true); } }
public void startGenerateMoney(UserGameData gameData) { isSetGenerateMoney = true; StartCoroutine(generateMoney(gameData)); StartCoroutine(setMoneyGenerationDiff(gameData)); }
//// 유니티광고를 보여주는 method. //public void ShowUnityAds() //{ // if (Advertisement.IsReady()) // { // var options = new ShowOptions { resultCallback = HandleEndGameShowAds }; // Advertisement.Show("video", options); // } //} //// unity-ads Show Result Call back //private void HandleEndGameShowAds(ShowResult result) //{ // switch (result) // { // case ShowResult.Finished: // //Debug.Log("The ad was successfully shown."); // Application.Quit(); // break; // case ShowResult.Skipped: // //Debug.Log("The ad was skipped before reaching the end."); // Application.Quit(); // break; // case ShowResult.Failed: // //Debug.LogError("The ad failed to be shown."); // Application.Quit(); // break; // } //} public void OpenGameOver() { col_joyStick.enabled = false; col_jump.enabled = false; col_menuPop.enabled = false; gameTimer.SetGameTimeState(GameTimer.GAME_TIME_STATE.TIME_END); //for windows and editor save&load commands. if((Application.platform == RuntimePlatform.WindowsPlayer) || (Application.platform == RuntimePlatform.WindowsEditor)) { userDataProcess = new UserDataProcess(); userDataProcess.InitData(); // 먼저 기존에 존재하는 시간기록을 가져온다. userDataProcess.LoadUserDataForWindows(); userGameData = userDataProcess.GetUserGameRecord(); lbl_lastRecord.text = userGameData.GetGameTime().ToStringType(); // 현재 기록한 시간을 저장한다. userGameData.SetGameTime(gameTimer.GetGameTimeInfo()); userDataProcess.SaveUserDataForWindows(userGameData); } else if(Application.platform == RuntimePlatform.Android) { string timeRecord = PlayerPrefs.GetString("PlayerTimeRecord"); if (timeRecord == "") lbl_lastRecord.text = "00:00:00"; else lbl_lastRecord.text = timeRecord; PlayerPrefs.SetString("PlayerTimeRecord", gameTimer.GetGameTimeString()); } // 현재 기록한 시간을 UI에 보여준다. lbl_curRecord.text = gameTimer.GetGameTimeString(); gameOverObj.SetActive(true); spr_gameOverBg.alpha = 0.7f; isFlickering = true; StartCoroutine(FlickeringSprite(spr_home)); StartCoroutine(FlickeringSprite(spr_ReStart)); }
bool isMyData(UserGameData data) { return(data.email.Equals(UserManager.Instance().email)); }
//RequestAttack autoAttack(List<UserGameData> userList, List<Card> filedCards, UserGameData player, UserGameData selectUser, int index) //{ // RequestAttack req = new RequestAttack(roomNo, selectUser.email, index, autoIndex); // return req; // //SocketManager.Instance().sendMessage(req); //} IEnumerator waitAttack(List <UserGameData> userList, List <Card> filedCards, UserGameData player) { yield return(new WaitForSeconds(1)); autoAttack(userList, filedCards, player); }
IEnumerator waitSelectFieldCard(List <Card> fieldList, UserGameData user) { yield return(new WaitForSeconds(2)); autoSelect(fieldList, user); }