Пример #1
0
        private void Update_AddBot(ArcBotNPC[] currentBots)
        {
            const double HOMINGRADIUS = 8d;
            //const int LEVEL = 1;

            if (currentBots.Length >= 2)       //TODO: Get this from DNA
            {
                // There are enough bots
                return;
            }

            if (_eggs.Count == 0)
            {
                return;
            }
            else if (_eggs[0].Item3 > _time - 4)        // item 0 will always be the oldest egg.  Time is in seconds
            {
                // The egg hasn't been sitting long enough to hatch
                return;
            }

            // Remove the egg
            _eggModels.Children.Remove(_eggs[0].Item1);
            _eggs.RemoveAt(0);

            // Create a bot
            Tuple<BotDNA, WeaponDNA> dna = _dreamer.GetBestBotDNA();

            Point3D? position = _dragPlane.CastRay(this.PositionWorld + Math3D.GetRandomVector_Circular(this.Radius * 3));
            if (position == null)
            {
                throw new ApplicationException("Drag plane couldn't find the nearest point");
            }

            int level = StaticRandom.Next(1, 20);
            ArcBotNPC bot = new ArcBotNPC(dna.Item1, level, position.Value, _world, _map, _keepItems2D, _materialIDs, _viewport, _editorOptions, _itemOptions, _gravity, _dragPlane, this.PositionWorld, HOMINGRADIUS, true, true);

            _map.AddItem(bot);
            _botTokens.Add(bot.Token);

            // Attached Weapon
            //NOTE: Doing this here, because bot.AttachWeapon plays with the viewport, so does map.  If this is done before map, it blows up.
            //if it's done after, then bot.AttachWeapon handles that properly
            if (dna.Item2 != null)
            {
                Weapon weapon = new Weapon(dna.Item2, new Point3D(0, 0, 0), _world, _materialIDs.Weapon);

                bot.AttachWeapon(weapon);
            }
        }
Пример #2
0
        private static void AddBot(AddBotArgs dna, WorldVars arg)
        {
            // Bot
            ArcBotNPC bot = new ArcBotNPC(dna.Bot, dna.Level, dna.Position, arg.World, arg.Map, arg.Keep2D, arg.MaterialIDs, null, arg.EditorOptions, arg.ItemOptions, arg.Gravity, arg.DragPlane, dna.HomingPoint, dna.HomingRadius, true, true);

            if (dna.AngularVelocity != null)
            {
                bot.PhysicsBody.AngularVelocity = dna.AngularVelocity.Value;
            }

            arg.Map.AddItem(bot);

            // Attached Weapon
            if (dna.AttachedWeapon != null)
            {
                Weapon weapon = new Weapon(dna.AttachedWeapon, new Point3D(0, 0, 0), arg.World, arg.MaterialIDs.Weapon);

                bot.AttachWeapon(weapon);
            }

            // Inventory Weapons
            if (dna.InventoryWeapons != null)
            {
                foreach (var weapDNA in dna.InventoryWeapons)
                {
                    Weapon weapon = new Weapon(weapDNA, new Point3D(0, 0, 0), arg.World, arg.MaterialIDs.Weapon);

                    bot.AddToInventory(weapon);
                }
            }

            // Call delegate
            if (dna.ItemAdded != null)
            {
                dna.ItemAdded(bot);
            }
        }