back_recharge
mashiyu 2019-03-22 15:00:06 +08:00
parent 6c70934842
commit 1793ddffd9
7 changed files with 111 additions and 53 deletions

View File

@ -25,14 +25,62 @@ local Random = Random
local _fightData
local _optionData
function PrintTable(tb)
local function newPairs(tbl, func)
if func == nil then
return pairs(tbl)
end
local ary = {}
local lastUsed = 0
for key --[[, val--]] in pairs(tbl) do
if (lastUsed == 0) then
ary[1] = key
else
local done = false
for j=1,lastUsed do -- 进行插入排序
if (func(key, ary[j]) == true) then
arrayInsert( ary, key, j )
done = true
break
end
end
if (done == false) then
ary[lastUsed + 1] = key
end
end
lastUsed = lastUsed + 1
end
-- 定义并返回迭代器
local i = 0
local iter = function ()
i = i + 1
if ary[i] == nil then
return nil
else
return ary[i], tbl[ary[i]]
end
end
return iter
end
local function PrintTable(tb)
local indent_str = "{"
for k,v in pairs(tb) do
indent_str = string.format("%s%s=%s", indent_str,
type(k) == "number" and string.format("[%d]",k) or tostring(k),
type(v) == "table" and "" or tostring(v)..",")
for k=1, #tb do
local v = tb[k]
if type(v) == "table" then
indent_str = indent_str .. PrintTable(v)
else
indent_str = indent_str .. tostring(v)..","
end
end
for k,v in newPairs(tb) do
if type(k) ~= "number" then
if type(v) == "table" then
indent_str = string.format("%s%s=%s", indent_str, tostring(k), PrintTable(v))
else
indent_str = string.format("%s%s=%s", indent_str, tostring(k), tostring(v)..",")
end
end
end
indent_str = indent_str .. "},"
@ -48,17 +96,34 @@ local function error( err )
os.date("%H"),
os.date("%M"),
os.date("%S"))
local file = io.open("LogError/"..time..".txt", "a")
file:write("fightData:\n"..PrintTable(_fightData).."\n")
file:write("optionData:\n"..PrintTable(_optionData).."\n")
local file = io.open("luafight/LogError/"..time..".txt", "a")
--file:write("fightData:\n"..PrintTable(_fightData).."\n")
--file:write("optionData:\n"..PrintTable(_optionData).."\n")
file:write("error:\n"..debug.traceback(err).."\n")
io.close(file)
end
local function generateRecordFile()
local time = string.format("%d-%d-%d-%d-%d-%d",
os.date("%Y"),
os.date("%m"),
os.date("%d"),
os.date("%H"),
os.date("%M"),
os.date("%S"))
local file = io.open("luafight/BattleRecord/"..time..".txt", "a")
local record = BattleLogic.GetRecord()
for i=1, #record do
file:write(record[i].."\n")
end
io.close(file)
end
function BattleMain.Execute(seed, fightData, optionData)
_fightData = fightData
_optionData = optionData
print(PrintTable(fightData))
--该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步
BattleLogic.IsOpenBattleRecord = false
@ -86,18 +151,21 @@ function BattleMain.Execute(seed, fightData, optionData)
resultList.result = BattleLogic.Result
if BattleLogic.IsOpenBattleRecord then
BattleLogic.GenerateRecordFile()
generateRecordFile()
end
-- print -----------------------------------------
--for i=1, #resultList do
-- print("hp:"..resultList[i])
--end
--print("最终运行帧数:"..BattleLogic.CurFrame())
--print("result:"..BattleLogic.Result)
for i=1, #resultList do
print("hp:"..resultList[i])
end
print("最终运行帧数:"..BattleLogic.CurFrame())
print("result:"..BattleLogic.Result)
return resultList
end
return { result = -1 }
end
--BattleMain.Execute(1553167956, {enemyData={{{passivity={},skill={0,{20011,0.7,{1,1,1,},{3,0.3,1,3,},},},roleId=5,property={0,772,772,260,61,61,80,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,2,2,},type=2,professionId=0,quality=1,camp=1,},{passivity={},skill={0,{20011,0.7,{1,0.8,1,},{13,1,0.1,2,5,},},},roleId=3,property={0,772,772,260,61,61,240,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},type=2,professionId=0,quality=1,camp=1,},{passivity={},skill={0,{20011,0.7,{1,0.8,1,},{13,1,0.1,2,5,},},},roleId=3,property={0,772,772,260,61,61,7,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},type=2,professionId=0,quality=1,camp=1,},teamSkill={},},},playerData={{passivity={},superSkill={1.6,{20211,0.7,{1,3.3,2,},{15,1.98,2,1.98,},},},skill={0,{40001,0.7,{1,2.3,2,},},{30011,0.7,{4,9,0.2,4,1,},{4,10,0.2,4,1,},},},camp=0,roleId=10022,type=1,professionId=3,quality=0,property={1,1676,1678,248,167,200,173,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},},{passivity={},superSkill={3,{20000,0.7,{2,1.06,2,},{3,0.6,1,4,},},},skill={0,{40001,0.7,{11,0.93,2,2,0.2,},},},camp=0,roleId=10008,type=1,professionId=5,quality=0,property={1,2206,2208,221,193,232,130,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},},{passivity={},superSkill={2.5,{20000,0.7,{14,1.55,2,1,10023,0.2,},},},skill={0,{40001,0.7,{1,1.35,2,},},{30011,0.7,{3,0,0,5,},},},camp=0,roleId=10023,type=1,professionId=4,quality=0,property={1,1439,1441,284,131,157,168,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},},{passivity={},superSkill={2.3,{20312,0.7,{19,1.35,1,0.5,5,},},},skill={0,{40001,0.7,{1,1,1,},},{30011,0.7,{4,9,0.1,5,1,},{4,10,0.1,5,1,},},},camp=0,roleId=10013,type=1,professionId=1,quality=0,property={1,1678,1680,246,194,162,163,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},},{passivity={},superSkill={1.6,{20211,0.7,{1,3.3,2,},{15,1.98,2,1.98,},},},skill={0,{40001,0.7,{1,2.3,2,},},{30011,0.7,{4,9,0.2,4,1,},{4,10,0.2,4,1,},},},camp=0,roleId=10022,type=1,professionId=3,quality=0,property={1,1676,1678,248,167,200,173,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},},teamSkill={{3,{20012,0.7,{26,600,},{27,100,4,},},{10014,0.7,{25,2,0.1,4,},},},},},})
BattleMain.Execute(1553167956, {playerData={{professionId=4,passivity={},type=1,skill={0,{40001,0.7,{1,1.35,2,},},{30011,0.7,{3,0,0,5,},},},superSkill={2.5,{20000,0.7,{14,1.55,2,1,10023,0.2,},},},roleId=10023,camp=0,property={1,1439,1441,284,131,157,168,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=3,passivity={},type=1,skill={0,{40001,0.7,{1,2.3,2,},},{30011,0.7,{4,9,0.2,4,1,},{4,9,0.2,4,1,},},},superSkill={1.6,{20211,0.7,{1,3.3,2,},{15,1.98,2,1.98,},},},roleId=10022,camp=0,property={1,1676,1678,248,167,200,173,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=2,passivity={},type=1,skill={0,{40001,0.7,{1,1.05,2,},{4,4,5,5,3,},},},superSkill={2.3,{20000,0.7,{2,1.89,2,},},{20012,0.7,{3,1,5,5,},},},roleId=10021,camp=0,property={1,1920,1922,209,170,204,178,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=5,passivity={},type=1,skill={0,{40001,0.7,{11,0.93,2,2,0.2,},},},superSkill={3,{20000,0.7,{2,1.06,2,},{3,0.6,1,4,},},},roleId=10008,camp=0,property={1,2206,2208,221,193,232,130,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=1,passivity={},type=1,skill={0,{40001,0.7,{1,1,1,},},{30011,0.7,{4,9,0.1,5,1,},{4,9,0.1,5,1,},},},superSkill={2.3,{20312,0.7,{19,1.35,1,0.5,5,},},},roleId=10013,camp=0,property={1,1678,1680,246,194,162,163,0,0,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},teamSkill={{3,{20012,0.7,{26,600,},{27,100,4,},},{10014,0.7,{25,2,0.1,4,},},},},},enemyData={{{professionId=0,passivity={},type=2,skill={0,{20011,0.7,{1,1,1,},{3,0.3,1,3,},},},superSkill={},roleId=14,camp=1,property={0,772,772,260,61,61,80,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,2,2,},quality=1,},{professionId=0,passivity={},type=2,skill={0,{20013,0.7,{1,0.45,1,},},},superSkill={},roleId=1,camp=1,property={0,483,483,260,61,61,240,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},{professionId=0,passivity={},type=2,skill={0,{20013,0.7,{1,0.45,1,},},},superSkill={},roleId=3,camp=1,property={0,483,483,260,61,61,7,0,0,0.3,0.3,0.2,1.5,1,0,0,0,0,0,0,0,0,0,0,0,0,},quality=1,},teamSkill={},},},})
return BattleMain

View File

@ -42,30 +42,18 @@ function Buff.Create(caster, type, duration, ...)
return buff
end
local queuePool = BattleObjectPool.New(function ()
return BattleQueue.New()
end)
local dicPool = BattleObjectPool.New(function ()
return BattleDictionary.New()
end)
BuffManager = {}
BuffManager.__index = BuffManager
function BuffManager.New()
local instance = {owner=0, buffQueue = queuePool:Get(), buffList = dicPool:Get()}
local instance = {owner=0, buffQueue = BattleQueue.New(), buffList = BattleDictionary.New()}
setmetatable(instance, BuffManager)
return instance
end
function BuffManager:Init(owner)
self.owner = owner
end
function BuffManager:Dispose(owner)
self.buffQueue:Clear()
self.buffList:Clear()
queuePool:Put(self.buffQueue)
dicPool:Put(self.buffList)
self.owner = owner
end

View File

@ -486,6 +486,24 @@ local effectList = {
target:AddBuff(Buff.Create(caster, BuffName.DOT, d2, 1, 0, d1, 1))
end)
end,
--造成[a]%的[b]伤害,对[c]造成额外[d]%伤害
--a[float],b[伤害类型,]c[持续伤害状态],d[float]
[28] = function(caster, target, args, interval)
local f1 = args[1]
local dt = args[2]
local dot = args[3]
local f2 = args[4]
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, interval)
if caster.camp == 0 and target.camp == 1 then
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, target, interval)
end
BattleLogic.WaitForTrigger(interval, function ()
if target.BuffMgr:HasBuff(BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
f1 = f1 + f2
end
BattleUtil.CalDamage(caster, target, dt, f1)
end)
end,
}
return effectList

View File

@ -1,10 +1,10 @@
BattleLogic = {}
local floor = math.floor
local min = math.min
local max = math.min
local objList = BattleDictionary.New()
local skillList
local curUid
local curBuffId
local curFrame
@ -74,8 +74,6 @@ function BattleLogic.Init(data, optionData)
BattleLogic.Clear()
skillList = {}
curUid = 0
curBuffId = 0
curFrame = 0
@ -147,9 +145,9 @@ end
function BattleLogic.AddMP(camp, mp)
if camp == 0 then
playerMP = math.min(playerMP + mp, 100)
playerMP = min(playerMP + mp, 100)
else
enemyMP = math.min(playerMP + mp, 100)
enemyMP = min(playerMP + mp, 100)
end
end
@ -190,7 +188,7 @@ function BattleLogic.SetAggro(role, duration)
if playerAggroChangable then
playerAggro = role
if enemySkillUsable then
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, role, math.max(duration/2, 0.3))
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, role, max(duration/2, 0.3))
end
playerAggroChangable = false
BattleLogic.WaitForTrigger(duration-BattleLogic.GameDeltaTime, function () --减去一帧避免卡点

View File

@ -11,19 +11,10 @@ local Passivity = require("Modules/Battle/Logic/Base/Passivity")
local skillPool = BattleObjectPool.New(function ()
return Skill:New()
end)
local buffPool = BattleObjectPool.New(function ()
return BuffManager.New()
end)
local eventPool = BattleObjectPool.New(function ()
return BattleEvent:New()
end)
local dataPool = BattleObjectPool.New(function ()
return RoleData.New()
end)
function RoleLogic.New()
local instance = {uid=0,roleData=0,data=0,camp=0,name=0,roleType=0,shield=BattleList.New(),exCalDmgList=BattleList.New(),
BuffMgr=0,Event=0,passiveList=0,isDead=false,Auto=false,IsDebug=false,enable=false}
local instance = {uid=0,roleData=0,data=RoleData.New(),camp=0,name=0,roleType=0,shield=BattleList.New(),exCalDmgList=BattleList.New(),
BuffMgr=BuffManager.New(),Event=BattleEvent:New(),passiveList=0,isDead=false,Auto=false,IsDebug=false,enable=false}
setmetatable(instance, RoleLogic)
return instance
end
@ -32,7 +23,6 @@ function RoleLogic:Init(uid, data)
self.uid = uid
self.roleData = data
self.data = dataPool:Get()
self.data:Init(self, data.property)
self.camp = data.camp --阵营 0我方 1敌方
@ -42,10 +32,7 @@ function RoleLogic:Init(uid, data)
self.shield:Clear() --护盾列表
self.exCalDmgList:Clear() --额外计算伤害列表
self.BuffMgr = buffPool:Get()
self.BuffMgr:Init(self)
self.Event = eventPool:Get()
self.Event:ClearEvent()
self.passiveList = {}
@ -84,9 +71,6 @@ function RoleLogic:AddBuff(buff)
end
function RoleLogic:Dispose()
eventPool:Put(self.Event)
dataPool:Put(self.data)
buffPool:Put(self.BuffMgr)
if self.skill then
self.skill:Dispose()
skillPool:Put(self.skill)

View File

@ -132,7 +132,8 @@ public class BehaviorUtil {
fightData.addAllMonsterList(monsterGroupList);
//设置战斗随机种子
int seed = (int)(System.currentTimeMillis()/1000);
// int seed = (int)(System.currentTimeMillis()/1000);
int seed = 1553167956;
fightData.setFightSeed(seed);
fightStartRespons.setFightData(fightData);

View File

@ -68,6 +68,7 @@ public class CheckFight {
/**
* 线50ms100线
* http://www.luaj.org/luaj/3.0/examples/jse/SampleMultiThreaded.java
* @param seed
* @param fightData
* @param optionData