Exemple #1
0
        /// <inheritdoc/>
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            pageList.Clear();
            var node = KIS_Shared.GetBaseConfigNode(this);

            foreach (string page in node.GetValues("page"))
            {
                pageList.Add(page);
            }
            if (pageList.Count > 0)
            {
                pageIndex = 0;
                pageTotal = pageList.Count;
                guiObj    = new GameObject("KISManualDialog-" + part.flightID);
                var dlg = guiObj.AddComponent <GuiDialog>();
                dlg.dialogFunction = GuiReader;

                pageTexture = GameDatabase.Instance.GetTexture(pageList[0], false);
                UISoundPlayer.instance.Play(bookOpenSndPath);
            }
            else
            {
                DebugEx.Info("The book has no pages configured");
            }
        }
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            string shipProp = this.settings.ShipPropellantName;
            string evaProp  = this.settings.EvaPropellantName;

            if (useFrom != KIS_Item.UseFrom.KeyUp && item.inventory.invType == ModuleKISInventory.InventoryType.Pod)
            {
                double fuelLeft = 0;
                double fuelMax  = 0;
                fuelLeft = GetCanisterFuelResource(item).amount;
                fuelMax  = GetCanisterFuelResource(item).maxAmount;

                double fuelRequest = item.inventory.part.RequestResource(shipProp, fuelMax - fuelLeft);
                item.SetResource(evaProp, fuelLeft + fuelRequest);

                if (fuelRequest < fuelMax - fuelLeft)
                {
                    ScreenMessaging.ShowPriorityScreenMessage("Warning! Only " + Math.Round(fuelRequest, 2).ToString() + " units of " + shipProp + " were left to fill the tank!");
                }
                else
                {
                    ScreenMessaging.ShowPriorityScreenMessage("Fuel tank refueled with " + Math.Round(fuelRequest, 2).ToString() + " units of " + shipProp + ".");
                }
                UISoundPlayer.instance.Play(refuelSndPath);
            }
            else
            {
                base.OnItemUse(item, useFrom);
            }
        }
 public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
 {
     // Check if grab key is pressed
     if (useFrom == KIS_Item.UseFrom.KeyDown)
     {
         KISAddonPickup.instance.EnableAttachMode();
     }
     if (useFrom == KIS_Item.UseFrom.KeyUp)
     {
         KISAddonPickup.instance.DisableAttachMode();
     }
 }
 public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
 {
     if (useFrom != KIS_Item.UseFrom.KeyUp && item.equippedPart != null)
     {
         // Only play if the item is equipped, since we need a real part for this to work.
         // Multiple modules are not supported!
         var soundPlayerModule = item.equippedPart.GetComponent <ModuleKISItemSoundPlayer>();
         if (soundPlayerModule != null)
         {
             soundPlayerModule.TogglePlayStateEvent();
         }
     }
 }
 /// <inheritdoc/>
 public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
 {
     if (useFrom != KIS_Item.UseFrom.KeyUp)
     {
         if (item.inventory.invType == ModuleKISInventory.InventoryType.Pod)
         {
             RefillCanister(item); // Refuel canister item.
         }
         else if (item.inventory.invType == ModuleKISInventory.InventoryType.Eva)
         {
             RefillEVAPack(item); // Refuel EVA pack from canister.
         }
     }
 }
 public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
 {
     if (useFrom != KIS_Item.UseFrom.KeyUp)
     {
         if (item.inventory.sndFx.audio.isPlaying)
         {
             item.inventory.sndFx.audio.Stop();
         }
         else
         {
             UISoundPlayer.instance.Play(sndPath);
         }
     }
 }
 public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
 {
     if (useFrom != KIS_Item.UseFrom.KeyUp)
     {
         if (item.inventory.sndFx.audio.isPlaying)
         {
             item.inventory.sndFx.audio.Stop();
         }
         else
         {
             item.inventory.PlaySound(sndPath, false, false);
         }
     }
 }
Exemple #8
0
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            if (useFrom != KIS_Item.UseFrom.KeyUp)
            {
                item.StackRemove();
                eatCount++;

                if (eatCount > 3)
                {
                    Logger.logInfo("Burp incoming...");
                    System.Random rnd   = new System.Random();
                    int           delay = rnd.Next(1, 5);
                    item.inventory.DelayedAction(Burp, item, delay);
                    eatCount = 0;
                }
                item.inventory.PlaySound(eatSndPath, false, false);
            }
        }
