/// <summary> /// Process the Player Position message. /// </summary> /// <param name="client">Client the message is from.</param> /// <param name="message">Message itself.</param> protected override void PlayerPositionChange(Client client, Message message) { // Get current world. SubWorld world = CurrentWorld; // Find the TCP Client's world. while (world.Client != client) { if (world.Opponent == null) { world = null; break; } world = world.Opponent; } // If Client World is found. if (world != null) { // Get the World's Player. GameEntity player = world.GetSystem <PlayerSystem>().Get("Player").Parent; // Calculate the new Player position. byte[] data = message.GetData(); data = (data.Length == 2) ? data : new byte[] { 0, data[0] }; data = new byte[] { data[1], data[0] }; short pos = BitConverter.ToInt16(data, 0); // Update Player position. player.Position.x = pos; } }
} // Priority of the System. /// <summary> /// Create the System with the World as owning world. /// </summary> /// <param name="world">System's owner SubWorld.</param> public GameSystem(SubWorld world) { // Set up attributes. Priority = 1; World = world; BreakWorld = (BreakoutWorld)world; }
/// <summary> /// Process the activate PowerUp message. /// </summary> /// <param name="client">Client the message is from.</param> /// <param name="message">Message itself.</param> protected override void ActivatePowerUp(Client client, Message message) { // Get the Client's SubWorld and activate PowerUp. SubWorld world = SubWorlds[Clients.IndexOf(client)]; world.GetSystem <PowerUpSystem>().ActivatePowerUp(); }
// Create brick and accompanying components. private Brick CreateBrick(SubWorld world, string name = "") { GameEntity entity = new GameEntity(name); Brick brick = new Brick(entity, 96, 16); Collider collider = new Collider(entity, 96, 16, false); world.GetSystem <ColliderSystem>().Add(collider); return(brick); }
// Create player and accompanying components. private Ball CreatePlayer(SubWorld world, string name = "") { GameEntity entity = new GameEntity(name); Ball ball = new Ball(entity); Collider collider = new Collider(entity, 64, 64, true); world.GetSystem <BallSystem>().Add(ball); world.GetSystem <ColliderSystem>().Add(collider); return(ball); }
private static void DisableDefaultPoiGeysers(ref SubWorld subWorld) { Dictionary <string, string[]> finalPois = new Dictionary <string, string[]>(subWorld.pointsOfInterest); foreach (string poi in subWorld.pointsOfInterest.Keys) { Debug.Log("[] " + poi.ToLower()); if (poi.ToLower().Contains("geyser")) { finalPois.Remove(poi); } } AccessTools.Property(typeof(SubWorld), "pointsOfInterest").SetValue(subWorld, finalPois, null); }
public static void Postfix(WorldGen __instance) { if (!Options.Enabled) { return; } foreach (TerrainCell overworldCell in __instance.OverworldCells) { SubWorld subWorld = __instance.Settings.GetSubWorld(overworldCell.node.type); if (subWorld != null) { var x = (int)Math.Round(overworldCell.node.position.x); var y = (int)Math.Round(overworldCell.node.position.y); #if DEBUG Debug.Log("Node: " + overworldCell.node.type + " at " + x + "|" + y); #endif var borderTop = FindNextBorderCell(x, y, 0, 1); var borderRight = FindNextBorderCell(x, y, 1, 0); var borderBottom = FindNextBorderCell(x, y, 0, -1); var borderLeft = FindNextBorderCell(x, y, -1, 0); _useGranite = overworldCell.node.tags.Contains(WorldGenTags.StartWorld); ReplaceVerticalBorderCells(overworldCell, borderTop, true); ReplaceHorizontalBorderCells(overworldCell, borderRight, true); if (Options.MoreEntrances) { ReplaceVerticalBorderCells(overworldCell, borderBottom, false); ReplaceHorizontalBorderCells(overworldCell, borderLeft, false); } } } // cleanup _cells = null; _world = null; }
/// <summary> /// Transmit all alterations to current SubWorld for systems at given priority. /// </summary> /// <param name="priority">Required priority of systems for to have its messages gathered.</param> public override void TransmitAtlerations(int priority) { if (!CurrentWorld.DummyWorld) // If the current SubWorld isn't an inactive dummy world... { // Start Message Queue to hold produced Massages. MessageQueue queue = new MessageQueue(); // Gather all alterations from current SubWorld and send them to Client. queue.Add(CurrentWorld.GatherAlterations(priority)); SendQueue(CurrentWorld.Client, queue); // Create another Message Queue. queue = new MessageQueue(); // Get previous transmitted alterations from opponent SubWorld. SubWorld opponent = CurrentWorld.Opponent; List <Message> messages = opponent.GetPreviousAlterations(); // Set each message to be relating to the opponent. messages.ForEach((m) => { m.Player = 0; }); if (messages.Count > 0) // If there are more than one messages... { // ... Add them to the queue and send. queue.Add(messages); SendQueue(CurrentWorld.Client, queue); } } else // ... Otherwise... { // Gather current SubWorld alterations. CurrentWorld.GatherAlterations(priority); } }
private static Sim.Cell[] RenderOffline(WorldGen __instance, bool doSettle, ref Sim.DiseaseCell[] dc) { Debug.Log(" === WorldGenReloadedMod_WorldGen_RenderOffline ==="); WorldGen.OfflineCallbackFunction successCallbackFn = ((WorldGen.OfflineCallbackFunction)successCallbackFnF.GetValue(__instance)); SeededRandom myRandom = ((SeededRandom)myRandomF.GetValue(__instance)); Data data = ((Data)dataF.GetValue(__instance)); Action <OfflineWorldGen.ErrorInfo> errorCallback = ((Action <OfflineWorldGen.ErrorInfo>)errorCallbackF.GetValue(__instance)); Sim.Cell[] cells = null; float[] bgTemp = null; dc = null; HashSet <int> borderCells = new HashSet <int>(); //CompleteLayout(successCallbackFn); __instance.CompleteLayout(successCallbackFn); //WriteOverWorldNoise(successCallbackFn); __instance.WriteOverWorldNoise(successCallbackFn); if (!__instance.RenderToMap(successCallbackFn, ref cells, ref bgTemp, ref dc, ref borderCells)) { successCallbackFn(UI.WORLDGEN.FAILED.key, -100f, WorldGenProgressStages.Stages.Failure); return(null); } __instance.EnsureEnoughAlgaeInStartingBiome(cells); List <KeyValuePair <Vector2I, TemplateContainer> > list = new List <KeyValuePair <Vector2I, TemplateContainer> >(); TemplateContainer baseStartingTemplate = TemplateCache.GetBaseStartingTemplate(); List <TerrainCell> terrainCellsForTag = __instance.GetTerrainCellsForTag(WorldGenTags.StartLocation); foreach (TerrainCell item5 in terrainCellsForTag) { List <KeyValuePair <Vector2I, TemplateContainer> > list2 = list; Vector2 vector = item5.poly.Centroid(); int a = (int)vector.x; Vector2 vector2 = item5.poly.Centroid(); list2.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a, (int)vector2.y), baseStartingTemplate)); } List <TemplateContainer> list3 = TemplateCache.CollectBaseTemplateAssets("poi/"); foreach (SubWorld subWorld in __instance.Settings.GetSubWorldList()) { if (subWorld.pointsOfInterest != null) { //// Disable default POI geysers if (WorldGenReloadedData.Config.DisableDefaultPoiGeysers) { SubWorld _subWorld = subWorld; DisableDefaultPoiGeysers(ref _subWorld); } //// foreach (KeyValuePair <string, string[]> item6 in subWorld.pointsOfInterest) { List <TerrainCell> terrainCellsForTag2 = __instance.GetTerrainCellsForTag(subWorld.name.ToTag()); for (int num = terrainCellsForTag2.Count - 1; num >= 0; num--) { if (!__instance.IsSafeToSpawnPOI(terrainCellsForTag2[num])) { terrainCellsForTag2.Remove(terrainCellsForTag2[num]); } } if (terrainCellsForTag2.Count > 0) { string template = null; TemplateContainer templateContainer = null; int num2 = 0; while (templateContainer == null && num2 < item6.Value.Length) { template = item6.Value[myRandom.RandomRange(0, item6.Value.Length)]; templateContainer = list3.Find((TemplateContainer value) => value.name == template); num2++; } if (templateContainer != null) { list3.Remove(templateContainer); for (int i = 0; i < terrainCellsForTag2.Count; i++) { TerrainCell terrainCell = terrainCellsForTag2[myRandom.RandomRange(0, terrainCellsForTag2.Count)]; if (!terrainCell.node.tags.Contains(WorldGenTags.POI)) { if (!(templateContainer.info.size.Y > terrainCell.poly.MaxY - terrainCell.poly.MinY)) { List <KeyValuePair <Vector2I, TemplateContainer> > list4 = list; Vector2 vector3 = terrainCell.poly.Centroid(); int a2 = (int)vector3.x; Vector2 vector4 = terrainCell.poly.Centroid(); list4.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a2, (int)vector4.y), templateContainer)); terrainCell.node.tags.Add(template.ToTag()); terrainCell.node.tags.Add(WorldGenTags.POI); break; } float num3 = templateContainer.info.size.Y - (terrainCell.poly.MaxY - terrainCell.poly.MinY); float num4 = templateContainer.info.size.X - (terrainCell.poly.MaxX - terrainCell.poly.MinX); if (terrainCell.poly.MaxY + num3 < (float)Grid.HeightInCells && terrainCell.poly.MinY - num3 > 0f && terrainCell.poly.MaxX + num4 < (float)Grid.WidthInCells && terrainCell.poly.MinX - num4 > 0f) { List <KeyValuePair <Vector2I, TemplateContainer> > list5 = list; Vector2 vector5 = terrainCell.poly.Centroid(); int a3 = (int)vector5.x; Vector2 vector6 = terrainCell.poly.Centroid(); list5.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a3, (int)vector6.y), templateContainer)); terrainCell.node.tags.Add(template.ToTag()); terrainCell.node.tags.Add(WorldGenTags.POI); break; } } } } } } } } //// ProcessGeysers(__instance, ref list, myRandom); //// // Generation of geyser Overwrited in the previous line /* * List<TemplateContainer> list6 = TemplateCache.CollectBaseTemplateAssets("features/"); * foreach (SubWorld subWorld2 in WorldGen.Settings.GetSubWorldList()) * { * if (subWorld2.featureTemplates != null && subWorld2.featureTemplates.Count > 0) * { * List<string> list7 = new List<string>(); * foreach (KeyValuePair<string, int> featureTemplate in subWorld2.featureTemplates) * { * for (int j = 0; j < featureTemplate.Value; j++) * { * list7.Add(featureTemplate.Key); * } * } * list7.ShuffleSeeded(myRandom.RandomSource()); * List<TerrainCell> terrainCellsForTag3 = WorldGen.GetTerrainCellsForTag(subWorld2.name.ToTag()); * terrainCellsForTag3.ShuffleSeeded(myRandom.RandomSource()); * foreach (TerrainCell item7 in terrainCellsForTag3) * { * if (list7.Count == 0) * { * break; * } * if (item7.IsSafeToSpawnFeatureTemplate()) * { * string template2 = list7[list7.Count - 1]; * list7.RemoveAt(list7.Count - 1); * TemplateContainer templateContainer2 = list6.Find((TemplateContainer value) => value.name == template2); * if (templateContainer2 != null) * { * List<KeyValuePair<Vector2I, TemplateContainer>> list8 = list; * Vector2 vector7 = item7.poly.Centroid(); * int a4 = (int)vector7.x; * Vector2 vector8 = item7.poly.Centroid(); * list8.Add(new KeyValuePair<Vector2I, TemplateContainer>(new Vector2I(a4, (int)vector8.y), templateContainer2)); * item7.node.tags.Add(template2.ToTag()); * item7.node.tags.Add(WorldGenTags.POI); * } * } * } * } * } */ foreach (int item8 in borderCells) { cells[item8].SetValues(WorldGen.unobtaniumElement, ElementLoader.elements); } if (doSettle) { //this.running = WorldGenSimUtil.DoSettleSim(this.Settings, array, bgTemp, dc, this.successCallbackFn, this.data, list, this.errorCallback, delegate(Sim.Cell[] updatedCells, float[] updatedBGTemp, Sim.DiseaseCell[] updatedDisease) runningF.SetValue(__instance, WorldGenSimUtil.DoSettleSim(__instance.Settings, cells, bgTemp, dc, successCallbackFn, data, list, errorCallback, delegate(Sim.Cell[] updatedCells, float[] updatedBGTemp, Sim.DiseaseCell[] updatedDisease) { //SpawnMobsAndTemplates(updatedCells, updatedBGTemp, updatedDisease, borderCells); SpawnMobsAndTemplatesM.Invoke(__instance, new object[] { updatedCells, updatedBGTemp, updatedDisease, borderCells }); })); } foreach (KeyValuePair <Vector2I, TemplateContainer> item9 in list) { //PlaceTemplateSpawners(item9.Key, item9.Value); PlaceTemplateSpawnersM.Invoke(__instance, new object[] { item9.Key, item9.Value }); } for (int num5 = data.gameSpawnData.buildings.Count - 1; num5 >= 0; num5--) { int item = Grid.XYToCell(data.gameSpawnData.buildings[num5].location_x, data.gameSpawnData.buildings[num5].location_y); if (borderCells.Contains(item)) { data.gameSpawnData.buildings.RemoveAt(num5); } } for (int num6 = data.gameSpawnData.elementalOres.Count - 1; num6 >= 0; num6--) { int item2 = Grid.XYToCell(data.gameSpawnData.elementalOres[num6].location_x, data.gameSpawnData.elementalOres[num6].location_y); if (borderCells.Contains(item2)) { data.gameSpawnData.elementalOres.RemoveAt(num6); } } for (int num7 = data.gameSpawnData.otherEntities.Count - 1; num7 >= 0; num7--) { int item3 = Grid.XYToCell(data.gameSpawnData.otherEntities[num7].location_x, data.gameSpawnData.otherEntities[num7].location_y); if (borderCells.Contains(item3)) { data.gameSpawnData.otherEntities.RemoveAt(num7); } } for (int num8 = data.gameSpawnData.pickupables.Count - 1; num8 >= 0; num8--) { int item4 = Grid.XYToCell(data.gameSpawnData.pickupables[num8].location_x, data.gameSpawnData.pickupables[num8].location_y); if (borderCells.Contains(item4)) { data.gameSpawnData.pickupables.RemoveAt(num8); } } __instance.SaveWorldGen(); successCallbackFn(UI.WORLDGEN.COMPLETE.key, 101f, WorldGenProgressStages.Stages.Complete); //running = false; runningF.SetValue(__instance, false); return(cells); }
public WeightedSubWorld(float weight, SubWorld subWorld) { this.weight = weight; this.subWorld = subWorld; }
/// <summary> /// Create Brick system. /// </summary> /// <param name="world">Owning SubWorld.</param> public BrickSystem(SubWorld world) : base(world) { // Lower System priority to 2. Priority = 2; }
/// <summary> /// Create Ball system. /// </summary> /// <param name="world">Owning SubWorld.</param> public BallSystem(SubWorld world) : base(world) { }
/// <summary> /// Create Player system. /// </summary> /// <param name="world">Owning SubWorld.</param> public PlayerSystem(SubWorld world) : base(world) { }
private void ShowStartingLocationChoices() { if ((UnityEngine.Object)titleText != (UnityEngine.Object)null) { titleText.text = "Choose Starting Location"; } startNodes = worldGen.WorldLayout.GetStartNodes(); startNodes.Shuffle(); if (startNodes.Count > 0) { ChooseBaseLocation(startNodes[0]); } else { List <SubWorld> list = new List <SubWorld>(); for (int i = 0; i < startNodes.Count; i++) { Tree tree = startNodes[i] as Tree; if (tree == null) { tree = worldGen.GetOverworldForNode(startNodes[i] as Leaf); if (tree == null) { continue; } } SubWorld subWorldForNode = worldGen.GetSubWorldForNode(tree); if (subWorldForNode != null && !list.Contains(subWorldForNode)) { list.Add(subWorldForNode); GameObject gameObject = UnityEngine.Object.Instantiate(locationButtonPrefab); RectTransform component = gameObject.GetComponent <RectTransform>(); component.SetParent(chooseLocationPanel); component.localScale = Vector3.one; Text componentInChildren = gameObject.GetComponentInChildren <Text>(); SubWorld subWorld = null; Tree parent = startNodes[i].parent; while (subWorld == null && parent != null) { subWorld = worldGen.GetSubWorldForNode(parent); if (subWorld == null) { parent = parent.parent; } } TagSet tagSet = new TagSet(startNodes[i].tags); tagSet.Remove(WorldGenTags.Feature); tagSet.Remove(WorldGenTags.StartLocation); tagSet.Remove(WorldGenTags.IgnoreCaveOverride); componentInChildren.text = tagSet.ToString(); int idx = i; Button.ButtonClickedEvent buttonClickedEvent = new Button.ButtonClickedEvent(); buttonClickedEvent.AddListener(delegate { ChooseBaseLocation(startNodes[idx]); }); Button component2 = gameObject.GetComponent <Button>(); component2.onClick = buttonClickedEvent; } } } }
private List <GameEntity> SpawnedObjects = new List <GameEntity>(); // Track all spawned Entities by PowerUps. /// <summary> /// Create PowerUp system. /// </summary> /// <param name="world">Owning SubWorld.</param> public PowerUpSystem(SubWorld world) : base(world) { }
/// <summary> /// Create Collider system. /// </summary> /// <param name="world">Owning SubWorld.</param> public ColliderSystem(SubWorld world) : base(world) { }