Ejemplo n.º 1
0
        public MoveBuildItemAssignment(IJobObserver parent, IItemObject workplace, string buildableItemKey, IItemObject[] items)
            : base(parent, workplace.Environment, workplace.Location)
        {
            m_workplace        = workplace;
            m_items            = items;
            m_buildableItemKey = buildableItemKey;

            var bii = Workbenches.GetWorkbenchInfo(workplace.ItemID);
            var bi  = bii.FindBuildableItem(buildableItemKey);

            this.LaborID = bi.LaborID;
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 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);
        }