//a method that sets the target resource to collect locally public override void SetTargetLocal(Resource newTarget) { if (newTarget.IsEmpty() || newTarget == null || (target == newTarget && dropOffStatus != DropOffStatus.done)) //if the new target is invalid or it's already the collector's target (if the collector is not coming back after dropping off resources) { return; //do not proceed } if (target != newTarget) //if the resource wasn't being collected by this collector: { if (newTarget.WorkerMgr.currWorkers < newTarget.WorkerMgr.GetAvailableSlots() && (newTarget.CanCollectOutsideBorder() == true || newTarget.FactionID == unit.FactionID)) //does the new target has empty slots in its worker manager? and can this be collected outside the border or this under the collector's territory { CancelDropOff(); //cancel drop off if it was pending Stop(); //stop collecting from the last resource (if there was one). //set new target inProgress = false; target = newTarget; inProgressObject = null; //initially set to nothing if (collectionObjectsDic.TryGetValue(target.GetResourceType().GetName(), out CollectionObject collectionObject)) { inProgressObject = collectionObject.obj; //update the current collection object } //Search for the nearest drop off building if we are not automatically collecting: if (!gameMgr.ResourceMgr.CanAutoCollect()) { UpdateDropOffBuilding(); } //Move the unit to the resource and add the collector to the workers list in the worker manager gameMgr.MvtMgr.PrepareMove(unit, target.WorkerMgr.Add(unit), target.GetRadius(), target, InputMode.resource, false); CustomEvents.OnUnitCollectionOrder(unit, target); //trigger custom event } } else if (dropOffStatus == DropOffStatus.done) //collector is going back to the resource after a drop off { gameMgr.MvtMgr.PrepareMove(unit, target.WorkerMgr.GetWorkerPos(unit.LastWorkerPosID), target.GetRadius(), target, InputMode.resource, false); dropOffStatus = DropOffStatus.goingBack; } }