private void ReportFatalError(object sender, UnhandledExceptionEventArgs fatal) { Qizarate.Output?.WriteLine("******* FATAL ERROR *******"); Qizarate.Output?.WriteLine("{0}", ((Exception)fatal.ExceptionObject).Message); KernelUtils.TerminateCurrentProcess(); }
private int Run(UnhandledExceptionEventHandler handler, params string[] parameters) { if (null != handler) { AppDomain.CurrentDomain.UnhandledException += handler; } var consoleMode = false; if (parameters.Any()) { // we have arguments in command line String sOption = parameters[0]; sOption = sOption.ToLower().Replace("/", "-"); switch (sOption) { case "-install": { return(RunInstall()); } case "-console": { consoleMode = true; Runner.Run(parameters); break; } default: { if (!Runner.UserCommandLine(parameters)) { return(-1); } break; } } } if (!consoleMode) { // // Other than -console and -install, assume Windows Service startup mode. // ServiceBase.Run(Runner); } Qizarate.Output?.Write($"{Runner.Name} has finished with exit code {Runner.ExitCode}."); KernelUtils.TerminateCurrentProcess((uint)Runner.ExitCode); // This is just for fun. return(int.MaxValue); }
private bool IsBetterMove(MoveAction newAction, float currentDistance, MoveAction prevAction, float bestDistance, Kernel kernel) { var newContext = (MoveActionContext)newAction.getContext(); var prevContext = (MoveActionContext)prevAction.getContext(); Fruiton newSource = KernelUtils.GetFruitonAt(kernel, newContext.source); Fruiton prevSource = KernelUtils.GetFruitonAt(kernel, prevContext.source); float newDistModifier = newSource.type == Fruiton.MAJOR_TYPE ? -1 : newSource.get_isKing() ? +1 : 0; float prevDistModifier = prevSource.type == Fruiton.MAJOR_TYPE ? -1 : prevSource.get_isKing() ? +1 : 0; return(currentDistance + newDistModifier < bestDistance + prevDistModifier); }
private bool IsBetterHeal(HealAction newAction, HealAction prevAction, Kernel kernel) { var newContext = (HealActionContext)newAction.getContext(); var prevContext = (HealActionContext)prevAction.getContext(); Fruiton newTarget = KernelUtils.GetFruitonAt(kernel, newContext.target); Fruiton prevTarget = KernelUtils.GetFruitonAt(kernel, prevContext.target); int newHealAmount = Math.Min(newContext.heal, newTarget.originalAttributes.hp - newTarget.currentAttributes.hp); int prevHealAmount = Math.Min(prevContext.heal, prevTarget.originalAttributes.hp - prevTarget.currentAttributes.hp); return(newTarget.get_isKing() || newTarget.type == Fruiton.MAJOR_TYPE && prevTarget.type == Fruiton.MINOR_TYPE || newTarget.type == prevTarget.type && newHealAmount > prevHealAmount); }
private bool IsBetterAttack(AttackAction newAction, AttackAction prevAction, Kernel kernel) { var newContext = (AttackActionContext)newAction.getContext(); var prevContext = (AttackActionContext)prevAction.getContext(); Fruiton newTarget = KernelUtils.GetFruitonAt(kernel, newContext.target); Fruiton prevTarget = KernelUtils.GetFruitonAt(kernel, prevContext.target); bool isNewKill = newTarget.currentAttributes.hp <= newContext.damage; bool isPrevKill = prevTarget.currentAttributes.hp <= prevContext.damage; if (prevTarget.get_isKing()) { return(false); } return(newTarget.get_isKing() || isNewKill && !isPrevKill || newContext.damage > prevContext.damage || newTarget.type == Fruiton.MAJOR_TYPE && prevTarget.type == Fruiton.MINOR_TYPE); }
private void ShowOffer(TradeOffer offer) { int notifId = FeedbackNotificationManager.Instance.Show( "Offer from " + offer.OfferedFrom, string.Format("Fruiton {0} for {1} coins.", KernelUtils.GetFruitonName(offer.FruitonId), offer.Price), () => { PlayerHelper.ProvideOfferResult(offer.OfferId, true, () => { GameManager.Instance.AdjustMoney(-(int)offer.Price); Bazaar.Instance.NotifyListeners(); }, s => NotificationManager.Instance.ShowError("Could not buy :(", s)); }, () => { PlayerHelper.ProvideOfferResult(offer.OfferId, false, () => { // ignore - everything is ok }, s => NotificationManager.Instance.ShowError("Unknown error", s)); }); offerToNotificationMap[offer.OfferId] = notifId; }
/// <summary> /// Loads last saved player's data from local cache and server, sets up fruiton database. /// </summary> private void Initialize() { FruitonDatabase = new FruitonDatabase(KernelUtils.LoadTextResource(FRUITON_DB_FILE)); AllFruitons = ClientFruitonFactory.CreateAllKernelFruitons(); if (IsInTrial) { AvailableFruitons = AllPlayableFruitons.Select(fruiton => fruiton.dbId).ToList(); FruitonTeamList = new FruitonTeamList(); loggedPlayerInfo = new LoggedPlayerInfo(); } else { PlayerOptions = Serializer.LoadPlayerSettings(); Serializer.DeserializeFruitonTeams(); AvailableFruitons = Serializer.LoadAvailableFruitons(); } if (IsOnline) { PlayerHelper.GetAllFruitonTeams(MergeTeamLists, Debug.Log); PlayerHelper.GetAvailableFruitons((list) => Debug.Log("Available fruitons loaded from server."), Debug.Log); } }