Beispiel #1
0
        private void fillApppointmentForm(int taskID)
        {
            LeadTask task = TasksManager.GetLeadTask(taskID);

            if (task != null)
            {
                txtDetails.Text = task.details;
                txtSubject.Text = task.text;

                startDate.Text = ((DateTime)task.start_date).ToShortDateString();
                endDate.Text   = ((DateTime)task.end_date).ToShortDateString();

                startTime.Text = ((DateTime)task.start_date).ToString("hh:mm tt");
                endTime.Text   = ((DateTime)task.end_date).ToString("hh:mm tt");

                cbxAllDayEvent.Checked = task.isAllDay;

                ddlPriority.SelectedValue = task.priorityID.ToString();

                if (task.owner_id != null)
                {
                    ddlUsers.SelectedValue = task.owner_id.ToString();
                }

                //ucPolicyType.SelectedValue = task.policy_type.ToString();

                ucReminderInterval.SelectedValue = task.reminderInterval.ToString();
            }
        }
Beispiel #2
0
        public static LeadTask GetPolicyReminderTask(int leadID, int leadPolicyID)
        {
            LeadTask task = null;

            task = (from x in DbContextHelper.DbContext.Task.Include("Leads").Include("SecUser").Include("TaskStatus")
                    where x.lead_policy_id == leadPolicyID &&
                    x.lead_id == leadID
                    select new LeadTask {
                creator_id = x.creator_id,
                details = x.details,
                end_date = x.end_date,
                id = x.id,
                lead_id = x.lead_id,
                lead_name = x.Leads == null ? "" : x.Leads.ClaimantFirstName + " " + x.Leads.ClaimantLastName,
                owner_id = x.owner_id,
                owner_name = x.SecUser == null ? "" : x.SecUser.FirstName + " " + x.SecUser.LastName,
                start_date = x.start_date,
                status_id = x.status_id,
                statusName = x.Leads.StatusMaster == null ? "" : x.Leads.StatusMaster.StatusName,       //x.TaskStatus == null ? "" : x.TaskStatus.label,
                text = x.text,
                master_status_id = x.master_status_id,
                lead_policy_id = x.lead_policy_id,
                reminderInterval = x.ReminderInterval ?? 0,
                policy_type = x.policy_type                                     // 1 = homeowners...
            }).FirstOrDefault <LeadTask>();

            return(task);
        }
Beispiel #3
0
        public static int Save(LeadTask leadTask)
        {
            Task task = null;

            if (leadTask.id == 0)
            {
                task = new Task();

                DbContextHelper.DbContext.Add(task);
            }
            else
            {
                task = DbContextHelper.DbContext.Task.Where(x => x.id == leadTask.id).FirstOrDefault();
            }

            task.creator_id = leadTask.creator_id;
            task.details    = leadTask.details;
            task.end_date   = leadTask.end_date;
            task.lead_id    = leadTask.lead_id;
            task.owner_id   = leadTask.owner_id;
            task.start_date = leadTask.start_date;
            task.status_id  = leadTask.status_id;
            task.text       = leadTask.text;

            task.lead_policy_id   = leadTask.lead_policy_id;
            task.master_status_id = leadTask.master_status_id;

            task.policy_type = leadTask.policy_type;

            DbContextHelper.DbContext.SaveChanges();

            return(task.id);
        }
        //protected void WebMonthCalendar1_SelectedDateChanged(object sender, Infragistics.Web.UI.EditorControls.CalendarSelectedDateChangedEventArgs e) {
        //	DateTime fromDate = e.NewDate;
        //	DateTime toDate = e.NewDate;
        //	string tempDate = null;

        //	if (WebMonthCalendar1.SelectedDates.IndividualDates == null) {
        //		// user selected multiple dates on calendar
        //		bindTasks(WebMonthCalendar1.SelectedDates.RangeMin, WebMonthCalendar1.SelectedDates.RangeMax);
        //	}
        //	else {
        //		// user picked a single date on calendar
        //		tempDate = string.Format("{0} 11:59:59 PM", fromDate.ToShortDateString());

        //		toDate = Convert.ToDateTime(tempDate);

        //		bindTasks(fromDate, toDate);
        //	}
        //}

        protected void gvTasks_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
        {
            LeadTask task = null;

            if (e.Row.DataItem != null)
            {
                task = (LeadTask)e.Row.DataItem;

                if (task.statusName == "Expired")
                {
                    e.Row.CssClass = "redstar";
                }

                HyperLink hlnkLead = e.Row.Items.FindItemByKey("lead_name").FindControl("hlnkLead") as HyperLink;

                if (hlnkLead != null && task.lead_id != null)
                {
                    hlnkLead.Text = task.lead_name;

                    hlnkLead.NavigateUrl = "~/Protected/NewLead.aspx?q=" + Core.SecurityManager.EncryptQueryString(task.lead_id.ToString());
                }
            }
        }
