Esempio n. 1
0
    /// <summary>
    /// 载入数据
    /// </summary>
    public override void loadData()
    {
        // 声明临时变量存放数据
        Data data = new Data();

        DataForPlayer playerdata = new DataForPlayer();

        // 从DataAssets获取数据至playerdata
        Operator.loadData(out data);

        playerdata = (DataForPlayer)data;
        // 同步数据至人物
        #region  步
        TotalHealth        = playerdata.TotalHealth;
        CurrentHealth      = playerdata.CurrentHealth;
        TotalEnergy        = playerdata.TotalEnergy;
        CurrentEnergy      = playerdata.CurrentEnergy;
        TotalHungerValue   = playerdata.TotalHungerValue;
        CurrentHungerValue = playerdata.CurrentHungerValue;
        Coins         = playerdata.Coins;
        ItemReference = playerdata.ItemReference;
        #endregion
        // 清空背包
        Bag.clearItem();
        // 更新背包
        Bag.LoadMode = true;
        foreach (ItemLoadIndex i in playerdata.ItemReference)
        {
            Item item = ItemStock.Instance.getItemByID(i.ID);
            item.setStatus(i.State);
            Bag.addItem(item, i.Count);
        }
        if (playerdata.BuffReference != null)
        {
            foreach (BuffLoadIndex b in playerdata.BuffReference)
            {
                Buff buff = BuffStock.findBuff(b.ID);
                buff.setStatus(b.State);
                BM.addBuff(buff);
            }
        }

        Bag.LoadMode             = false;
        Operator.DataAssets.Path = Application.dataPath + "/Save/" + CharacterName + "Data.txt";
    }
