Ejemplo n.º 1
0
        public void Update(bool playing)
        {
            if (PendingActions.Count > 0)
            {
                foreach (var action in PendingActions)
                {
                    action(this);
                }
                PendingActions.Clear();
            }

            if (playing)
            {
                // simulate all units
                foreach (var unit in Units)
                {
                    unit.Update();
                }
            }
            WorldUpdated?.Invoke(this);
        }
        /// <summary>
        /// Called every tick of the game loop.
        /// </summary>
        private void OnTick()
        {
            // Cleaning
            CleanupProjectiles();

            // Spawning
            SpawnShips();
            SpawnProjectiles();

            // Motion
            ComputeShipMotion();
            ComputeProjectileMotion();
            ComputeWrapping();

            // Collision
            ComputeProjectileCollisions();
            ComputeShipCollisions();

            // Notify listeners of world updated
            WorldUpdated?.Invoke(_world);
        }
Ejemplo n.º 3
0
        public void UpdatePlayerContext(PlayerContext context)
        {
            World              = context.World;
            Me                 = context.Wizards.Single(x => x.IsMe);
            CurrentBuildings   = new Dictionary <long, Building>();
            CurrentWizards     = new Dictionary <long, Wizard>();
            CurrentMinions     = new Dictionary <long, Minion>();
            CurrentProjectiles = new Dictionary <long, Projectile>();

            foreach (var unit in context.World.Buildings)
            {
                DeadBuildings.Remove(unit.Id);
                AllBuildings[unit.Id]     = unit;
                CurrentBuildings[unit.Id] = unit;
            }
            foreach (var unit in context.World.Wizards)
            {
                DeadWizards.Remove(unit.Id);
                AllWizards[unit.Id]     = unit;
                CurrentWizards[unit.Id] = unit;
            }
            foreach (var unit in context.World.Minions)
            {
                DeadMinions.Remove(unit.Id);
                AllMinions[unit.Id]     = unit;
                CurrentMinions[unit.Id] = unit;
            }

            foreach (var unit in context.World.Projectiles)
            {
                DeadProjectiles.Remove(unit.Id);
                AllProjectiles[unit.Id]     = unit;
                CurrentProjectiles[unit.Id] = unit;
            }

            foreach (var diedUnit in AllBuildings.Except(CurrentBuildings).Where(x => x.Value.IsUnion(Me) || x.Value.Life <= 36))
            {
                DeadBuildings[diedUnit.Key] = new DeadUnitInfo(context.World, diedUnit.Value, Me);
            }

            foreach (var diedUnit in AllWizards.Except(CurrentWizards).Where(x => x.Value.IsUnion(Me) || x.Value.Life <= 36))
            {
                DeadWizards[diedUnit.Key] = new DeadUnitInfo(context.World, diedUnit.Value, Me);
            }

            foreach (var diedUnit in AllMinions.Except(CurrentMinions).Where(x => x.Value.IsUnion(Me) || x.Value.Life <= 36))
            {
                DeadMinions[diedUnit.Key] = new DeadUnitInfo(context.World, diedUnit.Value, Me);
            }

            foreach (var diedUnit in AllProjectiles.Except(CurrentProjectiles))
            {
                bool isTargetTree = context.World.Trees.Any(x => x.GetDistanceTo(diedUnit.Value) < 220);
                DeadProjectiles[diedUnit.Key] = new DeadUnitInfo(context.World, diedUnit.Value, Me, isTargetTree);
            }

            AllBuildings   = CurrentBuildings;
            AllWizards     = CurrentWizards;
            AllMinions     = CurrentMinions;
            AllProjectiles = CurrentProjectiles;

            CurrentBuildingTargets = new Dictionary <long, List <LivingUnit> >();
            foreach (var building in CurrentBuildings)
            {
                var buildingUnit          = building.Value;
                var attackRange           = buildingUnit.Type == BuildingType.GuardianTower ? Game.GuardianTowerAttackRange : Game.FactionBaseAttackRange;
                var maxDamage             = buildingUnit.Type == BuildingType.GuardianTower ? Game.GuardianTowerDamage : Game.FactionBaseDamage;
                List <LivingUnit> p1Units = new List <LivingUnit>();
                List <LivingUnit> p2Units = new List <LivingUnit>();
                foreach (var minion in CurrentMinions)
                {
                    FindBuildingTarget(minion.Value, buildingUnit, attackRange, maxDamage, p1Units, p2Units);
                }
                foreach (var wizard in CurrentWizards)
                {
                    FindBuildingTarget(wizard.Value, buildingUnit, attackRange, maxDamage, p1Units, p2Units);
                }
                var buildingTargets = p1Units.Count > 0 ? p1Units : p2Units;
                CurrentBuildingTargets[building.Key] = buildingTargets;
            }

            DeadProjectiles = DeadProjectiles
                              .Where(x => x.Value.ProjectileType == ProjectileType.MagicMissile &&
                                     context.World.TickIndex < x.Value.TickIndex + 5 * 4)
                              .ToDictionary(x => x.Key, y => y.Value);

            WorldUpdated?.Invoke(this, EventArgs.Empty);
        }