protected override GameAction PrepareNextActionOverride(out JobStatus progress)
        {
            var action = new BuildItemAction(m_workbench, m_buildableItemKey, m_items);

            progress = JobStatus.Ok;
            return(action);
        }
Example #2
0
 protected override GameAction PrepareNextActionOverride(out JobStatus progress)
 {
     var action = new BuildItemAction(m_workbench, m_buildableItemKey, m_items);
     progress = JobStatus.Ok;
     return action;
 }
Example #3
0
        static void HandleBuildItem(string str)
        {
            var living = GameData.Data.FocusedObject;

            var workbench = living.Environment.GetContents(living.Location).OfType<ItemObject>()
                .Where(item => item.ItemCategory == ItemCategory.Workbench && item.IsInstalled)
                .FirstOrDefault();

            if (workbench == null)
            {
                Inform("No workbench");
                return;
            }

            var wbInfo = Workbenches.GetWorkbenchInfo(workbench.ItemID);

            BuildableItem buildableItem;

            {
                var dlg = new ItemSelectorDialog();
                dlg.Owner = App.Current.MainWindow;
                dlg.DataContext = wbInfo.BuildableItems;
                dlg.Title = "Buildable Items";
                bool? res = dlg.ShowDialog();

                if (res.HasValue == false || res == false)
                    return;

                buildableItem = (BuildableItem)dlg.SelectedItem;
            }

            foreach (var component in buildableItem.FixedBuildMaterials)
            {
                var obs = living.Inventory.Where(item => component.Match(item));

                if (obs.Any() == false)
                {
                    Inform("Missing required components");
                    return;
                }
            }

            List<ItemObject> materials = new List<ItemObject>();

            foreach (var component in buildableItem.FixedBuildMaterials)
            {
                var obs = living.Inventory.Where(item => component.Match(item));

                var dlg = new ItemSelectorDialog();
                dlg.Owner = App.Current.MainWindow;
                dlg.DataContext = obs;
                dlg.Title = "Select component";
                bool? res = dlg.ShowDialog();
                if (res.HasValue == false || res == false)
                    return;
                materials.Add((ItemObject)dlg.SelectedItem);
            }

            var action = new BuildItemAction(workbench, buildableItem.Key, materials);
            action.GUID = new ActionGUID(living.World.PlayerID, 0);
            living.RequestAction(action);
        }
Example #4
0
        ActionState ProcessAction(BuildItemAction action)
        {
            if (this.ActionTicksUsed == 1)
            {
                var workbench = this.World.FindObject<ItemObject>(action.WorkbenchID);
                if (workbench == null)
                    throw new Exception();

                var bi = Workbenches.GetWorkbenchInfo(workbench.ItemID);

                var buildableItem = bi.FindBuildableItem(action.BuildableItemKey);
                if (buildableItem == null)
                    throw new Exception();

                this.ActionTotalTicks = GetTicks(buildableItem.SkillID);
            }

            if (this.ActionTicksUsed < this.ActionTotalTicks)
            {
                return ActionState.Ok;
            }
            else
            {
                var workbench = this.World.FindObject<ItemObject>(action.WorkbenchID);

                var report = new BuildItemActionReport(this, action.BuildableItemKey);

                if (workbench == null)
                {
                    SendFailReport(report, "cannot find building");
                    return ActionState.Fail;
                }

                /*
                            if (this.ActionTicksLeft != 0)
                            {
                                var ok = building.VerifyBuildItem(this, action.SourceObjectIDs, action.DstItemID);
                                if (!ok)
                                    SetActionError("build item request is invalid");
                                return ok;
                            }
                 */

                var bi2 = Workbenches.GetWorkbenchInfo(workbench.ItemID);

                var bi = bi2.FindBuildableItem(action.BuildableItemKey);

                var item = PerformBuildItem(this, bi, action.SourceObjectIDs);

                if (item == null)
                {
                    SendFailReport(report, "unable to build the item");
                    return ActionState.Fail;
                }

                report.ItemObjectID = item.ObjectID;
                SendReport(report);

                return ActionState.Done;
            }
        }
