Esempio n. 1
0
        //From main thread
        private void StartWork(WorkerBase worker, WaitCallback workerLogic, WorkerBase.WorkerDataBase data)
        {
            var localWorksCount = Interlocked.Increment(ref _worksCount);

            if (localWorksCount > _maxWorks)
            {
                _maxWorks = localWorksCount;
            }
            _totalWorks++;

            int threadId;

            lock (_pool)
            {
                threadId = Array.FindIndex(_pool, w => w == null);
                if (threadId < 0)
                {
                    throw new InvalidOperationException("There is no free thread in pool");
                }
                _pool[threadId] = worker;
            }

            data.ThreadId = threadId;

#if MAIN_THREAD_WORK
            workerLogic(data);                                                      //Debug work from Main thread
#else
            ThreadPool.QueueUserWorkItem(workerLogic, data);
#endif
        }
Esempio n. 2
0
    void KillWorker(WorkerBase _worker)
    {
        int station = 0;

        for (station = 0; station < crew.Length; station++)
        {
            if (crew[station] == _worker)
            {
                AssignWorker(station, null);
                break;
            }
        }
        if (station == 0 && crewCount > 0)
        {
            for (station = crew.Length - 1; station >= 0; station--)
            {
                if (crew[station] != null)
                {
                    AssignWorker(WorkStation.Cabin, crew[station]);
                    AssignWorker(station, null);
                    return;
                }
            }
        }
    }
Esempio n. 3
0
    float GetWorkerCost(WorkerBase _worker)
    {
        float workerCost = (_worker.Motorskills * _worker.Engineering * _worker.Operating) * UnityEngine.Random.Range(2, 6);

        Mathf.RoundToInt(workerCost *= otherMultiplier);
        return(workerCost);
    }
Esempio n. 4
0
 /// <summary>
 /// Add a new worker to be processed
 /// </summary>
 public void AddWorker(WorkerBase worker)
 {
     if (worker != null)
     {
         this._workersList.Add(worker);
     }
 }
Esempio n. 5
0
        protected override void BeginProcessing()
        {
            ValidateParameters();
            var iss = GetSessionState();

            PowershellPool = new PowershellPool(ThrottleLimit, iss, _cancelationTokenSource.Token);
            _worker        = NoProgress ? (WorkerBase) new NoProgressWorker(this) : new ProgressWorker(this);
        }
 public void RemoveWorker()
 {
     assignedWorker = null;
     nameText.text  = "Empty";
     statsText.text = "";
     icon.sprite    = null;
     icon.color     = new Color(1, 1, 1, 0);
 }
Esempio n. 7
0
 public void RemoveContent()
 {
     workerContent      = null;
     partContent        = null;
     hasContent         = false;
     contentIcon.sprite = null;
     emptyContentIcon.SetActive(true);
     contentMain.SetActive(false);
 }
Esempio n. 8
0
        protected override void OnCreateManager(int capacity)
        {
            base.OnCreateManager(capacity);

            worker = WorkerRegistry.GetWorkerForWorld(World);
            view   = worker.View;
            origin = worker.Origin;
            entityGameObjectCreator = new EntityGameObjectCreator(World);
        }
Esempio n. 9
0
    public void AssignWorker(int _stationIndex, WorkerBase _worker)
    {
        if (crewCount < CrewCountMax || _worker == null)
        {
            switch (_stationIndex)
            {
            case 0:
                crew[0] = _worker;
                if (_worker != null)
                {
                    _worker.Station = WorkStation.Cabin;
                }
                break;

            case 1:
                if (cabin != null)
                {
                    crew[1] = _worker;
                    if (_worker != null)
                    {
                        _worker.Station = WorkStation.Engine;
                    }
                }
                break;

            case 2:
                if (cabin != null)
                {
                    crew[2] = _worker;
                    if (_worker != null)
                    {
                        _worker.Station = WorkStation.Drill;
                    }
                }
                break;

            case 3:
                if (cabin != null)
                {
                    crew[3] = _worker;
                    if (_worker != null)
                    {
                        _worker.Station = WorkStation.Spare;
                    }
                }
                break;
            }
        }
        if (_worker == null)
        {
            crewCount--;
            print("Crew is" + CrewCount + "/" + CrewCountMax);
        }
        RecalculateStats();
    }
Esempio n. 10
0
 void ModifyCrewCount(WorkerBase _worker, int _crewPosition)
 {
     if (crew[_crewPosition] == null && _worker != null)
     {
         crewCount++;
     }
     else if (_worker == null)
     {
         crewCount--;
     }
 }
