예제 #1
0
        private void Move(PartContent aPart, int qty, KASModuleContainer destContainer)
        {
            if (destContainer.MaxSizeReached(aPart.grabModule, qty))
            {
                fxSndBipWrong.audio.Play();
                ScreenMessages.PostScreenMessage("Max size of the destination container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            PartContent dest = PartContent.Get(destContainer.contents, aPart.name);

            if (aPart.pristine_count > 0)
            {
                int delta = Math.Min(aPart.pristine_count, qty);
                aPart.pristine_count -= delta;
                dest.pristine_count  += delta;
                qty -= delta;
            }
            while (qty > 0 && aPart.instances.Count > 0)
            {
                dest.Load(aPart.PopInstance());
                qty--;
            }
            RefreshTotalSize();
            destContainer.RefreshTotalSize();
        }
예제 #2
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            if (node.HasNode("CONTENT") || node.HasNode("CONTENT_PART"))
            {
                contents.Clear();
            }

            foreach (ConfigNode cn in node.nodes)
            {
                if (cn.name != "CONTENT" && cn.name != "CONTENT_PART")
                {
                    continue;
                }

                string      AvPartName = cn.GetValue("name") ?? "null";
                PartContent item       = PartContent.Get(contents, AvPartName);

                if (item != null)
                {
                    item.Load(cn);
                }
                else
                {
                    KAS_Shared.DebugError("Load(Container) - Cannot retrieve " + AvPartName + " from PartLoader !");
                }
            }
        }
예제 #3
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            // Do not load ScienceData nodes for this module's host part (a KAS container) as they were only stored in case the vessel was
            // recovered. The original parts still contain the science data. (See OnSave.)

            if (node.HasNode("CONTENT") || node.HasNode("CONTENT_PART"))
            {
                contents.Clear();
            }

            foreach (ConfigNode cn in node.nodes)
            {
                if (cn.name != "CONTENT" && cn.name != "CONTENT_PART")
                {
                    continue;
                }

                string      AvPartName = cn.GetValue("name") ?? "null";
                PartContent item       = PartContent.Get(contents, AvPartName);

                if (item != null)
                {
                    item.Load(cn);
                }
                else
                {
                    KAS_Shared.DebugError("Load(Container) - Cannot retrieve " + AvPartName + " from PartLoader !");
                }
            }
        }
예제 #4
0
        private void Take(PartContent avPart)
        {
            if (waitAndGrabRunning)
            {
                KAS_Shared.DebugError("Take(Container) Take action is already running, please wait !");
                return;
            }
            if (!FlightGlobals.ActiveVessel.isEVA)
            {
                KAS_Shared.DebugError("Take(Container) Can only grab from EVA!");
                return;
            }
            KASModuleGrab grabbed = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel);

            if (grabbed && grabbed.part.packed)
            {
                KAS_Shared.DebugError("Take(Container) EVA holding a packed part!");
                return;
            }
            if (avPart.pristine_count <= 0 && avPart.instances.Count > 0)
            {
                if (TakeStoredInstance(avPart.instances[0], FlightGlobals.ActiveVessel))
                {
                    avPart.PopInstance();
                    RefreshTotalSize();
                }
                return;
            }
            KASModuleGrab prefabGrabModule = avPart.grabModule;
            // get grabbed position and rotation
            Vector3    pos = FlightGlobals.ActiveVessel.rootPart.transform.TransformPoint(prefabGrabModule.evaPartPos);
            Quaternion rot = FlightGlobals.ActiveVessel.rootPart.transform.rotation * Quaternion.Euler(prefabGrabModule.evaPartDir);

            //Move away the part at creation
            pos += new Vector3(0f, 0f, 100);

            //Part newPart = KAS_Shared.CreatePart(avPart, pos, rot, this.part);
            Part newPart = KAS_Shared.CreatePart(avPart.name, pos, rot, this.part);

            if (!newPart)
            {
                KAS_Shared.DebugError("Take(Container) failed to create the part !");
                return;
            }

            KASModuleGrab moduleGrab = newPart.GetComponent <KASModuleGrab>();

            if (!moduleGrab)
            {
                KAS_Shared.DebugError("Take(Container) Cannot grab the part taken, no grab module found !");
                return;
            }
            avPart.pristine_count--;
            RefreshTotalSize();
            StartCoroutine(WaitAndGrab(moduleGrab, FlightGlobals.ActiveVessel));
        }
예제 #5
0
        private void Add(AvailablePart avPart, int qty)
        {
            var item = PartContent.Get(contents, avPart.name);

            if (item != null)
            {
                item.pristine_count += qty;
                RefreshTotalSize();
            }
        }
예제 #6
0
        private void Add(AvailablePart avPart, int qty)
        {
            var item = PartContent.Get(contents, avPart.name);

            if (item != null)
            {
                item.pristine_count += qty;
                RefreshTotalSize();
            }

            GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
        }
예제 #7
0
        private Dictionary <string, PartContent> GetAvailableContents()
        {
            var edct = new Dictionary <string, PartContent>();

            foreach (AvailablePart avPart in PartLoader.LoadedPartsList)
            {
                if (ResearchAndDevelopment.PartModelPurchased(avPart))
                {
                    PartContent.Get(edct, avPart.name);
                }
            }
            return(edct);
        }
예제 #8
0
        private void Remove(AvailablePart avPart, int qty)
        {
            var item = PartContent.Get(contents, avPart.name, false);

            if (item != null)
            {
                item.pristine_count = Math.Max(0, item.pristine_count - qty);
                RefreshTotalSize();
            }
            else
            {
                KAS_Shared.DebugLog("Remove(Container) - Nothing to remove");
            }
        }
