void EnsureCurrentMasterExists() { if (_currentMasterMessageItem == null) { Main.Add(_currentMasterMessageItem = new TreeMasterMessageItem(treeView1, "", "Start", 0, 4)); } }
public void AddMain(int cardId) { Card card = Card.Get(cardId); if (card == null) { return; } if ((card.Data.Type & (int)CardType.Token) != 0) { return; } if ((card.Data.Type & 0x802040) != 0) { if (Extra.Count < YGOCore.Program.Config.ExtraCount) { Extra.Add(cardId); } } else { if (Main.Count < YGOCore.Program.Config.MainCountMax) { Main.Add(cardId); } } }
public void TransactionTest() { using (var trans = this.Database.BeginTransaction(IsolationLevel.ReadUncommitted)) { var testSession = Guid.NewGuid(); try { var main = new Main() { Session = testSession, Clsid = Guid.NewGuid(), Main1 = new byte[] { } }; Main.Add(main); SaveChanges(); var fromDb = LoadMain(testSession); Assert.That(fromDb, Is.Not.Null); Assert.That(fromDb.Session, Is.EqualTo(testSession)); } finally { trans.Rollback(); var fromDb = LoadMain(testSession); Assert.That(fromDb, Is.Null); } } }
public void AddTest() { Demo.API.Main main = new Main(); var result = main.Add(50, 50); Assert.AreEqual(100, result); }
public void AddMain(int cardId) { Card card = Card.Get(cardId); if (card == null) { return; } if ((card.Type & (int)CardType.Token) != 0) { return; } if ((card.Type & 0x802040) != 0) { if (Extra.Count < 15) { Extra.Add(cardId); } } else { if (Main.Count < 60) { Main.Add(cardId); } } }
public void Add(Zone zone) { All.Add(zone); if (ReferenceEquals(zone.Main, zone)) { Main.Add(zone); } }
public async Task TestAdd() { string guid = Guid.NewGuid().ToString(); var add = await Main.Add(guid); var get = await Main.Get(add); Assert.AreEqual(guid, get); }
private void button4_Click(object sender, EventArgs e) { if (_usr != null) //edit { Main.SetPwd(textBox1.Text, textBox3.Text); } else //add { Main.Add(textBox1.Text, textBox3.Text); } this.Close(); }
void AddLine(string line) { string[] items = line.Split(';'); if (items.Length == 0) { return; } int range = items.Count(item => String.IsNullOrEmpty(item)); bool isComment = range == 0 && !char.IsDigit(items[0][0]); bool isSubMasterNode = range == 0 && !isComment; if (isSubMasterNode) // Start of a message { string timeStamp = items[0]; string message = items.Length > 1 ? items[1] : "???"; string masterName = null; int imageId = -1; bool endFlag; int masterRange = GetMasterRange(message, out imageId, out masterName, out endFlag); ListMessages.Add(currentMessageItem = new TreeMessageItem(timeStamp, message, GetImage(items.Length > 2 ? items[3] : "???", isComment), isComment)); MessageCount++; if (masterRange >= 0) // It's a group start or end { if (endFlag) { currentMasterMessageItem.Add(currentMessageItem); } Main.Add(currentMasterMessageItem = new TreeMasterMessageItem(treeView1, timeStamp, masterName, masterRange, imageId)); } if (!endFlag) { currentMasterMessageItem.Add(currentMessageItem); } } else if (isComment) // Just a comment { currentMessageItem = new TreeMessageItem(null, line, GetImage(line, isComment), isComment); ListMessages.Add(currentMessageItem); if (currentMasterMessageItem == null) { Main.Add(currentMasterMessageItem = new TreeMasterMessageItem(treeView1, "", "Start", 0, GetImage(line, isComment))); } currentMasterMessageItem.Add(currentMessageItem); } else // A line within a message if (currentMessageItem != null) { currentMessageItem.Add(new TreeItemLine(range, items[range], (items.Length == range + 2) ? items[range + 1] : null)); } }
public async Task TestReuseRefId() { string guid1 = Guid.NewGuid().ToString(); var add1 = await Main.Add(guid1); await Main.Delete(add1); string guid2 = Guid.NewGuid().ToString(); var add2 = await Main.Add(guid2); Assert.AreEqual(add1, add2); }
public static void Transition(Main main, string nextMap, string spawn = null) { Stream stream = new MemoryStream(); Animation anim = new Animation ( new Animation.Set <bool>(main.Menu.CanPause, false), main.Spawner.FlashAnimation(), new Animation.Execute(delegate() { // We are exiting the map; just save the state of the map without the player. ListProperty <RespawnLocation> respawnLocations = PlayerDataFactory.Instance.Get <PlayerData>().RespawnLocations; respawnLocations.Clear(); List <Entity> persistentEntities = main.Entities.Where((Func <Entity, bool>)MapLoader.entityIsPersistent).ToList(); IO.MapLoader.Serializer.Serialize(stream, persistentEntities); foreach (Entity e in persistentEntities) { e.Delete.Execute(); } main.Spawner.StartSpawnPoint.Value = spawn; if (PlayerFactory.Instance != null) { PlayerFactory.Instance.Delete.Execute(); } main.SaveCurrentMap(); MapLoader.Load(main, nextMap); stream.Seek(0, SeekOrigin.Begin); List <Entity> entities = (List <Entity>)IO.MapLoader.Serializer.Deserialize(stream); foreach (Entity e in entities) { Factory <Main> factory = Factory <Main> .Get(e.Type); e.GUID = 0; factory.Bind(e, main); main.Add(e); } stream.Dispose(); }), new Animation.Delay(0.01f), new Animation.Set <bool>(main.Menu.CanPause, true), new Animation.Execute(main.ScheduleSave) ); anim.EnabledWhenPaused = false; main.AddComponent(anim); }
private static void load(Main main, Stream stream, bool deleteEditor, Entity playerData) { main.Camera.Position.Value = new Vector3(0, -1000, 0); main.IsLoadingMap = true; main.ClearEntities(deleteEditor); if (stream == null) { main.DefaultLighting(); // There's no World entity to set the correct lighting, so set the defaults } else { List <Entity> entities = null; try { entities = (List <Entity>)MapLoader.Serializer.Deserialize(stream); } catch (InvalidOperationException e) { throw new Exception("Failed to deserialize file stream.", e); } if (playerData != null) { entities.Add(playerData); } foreach (Entity entity in entities) { Factory <Main> factory = Factory <Main> .Get(entity.Type); if (factory != null) { factory.Bind(entity, main); main.Add(entity); } } } main.IsLoadingMap = false; main.MapLoaded.Execute(); }
public static void LoadWithEntities(Main main, string nextMap, List <Entity> persistentEntities) { Stream stream = new MemoryStream(); IO.MapLoader.Serializer.Serialize(stream, persistentEntities); MapLoader.Load(main, nextMap); stream.Seek(0, SeekOrigin.Begin); List <Entity> entities = (List <Entity>)IO.MapLoader.Serializer.Deserialize(stream); foreach (Entity e in entities) { Factory <Main> factory = Factory <Main> .Get(e.Type); e.GUID = 0; factory.Bind(e, main); main.Add(e); } stream.Dispose(); }
public static void Reload(Main main, bool deleteEditor = true) { main.LoadingMap.Execute(main.MapFile); using (Stream stream = new MemoryStream()) { XmlSerializer serializer = new XmlSerializer(typeof(List<Entity>)); serializer.Serialize(stream, main.Entities.Where(x => x.Serialize).ToList()); main.ClearEntities(deleteEditor); stream.Seek(0, SeekOrigin.Begin); List<Entity> entities = (List<Entity>)serializer.Deserialize(stream); foreach (Entity entity in entities) { Factory factory = Factory.Get(entity.Type); factory.Bind(entity, main); main.Add(entity); } } main.MapLoaded.Execute(); }
public static void Consolidate(Main main, DynamicVoxel voxel, Voxel targetVoxel, Voxel.Coord targetCoord, float interval = 1.0f) { if (targetVoxel != null) { // Combine this map with the other one Direction x = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Right)); Direction y = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Up)); Direction z = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Backward)); if (x.IsParallel(y)) x = y.Cross(z); else if (y.IsParallel(z)) y = x.Cross(z); Voxel.Coord offset = new Voxel.Coord(); float closestCoordDistance = float.MaxValue; Vector3 closestCoordPosition = targetVoxel.GetAbsolutePosition(targetCoord); lock (voxel.MutationLock) { foreach (Voxel.Coord c in voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords())) { float distance = (voxel.GetAbsolutePosition(c) - closestCoordPosition).LengthSquared(); if (distance < closestCoordDistance) { closestCoordDistance = distance; offset = c; } } } Vector3 toLevitatingMap = voxel.Transform.Value.Translation - targetVoxel.GetAbsolutePosition(targetCoord); offset = offset.Move(voxel.GetRelativeDirection(-toLevitatingMap)); Quaternion orientation = Quaternion.CreateFromRotationMatrix(voxel.Transform.Value); EffectBlockFactory blockFactory = Factory.Get<EffectBlockFactory>(); int index = 0; List<Voxel.Coord> coords; lock (voxel.MutationLock) coords = voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()).ToList(); Voxel.Coord camera = voxel.GetCoordinate(main.Camera.Position); foreach (Voxel.Coord c in coords.OrderBy(c2 => new Vector3(c2.X - camera.X, c2.Y - camera.Y, c2.Z - camera.Z).LengthSquared())) { Voxel.Coord offsetFromCenter = c.Move(-offset.X, -offset.Y, -offset.Z); Voxel.Coord targetCoord2 = new Voxel.Coord(); targetCoord2.SetComponent(x, offsetFromCenter.GetComponent(Direction.PositiveX)); targetCoord2.SetComponent(y, offsetFromCenter.GetComponent(Direction.PositiveY)); targetCoord2.SetComponent(z, offsetFromCenter.GetComponent(Direction.PositiveZ)); targetCoord2 = targetCoord2.Move(targetCoord.X, targetCoord.Y, targetCoord.Z); if (targetVoxel[targetCoord2].ID == 0) { Entity blockEntity = blockFactory.CreateAndBind(main); c.Data.ApplyToEffectBlock(blockEntity.Get<ModelInstance>()); EffectBlock effectBlock = blockEntity.Get<EffectBlock>(); effectBlock.Offset.Value = targetVoxel.GetRelativePosition(targetCoord2); effectBlock.DoScale = false; effectBlock.StartPosition = voxel.GetAbsolutePosition(c); effectBlock.StartOrientation = orientation; effectBlock.TotalLifetime = (0.05f + (index * 0.0075f)) * interval; effectBlock.Setup(targetVoxel.Entity, targetCoord2, c.Data.ID); main.Add(blockEntity); index++; } } // Delete the map voxel.Entity.Delete.Execute(); } }
public override void Bind(Entity result, Main main, bool creating = false) { PointLight light = result.GetOrCreate<PointLight>("PointLight"); light.Serialize = false; const float defaultLightAttenuation = 15.0f; light.Attenuation.Value = defaultLightAttenuation; Transform transform = result.GetOrCreate<Transform>("Transform"); light.Add(new Binding<Vector3>(light.Position, transform.Position)); VoxelChaseAI chase = result.GetOrCreate<VoxelChaseAI>("VoxelChaseAI"); chase.Filter = delegate(Map.CellState state) { return state.ID == 0 ? VoxelChaseAI.Cell.Empty : VoxelChaseAI.Cell.Filled; }; chase.Add(new TwoWayBinding<Vector3>(transform.Position, chase.Position)); result.Add(new CommandBinding(chase.Delete, result.Delete)); Sound sound = result.GetOrCreate<Sound>("LoopSound"); sound.Serialize = false; sound.Cue.Value = "Orb Loop"; sound.Is3D.Value = true; sound.IsPlaying.Value = true; sound.Add(new Binding<Vector3>(sound.Position, chase.Position)); Property<float> volume = sound.GetProperty("Volume"); Property<float> pitch = sound.GetProperty("Pitch"); const float defaultVolume = 0.5f; volume.Value = defaultVolume; AI ai = result.GetOrCreate<AI>(); Model model = result.GetOrCreate<Model>(); model.Add(new Binding<Matrix>(model.Transform, transform.Matrix)); model.Filename.Value = "Models\\sphere"; model.Editable = false; model.Serialize = false; const float defaultModelScale = 0.25f; model.Scale.Value = new Vector3(defaultModelScale); model.Add(new Binding<Vector3, string>(model.Color, delegate(string state) { switch (state) { case "Alert": return new Vector3(1.5f, 1.5f, 0.5f); case "Chase": return new Vector3(1.5f, 0.5f, 0.5f); case "Explode": return new Vector3(2.0f, 1.0f, 0.5f); case "Idle": return new Vector3(1.0f, 1.0f, 1.0f); default: return new Vector3(0.0f, 0.0f, 0.0f); } }, ai.CurrentState)); Random random = new Random(); result.Add(new Updater { delegate(float dt) { float source = ((float)random.NextDouble() - 0.5f) * 2.0f; model.Scale.Value = new Vector3(defaultModelScale * (1.0f + (source * 0.5f))); light.Attenuation.Value = defaultLightAttenuation * (1.0f + (source * 0.05f)); } }); model.Add(new Binding<bool, string>(model.Enabled, x => x != "Exploding", ai.CurrentState)); light.Add(new Binding<Vector3>(light.Color, model.Color)); Agent agent = result.GetOrCreate<Agent>(); agent.Add(new Binding<Vector3>(agent.Position, chase.Position)); Property<int> operationalRadius = result.GetOrMakeProperty<int>("OperationalRadius", true, 100); AI.Task checkOperationalRadius = new AI.Task { Interval = 2.0f, Action = delegate() { bool shouldBeActive = (chase.Position.Value - main.Camera.Position).Length() < operationalRadius; if (shouldBeActive && ai.CurrentState == "Suspended") ai.CurrentState.Value = "Idle"; else if (!shouldBeActive && ai.CurrentState != "Suspended") ai.CurrentState.Value = "Suspended"; }, }; const float sightDistance = 30.0f; const float hearingDistance = 15.0f; ai.Add(new AI.State { Name = "Idle", Enter = delegate(AI.State previous) { chase.Speed.Value = 3.0f; }, Tasks = new[] { checkOperationalRadius, new AI.Task { Interval = 1.0f, Action = delegate() { Agent a = Agent.Query(chase.Position, sightDistance, hearingDistance, x => x.Entity.Type == "Player"); if (a != null) ai.CurrentState.Value = "Alert"; }, }, }, }); Property<Entity.Handle> targetAgent = result.GetOrMakeProperty<Entity.Handle>("TargetAgent"); ai.Add(new AI.State { Name = "Alert", Enter = delegate(AI.State previous) { chase.Enabled.Value = false; }, Exit = delegate(AI.State next) { chase.Enabled.Value = true; }, Tasks = new[] { checkOperationalRadius, new AI.Task { Interval = 1.0f, Action = delegate() { if (ai.TimeInCurrentState > 3.0f) ai.CurrentState.Value = "Idle"; else { Agent a = Agent.Query(chase.Position, sightDistance, hearingDistance, x => x.Entity.Type == "Player"); if (a != null) { targetAgent.Value = a.Entity; ai.CurrentState.Value = "Chase"; } } }, }, }, }); AI.Task checkTargetAgent = new AI.Task { Action = delegate() { Entity target = targetAgent.Value.Target; if (target == null || !target.Active) { targetAgent.Value = null; ai.CurrentState.Value = "Idle"; } }, }; ai.Add(new AI.State { Name = "Chase", Enter = delegate(AI.State previous) { chase.Speed.Value = 10.0f; chase.TargetActive.Value = true; }, Exit = delegate(AI.State next) { chase.TargetActive.Value = false; }, Tasks = new[] { checkOperationalRadius, checkTargetAgent, new AI.Task { Action = delegate() { Entity target = targetAgent.Value.Target; Vector3 targetPosition = target.Get<Transform>().Position; chase.Target.Value = targetPosition; if ((targetPosition - chase.Position).Length() < 10.0f) ai.CurrentState.Value = "Explode"; } } }, }); ListProperty<Map.Coordinate> coordQueue = result.GetOrMakeListProperty<Map.Coordinate>("CoordQueue"); Property<Map.Coordinate> explosionOriginalCoord = result.GetOrMakeProperty<Map.Coordinate>("ExplosionOriginalCoord"); ai.Add(new AI.State { Name = "Explode", Enter = delegate(AI.State previous) { chase.Speed.Value = 5.0f; coordQueue.Clear(); chase.EnablePathfinding.Value = false; Map map = chase.Map.Value.Target.Get<Map>(); Map.Coordinate coord = chase.Coord.Value; Direction toSupport = Direction.None; foreach (Direction dir in DirectionExtensions.Directions) { if (map[coord.Move(dir)].ID != 0) { toSupport = dir; break; } } if (toSupport == Direction.None) { // Try again with the last coord coord = chase.LastCoord.Value; foreach (Direction dir in DirectionExtensions.Directions) { if (map[coord.Move(dir)].ID != 0) { toSupport = dir; break; } } if (toSupport == Direction.None) { ai.CurrentState.Value = "Idle"; return; } } Direction up = toSupport.GetReverse(); explosionOriginalCoord.Value = coord; Direction right; if (up.IsParallel(Direction.PositiveX)) right = Direction.PositiveZ; else right = Direction.PositiveX; Direction forward = up.Cross(right); for (Map.Coordinate y = coord.Clone(); y.GetComponent(up) < coord.GetComponent(up) + 3; y = y.Move(up)) { for (Map.Coordinate x = y.Clone(); x.GetComponent(right) < coord.GetComponent(right) + 2; x = x.Move(right)) { for (Map.Coordinate z = x.Clone(); z.GetComponent(forward) < coord.GetComponent(forward) + 2; z = z.Move(forward)) coordQueue.Add(z); } } }, Exit = delegate(AI.State next) { coordQueue.Clear(); chase.EnablePathfinding.Value = true; chase.LastCoord.Value = chase.Coord.Value = explosionOriginalCoord; }, Tasks = new[] { checkOperationalRadius, new AI.Task { Action = delegate() { volume.Value = MathHelper.Lerp(defaultVolume, 1.0f, ai.TimeInCurrentState.Value / 2.0f); pitch.Value = MathHelper.Lerp(0.0f, 0.5f, ai.TimeInCurrentState.Value / 2.0f); if (coordQueue.Count == 0) { // Explode ai.CurrentState.Value = "Exploding"; } }, }, }, }); Property<bool> exploded = result.GetOrMakeProperty<bool>("Exploded"); ai.Add(new AI.State { Name = "Exploding", Enter = delegate(AI.State previous) { chase.EnablePathfinding.Value = false; exploded.Value = false; sound.Stop.Execute(AudioStopOptions.AsAuthored); }, Exit = delegate(AI.State next) { chase.EnablePathfinding.Value = true; exploded.Value = false; volume.Value = defaultVolume; pitch.Value = 0.0f; sound.Play.Execute(); }, Tasks = new[] { new AI.Task { Interval = 0.1f, Action = delegate() { const int radius = 8; float timeInCurrentState = ai.TimeInCurrentState; if (timeInCurrentState > 1.0f && !exploded) { Map map = chase.Map.Value.Target.Get<Map>(); Explosion.Explode(main, map, chase.Coord, radius, 18.0f); exploded.Value = true; } if (timeInCurrentState > 2.0f) { Map map = chase.Map.Value.Target.Get<Map>(); Map.Coordinate? closestCell = map.FindClosestFilledCell(chase.Coord, radius + 1); if (closestCell.HasValue) { chase.Blend.Value = 0.0f; chase.Coord.Value = closestCell.Value; ai.CurrentState.Value = "Alert"; } else result.Delete.Execute(); } }, }, }, }); EffectBlockFactory factory = Factory.Get<EffectBlockFactory>(); Map.CellState snakeState = WorldFactory.StatesByName["Snake"]; chase.Add(new CommandBinding<Map, Map.Coordinate>(chase.Moved, delegate(Map m, Map.Coordinate c) { if (chase.Active) { if (coordQueue.Count > 0) { Map.Coordinate coord = chase.Coord.Value = coordQueue[0]; coordQueue.RemoveAt(0); Entity block = factory.CreateAndBind(main); snakeState.ApplyToEffectBlock(block.Get<ModelInstance>()); Map map = chase.Map.Value.Target.Get<Map>(); block.GetProperty<Vector3>("Offset").Value = map.GetRelativePosition(coord); Vector3 absolutePos = map.GetAbsolutePosition(coord); block.GetProperty<Vector3>("StartPosition").Value = absolutePos + new Vector3(0.05f, 0.1f, 0.05f); block.GetProperty<Matrix>("StartOrientation").Value = Matrix.CreateRotationX(0.15f) * Matrix.CreateRotationY(0.15f); block.GetProperty<float>("TotalLifetime").Value = 0.05f; factory.Setup(block, chase.Map.Value.Target, coord, snakeState.ID); main.Add(block); } } })); this.SetMain(result, main); }
public static void Consolidate(Main main, DynamicVoxel voxel, Voxel targetVoxel, Voxel.Coord targetCoord, float interval = 1.0f) { if (targetVoxel != null) { // Combine this map with the other one Direction x = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Right)); Direction y = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Up)); Direction z = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Backward)); if (x.IsParallel(y)) { x = y.Cross(z); } else if (y.IsParallel(z)) { y = x.Cross(z); } Voxel.Coord offset = new Voxel.Coord(); float closestCoordDistance = float.MaxValue; Vector3 closestCoordPosition = targetVoxel.GetAbsolutePosition(targetCoord); foreach (Voxel.Coord c in voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords())) { float distance = (voxel.GetAbsolutePosition(c) - closestCoordPosition).LengthSquared(); if (distance < closestCoordDistance) { closestCoordDistance = distance; offset = c; } } Vector3 toLevitatingMap = voxel.Transform.Value.Translation - targetVoxel.GetAbsolutePosition(targetCoord); offset = offset.Move(voxel.GetRelativeDirection(-toLevitatingMap)); Quaternion orientation = Quaternion.CreateFromRotationMatrix(voxel.Transform.Value); EffectBlockFactory blockFactory = Factory.Get <EffectBlockFactory>(); int index = 0; List <Voxel.Coord> coords = voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()).ToList(); Voxel.Coord camera = voxel.GetCoordinate(main.Camera.Position); foreach (Voxel.Coord c in coords.OrderBy(c2 => new Vector3(c2.X - camera.X, c2.Y - camera.Y, c2.Z - camera.Z).LengthSquared())) { Voxel.Coord offsetFromCenter = c.Move(-offset.X, -offset.Y, -offset.Z); Voxel.Coord targetCoord2 = new Voxel.Coord(); targetCoord2.SetComponent(x, offsetFromCenter.GetComponent(Direction.PositiveX)); targetCoord2.SetComponent(y, offsetFromCenter.GetComponent(Direction.PositiveY)); targetCoord2.SetComponent(z, offsetFromCenter.GetComponent(Direction.PositiveZ)); targetCoord2 = targetCoord2.Move(targetCoord.X, targetCoord.Y, targetCoord.Z); if (targetVoxel[targetCoord2].ID == 0) { Entity blockEntity = blockFactory.CreateAndBind(main); c.Data.ApplyToEffectBlock(blockEntity.Get <ModelInstance>()); EffectBlock effectBlock = blockEntity.Get <EffectBlock>(); effectBlock.Offset.Value = targetVoxel.GetRelativePosition(targetCoord2); effectBlock.DoScale = false; effectBlock.StartPosition = voxel.GetAbsolutePosition(c); effectBlock.StartOrientation = orientation; effectBlock.TotalLifetime = (0.05f + (index * 0.0075f)) * interval; effectBlock.Setup(targetVoxel.Entity, targetCoord2, c.Data.ID); main.Add(blockEntity); index++; } } // Delete the map voxel.Entity.Delete.Execute(); } }
private static void explode(Main main, Map map, Map.Coordinate coord, Vector3 pos, int radius, float physicsRadius) { // Kaboom AkSoundEngine.PostEvent("Play_explosion", pos); Entity lightEntity = Factory.Get<PointLightFactory>().CreateAndBind(main); lightEntity.Serialize = false; PointLight light = lightEntity.Get<PointLight>(); light.Color.Value = new Vector3(1.3f, 1.1f, 0.9f); light.Attenuation.Value = 20.0f; light.Position.Value = pos; lightEntity.Add(new Animation ( new Animation.FloatMoveTo(light.Attenuation, 0.0f, 1.0f), new Animation.Execute(light.Delete) )); main.Add(lightEntity); SmokeFactory smokeFactory = Factory.Get<SmokeFactory>(); for (int i = 0; i < 5; i++) { Entity smoke = smokeFactory.CreateAndBind(main); smoke.Get<Transform>().Position.Value = pos; main.Add(smoke); } ParticleEmitter.Emit(main, "Smoke", pos, physicsRadius * 0.4f, 250); Entity player = PlayerFactory.Instance; if (player != null && player.Active) player.Get<CameraController>().Shake.Execute(pos, 50.0f); const float physicsImpulse = 70.0f; const float minPlayerDamage = 0.1f; const float playerDamageMultiplier = 2.0f; // Remove the cells BlockFactory blockFactory = Factory.Get<BlockFactory>(); foreach (Map m in Map.ActiveMaps.ToList()) { List<Map.Coordinate> removals = new List<Map.Coordinate>(); Map.Coordinate c = m.GetCoordinate(pos); Vector3 relativePos = m.GetRelativePosition(c); Quaternion quat = m.Entity.Get<Transform>().Quaternion; for (Map.Coordinate x = c.Move(Direction.NegativeX, radius - 1); x.X < c.X + radius; x.X++) { for (Map.Coordinate y = x.Move(Direction.NegativeY, radius - 1); y.Y < c.Y + radius; y.Y++) { for (Map.Coordinate z = y.Move(Direction.NegativeZ, radius - 1); z.Z < c.Z + radius; z.Z++) { Map.CellState s = m[z]; if (s.ID == 0 || s.Permanent) continue; Vector3 cellPos = m.GetRelativePosition(z); if ((cellPos - relativePos).Length() < radius - 1) { removals.Add(z); if (random.NextDouble() > 0.5) { Entity block = blockFactory.CreateAndBind(main); Transform blockTransform = block.Get<Transform>(); blockTransform.Position.Value = m.GetAbsolutePosition(cellPos); blockTransform.Quaternion.Value = quat; s.ApplyToBlock(block); main.Add(block); } } } } } if (removals.Count > 0) { m.Empty(removals); m.Regenerate(); } } // Damage the player if (player != null && player.Active) { float d = (player.Get<Transform>().Position - pos).Length(); if (d < physicsRadius) player.Get<Player>().Health.Value -= minPlayerDamage + (1.0f - (d / physicsRadius)) * playerDamageMultiplier; } // Apply impulse to dynamic maps foreach (Map m in Map.ActiveMaps) { DynamicMap dm = m as DynamicMap; if (dm == null) continue; Vector3 toMap = dm.Transform.Value.Translation - pos; float distanceToMap = toMap.Length(); toMap /= distanceToMap; toMap *= Math.Max(0.0f, 1.0f - (distanceToMap / physicsRadius)) * Math.Min(200.0f, dm.PhysicsEntity.Mass) * physicsImpulse; dm.PhysicsEntity.ApplyImpulse(dm.Transform.Value.Translation + new Vector3(((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f), toMap); } // Apply impulse to physics blocks foreach (Entity b in main.Get("Block")) { PhysicsBlock block = b.Get<PhysicsBlock>(); Vector3 fromExplosion = b.Get<Transform>().Position.Value - pos; float distance = fromExplosion.Length(); if (distance > 0.0f && distance < physicsRadius) { float blend = 1.0f - (distance / physicsRadius); block.LinearVelocity.Value += fromExplosion * blend * 10.0f / distance; block.AngularVelocity.Value += new Vector3(((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f) * blend; } } }
public override void Bind(Entity result, Main main, bool creating = false) { this.InternalBind(result, main, creating, null, true); if (result.GetOrMakeProperty<bool>("Attached", true)) MapAttachable.MakeAttachable(result, main); Property<Entity.Handle> target = result.GetOrMakeProperty<Entity.Handle>("Target"); Map map = result.Get<Map>(); Property<float> intervalMultiplier = result.GetOrMakeProperty<float>("IntervalMultiplier", true, 1.0f); ListProperty<CoordinateEntry> coords = result.GetOrMakeListProperty<CoordinateEntry>("Coordinates"); Property<int> index = result.GetOrMakeProperty<int>("FillIndex"); Action populateCoords = delegate() { if (coords.Count == 0) { Entity targetEntity = target.Value.Target; if (targetEntity != null && targetEntity.Active) { Map m = targetEntity.Get<Map>(); foreach (CoordinateEntry e in map.Chunks.SelectMany(c => c.Boxes.SelectMany(x => x.GetCoords())).Select(delegate(Map.Coordinate y) { Map.Coordinate z = m.GetCoordinate(map.GetAbsolutePosition(y)); z.Data = y.Data; return new CoordinateEntry { Coord = z, }; })) coords.Add(e); } } }; if (main.EditorEnabled) coords.Clear(); else result.Add(new PostInitialization { populateCoords }); Property<float> blockLifetime = result.GetOrMakeProperty<float>("BlockLifetime", true, 0.25f); float intervalTimer = 0.0f; Updater update = new Updater { delegate(float dt) { intervalTimer += dt; Entity targetEntity = target.Value.Target; if (targetEntity != null && targetEntity.Active && index < coords.Count) { float interval = 0.03f * intervalMultiplier; while (intervalTimer > interval && index < coords.Count) { EffectBlockFactory factory = Factory.Get<EffectBlockFactory>(); Map m = targetEntity.Get<Map>(); CoordinateEntry entry = coords[index]; Entity block = factory.CreateAndBind(main); entry.Coord.Data.ApplyToEffectBlock(block.Get<ModelInstance>()); block.GetProperty<bool>("CheckAdjacent").Value = false; block.GetProperty<Vector3>("Offset").Value = m.GetRelativePosition(entry.Coord); block.GetProperty<bool>("Scale").Value = true; block.GetProperty<Vector3>("StartPosition").Value = entry.Position + new Vector3(8.0f, 20.0f, 8.0f) * blockLifetime.Value; block.GetProperty<Matrix>("StartOrientation").Value = Matrix.CreateRotationX(0.15f * index) * Matrix.CreateRotationY(0.15f * index); block.GetProperty<float>("TotalLifetime").Value = blockLifetime; factory.Setup(block, targetEntity, entry.Coord, entry.Coord.Data.ID); main.Add(block); index.Value++; intervalTimer -= interval; } } else result.Delete.Execute(); } }; update.Enabled.Value = index > 0; result.Add("Update", update); Action fill = delegate() { if (index > 0 || update.Enabled) return; // We're already filling Entity targetEntity = target.Value.Target; if (targetEntity != null && targetEntity.Active) { populateCoords(); Map m = targetEntity.Get<Map>(); Vector3 focusPoint = main.Camera.Position; foreach (CoordinateEntry entry in coords) { entry.Position = m.GetAbsolutePosition(entry.Coord); entry.Distance = (focusPoint - entry.Position).LengthSquared(); } List<CoordinateEntry> coordList = coords.ToList(); coords.Clear(); coordList.Sort(new LambdaComparer<CoordinateEntry>((x, y) => x.Distance.CompareTo(y.Distance))); foreach (CoordinateEntry e in coordList) coords.Add(e); update.Enabled.Value = true; } }; result.Add("Fill", new Command { Action = fill }); result.Add("Trigger", new Command<Entity> { Action = delegate(Entity p) { fill(); } }); }
public override void Bind(Entity result, Main main, bool creating = false) { PointLight light = result.GetOrCreate<PointLight>("PointLight"); light.Serialize = false; const float defaultLightAttenuation = 15.0f; light.Attenuation.Value = defaultLightAttenuation; Transform transform = result.GetOrCreate<Transform>("Transform"); light.Add(new Binding<Vector3>(light.Position, transform.Position)); VoxelChaseAI chase = result.GetOrCreate<VoxelChaseAI>("VoxelChaseAI"); chase.Filter = delegate(Map.CellState state) { return state.ID == 0 ? VoxelChaseAI.Cell.Empty : VoxelChaseAI.Cell.Filled; }; chase.Add(new TwoWayBinding<Vector3>(transform.Position, chase.Position)); result.Add(new CommandBinding(chase.Delete, result.Delete)); Sound sound = result.GetOrCreate<Sound>("LoopSound"); sound.Serialize = false; sound.Cue.Value = "Orb Loop"; sound.Is3D.Value = true; sound.IsPlaying.Value = true; sound.Add(new Binding<Vector3>(sound.Position, chase.Position)); Property<float> volume = sound.GetProperty("Volume"); Property<float> pitch = sound.GetProperty("Pitch"); const float defaultVolume = 0.5f; volume.Value = defaultVolume; AI ai = result.GetOrCreate<AI>(); Model model = result.GetOrCreate<Model>(); model.Add(new Binding<Matrix>(model.Transform, transform.Matrix)); model.Filename.Value = "Models\\sphere"; model.Editable = false; model.Serialize = false; const float defaultModelScale = 0.25f; model.Scale.Value = new Vector3(defaultModelScale); model.Add(new Binding<Vector3, string>(model.Color, delegate(string state) { switch (state) { case "Alert": return new Vector3(1.5f, 1.5f, 0.5f); case "Chase": return new Vector3(1.5f, 0.5f, 0.5f); case "Levitating": return new Vector3(2.0f, 1.0f, 0.5f); case "Idle": return new Vector3(1.0f, 1.0f, 1.0f); default: return new Vector3(0.0f, 0.0f, 0.0f); } }, ai.CurrentState)); Random random = new Random(); result.Add(new Updater { delegate(float dt) { float source = ((float)random.NextDouble() - 0.5f) * 2.0f; model.Scale.Value = new Vector3(defaultModelScale * (1.0f + (source * 0.5f))); light.Attenuation.Value = defaultLightAttenuation * (1.0f + (source * 0.05f)); } }); model.Add(new Binding<bool, string>(model.Enabled, x => x != "Exploding", ai.CurrentState)); light.Add(new Binding<Vector3>(light.Color, model.Color)); Agent agent = result.GetOrCreate<Agent>(); agent.Add(new Binding<Vector3>(agent.Position, chase.Position)); Property<int> operationalRadius = result.GetOrMakeProperty<int>("OperationalRadius", true, 100); AI.Task checkOperationalRadius = new AI.Task { Interval = 2.0f, Action = delegate() { bool shouldBeActive = (chase.Position.Value - main.Camera.Position).Length() < operationalRadius; if (shouldBeActive && ai.CurrentState == "Suspended") ai.CurrentState.Value = "Idle"; else if (!shouldBeActive && ai.CurrentState != "Suspended") ai.CurrentState.Value = "Suspended"; }, }; const float sightDistance = 30.0f; const float hearingDistance = 15.0f; ai.Add(new AI.State { Name = "Idle", Enter = delegate(AI.State previous) { chase.Speed.Value = 3.0f; }, Tasks = new[] { checkOperationalRadius, new AI.Task { Interval = 1.0f, Action = delegate() { Agent a = Agent.Query(chase.Position, sightDistance, hearingDistance, x => x.Entity.Type == "Player"); if (a != null) ai.CurrentState.Value = "Alert"; }, }, }, }); Property<Entity.Handle> targetAgent = result.GetOrMakeProperty<Entity.Handle>("TargetAgent"); ai.Add(new AI.State { Name = "Alert", Enter = delegate(AI.State previous) { chase.Enabled.Value = false; }, Exit = delegate(AI.State next) { chase.Enabled.Value = true; }, Tasks = new[] { checkOperationalRadius, new AI.Task { Interval = 1.0f, Action = delegate() { if (ai.TimeInCurrentState > 3.0f) ai.CurrentState.Value = "Idle"; else { Agent a = Agent.Query(chase.Position, sightDistance, hearingDistance, x => x.Entity.Type == "Player"); if (a != null) { targetAgent.Value = a.Entity; ai.CurrentState.Value = "Chase"; } } }, }, }, }); AI.Task checkTargetAgent = new AI.Task { Action = delegate() { Entity target = targetAgent.Value.Target; if (target == null || !target.Active) { targetAgent.Value = null; ai.CurrentState.Value = "Idle"; } }, }; // Levitate Property<Entity.Handle> levitatingMap = result.GetOrMakeProperty<Entity.Handle>("LevitatingMap"); Property<Map.Coordinate> grabCoord = result.GetOrMakeProperty<Map.Coordinate>("GrabCoord"); const int levitateRipRadius = 4; Func<bool> tryLevitate = delegate() { Map map = chase.Map.Value.Target.Get<Map>(); Map.Coordinate? candidate = map.FindClosestFilledCell(chase.Coord, 3); if (!candidate.HasValue) return false; Map.Coordinate center = candidate.Value; if (!map[center].Permanent) { // Break off a chunk of this map into a new DynamicMap. List<Map.Coordinate> edges = new List<Map.Coordinate>(); Map.Coordinate ripStart = center.Move(-levitateRipRadius, -levitateRipRadius, -levitateRipRadius); Map.Coordinate ripEnd = center.Move(levitateRipRadius, levitateRipRadius, levitateRipRadius); Dictionary<Map.Box, bool> permanentBoxes = new Dictionary<Map.Box, bool>(); foreach (Map.Coordinate c in ripStart.CoordinatesBetween(ripEnd)) { Map.Box box = map.GetBox(c); if (box != null && box.Type.Permanent) permanentBoxes[box] = true; } foreach (Map.Box b in permanentBoxes.Keys) { // Top and bottom for (int x = b.X - 1; x <= b.X + b.Width; x++) { for (int z = b.Z - 1; z <= b.Z + b.Depth; z++) { Map.Coordinate coord = new Map.Coordinate { X = x, Y = b.Y + b.Height, Z = z }; if (coord.Between(ripStart, ripEnd)) edges.Add(coord); coord = new Map.Coordinate { X = x, Y = b.Y - 1, Z = z }; if (coord.Between(ripStart, ripEnd)) edges.Add(coord); } } // Outer shell for (int y = b.Y; y < b.Y + b.Height; y++) { // Left and right for (int z = b.Z - 1; z <= b.Z + b.Depth; z++) { Map.Coordinate coord = new Map.Coordinate { X = b.X - 1, Y = y, Z = z }; if (coord.Between(ripStart, ripEnd)) edges.Add(coord); coord = new Map.Coordinate { X = b.X + b.Width, Y = y, Z = z }; if (coord.Between(ripStart, ripEnd)) edges.Add(coord); } // Backward and forward for (int x = b.X; x < b.X + b.Width; x++) { Map.Coordinate coord = new Map.Coordinate { X = x, Y = y, Z = b.Z - 1 }; if (coord.Between(ripStart, ripEnd)) edges.Add(coord); coord = new Map.Coordinate { X = x, Y = y, Z = b.Z + b.Depth }; if (coord.Between(ripStart, ripEnd)) edges.Add(coord); } } } if (edges.Contains(center)) return false; // Top and bottom for (int x = ripStart.X; x <= ripEnd.X; x++) { for (int z = ripStart.Z; z <= ripEnd.Z; z++) { edges.Add(new Map.Coordinate { X = x, Y = ripStart.Y, Z = z }); edges.Add(new Map.Coordinate { X = x, Y = ripEnd.Y, Z = z }); } } // Sides for (int y = ripStart.Y + 1; y <= ripEnd.Y - 1; y++) { // Left and right for (int z = ripStart.Z; z <= ripEnd.Z; z++) { edges.Add(new Map.Coordinate { X = ripStart.X, Y = y, Z = z }); edges.Add(new Map.Coordinate { X = ripEnd.X, Y = y, Z = z }); } // Backward and forward for (int x = ripStart.X; x <= ripEnd.X; x++) { edges.Add(new Map.Coordinate { X = x, Y = y, Z = ripStart.Z }); edges.Add(new Map.Coordinate { X = x, Y = y, Z = ripEnd.Z }); } } map.Empty(edges); map.Regenerate(delegate(List<DynamicMap> spawnedMaps) { foreach (DynamicMap spawnedMap in spawnedMaps) { if (spawnedMap[center].ID != 0) { levitatingMap.Value = spawnedMap.Entity; break; } } }); grabCoord.Value = center; return true; } return false; }; Action delevitateMap = delegate() { Entity levitatingMapEntity = levitatingMap.Value.Target; if (levitatingMapEntity == null || !levitatingMapEntity.Active) return; DynamicMap dynamicMap = levitatingMapEntity.Get<DynamicMap>(); int maxDistance = levitateRipRadius + 7; Map closestMap = null; Map.Coordinate closestCoord = new Map.Coordinate(); foreach (Map m in Map.ActivePhysicsMaps) { if (m == dynamicMap) continue; Map.Coordinate relativeCoord = m.GetCoordinate(dynamicMap.Transform.Value.Translation); Map.Coordinate? closestFilled = m.FindClosestFilledCell(relativeCoord, maxDistance); if (closestFilled != null) { maxDistance = Math.Min(Math.Abs(relativeCoord.X - closestFilled.Value.X), Math.Min(Math.Abs(relativeCoord.Y - closestFilled.Value.Y), Math.Abs(relativeCoord.Z - closestFilled.Value.Z))); closestMap = m; closestCoord = closestFilled.Value; } } if (closestMap != null) { // Combine this map with the other one Direction x = closestMap.GetRelativeDirection(dynamicMap.GetAbsoluteVector(Vector3.Right)); Direction y = closestMap.GetRelativeDirection(dynamicMap.GetAbsoluteVector(Vector3.Up)); Direction z = closestMap.GetRelativeDirection(dynamicMap.GetAbsoluteVector(Vector3.Backward)); if (x.IsParallel(y)) x = y.Cross(z); else if (y.IsParallel(z)) y = x.Cross(z); Map.Coordinate offset = new Map.Coordinate(); float closestCoordDistance = float.MaxValue; Vector3 closestCoordPosition = closestMap.GetAbsolutePosition(closestCoord); foreach (Map.Coordinate c in dynamicMap.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords())) { float distance = (dynamicMap.GetAbsolutePosition(c) - closestCoordPosition).LengthSquared(); if (distance < closestCoordDistance) { closestCoordDistance = distance; offset = c; } } Vector3 toLevitatingMap = dynamicMap.Transform.Value.Translation - closestMap.GetAbsolutePosition(closestCoord); offset = offset.Move(dynamicMap.GetRelativeDirection(-toLevitatingMap)); Matrix orientation = dynamicMap.Transform.Value; orientation.Translation = Vector3.Zero; EffectBlockFactory blockFactory = Factory.Get<EffectBlockFactory>(); int index = 0; foreach (Map.Coordinate c in dynamicMap.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()).OrderBy(c2 => new Vector3(c2.X - offset.X, c2.Y - offset.Y, c2.Z - offset.Z).LengthSquared())) { Map.Coordinate offsetFromCenter = c.Move(-offset.X, -offset.Y, -offset.Z); Map.Coordinate targetCoord = new Map.Coordinate(); targetCoord.SetComponent(x, offsetFromCenter.GetComponent(Direction.PositiveX)); targetCoord.SetComponent(y, offsetFromCenter.GetComponent(Direction.PositiveY)); targetCoord.SetComponent(z, offsetFromCenter.GetComponent(Direction.PositiveZ)); targetCoord = targetCoord.Move(closestCoord.X, closestCoord.Y, closestCoord.Z); if (closestMap[targetCoord].ID == 0) { Entity block = blockFactory.CreateAndBind(main); c.Data.ApplyToEffectBlock(block.Get<ModelInstance>()); block.GetProperty<Vector3>("Offset").Value = closestMap.GetRelativePosition(targetCoord); block.GetProperty<bool>("Scale").Value = false; block.GetProperty<Vector3>("StartPosition").Value = dynamicMap.GetAbsolutePosition(c); block.GetProperty<Matrix>("StartOrientation").Value = orientation; block.GetProperty<float>("TotalLifetime").Value = 0.05f + (index * 0.0075f); blockFactory.Setup(block, closestMap.Entity, targetCoord, c.Data.ID); main.Add(block); index++; } } // Delete the map levitatingMapEntity.Delete.Execute(); } }; // Chase AI state ai.Add(new AI.State { Name = "Chase", Enter = delegate(AI.State previous) { chase.Speed.Value = 10.0f; chase.TargetActive.Value = true; }, Exit = delegate(AI.State next) { chase.TargetActive.Value = false; }, Tasks = new[] { checkOperationalRadius, checkTargetAgent, new AI.Task { Interval = 0.1f, Action = delegate() { Entity target = targetAgent.Value.Target; Vector3 targetPosition = target.Get<Transform>().Position; chase.Target.Value = targetPosition; Entity levitatingMapEntity = levitatingMap.Value.Target; if ((targetPosition - chase.Position).Length() < 10.0f && (levitatingMapEntity == null || !levitatingMapEntity.Active)) { if (tryLevitate()) ai.CurrentState.Value = "Levitating"; } } } }, }); Property<Vector3> lastPosition = result.GetOrMakeProperty<Vector3>("LastPosition"); Property<Vector3> nextPosition = result.GetOrMakeProperty<Vector3>("NextPosition"); Property<float> positionBlend = result.GetOrMakeProperty<float>("PositionBlend"); Action findNextPosition = delegate() { lastPosition.Value = chase.Position.Value; nextPosition.Value = targetAgent.Value.Target.Get<Transform>().Position + new Vector3((float)random.NextDouble() - 0.5f, (float)random.NextDouble(), (float)random.NextDouble() - 0.5f) * 5.0f; positionBlend.Value = 0.0f; }; ai.Add(new AI.State { Name = "Levitating", Enter = delegate(AI.State previous) { chase.Enabled.Value = false; findNextPosition(); }, Exit = delegate(AI.State next) { delevitateMap(); levitatingMap.Value = null; Map map = chase.Map.Value.Target.Get<Map>(); Map.Coordinate currentCoord = map.GetCoordinate(chase.Position); Map.Coordinate? closest = map.FindClosestFilledCell(currentCoord, 10); if (closest.HasValue) { chase.LastCoord.Value = currentCoord; chase.Coord.Value = closest.Value; chase.Blend.Value = 0.0f; } chase.Enabled.Value = true; volume.Value = defaultVolume; pitch.Value = 0.0f; }, Tasks = new[] { checkTargetAgent, new AI.Task { Action = delegate() { volume.Value = 1.0f; pitch.Value = 1.0f; Entity levitatingMapEntity = levitatingMap.Value.Target; if (!levitatingMapEntity.Active || ai.TimeInCurrentState.Value > 8.0f) { ai.CurrentState.Value = "Alert"; return; } DynamicMap dynamicMap = levitatingMapEntity.Get<DynamicMap>(); positionBlend.Value += (main.ElapsedTime.Value / 1.0f); if (positionBlend > 1.0f) findNextPosition(); chase.Position.Value = Vector3.Lerp(lastPosition, nextPosition, positionBlend); Vector3 grabPoint = dynamicMap.GetAbsolutePosition(grabCoord); Vector3 diff = chase.Position.Value - grabPoint; if (diff.Length() > 15.0f) { ai.CurrentState.Value = "Chase"; return; } diff *= (float)Math.Sqrt(dynamicMap.PhysicsEntity.Mass) * 0.5f; dynamicMap.PhysicsEntity.ApplyImpulse(ref grabPoint, ref diff); }, }, }, }); this.SetMain(result, main); }
public override void Bind(Entity result, Main main, bool creating = false) { Factory.Get<DynamicMapFactory>().Bind(result, main); Transform transform = result.Get<Transform>(); DynamicMap map = result.Get<DynamicMap>(); PointLight light = result.Get<PointLight>(); Sound blastFireSound = result.Get<Sound>("BlastFireSound"); blastFireSound.Add(new Binding<Vector3>(blastFireSound.Position, transform.Position)); blastFireSound.Add(new Binding<Vector3>(blastFireSound.Velocity, map.LinearVelocity)); Sound blastChargeSound = result.Get<Sound>("BlastChargeSound"); blastChargeSound.Add(new Binding<Vector3>(blastChargeSound.Position, transform.Position)); blastChargeSound.Add(new Binding<Vector3>(blastChargeSound.Velocity, map.LinearVelocity)); map.Add(new CommandBinding(map.CompletelyEmptied, delegate() { if (!main.EditorEnabled) result.Delete.Execute(); })); EntityRotator rotator = null; EntityMover mover = null; if (!main.EditorEnabled) { rotator = new EntityRotator(map.PhysicsEntity); main.Space.Add(rotator); mover = new EntityMover(map.PhysicsEntity); mover.TargetPosition = transform.Position; main.Space.Add(mover); } Map.Coordinate blastSource = map.GetCoordinate(0, 0, 0); Map.Coordinate blastPosition = blastSource; Map.CellState criticalMaterial = WorldFactory.StatesByName["Critical"]; foreach (Map.Box box in map.Chunks.SelectMany(x => x.Boxes)) { if (box.Type == criticalMaterial) { blastSource = map.GetCoordinate(box.X, box.Y, box.Z); blastPosition = map.GetCoordinate(box.X, box.Y, box.Z - 3); break; } } Property<float> blastIntervalTime = result.GetProperty<float>("BlastInterval"); float blastInterval = 0.0f; Property<float> playerPositionMemoryTime = result.GetProperty<float>("PlayerPositionMemoryTime"); float timeSinceLastSpottedPlayer = playerPositionMemoryTime; Property<float> visibilityCheckInterval = result.GetProperty<float>("VisibilityCheckInterval"); float timeSinceLastVisibilityCheck = 0.0f; Property<float> blastChargeTime = result.GetProperty<float>("BlastChargeTime"); float blastCharge = 0.0f; Property<float> blastSpeed = result.GetProperty<float>("BlastSpeed"); Property<float> playerDetectionRadius = result.GetProperty<float>("PlayerDetectionRadius"); Updater update = new Updater(); update.Add(delegate(float dt) { if (map[blastSource].ID == 0) { update.Delete.Execute(); if (rotator != null) { main.Space.Remove(rotator); main.Space.Remove(mover); } light.Delete.Execute(); return; } Entity player = PlayerFactory.Instance; if (player != null) { Vector3 playerPosition = player.Get<Transform>().Position.Value; Vector3 rayStart = map.GetAbsolutePosition(blastPosition); Vector3 rayDirection = playerPosition - rayStart; rayDirection.Normalize(); timeSinceLastVisibilityCheck += dt; if (timeSinceLastVisibilityCheck > visibilityCheckInterval) { if ((playerPosition - transform.Position).Length() < playerDetectionRadius) timeSinceLastSpottedPlayer = 0.0f; else if (Vector3.Dot(rayDirection, map.GetAbsoluteVector(Vector3.Forward)) > 0) { RayCastResult hit; if (main.Space.RayCast(new Ray(rayStart, rayDirection), out hit)) { EntityCollidable collidable = hit.HitObject as EntityCollidable; if (collidable != null && collidable.Entity.Tag is Player) timeSinceLastSpottedPlayer = 0.0f; } } timeSinceLastVisibilityCheck = 0.0f; } timeSinceLastSpottedPlayer += dt; light.Attenuation.Value = 0.0f; if (timeSinceLastSpottedPlayer < playerPositionMemoryTime) { rotator.TargetOrientation = Quaternion.CreateFromRotationMatrix(Matrix.Invert(Matrix.CreateLookAt(rayStart, playerPosition, Vector3.Up))); if (blastInterval > blastIntervalTime) { if (blastCharge < blastChargeTime) { if (blastCharge == 0.0f) blastChargeSound.Play.Execute(); blastCharge += dt; light.Position.Value = rayStart; light.Attenuation.Value = (blastCharge / blastChargeTime) * 30.0f; } else { blastCharge = 0.0f; blastFireSound.Play.Execute(); blastInterval = 0.0f; Entity blast = Factory.CreateAndBind(main, "Blast"); PhysicsBlock physics = blast.Get<PhysicsBlock>(); Transform blastTransform = blast.Get<Transform>(); blastTransform.Position.Value = rayStart; physics.LinearVelocity.Value = (rayDirection * blastSpeed) + new Vector3(0.0f, 6.0f, 0.0f); main.Add(blast); } } else { blastInterval += dt; blastCharge = 0.0f; } } else blastCharge = 0.0f; } }); result.Add("Update", update); }
public static void Transition(Main main, string nextMap, string spawn = null, bool saveInfo = true) { Stream stream = new MemoryStream(); Container loadingNotification = new Container(); loadingNotification.Tint.Value = Microsoft.Xna.Framework.Color.Black; loadingNotification.Opacity.Value = 0.5f; TextElement loadingNotificationText = new TextElement(); loadingNotificationText.Name.Value = "Text"; loadingNotificationText.FontFile.Value = main.Font; loadingNotificationText.Text.Value = "\\loading"; loadingNotification.Children.Add(loadingNotificationText); Animation anim = new Animation ( new Animation.Set <bool>(main.Menu.CanPause, false), main.Spawner.FlashAnimation(), new Animation.Execute(delegate() { main.UI.Root.GetChildByName("Notifications").Children.Add(loadingNotification); }), new Animation.Delay(0.01f), new Animation.Execute(delegate() { // We are exiting the map; just save the state of the map without the player. ListProperty <RespawnLocation> respawnLocations = PlayerDataFactory.Instance.Get <PlayerData>().RespawnLocations; respawnLocations.Clear(); List <Entity> persistentEntities = main.Entities.Where((Func <Entity, bool>)MapLoader.entityIsPersistent).ToList(); IO.MapLoader.Serializer.Serialize(stream, persistentEntities); foreach (Entity e in persistentEntities) { e.Delete.Execute(); } main.Spawner.StartSpawnPoint.Value = spawn; if (PlayerFactory.Instance != null) { PlayerFactory.Instance.Delete.Execute(); } main.SaveCurrentMap(null, default(Point), saveInfo); MapLoader.Load(main, nextMap); stream.Seek(0, SeekOrigin.Begin); List <Entity> entities = (List <Entity>)IO.MapLoader.Serializer.Deserialize(stream); foreach (Entity e in entities) { Factory <Main> factory = Factory <Main> .Get(e.Type); e.GUID = 0; factory.Bind(e, main); main.Add(e); } stream.Dispose(); }), new Animation.Delay(0.01f), new Animation.Execute(loadingNotification.Delete), new Animation.Set <bool>(main.Menu.CanPause, true), new Animation.Execute(main.ScheduleSave) ); anim.EnabledWhenPaused = false; main.AddComponent(anim); }
private void Button_Click(object sender, RoutedEventArgs e) { main.Add(); }
public override Action NextAction() { // Evaluation des dominos dans la main var leftNum = game.PlayedDominos.First(); var rightNum = game.PlayedDominos.Last(); var possibleDominos = Main.Where(d => d.Values.Any(i => i == leftNum || i == rightNum)); // score = coeff_double*score_double + coeff_div*score_div + coeff_valeur * score_valeur + coeff_bloq * score_bloq // Recupération Action action; Domino playDomino; if (possibleDominos.Any()) { // scoring IA CalculScore(possibleDominos, leftNum, rightNum); playDomino = possibleDominos.OrderByDescending(d => d.scores.Max()).First(); Main.Remove(playDomino); if (playDomino.scores[0] > playDomino.scores[1]) { if (playDomino.Values[0] == leftNum) { game.PlayedDominos.Insert(0, playDomino.Values[0]); game.PlayedDominos.Insert(0, playDomino.Values[1]); } else { game.PlayedDominos.Add(playDomino.Values[0]); game.PlayedDominos.Add(playDomino.Values[1]); } } else { if (playDomino.Values[1] == leftNum) { game.PlayedDominos.Insert(0, playDomino.Values[1]); game.PlayedDominos.Insert(0, playDomino.Values[0]); } else { game.PlayedDominos.Add(playDomino.Values[1]); game.PlayedDominos.Add(playDomino.Values[0]); } } action = new Action { name = "domino", domino = playDomino }; return(action); } if (game.Pioche.Any()) { nbPioche += 1; var index = GameIA.rnd.Next(game.Pioche.Count); var domino = game.Pioche[index]; game.Pioche.RemoveAt(index); Main.Add(domino); UpdateProbabilite(domino); action = new Action { name = "pioche" }; return(action); } action = new Action { name = "passe" }; return(action); }
public void TestAdd() { Assert.AreEqual(4, Main.Add(2, 2)); }
public override void Bind(Entity result, Main main, bool creating = false) { Transform transform = result.Get<Transform>(); EnemyBase enemy = result.GetOrCreate<EnemyBase>("Base"); PlayerCylinderTrigger trigger = result.Get<PlayerCylinderTrigger>(); PointLight light = result.GetOrCreate<PointLight>(); light.Color.Value = new Vector3(1.3f, 0.5f, 0.5f); light.Attenuation.Value = 15.0f; light.Shadowed.Value = false; light.Serialize = false; ListProperty<Entity.Handle> dynamicMaps = result.GetListProperty<Entity.Handle>("DynamicMaps"); Property<float> timeUntilRebuild = result.GetProperty<float>("TimeUntilRebuild"); Property<float> timeUntilRebuildComplete = result.GetProperty<float>("TimeUntilRebuildComplete"); Property<float> rebuildDelay = result.GetProperty<float>("RebuildDelay"); Property<float> rebuildTime = result.GetProperty<float>("RebuildTime"); const float rebuildTimeMultiplier = 0.03f; enemy.Add(new CommandBinding(enemy.Delete, result.Delete)); enemy.Add(new Binding<Matrix>(enemy.Transform, transform.Matrix)); light.Add(new Binding<Vector3>(light.Position, enemy.Position)); trigger.Add(new Binding<Matrix>(trigger.Transform, () => Matrix.CreateTranslation(0.0f, 0.0f, enemy.Offset) * transform.Matrix, transform.Matrix, enemy.Offset)); Action<Entity> fall = delegate(Entity player) { if (timeUntilRebuild.Value > 0 || timeUntilRebuildComplete.Value > 0) return; if (!enemy.IsValid) { result.Delete.Execute(); return; } // Disable the cell-emptied notification. // This way, we won't think that the base has been destroyed by the player. // We are not in fact dying, we're just destroying the base so we can fall over. enemy.EnableCellEmptyBinding = false; Map m = enemy.Map.Value.Target.Get<Map>(); m.Empty(enemy.BaseBoxes.SelectMany(x => x.GetCoords())); m.Regenerate(delegate(List<DynamicMap> spawnedMaps) { Vector3 playerPos = player.Get<Transform>().Position; playerPos += player.Get<Player>().LinearVelocity.Value * 0.65f; foreach (DynamicMap newMap in spawnedMaps) { Vector3 toPlayer = playerPos - newMap.PhysicsEntity.Position; toPlayer.Normalize(); if (Math.Abs(toPlayer.Y) < 0.9f) { toPlayer *= 25.0f * newMap.PhysicsEntity.Mass; Vector3 positionAtPlayerHeight = newMap.PhysicsEntity.Position; Vector3 impulseAtBase = toPlayer * -0.75f; impulseAtBase.Y = 0.0f; positionAtPlayerHeight.Y = playerPos.Y; newMap.PhysicsEntity.ApplyImpulse(ref positionAtPlayerHeight, ref impulseAtBase); newMap.PhysicsEntity.ApplyLinearImpulse(ref toPlayer); } newMap.PhysicsEntity.Material.KineticFriction = 1.0f; newMap.PhysicsEntity.Material.StaticFriction = 1.0f; dynamicMaps.Add(newMap.Entity); } }); timeUntilRebuild.Value = rebuildDelay; }; result.Add(new PostInitialization { delegate() { foreach (Entity.Handle map in dynamicMaps) { if (map.Target != null) { BEPUphysics.Entities.MorphableEntity e = map.Target.Get<DynamicMap>().PhysicsEntity; e.Material.KineticFriction = 1.0f; e.Material.StaticFriction = 1.0f; } } } }); result.Add(new CommandBinding<Entity>(trigger.PlayerEntered, fall)); result.Add(new Updater { delegate(float dt) { if (timeUntilRebuild > 0) { if (enemy.Map.Value.Target == null || !enemy.Map.Value.Target.Active) { result.Delete.Execute(); return; } float newValue = Math.Max(0.0f, timeUntilRebuild.Value - dt); timeUntilRebuild.Value = newValue; if (newValue == 0.0f) { // Rebuild Map m = enemy.Map.Value.Target.Get<Map>(); int index = 0; Vector3 baseCenter = Vector3.Zero; EffectBlockFactory factory = Factory.Get<EffectBlockFactory>(); Entity targetMap = enemy.Map.Value.Target; foreach (Map.Coordinate c in enemy.BaseBoxes.SelectMany(x => x.GetCoords())) { if (m[c].ID == 0) { Entity block = factory.CreateAndBind(main); c.Data.ApplyToEffectBlock(block.Get<ModelInstance>()); block.GetProperty<Vector3>("Offset").Value = m.GetRelativePosition(c); block.GetProperty<Vector3>("StartPosition").Value = m.GetAbsolutePosition(c) + new Vector3(0.25f, 0.5f, 0.25f) * index; block.GetProperty<Matrix>("StartOrientation").Value = Matrix.CreateRotationX(0.15f * index) * Matrix.CreateRotationY(0.15f * index); block.GetProperty<float>("TotalLifetime").Value = 0.05f + (index * rebuildTimeMultiplier * rebuildTime); factory.Setup(block, targetMap, c, c.Data.ID); main.Add(block); index++; baseCenter += new Vector3(c.X, c.Y, c.Z); } } baseCenter /= index; // Get the average position of the base cells foreach (Entity.Handle e in dynamicMaps) { Entity dynamicMap = e.Target; Map dynamicMapComponent = dynamicMap != null && dynamicMap.Active ? dynamicMap.Get<Map>() : null; if (dynamicMap == null || !dynamicMap.Active) continue; Matrix orientation = dynamicMapComponent.Transform.Value; orientation.Translation = Vector3.Zero; List<Map.Coordinate> coords = new List<Map.Coordinate>(); foreach (Map.Coordinate c in dynamicMapComponent.Chunks.SelectMany(x => x.Boxes).SelectMany(x => x.GetCoords())) { if (m[c].ID == 0) coords.Add(c); } foreach (Map.Coordinate c in coords.OrderBy(x => (new Vector3(x.X, x.Y, x.Z) - baseCenter).LengthSquared())) { Entity block = factory.CreateAndBind(main); c.Data.ApplyToEffectBlock(block.Get<ModelInstance>()); block.GetProperty<Vector3>("Offset").Value = m.GetRelativePosition(c); block.GetProperty<bool>("Scale").Value = dynamicMapComponent == null; if (dynamicMapComponent != null && dynamicMapComponent[c].ID == c.Data.ID) { block.GetProperty<Vector3>("StartPosition").Value = dynamicMapComponent.GetAbsolutePosition(c); block.GetProperty<Matrix>("StartOrientation").Value = orientation; } else { block.GetProperty<Vector3>("StartPosition").Value = m.GetAbsolutePosition(c) + new Vector3(0.25f, 0.5f, 0.25f) * index; block.GetProperty<Matrix>("StartOrientation").Value = Matrix.CreateRotationX(0.15f * index) * Matrix.CreateRotationY(0.15f * index); } block.GetProperty<float>("TotalLifetime").Value = 0.05f + (index * rebuildTimeMultiplier * rebuildTime); factory.Setup(block, targetMap, c, c.Data.ID); main.Add(block); index++; } dynamicMap.Delete.Execute(); } timeUntilRebuildComplete.Value = 0.05f + (index * rebuildTimeMultiplier * rebuildTime); dynamicMaps.Clear(); } } else if (timeUntilRebuildComplete > 0) { // Rebuilding float newValue = Math.Max(0.0f, timeUntilRebuildComplete.Value - dt); timeUntilRebuildComplete.Value = newValue; if (newValue == 0.0f) { // Done rebuilding if (!enemy.IsValid) result.Delete.Execute(); else { enemy.EnableCellEmptyBinding = !main.EditorEnabled; if (trigger.IsTriggered) fall(trigger.Player.Value.Target); } } } } }); this.SetMain(result, main); }
public static void LoadWithEntities(Main main, string nextMap, List<Entity> persistentEntities) { Stream stream = new MemoryStream(); IO.MapLoader.Serializer.Serialize(stream, persistentEntities); MapLoader.Load(main, nextMap); stream.Seek(0, SeekOrigin.Begin); List<Entity> entities = (List<Entity>)IO.MapLoader.Serializer.Deserialize(stream); foreach (Entity e in entities) { Factory<Main> factory = Factory<Main>.Get(e.Type); e.GUID = 0; factory.Bind(e, main); main.Add(e); } stream.Dispose(); }
public override void Bind(Entity result, Main main, bool creating = false) { this.SetMain(result, main); Transform transform = result.Get<Transform>(); PlayerTrigger trigger = result.Get<PlayerTrigger>(); Property<string> nextMap = result.GetProperty<string>("NextMap"); Property<string> startSpawnPoint = result.GetProperty<string>("SpawnPoint"); trigger.Add(new TwoWayBinding<Vector3>(transform.Position, trigger.Position)); trigger.Add(new CommandBinding<Entity>(trigger.PlayerEntered, delegate(Entity player) { XmlSerializer serializer = new XmlSerializer(typeof(List<Entity>)); Container notification = new Container(); notification.Tint.Value = Microsoft.Xna.Framework.Color.Black; notification.Opacity.Value = 0.5f; TextElement notificationText = new TextElement(); notificationText.Name.Value = "Text"; notificationText.FontFile.Value = "Font"; notificationText.Text.Value = "Loading..."; notification.Children.Add(notificationText); ((GameMain)main).UI.Root.GetChildByName("Notifications").Children.Add(notification); Stream stream = new MemoryStream(); main.AddComponent(new Animation ( new Animation.Delay(0.01f), new Animation.Execute(delegate() { // We are exiting the map; just save the state of the map without the player. ListProperty<PlayerFactory.RespawnLocation> respawnLocations = Factory.Get<PlayerDataFactory>().Instance(main).GetOrMakeListProperty<PlayerFactory.RespawnLocation>("RespawnLocations"); respawnLocations.Clear(); List<Entity> persistentEntities = main.Entities.Where((Func<Entity, bool>)MapExitFactory.isPersistent).ToList(); serializer.Serialize(stream, persistentEntities); foreach (Entity e in persistentEntities) e.Delete.Execute(); ((GameMain)main).StartSpawnPoint = startSpawnPoint; }), new Animation.Execute(((GameMain)main).SaveCurrentMap), new Animation.Set<string>(main.MapFile, nextMap), new Animation.Execute(delegate() { notification.Visible.Value = false; stream.Seek(0, SeekOrigin.Begin); List<Entity> entities = (List<Entity>)serializer.Deserialize(stream); foreach (Entity entity in entities) { Factory factory = Factory.Get(entity.Type); factory.Bind(entity, main); main.Add(entity); } stream.Dispose(); }), new Animation.Delay(1.5f), new Animation.Set<string>(notificationText.Text, "Saving..."), new Animation.Set<bool>(notification.Visible, true), new Animation.Delay(0.01f), new Animation.Execute(((GameMain)main).Save), new Animation.Set<string>(notificationText.Text, "Saved"), new Animation.Parallel ( new Animation.FloatMoveTo(notification.Opacity, 0.0f, 1.0f), new Animation.FloatMoveTo(notificationText.Opacity, 0.0f, 1.0f) ), new Animation.Execute(notification.Delete) )); })); }
private static void load(Main main, Stream stream, bool deleteEditor, Entity playerData) { main.Camera.Position.Value = new Vector3(0, -1000, 0); main.IsLoadingMap = true; main.ClearEntities(deleteEditor); if (stream == null) main.DefaultLighting(); // There's no World entity to set the correct lighting, so set the defaults else { List<Entity> entities = null; try { entities = (List<Entity>)MapLoader.Serializer.Deserialize(stream); } catch (InvalidOperationException e) { throw new Exception("Failed to deserialize file stream.", e); } if (playerData != null) entities.Add(playerData); foreach (Entity entity in entities) { Factory<Main> factory = Factory<Main>.Get(entity.Type); if (factory != null) { factory.Bind(entity, main); main.Add(entity); } } } main.IsLoadingMap = false; main.MapLoaded.Execute(); }
public override void Bind(Entity result, Main main, bool creating = false) { result.CannotSuspend = true; Transform transform = result.Get<Transform>(); PhysicsBlock physics = result.Get<PhysicsBlock>(); Model model = result.Get<Model>(); Sound loopSound = result.Get<Sound>("LoopSound"); PointLight light = result.Get<PointLight>(); ParticleEmitter emitter = result.Get<ParticleEmitter>("Particles"); physics.Add(new TwoWayBinding<Matrix>(transform.Matrix, physics.Transform)); light.Add(new Binding<Vector3>(light.Position, transform.Position)); emitter.Add(new Binding<Vector3>(emitter.Position, transform.Position)); model.Add(new Binding<Matrix>(model.Transform, transform.Matrix)); loopSound.Add(new Binding<Vector3>(loopSound.Position, transform.Position)); loopSound.Add(new Binding<Vector3>(loopSound.Velocity, physics.LinearVelocity)); loopSound.Position.Value = transform.Position; physics.Add(new CommandBinding<Collidable, ContactCollection>(physics.Collided, delegate(Collidable collidable, ContactCollection contacts) { if (result.Active) { result.Delete.Execute(); Sound.PlayCue(main, "Explosion", transform.Position); if (collidable is EntityCollidable) { if (((EntityCollidable)collidable).Entity.Tag is Map) { ContactInformation contact = contacts.First(); Vector3 pos = contact.Contact.Position - (contact.Contact.Normal * 0.5f); Map map = (Map)((EntityCollidable)collidable).Entity.Tag; Map.Coordinate center = map.GetCoordinate(pos); int radius = 3; Random random = new Random(); for (Map.Coordinate x = center.Move(Direction.NegativeX, radius - 1); x.X < center.X + radius; x.X++) { for (Map.Coordinate y = x.Move(Direction.NegativeY, radius - 1); y.Y < center.Y + radius; y.Y++) { for (Map.Coordinate z = y.Move(Direction.NegativeZ, radius - 1); z.Z < center.Z + radius; z.Z++) { Vector3 cellPos = map.GetAbsolutePosition(z); Vector3 toCell = cellPos - pos; if (toCell.Length() < radius - 1) { Map.CellState state = map[z]; if (map.Empty(z)) { Entity block = Factory.CreateAndBind(main, "Block"); block.Get<Transform>().Position.Value = cellPos; block.Get<Transform>().Quaternion.Value = map.Entity.Get<Transform>().Quaternion; state.ApplyToBlock(block); block.Get<ModelInstance>().GetVector3Parameter("Offset").Value = map.GetRelativePosition(z); toCell += contact.Contact.Normal * 4.0f; toCell.Normalize(); block.Get<PhysicsBlock>().LinearVelocity.Value = toCell * 15.0f; block.Get<PhysicsBlock>().AngularVelocity.Value = new Vector3(((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f); main.Add(block); } } } } } map.Regenerate(); } else if (((EntityCollidable)collidable).Entity.Tag is Player) { Player player = (Player)((EntityCollidable)collidable).Entity.Tag; player.Health.Value -= 0.75f; } } } })); this.SetMain(result, main); loopSound.Play.Execute(); }
public static void Transition(Main main, string nextMap, string spawn = null) { Container loadingNotification = new Container(); loadingNotification.Tint.Value = Microsoft.Xna.Framework.Color.Black; loadingNotification.Opacity.Value = UIFactory.Opacity; TextElement loadingNotificationText = new TextElement(); loadingNotificationText.Name.Value = "Text"; loadingNotificationText.FontFile.Value = main.Font; loadingNotificationText.Text.Value = "\\loading"; loadingNotification.Children.Add(loadingNotificationText); Animation anim = new Animation ( new Animation.Set<bool>(main.Menu.CanPause, false), main.Spawner.FlashAnimation(), new Animation.Execute(delegate() { main.UI.Root.GetChildByName("Notifications").Children.Add(loadingNotification); }), new Animation.Delay(0.01f), new Animation.Execute(delegate() { #if DEMO if (nextMap == "forest") { main.Spawner.StartSpawnPoint.Value = "demo"; MapLoader.Load(main, Main.MenuMap); } else #endif { // We are exiting the map; just save the state of the map without the player. ListProperty<RespawnLocation> respawnLocations = PlayerDataFactory.Instance.Get<PlayerData>().RespawnLocations; respawnLocations.Clear(); List<Entity> persistentEntities = main.Entities.Where((Func<Entity, bool>)MapLoader.entityIsPersistent).ToList(); Stream stream = new MemoryStream(); IO.MapLoader.Serializer.Serialize(stream, persistentEntities); foreach (Entity e in persistentEntities) e.Delete.Execute(); main.Spawner.StartSpawnPoint.Value = spawn; if (PlayerFactory.Instance != null) PlayerFactory.Instance.Delete.Execute(); main.SaveCurrentMap(null, default(Point)); MapLoader.Load(main, nextMap); stream.Seek(0, SeekOrigin.Begin); List<Entity> entities = (List<Entity>)IO.MapLoader.Serializer.Deserialize(stream); foreach (Entity e in entities) { Factory<Main> factory = Factory<Main>.Get(e.Type); e.GUID = 0; factory.Bind(e, main); main.Add(e); } stream.Dispose(); } }), new Animation.Delay(0.01f), new Animation.Execute(loadingNotification.Delete), new Animation.Set<bool>(main.Menu.CanPause, true), new Animation.Execute(main.ScheduleSave) ); anim.EnabledWhenPaused = false; main.AddComponent(anim); }
public async Task <ActionResult <long> > Add(Model value) { return(Ok(await Main.Add(value.Value))); }
private static void Load(Main main, Stream stream, bool deleteEditor = true) { main.Camera.Position.Value = new Vector3(0, -10000, 0); main.IsLoadingMap = true; main.ClearEntities(deleteEditor); List<Entity> entities = null; try { entities = (List<Entity>)MapLoader.Serializer.Deserialize(stream); } catch (InvalidOperationException e) { throw new Exception("Failed to deserialize file stream.", e); } foreach (Entity entity in entities) { Factory<Main> factory = Factory<Main>.Get(entity.Type); factory.Bind(entity, main); main.Add(entity); } main.IsLoadingMap = false; main.MapLoaded.Execute(); }
public void ActionDataAdd(ActionData a) { Main.Add(a); }