Esempio n. 11
0
        public void BeAssignableFromDerivedTypes()
        {
            var worker = new Manager();

            Assert.Equal(0, worker.WorkIterations);

            WorkerBase workerBase = worker;

            workerBase.DoSomeWork();

            Assert.Equal(-1, workerBase.WorkIterations);
        }
Esempio n. 12
0
        private void AddWorker([NotNull] WorkerBase worker)
        {
            if (worker == null)
            {
                throw new ArgumentNullException("worker");
            }

            if (!_workers.Contains(worker))
            {
                _workers.Add(worker);
            }
        }
Esempio n. 13
0
 internal void Return(WorkerBase worker)
 {
     if (disposed)
     {
         worker.UnderlyingThread.Dispose();
     }
     else
     {
         stack.Push(worker.UnderlyingThread);
     }
     ActiveThreads--;
 }
Esempio n. 14
0
 public void AddContent(WorkerBase _worker)
 {
     if (_worker != null)
     {
         workerContent      = _worker;
         partContent        = null;
         type               = ContentType.Worker;
         hasContent         = true;
         contentIcon.sprite = workerContent.Portrait;
         emptyContentIcon.SetActive(false);
         contentMain.SetActive(true);
         contentButton.onClick.AddListener(OnPickUp);
     }
 }
Esempio n. 15
0
 public void AddContent(PartBase _part)
 {
     if (_part != null)
     {
         partContent        = _part;
         workerContent      = null;
         type               = ContentType.Part;
         hasContent         = true;
         contentIcon.sprite = partContent.Icon;
         emptyContentIcon.SetActive(false);
         contentMain.SetActive(true);
         contentButton.onClick.AddListener(OnPickUp);
     }
 }
Esempio n. 16
0
 public override void AddWorker(WorkerBase Worker)
 {
     if (Worker is TeamLeader)
     {
         throw new ArgumentException("A Team Leader can't command another Team Leader.");
     }
     else if (this.Team.Count >= 3)
     {
         throw new Exception("A Team Leader can't hold more than 3 workers at a time.");
     }
     else
     {
         this.Team.Add(Worker);
     }
 }
Esempio n. 17
0
 public void Add(string primaryKey, string secondaryKey, WorkerBase worker)
 {
     if (Threads == null)
     {
         Threads = new Dictionary <string, Dictionary <string, WorkerBase> >();
     }
     if (!Threads.ContainsKey(primaryKey))
     {
         Threads.Add(primaryKey, new Dictionary <string, WorkerBase>());
     }
     if (!Threads[primaryKey].ContainsKey(secondaryKey))
     {
         Threads[primaryKey].Add(secondaryKey, worker);
     }
 }
Esempio n. 18
0
    void NewWorkerCard(WorkerBase _worker)
    {
        WorkerCardConnector newWorkerCard = Instantiate(workerCardPrefab, workerCardGroup).GetComponent <WorkerCardConnector>();

        newWorkerCard.worker = _worker;
        newWorkerCard.workerNameText.text     = _worker.WorkerName;
        newWorkerCard.healthSkillText.text    = _worker.Health.ToString();
        newWorkerCard.motorSkillText.text     = _worker.Motorskills.ToString();
        newWorkerCard.engineerSkillText.text  = _worker.Engineering.ToString();
        newWorkerCard.operationSkillText.text = _worker.Operating.ToString();
        newWorkerCard.workerImage.sprite      = _worker.Portrait;
        newWorkerCard.shopMain = this;

        newWorkerCard.costText.text = "Cost: $" + _worker.Cost;

        workerConnectors.Add(newWorkerCard);
    }
Esempio n. 19
0
    public void AssignWorker(WorkStation _station, WorkerBase _worker)
    {
        if (crewCount < CrewCountMax || _worker == null)
        {
            switch (_station)
            {
            case WorkStation.None:
                return;

            case WorkStation.Cabin:
                crew[0] = _worker;
                break;

            case WorkStation.Engine:
                if (cabin != null)
                {
                    crew[1] = _worker;
                }
                break;

            case WorkStation.Drill:
                if (cabin != null)
                {
                    crew[2] = _worker;
                }
                break;

            case WorkStation.Spare:
                if (cabin != null)
                {
                    crew[3] = _worker;
                }
                break;
            }
        }
        if (_worker != null)
        {
            _worker.Station = _station;
        }
        else
        {
            crewCount--;
            print("Crew is" + CrewCount + "/" + CrewCountMax);
        }
        RecalculateStats();
    }
