战斗同步

back_recharge
zhangshanxue 2020-06-19 02:19:55 +08:00
parent c61fb855a4
commit 3cbf610c92
2 changed files with 148 additions and 11 deletions

View File

@ -0,0 +1,133 @@
BattleLogManager = {}
local this = BattleLogManager
local isLog = true
local function pairsByKeys(t)
local a = {}
for n in pairs(t) do
if n then
a[#a+1] = n
end
end
table.sort(a, function( op1, op2 )
local type1, type2 = type(op1), type(op2)
local num1, num2 = tonumber(op1), tonumber(op2)
if ( num1 ~= nil) and (num2 ~= nil) then
return num1 < num2
elseif type1 ~= type2 then
return type1 < type2
elseif type1 == "string" then
return op1 < op2
elseif type1 == "boolean" then
return op1
-- 以上处理: number, string, boolean
else -- 处理剩下的: function, table, thread, userdata
return tostring(op1) < tostring(op2) -- tostring后比较字符串
end
end)
local i = 0
return function()
i = i + 1
return a[i], t[a[i]]
end
end
function this.PrintBattleTable(tb)
local indent_str = "{"
local count = 0
for k,v in pairs(tb) do
count = count + 1
end
for k=1, #tb do
local v = tb[k]
if type(v) == "table" then
indent_str = indent_str .. this.PrintBattleTable(v)
elseif type(v) == "string" then
indent_str = indent_str .. "\""..tostring(v) .. "\""
else
indent_str = indent_str .. tostring(v)
end
if k < count then
indent_str = indent_str..","
end
end
local index = 0
for k,v in pairsByKeys(tb) do
index = index + 1
if type(k) ~= "number" then
if type(v) == "table" then
indent_str = string.format("%s%s=%s", indent_str, tostring(k), this.PrintBattleTable(v))
elseif type(v) == "string" then
indent_str = string.format("%s%s=\"%s\"", indent_str, tostring(k), tostring(v))
else
indent_str = string.format("%s%s=%s", indent_str, tostring(k), tostring(v))
end
if index < count then
indent_str = indent_str .. ","
end
end
end
indent_str = indent_str .. "}"
return indent_str
end
--
function this.Init(fightdata)
this.timestamp = Random.GetSeed()
this.fightdata = fightdata
this.logList = {}
end
function this.Log(...)
if not isLog then return end
local args = {...}
local log = args[1] .. ":\n"
log = log .. string.format("%s = %s, ", "frame", BattleLogic.CurFrame())
for i = 2, #args, 2 do
local key = args[i]
local value = args[i + 1]
log = log .. string.format("%s = %s, ", key, value)
end
table.insert(this.logList, log)
end
function this.WriteFile()
if not isLog then return end
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
local platform
-- linux
if not file then
file = io.open("../luafight/BattleRecord/log-"..time..".txt", "a")
platform = "Linux"
end
-- local window server
if not file then
file = io.open("luafight/BattleRecord/log-"..time..".txt", "a")
platform = "Local Windows Server"
end
-- local
if not file then
file = io.open("BattleRecord/log-"..time..".txt", "a")
platform = "Local"
end
file:write(platform..":\n\n\n")
for i = 1, #this.logList do
file:write(this.logList[i].."\n")
end
file:write("\n\n\n\n\n")
file:write("fightData:\n")
file:write(this.PrintBattleTable(this.fightdata))
file:write("\n\n")
file:write("timeStamp: " .. this.timestamp)
io.close(file)
end
return BattleLogManager

View File

@ -6,6 +6,7 @@ import com.ljsd.jieling.config.clazzStaticCfg.MapStaticConfig;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.core.VipPrivilegeType;
import com.ljsd.jieling.dataReport.reportBeans_37.Repot37EventUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.globals.Global;
@ -160,7 +161,7 @@ public class ItemUtil {
private static void combineRewardDropGroup(User user, int[] dropGroupIds, float dropRatio, Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap, Map<Integer, Integer> equipMap, Map<Integer, Integer> randomMap) {
private static void combineRewardDropGroup(User user, int[] dropGroupIds, float dropRatio, Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap, Map<Integer, Integer> equipMap, Map<Integer, Integer> randomMap) throws ErrorCodeException{
for (int dropGroupId : dropGroupIds) {
if(MapLogic.getInstance().getDifficultyReward().containsKey(dropGroupId)){
dropGroupId =MapLogic.getInstance().getDifficultyReward().get(dropGroupId);
@ -259,7 +260,7 @@ public class ItemUtil {
public static void combineReward(User user,boolean isLoop,int[] dropGroupIds,float dropRatio, Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap, Map<Integer, Integer> equipMap, Map<Integer, Integer> randomMap,int reason){
public static void combineReward(User user,boolean isLoop,int[] dropGroupIds,float dropRatio, Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap, Map<Integer, Integer> equipMap, Map<Integer, Integer> randomMap,int reason)throws ErrorCodeException{
combineRewardDropGroup(user, dropGroupIds, dropRatio, itemMap, cardMap, equipMap, randomMap);
if(!isLoop){
extraAddItem(user,itemMap,reason);
@ -289,7 +290,7 @@ public class ItemUtil {
}
}
public static void combineReward(int[][] itemArr, Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap, Map<Integer, Integer> equipMap, Map<Integer, Integer> randomMap){
public static void combineReward(int[][] itemArr, Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap, Map<Integer, Integer> equipMap, Map<Integer, Integer> randomMap)throws ErrorCodeException{
selectItemArr(itemArr,cardMap,itemMap,equipMap,randomMap);
}
@ -338,19 +339,19 @@ public class ItemUtil {
}
private static void selectItemArr(int[][] itemArr, Map<Integer, Integer> cardMap, Map<Integer, Integer>
itemMap,Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap) {
itemMap,Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap) throws ErrorCodeException{
for (int[] items : itemArr){
getMap(items[0],items[1], itemMap, cardMap,equipMap,randomMap,1);
}
}
private static void selectItemArr(Map<Integer,Integer>itemArr, Map<Integer, Integer> cardMap, Map<Integer, Integer>
itemMap,Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap) {
itemMap,Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap) throws ErrorCodeException{
for (Map.Entry<Integer,Integer> items : itemArr.entrySet()){
getMap(items.getKey(), items.getValue(), itemMap, cardMap,equipMap,randomMap,1);
}
}
private static void selectDrop(User user, SRewardGroup sRewardGroup,Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap , float dropRatio) {
private static void selectDrop(User user, SRewardGroup sRewardGroup,Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap , float dropRatio)throws ErrorCodeException {
String dropInfo = dropRewardMap.get(sRewardGroup.getId());
String rewardStr = dropInfo.split("\\|")[0];
String weight = dropInfo.split("\\|")[1];
@ -395,7 +396,7 @@ public class ItemUtil {
private static void getSuccessivelyRandmoMap(User user,SRewardGroup sRewardGroup, String[]
rewardArr, String[] weightArr, Map<Integer, Integer> itemMap, Map<Integer, Integer>
cardMap, Map<Integer,Integer> equipMap, Map<Integer,Integer> randomMap, float dropRatio) {
cardMap, Map<Integer,Integer> equipMap, Map<Integer,Integer> randomMap, float dropRatio) throws ErrorCodeException{
for (int i = 0 ; i < sRewardGroup.getRewardMaxNum();i++){
int id = 0;
for (int j = 0 ; j < sRewardGroup.getLoop();i++){
@ -419,7 +420,7 @@ public class ItemUtil {
}
private static void getRandomMap(User user,int randomItemNum ,String[] rewardArr,String[] weightArr, Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap,
Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap ,float dropRatio) {
Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap ,float dropRatio)throws ErrorCodeException {
for (int i = 0 ; i < randomItemNum;i++){
int index = MathUtils.randomForStrArray(weightArr);
if (index == -1) {
@ -464,7 +465,7 @@ public class ItemUtil {
return itemNum;
}
private static void getMap(User user,int[] itemInfo, Map<Integer, Integer> itemMap,Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap ,float dropRatio) {
private static void getMap(User user,int[] itemInfo, Map<Integer, Integer> itemMap,Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap,Map<Integer,Integer> randomMap ,float dropRatio) throws ErrorCodeException{
for (int id :itemInfo){
SRewardItem sRewardItem = SRewardItem.getsDropMap().get(id);
int itemNum = getItemNum(user,sRewardItem);
@ -476,15 +477,18 @@ public class ItemUtil {
}
private static void getMap(int itemId ,int itemNum, Map<Integer, Integer> itemMap,
Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap ,Map<Integer,Integer> randomMap,float dropRatio) {
Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap ,Map<Integer,Integer> randomMap,float dropRatio) throws ErrorCodeException{
Map<Integer, Integer> mapRe = getMapRe(itemId, itemMap, cardMap, equipMap, randomMap);
putcountMap(itemId,MathUtils.numRount((itemNum * dropRatio)) , mapRe);
}
public static Map<Integer, Integer> getMapRe(int itemId, Map<Integer, Integer> itemMap,
Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap ,Map<Integer,Integer> randomMap) {
Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap ,Map<Integer,Integer> randomMap) throws ErrorCodeException{
SItem sItem = SItem.getsItemMap().get(itemId);
if(sItem==null){
throw new ErrorCodeException("SItem配置不存在 id:"+itemId);
}
int itemType =getItemType(sItem);
switch (itemType) {
case GlobalItemType.SOUL_MARK: