private void ProcessAttack(Command cmd, IMap map) { var cell = map.Locate(cmd.Target); var player = Core.Players.Get(cmd.Sender); int time = ActionLogic.Calc(cmd.Action, cell, player); if (cell.CanAttack(player)) { Task <bool> .Factory.StartNew(() => { return(cell.BeginChangeOwner(player, time)); }).ContinueWith((task) => { if (task.Result) { return(cell.EndChangeOwner(player)); } else { return(false); } }).ContinueWith((task) => { if (task.Result) { ProcessAttackResult(player, cell); } ClearLostCells(); }); } }
private void ProcessAttack(Command cmd, IMap map) { int time = 0; try { var cell = map.Locate(cmd.Target); var player = Core.Players.Get(cmd.Sender); if (cell != null && cell.CanAttack(player, ThreadNum)) { time = ActionLogic.Calc(cmd.Action, cell, player); Task <bool> .Factory.StartNew(() => { return(cell.BeginChangeOwner(player, time, ThreadNum)); }).ContinueWith((task) => { if (task.Result) { return(cell.EndChangeOwner(player)); } else { return(false); } }).ContinueWith((task) => { if (task.Result) { ProcessAttackResult(player, cell); } ClearLostCells(); }); } } catch (Exception ex) { Console.WriteLine("cell pos:" + cmd.Target.ToString()); Console.WriteLine("sender:" + cmd.Sender); Console.WriteLine("calced time:" + time.ToString()); throw ex; } }