public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { BodyRaycastResult?bodyRaycastResult = componentMiner.Raycast <BodyRaycastResult>(ray, RaycastMode.Interaction); if (bodyRaycastResult.HasValue) { ComponentHealth componentHealth = bodyRaycastResult.Value.ComponentBody.Entity.FindComponent <ComponentHealth>(); if (componentHealth == null || componentHealth.Health > 0f) { string entityTemplateName = bodyRaycastResult.Value.ComponentBody.Entity.ValuesDictionary.DatabaseObject.Name + "_Saddled"; Entity entity = DatabaseManager.CreateEntity(base.Project, entityTemplateName, throwIfNotFound: false); if (entity != null) { ComponentBody componentBody = entity.FindComponent <ComponentBody>(throwOnError: true); componentBody.Position = bodyRaycastResult.Value.ComponentBody.Position; componentBody.Rotation = bodyRaycastResult.Value.ComponentBody.Rotation; componentBody.Velocity = bodyRaycastResult.Value.ComponentBody.Velocity; entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0f; base.Project.RemoveEntity(bodyRaycastResult.Value.ComponentBody.Entity, disposeEntity: true); base.Project.AddEntity(entity); m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); } } return(true); } return(false); }
public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { _ = componentMiner.Inventory; if (Terrain.ExtractContents(componentMiner.ActiveBlockValue) == 178) { TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Digging); if (terrainRaycastResult.HasValue) { Vector3 position = terrainRaycastResult.Value.HitPoint(); DynamicArray <ComponentBody> dynamicArray = new DynamicArray <ComponentBody>(); m_subsystemBodies.FindBodiesInArea(new Vector2(position.X, position.Z) - new Vector2(8f), new Vector2(position.X, position.Z) + new Vector2(8f), dynamicArray); if (dynamicArray.Count((ComponentBody b) => b.Entity.ValuesDictionary.DatabaseObject.Name == "Boat") < 6) { Entity entity = DatabaseManager.CreateEntity(base.Project, "Boat", throwIfNotFound: true); entity.FindComponent <ComponentFrame>(throwOnError: true).Position = position; entity.FindComponent <ComponentFrame>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.Float(0f, (float)Math.PI * 2f)); entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0f; base.Project.AddEntity(entity); componentMiner.RemoveActiveTool(1); m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, autoDelay: true); } else { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: false); } return(true); } } return(false); }
public static Widget OpenEntity(IInventory inventory, Entity entity) { var componentTrain = entity.FindComponent <ComponentTrain>(); var componentChest = entity.FindComponent <ComponentChest>(); if (componentTrain != null) { return(componentChest != null ? new NewChestWidget(inventory, componentChest, Utils.Get(componentTrain.ParentBody != null ? "车厢(已连接)" : "车厢")) : (Widget) new StoveWidget(inventory, componentTrain.ComponentEngine, "Widgets/TrainWidget")); } var componentEngine = entity.FindComponent <ComponentEngine>(); if (componentEngine != null) { return(new Engine2Widget(inventory, componentEngine)); } var componentEngine3 = entity.FindComponent <ComponentEngineA>(); if (componentEngine3 != null) { return(new EngineAWidget(inventory, componentEngine3)); } return(null); }
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 CreativeInventoryWidget(Entity entity) { m_componentCreativeInventory = entity.FindComponent <ComponentCreativeInventory>(throwOnError: true); XElement node = ContentManager.Get <XElement>("Widgets/CreativeInventoryWidget"); LoadContents(this, node); m_categoryLeftButton = Children.Find <ButtonWidget>("CategoryLeftButton"); m_categoryRightButton = Children.Find <ButtonWidget>("CategoryRightButton"); m_categoryButton = Children.Find <ButtonWidget>("CategoryButton"); m_pageUpButton = Children.Find <ButtonWidget>("PageUpButton"); m_pageDownButton = Children.Find <ButtonWidget>("PageDownButton"); m_pageLabel = Children.Find <LabelWidget>("PageLabel"); m_panelContainer = Children.Find <ContainerWidget>("PanelContainer"); CreativeInventoryPanel creativeInventoryPanel = new CreativeInventoryPanel(this) { IsVisible = false }; m_panelContainer.Children.Add(creativeInventoryPanel); FurnitureInventoryPanel furnitureInventoryPanel = new FurnitureInventoryPanel(this) { IsVisible = false }; m_panelContainer.Children.Add(furnitureInventoryPanel); foreach (string category in BlocksManager.Categories) { m_categories.Add(new Category { Name = category, Panel = creativeInventoryPanel }); } m_categories.Add(new Category { Name = LanguageControl.Get(fName, 1), Panel = furnitureInventoryPanel }); m_categories.Add(new Category { Name = LanguageControl.Get(fName, 2), Panel = creativeInventoryPanel }); for (int i = 0; i < m_categories.Count; i++) { if (m_categories[i].Name == LanguageControl.Get("BlocksManager", "Electrics")) { m_categories[i].Color = new Color(128, 140, 255); } if (m_categories[i].Name == LanguageControl.Get("BlocksManager", "Plants")) { m_categories[i].Color = new Color(64, 160, 64); } if (m_categories[i].Name == LanguageControl.Get("BlocksManager", "Weapons")) { m_categories[i].Color = new Color(255, 128, 112); } } }
public override bool OnHitAsProjectile(CellFace?cellFace, ComponentBody componentBody, WorldItem worldItem) { int data = TerrainData.ExtractData(worldItem.Value); bool isLaid = EggBlock.GetIsLaid(data); if (!EggBlock.GetIsCooked(data) && ((this.m_subsystemGameInfo.WorldInfo.GameMode == GameMode.Creative) || (this.m_random.UniformFloat(0f, 1f) <= (isLaid ? 0.2f : 1f)))) { EggBlock.EggType eggType = this.m_eggBlock.GetEggType(data); Entity entity = this.m_subsystemEntityFactory.CreateEntity(eggType.TemplateName, true); entity.FindComponent <ComponentBody>(true).Position = worldItem.Position; entity.FindComponent <ComponentBody>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, this.m_random.UniformFloat(0f, 6.283185f)); entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0.25f; base.Project.AddEntity(entity); } return(true); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_componentMount = Entity.FindComponent <ComponentMount>(true); m_componentBody = Entity.FindComponent <ComponentBody>(true); m_componentDamage = Entity.FindComponent <ComponentDamage>(true); componentEngine = Entity.FindComponent <ComponentEngineA>(); Entity.FindComponent <ComponentModel>().TextureOverride = Airship.WhiteTexture; }
public void ComponentSpawn_Despawned(ComponentSpawn componentSpawn) { if (m_componentHealth.Health > 0f && !string.IsNullOrEmpty(m_spawnEntityTemplateName)) { Entity entity = DatabaseManager.CreateEntity(base.Project, m_spawnEntityTemplateName, throwIfNotFound: true); ComponentBody componentBody = entity.FindComponent <ComponentBody>(throwOnError: true); componentBody.Position = m_componentBody.Position; componentBody.Rotation = m_componentBody.Rotation; componentBody.Velocity = m_componentBody.Velocity; entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0.5f; base.Project.AddEntity(entity); } if (m_particleSystem != null) { m_particleSystem.Stopped = true; } }
public override void OnEntityRemoved(Entity entity) { ComponentCreature componentCreature = entity.FindComponent <ComponentCreature>(); if (componentCreature != null) { m_lastInjuryTimes.Remove(componentCreature); } }
public override void OnEntityRemoved(Entity entity) { ComponentBlockEntity componentBlockEntity = entity.FindComponent <ComponentBlockEntity>(); if (componentBlockEntity != null) { m_blockEntities.Remove(componentBlockEntity.Coordinates); } }
public T GetComponent <T>(Entity localEntity, IdToEntityMap idToEntityMap, bool throwIfNotFound) where T : class { Entity entity = GetEntity(localEntity, idToEntityMap, throwIfNotFound); if (entity == null) { return(null); } return(entity.FindComponent <T>(m_componentReference, throwIfNotFound)); }
public static EntityReference FromName(Entity entity) { string entityReference = (entity != null) ? entity.FindComponent <ComponentName>(null, throwOnError: true).Name : string.Empty; EntityReference result = default(EntityReference); result.m_referenceType = ReferenceType.ByEntityName; result.m_entityReference = entityReference; result.m_componentReference = string.Empty; return(result); }
public T FindComponentByName <T>(string name, string componentName) where T : Component { Entity entity = FindEntityByName(name); if (entity == null) { return(null); } return(entity.FindComponent <T>(componentName, throwOnError: false)); }
public static string GetEntityName(Entity entity) { ComponentName componentName = entity.FindComponent <ComponentName>(); if (componentName != null) { return(componentName.Name); } return(string.Empty); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { //base.Load(valuesDictionary, idToEntityMap); m_matchedIngredients = new string[36]; this.LoadItems(valuesDictionary); //m_subsystemExplosions = Project.FindSubsystem<SubsystemExplosions>(true); m_componentBlockEntity = Entity.FindComponent <ComponentBlockEntity>(true); m_fireTimeRemaining = valuesDictionary.GetValue("FireTimeRemaining", 0f); m_furnaceSize = SlotsCount - 5; m_fireTimeRemaining = valuesDictionary.GetValue("FireTimeRemaining", 0f); m_updateSmeltingRecipe = true; }
public Entity SpawnEntity(SpawnEntityData data) { try { Entity entity = DatabaseManager.CreateEntity(base.Project, data.TemplateName, throwIfNotFound: true); entity.FindComponent <ComponentBody>(throwOnError: true).Position = data.Position; entity.FindComponent <ComponentBody>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.Float(0f, (float)Math.PI * 2f)); ComponentCreature componentCreature = entity.FindComponent <ComponentCreature>(); if (componentCreature != null) { componentCreature.ConstantSpawn = data.ConstantSpawn; } base.Project.AddEntity(entity); return(entity); } catch (Exception ex) { Log.Error($"Unable to spawn entity with template \"{data.TemplateName}\". Reason: {ex.Message}"); return(null); } }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { base.Load(valuesDictionary, idToEntityMap); ExplosionPressure = valuesDictionary.GetValue("ExplosionPressure", 60f); MineType = valuesDictionary.GetValue <MineType>("Type", 0); Delay = valuesDictionary.GetValue("Delay", .0); (ComponentBody = Entity.FindComponent <ComponentBody>(true)).CollidedWithBody += CollidedWithBody; if ((MineType & MineType.Torpedo) != 0) { ComponentBody.Density = .8f; } }
public bool IsPredator(Entity entity) { if (entity != base.Entity) { ComponentCreature componentCreature = entity.FindComponent <ComponentCreature>(); if (componentCreature != null && (componentCreature.Category == CreatureCategory.LandPredator || componentCreature.Category == CreatureCategory.WaterPredator || componentCreature.Category == CreatureCategory.LandOther)) { return(true); } } return(false); }
public override bool OnHitAsProjectile(CellFace?cellFace, ComponentBody componentBody, WorldItem worldItem) { int data = Terrain.ExtractData(worldItem.Value); bool isCooked = EggBlock.GetIsCooked(data); bool isLaid = EggBlock.GetIsLaid(data); if (!isCooked && (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative || m_random.Float(0f, 1f) <= (isLaid ? 0.15f : 1f))) { if (m_subsystemCreatureSpawn.Creatures.Count < 35) { EggBlock.EggType eggType = m_eggBlock.GetEggType(data); Entity entity = DatabaseManager.CreateEntity(base.Project, eggType.TemplateName, throwIfNotFound: true); entity.FindComponent <ComponentBody>(throwOnError: true).Position = worldItem.Position; entity.FindComponent <ComponentBody>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.Float(0f, (float)Math.PI * 2f)); entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0.25f; base.Project.AddEntity(entity); } else { ((worldItem as Projectile)?.Owner as ComponentPlayer)?.ComponentGui.DisplaySmallMessage("Too many creatures", Color.White, blinking: true, playNotificationSound: false); } } return(true); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { base.Load(valuesDictionary, idToEntityMap); m_componentBody = Entity.FindComponent <ComponentBody>(true); componentDamage = Entity.FindComponent <ComponentDamage>(); m_componentMount = Entity.FindComponent <ComponentMount>(true); if ((ComponentEngine = Entity.FindComponent <ComponentEngine>()) != null) { m_componentBody.CollidedWithBody += CollidedWithBody; } else { ParentBody = valuesDictionary.GetValue("ParentBody", default(EntityReference)).GetComponent <ComponentTrain>(Entity, idToEntityMap, false); } Direction = valuesDictionary.GetValue("Direction", 0); }
public void OnEntityAdded(Entity entity) { ComponentPlayer componentPlayer = entity.FindComponent <ComponentPlayer>(); if (componentPlayer != null && componentPlayer.PlayerData == this) { if (ComponentPlayer != null) { throw new InvalidOperationException(string.Format(LanguageControl.Get(fName, 10), PlayerIndex)); } ComponentPlayer = componentPlayer; GameWidget.ActiveCamera = GameWidget.FindCamera <FppCamera>(); GameWidget.Target = componentPlayer; if (FirstSpawnTime < 0.0) { FirstSpawnTime = m_subsystemGameInfo.TotalElapsedGameTime; } } }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { ComponentGui = Entity.FindComponent <ComponentGui>(true); base.Load(valuesDictionary, idToEntityMap); }
void InitCommands() { commands["msg"] = new CommandDefination { Usage = "msg @a/r/p/e <string> [bool=true] [bool=true]", AutoComplete = (obj) => obj.Enum(enumCreatureType).String().Bool().Bool(), Operation = (obj) => { string type = obj.NextString(); string msg = obj.NextString(); bool b1 = obj.NextBool(true); bool b2 = obj.NextBool(true); FindPlayer(type, obj, (a) => { a.ComponentGui.DisplaySmallMessage(msg, b1, b2); }); } }; commands["msgl"] = new CommandDefination { Usage = "msgl @a/r/p/e <string> <string> <string> [float=5] [float=0]", AutoComplete = (obj) => obj.Enum(enumCreatureType).String().String().Float().Float(), Operation = (obj) => { string type = obj.NextString(); string m1 = obj.NextString(); string m2 = obj.NextString(); float f1 = obj.NextFloat(5); float f2 = obj.NextFloat(0); FindPlayer(type, obj, (a) => { a.ComponentGui.DisplayLargeMessage(m1, m2, f1, f2); }); } }; commands["kill"] = new CommandDefination { Usage = "kill @a/r/p/e [string=magic]", AutoComplete = (obj) => obj.Enum(enumCreatureType).String(), Operation = (obj) => { string type = obj.NextString(); string reason = obj.NextString("magic"); EnumCreatures(type, obj, (c) => { c.ComponentHealth.Injure(1, null, true, reason); }); } }; commands["health"] = new CommandDefination { Usage = "health heal/injure [float=1] [string=magic]", AutoComplete = (obj) => obj.Enum(new string[] { "heal", "injure" }).Float().String(), Operation = (obj) => { string type = obj.NextString(); switch (type) { case "heal": float amount1 = obj.NextFloat(1); obj.Creature.ComponentHealth.Heal(amount1); break; case "injure": float amount = obj.NextFloat(1); string reason = obj.NextString("magic"); obj.Creature.ComponentHealth.Injure(amount, null, true, reason); break; default: throw new Exception("usage: health heal/injure [float=1] [string=magic]"); } } }; commands["strike"] = new CommandDefination { Usage = "strike <vector3>", AutoComplete = (obj) => obj.Vector3(), Operation = (obj) => { subsystemSky.MakeLightningStrike(obj.NextVector3()); } }; commands["setblock"] = new CommandDefination { Usage = "setblock <point3> <int>", AutoComplete = (obj) => obj.Point3().Int(), Operation = (s) => { var p = s.NextPoint3(); subsystemTerrain.ChangeCell(p.X, p.Y, p.Z, s.NextInt()); } }; commands["place"] = new CommandDefination { Usage = "place <point3> <int> [bool=false] [bool=false]", AutoComplete = (obj) => obj.Point3().Int().Bool().Bool(), Operation = (obj) => { var p = obj.NextPoint3(); subsystemTerrain.DestroyCell(2, p.X, p.Y, p.Z, obj.NextInt(), obj.NextBool(false), obj.NextBool(false)); } }; commands["fill"] = new CommandDefination { Usage = "fill <point3> <point3>", AutoComplete = (obj) => obj.Point3().Point3().Int(), Operation = (obj) => { var p1 = obj.NextPoint3(); var p2 = obj.NextPoint3(); var startx = Math.Min(p1.X, p2.X); var endx = Math.Max(p1.X, p2.X); var starty = Math.Min(p1.Y, p2.Y); var endy = Math.Max(p1.Y, p2.Y); var startz = Math.Min(p1.Z, p2.Z); var endz = Math.Max(p1.Z, p2.Z); var val = obj.NextInt(); for (int x = startx; x <= endx; x++) { for (int y = starty; y <= endy; y++) { for (int z = startz; z <= endz; z++) { subsystemTerrain.Terrain.SetCellValueFast(x, y, z, val); } } } var startChunk = Terrain.ToChunk(startx, startz); var endChunk = Terrain.ToChunk(endx, endz); for (int x = startChunk.X; x <= endChunk.X; x++) { for (int y = startChunk.Y; y <= endChunk.Y; y++) { var c = subsystemTerrain.Terrain.GetChunkAtCoords(x, y); if (c != null) { subsystemTerrain.TerrainUpdater.DowngradeChunkNeighborhoodState(c.Coords, 1, TerrainChunkState.InvalidLight, false); } } } } }; commands["time"] = new CommandDefination { Usage = "time add/set <float>", AutoComplete = (obj) => obj.Enum(new string[] { "add", "set" }).Float(), Operation = (obj) => { switch (obj.NextString()) { case "add": subsystemTime.TimeOfDayOffset += obj.NextFloat(); break; case "set": subsystemTime.TimeOfDayOffset = obj.NextFloat(); break; default: throw new Exception("usage: time add/set <float>"); } } }; commands["execute"] = new CommandDefination { Usage = "execute @a/r/p/e <another command>", AutoComplete = (obj) => { obj.Enum(enumCreatureType); AutoCompleteCommand(obj.CommandStream.GetAllLeft(), obj.Reciver); }, Operation = (obj) => { var type = obj.NextString(); var command = obj.GetAllLeft(); EnumCreatures(type, obj, (a) => { RunCommand(a, command); }); } }; commands["setdata"] = new CommandDefination { Usage = "setdata <creature data> <data type>", AutoComplete = (obj) => { obj.Enum(creatureDatas.Keys); string component = obj.CommandStream.Last; int i = creatureDatas[component]; switch (i) { case 0: obj.Any(typeof(ComponentLocomotion).GetProperty(component).PropertyType); break; case 1: obj.Any(typeof(ComponentHealth).GetProperty(component).PropertyType); break; case 2: obj.Any(typeof(ComponentBody).GetProperty(component).PropertyType); break; } }, Operation = (s) => { while (s.HasNext) { var component = s.NextString(); PropertyInfo p; if (creatureDatas.TryGetValue(component, out int i)) { switch (i) { case 0: p = typeof(ComponentLocomotion).GetProperty(component); p.SetValue(s.Creature.ComponentLocomotion, s.Next(p.PropertyType), null); break; case 1: p = typeof(ComponentHealth).GetProperty(component); p.SetValue(s.Creature.ComponentHealth, s.Next(p.PropertyType), null); break; case 2: p = typeof(ComponentBody).GetProperty(component); p.SetValue(s.Creature.ComponentBody, s.Next(p.PropertyType), null); break; } } else { throw new Exception(component + " is not a creature data"); } } } }; commands["gameinfo"] = new CommandDefination { Usage = "gameinfo <info name> <info value>", AutoComplete = (obj) => { Type settings = typeof(WorldSettings); obj.Enum(settings.GetFields().Select(f => f.Name)); obj.Any(settings.GetField(obj.CommandStream.Last).FieldType); }, Operation = (s) => { var setting = s.NextString(); var val = s.NextString(); var f = typeof(WorldSettings).GetField(setting); if (f != null) { f.SetValue(GameManager.WorldInfo.WorldSettings, ChangeType(val, f.FieldType)); } } }; commands["summon"] = new CommandDefination { Usage = "summon <animal name> <vector3> [float=0]", AutoComplete = (obj) => obj.String().Vector3().Float(), Operation = (s) => { var name = s.NextString(); var position = s.NextVector3(); var rotation = s.NextFloat(0); Entity entity = DatabaseManager.CreateEntity(Project, creatureTemplateNames[name], true); entity.FindComponent <ComponentBody>(true).Position = position; entity.FindComponent <ComponentBody>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, rotation); entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0.25f; Project.AddEntity(entity); } }; commands["tp"] = new CommandDefination { Usage = "tp <vector3>", AutoComplete = (obj) => obj.Vector3(), Operation = s => s.Creature.ComponentBody.Position = s.NextVector3() }; commands["additem"] = new CommandDefination { Usage = "additem <vector3> <int> [int=1] [vector=0,0,0]", AutoComplete = (obj) => obj.Vector3().Int().Int().Vector3(), Operation = s => { var position = s.NextVector3(); var val = s.NextInt(); var count = s.NextInt(1); Vector3?speed = null; if (s.HasNext) { speed = s.NextVector3(); } Project.FindSubsystem <SubsystemPickables>(true).AddPickable(s.NextInt(), s.NextInt(1), position, speed, null); } }; commands["give"] = new CommandDefination { Usage = "give @a/r/p/e <int> [int=1]", AutoComplete = (obj) => obj.Enum(enumCreatureType).Int().Int(), Operation = s => { var enumType = s.NextString(); var val = s.NextInt(); var count = s.NextInt(1); FindPlayer(enumType, s, (p) => ComponentInventoryBase.AcquireItems(p.ComponentMiner.Inventory, val, count)); } }; foreach (string name in commands.Keys) { commandUsage[commands[name].Usage] = name; } } void LoadBlockIds() { foreach (Block b in BlocksManager.Blocks) { foreach (int id in b.GetCreativeValues()) { var name = b.GetDisplayName(subsystemTerrain, id).Replace(' ', '_').ToLower(); blockIds[name] = id; } blockIds[b.DefaultDisplayName.Replace(' ', '_').ToLower()] = b.BlockIndex; } } void FindPlayer(string type, CommandStream s, Action <ComponentPlayer> a) { if (type[0] == '@') { EnumCreatures(type, s, c => { if (c is ComponentPlayer) { a(c as ComponentPlayer); } }); } else { FindPlayerByName(type, a); } } void FindPlayerByName(string name, Action <ComponentPlayer> a) { foreach (ComponentPlayer p in subsystemPlayers.ComponentPlayers) { if (p.PlayerData.Name == name) { a(p); } else { throw new WrongArgTypeException(name, "player"); } } } void LoadCreatureTemplateNames() { var paramterType = DatabaseManager.GameDatabase.ParameterType; var entities = DatabaseManager.GameDatabase.Database.Root.GetExplicitNestingChildren(paramterType, false); var displayName = new Guid("715ff548-ef2b-430e-8e6b-51b934e5da1d"); foreach (TemplatesDatabase.DatabaseObject o in entities) { if (o.EffectiveInheritanceRoot.Guid == displayName && o.Value.ToString() != string.Empty) { creatureTemplateNames[o.NestingParent.NestingParent.Name.ToLower()] = o.Value.ToString(); //Log.Information("{0}, {1}", o.NestingParent.NestingParent.Name, o.Value); } } } void LoadCreatureDatas() { foreach (PropertyInfo p in typeof(ComponentLocomotion).GetRuntimeProperties()) { if (CommandStream.IsTypeSupported(p.PropertyType)) { creatureDatas[p.Name] = 0; } } foreach (PropertyInfo p in typeof(ComponentHealth).GetRuntimeProperties()) { if (CommandStream.IsTypeSupported(p.PropertyType)) { creatureDatas[p.Name] = 1; } } foreach (PropertyInfo p in typeof(ComponentBody).GetRuntimeProperties()) { if (CommandStream.IsTypeSupported(p.PropertyType)) { creatureDatas[p.Name] = 2; } } } void EnumCreatures(string type, CommandStream s, Action <ComponentCreature> a) { var data = new EnumData(type, subsystemCreature.Creatures.Count, s.ExePosition); if (data.name == "player") { data.name = string.Empty; SearchCreature(data, SortCreatures(data, subsystemPlayers.ComponentPlayers), a); } else { SearchCreature(data, SortCreatures(data, subsystemCreature.Creatures), a); } } List <ComponentCreature> SortCreatures <T>(EnumData data, IEnumerable <T> collection) where T : ComponentCreature { var l = new List <ComponentCreature>(); if (data.mode1 == SearchingMode1.Regular) { foreach (ComponentCreature c in collection) { if (CheckCreatureWithData(data, c)) { l.Add(c); } } } else if (data.mode1 == SearchingMode1.Nearest) { var v = new Vector3(data.x, data.y, data.z); var dict = new Dictionary <float, ComponentCreature>(); foreach (ComponentCreature c in collection) { if (CheckCreatureWithData(data, c)) { dict.Add(Vector3.DistanceSquared(v, c.ComponentBody.Position), c); } } var l2 = new List <float>(); foreach (float i in dict.Keys) { l2.Add(i); } l2.Sort(delegate(float i1, float i2) { if (i1 > i2) { return(1); } return(-1); }); foreach (float i in l2) { l.Add(dict[i]); } } else { foreach (ComponentCreature c in collection) { if (CheckCreatureWithData(data, c)) { l.Add(c); } } var r = new Random(); var count = l.Count; int n = l.Count; while (n > 1) { n--; int k = r.UniformInt(0, n); var value = l[k]; l[k] = l[n]; l[n] = value; } } return(l); } void SearchCreature(EnumData data, List <ComponentCreature> sorted, Action <ComponentCreature> a) { for (int i = 0; i < data.count; i++) { if (i >= sorted.Count) { return; } a.Invoke(sorted[i]); } } bool CheckCreatureWithData(EnumData data, ComponentCreature c) { if (data.name != string.Empty) { string dataname; if (data.name[0] == '!') { Log.Information(c.DisplayName); if (creatureTemplateNames.TryGetValue(data.name.Substring(1), out dataname)) { if (dataname == c.DisplayName) { return(false); } } else { return(false); } } else { if (creatureTemplateNames.TryGetValue(data.name, out dataname)) { if (dataname != c.DisplayName) { return(false); } } else { return(false); } } } switch (data.SearchingMode) { case SearchingMode.Radius: if (data.r > 0) { if (Vector3.DistanceSquared(new Vector3(data.x, data.y, data.z), c.ComponentBody.Position) >= data.r2) { return(false); } } else { if (Vector3.DistanceSquared(new Vector3(data.x, data.y, data.z), c.ComponentBody.Position) <= data.r2) { return(false); } } break; case SearchingMode.Volume: var p = c.ComponentBody.Position; var x = p.X - data.x; var y = p.Y - data.y; var z = p.Z - data.z; if (x < 0 && x > data.dx && y < 0 && y > data.dy && z < 0 && z > data.dz) { return(false); } break; } return(true); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { this.LoadItems(valuesDictionary); m_componentBlockEntity = Entity.FindComponent <ComponentBlockEntity>(true); SubsystemPlayers = Project.FindSubsystem <SubsystemPlayers>(true); }
public override void OnEntityAdded() { if (Genome.DominantGenes == null) { Task.Run((Action)Initialize); return; } var caj = Entity.FindComponent <ComponentAutoJump>(); if (caj != null) { caj.m_jumpStrength = Genome[Trait.JumpStrength]; } var cafb = Entity.FindComponent <ComponentAvoidFireBehavior>(); if (cafb != null) { cafb.m_dayRange = Genome[Trait.AvoidFire_DayRange]; cafb.m_nightRange = Genome[Trait.AvoidFire_NightRange]; } var capb = Entity.FindComponent <ComponentAvoidPlayerBehavior>(); if (capb != null) { capb.m_dayRange = Genome[Trait.AvoidPlayer_DayRange]; capb.m_nightRange = Genome[Trait.AvoidPlayer_NightRange]; } var cb = Entity.FindComponent <ComponentBody>(); if (cb != null) { cb.BoxSize = new Vector3( Genome[Trait.BoxSizeX], Genome[Trait.BoxSizeY], Genome[Trait.BoxSizeZ]); cb.Mass = Genome[Trait.Mass]; cb.Density = Genome[Trait.Density]; var vec2 = new Vector2(Genome[Trait.AirDragX], Genome[Trait.AirDragY]); cb.AirDrag = vec2; vec2 = new Vector2(Genome[Trait.WaterDragX], Genome[Trait.WaterDragY]); cb.WaterDrag = vec2; cb.WaterSwayAngle = Genome[Trait.WaterSwayAngle]; cb.WaterTurnSpeed = Genome[Trait.WaterTurnSpeed]; cb.MaxSmoothRiseHeight = Genome[Trait.MaxSmoothRiseHeight]; } var ccb = Entity.FindComponent <ComponentChaseBehavior>(); if (ccb != null) { ccb.m_dayChaseRange = Genome[Trait.DayChaseRange]; ccb.m_nightChaseRange = Genome[Trait.NightChaseRange]; ccb.m_dayChaseTime = Genome[Trait.DayChaseTime]; ccb.m_nightChaseTime = Genome[Trait.NightChaseTime]; ccb.m_autoChaseMask = (CreatureCategory)(int)Genome[Trait.AutoChaseMask]; ccb.m_chaseNonPlayerProbability = Genome[Trait.ChaseNonPlayerProbability]; ccb.m_chaseWhenAttackedProbability = Genome[Trait.ChaseWhenAttackedProbability]; ccb.m_chaseOnTouchProbability = Genome[Trait.ChaseOnTouchProbability]; } var cdb = Entity.FindComponent <ComponentDigInMudBehavior>(); if (cdb != null) { cdb.m_maxDigInDepth = Genome[Trait.MaxDigInDepth]; } var ceb = Entity.FindComponent <ComponentEatPickableBehavior>(); if (ceb != null) { ceb.m_foodFactors[(int)FoodType.Meat] = Genome[Trait.MeatFoodFactor]; ceb.m_foodFactors[(int)FoodType.Fish] = Genome[Trait.FishFoodFactor]; ceb.m_foodFactors[(int)FoodType.Fruit] = Genome[Trait.FruitFoodFactor]; ceb.m_foodFactors[(int)FoodType.Grass] = Genome[Trait.GrassFoodFactor]; ceb.m_foodFactors[(int)FoodType.Bread] = Genome[Trait.BreadFoodFactor]; } var cfb = Entity.FindComponent <ComponentFindPlayerBehavior>(); if (cfb != null) { cfb.m_dayRange = Genome[Trait.FindPlayer_DayRange]; cfb.m_nightRange = Genome[Trait.FindPlayer_NightRange]; } var cge = Entity.FindComponent <ComponentGlowingEyes>(); if (cge != null) { cge.GlowingEyesColor = new Color((uint)Genome[Trait.GlowingEyesColor] | 4278190080u); } var ch = Entity.FindComponent <ComponentHealth>(); if (ch != null) { ch.AttackResilience = Genome[Trait.AttackResilience]; ch.FallResilience = Genome[Trait.FallResilience]; ch.FireResilience = Genome[Trait.FireResilience]; ch.CanStrand = Genome[Trait.CanStrand] > 0; ch.AirCapacity = Genome[Trait.AirCapacity]; } var chb = Entity.FindComponent <ComponentHerdBehavior>(); if (chb != null) { float v = Genome[Trait.HerdingRange]; chb.m_herdingRange = MathUtils.Abs(v); chb.m_autoNearbyCreaturesHelp = v < 0; } var cl = Entity.FindComponent <ComponentLocomotion>(); if (cl != null) { cl.AccelerationFactor = Genome[Trait.AccelerationFactor]; cl.WalkSpeed = Genome[Trait.WalkSpeed]; cl.m_walkSpeedWhenTurning = Genome[Trait.WalkSpeedWhenTurning]; cl.LadderSpeed = Genome[Trait.LadderSpeed]; cl.JumpSpeed = Genome[Trait.JumpSpeed]; cl.CreativeFlySpeed = Genome[Trait.CreativeFlySpeed]; cl.FlySpeed = Genome[Trait.FlySpeed]; cl.SwimSpeed = Genome[Trait.SwimSpeed]; cl.TurnSpeed = Genome[Trait.TurnSpeed]; cl.LookSpeed = Genome[Trait.LookSpeed]; cl.InAirWalkFactor = Genome[Trait.InAirWalkFactor]; int v = (int)Genome[Trait.LookAutoLevel]; cl.m_lookAutoLevelX = (v & 1) != 0; cl.m_lookAutoLevelY = (v & 2) != 0; } var cloot = Entity.FindComponent <ComponentLoot>(); if (cloot != null) { ComponentLoot.Loot item; if (cloot.m_lootList.Count > 0) { item = cloot.m_lootList[0]; item.MinCount = (int)Genome[Trait.LootMinCount]; item.MaxCount = (int)Genome[Trait.LootMaxCount]; item.Probability = Genome[Trait.LootProbability]; cloot.m_lootList[0] = item; } if (cloot.m_lootOnFireList.Count > 0) { item = cloot.m_lootOnFireList[0]; item.MinCount = (int)Genome[Trait.LootOnFireMinCount]; item.MaxCount = (int)Genome[Trait.LootOnFireMaxCount]; item.Probability = Genome[Trait.LootOnFireProbability]; cloot.m_lootOnFireList[0] = item; } } var cmr = Entity.FindComponent <ComponentMiner>(); if (cmr != null) { cmr.AttackPower = Genome[Trait.AttackPower]; } var cm = Entity.FindComponent <ComponentModel>(); if (cm != null) { cm.DiffuseColor = new Vector3(new Color((uint)Genome[Trait.DiffuseColor] | 4278190080u)); cm.Opacity = Genome[Trait.Opacity]; } var cleb = Entity.FindComponent <ComponentLayEggBehavior>(); if (cleb != null) { cleb.m_layFrequency = Genome[Trait.LayFrequency]; } var cs = Entity.FindComponent <ComponentShapeshifter>(); if (cs != null) { cs.IsEnabled = Utils.Random.UniformFloat(0f, 1f) < Genome[Trait.ShapeshifterProbability]; } var cssb = Entity.FindComponent <ComponentStubbornSteedBehavior>(); if (cssb != null) { cssb.m_stubbornProbability = Genome[Trait.StubbornProbability]; } var cu = Entity.FindComponent <ComponentUdder>(); if (cu != null) { cu.m_milkRegenerationTime = Genome[Trait.MilkRegenerationTime]; } OGenome = Genome.DominantGenes; //Hybridize(); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { base.Load(valuesDictionary, idToEntityMap); componentEngine = Entity.FindComponent <ComponentEngine>(); }
public override int RemoveSlotItems(int slotIndex, int count) { int num = 0; if (slotIndex == ResultSlotIndex) { if (m_matchedRecipe != null) { if (m_matchedRecipe.RemainsValue != 0 && m_matchedRecipe.RemainsCount > 0) { if (m_slots[RemainsSlotIndex].Count == 0 || m_slots[RemainsSlotIndex].Value == m_matchedRecipe.RemainsValue) { int num2 = BlocksManager.Blocks[Terrain.ExtractContents(m_matchedRecipe.RemainsValue)].MaxStacking - m_slots[RemainsSlotIndex].Count; count = MathUtils.Min(count, num2 / m_matchedRecipe.RemainsCount); } else { count = 0; } } count = count / m_matchedRecipe.ResultCount * m_matchedRecipe.ResultCount; if (slotIndex >= 0 && slotIndex < m_slots.Count) { Slot slot = m_slots[slotIndex]; count = MathUtils.Min(count, GetSlotCount(slotIndex)); slot.Count -= count; num = count; } else { num = 0; } if (num > 0) { for (int index = 0; index < 36; index++) { if (!string.IsNullOrEmpty(m_matchedIngredients[index])) { int index2 = index % 6 + m_craftingGridSize * (index / 6); m_slots[index2].Count = MathUtils.Max(m_slots[index2].Count - num / m_matchedRecipe.ResultCount, 0); } } if (m_matchedRecipe.RemainsValue != 0 && m_matchedRecipe.RemainsCount > 0) { m_slots[RemainsSlotIndex].Value = m_matchedRecipe.RemainsValue; m_slots[RemainsSlotIndex].Count += num / m_matchedRecipe.ResultCount * m_matchedRecipe.RemainsCount; } ComponentPlayer componentPlayer = Entity.FindComponent <ComponentPlayer>(); if (componentPlayer == null) { ComponentBlockEntity componentBlockEntity = Entity.FindComponent <ComponentBlockEntity>(); if (componentBlockEntity != null) { var position = new Vector3(componentBlockEntity.Coordinates); componentPlayer = Project.FindSubsystem <SubsystemPlayers>(true).FindNearestPlayer(position); } } if (componentPlayer != null && componentPlayer.PlayerStats != null) { componentPlayer.PlayerStats.ItemsCrafted += num; } } } } else { if (slotIndex >= 0 && slotIndex < m_slots.Count) { Slot slot = m_slots[slotIndex]; count = MathUtils.Min(count, GetSlotCount(slotIndex)); slot.Count -= count; num = count; } else { num = 0; } } UpdateCraftingResult(); return(num); }
public void Initialize() { Genome = new Genome(new float[68], new float[68]); var caj = Entity.FindComponent <ComponentAutoJump>(); if (caj != null) { Genome[Trait.JumpStrength] = caj.m_jumpStrength; } var cafb = Entity.FindComponent <ComponentAvoidFireBehavior>(); if (cafb != null) { Genome[Trait.AvoidFire_DayRange] = cafb.m_dayRange; Genome[Trait.AvoidFire_NightRange] = cafb.m_nightRange; } var capb = Entity.FindComponent <ComponentAvoidPlayerBehavior>(); if (capb != null) { Genome[Trait.AvoidPlayer_DayRange] = capb.m_dayRange; Genome[Trait.AvoidPlayer_NightRange] = capb.m_nightRange; } var cb = Entity.FindComponent <ComponentBody>(); if (cb != null) { var boxSize = cb.BoxSize; Genome[Trait.BoxSizeX] = boxSize.X; Genome[Trait.BoxSizeY] = boxSize.Y; Genome[Trait.BoxSizeZ] = boxSize.Z; Genome[Trait.Mass] = cb.Mass; Genome[Trait.Density] = cb.Density; var vec2 = cb.AirDrag; Genome[Trait.AirDragX] = vec2.X; Genome[Trait.AirDragY] = vec2.Y; vec2 = cb.WaterDrag; Genome[Trait.WaterDragX] = vec2.X; Genome[Trait.WaterDragY] = vec2.Y; Genome[Trait.WaterSwayAngle] = cb.WaterSwayAngle; Genome[Trait.WaterTurnSpeed] = cb.WaterTurnSpeed; Genome[Trait.MaxSmoothRiseHeight] = cb.MaxSmoothRiseHeight; } var ccb = Entity.FindComponent <ComponentChaseBehavior>(); if (ccb != null) { Genome[Trait.DayChaseRange] = ccb.m_dayChaseRange; Genome[Trait.NightChaseRange] = ccb.m_nightChaseRange; Genome[Trait.DayChaseTime] = ccb.m_dayChaseTime; Genome[Trait.NightChaseTime] = ccb.m_nightChaseTime; Genome[Trait.AutoChaseMask] = (int)ccb.m_autoChaseMask; Genome[Trait.ChaseNonPlayerProbability] = ccb.m_chaseNonPlayerProbability; Genome[Trait.ChaseWhenAttackedProbability] = ccb.m_chaseWhenAttackedProbability; Genome[Trait.ChaseOnTouchProbability] = ccb.m_chaseOnTouchProbability; } var cdb = Entity.FindComponent <ComponentDigInMudBehavior>(); if (cdb != null) { Genome[Trait.MaxDigInDepth] = cdb.m_maxDigInDepth; } var ceb = Entity.FindComponent <ComponentEatPickableBehavior>(); if (ceb != null) { Genome[Trait.MeatFoodFactor] = ceb.m_foodFactors[(int)FoodType.Meat]; Genome[Trait.FishFoodFactor] = ceb.m_foodFactors[(int)FoodType.Fish]; Genome[Trait.FruitFoodFactor] = ceb.m_foodFactors[(int)FoodType.Fruit]; Genome[Trait.GrassFoodFactor] = ceb.m_foodFactors[(int)FoodType.Grass]; Genome[Trait.BreadFoodFactor] = ceb.m_foodFactors[(int)FoodType.Bread]; } var cfb = Entity.FindComponent <ComponentFindPlayerBehavior>(); if (cfb != null) { Genome[Trait.FindPlayer_DayRange] = cfb.m_dayRange; Genome[Trait.FindPlayer_NightRange] = cfb.m_nightRange; } var cge = Entity.FindComponent <ComponentGlowingEyes>(); if (cge != null) { Genome[Trait.GlowingEyesColor] = cge.GlowingEyesColor.PackedValue & 16777215u; } var ch = Entity.FindComponent <ComponentHealth>(); if (ch != null) { Genome[Trait.AttackResilience] = ch.AttackResilience; Genome[Trait.FallResilience] = ch.FallResilience; Genome[Trait.FireResilience] = ch.FireResilience; Genome[Trait.CanStrand] = ch.CanStrand ? 1 : -1; Genome[Trait.AirCapacity] = ch.AirCapacity; } var chb = Entity.FindComponent <ComponentHerdBehavior>(); if (chb != null) { float v = chb.m_herdingRange; if (chb.m_autoNearbyCreaturesHelp) { v = -v; } Genome[Trait.HerdingRange] = v; } var cl = Entity.FindComponent <ComponentLocomotion>(); if (cl != null) { Genome[Trait.AccelerationFactor] = cl.AccelerationFactor; Genome[Trait.WalkSpeed] = cl.WalkSpeed; Genome[Trait.WalkSpeedWhenTurning] = cl.m_walkSpeedWhenTurning; Genome[Trait.LadderSpeed] = cl.LadderSpeed; Genome[Trait.JumpSpeed] = cl.JumpSpeed; Genome[Trait.CreativeFlySpeed] = cl.CreativeFlySpeed; Genome[Trait.FlySpeed] = cl.FlySpeed; Genome[Trait.SwimSpeed] = cl.SwimSpeed; Genome[Trait.TurnSpeed] = cl.TurnSpeed; Genome[Trait.LookSpeed] = cl.LookSpeed; Genome[Trait.InAirWalkFactor] = cl.InAirWalkFactor; int v = cl.m_lookAutoLevelX ? 1 : 0; if (cl.m_lookAutoLevelY) { v |= 2; } Genome[Trait.LookAutoLevel] = v; } var cloot = Entity.FindComponent <ComponentLoot>(); if (cloot != null) { ComponentLoot.Loot item; if (cloot.m_lootList.Count > 0) { item = cloot.m_lootList[0]; Genome[Trait.LootMinCount] = item.MinCount; Genome[Trait.LootMaxCount] = item.MaxCount; Genome[Trait.LootProbability] = item.Probability; } if (cloot.m_lootOnFireList.Count > 0) { item = cloot.m_lootOnFireList[0]; Genome[Trait.LootOnFireMinCount] = item.MinCount; Genome[Trait.LootOnFireMaxCount] = item.MaxCount; Genome[Trait.LootOnFireProbability] = item.Probability; } } var cmr = Entity.FindComponent <ComponentMiner>(); if (cmr != null) { Genome[Trait.AttackPower] = cmr.AttackPower; } var cm = Entity.FindComponent <ComponentModel>(); if (cm != null) { Genome[Trait.DiffuseColor] = new Color(cm.DiffuseColor ?? Vector3.One).PackedValue & 16777215u; Genome[Trait.Opacity] = cm.Opacity ?? 1; } var cleb = Entity.FindComponent <ComponentLayEggBehavior>(); if (cleb != null) { Genome[Trait.LayFrequency] = cleb.m_layFrequency; } var cs = Entity.FindComponent <ComponentShapeshifter>(); if (cs != null) { Genome[Trait.ShapeshifterProbability] = cs.ValuesDictionary.GetValue <float>("Probability"); } var cssb = Entity.FindComponent <ComponentStubbornSteedBehavior>(); if (cssb != null) { Genome[Trait.StubbornProbability] = cssb.m_stubbornProbability; } var cu = Entity.FindComponent <ComponentUdder>(); if (cu != null) { Genome[Trait.MilkRegenerationTime] = cu.m_milkRegenerationTime; } }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { this.LoadItems(valuesDictionary); m_componentBlockEntity = Entity.FindComponent <ComponentBlockEntity>(true); }
public void SpawnPlayer(Vector3 position, SpawnMode spawnMode) { ComponentMount componentMount = null; if (spawnMode != SpawnMode.Respawn && CheckIsPointInWater(Terrain.ToCell(position))) { Entity entity = DatabaseManager.CreateEntity(m_project, "Boat", throwIfNotFound: true); entity.FindComponent <ComponentBody>(throwOnError: true).Position = position; entity.FindComponent <ComponentBody>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathUtils.DegToRad(45f)); componentMount = entity.FindComponent <ComponentMount>(throwOnError: true); m_project.AddEntity(entity); position.Y += entity.FindComponent <ComponentBody>(throwOnError: true).BoxSize.Y; } string value = ""; string value2 = ""; string value3 = ""; string value4 = ""; if (spawnMode != SpawnMode.Respawn) { if (PlayerClass == PlayerClass.Female) { if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("2")) { value = ""; value2 = MakeClothingValue(37, 2); value3 = MakeClothingValue(16, 14); value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(27, 0); } else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("3")) { value = MakeClothingValue(31, 0); value2 = MakeClothingValue(13, 7) + ";" + MakeClothingValue(5, 0); value3 = MakeClothingValue(17, 15); value4 = MakeClothingValue(29, 0); } else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("4")) { value = MakeClothingValue(30, 7); value2 = MakeClothingValue(14, 6); value3 = MakeClothingValue(25, 7); value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(8, 0); } else { value = MakeClothingValue(30, 12); value2 = MakeClothingValue(37, 3) + ";" + MakeClothingValue(1, 3); value3 = MakeClothingValue(0, 12); value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(29, 0); } } else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("2")) { value = ""; value2 = MakeClothingValue(13, 0) + ";" + MakeClothingValue(5, 0); value3 = MakeClothingValue(25, 8); value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(29, 0); } else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("3")) { value = MakeClothingValue(32, 0); value2 = MakeClothingValue(37, 5); value3 = MakeClothingValue(0, 15); value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(8, 0); } else if (CharacterSkinsManager.IsBuiltIn(CharacterSkinName) && CharacterSkinName.Contains("4")) { value = MakeClothingValue(31, 0); value2 = MakeClothingValue(15, 14); value3 = MakeClothingValue(0, 0); value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(8, 0); } else { value = MakeClothingValue(32, 0); value2 = MakeClothingValue(37, 0) + ";" + MakeClothingValue(1, 9); value3 = MakeClothingValue(0, 12); value4 = MakeClothingValue(26, 6) + ";" + MakeClothingValue(29, 0); } } ValuesDictionary overrides = new ValuesDictionary { { "Player", new ValuesDictionary { { "PlayerIndex", PlayerIndex } } }, { "Intro", new ValuesDictionary { { "PlayIntro", spawnMode == SpawnMode.InitialIntro } } }, { "Clothing", new ValuesDictionary { { "Clothes", new ValuesDictionary { { "Feet", value4 }, { "Legs", value3 }, { "Torso", value2 }, { "Head", value } } } } } }; Vector2 v = ComponentIntro.FindOceanDirection(m_subsystemTerrain.TerrainContentsGenerator, position.XZ); string entityTemplateName = (PlayerClass == PlayerClass.Male) ? "MalePlayer" : "FemalePlayer"; Entity entity2 = DatabaseManager.CreateEntity(m_project, entityTemplateName, overrides, throwIfNotFound: true); entity2.FindComponent <ComponentBody>(throwOnError: true).Position = position; entity2.FindComponent <ComponentBody>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, Vector2.Angle(v, -Vector2.UnitY)); m_project.AddEntity(entity2); if (componentMount != null) { entity2.FindComponent <ComponentRider>(throwOnError: true).StartMounting(componentMount); } LastSpawnTime = m_subsystemGameInfo.TotalElapsedGameTime; int num = ++SpawnsCount; }