public bool Trade(GameResource res1, GameResource res2, int traderId = -1) { if (needsToRefresh) { return(false); } tradeMutex.WaitOne(); if (traderId == -1) { traderId = globalStorage.CurrentMainPlayerId(); } bool isSuccessfullTrade = false; if (res2.amount <= marketStorage.getResourceAmount(res2.resourceType)) { globalStorage.RemoveResource(res1.resourceType, res1.amount); marketStorage.AddResource(res1.resourceType, res1.amount); marketStorage.RemoveResource(res2.resourceType, res2.amount); globalStorage.AddResource(res2.resourceType, res2.amount); isSuccessfullTrade = true; needsToRefresh = true; } tradeMutex.ReleaseMutex(); return(isSuccessfullTrade); }
public void gatherResources() { if (deposit.AvailableResource() > 0) { deposit.GetResourceFromDeposit(resourcesPerGather); inventory.AddResource(resourceType, resourcesPerGather); globalStorage.GetComponent <GlobalStorage>().AddResource(resourceType, resourcesPerGather, ownerId); } }