trade & sell UI added

This commit is contained in:
2022-05-17 11:36:24 +05:30
parent 58f7212434
commit a3aba776a5
25 changed files with 22513 additions and 635 deletions

View File

@@ -21,7 +21,7 @@ public class CollectBtn : MonoBehaviour
void Update()
{
collectableAmount=((DateTime.Now - lastCollected).TotalSeconds * productionRate);
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * productionRate);
txt.text = ((int)collectableAmount).ToString();
btn.interactable = collectableAmount > 1;
@@ -34,9 +34,9 @@ public class CollectBtn : MonoBehaviour
resourceType = _resourceType;
}
void OnClick(){
async void OnClick(){
collectableAmount=((DateTime.Now - lastCollected).TotalSeconds * productionRate);
lastCollected = DBmanager.GetNetworkTime();
lastCollected = await DBmanager.GetNetworkTime();
switch (resourceType){
case CollectablesData.ResourceType.Metal:
DBmanager.SetMetal(DBmanager.Metal + (int)collectableAmount);

View File

@@ -40,8 +40,27 @@ public class DBmanager : MonoBehaviour
username = null;
}
public static DateTime GetNetworkTime()
public static async Task<DateTime> GetNetworkTime()
{
int unixTime = 0;
using (UnityWebRequest www = UnityWebRequest.Get(phpRoot + "get_time.php"))
{
var operation = www.SendWebRequest();
while (!operation.isDone)
{
await Task.Yield();
}
try{
unixTime = int.Parse(www.downloadHandler.text);
}catch{
Debug.Log("Invalid response from server : " + www.downloadHandler.text);
}
}
if(unixTime> 0){
return DateTimeOffset.FromUnixTimeSeconds(unixTime).UtcDateTime;
}
//default Windows time server
const string ntpServer = "time.windows.com";
@@ -352,7 +371,7 @@ public class DBmanager : MonoBehaviour
}
}
Debug.Log("adding new building " + buildingData.buildingName);
buildingStates.Add(new BuildingState(buildingData.buildingName, 0, Vector3.zero, GetNetworkTime()));
buildingStates.Add(new BuildingState(buildingData.buildingName, 0, Vector3.zero,await GetNetworkTime()));
Debug.Log("Added new building " + buildingData.buildingName);
await UpdateBuildingsToServer();
OnStateChanged.Invoke();
@@ -383,7 +402,7 @@ public class DBmanager : MonoBehaviour
{
if (buildingStates[i].id == id)
{
buildingStates[i].lastCollectedTimestamp = GetNetworkTime();
buildingStates[i].lastCollectedTimestamp = await GetNetworkTime();
Debug.Log("Setting " + id + " last collected to " + buildingStates[i].lastCollectedTimestamp);
break;
}