Example #5
0
        ActionState ProcessAction(BuildItemAction action)
        {
            if (this.ActionTicksUsed == 1)
            {
                var workbench = this.World.FindObject <ItemObject>(action.WorkbenchID);
                if (workbench == null)
                {
                    throw new Exception();
                }

                var bi = Workbenches.GetWorkbenchInfo(workbench.ItemID);

                var buildableItem = bi.FindBuildableItem(action.BuildableItemKey);
                if (buildableItem == null)
                {
                    throw new Exception();
                }

                this.ActionTotalTicks = GetTicks(buildableItem.SkillID);
            }

            if (this.ActionTicksUsed < this.ActionTotalTicks)
            {
                return(ActionState.Ok);
            }
            else
            {
                var workbench = this.World.FindObject <ItemObject>(action.WorkbenchID);

                var report = new BuildItemActionReport(this, action.BuildableItemKey);

                if (workbench == null)
                {
                    SendFailReport(report, "cannot find building");
                    return(ActionState.Fail);
                }

                /*
                 *                      if (this.ActionTicksLeft != 0)
                 *                      {
                 *                              var ok = building.VerifyBuildItem(this, action.SourceObjectIDs, action.DstItemID);
                 *                              if (!ok)
                 *                                      SetActionError("build item request is invalid");
                 *                              return ok;
                 *                      }
                 */


                var bi2 = Workbenches.GetWorkbenchInfo(workbench.ItemID);

                var bi = bi2.FindBuildableItem(action.BuildableItemKey);

                var item = PerformBuildItem(this, bi, action.SourceObjectIDs);

                if (item == null)
                {
                    SendFailReport(report, "unable to build the item");
                    return(ActionState.Fail);
                }

                report.ItemObjectID = item.ObjectID;
                SendReport(report);

                return(ActionState.Done);
            }
        }
Example #6
0
        static void HandleBuildItem(string str)
        {
            var living = GameData.Data.FocusedObject;

            var workbench = living.Environment.GetContents(living.Location).OfType <ItemObject>()
                            .Where(item => item.ItemCategory == ItemCategory.Workbench && item.IsInstalled)
                            .FirstOrDefault();

            if (workbench == null)
            {
                Inform("No workbench");
                return;
            }

            var wbInfo = Workbenches.GetWorkbenchInfo(workbench.ItemID);

            BuildableItem buildableItem;

            {
                var dlg = new ItemSelectorDialog();
                dlg.Owner       = App.Current.MainWindow;
                dlg.DataContext = wbInfo.BuildableItems;
                dlg.Title       = "Buildable Items";
                bool?res = dlg.ShowDialog();

                if (res.HasValue == false || res == false)
                {
                    return;
                }

                buildableItem = (BuildableItem)dlg.SelectedItem;
            }

            foreach (var component in buildableItem.FixedBuildMaterials)
            {
                var obs = living.Inventory.Where(item => component.Match(item));

                if (obs.Any() == false)
                {
                    Inform("Missing required components");
                    return;
                }
            }

            List <ItemObject> materials = new List <ItemObject>();

            foreach (var component in buildableItem.FixedBuildMaterials)
            {
                var obs = living.Inventory.Where(item => component.Match(item));

                var dlg = new ItemSelectorDialog();
                dlg.Owner       = App.Current.MainWindow;
                dlg.DataContext = obs;
                dlg.Title       = "Select component";
                bool?res = dlg.ShowDialog();
                if (res.HasValue == false || res == false)
                {
                    return;
                }
                materials.Add((ItemObject)dlg.SelectedItem);
            }

            var action = new BuildItemAction(workbench, buildableItem.Key, materials);

            action.GUID = new ActionGUID(living.World.PlayerID, 0);
            living.RequestAction(action);
        }