public async Task <IActionResult> SetBlueprintResources([FromBody] BlueprintResources aRessources) { try { if (aRessources.ReplaceExisting) { var p = await FactoryManager.Request_Player_Info(aRessources.PlayerId.ToId()); var setRes = new List <ItemStack>(); aRessources.ItemStacks.ForEach(I => { if (p.bpResourcesInFactory.TryGetValue(I.id, out var count)) { if (count < I.count) { setRes.Add(new ItemStack(I.id, I.count - (int)count)); } } else { setRes.Add(I); } }); aRessources.ItemStacks = setRes; aRessources.ReplaceExisting = false; } await FactoryManager.Request_Blueprint_Resources(aRessources); return(Ok()); } catch (Exception Error) { return(NotFound(Error.Message)); } }
public async Task <ActionResult <BlueprintResources> > GetBlueprintResources(int aPlayerId) { try { var onlinePlayers = await FactoryManager.Request_Player_List(); if (!onlinePlayers.list.Contains(aPlayerId)) { return(NotFound($"Player {aPlayerId} not online")); } var PlayerInfo = await FactoryManager.Request_Player_Info(aPlayerId.ToId()); var Result = new BlueprintResources() { PlayerId = aPlayerId, ItemStacks = new List <ItemStack>(), ReplaceExisting = true, }; PlayerInfo.bpResourcesInFactory?.ForEach(I => Result.ItemStacks.Add(new ItemStack() { id = I.Key, count = (int)I.Value })); return(Ok(Result)); } catch (Exception Error) { return(NotFound(Error.Message)); } }
public static void Request_Blueprint_Resources(BlueprintResources arg, Action callback = null, Action <ErrorInfo> onError = null) { Action <CmdId, object> wiredCallback = null; if (callback != null) { wiredCallback = (_, val) => callback(); } var apiCmd = new GenericAPICommand( CmdId.Request_Blueprint_Resources, arg, wiredCallback, onError ?? noOpErrorHandler ); Broker.Execute(apiCmd); }
public async Task <bool> Request_Blueprint_Resources(BlueprintResources arg, CancellationToken ct) { return(await Broker.SendRequestAsync(CmdId.Request_Blueprint_Resources, arg, ct)); }
public async Task <bool> Request_Blueprint_Resources(BlueprintResources arg) { return(await Broker.SendRequestAsync(CmdId.Request_Blueprint_Resources, arg)); }
public void Request_Blueprint_Resources(BlueprintResources arg, Action callback = null, Action <ErrorInfo> onError = null) { Broker.Request_Blueprint_Resources(arg, callback, onError); }
public static Task <object> Request_Blueprint_Resources(BlueprintResources param) { return(Broker.CreateCommandWithArgAndReturn <BlueprintResources, object>(CmdId.Request_Blueprint_Resources, param)); }
public static Task <object> Request_Blueprint_Resources(BlueprintResources param, Action callback, Action <ErrorInfo> onError = null) { return(Broker.CreateCommandWithArgAndReturn <BlueprintResources, object>(CmdId.Request_Blueprint_Resources, param, callback, onError)); }