示例#1
0
        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);
        }
示例#2
0
 private static async Task <TBattleResult> AsyncSimulateBattle(TBattleRecord record)
 {
     return(await ASYNC_PRODUCER.Enqueue(record));
 }
示例#3
0
 public static async Task <TBattleResult> SimulateBattle(TBattleRecord record) => await AsyncSimulateBattle(record);