Beispiel #1
0
        IEnumerator DeployDrone()
        {
            var       time        = TimeKeeper.Chronos.Get();
            WaitUntil _DroneReady = new WaitUntil(() => time.Timer() > HubData.deploymentPeriod);
            Drone     outgoing    = null;

            while (true)
            {
                if (!DronePath.IsClear)
                {
                    yield return(null);
                }
                if (_Data.deploymentQueue.Count > 0)
                {
                    outgoing = _Data.deploymentQueue.Dequeue();
                    if (outgoing.InPool)
                    {
                        continue;
                    }
                    _Data.freeDrones.Remove(outgoing);
                    GetBatteryForDrone(outgoing);
                    StopCharging(outgoing.GetBattery());
                    outgoing.GetBattery().SetStatus(BatteryStatus.Discharge);
                    outgoing.Deploy();
                }
                yield return(_DroneReady);

                time.Now();
            }
        }
Beispiel #2
0
 private void RemoveBatteryFromDrone(Drone drone)
 {
     if (drone.GetHub() == this && _Data.freeBatteries.Add(drone.GetBattery().UID, drone.GetBattery()))
     {
         _Data.chargingBatteries.Add(drone.GetBattery().UID, drone.GetBattery());
         drone.AssignBattery(null);
     }
 }
Beispiel #3
0
 public void OnDroneReturn(Drone drone)
 {
     if (drone != null && _Data.freeDrones.Add(drone.UID, drone))
     {
         _Data.chargingBatteries.Add(drone.GetBattery().UID, drone.GetBattery());
     }
     drone.WaitForDeployment();
 }
Beispiel #4
0
 public void ReassignDrone(Drone drone, Hub hub)
 {
     _Data.drones.Remove(drone);
     _Data.batteries.Remove(drone.GetBattery());
     drone.AssignHub(hub);
     hub._Data.drones.Add(drone.UID, drone);
     hub._Data.batteries.Add(drone.GetBattery().UID, drone.GetBattery());
     drone.GetBattery().AssignHub(hub);
 }
Beispiel #5
0
        private void GetBatteryForDrone(Drone drone)
        {
            if (drone.GetBattery() != null)
            {
                return;
            }

            if (_Data.drones.Count >= _Data.batteries.Count)
            {
                drone.AssignBattery(BuyBattery(drone));
            }
            else
            {
                drone.AssignBattery(_Data.freeBatteries.GetMax(true));
                drone.GetBattery().AssignDrone(drone);
            }
        }