Esempio n. 1
0
    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("名字不可以为空");
        }
    }
Esempio n. 2
0
    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));
        }
    }