예제 #9
0
        private void StoreGrabbedPart()
        {
            KASModuleGrab moduleGrab = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel);

            if (!moduleGrab || moduleGrab.part.packed)
            {
                fxSndBipWrong.audio.Play();
                ScreenMessages.PostScreenMessage("You didn't grab anything to store !", 5, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            if (!moduleGrab.storable)
            {
                fxSndBipWrong.audio.Play();
                ScreenMessages.PostScreenMessage("This part cannot be stored !", 5, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            if (MaxSizeReached(moduleGrab, 1))
            {
                fxSndBipWrong.audio.Play();
                ScreenMessages.PostScreenMessage("Max size of the container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            PartContent info = PartContent.Get(contents, moduleGrab.part.partInfo.name);

            if (info == null)
            {
                fxSndBipWrong.audio.Play();
                ScreenMessages.PostScreenMessage("Could not store part!", 5, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            if (moduleGrab.stateless)
            {
                info.pristine_count++;
            }
            else
            {
                info.Load(KAS_Shared.SavePartSnapshot(moduleGrab.part));
            }
            RefreshTotalSize();
            moduleGrab.Drop(true);
            moduleGrab.part.Die();
            fxSndStore.audio.Play();
        }
예제 #10
0
            public static PartContent Get(Dictionary <string, PartContent> table, string name, bool create = true)
            {
                PartContent item;

                if (!table.TryGetValue(name, out item) && create)
                {
                    AvailablePart avPart = PartLoader.getPartInfoByName(name);

                    if (avPart != null)
                    {
                        KASModuleGrab grab = avPart.partPrefab.GetComponent <KASModuleGrab>();

                        if (grab != null && grab.storable)
                        {
                            item = new PartContent(avPart, grab);
                            table.Add(name, item);
                        }
                    }
                }

                return(item);
            }
예제 #11
0
            public static PartContent Get(Dictionary<string,PartContent> table, string name, bool create = true)
            {
                PartContent item;

                if (!table.TryGetValue(name, out item) && create)
                {
                    AvailablePart avPart = PartLoader.getPartInfoByName(name);

                    if (avPart != null)
                    {
                        KASModuleGrab grab = avPart.partPrefab.GetComponent<KASModuleGrab>();

                        if (grab != null && grab.storable)
                        {
                            item = new PartContent(avPart, grab);
                            table.Add(name, item);
                        }
                    }
                }

                return item;
            }
예제 #12
0
        private void Take(PartContent avPart)
        {
            if (waitAndGrabRunning)
            {
                KAS_Shared.DebugError("Take(Container) Take action is already running, please wait !");
                return;
            }
            if (!FlightGlobals.ActiveVessel.isEVA)
            {
                KAS_Shared.DebugError("Take(Container) Can only grab from EVA!");
                return;
            }
            KASModuleGrab grabbed = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel);
            if (grabbed && grabbed.part.packed)
            {
                KAS_Shared.DebugError("Take(Container) EVA holding a packed part!");
                return;
            }
            if (avPart.pristine_count <= 0 && avPart.instances.Count > 0)
            {
                if (TakeStoredInstance(avPart.instances[0], FlightGlobals.ActiveVessel))
                {
                    avPart.PopInstance();
                    RefreshTotalSize();
                }
                return;
            }
            KASModuleGrab prefabGrabModule = avPart.grabModule;
            // get grabbed position and rotation
            Vector3 pos = FlightGlobals.ActiveVessel.rootPart.transform.TransformPoint(prefabGrabModule.evaPartPos);
            Quaternion rot = FlightGlobals.ActiveVessel.rootPart.transform.rotation * Quaternion.Euler(prefabGrabModule.evaPartDir);

            //Move away the part at creation
            pos += new Vector3(0f, 0f, 100);

            //Part newPart = KAS_Shared.CreatePart(avPart, pos, rot, this.part);
            Part newPart = KAS_Shared.CreatePart(avPart.name, pos, rot, this.part);
            if (!newPart)
            {
                KAS_Shared.DebugError("Take(Container) failed to create the part !");
                return;
            }

            KASModuleGrab moduleGrab = newPart.GetComponent<KASModuleGrab>();
            if (!moduleGrab)
            {
                KAS_Shared.DebugError("Take(Container) Cannot grab the part taken, no grab module found !");
                return;
            }
            avPart.pristine_count--;
            RefreshTotalSize();
            StartCoroutine(WaitAndGrab(moduleGrab, FlightGlobals.ActiveVessel));
        }
예제 #13
0
 private void Move(PartContent aPart, int qty, KASModuleContainer destContainer)
 {
     if (destContainer.MaxSizeReached(aPart.grabModule, qty))
     {
         fxSndBipWrong.audio.Play();
         ScreenMessages.PostScreenMessage("Max size of the destination container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
         return;
     }
     PartContent dest = PartContent.Get(destContainer.contents, aPart.name);
     if (aPart.pristine_count > 0)
     {
         int delta = Math.Min(aPart.pristine_count, qty);
         aPart.pristine_count -= delta;
         dest.pristine_count += delta;
         qty -= delta;
     }
     while (qty > 0 && aPart.instances.Count > 0)
     {
         dest.Load(aPart.PopInstance());
         qty--;
     }
     RefreshTotalSize();
     destContainer.RefreshTotalSize();
 }