Ejemplo n.º 1
0
        public MissionViewModel(MissionModel mission, WorldNavigation navigation)
        {
            Contract.Requires<ArgumentNullException>(mission != null);
            Contract.Requires<ArgumentNullException>(navigation != null);

            _mission = mission;
            _entityNavigation = navigation;
        }
Ejemplo n.º 2
0
 public void Complete(MissionModel mission)
 {
     var world = _recordedWorld.Head;
     var tasks = world.MissionRequiresTasks.ValueOrDefault(mission.Id);
     if (tasks != null)
         foreach (var t in tasks)
             world = world.Complete(world.Tasks[t], null);
     _recordedWorld.Head = world.Complete(mission);
 }
Ejemplo n.º 3
0
 public void EventApplication()
 {
     var mission = new MissionModel(0, EnumMissionAction.Move, entity.Id, DateTime.Now, SetModule.Empty<int>(), DateTime.Now, entity.Position, 1);
     var task = new TaskModel(0, 0, new Vector3D(), null);
     world.Apply(new EntityUpdateEvent(entity, "Test entity event"));
     world.Apply(new MissionUpdateEvent(mission, "Test mission event"));
     world.Apply(new TaskUpdateEvent(task, "Test task event"));
     world.Apply(new TaskCompleteEvent(task, null, "Test task complete event"));
     world.Apply(new MissionCompleteEvent(mission, "Test task complete event"));
     world.Apply(new EntityUpdateEvent(entity, "Test entity event"));
     world.Apply(new SkillEvent(entity, EnumSkill.AcidBlast, entity, true, true, false, "Test skill event"));
 }
Ejemplo n.º 4
0
        public void Updates()
        {
            var mission = new MissionModel(0, EnumMissionAction.Move, combatant.Id, DateTime.Now, SetModule.Empty<int>(), DateTime.Now, entity.Position, 1);
            world.Apply(new EntityUpdateEvent(combatant, "Test entity event"));
            world.Apply(new MissionUpdateEvent(mission, "Test mission event"));
            world.Apply(new EntityUpdateEvent(entity, "Test entity event"));

            world.Update(DateTime.Now);
            world.History.Head.Tasks.Count
                .Should().Be(1);

            var newPosition = world.History.Head.Entities[combatant.Id].Position;
            (entity.Position - newPosition).Length
                .Should().BeLessThan((entity.Position - combatant.Position).Length);
        }
Ejemplo n.º 5
0
        public void TaskCompletion()
        {
            var mission = new MissionModel(0, EnumMissionAction.Move, combatant.Id, DateTime.Now, SetModule.Empty<int>(), DateTime.Now, entity.Position, 1);
            world.Apply(new EntityUpdateEvent(combatant, "Test entity event"));
            world.Apply(new MissionUpdateEvent(mission, "Test mission event"));
            world.Apply(new EntityUpdateEvent(entity, "Test entity event"));

            world.Update(DateTime.Now);
            world.History.Head.Tasks.Count
                .Should().Be(1);

            world.Apply(new EntityUpdateEvent(combatant.Move(combatant.MobileState, entity.Position, entity.Rotation, DateTime.Now), "Test move to target"));

            world.Update(DateTime.Now);
            world.History.Head.Tasks.Count
                .Should().Be(0);
        }
Ejemplo n.º 6
0
 public void Add(MissionModel mission) { _recordedWorld.Head = _recordedWorld.Head.Add(mission); }
 void Process(MissionModel m)
 {
     History.Add(m);
 }
 public MissionCompleteEvent(MissionModel mission, string description)
 {
     Mission = mission;
     Description = description;
 }
Ejemplo n.º 9
0
 public bool IsSelected(MissionModel mission) { return IsSelectedMission(mission.Id); }
Ejemplo n.º 10
0
 public void RemoveSelected(MissionModel mission) { RemoveSelectedMission(mission.Id); }
Ejemplo n.º 11
0
 public void AddSelected(MissionModel mission) { AddSelectedMission(mission.Id); }
Ejemplo n.º 12
0
 public void SetSelected(MissionModel mission) { SetSelectedMission(mission.Id); }
Ejemplo n.º 13
0
        // TODO: Might be useful to differentiate between success and failure reason for completion
        bool IsMissionComplete(MissionModel mission, EntityModel doer)
        {
            if ((doer.Position - mission.Destination).Length > 1)
                return false;

            var world = History.Head;
            var holding = world.EntityHoldingEntities.ValueOr(doer.Id, SetModule.Empty<int>());

            switch (mission.Action)
            {
                case EnumMissionAction.Move:
                    return !mission.Targets.Except(holding).Any();
                case EnumMissionAction.Destroy:
                    return !mission.Targets.Any();
                case EnumMissionAction.Protect:
                    return !mission.Targets.Any();
                case EnumMissionAction.Build:
                    // TODO: hmmm targets are not built yet
                    return true;
                case EnumMissionAction.Capture:
                    return mission.Targets.All(t =>
                    {
                        var oo = world.Entities.TryFind(t);
                        return oo == null || oo.Value.Owner == doer.Owner;
                    });
                case EnumMissionAction.Harvest:
                    return false;
                default:
                    Contract.Assert(false, "Unexpected " + mission.Action);
                    return false;
            }
        }
Ejemplo n.º 14
0
        void UpdateMission(MissionModel mission)
        {
            var world = History.Head;
            var doers = mission.DoerIds.Select(x => world.Entities[x]);

            // Has this mission been completed?
            if (doers.Any(d => IsMissionComplete(mission, d)))
            {
                Apply(new MissionCompleteEvent(mission, "Finished " + mission));
                return;
            }

            // What task chains exist to satisfy this mission?
            // Build a graph of connections from current state to final state

            // Which task chain should I choose?
            // Shortest path search of the graph

            var tasks = new List<TaskModel>();
            var task = new TaskModel(Global.Rand.Next(), mission.Id, mission.Destination, null);
            tasks.Add(task);

            // Does this match my current task allocation?
            // Only change if there is a significant reason to
            IEnumerable<TaskModel> old;
            var TaskIds = world.MissionRequiresTasks.ValueOrDefault(mission.Id);

            if (TaskIds == null)
                old = Enumerable.Empty<TaskModel>();
            else
            {
                old = TaskIds.Select(id => world.Tasks[id]);
                foreach (var t in old.Where(x => !tasks.Any(y => y.Matches(x))))
                    Apply(new TaskCompleteEvent(t, null, "Remove task " + t + " of " + mission));
            }
            foreach (var t in tasks.Where(x => !old.Any(y => y.Matches(x))))
                Apply(new TaskUpdateEvent(t, "Added task " + t + " of " + mission));
        }
Ejemplo n.º 15
0
 public CreateMission(MissionModel mission)
 {
     Mission = mission;
 }