Exemple #9
0
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            if (useFrom != KIS_Item.UseFrom.KeyUp)
            {
                item.StackRemove();
                eatCount++;

                if (eatCount > 3)
                {
                    DebugEx.Fine("Burp incoming...");
                    System.Random rnd   = new System.Random();
                    int           delay = rnd.Next(1, 5);
                    item.inventory.DelayedAction(Burp, item, delay);
                    eatCount = 0;
                }
                UISoundPlayer.instance.Play(eatSndPath);
            }
        }
Exemple #10
0
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            if (useFrom != KIS_Item.UseFrom.KeyUp)
            {
                item.StackRemove(1);
                eatCount++;

                if (eatCount > 3)
                {
                    DebugEx.Fine("Burp incoming...");
                    Random rnd   = new System.Random();
                    int    delay = rnd.Next(1, 5);
                    AsyncCall.CallOnTimeout(item.inventory, delay, () => Burp(item));
                    eatCount = 0;
                }
                UISoundPlayer.instance.Play(eatSndPath);
            }
        }
Exemple #11
0
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            if (ModEnabled && KISIntegrationEnabled)
            {
                if (useFrom != KIS_Item.UseFrom.KeyUp && item.inventory.invType == ModuleKISInventory.InventoryType.Pod)
                {
                    double fuelLeft = 0;
                    double fuelMax  = 0;


                    fuelLeft = ModuleKISItemEvaPropellant.GetCanisterFuelResource(item).amount;
                    fuelMax  = ModuleKISItemEvaPropellant.GetCanisterFuelResource(item).maxAmount;

                    double takenFuel   = item.inventory.part.RequestResource(shipPropName, (fuelMax - fuelLeft) / fuelConvFactor);
                    double fuelRequest = takenFuel * fuelConvFactor;
                    item.UpdateResource(resourceName, fuelLeft + fuelRequest);

                    if (fuelRequest + 0.001 < fuelMax - fuelLeft)                      //0.001 for floating point rounding issues. Don't want to trigger insufficient fuel all the time.
                    {
                        if (ShowLowFuelWarning)
                        {
                            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "OnItemUse", "Low EVA Fuel!", "Warning! Only " + Math.Round(takenFuel, 2).ToString() + " units of " + shipPropName + " were available to refill the EVA Canister! Meaning it only has " + Math.Round(fuelLeft + fuelRequest, 2).ToString() + " units of " + resourceName + "!", "OK", false, HighLogic.UISkin);
                        }
                    }
                    else
                    {
                        if (ShowInfoMessage)
                        {
                            ScreenMessaging.ShowPriorityScreenMessage("Fuel tank refueled with " + Math.Round(takenFuel, 2).ToString() + " units of " + shipPropName + ".");
                        }
                    }
                    UISoundPlayer.instance.Play(refuelSndPath);
                }
                else
                {
                    base.OnItemUse(item, useFrom);
                }
            }
            else
            {
                base.OnItemUse(item, useFrom);
            }
        }
Exemple #12
0
        /// <inheritdoc/>
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            pageList.Clear();
            var node = KIS_Shared.GetBaseConfigNode(this);

            foreach (string page in node.GetValues("page"))
            {
                pageList.Add(page);
            }
            if (pageList.Count > 0)
            {
                pageIndex   = 0;
                pageTotal   = pageList.Count;
                pageTexture = GameDatabase.Instance.GetTexture(pageList[0], false);
                showPage    = true;
                UISoundPlayer.instance.Play(bookOpenSndPath);
            }
            else
            {
                Debug.LogError("The book has no pages configured");
            }
        }
Exemple #13
0
 public virtual void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
 {
 }
