Example #1
0
 public void Apply(MutatingWorld world)
 {
     if (world.Entities.ContainsKey(ID))
     {
         world.RemoveByID(ID);
     }
 }
Example #2
0
        public void Apply(MutatingWorld world)
        {
            Entity e;

            if (!world.Entities.TryGetValue(ID, out e))
            {
                return;
            }

            world.Entities[ID] = new Entity(e, velocity: NewVelocity);
        }
Example #3
0
        public void Apply(MutatingWorld world)
        {
            Entity entity;

            if (!world.Entities.TryGetValue(EntityID, out entity))
            {
                return;
            }

            world.Entities[EntityID] = new Entity(entity, spell: (Maybe <SpellInfo>)Spell);
        }
 public IEnumerable <int> GetTargets(MutatingWorld world)
 {
     return(Delegate(world));
 }
Example #5
0
 public IEnumerable <int> GetTargets(MutatingWorld world)
 {
     return(Enumerable.Empty <int>());
 }
Example #6
0
 public void OnCast(MutatingWorld world, Entity caster, IEnumerable <int> targets)
 {
     Delegate(world, caster, targets);
 }
Example #7
0
        public void Apply(MutatingWorld world)
        {
            var watch = new Stopwatch();

            watch.Start();
            var spawnBounds = SpawnBounds;
            var team        = Team;

            if (team == -1)
            {
                MutatingTeam teamObj = null;
                foreach (var teamkvp in world.Teams)
                {
                    if (teamObj == null || teamkvp.Value.Members.Count < teamObj.Members.Count)
                    {
                        team    = teamkvp.Key;
                        teamObj = teamkvp.Value;
                    }
                }
                world.Teams[team].LastSpawnTimeMS = world.Timestamp;
                spawnBounds = world.Teams[team].SpawnRect;
            }

            Vector2 spawnLoc;

            while (true)
            {
                spawnLoc = new Vector2(
                    (float)(spawnBounds.Min.X + world.RandomGen.NextDouble() * spawnBounds.Width),
                    (float)(spawnBounds.Min.Y + world.RandomGen.NextDouble() * spawnBounds.Height));

                var alreadyCollidedIds = new HashSet <int>();
                var done = true;
                while (true)
                {
                    var inter = world.Entities.Select((e) => Tuple.Create(e, Polygon2.IntersectMTV(e.Value.Attributes.Bounds, Attributes.Bounds, e.Value.Location, spawnLoc))).FirstOrDefault((tup) => tup.Item2 != null);
                    if (inter != null)
                    {
                        if (alreadyCollidedIds.Contains(inter.Item1.Key))
                        {
                            break;
                        }

                        alreadyCollidedIds.Add(inter.Item1.Key);
                        spawnLoc += inter.Item2.Item1 * (inter.Item2.Item2 * 1.1f);
                        done      = false;
                    }
                    else
                    {
                        break;
                    }
                }

                if (done)
                {
                    break;
                }
            }

            var entId        = world.IDCounter++;
            var nearbyBounds = Logic.NEARBY_BOUNDS;
            var nearby       = new HashSet <int>();

            foreach (var kvp in world.Entities)
            {
                if (Rect2.Intersects(kvp.Value.Attributes.Bounds.AABB, nearbyBounds, kvp.Value.Location, spawnLoc, true))
                {
                    nearby.Add(kvp.Key);
                }
            }

            foreach (var id in nearby)
            {
                var e = world.Entities[id];
                world.Entities[id] = new Entity(e, nearby: (Maybe <ImmutableHashSet <int> >)e.NearbyEntityIds.Add(entId));
            }

            var ent = new Entity(entId, team, Name, Attributes, spawnLoc, Vector2.Zero, Attributes.MaxHealth, Attributes.MaxMana, null,
                                 ImmutableDictionary.Create <int, int>(), nearby.ToImmutableHashSet(), ImmutableList <IModifier> .Empty);

            world.Add(ent);
            world.FinishedCallbacks.Add(() => Callback?.Invoke(ent));

            watch.Stop();
            var elapsedMS = watch.ElapsedMilliseconds;

            if (elapsedMS > 2)
            {
                Console.WriteLine($"Took a long time to spawn new entity! ({elapsedMS} ms)");
            }
        }