Example #1
0
        public double GetRecoveryPercent(bool dry = true)
        {
            double Vt        = GetVelocity(dry);
            bool   recovered = false;

            if (Settings1.Instance.FlatRateModel)
            {
                recovered = Vt < Settings2.Instance.CutoffVelocity;
            }
            else
            {
                recovered = Vt < Settings2.Instance.HighCut;
            }

            if (!recovered)
            {
                return(0);
            }

            double recoveryPercent = 0;

            if (recovered && Settings1.Instance.FlatRateModel)
            {
                recoveryPercent = 1;
            }
            else if (recovered && !Settings1.Instance.FlatRateModel)
            {
                recoveryPercent = RecoveryItem.GetVariableRecoveryValue(Vt);
            }

            return(Math.Round(100 * recoveryPercent, 2));
        }
Example #2
0
        public void FixedUpdate()
        {
            //For each vessel in the watchlist, check to see if it reaches an atm density of 0.01 and if so, pre-recover it
            foreach (Guid id in new List <Guid>(StageWatchList))
            {
                Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == id);
                if (vessel == null)
                {
                    StageWatchList.Remove(id);
                    continue;
                }
                if ((!vessel.loaded || vessel.packed) && vessel.altitude < cutoffAlt)
                {
                    Debug.Log("[SR] Vessel " + vessel.vesselName + " (" + id + ") is about to be destroyed. Pre-recovering Kerbals.");
                    RecoveryItem recItem = new RecoveryItem(vessel);

                    //Pre-recover the Kerbals
                    recItem.PreRecoverKerbals();

                    //Add the ship to the RecoveryQueue to be handled by the VesselDestroy event
                    instance.RecoveryQueue.Add(recItem);

                    // Debug.Log("[SR] Current RecoveryQueue size: " + instance.RecoveryQueue.Count);

                    StageWatchList.Remove(id);
                }
            }
        }
 public void Recover(IPAddress endpoint, IConnectionFactory connectionFactory, Action<IConnection> clientRecoveredCallback)
 {
     lock (_lock)
     {
         RecoveryItem recoveryItem = new RecoveryItem(endpoint, connectionFactory, clientRecoveredCallback);
         _toRecover.Add(recoveryItem);
         _timer.Start();
     }
 }
Example #4
0
 public void Recover(IPAddress endpoint, IConnectionFactory connectionFactory, Action <IConnection> clientRecoveredCallback)
 {
     lock (_lock)
     {
         RecoveryItem recoveryItem = new RecoveryItem(endpoint, connectionFactory, clientRecoveredCallback);
         _toRecover.Add(recoveryItem);
         _timer.Start();
     }
 }
Example #5
0
        private static void RecoverVessel(Vessel v, bool preRecovery)
        {
            //Indicate that we've at least attempted recovery of this vessel
            RecoverAttemptLog.Add(v.id, Planetarium.GetUniversalTime());

            bool OnlyBlacklistedItems = true;

            foreach (ProtoPartSnapshot pps in v.protoVessel.protoPartSnapshots)
            {
                if (!Settings.Instance.BlackList.Contains(pps.partInfo.title))
                {
                    OnlyBlacklistedItems = false;
                    break;
                }
            }
            if (OnlyBlacklistedItems)
            {
                return;
            }

            //If we got this far, we can assume we're going to be attempting to recover the vessel, so we should fire the processing event
            APIManager.instance.OnRecoveryProcessingStart.Fire(v);

            //Create a new RecoveryItem. Calling this calculates everything regarding the success or failure of the recovery. We need it for display purposes in the main gui
            Log.Info("[SR] Searching in RecoveryQueue (" + instance.RecoveryQueue.Count + ") for " + v.id);
            RecoveryItem Stage;

            if (instance.RecoveryQueue.Count > 0 && instance.RecoveryQueue.Exists(ri => ri.vessel.id == v.id))
            {
                Stage = instance.RecoveryQueue.Find(ri => ri.vessel.id == v.id);
                instance.RecoveryQueue.Remove(Stage);
                Log.Info("[SR] Found vessel in the RecoveryQueue.");
            }
            else
            {
                Stage = new RecoveryItem(v);
            }
            Stage.Process(preRecovery);
            //Fire the pertinent RecoveryEvent (success or failure). Aka, make the API do its work
            Stage.FireEvent();
            //Add the Stage to the correct list of stages. Either the Recovered Stages list or the Destroyed Stages list, for display on the main gui
            Stage.AddToList();
            //Post a message to the stock message system, if people are still using that.
            Stage.PostStockMessage();
            //Remove all crew on the vessel
            Stage.RemoveCrew();

            if (preRecovery)
            {
                //remove the vessel so it doesn't get destroyed
                v.Die();
            }

            //Fire the event stating we are done processing
            APIManager.instance.OnRecoveryProcessingFinish.Fire(v);
        }