Esempio n. 20
0
    public void AddWorker(WorkerBase _worker)
    {
        if (_worker == null)
        {
            return;
        }

        workersInventoryBar.AddItem(_worker);
        for (int i = 0; i < workerInventory.Count; i++)
        {
            if (workerInventory[i] == null)
            {
                workerInventory[i] = _worker;
                return;
            }
        }
        workerInventory.Add(_worker);
    }
Esempio n. 21
0
        public static void SendEmail(AryaTask job, bool includeLogUrl, string customStatus, string projectName, string emailAddress, string portalLocation)
        {
            var subject = String.Format("{0}: {1}", job.JobType.Spacify(), job.Description);
            //var to = aryaDb.CurrentUser.EmailAddress;
            var to          = emailAddress;
            var messageBody = String.Format(@"
    Project Name: {0}
    Description: {1}
    Status: {2}", projectName, job.Description, customStatus ?? WorkerBase.GetFriendlyWorkerState((WorkerState)Enum.Parse(typeof(WorkerState), job.Status)));

            if (includeLogUrl)
            {
                messageBody += String.Format("{0}{0}Log file can be viewed here: {1}/Log.aspx?ID={2}", Environment.NewLine,
                                             portalLocation, job.ID);
            }

            EmailSender.SendEmail(to, messageBody, subject);
        }
Esempio n. 22
0
    public void AddItem(WorkerBase _worker)
    {
        if (currentItems >= maxItems)
        {
            return;
        }

        foreach (InventoryBarContent item in invContent)
        {
            if (!item.HasContent)
            {
                item.AddContent(_worker);
                item.shipEditor = shipEditor;
                currentItems++;
                return;
            }
        }
    }
Esempio n. 23
0
    public void RemoveItem(WorkerBase _worker)
    {
        if (currentItems <= 0)
        {
            return;
        }

        foreach (InventoryBarContent item in invContent)
        {
            if (item.workerContent == _worker)
            {
                print("Removing worker " + currentItems);
                item.RemoveContent();
                currentItems--;
                print("Remaining Items " + currentItems);
                return;
            }
        }
    }
Esempio n. 24
0
    void OnTriggerEnter(Collider other)
    {
        if (state == State.Idle && other.tag == "Player")
        {
            masterController = other.GetComponent <WorkerBase>();
            masterController.MovementEvent += NewMovement;

            startPosition = other.transform.position;

            slaveControllers = new List <ArtificialController>();
            frameMovements   = new List <FrameMovement>();
            CycleElapsed?.Invoke();

            numFrames = 1;
            state     = State.Recording;

            AudioHelper.PlayClip(activateSound, 1f, 1f, transform);
        }
    }
Esempio n. 25
0
    WorkerBase NewWorker()
    {
        WorkerBase newWorker = ScriptableObject.CreateInstance <WorkerBase>();

        newWorker.Health      = UnityEngine.Random.Range(1, 11);
        newWorker.Motorskills = UnityEngine.Random.Range(1, 11);
        newWorker.Engineering = UnityEngine.Random.Range(1, 11);
        newWorker.Operating   = UnityEngine.Random.Range(1, 11);
        int rand = UnityEngine.Random.Range(0, 3);

        switch (rand)
        {
        case 0:
            newWorker.WorkerName = workerInfoHolder.GetName(Gender.Male);
            newWorker.Gender     = Gender.Male;
            newWorker.Portrait   = workerInfoHolder.GetPortrait(Gender.Male);
            break;

        case 1:
            newWorker.WorkerName = workerInfoHolder.GetName(Gender.Female);
            newWorker.Gender     = Gender.Female;
            newWorker.Portrait   = workerInfoHolder.GetPortrait(Gender.Female);
            break;

        case 2:
            newWorker.WorkerName = workerInfoHolder.GetName(Gender.Other);
            newWorker.Gender     = Gender.Other;
            newWorker.Portrait   = workerInfoHolder.GetPortrait(Gender.Other);
            break;
        }

        newWorker.name = newWorker.WorkerName + " Asset";
        newWorker.Cost = GetWorkerCost(newWorker);

        return(newWorker);
    }
Esempio n. 26
0
 protected override IEnumerable <WorkerEntry> ProvideWorkers()
 {
     yield return(new WorkerEntry(
                      WorkerBase.RouteFor <IntraTalk>(),
                      (id, host, factoryRoute) => new IntraTalk(id, host, factoryRoute)));
 }
Esempio n. 27
0
 public void RemoveWorker(WorkerBase _worker)
 {
     workerInventory.Remove(_worker);
     workersInventoryBar.RemoveItem(_worker);
 }
Esempio n. 28
0
 protected override IEnumerable <PluginBase.WorkerEntry> ProvideWorkers()
 {
     yield return(new WorkerEntry(
                      WorkerBase.RouteFor <DiagnosticWorker>(),
                      (id, host, factoryRoute) => new DiagnosticWorker(id, host, factoryRoute)));
 }
Esempio n. 29
0
 private void LoadLevel(WorkerBase worker)
 {
     Instantiate(Level, worker.Origin, Quaternion.identity);
 }
Esempio n. 30
0
    IEnumerator DrillRepeated()
    {
        if (drillActive || !vehicleMover.IsMining)
        {
            vehicleMain.Audio.StopAudio(VehicleSounds.Drilling);
            yield break;
        }
        int _hardnessCount = 0;

        while (true)
        {
            float gasLeft = vehicleMain.Inventory.GetFuelAmount();
            if (!drillActive && vehicleMover.IsMining)
            {
                drillActive = true;
            }
            else if (!vehicleMover.IsMining || gasLeft <= 0)
            {
                vehicleMain.Audio.StopAudio(VehicleSounds.Drilling);
                drillActive = false;
                yield break;
            }
            _hardnessCount = 0;
            RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, drillCollider.radius, transform.forward, drillCollider.radius, miningLayerMask);
            if (hits.Length > 0)
            {
                print(hits[0].transform.gameObject.layer);
                bool hasChanged = false;
                foreach (RaycastHit2D hit in hits)
                {
                    //print("DrillRepeated");
                    Vector2 hitPosition = new Vector2();

                    hitPosition.x = hit.point.x;
                    hitPosition.y = hit.point.y;

                    hitPosition.x = hit.point.x;
                    hitPosition.y = hit.point.y;

                    if (tilemap.GetTile(tilemap.WorldToCell(hitPosition)) != null)
                    {
                        ResourceTile _tile = tilemap.GetTile <ResourceTile>(tilemap.WorldToCell(hitPosition));
                        if (_tile.Hardness <= vehicleMain.DrillTier)
                        {
                            int   damage          = 5;
                            float collectionBonus = 1;
                            vehicleMain.Audio.PlayAudio(VehicleSounds.Drilling);
                            WorkerBase _drillOperater = vehicleMain.GetWorker(WorkStation.Drill);
                            if (_drillOperater != null)
                            {
                                damage         += _drillOperater.Operating;
                                collectionBonus = (float)_drillOperater.Operating * 0.25f;
                            }
                            if (vehicleMain.GetWorker(WorkStation.Spare) != null)
                            {
                                damage += Mathf.RoundToInt((float)vehicleMain.GetWorker(WorkStation.Spare).Operating / 2f);
                            }
                            _tile.TakeDamage(damage);
                            //print("Tile Health " + _tile.Health);
                            if (_tile.Health <= 0)
                            {
                                //Add a resource
                                vehicleMain.Inventory.AddResource(_tile.Resource, (1 * vehicleMain.DrillEfficiency) + collectionBonus);
                                tilemap.SetTile(tilemap.WorldToCell(hitPosition), null);
                                hasChanged = true;
                            }
                        }
                        else
                        {
                            _hardnessCount++;
                        }
                        vehicleMain.UseFuel(-1 * vehicleMain.DrillFuelEfficiency);
                    }

                    //Code for Particle system spawning.
                    //CreateParticle(this.transform.position);
                    drill.transform.parent = drill.transform;
                    //Consume a fuel with every block mined

                    if (_hardnessCount >= hits.Length)
                    {
                        Debug.LogWarning("Soil is too hard");
                        vehicleMain.Audio.StopAudio(VehicleSounds.Drilling);
                        drillActive = false;
                        yield break;
                    }
                }
                if (hasChanged)
                {
                    GameObject.FindObjectOfType <PlayerController>().dirtyNav = true;
                }
            }
            else
            {
                vehicleMain.Audio.StopAudio(VehicleSounds.Drilling);
                drillActive = false;
                yield break;
            }
            yield return(new WaitForSeconds(vehicleMain.DrillSpeed));
        }
    }
		protected override void BeginProcessing()
		{
			ValidateParameters();
			var iss = GetSessionState();
			PowershellPool = new PowershellPool(ThrottleLimit, iss, _cancelationTokenSource.Token);			
			_worker = NoProgress ? (WorkerBase) new NoProgressWorker(this) : new ProgressWorker(this);
		}