Exemplo n.º 1
0
 private void sendScenarios()
 {
     Log.Debug("sendScenarios");
     if (!syncing)
     {
         lastScenarioUpdateTime = UnityEngine.Time.realtimeSinceStartup;
         double tick = Planetarium.GetUniversalTime();
         foreach (ProtoScenarioModule proto in HighLogic.CurrentGame.scenarios)
         {
             if (proto != null && proto.moduleName != null && proto.moduleRef != null)
             {
                 KMPScenarioUpdate update = new KMPScenarioUpdate(proto.moduleName, proto.moduleRef, tick);
                 byte[] update_bytes = KSP.IO.IOUtils.SerializeToBinary(update);
                 enqueuePluginInteropMessage(KMPCommon.PluginInteropMessageID.SCENARIO_UPDATE, update_bytes);
             }
         }
     }
 }
Exemplo n.º 2
0
 private void applyScenarioUpdate(KMPScenarioUpdate update)
 {
     bool loaded = false;
     foreach (ProtoScenarioModule proto in HighLogic.CurrentGame.scenarios)
     {
         if (proto != null && proto.moduleName == update.name && proto.moduleRef != null && update.getScenarioNode() != null)
         {
             Log.Debug("Loading scenario data for existing module: " + update.name);
             if (update.name == "ResearchAndDevelopment")
             {
                 ResearchAndDevelopment rd = (ResearchAndDevelopment) proto.moduleRef;
                 Log.Debug("pre-R&D: {0}", rd.Science);
             }
             try
             {
                 proto.moduleRef.Load(update.getScenarioNode());
             } catch (Exception e) { KMPClientMain.sendConnectionEndMessage("Error in handling scenario data. Please restart your client. "); Log.Debug(e.ToString());  }
             if (update.name == "ResearchAndDevelopment")
             {
                 ResearchAndDevelopment rd = (ResearchAndDevelopment) proto.moduleRef;
                 Log.Debug("post-R&D: {0}", rd.Science);
             }
             loaded = true;
             break;
         }
     }
     if (!loaded)
     {
         Log.Debug("Loading new scenario module data: " + update.name);
         ProtoScenarioModule newScenario = new ProtoScenarioModule(update.getScenarioNode());
         //var proto = HighLogic.CurrentGame.AddProtoScenarioModule(newScenario.GetType(), GameScenes.SPACECENTER, GameScenes.FLIGHT, GameScenes.TRACKSTATION);
         HighLogic.CurrentGame.scenarios.Add(newScenario);
         newScenario.Load(ScenarioRunner.fetch);
         if (update.name == "ScenarioDiscoverableObjects")
         {
             ScenarioDiscoverableObjects sdo = (ScenarioDiscoverableObjects) newScenario.moduleRef;
             sdo.spawnInterval *= (playerStatus.Count()+1); //Throttle spawn rate based on number of players (at connection time)
             sdo.debugSpawnProbability();
             sdoReceived = true;
         }
     }
     clearEditorPartList = true;
 }