Example #6
0
 /// <summary>
 /// Adds the stage's parts to ScrapYard if it was recovered
 /// </summary>
 /// <param name="stage">The processed stage</param>
 public static void AddToScrapYard(RecoveryItem stage)
 {
     if (stage.recovered)
     {
         Debug.Log("[StageRecovery] Attempting to add parts to ScrapYard inventory");
         ScrapYardWrapper.AddPartsToInventory(stage.vessel.protoVessel.protoPartSnapshots.Select((p) =>
         {
             ConfigNode tmp = new ConfigNode();
             p.Save(tmp);
             return(tmp);
         }).ToList(), true);
     }
 }
Example #7
0
        public override void Request(object sender, CqGroupMessageEventArgs e, string groupPath)
        {
            string[] arr = e.Message.Split(' ');

            if (arr.Length > 1)
            {
                string propItem = iniTool.IniReadValue(devPath, itemIni, arr[1], "效果");

                if (propItem != "")
                {
                    RecoveryItem recoveryItem = GetRecoveryItem(arr[1]);

                    string propItemInfo = "[" + arr[1] + "]" + Environment.NewLine;

                    foreach (string name in GameConfig.recoveryItem)
                    {
                        propItemInfo += name + "=" + iniTool.IniReadValue(devPath, itemIni, arr[1], name) + Environment.NewLine;
                    }

                    propItemInfo = SubRN(propItemInfo);

                    Common.CqApi.SendGroupMessage(e.FromGroup, propItemInfo);

                    return;
                }

                string equipItem = iniTool.IniReadValue(devPath, equipIni, arr[1], "装备方式");

                if (equipItem != "")
                {
                    Equip equip = GetEquip(arr[1]);

                    string equipInfo = "[" + arr[1] + "]" + Environment.NewLine;

                    foreach (string eq in GameConfig.equip)
                    {
                        equipInfo += eq + "=" + iniTool.IniReadValue(devPath, equipIni, arr[1], eq) + Environment.NewLine;
                    }

                    equipInfo = SubRN(equipInfo);

                    Common.CqApi.SendGroupMessage(e.FromGroup, equipInfo);

                    return;
                }

                Common.CqApi.SendGroupMessage(e.FromGroup, "不能查看:" + arr[1]);

                return;
            }
        }
