예제 #1
0
        //a method that updates the drop off resources that the collector is holding
        public void UpdateDropOffResources(int resourceID, int value)
        {
            dropOffResources[resourceID].CurrAmount += value;           //update the current amount of this drop off resource

            if (dropOffResources[resourceID].CurrAmount >= maxCapacity) //if the maximum capacity has been reached
            {
                dropOffStatus = DropOffStatus.ready;                    //the collector is now in drop off mode
                unit.SetAnimState(UnitAnimState.idle);                  //move to idle state
                SendToDropOff();                                        //send the unit to drop off resources
                AudioManager.Stop(unit.AudioSourceComp);                //stop the collection audio.

                if (inProgressObject != null)
                {
                    inProgressObject.SetActive(false); //hide the collection object
                }
                //look if there's a drop off object for the current taget's resource type
                if (collectionObjectsDic.TryGetValue(target.GetResourceType().GetName(), out CollectionObject collectionObject))
                {
                    currDropOffObject = collectionObject.dropOffObject;
                    if (currDropOffObject != null) //activate the drop off object
                    {
                        currDropOffObject.SetActive(true);
                    }
                }

                ToggleSourceTargetEffect(false); //hide the source and target effect objects during drop off
            }
        }
예제 #2
0
        //drop off resources at the drop off building
        public void DropOff()
        {
            foreach (DropOffResource dor in dropOffResources) //go through the drop off resources
            {
                dor.AddResource(unit.FactionID);
            }

            //make the unit go back to the resource he's collecting from:
            dropOffStatus = DropOffStatus.done;
            SetTarget(target);

            unit.ResetAnimatorOverrideController();           //in case the animator override controller has been modified, reset it

            CustomEvents.OnUnitDropOffComplete(unit, target); //trigger custom event
        }
예제 #3
0
        //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;
            }
        }
예제 #4
0
        //a method that sends the unit to drop off resources at the drop off building locally
        public void SendToDropOffLocal()
        {
            if (dropOffBuilding == null && unit.FactionID == GameManager.PlayerFactionID) //no drop off building and this is the player's faction
            {
                ErrorMessageHandler.OnErrorMessage(ErrorMessage.dropoffBuildingMissing, unit);
                return;
            }

            AudioManager.Stop(unit.AudioSourceComp); //stop the collection audio clip.

            dropOffStatus = DropOffStatus.active;

            if (collectionObjectsDic.TryGetValue(target.GetResourceType().GetName(), out CollectionObject collectionObject))
            {
                unit.SetAnimatorOverrideController(collectionObject.dropOffOverrideController); //enable the drop off override controller.
            }
            gameMgr.MvtMgr.PrepareMove(unit, dropOffBuilding.DropOffComp.GetDropOffPosition(), dropOffBuilding.DropOffComp.GetDropOffRadius(), dropOffBuilding, InputMode.building, false);

            CustomEvents.OnUnitDropOffStart(unit, target); //trigger custom event
        }
예제 #5
0
 //a method that cancels drop off:
 public void CancelDropOff()
 {
     dropOffStatus = DropOffStatus.inactive;
 }