角色升级模拟VBA(转给想学VBA的数值新人,带附件)

发表于2016-07-03
评论4 1.05w浏览
  笔者最近抽空写了一个简单的RPG游戏的升级经验模型。主要包含主线任务、日常任务,其他经验产出渠道可自行补充,这里只分享一个模型思路,抛砖引玉,欢迎大家讨论。
  excel中还包含一个升级模拟工具,该工具主要作用是,当频繁调整升级经验时(项目早期),能快速的看到各个经验卡点的变化(主线任务经验不足,需要做日常任务、刷副本等)的情况。实际上如果模型搭建合理,这个验算工具基本没什么卵用。

     excel中的数值笔者已做过特殊处理,仅供测试模型用,不建议直接使用:)。

     欢迎有兴趣的朋友一起讨论
  QQ:1437900504 唐僧
      Q群:564663199



  以下是相关的VBA代码:
  1. Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

  2. Sub 升级行为模拟器2()
  3. '模拟器只规划玩家行为,统计经验在表格中。
  4. '定义变量----------------------------------------------
  5. action_type = 0 '确定行为类型
  6. task_zhuxian = "主线"
  7. task_richang = "日常"
  8. task_richang_huan_max = 20 '日常任务最大环数
  9. task_richang_huan_finished = 0

  10. guaji = "挂机"
  11. guaji_time_max = 60 * 8 '每日挂机时间
  12. guaji_time = 0
  13.     
  14. '初始化数据-------------------------------------------------------------------------------
  15.         
  16.     sheetname = "升级模拟器2.0"
  17.     playerlv = 1 '玩家初始等级
  18.     playerlv_max = 150 '设定玩家等级上限
  19.     action_row = 18 '开始写入行为相关内容的行-------------------
  20.     
  21.     action_column = "L"
  22. '清空行为区域-------------------------------------------------------------------------------
  23.   
  24.     rangevalue = "L" & action_row & ":L10000" '清空行为区域的范围
  25.     Sheets(sheetname).Select
  26.     Range(rangevalue).Select
  27.     Selection.ClearContents
  28. '开始循环======================================================================================================================

  29.     For action_row = 18 To 4000
  30.     
  31.         Cells(action_row, 1).Select
  32.         Debug.Print action_row
  33.         
  34.         playerlv = Sheets(sheetname).Cells(action_row, "B") '获取上一次行为后玩家等级
  35.         playerlv_lastture = Sheets(sheetname).Cells(action_row - 1, "B")
  36. '主线任务-----------------------------------------------------------------------------
  37.         If playerlv = 1 Then
  38.         
  39.             action_type = task_zhuxian
  40.             Sheets(sheetname).Cells(action_row, action_column).Value = action_type & "Lv." & playerlv '写入行为类型
  41.             Debug.Print action_type & "Lv." & playerlv
  42.             GoTo nextfor '跳下一循环
  43.         
  44.         ElseIf playerlv > playerlv_lastture Then '判断是否升级了,如果升级则做主线,并退出当前循环------------------------------------
  45.         
  46.             action_type = task_zhuxian
  47.             Sheets(sheetname).Cells(action_row, action_column).Value = action_type & "Lv." & playerlv '写入行为类型
  48.             
  49.             Debug.Print action_type & "Lv." & playerlv
  50.             GoTo nextfor '跳下一循环
  51.         
  52.         End If
  53.         
  54.         
  55.         
  56. '日常任务--------------------------------------------------------------------------
  57.         
  58.         If task_richang_huan_finished < task_richang_huan_max Then '如果日常任务还有剩余,则做日常任务,直到升级或做完。

  59.                 action_type = task_richang
  60.                 task_richang_huan_finished = task_richang_huan_finished + 1
  61.                 Sheets(sheetname).Cells(action_row, action_column).Value = action_type & "(" & task_richang_huan_finished & "/" & task_richang_huan_max & ")"  '写入行为类型
  62.                 
  63.                 
  64.                 Debug.Print action_type & "(" & task_richang_huan_finished & "/" & task_richang_huan_max & ")"
  65.                 GoTo nextfor '跳下一循环
  66.             
  67.         End If
  68.         'Debug.Print "日常任务已全部完成!!!";


  69. '挂机--------------------------------------------------------------------------------
  70. guijia:
  71.         
  72.         If guaji_time < guaji_time_max Then '如果挂机可已做,则做,直到升级或做完

  73.                 action_type = guaji
  74.                 guaji_time = guaji_time + 60
  75.                 Sheets(sheetname).Cells(action_row, action_column).Value = action_type & "(小时:" & guaji_time / 60 & "/" & guaji_time_max / 60 & ")" '写入行为类型
  76.                 
  77.                 
  78.                 Debug.Print action_type & "(" & guaji_time / 60 & "/" & guaji_time_max / 60 & ")"
  79.                 GoTo nextfor '跳下一循环

  80.         End If
  81.         'Debug.Print "挂机已全部完成!!!";
  82.         
  83.         
  84. '离线&重置次数--------------------------------------------------------------------------------
  85. lixian:
  86.     
  87.         action_type = lixian
  88.                 
  89.         lixian_time = 60 * 24 - guaji_time
  90.         Sheets(sheetname).Cells(action_row, action_column).Value = action_type & "(小时:" & lixian_time / 60 & ")" '写入行为类型
  91.         
  92.         '重置次数和时间
  93.         task_richang_huan_finished = 0
  94.         task_bangpai_huan_finished = 0
  95.         juqingfuben_finished = 0
  96.         'shouweinvshen_finished = 0
  97.         shouweinvshen_saodang_finished = 0
  98.         'tongtianta_finished = 0
  99.         tongtianta_saodang_finished = 0
  100.         danaotiangong_finished = 0
  101.         zuduifuben_finished = 0
  102.         yabiao_finished = 0
  103.         shuilufahui_finished = 0
  104.         guaji_time = 0



  105. '等级最大时---------------------------------------------------------------------------------
  106.         
  107.         If playerlv = playerlv_max Then
  108.             Exit For
  109.         End If

  110. nextfor: '跳下一循环---------------------------------------------------------------------------

  111.     Next
  112.     
  113.     Sheets("模拟2数据分析").EnableCalculation = True '开启分析表的自动运算
  114.     
  115. End Sub
复制代码

附件下载地址:
http://bbs.gameres.com/forum.php?mod=attachment&aid=MzQyNTA5fDIyZmE1ZTNmfDE0Njc4NzExNDB8MTk0MTQ1fDY2ODM2Mg%3D%3D

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引