Example #8
0
    public ItemList(XmlReader reader)
    {
        while (reader.Read())
        {
            if (reader.NodeType == XmlNodeType.Element && reader.Name == "inventoryItem")
            {
                int           type = int.Parse(reader.GetAttribute("Type"));
                inventoryItem item; //can be overwritten by the switch

                # region switch (type)
                switch (type)
                {
                case 1:     //medicine
                    item = new RecoveryItem();
                    break;

                case 2:     //pokeball
                    item       = new Pokeball();
                    item.Power = double.Parse(reader.GetAttribute("Power"));
                    break;

                case 3:     //TM
                    item = new TMItem();
                    break;

                case 4:     //berry
                    item = new Berry();
                    break;

                case 5:                    //holdable item
                    //item = new MainItem();
                    item = new HoldItem(); //still returns "MainItem"";
                    break;

                case 6:     //key item
                    item = new KeyItem();
                    break;

                default:
                    item = new inventoryItem();
                    break;
                }
                # endregion

                item.ID          = reader.GetAttribute("ID");
                item.Name        = reader.GetAttribute("Name");
                item.type        = type;
                item.Description = reader.ReadElementString();

                items.Add(item.ID, item);
            }
Example #9
0
        // 获取药品信息
        protected RecoveryItem GetRecoveryItem(string ItemName)
        {
            RecoveryItem recoveryItem = new RecoveryItem();

            string itemInfo = "";

            foreach (string name in GameConfig.recoveryItem)
            {
                itemInfo += iniTool.IniReadValue(devPath, itemIni, ItemName, name) + ",";
            }

            recoveryItem.Add(itemInfo);

            return(recoveryItem);
        }
Example #10
0
        public void FixedUpdate()
        {
            if (!sceneChangeComplete)
            {
                return;
            }
            //For each vessel in the watchlist, check to see if it reaches an atm density of 0.01 and if so, pre-recover it
            foreach (Guid id in new List <Guid>(StageWatchList))
            {
                Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == id);
                if (vessel == null)
                {
                    StageWatchList.Remove(id);
                    continue;
                }
                if ((!vessel.loaded || vessel.packed) && vessel.mainBody == Planetarium.fetch.Home && vessel.altitude < cutoffAlt && vessel.altitude > 0)
                {
                    if (!SRShouldRecover(vessel))
                    {
                        StageWatchList.Remove(id);
                        continue;
                    }
                    Debug.Log($"[SR] Vessel {vessel.vesselName} ({id}) is about to be destroyed at altitude {vessel.altitude}. Pre-recovering Kerbals.");
                    RecoveryItem recItem = new RecoveryItem(vessel);

                    //Pre-recover the Kerbals
                    recItem.PreRecoverKerbals();

                    //Add the ship to the RecoveryQueue to be handled by the VesselDestroy event
                    RecoveryQueue.Add(recItem);

                    // Debug.Log("[SR] Current RecoveryQueue size: " + instance.RecoveryQueue.Count);

                    StageWatchList.Remove(id);
                }
            }

            //foreach (RecoveryItem recItem in new List<RecoveryItem>(RecoveryQueue)) //Assignment validation is failing :(
            //{
            //    if (Planetarium.GetUniversalTime() - recItem.PreRecoveredTime > 10) //must be destroyed within 10 seconds?
            //    {
            //        recItem.ResetPreRecoveredKerbals();
            //        RecoveryQueue.Remove(recItem);
            //    }
            //}
        }
Example #11
0
 //Set the selected stage to null and reset the info toolbar to "Parts"
 public void NullifySelected()
 {
     selectedStage = null;
     infoBarIndex  = 0;
 }
Example #12
0
        //And this does the actual drawing
        public void DrawFlightGUI(int windowID)
        {
            //Start with a vertical, then a horizontal (stage list and stage info), then another vertical (stage list).
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical(GUILayout.Width(225));
            //Draw the toolbar that selects between recovered and destroyed stages
            int temp = firstToolbarIndex;

            //firstToolbarIndex = GUILayout.Toolbar(firstToolbarIndex, new string[] { "Recovered", "Destroyed" });
            GUILayout.BeginHorizontal();
            bool active = GUILayout.Toggle(firstToolbarIndex == 0, Localizer.Format("#StageRecovery_Recovered") + (Settings.Instance.RecoveredStages.Count > 0 ? " (" + Settings.Instance.RecoveredStages.Count + ")" : ""), GUI.skin.button);//"Recovered"

            if (!active && firstToolbarIndex == 0)
            {
                firstToolbarIndex = -1;
            }
            else if (active)
            {
                firstToolbarIndex = 0;
            }

            active = GUILayout.Toggle(firstToolbarIndex == 1, Localizer.Format("#StageRecovery_Destroyed") + (Settings.Instance.DestroyedStages.Count > 0 ? " (" + Settings.Instance.DestroyedStages.Count + ")" : ""), GUI.skin.button);//"Destroyed"
            if (!active && firstToolbarIndex == 1)
            {
                firstToolbarIndex = -1;
            }
            else if (active)
            {
                firstToolbarIndex = 1;
            }

            if (temp != firstToolbarIndex)
            {
                NullifySelected();
                if (firstToolbarIndex == -1)
                {
                    flightWindowRect.height = 1;
                }
                else
                {
                    flightWindowRect.height = 480;
                }
            }
            GUILayout.EndHorizontal();
            //NullifySelected will set the selectedStage to null and reset the toolbar

            // GUILayout.Label("FMRS: " + (StageRecovery.FMRS_Enabled() ? "Active" : "Inactive"));

            if (firstToolbarIndex >= 0)
            {
                //Begin listing the recovered/destryoed stages in a scroll view (so you can scroll if it's too long)
                GUILayout.Label((firstToolbarIndex == 0 ? Localizer.Format("#StageRecovery_Recovered") : Localizer.Format("#StageRecovery_Destroyed")) + Localizer.Format("#StageRecovery_Stages"));//"Recovered""Destroyed"" Stages:"
                stagesScroll = GUILayout.BeginScrollView(stagesScroll, HighLogic.Skin.textArea);

                RecoveryItem deleteThis = null;
                //List all recovered stages
                if (firstToolbarIndex == 0)
                {
                    for (int i = 0; i < Settings.Instance.RecoveredStages.Count; i++)
                    //foreach (RecoveryItem stage in Settings.Instance.RecoveredStages)
                    {
                        RecoveryItem stage      = Settings.Instance.RecoveredStages[i];
                        string       buttonText = stage.StageName;
                        if (stage == selectedStage)
                        {
                            buttonText = "--  " + buttonText + "  --";
                        }

                        if (GUILayout.Button(buttonText))
                        {
                            if (Input.GetMouseButtonUp(0))
                            {
                                //If you select the same stage again it will minimize the list
                                if (selectedStage == stage)
                                {
                                    selectedStage = null;
                                }
                                else
                                {
                                    selectedStage = stage;
                                }
                            }
                            else if (Input.GetMouseButtonUp(1))
                            {
                                //Right clicking deletes the stage
                                deleteThis = stage;
                            }
                        }
                    }
                }
                //List all destroyed stages
                else if (firstToolbarIndex == 1)
                {
                    for (int i = 0; i < Settings.Instance.DestroyedStages.Count; i++)
                    //foreach (RecoveryItem stage in Settings.Instance.DestroyedStages)
                    {
                        RecoveryItem stage      = Settings.Instance.DestroyedStages[i];
                        string       buttonText = stage.StageName;
                        if (stage == selectedStage)
                        {
                            buttonText = "--  " + buttonText + "  --";
                        }

                        if (GUILayout.Button(buttonText))
                        {
                            if (Input.GetMouseButtonUp(0))
                            {
                                //If you select the same stage again it will minimize the list
                                if (selectedStage == stage)
                                {
                                    selectedStage = null;
                                }
                                else
                                {
                                    selectedStage = stage;
                                }
                            }
                            else if (Input.GetMouseButtonUp(1))
                            {
                                //Right clicking deletes the stage
                                deleteThis = stage;
                            }
                        }
                    }
                }

                if (deleteThis != null)
                {
                    if (deleteThis == selectedStage)
                    {
                        NullifySelected();
                    }

                    if (firstToolbarIndex == 0)
                    {
                        Settings.Instance.RecoveredStages.Remove(deleteThis);
                    }
                    else
                    {
                        Settings.Instance.DestroyedStages.Remove(deleteThis);
                    }
                }

                //End the list of stages
                GUILayout.EndScrollView();
            }

            //GUILayout.Label("FMRS: " + StageRecovery.FMRS_Enabled(false).ToString());
            //GUILayout.Label("Chutes: " + StageRecovery.FMRS_Enabled(true).ToString());

            GUILayout.EndVertical();

            //If a stage is selected we show the info for it
            if (selectedStage != null)
            {
                //Make the window larger to accomodate the info
                if (flightWindowRect.width != 600)
                {
                    flightWindowRect.width = 600;
                }

                GUILayout.BeginVertical(HighLogic.Skin.textArea);
                //Show a toolbar with options for specific data, defaulting to the Parts list
                if (selectedStage.propRemaining.Count > 0)
                {
                    infoBarIndex = GUILayout.Toolbar(infoBarIndex, new string[] { Localizer.Format("#StageRecovery_InfoBar_Parts"), Localizer.Format("#StageRecovery_InfoBar_Crew"), Localizer.Format("#StageRecovery_InfoBar_Science"), Localizer.Format("#StageRecovery_InfoBar_Info"), Localizer.Format("#StageRecovery_InfoBar_Fuel") });//"Parts""Crew""Science""Info""Fuel"
                }
                else
                {
                    if (infoBarIndex == 4)
                    {
                        infoBarIndex = 3;
                    }
                    infoBarIndex = GUILayout.Toolbar(infoBarIndex, new string[] { Localizer.Format("#StageRecovery_InfoBar_Parts"), Localizer.Format("#StageRecovery_InfoBar_Crew"), Localizer.Format("#StageRecovery_InfoBar_Science"), Localizer.Format("#StageRecovery_InfoBar_Info") });//"Parts", "Crew", "Science", "Info"
                }
                //List the stage name and whether it was recovered or destroyed
                GUILayout.Label(Localizer.Format("#StageRecovery_StagesName", selectedStage.StageName));                                                                                             //"Stage name: " +
                GUILayout.Label(Localizer.Format("#StageRecovery_Status", (selectedStage.Recovered ? Localizer.Format("#StageRecovery_Recovered") : Localizer.Format("#StageRecovery_Destroyed")))); //"Status: " + "RECOVERED""DESTROYED"
                //Put everything in a scroll view in case it is too much data for the window to display
                infoScroll = GUILayout.BeginScrollView(infoScroll);

                //Depending on the selected data view we display different things (split into different functions for ease)
                switch (infoBarIndex)
                {
                case 0: DrawPartsInfo(); break;

                case 1: DrawCrewInfo(); break;

                case 2: DrawScienceInfo(); break;

                case 3: DrawAdvancedInfo(); break;

                case 4: DrawFuelInfo(); break;
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
                //End the info side of the window
            }
            //If no stage is selected we reset the window size back to 240
            else
            {
                if (flightWindowRect.width != 240)
                {
                    flightWindowRect.width = 240;
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            //End the entire window

            //Make it draggable
            if (!Input.GetMouseButtonDown(1) && !Input.GetMouseButtonDown(2))
            {
                GUI.DragWindow();
            }
        }
Example #13
0
        //The main show. The VesselDestroyEvent is activated whenever KSP destroys a vessel. We only care about it in a specific set of circumstances
        private void VesselDestroyEvent(Vessel v)
        {
            //If we're disabled, just return
            if (!Settings.Instance.SREnabled)
            {
                return;
            }

            if (!sceneChangeComplete)
            {
                return;
            }

            //If FlightGlobals is null, just return. We can't do anything
            if (FlightGlobals.fetch == null)
            {
                return;
            }

            //If the protoVessel is null, we can't do anything so just return
            if (v.protoVessel == null)
            {
                return;
            }

            //Check if we should even recover it
            if (!SRShouldRecover(v))
            {
                return;
            }

            //Our criteria for even attempting recovery. Broken down: vessel exists, hasn't had recovery attempted, isn't the active vessel, is around Kerbin, is either unloaded or packed, altitude is within atmosphere,
            //is flying or sub orbital, and is not an EVA (aka, Kerbals by themselves)
            if (v != null && !RecoverAttemptLog.ContainsKey(v.id) && !(HighLogic.LoadedSceneIsFlight && v.isActiveVessel) && (v.mainBody == Planetarium.fetch.Home) && (!v.loaded || v.packed) && (v.altitude < v.mainBody.atmosphereDepth) &&
                (v.situation == Vessel.Situations.FLYING || v.situation == Vessel.Situations.SUB_ORBITAL || v.situation == Vessel.Situations.ORBITING) && !v.isEVA && v.altitude > 100)
            {
                //Indicate that we've at least attempted recovery of this vessel
                RecoverAttemptLog.Add(v.id, Planetarium.GetUniversalTime());

                bool OnlyBlacklistedItems = true;
                foreach (ProtoPartSnapshot pps in v.protoVessel.protoPartSnapshots)
                {
                    if (!Settings.Instance.BlackList.Contains(pps.partInfo.title))
                    {
                        OnlyBlacklistedItems = false;
                        break;
                    }
                }
                if (OnlyBlacklistedItems)
                {
                    return;
                }

                //If we got this far, we can assume we're going to be attempting to recover the vessel, so we should fire the processing event
                APIManager.instance.OnRecoveryProcessingStart.Fire(v);

                //Create a new RecoveryItem. Calling this calculates everything regarding the success or failure of the recovery. We need it for display purposes in the main gui
                Debug.Log("[SR] Searching in RecoveryQueue (" + instance.RecoveryQueue.Count + ") for " + v.id);
                RecoveryItem Stage;
                if (instance.RecoveryQueue.Count > 0 && instance.RecoveryQueue.Exists(ri => ri.vessel.id == v.id))
                {
                    Stage = instance.RecoveryQueue.Find(ri => ri.vessel.id == v.id);
                    instance.RecoveryQueue.Remove(Stage);
                    Debug.Log("[SR] Found vessel in the RecoveryQueue.");
                }
                else
                {
                    Stage = new RecoveryItem(v);
                }
                Stage.Process();
                //Fire the pertinent RecoveryEvent (success or failure). Aka, make the API do its work
                Stage.FireEvent();
                //Add the Stage to the correct list of stages. Either the Recovered Stages list or the Destroyed Stages list, for display on the main gui
                Stage.AddToList();
                //Post a message to the stock message system, if people are still using that.
                Stage.PostStockMessage();
                //Add to ScrapYard if it's installed
                AddToScrapYard(Stage);

                APIManager.instance.OnRecoveryProcessingFinish.Fire(v);
            }
        }
Example #14
0
        public void VesselUnloadEvent(Vessel vessel)
        {
            //If we're disabled, just return
            if (!Settings.Instance.SREnabled)
            {
                return;
            }

            //If the vessel or the protovessel are null then we surely can't do anything with them
            if (vessel == null || vessel.protoVessel == null)
            {
                return;
            }

            ProtoVessel pv = vessel.protoVessel;

            //If we aren't supposed to recover clamps, then don't try.
            if (Settings.Instance.RecoverClamps)
            {
                //If we've already recovered the clamps, then no need to try again
                if (clampsRecovered.Find(a => a.id == vessel.id) != null)
                {
                    return;
                }

                //Assign the pv variable to the protovessel, then look for if the root is a clamp

                if (pv.protoPartSnapshots.Count > 0 && pv.protoPartSnapshots[0].modules.Exists(m => m.moduleName == "LaunchClamp"))
                {
                    //We look for the launchclamp module, which will hopefully cover FASA and stock.
                    Debug.Log("[SR] Recovering a clamp!");
                    //Add it to the recovered clamps list so we don't try to recover it again
                    clampsRecovered.Add(vessel);
                    float totalRefund = 0;
                    //Loop over all the parts and calculate their cost (we recover at 100% since we're at the launchpad/runway)
                    foreach (ProtoPartSnapshot pps in pv.protoPartSnapshots)
                    {
                        float out1, out2;
                        totalRefund += ShipConstruction.GetPartCosts(pps, pps.partInfo, out out1, out out2);
                    }
                    //Add dem funds to da total. Get dem funds!
                    AddFunds(totalRefund);
                    //Fire the successful recovery event. Even though this isn't a stage we still need to do this for things like KCT to recover the parts.
                    //Can be averted with stock functions if I can get them working properly
                    APIManager.instance.RecoverySuccessEvent.Fire(vessel, new float[] { 100, totalRefund, 0 }, "SUCCESS");
                    //And then we try a bunch of things to make sure the clamps are removed (remove it from the flight state, kill it, and destroy it)
                    HighLogic.CurrentGame.flightState.protoVessels.Remove(pv);
                    vessel.Die();
                    Destroy(vessel);
                    //So, question for myself. Would it be better to try to manually fire the recovery events? Would that really be worth anything?
                }
            }

            //If it's a stage that will be destroyed, we need to manually recover the Kerbals
            if (Settings.Instance.RecoverKerbals && Settings.Instance.PreRecover && pv.GetVesselCrew().Count > 0)
            {
                //Check if the conditions for vessel destruction are met
                if (vessel != FlightGlobals.ActiveVessel && !vessel.isEVA && vessel.mainBody == Planetarium.fetch.Home &&
                    pv.situation != Vessel.Situations.LANDED && vessel.altitude < cutoffAlt && vessel.altitude > 0) //unloading in > 0.01 atm and not landed //pv.altitude < vessel.mainBody.atmosphereDepth
                {
                    Debug.Log("[SR] Vessel " + pv.vesselName + " is going to be destroyed. Recovering Kerbals!");   //Kerbal death should be handled by SR instead
                    RecoveryItem recItem = new RecoveryItem(vessel);

                    //Pre-recover the Kerbals
                    recItem.PreRecoverKerbals();

                    //Add the ship to the RecoveryQueue to be handled by the OnDestroy event
                    instance.RecoveryQueue.Add(recItem);
                }
                else
                {
                    WatchVessel(vessel);
                }
            }
        }
Example #15
0
        public override void Request(object sender, CqGroupMessageEventArgs e, string groupPath)
        {
            string userName = GetUserName(e.FromQQ.ToString(), groupPath);

            // 用户验证
            if (userName == "")
            {
                return;
            }

            // 获取用户信息
            User user = GetUser(e.FromQQ.ToString(), e, groupPath);

            if (user.HP <= 0)
            {
                Common.CqApi.SendGroupMessage(e.FromGroup, "对不起,您已死亡:请复活后继续!");
                return;
            }

            string[] arr = e.Message.Split(' ');

            if (arr.Length > 1)
            {
                int itemNum = GetKnapsackItemNum(arr[1], groupPath, e.FromQQ.ToString());

                if (itemNum == 0)
                {
                    Common.CqApi.SendGroupMessage(e.FromGroup, "您没有物品:" + arr[1]);
                    return;
                }

                int count = 1;

                if (arr.Length > 2)
                {
                    if (Int32.TryParse(arr[2], out int num))
                    {
                        if (itemNum < num)
                        {
                            Common.CqApi.SendGroupMessage(e.FromGroup, "您没有足够的物品数量:" + arr[1]);
                            return;
                        }

                        count = num;
                    }
                }

                string use = iniTool.IniReadValue(devPath, itemIni, arr[1], "效果");

                if (use == "")
                {
                    Common.CqApi.SendGroupMessage(e.FromGroup, arr[1] + " 不能使用");
                    return;
                }

                if (use == "恢复")
                {
                    RecoveryItem recoveryItem = GetRecoveryItem(arr[1]);

                    user.HP += recoveryItem.HP * count;
                    user.MP += recoveryItem.MP * count;

                    if (user.HP > user.MaxHP)
                    {
                        user.HP = user.MaxHP;
                    }

                    if (user.MP > user.MaxMP)
                    {
                        user.MP = user.MaxMP;
                    }

                    iniTool.IniWriteValue(groupPath, userInfoIni, e.FromQQ.ToString(), "血量", user.HP.ToString());
                    iniTool.IniWriteValue(groupPath, userInfoIni, e.FromQQ.ToString(), "蓝量", user.MP.ToString());

                    // 使用背包物品
                    DeleteKnapsackItemNum(arr[1], itemNum, 1, groupPath, e.FromQQ.ToString());

                    Common.CqApi.SendGroupMessage(e.FromGroup, "使用成功:" + arr[1] + "*" + count + Environment.NewLine + "当前血量:" + user.HP);
                    return;
                }
            }

            return;
        }
Example #16
0
    private void ShowConsumables()
    {
        GUILayout.Label("> Consumable", EditorStyles.boldLabel);
        //newConsumableType = (Enums.eConsumableType)EditorGUILayout.EnumPopup("Consumable: ", newConsumableType);
        ConsumableItem consumable = (ConsumableItem)mCurrentCreateType;

        switch (consumable.ConsumableType)
        {
        case Enums.eConsumableType.Recovery:
            GUILayout.Label("  > Recovery", EditorStyles.boldLabel);
            RecoveryItem recovery = (RecoveryItem)consumable;
            //newRecoveryStatType = (Enums.eConsumableStatType)EditorGUILayout.EnumPopup("Stat Type: ", newRecoveryStatType);
            GUILayout.Label("Recovery Type: " + recovery.ConsumableStatType, EditorStyles.boldLabel);
            recoveryAmount = EditorGUILayout.IntField("Recovery Amount: ", Mathf.Clamp(recoveryAmount, 0, 99));

            //if (mCurrentItem.GetType() != typeof(RecoveryItem))
            //{
            //    mCurrentItem = new RecoveryItem();
            //}
            break;

        case Enums.eConsumableType.StatUpgrade:
            GUILayout.Label("  > Stat Upgrade", EditorStyles.boldLabel);
            StatUpgradeItem statUpgrade = (StatUpgradeItem)consumable;
            newStatType     = (Enums.eStatType)EditorGUILayout.EnumPopup("Boost Max Stat: ", newStatType);
            statBoostAmount = EditorGUILayout.IntField("Amount: ", Mathf.Clamp(statBoostAmount, 0, 99));

            //if (mCurrentItem.GetType() != typeof(StatUpgradeItem))
            //{
            //    mCurrentItem = new StatUpgradeItem();
            //}
            break;

        case Enums.eConsumableType.StatusEffect:
            GUILayout.Label("  > Status Effect", EditorStyles.boldLabel);
            StatusEffectItem status = (StatusEffectItem)consumable;
            newEffectType = (Enums.eStatusEffect)EditorGUILayout.EnumPopup("Effect: ", newEffectType);

            //if (mCurrentItem.GetType() != typeof(StatusEffectItem))
            //{
            //    mCurrentItem = new StatusEffectItem();
            //}
            break;

        case Enums.eConsumableType.WeaponUpgrade:
            GUILayout.Label("  > Weapon Upgrade", EditorStyles.boldLabel);
            WeaponUpgradeItem weaponUpgrade = (WeaponUpgradeItem)consumable;
            GUILayout.Label("Stat Boosted: ATT", EditorStyles.boldLabel);
            weaponUpgradeAmount = EditorGUILayout.IntField("Amount: ", Mathf.Clamp(weaponUpgradeAmount, 0, 99));

            //if (mCurrentItem.GetType() != typeof(WeaponUpgradeItem))
            //{
            //    mCurrentItem = new WeaponUpgradeItem();
            //}
            break;

        case Enums.eConsumableType.CharacterSupport:
            GUILayout.Label("  > Character Support", EditorStyles.boldLabel);
            CharacterSupportItem support = (CharacterSupportItem)consumable;
            switch (support.SupportType)
            {
            case Enums.eCharacterSupportType.Teleport:
                GUILayout.Label("    > Teleport", EditorStyles.boldLabel);
                Teleport t = (Teleport)support;
                TeleportPrefab = (GameObject)EditorGUILayout.ObjectField("Prefab:", TeleportPrefab, typeof(GameObject), false);
                if (TeleportPrefab != null)
                {
                    TeleportPrefabName = TeleportPrefab.name;
                }
                break;

            case Enums.eCharacterSupportType.Revive:
                GUILayout.Label("    > Revive", EditorStyles.boldLabel);
                // no fields
                break;

            case Enums.eCharacterSupportType.Resource:
                GUILayout.Label("    > Resource", EditorStyles.boldLabel);
                // will need fields filled in
                break;

            case Enums.eCharacterSupportType.Scroll:
                GUILayout.Label("    > Scroll", EditorStyles.boldLabel);

                ScrollTeachType = (Enums.eSpellType)EditorGUILayout.EnumPopup("Spell Type: ", ScrollTeachType);
                break;
            }
            break;
        }
    }