public TBattleResult Simulate(TBattleRecord record) { LuaTable table; try { var times = Interlocked.Increment(ref _battleTimes); if (times >= _reInitCount && times % _reInitCount == 0) { InitState(); Logger.LogDebug("Reinit Lua State"); } Stopwatch watch = new Stopwatch(); watch.Start(); //Logger.LogWarning("Simulate Battle [" + record.ToJson() + "]"); table = _battleEntry.invoke("entry", record.ToLua(), false) as LuaTable; var result = new TBattleResult() { WinPlayerId = table["winPlayerId"].ToInt(), FrameCount = table["frameCount"].ToInt(), RoundNum = table["roundNum"].ToInt(), }; watch.Stop(); Logger.LogDebug($"Battle Simulate BattleId[{record.BattleId}] FrameCount[{record.FrameCount}] Result[{result.ToJson()}] Finish. Time cost [{watch.ElapsedMilliseconds}]ms"); return(result); } catch (Exception e) { Logger.LogError(e, "Simulate lua battle failed."); InitState(); _ = BattleService.ReportBattleException(Host.ServerId, record.PlayerList[0].PlayerId, BattleVersion, record.ToLua()); } return(null); }
private static async Task <TBattleResult> AsyncSimulateBattle(TBattleRecord record) { return(await ASYNC_PRODUCER.Enqueue(record)); }
public static async Task <TBattleResult> SimulateBattle(TBattleRecord record) => await AsyncSimulateBattle(record);