public override void OnBlockAdded(int value, int oldValue, int x, int y, int z) { ++ll; if (ll >= 2) { ll = 0; return; } //为箱子添加实体 try { Point3 point = new Point3(x, y, z); if (!pointlist.TryGetValue(point, out int vv)) { pointlist.Add(point, 0); } DatabaseObject databaseObject = base.Project.GameDatabase.Database.FindDatabaseObject("SingleChest", base.Project.GameDatabase.EntityTemplateType, throwIfNotFound: true); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(databaseObject); valuesDictionary.GetValue <ValuesDictionary>("BlockEntity").SetValue("Coordinates", new Point3(x, y, z)); Entity entity = base.Project.CreateEntity(valuesDictionary); base.Project.AddEntity(entity); } catch { //if (componentPlayer != null) componentPlayer.ComponentGui.DisplaySmallMessage($"",false,false); } }
public override void OnBlockAdded(int value, int oldValue, int x, int y, int z) { string name; switch (Terrain.ExtractContents(value)) { case BlastFurnaceBlock.Index: name = "BlastFurnace"; break; case CovenBlock.Index: name = "CokeOven"; break; case HearthFurnaceBlock.Index: name = "HearthFurnace"; break; case TankBlock.Index: if (TankBlock.GetType(value) == TankBlock.Type.FractionatingTower) { name = "FractionalTower"; break; } return; default: return; } var vd = new ValuesDictionary(); vd.PopulateFromDatabaseObject(Project.GameDatabase.Database.FindDatabaseObject(name, Project.GameDatabase.EntityTemplateType, true)); vd.GetValue <ValuesDictionary>("BlockEntity").SetValue("Coordinates", new Point3(x, y, z)); Project.AddEntity(Project.CreateEntity(vd)); }
public override void OnBlockAdded(int value, int oldValue, int x, int y, int z) { var vd = new ValuesDictionary(); vd.PopulateFromDatabaseObject(Project.GameDatabase.Database.FindDatabaseObject(Name, Project.GameDatabase.EntityTemplateType, true)); vd.GetValue <ValuesDictionary>("BlockEntity").SetValue("Coordinates", new Point3(x, y, z)); Project.AddEntity(Project.CreateEntity(vd)); }
public void ShipView_Enter() { ComponentBody componentBody = m_componentPlayer.Entity.FindComponent <ComponentBody>(throwOnError: true); Vector2 vector = FindOceanDirection(m_subsystemTerrain.TerrainContentsGenerator, componentBody.Position.XZ); Vector2 vector2 = componentBody.Position.XZ + 25f * vector; bool isPlayerMounted = m_componentPlayer.ComponentRider.Mount != null; Vector2 vector3 = vector2; float num = float.MinValue; for (int i = Terrain.ToCell(vector2.Y) - 15; i < Terrain.ToCell(vector2.Y) + 15; i++) { for (int j = Terrain.ToCell(vector2.X) - 15; j < Terrain.ToCell(vector2.X) + 15; j++) { float num2 = ScoreShipPosition(componentBody.Position.XZ, j, i); if (num2 > num) { num = num2; vector3 = new Vector2(j, i); } } } DatabaseObject databaseObject = base.Project.GameDatabase.Database.FindDatabaseObject("IntroShip", base.Project.GameDatabase.EntityTemplateType, throwIfNotFound: true); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(databaseObject); Entity entity = base.Project.CreateEntity(valuesDictionary); Vector3 vector4 = new Vector3(vector3.X, (float)m_subsystemTerrain.TerrainContentsGenerator.OceanLevel + 0.5f, vector3.Y); entity.FindComponent <ComponentFrame>(throwOnError: true).Position = vector4; entity.FindComponent <ComponentIntroShip>(throwOnError: true).Heading = Vector2.Angle(vector, -Vector2.UnitY); base.Project.AddEntity(entity); m_subsystemTime.QueueGameTimeDelayedExecution(2.0, delegate { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 1), 5f, 0f); }); m_subsystemTime.QueueGameTimeDelayedExecution(7.0, delegate { if (isPlayerMounted) { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 2), 5f, 0f); } else { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 3), 5f, 0f); } }); m_subsystemTime.QueueGameTimeDelayedExecution(12.0, delegate { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 4), 5f, 0f); }); IntroCamera introCamera = m_componentPlayer.GameWidget.FindCamera <IntroCamera>(); m_componentPlayer.GameWidget.ActiveCamera = introCamera; introCamera.CameraPosition = vector4 + new Vector3(12f * vector.X, 8f, 12f * vector.Y) + new Vector3(-5f * vector.Y, 0f, 5f * vector.X); introCamera.TargetPosition = m_componentPlayer.ComponentCreatureModel.EyePosition + 2.5f * new Vector3(vector.X, 0f, vector.Y); introCamera.Speed = 0f; introCamera.TargetCameraPosition = m_componentPlayer.ComponentCreatureModel.EyePosition; }
public ProjectData(GameDatabase gameDatabase, DatabaseObject projectTemplate, ValuesDictionary overrides) { ValuesDictionary = new ValuesDictionary(); ValuesDictionary.PopulateFromDatabaseObject(projectTemplate); if (overrides != null) { ValuesDictionary.ApplyOverrides(overrides); } }
public override void OnBlockAdded(int value, int oldValue, int x, int y, int z) { DatabaseObject databaseObject = base.Project.GameDatabase.Database.FindDatabaseObject("Chest", base.Project.GameDatabase.EntityTemplateType, throwIfNotFound: true); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(databaseObject); valuesDictionary.GetValue <ValuesDictionary>("BlockEntity").SetValue("Coordinates", new Point3(x, y, z)); Entity entity = base.Project.CreateEntity(valuesDictionary); base.Project.AddEntity(entity); }
public virtual void OnBlockAdded(SubsystemTerrain subsystemTerrain, int value, int oldValue) { if (oldValue == -1) { return; } var vd = new ValuesDictionary(); vd.PopulateFromDatabaseObject(subsystemTerrain.Project.GameDatabase.Database.FindDatabaseObject(Name, subsystemTerrain.Project.GameDatabase.EntityTemplateType, true)); vd.GetValue <ValuesDictionary>("BlockEntity").SetValue("Coordinates", Point); var entity = subsystemTerrain.Project.CreateEntity(vd); Component = entity.FindComponent <T>(true); subsystemTerrain.Project.AddEntity(entity); }
public override void OnBlockAdded(int value, int oldValue, int x, int y, int z) { if (Terrain.ExtractContents(oldValue) != 64 && Terrain.ExtractContents(oldValue) != 65) { DatabaseObject databaseObject = base.SubsystemTerrain.Project.GameDatabase.Database.FindDatabaseObject("Furnace", base.SubsystemTerrain.Project.GameDatabase.EntityTemplateType, throwIfNotFound: true); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(databaseObject); valuesDictionary.GetValue <ValuesDictionary>("BlockEntity").SetValue("Coordinates", new Point3(x, y, z)); Entity entity = base.SubsystemTerrain.Project.CreateEntity(valuesDictionary); base.SubsystemTerrain.Project.AddEntity(entity); } if (Terrain.ExtractContents(value) == 65) { AddFire(value, x, y, z); } }
public static bool addMekDynamicEntity(Project project, Point3 point, int max) { try { DatabaseObject databaseObject = project.GameDatabase.Database.FindDatabaseObject("MekDynamicBlock", project.GameDatabase.EntityTemplateType, throwIfNotFound: true); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(databaseObject); valuesDictionary.GetValue <ValuesDictionary>("BlockEntity").SetValue("Coordinates", point); valuesDictionary.GetValue <ValuesDictionary>("FluidBlock").SetValue <int>("MaxQuantity", max); valuesDictionary.GetValue <ValuesDictionary>("FluidBlock").SetValue <int>("Quantity", 0); valuesDictionary.GetValue <ValuesDictionary>("FluidBlock").SetValue <int>("Mode", 0); Entity entity = project.CreateEntity(valuesDictionary); project.AddEntity(entity); return(true); } catch { return(false); } }
public static void Initialize() { if (m_gameDatabase == null) { XElement node = ContentManager.Get <XElement>("Database"); ContentManager.Dispose("Database"); ModsManager.CombineXml(node, ModsManager.GetEntries(".xdb"), "Guid", "Name"); m_gameDatabase = new GameDatabase(XmlDatabaseSerializer.LoadDatabase(node)); foreach (DatabaseObject explicitNestingChild in GameDatabase.Database.Root.GetExplicitNestingChildren(GameDatabase.EntityTemplateType, directChildrenOnly: false)) { ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(explicitNestingChild); m_valueDictionaries.Add(explicitNestingChild.Name, valuesDictionary); } return; } throw new InvalidOperationException("Database already loaded."); }
public EntityData(GameDatabase gameDatabase, XElement entityNode) { Id = XmlUtils.GetAttributeValue <int>(entityNode, "Id"); Guid attributeValue = XmlUtils.GetAttributeValue(entityNode, "Guid", Guid.Empty); string attributeValue2 = XmlUtils.GetAttributeValue(entityNode, "Name", string.Empty); DatabaseObject databaseObject; if (attributeValue != Guid.Empty) { databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue, gameDatabase.EntityTemplateType, throwIfNotFound: true); } else { if (string.IsNullOrEmpty(attributeValue2)) { throw new InvalidOperationException("Entity template guid or name must be specified."); } databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue2, gameDatabase.EntityTemplateType, throwIfNotFound: true); } ValuesDictionary = new ValuesDictionary(); ValuesDictionary.PopulateFromDatabaseObject(databaseObject); ValuesDictionary.ApplyOverrides(entityNode); }
public ProjectData(GameDatabase gameDatabase, XElement projectNode, ValuesDictionary overrides, bool ignoreInvalidEntities) { Guid attributeValue = XmlUtils.GetAttributeValue(projectNode, "Guid", Guid.Empty); string attributeValue2 = XmlUtils.GetAttributeValue(projectNode, "Name", string.Empty); DatabaseObject databaseObject; if (attributeValue != Guid.Empty) { databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue, gameDatabase.ProjectTemplateType, throwIfNotFound: true); } else { if (string.IsNullOrEmpty(attributeValue2)) { throw new InvalidOperationException("Project template guid or name must be specified."); } databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue2, gameDatabase.ProjectTemplateType, throwIfNotFound: true); } ValuesDictionary = new ValuesDictionary(); ValuesDictionary.PopulateFromDatabaseObject(databaseObject); XElement xElement = XmlUtils.FindChildElement(projectNode, "Subsystems", throwIfNotFound: false); if (xElement != null) { ValuesDictionary.ApplyOverrides(xElement); } if (overrides != null) { ValuesDictionary.ApplyOverrides(overrides); } XElement xElement2 = XmlUtils.FindChildElement(projectNode, "Entities", throwIfNotFound: false); if (xElement2 != null) { EntityDataList = new EntityDataList(gameDatabase, xElement2, ignoreInvalidEntities); } }
public static void SpecialPasetData(CreatorAPI creatorAPI, string path, Point3 Start, Point3 End) { ChunkData chunkData = new ChunkData(creatorAPI); creatorAPI.revokeData = new ChunkData(creatorAPI); Stream stream = File.OpenRead(path); CreatorMain.Math.StartEnd(ref Start, ref End); StreamReader streamReader = new StreamReader(stream); string text = streamReader.ReadToEnd(); streamReader.Dispose(); stream.Dispose(); string[] data = text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); string[] data2 = data[0].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string[] data3 = data2[0].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int MaxX = int.Parse(data3[0]); int MaxY = int.Parse(data3[1]); int MaxZ = int.Parse(data3[2]); int num = 0; for (int x = 0; x <= MaxX; x++) { for (int y = 0; y <= MaxY; y++) { for (int z = 0; z <= MaxZ; z++) { creatorAPI.CreateBlock(End.X + x, End.Y + y, End.Z + z, int.Parse(data2[num + 1]), chunkData); num++; } } } chunkData.Render(); string[] data4 = data[1].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < data4.Length; i++) { string[] data5 = data4[i].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); string[] data6 = data5[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); DatabaseObject databaseObject = GameManager.Project.GameDatabase.Database.FindDatabaseObject(data5[0], GameManager.Project.GameDatabase.EntityTemplateType, true); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(databaseObject); valuesDictionary.GetValue <ValuesDictionary>("BlockEntity").SetValue <Point3>("Coordinates", new Point3(int.Parse(data6[0]) + End.X, int.Parse(data6[1]) + End.Y, int.Parse(data6[2]) + End.Z)); Entity entity = GameManager.Project.CreateEntity(valuesDictionary); ComponentInventoryBase inventoryBase = entity.FindComponent <ComponentInventoryBase>(); if (inventoryBase != null) { for (int j = 2, s = 0; j < data5.Length; j++, s++) { string[] data7 = data5[j].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); inventoryBase.AddSlotItems(s, int.Parse(data7[0]), int.Parse(data7[1])); } } GameManager.Project.AddEntity(entity); } string[] data8 = data[2].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < data8.Length; i++) { string[] data9 = data8[i].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); string[] data10 = data9[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); Entity entity = DatabaseManager.CreateEntity(GameManager.Project, data9[0], true); entity.FindComponent <ComponentBody>(true).Position = new Vector3(float.Parse(data10[0]) + End.X, float.Parse(data10[1]) + End.Y, float.Parse(data10[2]) + End.Z); entity.FindComponent <ComponentBody>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 1.2f); entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0.25f; ComponentInventoryBase inventoryBase = entity.FindComponent <ComponentInventoryBase>(); if (inventoryBase != null) { for (int j = 2, s = 0; j < data9.Length; j++, s++) { string[] data11 = data9[j].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); inventoryBase.AddSlotItems(s, int.Parse(data11[0]), int.Parse(data11[1])); } } GameManager.Project.AddEntity(entity); } creatorAPI.componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage($"粘贴成功,共{num}个方块", true, true); }