public void PerformAction() { if (jobAction == JobActions.DetermineResources) { Dictionary <Thing.Thing_Types, int> resourcesStillRequired = new Dictionary <Thing.Thing_Types, int>(); Dictionary <Thing.Thing_Types, int> resourcesNeededForThing; if (_parentJob.target is Building) { Building building = (Building)_parentJob.target; resourcesNeededForThing = Building.GetResourcesNeededToCreate(building.BuildingType); Debug.LogWarning("Resources needed - " + resourcesNeededForThing); } else { resourcesNeededForThing = new Dictionary <Thing.Thing_Types, int>(); } foreach (Thing.Thing_Types type in resourcesNeededForThing.Keys) { int needed = resourcesNeededForThing[type]; int owned = _parentJob.tribe.GetAmountOfThingOwned(type); if (needed > owned) { resourcesStillRequired.Add(type, needed - owned); } } resourcesRequired = resourcesStillRequired; _parentJob.tribe.AddTribeJobPosting(new TribeJobPosting (1, Tasks.CreatureTasks.GATHER, _parentJob)); jobAction = JobActions.WaitForResources; } }
public void AddAction(IAction action) { var e = new ActionAddedEventArgs(this, action); if (OnActionAdded != null) { OnActionAdded(this, e); } if (!e.SkipAction) { JobActions.Add(action); } }
private static bool TryGetJobType(ISchedulable device, JobActions action, out Type jobType) { jobType = null; if (device is IShuttable) { switch (action) { case JobActions.Open: jobType = typeof(ShuttableOpenJob); break; case JobActions.Close: jobType = typeof(ShuttableCloseJob); break; default: Logger.Error($"TryGetJobType method - Action {action} not implemented for device {device.Description} - {device.GetType().Name}"); return(false); } } else if (device is ISwitchable) { switch (action) { case JobActions.On: jobType = typeof(SwitchableOnJob); break; case JobActions.Off: jobType = typeof(SwitchableOffJob); break; default: Logger.Error($"TryGetJobType method - Action {action} not implemented for device {device.Description} - {device.GetType().Name}"); return(false); } } else { Logger.Error($"TryGetJobType method could not resolve the JobType for {device.Description} - {device.GetType().Name}"); return(false); } return(true); }
public void UpdateTrigger(ISchedulable device, JobActions action) { if (device.JobsCreated) { var oldTrigger = _scheduler.GetTrigger(new TriggerKey($"{device.Description}/{action}", device.DeviceTypeName)); if (oldTrigger != null) { TimeSpan timeSpanUtc; if (TryGetTimeSpan(device, action, out timeSpanUtc)) { var tb = oldTrigger.GetTriggerBuilder(); var newTrigger = tb .StartNow() .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(timeSpanUtc.Hours, timeSpanUtc.Minutes) .InTimeZone(TimeZoneInfo.Utc)) .Build(); _scheduler.RescheduleJob(oldTrigger.Key, newTrigger); } } } }
private static bool TryGetTimeSpan(ISchedulable device, JobActions action, out TimeSpan timeSpanUtc) { switch (action) { case JobActions.Close: case JobActions.Off: timeSpanUtc = device.OffTime.LocalToUtc(); break; case JobActions.Open: case JobActions.On: timeSpanUtc = device.OnTime.LocalToUtc(); break; default: Logger.Error( $"Time could not be set for device: {device.Description} - {device.GetType().Name} - action: {action}"); timeSpanUtc = new TimeSpan(0); return(false); } return(true); }
private void initialize(JobActions action, TribeJob job) { this._parentJob = job; this.jobAction = action; resourcesRequired = new Dictionary <Thing.Thing_Types, int>(); }
private void initialize(JobActions action, Transform target, TribeJob job) { this._targetTransform = target; this._targetPosition = target.position; initialize(action, job); }
private void initialize(JobActions action, Vector3 targetPosition, TribeJob job) { this._targetPosition = targetPosition; this._targetTransform = null; initialize(action, job); }
public JobAction(JobActions action, TribeJob job) { initialize(action, job); }
public JobAction(JobActions action, Transform target, TribeJob job) { initialize(action, target, job); }
public JobAction(JobActions action, Vector3 targetPosition, TribeJob job) { initialize(action, targetPosition, job); }