Beispiel #5
0
        private List <LeadTask> getSelectedTasks()
        {
            List <LeadTask> tasks = new List <LeadTask>();
            LeadTask        task  = null;
            DateTime        date  = DateTime.MinValue;

            foreach (GridViewRow row in gvTasks.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox cbxExport = row.FindControl("cbxExport") as CheckBox;

                    if (cbxExport != null && cbxExport.Checked)
                    {
                        task = new LeadTask();
                        Label start_date = row.FindControl("start_date") as Label;

                        DateTime.TryParse(start_date.Text, out date);
                        task.start_date = date;

                        Label end_date = row.FindControl("end_date") as Label;

                        DateTime.TryParse(end_date.Text, out date);
                        task.end_date = date;

                        Label title = row.FindControl("event") as Label;
                        task.text = title.Text;

                        Label details = row.FindControl("details") as Label;
                        task.details = details.Text;

                        tasks.Add(task);
                    }
                }
            }
            return(tasks);
        }
        public void Do(Dictionary <MyTuple <IntelItemType, long>, IFleetIntelligence> IntelItems, TimeSpan canonicalTime, Profiler profiler)
        {
            if (canonicalTime == TimeSpan.Zero)
            {
                return;
            }
            if (MiningSystem.Recalling > 0 || currentPosition > 120)
            {
                Recalling = true;
            }
            if (Recalling && state < 3)
            {
                state = 3;
            }
            if (state == 1) // Diving to surface of asteroid
            {
                MineTask.Do(IntelItems, canonicalTime, profiler);
                MineTask.Destination.MaxSpeed = Autopilot.GetMaxSpeedFromBrakingDistance(kFarSensorDist);

                if (MineTask.Status == TaskStatus.Complete || !MiningSystem.SensorsFarClear())
                {
                    EntryPoint = Autopilot.Reference.WorldMatrix.Translation + MineTask.Destination.Direction * (kFarSensorDist - 10);
                    MineTask.Destination.MaxSpeed = 1f;
                    state = 2;
                }
            }
            else if (state == 2) // Boring tunnel
            {
                bool   sampleHome      = false;
                double distToMiningEnd = (Autopilot.Reference.WorldMatrix.Translation - MiningEnd).Length();
                if (MiningSystem.SensorsClear())
                {
                    MineTask.Destination.Position = MiningEnd;
                }
                else if (MiningSystem.SensorsBack())
                {
                    MineTask.Destination.Position = EntryPoint;
                }
                else
                {
                    MineTask.Destination.Position = Vector3D.Zero;
                    if (SampleCount <= 0)
                    {
                        SampleCount = kSampleFrequency;
                        var cargoPercentage = MonitorSubsystem.GetPercentage(MonitorOptions.Cargo);
                        if (LastSampleCargoPercentages.Count >= kMaxSampleCount)
                        {
                            LastSampleCargoPercentages.Enqueue(cargoPercentage);

                            var sampleGreater     = 0;
                            var sampleLesser      = 0;
                            var comparePercentage = LastSampleCargoPercentages.Dequeue() + 0.00001;
                            foreach (var percentage in LastSampleCargoPercentages)
                            {
                                if (percentage > comparePercentage)
                                {
                                    sampleGreater++;
                                }
                                else
                                {
                                    sampleLesser++;
                                }
                            }

                            if (sampleGreater > sampleLesser)
                            {
                                if (!HitOre)
                                {
                                    HitOre = true;
                                    var currentCoords = GetMiningPosition(currentPosition);
                                    miningMatrix[currentCoords.X + 5, currentCoords.Y + 5] = 1;
                                }
                                if (LowestExpectedOreDist == -1)
                                {
                                    LowestExpectedOreDist = (float)distToMiningEnd - 5;
                                }
                            }
                            else
                            {
                                if (HitOre || distToMiningEnd < LowestExpectedOreDist)
                                {
                                    sampleHome = true;

                                    if (!HitOre)
                                    {
                                        var currentCoords = GetMiningPosition(currentPosition);
                                        miningMatrix[currentCoords.X + 5, currentCoords.Y + 5] = 2;
                                    }
                                }
                            }
                        }
                        else
                        {
                            LastSampleCargoPercentages.Enqueue(cargoPercentage);
                        }
                    }
                    else
                    {
                        SampleCount--;
                    }
                }

                MiningSystem.Drill();
                MineTask.Do(IntelItems, canonicalTime, profiler);

                if (GoHomeCheck() || MiningSystem.SensorsFarClear() || distToMiningEnd < 4 || sampleHome)
                {
                    if (MiningSystem.SensorsFarClear() || distToMiningEnd < 4 || sampleHome)
                    {
                        UpdateMiningMatrix(currentPosition);
                        IncrementCurrentPosition();
                        HitOre = false;
                    }
                    state = 3;
                    MineTask.Destination.MaxSpeed = 2;
                    LastSampleCargoPercentages.Clear();
                }
            }
            else if (state == 3) // Exiting tunnel
            {
                MiningSystem.StopDrill();
                if (MineTask.Destination.Position != ExitPoint)
                {
                    MineTask.Destination.Position = EntryPoint;
                }
                MineTask.Do(IntelItems, canonicalTime, profiler);
                if (MineTask.Status == TaskStatus.Complete)
                {
                    if (MineTask.Destination.Position == EntryPoint)
                    {
                        MineTask.Destination.Position = ExitPoint;
                        MineTask.Destination.MaxSpeed = 100;
                    }
                    else
                    {
                        state = 10;
                    }
                }
            }
            else if (state == 10) // Resuming to approach point
            {
                if (GoHomeCheck() || Recalling)
                {
                    state = 4;
                }
                else
                {
                    LeadTask.Destination.Position = ApproachPoint;
                    LeadTask.Do(IntelItems, canonicalTime, profiler);
                    if (LeadTask.Status == TaskStatus.Complete)
                    {
                        var position = GetMiningPosition(currentPosition);
                        LeadTask.Destination.Position = ApproachPoint + (Perpendicular * position.X * MiningSystem.OffsetDist + Perpendicular.Cross(MineTask.Destination.Direction) * position.Y * MiningSystem.OffsetDist);
                        LeadTask.Destination.MaxSpeed = 10;
                        ExitPoint = LeadTask.Destination.Position;
                        state     = 11;
                    }
                }
            }
            else if (state == 11) // Search for the digging spot
            {
                if (GoHomeCheck() || Recalling)
                {
                    state = 4;
                }
                else
                {
                    LeadTask.Do(IntelItems, canonicalTime, profiler);
                    if (LeadTask.Status == TaskStatus.Complete)
                    {
                        state = 1;
                        MiningSystem.SensorsOn();
                        var position = GetMiningPosition(currentPosition);
                        MineTask.Destination.Position = SurfacePoint + (Perpendicular * position.X * MiningSystem.OffsetDist + Perpendicular.Cross(MineTask.Destination.Direction) * position.Y * MiningSystem.OffsetDist) - MineTask.Destination.Direction * MiningSystem.CloseDist;
                        MiningEnd = SurfacePoint + (Perpendicular * position.X * MiningSystem.OffsetDist + Perpendicular.Cross(MineTask.Destination.Direction) * position.Y * MiningSystem.OffsetDist) + MineTask.Destination.Direction * MiningDepth;
                    }
                }
            }
            else if (state == 4) // Going home
            {
                if (DockingSubsystem == null || DockingSubsystem.HomeID == -1 || DockTaskGenerator == null || UndockTaskGenerator == null)
                {
                    state = 9999;
                }
                else
                {
                    if (HomeTask == null)
                    {
                        HomeTask = DockTaskGenerator.GenerateMoveToAndDockTask(MyTuple.Create(IntelItemType.NONE, (long)0), IntelItems, 40);
                    }
                    HomeTask.Do(IntelItems, canonicalTime, profiler);
                    if (HomeTask.Status != TaskStatus.Incomplete)
                    {
                        HomeTask  = null;
                        homeCheck = false;
                        state     = 5;
                    }
                }
            }
            else if (state == 5) // Waiting for refuel/unload
            {
                if (Recalling)
                {
                    state = 9999;
                }
                if ((Program.Me.WorldMatrix.Translation - EntryPoint).LengthSquared() > MiningSystem.CancelDist * MiningSystem.CancelDist)
                {
                    state = 9999;
                }
                if (LeaveHomeCheck())
                {
                    state = 6;
                }
            }
            else if (state == 6) // Undocking
            {
                if (DockingSubsystem != null && DockingSubsystem.Connector.Status == MyShipConnectorStatus.Connected)
                {
                    if (UndockTask == null)
                    {
                        UndockTask = UndockTaskGenerator.GenerateUndockTask(canonicalTime);
                    }
                }

                if (UndockTask != null)
                {
                    UndockTask.Do(IntelItems, canonicalTime, profiler);
                    if (UndockTask.Status != TaskStatus.Incomplete)
                    {
                        UndockTask = null;
                        state      = 10;
                    }
                }
                else
                {
                    state = 10;
                }
            }
            else if (state == 9999)
            {
                Status = TaskStatus.Complete;
            }
        }
        private void setReminder(int leadID, CRM.Data.Entities.LeadPolicy policy, int masterStatusID)
        {
            int      lastStatusID = 0;
            double   duration     = 0;
            LeadTask task         = null;
            DateTime reminderDate = DateTime.MaxValue;
            string   sdate        = null;

            // return if no change in status
            int.TryParse(hf_lastStatusID.Value, out lastStatusID);

            if (lastStatusID == masterStatusID)
            {
                return;
            }

            // get status with reminder duration
            StatusMaster statusMaster = StatusManager.GetStatusId(masterStatusID);

            // return if master status not loaded properly
            if (statusMaster == null)
            {
                return;
            }



            // get task associated with policy
            task = TasksManager.GetPolicyReminderTask(leadID, policy.Id);

            // master status has no reminder
            if (statusMaster.ReminderMaster == null)
            {
                // delete existing reminder
                if (task != null)
                {
                    TasksManager.Delete(task.id);
                }
            }
            else
            {
                if (task == null)
                {
                    // create new reminder as task
                    task                = new LeadTask();
                    task.lead_id        = leadID;
                    task.lead_policy_id = policy.Id;
                    task.policy_type    = policy.PolicyType;
                }

                if (SessionHelper.getClientId() > 0)
                {
                    task.creator_id = SessionHelper.getClientId();
                }

                // update existing reminder
                task.master_status_id = masterStatusID;

                sdate = DateTime.Now.ToShortDateString() + " 5:00:00 AM";

                DateTime.TryParse(sdate, out reminderDate);

                // get duration from status reminder
                if (statusMaster.ReminderMaster != null)
                {
                    duration = (double)(statusMaster.ReminderMaster.Duration ?? 0);
                }

                if ((int)statusMaster.ReminderMaster.DurationType == 1)
                {
                    task.start_date = reminderDate.AddHours(duration);
                }
                else
                {
                    task.start_date = reminderDate.AddDays(duration);
                }

                task.end_date  = task.start_date;
                task.status_id = 1;
                task.text      = "Alert";
                task.isAllDay  = true;
                task.details   = statusMaster.StatusName;              // +"&lt;div&gt;Ins. Co: " + policy.InsuranceCompanyName + "&lt;/div&gt;&lt;div&gt;Pol: " + policy.PolicyNumber + "&lt;/div&gt;";
                task.owner_id  = SessionHelper.getUserId();

                TasksManager.Save(task);
            }

            // refresh tasks on parent page
            if (statusChanged != null)
            {
                statusChanged(this, null);
            }
        }
