public void OnClickGuestLogin() { var duid = SystemInfo.deviceUniqueIdentifier; string name = inputText.text; if (!string.IsNullOrEmpty(name)) { IPlayer player = new IPlayer(); player.guid = duid; player.Level = 1; player.exp = 0; player.profileName = name; player.TowerAbsLevel = 1; player.TowerCurrentLevel = 1; IPlayer.InsertNewPlayer(player); IPlayerStamina iPlayerStamina = new IPlayerStamina(1, duid, duid, 1, 1, duid); IPlayerStamina.SetData(iPlayerStamina); IPlayerStamina.UpdataDataMap(); RPGSceneManager.LoadScene(RPGSceneManager.ManagerScene); } else { Debug.LogError("名字不可以为空"); } }
public IPlayerStamina GetStamina(string playerId, string dataId) { IPlayerStamina stamina = null; if (!IPlayerStamina.DataMap.ContainsKey(IPlayerStamina.GetId(playerId, dataId))) { stamina = new IPlayerStamina(); stamina.Guid = IPlayerStamina.GetId(playerId, dataId); stamina.playerId = playerId; stamina.Guid = IPlayerStamina.GetId(playerId, dataId); stamina.dataId = dataId; IPlayerStamina.DataMap.Add(IPlayerStamina.GetId(playerId, dataId), stamina); return(stamina); //GameInstance.dbDataUtils.ExecuteNonQuery(@"INSERT INTO playerStamina (id, playerId, Guid, amount, recoveredTime) VALUES (@id, @playerId, @Guid, @amount, @recoveredTime)", // new SqliteParameter("@id", stamina.Id), // new SqliteParameter("@playerId", stamina.PlayerId), // new SqliteParameter("@Guid", stamina.DataId), // new SqliteParameter("@amount", stamina.Amount), // new SqliteParameter("@recoveredTime", stamina.RecoveredTime)); } else { return(IPlayerStamina.DataMap[PlayerStamina.GetId(playerId, dataId)]); } //var staminas = GameInstance.dbDataUtils.ExecuteReader(@"SELECT * FROM playerStamina WHERE playerId=@playerId AND Guid=@Guid LIMIT 1", // new SqliteParameter("@playerId", playerId), // new SqliteParameter("@Guid", dataId)); //if (!staminas.Read()) //{ // stamina = new PlayerStamina(); // stamina.Id = PlayerStamina.GetId(playerId, dataId); // stamina.PlayerId = playerId; // stamina.DataId = dataId; // GameInstance.dbDataUtils.ExecuteNonQuery(@"INSERT INTO playerStamina (id, playerId, Guid, amount, recoveredTime) VALUES (@id, @playerId, @Guid, @amount, @recoveredTime)", // new SqliteParameter("@id", stamina.Id), // new SqliteParameter("@playerId", stamina.PlayerId), // new SqliteParameter("@Guid", stamina.DataId), // new SqliteParameter("@amount", stamina.Amount), // new SqliteParameter("@recoveredTime", stamina.RecoveredTime)); //} //else //{ // stamina = new PlayerStamina(); // stamina.Id = staminas.GetString(0); // stamina.PlayerId = staminas.GetString(1); // stamina.DataId = staminas.GetString(2); // stamina.Amount = staminas.GetInt32(3); // stamina.RecoveredTime = staminas.GetInt64(4); //} //return stamina; }
private void UpdatePlayerStamina(IPlayer player, Stamina staminaTable) { var gameDb = GameInstance.GameDatabase; var stamina = GetStamina(player.guid, staminaTable.id); var maxStamina = staminaTable.maxAmountTable.Calculate(player.Level, gameDb.playerMaxLevel); if (stamina.amount < maxStamina) { var currentTimeInMillisecond = System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond; var diffTimeInMillisecond = currentTimeInMillisecond - stamina.recoveredTime; var devideAmount = 1; switch (staminaTable.recoverUnit) { case StaminaUnit.Days: devideAmount = 1000 * 60 * 60 * 24; break; case StaminaUnit.Hours: devideAmount = 1000 * 60 * 60; break; case StaminaUnit.Minutes: devideAmount = 1000 * 60; break; case StaminaUnit.Seconds: devideAmount = 1000; break; } var recoveryAmount = (int)(diffTimeInMillisecond / devideAmount) / staminaTable.recoverDuration; stamina.amount += recoveryAmount; if (stamina.amount > maxStamina) { stamina.amount = maxStamina; } stamina.recoveredTime = currentTimeInMillisecond; IPlayerStamina.DataMap[IPlayerStamina.GetId(player.guid, staminaTable.id)].amount = stamina.amount; IPlayerStamina.DataMap[IPlayerStamina.GetId(player.guid, staminaTable.id)].recoveredTime = stamina.recoveredTime; IPlayerStamina.UpdataDataMap(); //GameInstance.dbDataUtils.ExecuteNonQuery(@"UPDATE playerStamina SET amount=@amount, recoveredTime=@recoveredTime WHERE id=@id", // new SqliteParameter("@amount", stamina.Amount), // new SqliteParameter("@recoveredTime", stamina.RecoveredTime), // new SqliteParameter("@id", stamina.Id)); } }
public void Init() { ConfigSQLite3Operate = SQLite3Factory.OpenToRead("Database.db"); LocalSQLite3Operate = SQLite3Factory.OpenToWrite("Dynamic.db"); CheckTable(); IPlayer.Init(); IPlayerBattle.Init(); ICharacter.Init(); IEquipment.Init(); IPlayerBattle.Init(); IPlayerClearStage.Init(); IPlayerCurrency.Init(); IPlayerFormation.Init(); IPlayerHasCharacters.Init(); IPlayerHasEquips.Init(); IPlayerOtherItem.Init(); IPlayerStamina.Init(); IPlayerUnlockItem.Init(); //IPlayerHasEquips.InsertNewEquips("2001"); //IPlayerHasCharacters.InsertNewCharacter("1001"); }