Esempio n. 2
0
 private void Update()
 {
     if (Time.timeScale == 0)
     {
         return;
     }
     // check alive
     #region check alive
     if (Alive == false)
     {
         Locked           = true;
         Rbody2D.velocity = new Vector2(0, Rbody2D.velocity.y);
         if (!IsDead)
         {
             MoveAnim.SetBool("dead", true);
             goToDead(-1f);
         }
     }
     #endregion
     // Hunger
     #region Hunger
     if (TC.Minutes - TimeOnHold >= 1)
     {
         CurrentHungerValue -= HungerCost;
         TimeOnHold          = TC.Minutes;
     }
     if (CurrentHungerValue <= 0)
     {
         CurrentHungerValue = 0;
         if (!BM.containsBuff("Hungry0"))
         {
             BM.addBuff(BuffStock.findBuff("Hungry0"));
         }
     }
     else if (CurrentHungerValue >= TotalHungerValue)
     {
         CurrentHungerValue = TotalHungerValue;
     }
     #endregion
     // go to crouch
     #region go to crouch
     if ((Input.GetKeyDown(KeyCodeList.Instance.Crouch)) && OnGround == true && CurrentState != StateEnum.ATTACK)
     {
         IsCrouching = true;
     }
     else if (Input.GetKeyUp(KeyCodeList.Instance.Crouch) && CurrentState != StateEnum.ATTACK)
     {
         IsCrouching = false;
     }
     if (IsCrouching == true)
     {
         updateState(StateEnum.CROUCH);
     }
     else if (CurrentState == StateEnum.CROUCH)
     {
         finishCrouch();
     }
     #endregion
     // operation
     #region operation
     if (Locked == false && IsRolling == false && IsCrouching == false)
     {
         // go to jump
         #region    go to jump
         if (Input.GetKeyDown(KeyCodeList.Instance.Jump) && CurrentState != StateEnum.ATTACK &&
             IsHealing == false &&
             IsSpeeling == false)
         {
             if (OnGround == true && OnWall == false)
             {
                 IsJumping = true;
                 OnGround  = false;
                 updateState(StateEnum.JUMP, Direction, CurrentSpeed, CurrentJumpForce * (1 + (CurrentSpeed - WalkingSpeed) * 0.1f));
             }
             else if (ExtraJumpCount > 0 && IsSpeeling == false)
             {
                 // extra jump
                 if (CurrentEnergy >= JumpCost)
                 {
                     ExtraJumpCount--;
                     CurrentEnergy   -= JumpCost;
                     Rbody2D.velocity = new Vector2(0, 0);
                     updateState(StateEnum.JUMP, Direction, CurrentSpeed, CurrentJumpForce * ExtraJumpMultiple);
                 }
             }
         }
         #endregion
         // jump higher
         #region  jump higher
         if (Input.GetKey(KeyCodeList.Instance.Jump) && IsJumping == true)
         {
             if (CurrentJumpDuration > 0)
             {
                 Rbody2D.velocity    += Vector2.up * CurrentJumpForce * DeltaJumpForcePercent;
                 CurrentJumpDuration -= Time.deltaTime;
             }
             else
             {
                 IsJumping = false;
             }
         }
         if (Input.GetKeyUp(KeyCodeList.Instance.Jump))
         {
             IsJumping = false;
         }
         #endregion
         // go to attack
         #region  go to attack
         if (ChainsDuration > 0)
         {
             ChainsDuration -= Time.deltaTime;
         }
         else
         {
             ChainsDuration = 0;
             AttackNum      = 0;
         }
         if (CurrentCoolDown < CoolDown)
         {
             // 更新冷却
             CurrentCoolDown += Time.deltaTime;
         }
         if (CurrentCoolDown >= CoolDown && !IsRolling && !IsHealing)
         {
             if (Input.GetKeyDown(KeyCodeList.Instance.Attack) && OnGround == true)
             {
                 if (IsDashing)
                 {
                     finishDash();
                 }
                 // 重置冷却时间
                 CurrentCoolDown = 0;
                 if (ChainsDuration > 0)
                 {
                     // 连续攻击
                     if (AttackNum < MaxAttackNum)
                     {
                         AttackNum++;
                         ChainsDuration = MaxChainsDuration;
                     }
                     else
                     {
                         AttackNum      = 0;
                         ChainsDuration = MaxChainsDuration;
                     }
                 }
                 else
                 {
                     // 超时,重置
                     AttackNum      = 0;
                     ChainsDuration = MaxChainsDuration;
                 }
                 updateState(StateEnum.ATTACK, Direction, CurrentSpeed, CurrentJumpForce, true, AttackEnum.NORMAL_ATTACK);
                 Skill = AttackEnum.NORMAL_ATTACK;
             }
             if (Input.GetKeyDown(KeyCodeList.Instance.Attack) && OnGround == false && !IsSpeeling)
             {
                 // 重置冷却时间
                 CurrentCoolDown = 0;
                 updateState(StateEnum.ATTACK, Direction, CurrentSpeed, CurrentJumpForce, true, AttackEnum.JUMP_ATTACK);
                 Skill = AttackEnum.JUMP_ATTACK;
             }
             if (Input.GetKeyDown(KeyCodeList.Instance.Attack) && OnWall == true)
             {
                 // 重置冷却时间
                 CurrentCoolDown = 0;
                 updateState(StateEnum.ATTACK, Direction, CurrentSpeed, CurrentJumpForce, true, AttackEnum.SPEEL_ATTACK);
                 Skill = AttackEnum.SPEEL_ATTACK;
             }
         }
         #endregion
         //roll
         #region roll
         if (/*CurrentState != StateEnum.ATTACK && */ !IsRolling && !IsHealing &&
             checkGround() && CurrentEnergy >= RollingCost &&
             Input.GetKeyDown(KeyCodeList.Instance.Roll))
         {
             if (IsDashing)
             {
                 finishDash();
             }
             else
             {
                 CurrentEnergy -= RollingCost;
             }
             IsRolling = true;
             if (CurrentState == StateEnum.ATTACK)
             {
                 finishAttack(Skill);
             }
             MoveAnim.SetBool("roll", true);
             ChainsDuration = MaxChainsDuration;
         }
         #endregion
         // dash
         #region dash
         if (IsRunning && Input.GetKey(KeyCodeList.Instance.Dash) && checkGround() && !IsHealing)
         {
             if (CurrentEnergy > 0)
             {
                 IsDashing      = true;
                 CurrentEnergy -= Time.deltaTime * DashingCost;
             }
             else
             {
                 finishDash();
             }
         }
         else
         {
             finishDash();
         }
         #endregion
     }
     #endregion
     // cure energy
     #region cure energy
     if (!IsDashing && !IsRolling && !(IsRunning && OnGround) && !(IsJumping && ExtraJumpCount < MaxExtraJumpCount))
     {
         CurrentEnergy += Time.deltaTime * EnergyCure;
         if (CurrentEnergy > TotalEnergy)
         {
             CurrentEnergy = TotalEnergy;
         }
         else if (CurrentEnergy < 0)
         {
             CurrentEnergy = 0;
         }
     }
     #endregion
     // cure shield
     #region cure shield
     if (CurrentShieldValue < 0)
     {
         CurrentShieldValue = 0;
     }
     else if (CurrentShieldValue < TotalShieldValue)
     {
         CurrentShieldValue += Time.deltaTime * ShieldCure;
     }
     else if (CurrentShieldValue > TotalShieldValue)
     {
         CurrentShieldValue = TotalShieldValue;
     }
     #endregion
 }