Beispiel #8
0
        public void Do(Dictionary <MyTuple <IntelItemType, long>, IFleetIntelligence> IntelItems, TimeSpan canonicalTime, Profiler profiler)
        {
            if (canonicalTime == TimeSpan.Zero)
            {
                return;
            }

            runs++;

            if (MonitorSubsystem != null &&
                (MonitorSubsystem.GetPercentage(MonitorOptions.Hydrogen) < 0.2 ||
                 MonitorSubsystem.GetPercentage(MonitorOptions.Cargo) < 0.02 ||
                 MonitorSubsystem.GetPercentage(MonitorOptions.Power) < 0.1))
            {
                GoHome(canonicalTime);
                return;
            }

            IMyShipController controller     = Autopilot.Controller;
            Vector3D          linearVelocity = controller.GetShipVelocities().LinearVelocity;
            var currentPosition = controller.WorldMatrix.Translation;

            LeadTask.Destination.MaxSpeed = Autopilot.CruiseSpeed;

            if (!TargetPositionSet)
            {
                if (IntelKey.Item1 == IntelItemType.Waypoint && IntelItems.ContainsKey(IntelKey))
                {
                    TargetPosition = IntelItems[IntelKey].GetPositionFromCanonicalTime(canonicalTime);
                    PatrolMaxSpeed = ((Waypoint)IntelItems[IntelKey]).MaxSpeed;
                }
                TargetPositionSet = true;
            }

            EnemyShipIntel orbitIntel       = null;
            EnemyShipIntel shootIntel       = null;
            double         closestIntelDist = CombatSystem.AlertDist;

            foreach (var intel in IntelItems)
            {
                if (intel.Key.Item1 != IntelItemType.Enemy)
                {
                    continue;
                }

                var enemyIntel = (EnemyShipIntel)intel.Value;
                if (!EnemyShipIntel.PrioritizeTarget(enemyIntel))
                {
                    continue;
                }
                if (IntelProvider.GetPriority(enemyIntel.ID) < 2)
                {
                    continue;
                }

                double dist = (enemyIntel.GetPositionFromCanonicalTime(canonicalTime) - controller.WorldMatrix.Translation).Length();

                if (IntelKey.Item1 == IntelItemType.Enemy && enemyIntel.ID != IntelKey.Item2 && FocusedTarget)
                {
                    continue;
                }

                if (enemyIntel.CubeSize == MyCubeSize.Small)
                {
                    dist -= 300;
                }
                if (IntelProvider.GetPriority(enemyIntel.ID) == 3)
                {
                    dist -= 600;
                }
                if (IntelProvider.GetPriority(enemyIntel.ID) == 4)
                {
                    dist -= 1200;
                }
                if (dist < closestIntelDist)
                {
                    closestIntelDist = dist;
                    shootIntel       = enemyIntel;
                    if (enemyIntel.Radius > 30)
                    {
                        orbitIntel = enemyIntel;
                    }
                }
            }

            if (shootIntel == null && CombatSystem.TargetIntel != null && IntelProvider.GetPriority(CombatSystem.TargetIntel.ID) >= 2)
            {
                shootIntel = CombatSystem.TargetIntel;
            }

            if (orbitIntel == null)
            {
                orbitIntel = shootIntel;
            }

            var gravdir = Autopilot.Controller.GetNaturalGravity();

            if (gravdir != Vector3D.Zero)
            {
                gravdir.Normalize();
            }

            // No Target
            if (orbitIntel == null)
            {
                // Plot Intercept
                if (IntelKey.Item1 == IntelItemType.Enemy && IntelItems.ContainsKey(IntelKey) && EnemyShipIntel.PrioritizeTarget((EnemyShipIntel)IntelItems[IntelKey]) && IntelProvider.GetPriority(IntelKey.Item2) >= 2)
                {
                    var target = IntelItems[IntelKey];
                    LeadTask.Destination.Position = currentPosition + AttackHelpers.GetAttackPoint(target.GetVelocity(), target.GetPositionFromCanonicalTime(canonicalTime) + target.GetVelocity() * 0.08 - currentPosition, Autopilot.CruiseSpeed);
                }
                // Go to Position ( Scramble )
                else if (TargetPosition != Vector3.Zero)
                {
                    LeadTask.Destination.MaxSpeed = PatrolMaxSpeed;
                    LeadTask.Destination.Position = TargetPosition;
                }
                else
                {
                    GoHome(canonicalTime);
                    return;
                }

                Vector3D toTarget = LeadTask.Destination.Position - Program.Me.WorldMatrix.Translation;
                if (toTarget.LengthSquared() > 400)
                {
                    if (gravdir == Vector3D.Zero)
                    {
                        LeadTask.Destination.Direction = toTarget;
                    }
                    else
                    {
                        LeadTask.Destination.Direction = Vector3D.Zero;
                    }
                }
                else
                {
                    LeadTask.Destination.Direction = Vector3D.Zero;
                }

                LastAcceleration        = Vector3D.Zero;
                LastReference           = MatrixD.Zero;
                LastEnemyVelocity       = Vector3D.Zero;
                LastEnemyPosition       = Vector3D.Zero;
                LastRelativeAttackPoint = Vector3D.Zero;
//                targetLastPoweredRun = 0;
            }

            // Orbiting a Target
            else
            {
                CombatSystem.MarkEngaged();
                LeadTask.Destination.MaxSpeed = Autopilot.CombatSpeed;
                Vector3D targetPosition    = orbitIntel.GetPositionFromCanonicalTime(canonicalTime);
                var      periodicFactor    = runs * Math.PI * CombatSystem.EngageTheta / 4;
                Vector3D periodicDirection = Math.Sin(periodicFactor) * controller.WorldMatrix.Left + Math.Cos(periodicFactor) * controller.WorldMatrix.Up;

                var Acceleration = linearVelocity - LastLinearVelocity;
                if (LastAcceleration == Vector3D.Zero)
                {
                    LastAcceleration = Acceleration;
                }
                if (LastReference == MatrixD.Zero)
                {
                    LastReference = controller.WorldMatrix;
                }
                if (LastEnemyVelocity == Vector3D.Zero)
                {
                    LastEnemyVelocity = shootIntel.GetVelocity();
                }
                if (LastEnemyPosition == Vector3D.Zero)
                {
                    LastEnemyPosition = shootIntel.GetPositionFromCanonicalTime(canonicalTime);
                }

                var enemyAcceleration = shootIntel.GetVelocity() - LastEnemyVelocity;

                var enemyVelocityAdjust = shootIntel.GetVelocity() * 2 - LastEnemyVelocity;

                var CurrentAccelerationPreviousFrame = Vector3D.TransformNormal(Acceleration, MatrixD.Transpose(LastReference));

                var accelerationAdjust = Vector3D.TransformNormal(CurrentAccelerationPreviousFrame, controller.WorldMatrix);
                var velocityAdjust     = linearVelocity + accelerationAdjust * 0.4;

                velocityAdjust *= CombatSystem.OwnSpeedMultiplier;

                Vector3D relativeAttackPoint = AttackHelpers.GetAttackPoint(enemyVelocityAdjust - velocityAdjust, shootIntel.GetPositionFromCanonicalTime(canonicalTime) + enemyVelocityAdjust * 0.25 - controller.WorldMatrix.Translation - velocityAdjust * 0.25, CombatSystem.ProjectileSpeed);

                relativeAttackPoint.Normalize();

                if (LastRelativeAttackPoint == Vector3D.Zero)
                {
                    LastRelativeAttackPoint = relativeAttackPoint;
                }

                LastAcceleration = linearVelocity - LastLinearVelocity;
                LeadTask.Destination.Direction = relativeAttackPoint;

                if ((controller.WorldMatrix.Translation - targetPosition).Length() < CombatSystem.FireDist &&
                    VectorHelpers.VectorAngleBetween(LeadTask.Destination.Direction, controller.WorldMatrix.Forward) < CombatSystem.FireTolerance)
                {
                    CombatSystem.Fire();
                }

                Vector3D dirTargetToMe  = controller.WorldMatrix.Translation - targetPosition;
                var      distTargetToMe = dirTargetToMe.Length();
                dirTargetToMe.Normalize();

                if (Mode == 0)
                {
                    Vector3D dirTargetToOrbitTarget = Vector3D.Cross(dirTargetToMe, controller.WorldMatrix.Up);
                    dirTargetToOrbitTarget.Normalize();

                    if (gravdir == Vector3D.Zero)
                    {
                        LeadTask.Destination.DirectionUp = Math.Sin(CombatSystem.EngageTheta) * controller.WorldMatrix.Right + Math.Cos(CombatSystem.EngageTheta) * controller.WorldMatrix.Up;
                        LeadTask.Destination.Position    = targetPosition + orbitIntel.GetVelocity() + dirTargetToMe * CombatSystem.EngageDist + dirTargetToOrbitTarget * 200;
                    }
                    else
                    {
                        var flatDirTargetToMe = dirTargetToMe - VectorHelpers.VectorProjection(dirTargetToMe, gravdir);
                        flatDirTargetToMe.Normalize();
                        LeadTask.Destination.Position = targetPosition + orbitIntel.GetVelocity() + flatDirTargetToMe * CombatSystem.EngageDist * 0.9 - gravdir * 300 + periodicDirection * 100;
                    }
                    LeadTask.Destination.Velocity = orbitIntel.GetVelocity() * 0.5;
                }
                else if (Mode == 2)
                {
                    LeadTask.Destination.Position = targetPosition + dirTargetToMe * (CombatSystem.EngageDist + (CombatSystem.EngageDist - distTargetToMe));
                    LeadTask.Destination.Velocity = orbitIntel.GetVelocity();
                }

                LastReference           = controller.WorldMatrix;
                LastEnemyVelocity       = shootIntel.GetVelocity();
                LastEnemyPosition       = shootIntel.GetPositionFromCanonicalTime(canonicalTime);
                LastRelativeAttackPoint = relativeAttackPoint;

                //var n = VectorHelpers.VectorProjection(enemyAcceleration, gravdir).Length() / enemyAcceleration.Length();
                //
                //if (targetLastPoweredRun == 0 || n < 0.6)
                //    targetLastPoweredRun = runs;
                //
                //if (runs - targetLastPoweredRun > 20)
                //    IntelProvider.SetPriority(shootIntel.ID, 1);
            }

            if (!Attack)
            {
                Vector3D toTarget = TargetPosition - Program.Me.WorldMatrix.Translation;
                if (toTarget.LengthSquared() > 100)
                {
                    LeadTask.Destination.Position = TargetPosition;
                }
                else
                {
                    LeadTask.Destination.Position = Vector3D.Zero;
                }
                LeadTask.Destination.Velocity = Vector3D.Zero;
            }

            if (Mode == 1)
            {
                //TODO: Add support for disabling dampeners in this mode - let pilot have full control aside from aiming
                LeadTask.Destination.Position = controller.GetPosition();
                LeadTask.Destination.Velocity = Vector3D.Zero;

                if (shootIntel == null)
                {
                    LeadTask.Destination.Direction   = Vector3D.Zero;
                    LeadTask.Destination.DirectionUp = Vector3D.Zero;
                }
            }

            LastLinearVelocity = linearVelocity;
            if (LeadTask.Status == TaskStatus.Incomplete)
            {
                LeadTask.Do(IntelItems, canonicalTime, profiler);
            }
        }
        private void bindTasks(DateTime fromDate, DateTime toDate)
        {
            List <LeadTask> tasks = null;

            Expression <Func <CRM.Data.Entities.Task, bool> > predicate = PredicateBuilder.True <CRM.Data.Entities.Task>();

            if (roleID == (int)UserRole.Administrator)
            {
            }
            else if ((roleID == (int)UserRole.Client || roleID == (int)UserRole.SiteAdministrator) && clientID > 0)
            {
                // load all tasks for client (sort of admin)

                predicate = predicate.And(LeadTask => LeadTask.creator_id == clientID);

                predicate = predicate.And(LeadTask => LeadTask.start_date >= fromDate && LeadTask.end_date <= toDate);

                // get overdue task for client
                predicate = predicate.Or(LeadTask => LeadTask.status_id == 1 && LeadTask.end_date <= toDate && LeadTask.creator_id == clientID);
            }
            else
            {
                // regular users

                predicate = predicate.And(LeadTask => LeadTask.start_date >= fromDate && LeadTask.end_date <= toDate);

                predicate = predicate.And(LeadTask => LeadTask.owner_id == userID);
            }

            tasks = TasksManager.GetLeadTask(predicate, fromDate, toDate);

            if (rbOn.Checked)
            {
                userID = SessionHelper.getUserId();

                CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID);
                string emailaddress = secUser.Email;
                string password     = SecurityManager.Decrypt(secUser.emailPassword);
                string url          = "https://" + secUser.emailHost + "/EWS/Exchange.asmx";

                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = new WebCredentials(emailaddress, password);
                service.Url         = new Uri(url);

                try
                {
                    TasksFolder tasksfolder = TasksFolder.Bind(service, WellKnownFolderName.Tasks);

                    ItemView view = new ItemView(int.MaxValue);
                    FindItemsResults <Item> OutlookTasks = tasksfolder.FindItems(view);

                    CalendarView calView = new CalendarView(fromDate, toDate);

                    FindItemsResults <Item> instanceResults = service.FindItems(WellKnownFolderName.Calendar, calView);

                    foreach (var item in instanceResults)
                    {
                        LeadTask newTask = new LeadTask();
                        Microsoft.Exchange.WebServices.Data.Appointment appointment = item as Microsoft.Exchange.WebServices.Data.Appointment;

                        newTask.creator_id = userID;
                        newTask.details    = appointment.Subject;
                        newTask.end_date   = appointment.End;
                        newTask.isAllDay   = appointment.IsRecurring;
                        newTask.text       = appointment.Subject;

                        newTask.priorityName = appointment.Importance.ToString();
                        newTask.owner_name   = appointment.Organizer.Name;
                        newTask.start_date   = appointment.Start;

                        tasks.Add(newTask);
                    }

                    foreach (var task in OutlookTasks)
                    {
                        task.Load();
                        Microsoft.Exchange.WebServices.Data.Task myTask = task as Microsoft.Exchange.WebServices.Data.Task;

                        LeadTask newTask = new LeadTask();
                        newTask.creator_id   = userID;
                        newTask.details      = ExtractHtmlInnerText(myTask.Body.Text);
                        newTask.end_date     = myTask.DueDate;
                        newTask.isAllDay     = myTask.IsRecurring;
                        newTask.text         = myTask.Subject;
                        newTask.statusName   = myTask.Status.ToString();
                        newTask.priorityName = myTask.Importance.ToString();
                        newTask.owner_name   = myTask.Owner;
                        if (myTask.StartDate == null)
                        {
                            newTask.start_date = myTask.DueDate;
                        }
                        else
                        {
                            newTask.start_date = myTask.StartDate;
                        }

                        tasks.Add(newTask);
                    }
                }
                catch (Exception ex)
                {
                }
            }
            // show tasks
            gvTasks.DataSource = tasks;
            gvTasks.DataBind();
        }