Exemple #14
0
 public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
 {
     if (useFrom != KIS_Item.UseFrom.KeyUp)
     {
         if (item.inventory.invType == ModuleKISInventory.InventoryType.Pod)
         {
             // Refuel item
             ScreenMessages.PostScreenMessage("Fuel tank refueled", 5, ScreenMessageStyle.UPPER_CENTER);
             foreach (KIS_Item.ResourceInfo itemRessource in item.GetResources())
             {
                 if (itemRessource.resourceName == "EVA Propellant")
                 {
                     item.SetResource("EVA Propellant", itemRessource.maxAmount);
                     item.inventory.PlaySound(refuelSndPath, false, false);
                 }
             }
         }
         if (item.inventory.invType == ModuleKISInventory.InventoryType.Eva)
         {
             // Refuel eva
             foreach (KIS_Item.ResourceInfo itemRessource in item.GetResources())
             {
                 if (itemRessource.resourceName == "EVA Propellant")
                 {
                     PartResource evaRessource = item.inventory.part.GetComponent <PartResource>();
                     if (evaRessource)
                     {
                         double amountToFill = evaRessource.maxAmount - evaRessource.amount;
                         if (itemRessource.amount > amountToFill)
                         {
                             ScreenMessages.PostScreenMessage("EVA pack refueled", 5, ScreenMessageStyle.UPPER_CENTER);
                             evaRessource.amount = evaRessource.maxAmount;
                             item.SetResource("EVA Propellant", (itemRessource.amount - amountToFill));
                             if (item.equippedPart)
                             {
                                 PartResource equippedTankRessource = item.equippedPart.Resources.list.Find(p => p.resourceName == "EVA Propellant");
                                 if (equippedTankRessource)
                                 {
                                     equippedTankRessource.amount = (itemRessource.amount - amountToFill);
                                 }
                             }
                             item.inventory.PlaySound(refuelSndPath, false, false);
                         }
                         else
                         {
                             if (itemRessource.amount == 0)
                             {
                                 ScreenMessages.PostScreenMessage("Fuel tank is empty ! Cannot refuel EVA pack", 5, ScreenMessageStyle.UPPER_CENTER);
                             }
                             else
                             {
                                 ScreenMessages.PostScreenMessage("Available propellant is not enough to refuel, EVA pack partially refueled", 5, ScreenMessageStyle.UPPER_CENTER);
                             }
                             evaRessource.amount += itemRessource.amount;
                             item.SetResource("EVA Propellant", 0);
                             item.inventory.PlaySound(refuelSndPath, false, false);
                         }
                     }
                 }
             }
         }
     }
 }
        public bool isWeldingTool = false;         // false => screw tool

        // check if the pointed part can be attach with our current tool
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            // Check if grab key is pressed
            //if (useFrom == KIS_Item.UseFrom.KeyDown)
            //{
            //    KISAddonPickup.instance.EnableAttachMode();
            //}

            // Check if grab key is pressed
            if (useFrom == KIS_Item.UseFrom.KeyDown)
            {
                if (KISAddonPointer.isRunning && KISAddonPointer.pointerTarget != KISAddonPointer.PointerTarget.PartMount)
                {
                    //float attachPartMass = KISAddonPointer.partToAttach.mass + KISAddonPointer.partToAttach.GetResourceMass();
                    //if (attachPartMass < attachMaxMass)
                    {
                        //test if the tool can attach this part (screw or weld)
                        //default (when ModuleAttachMode is not here) : magical yes
                        bool testIfCanAttachPart = true;
                        if (KISAddonPointer.partToAttach.Modules.Contains("ModuleAttachMode"))
                        {
                            ModuleAttachMode mkpam = (KISAddonPointer.partToAttach.Modules["ModuleAttachMode"] as ModuleAttachMode);
                            if (!mkpam.canBeWeld && !mkpam.canBeScrewed)
                            {
                                ScreenMessages.PostScreenMessage("This part can't be attached", 5, ScreenMessageStyle.UPPER_CENTER);
                                testIfCanAttachPart = false;
                            }
                            else
                            {
                                testIfCanAttachPart = isWeldingTool ? mkpam.canBeWeld : mkpam.canBeScrewed;
                                item.PlaySound(KIS_Shared.bipWrongSndPath);
                                if (!testIfCanAttachPart)
                                {
                                    ScreenMessages.PostScreenMessage("This part can't be attached with this tool: it need a " +
                                                                     (isWeldingTool ? "screwdriver" : "weld tool"), 5, ScreenMessageStyle.UPPER_CENTER);
                                }
                            }
                        }
                        if (testIfCanAttachPart)
                        {
                            //KISAddonPickup.instance.pointerMode = KISAddonPickup.PointerMode.Attach;
                            //KISAddonPointer.allowStack = allowStack;
                            //item.PlaySound(changeModeSndPath);
                            KISAddonPickup.instance.EnableAttachMode();
                        }
                    }
                    //else
                    //{
                    //	item.PlaySound(KIS_Shared.bipWrongSndPath);
                    //	ScreenMessages.PostScreenMessage("This part is too heavy for this tool", 5, ScreenMessageStyle.UPPER_CENTER);
                    //}
                }

                if (useFrom == KIS_Item.UseFrom.KeyUp)
                {
                    KISAddonPickup.instance.DisableAttachMode();
                }
            }
            //if (useFrom == KIS_Item.UseFrom.KeyUp)
            //{
            //    if (KISAddonPointer.isRunning && KISAddonPickup.instance.pointerMode == KISAddonPickup.PointerMode.Attach)
            //    {
            //        KISAddonPickup.instance.pointerMode = KISAddonPickup.PointerMode.Drop;
            //        KISAddonPointer.allowStack = false;
            //        item.PlaySound(changeModeSndPath);
            //    }
            //}
        }