コード例 #1
0
ファイル: GameManager.cs プロジェクト: ironicnet/simpletown
 public Worker RequestWorker(Building building, WorkerType workerType = WorkerType.Builder)
 {
     if (workerType == WorkerType.Builder)
     {
         if (isWorkerAvailable())
         {
             return(currentWorkers.Where(w => w.GetComponent <Worker>().Status == WorkerStatus.Free).OrderBy(w => Vector3.Distance(w.transform.position, building.Waypoint.transform.position)).Select(w => w.GetComponent <Worker>()).FirstOrDefault());
         }
         else if (currentWorkers.Count < maxWorkers)
         {
             var worker = Worker.Create(this, GetNearestAdminBuilding(building.transform.position), workerType);
             RegisterWorker(worker);
             worker.WorkerType = workerType;
             return(worker);
         }
     }
     else
     {
         var worker = Worker.Create(this, GetNearestAdminBuilding(building.transform.position), workerType);
         worker.name       = workerType.ToString();
         worker.WorkerType = workerType;
         return(worker);
     }
     return(null);
 }
コード例 #2
0
        public WorkAddress GetWorkAddress(WorkerType workerType, WorkAddressType workAddressType)
        {
            var address = WorkAddress.FirstOrDefault(p => p.Type == workerType.ToString() && p.SubType == workAddressType.ToString());

            if (address == null)
            {
                LogController.Log(workerType + " " + workAddressType + " work address type error.");
            }

            return(address);
        }
コード例 #3
0
        public async Task StoreLatencies(long iterationId, double writeLatency, double readLatency, string region, WorkerType workerType)
        {
            const string WriteLatencyField  = "writeLatency";
            const string ReadLatencyField   = "readLatency";
            const string RegionField        = "region";
            const string TypeField          = "type";
            const string IterationIdField   = "iterationId";
            const string RunnerTypeField    = "runnerType";
            const string LatencyInfoTypeStr = "latencyInfo";

            try
            {
                IMongoDatabase db = this.defaultClient.GetDatabase(LatencyResultStore.DatabaseName);
                IMongoCollection <BsonDocument> coll = db.GetCollection <BsonDocument>(LatencyResultStore.MetricsCollectionName);


                //store latency info
                BsonDocument latencyInfoDocument = new BsonDocument
                {
                    { IterationIdField, iterationId },
                    { RunnerTypeField, workerType.ToString() },
                    { TypeField, LatencyInfoTypeStr },
                    { WriteLatencyField, writeLatency },
                    { ReadLatencyField, readLatency },
                    { RegionField, region }
                };

                await coll.InsertOneAsync(latencyInfoDocument);

                //store worker region
                await this.StoreRegion();

                if (WorkerSettings.IsWriteRegion)
                {
                    //store account regions
                    await this.StoreAccountRegions();
                }

                if (DateTime.UtcNow - this.lastMetricsCleanupTime > this.MetricsCleanupInterval)
                {
                    //cleanup old metrics for each runner type
                    await this.CleanupMetrics();

                    this.lastMetricsCleanupTime = DateTime.UtcNow;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Storing latencies failed exception : {0}", ex.ToString());
            }
        }
コード例 #4
0
ファイル: Worker.cs プロジェクト: ironicnet/simpletown
    public static Worker Create(GameManager gameManager, Building building, WorkerType workerType)
    {
        if (!Prefabs.ContainsKey(workerType))
        {
            Prefabs.Add(workerType, Resources.Load <GameObject>(PrefabPath + WorkerType.Builder.ToString()));
        }
        GameObject workerGO = GameObject.Instantiate(Prefabs[workerType]) as GameObject;
        var        worker   = workerGO.GetComponent <Worker>();

        worker.ID     = gameManager.LastID++;
        workerGO.name = workerType.ToString() + " " + worker.ID.ToString();
        workerGO.transform.position = new Vector3(building.Waypoint.transform.position.x, 0, building.Waypoint.transform.position.z);


        Debug.Log(string.Format("#{0}. Worker Pos: {1}. Waypoint: {2}", worker.ID, workerGO.transform.position, building.Waypoint.transform.position));
        return(worker);
    }
コード例 #5
0
 public List <WorkAddress> GetWorkAddresses(WorkerType workerType)
 {
     return(WorkAddress.Where(address => address.Type == workerType.ToString()).ToList());
 }