Beispiel #10
0
        public void Do(Dictionary <MyTuple <IntelItemType, long>, IFleetIntelligence> IntelItems, TimeSpan canonicalTime, Profiler profiler)
        {
            IMyShipController controller = Autopilot.Controller;
            var      currentPosition     = controller.WorldMatrix.Translation;
            Vector3D linearVelocity      = controller.GetShipVelocities().LinearVelocity;

            if (!TargetPositionSet)
            {
                if (IntelKey.Item1 == IntelItemType.Waypoint && IntelItems.ContainsKey(IntelKey))
                {
                    TargetPosition = IntelItems[IntelKey].GetPositionFromCanonicalTime(canonicalTime);
                }
                TargetPositionSet = true;
            }

            Vector3D worldAttackPoint;

            if (TargetPositionSet && TargetPosition != Vector3D.Zero)
            {
                worldAttackPoint = TargetPosition;
            }
            else
            {
                if (IntelKey.Item1 != IntelItemType.Enemy || !IntelItems.ContainsKey(IntelKey))
                {
                    AgentSubsystem.AddTask(TaskType.Dock, MyTuple.Create(IntelItemType.NONE, (long)0), CommandType.Enqueue, 0, canonicalTime);
                    Status = TaskStatus.Aborted;
                    return;
                }

                var target = (EnemyShipIntel)IntelItems[IntelKey];
                worldAttackPoint = currentPosition + AttackHelpers.GetAttackPoint(target.GetVelocity(), target.GetPositionFromCanonicalTime(canonicalTime) + target.GetVelocity() * 0.08 - currentPosition, 98);
            }

            Vector3D dirToTarget = worldAttackPoint - currentPosition;

            if (dirToTarget.Length() < LocustCombatSystem.kEngageRange && deployTime == TimeSpan.Zero)
            {
                CombatSystem.Deploy();
                deployTime = canonicalTime;
            }

            dirToTarget.Normalize();
            LeadTask.Destination.Direction = dirToTarget;
            LeadTask.Destination.Position  = worldAttackPoint + dirToTarget * 400;

            if (deployTime != TimeSpan.Zero)
            {
                if (deployTime + TimeSpan.FromSeconds(2) < canonicalTime)
                {
                    AgentSubsystem.AddTask(TaskType.Dock, MyTuple.Create(IntelItemType.NONE, (long)0), CommandType.Enqueue, 0, canonicalTime);
                    Status = TaskStatus.Aborted;
                    return;
                }
                else
                {
                    LeadTask.Destination.DirectionUp = Math.Sin(kRotateTheta) * controller.WorldMatrix.Right + Math.Cos(kRotateTheta) * controller.WorldMatrix.Up;
                }
            }

            LeadTask.Do(IntelItems, canonicalTime, profiler);
        }