コード例 #1
0
        public bool ResolveCollision(GameObject go, BotObject bot)
        {
            // If the bot's ID has already been removed from the world, the bot is dead, return the alive state as false
            if (!worldStateService.GameObjectIsInWorldState(bot.Id))
            {
                return(false);
            }

            // If the colliding GO has already been removed from the world, but we reached here, the bot is alive but need not process the GO collision
            if (!worldStateService.GameObjectIsInWorldState(go.Id))
            {
                return(true);
            }

            if (bot.Size > engineConfig.WorldFood.MaxConsumptionSize)
            {
                return(true);
            }

            bot.Size  += go.Size;
            bot.Score += engineConfig.ScoreRates[GameObjectType.Food];
            go.Size    = 0;
            worldStateService.RemoveGameObjectById(go.Id);
            worldStateService.UpdateBotSpeed(bot);
            return(true);
        }
コード例 #2
0
        public bool ResolveCollision(GameObject gameObject, BotObject bot)
        {
            if (gameObject.Size < bot.Size)
            {
                return(true);
            }

            Tuple <GameObject, GameObject> wormholePair = worldStateService.GetWormholePair(gameObject.Id);

            if (wormholePair.Equals(null))
            {
                // Lol how? We found a wormhole in state that did not exist in the known wormhole pairs
                throw new InvalidOperationException("Invalid Wormhole");
            }

            var counterpartWormhole = wormholePair.Item1.Id == gameObject.Id ? wormholePair.Item2 : wormholePair.Item1;

            var resultingPosition = vectorCalculatorService.GetPositionFrom(
                counterpartWormhole.Position,
                counterpartWormhole.Size + bot.Size,
                bot.CurrentHeading);

            bot.Position = resultingPosition;
            bot.Score    = engineConfig.ScoreRates[GameObjectType.Wormhole];

            var newSize = (int)Math.Ceiling(wormholePair.Item1.Size * engineConfig.ConsumptionRatio[GameObjectType.Wormhole]);

            wormholePair.Item1.Size = newSize < engineConfig.Wormholes.MinSize ? engineConfig.Wormholes.MinSize : newSize;
            wormholePair.Item2.Size = wormholePair.Item1.Size;

            worldStateService.UpdateGameObject(wormholePair.Item1);
            worldStateService.UpdateGameObject(wormholePair.Item2);

            return(true);
        }
コード例 #3
0
        public bool ResolveCollision(GameObject gameObject, BotObject bot)
        {
            var currentEffect = new ActiveEffect
            {
                Bot    = bot,
                Effect = Effects.GasCloud
            };

            /* If the effect is not registered, add it to the list. */
            if (worldStateService.GetActiveEffectByType(bot.Id, Effects.GasCloud) != default)
            {
                if (bot.Size < engineConfig.MinimumPlayerSize)
                {
                    worldStateService.RemoveGameObjectById(bot.Id);
                }
                return(bot.Size >= engineConfig.MinimumPlayerSize);
            }

            worldStateService.AddActiveEffect(currentEffect);
            bot.Size -= engineConfig.GasClouds.AffectPerTick;
            if (bot.Size < engineConfig.MinimumPlayerSize)
            {
                worldStateService.RemoveGameObjectById(bot.Id);
            }
            return(bot.Size >= engineConfig.MinimumPlayerSize);
        }
コード例 #4
0
        public BotObject GetBotWithActions()
        {
            var id  = Guid.NewGuid();
            var bot = new BotObject
            {
                Id             = id,
                Size           = 10,
                Position       = new Position(),
                Speed          = 20,
                GameObjectType = GameObjectType.Player,
                PendingActions = new List <PlayerAction>
                {
                    GetForwardPlayerAction(id),
                    GetForwardPlayerAction(id)
                },
                CurrentAction = new PlayerAction
                {
                    Action   = PlayerActions.Stop,
                    Heading  = 0,
                    PlayerId = id
                }
            };

            worldStateService.AddBotObject(bot);
            return(bot);
        }
コード例 #5
0
ファイル: Day10.cs プロジェクト: herromega/AdventOfCode
        public static void setupBots(string[] instructions)
        {
            bots = new List <BotObject>();

            foreach (string instruction in instructions)
            {
                if (instruction.StartsWith("bot"))
                {
                    string[] botData = instruction.Split(' ');

                    BotObject bot = new BotObject();

                    bot.id              = int.Parse(botData[1]);
                    bot.lowValueToId    = int.Parse(botData[6]);
                    bot.highValueToId   = int.Parse(botData[11]);
                    bot.valueCollection = new List <int>();

                    if (botData[5] == "output")
                    {
                        bot.outputLow = true;
                    }

                    if (botData[10] == "output")
                    {
                        bot.outputHigh = true;
                    }

                    bots.Add(bot);
                }
            }
        }
コード例 #6
0
        public bool ResolveCollision(GameObject gameObject, BotObject bot)
        {
            if (!(gameObject is BotObject go))
            {
                throw new ArgumentException("Non player in player collision");
            }

            // If the bot's ID has already been removed from the world, the bot is dead, return the alive state as false
            if (!worldStateService.GameObjectIsInWorldState(bot.Id))
            {
                return(false);
            }

            // If the colliding GO has already been removed from the world, but we reached here, the bot is alive but need not process the GO collision
            if (!worldStateService.GameObjectIsInWorldState(go.Id))
            {
                return(true);
            }

            var botsAreEqualSize = bot.Size == go.Size;

            if (botsAreEqualSize)
            {
                BounceBots(go, bot, 1);
                return(true);
            }

            var botIsBigger = bot.Size > go.Size;
            var consumer    = botIsBigger ? bot : go;
            var consumee    = !botIsBigger ? bot : go;

            var consumedSize = collisionService.GetConsumedSizeFromPlayer(consumer, consumee);

            consumee.Size  -= consumedSize;
            consumer.Size  += consumedSize;
            consumer.Score += engineConfig.ScoreRates[GameObjectType.Player];

            worldStateService.UpdateBotSpeed(consumer);

            BounceBots(consumee, consumer, (int)Math.Ceiling((consumedSize + 1d) / 2));

            if (consumee.Size < engineConfig.MinimumPlayerSize)
            {
                consumer.Size += consumee.Size; // After the previous consumptionSize has already been removed
                consumee.Size  = 0;
                worldStateService.RemoveGameObjectById(consumee.Id);
            }

            worldStateService.UpdateBotSpeed(consumee);

            if (bot.Size > engineConfig.MinimumPlayerSize)
            {
                return(true);
            }

            Logger.LogInfo("BotDeath", "Bot Consumed");
            worldStateService.RemoveGameObjectById(bot.Id);
            return(false);
        }
コード例 #7
0
ファイル: BotChatPage.xaml.cs プロジェクト: nickvetter/Chiota
 public BotChatPage(BotObject bot)
 {
     this.InitializeComponent();
     this.Title          = bot.BotName;
     this.BindingContext = new BotChatViewModel(bot, this.MessagesListView, this.QuickReplyStack)
     {
         Navigation = this.Navigation
     };
 }
コード例 #8
0
        public void ProcessAction(BotObject bot)
        {
            var activeEffect = worldStateService.GetActiveEffectByType(bot.Id, Effects.Afterburner);

            /* If the effect is not registered, remove speed boost and remove it from the list. */
            if (activeEffect != default)
            {
                worldStateService.RemoveActiveEffect(activeEffect);
                worldStateService.UpdateBotSpeed(bot);
            }
        }
コード例 #9
0
        public GameObject GetSmallBotAt(Position position)
        {
            var bot = new BotObject
            {
                Id             = Guid.NewGuid(),
                Size           = 5,
                Position       = position,
                Speed          = 40,
                GameObjectType = GameObjectType.Player
            };

            worldStateService.AddBotObject(bot);
            return(bot);
        }
コード例 #10
0
        public BotObject GetBotAtDefault()
        {
            var bot = new BotObject
            {
                Id             = Guid.NewGuid(),
                Size           = 10,
                Position       = new Position(),
                Speed          = 20,
                GameObjectType = GameObjectType.Player
            };

            worldStateService.AddBotObject(bot);
            return(bot);
        }
コード例 #11
0
ファイル: BotChatViewModel.cs プロジェクト: llenroc/Chiota
    public BotChatViewModel(BotObject bot, ListView messagesListView, StackLayout quickReplyStack)
        {
      this.connection = new BotConnection(bot);
      this.botId = bot.BotId;
      this.messagesListView = messagesListView;
      this.quickReplyStack = quickReplyStack;
      this.profileImageUrl = bot.ImageUrl;

      this.OutGoingText = null;

      this.Messages = new ObservableCollection<MessageViewModel>();
      this.GetMessagesAsync(this.Messages);
      this.outgoingText = null;
    }
コード例 #12
0
        public override void Start()
        {
            base.Start();
            mWeapon    = RequireComponent <BaseWeapon>();
            mMessage   = RequireComponent <MmoMessageComponent>();
            mCharacter = RequireComponent <CharacterObject>();
            mTarget    = RequireComponent <PlayerTarget>();
            mMovable   = GetComponent <MovableObject>();
            m_Skills   = GetComponent <PlayerSkills>();
            m_Bonuses  = GetComponent <PlayerBonuses>();

            mChestLiveDuration = nebulaObject.world.Resource().ServerInputs.GetValue <float>("chest_life");
            //log.InfoFormat("chest life = {0}", mChestLiveDuration);
            mShotTimer = m_ShotCooldown;

            mDead = false;

            combatAIType = aiType as CombatAIType;
            if (combatAIType == null)
            {
                log.Error("CombatBasseAI must have CombatAIType, but not simple AIType");
            }
            mShipWeapon = GetComponent <ShipWeapon>();
            if (Rand.Int() % 2 == 0)
            {
                mMovNearTargetType = MovingNearTarget.Circle;
            }
            else
            {
                mMovNearTargetType = MovingNearTarget.LIne;
            }
            mStartPosition = nebulaObject.transform.position;

#if USE_SKILLS
            //--------------------------TESTING------------------------------------
            var ship = GetComponent <BaseShip>();
            if (ship)
            {
                string sSkill = skills[Rand.Int(skills.Count - 1)];
                ship.shipModel.Slot(ShipModelSlotType.CB).Module.SetSkill(SkillExecutor.SkilIDFromHexString(sSkill));
                mSkills = GetComponent <PlayerSkills>();
                mSkills.UpdateSkills(ship.shipModel);
            }
            //--------------------------------------------------------------------
#endif

            mBotObject = GetComponent <BotObject>();
            SetupSkills();
        }
コード例 #13
0
        private void BounceBots(BotObject go, BotObject bot, int spacing)
        {
            var bots = new List <BotObject>
            {
                go,
                bot
            };

            foreach (var botObject in bots.Where(botObject => botObject.CurrentAction != null))
            {
                botObject.CurrentHeading        = vectorCalculatorService.ReverseHeading(botObject.CurrentHeading);
                botObject.CurrentAction.Heading = botObject.CurrentHeading;
                botObject.Position = vectorCalculatorService.GetPointFrom(botObject.Position, spacing, botObject.CurrentHeading);
            }
        }
コード例 #14
0
        public bool ResolveCollision(GameObject gameObject, BotObject bot)
        {
            var currentEffect = new ActiveEffect
            {
                Bot    = bot,
                Effect = Effects.AsteroidField
            };

            /* If the effect is not registered, add it to the list. */
            if (worldStateService.GetActiveEffectByType(bot.Id, Effects.AsteroidField) == default)
            {
                worldStateService.AddActiveEffect(currentEffect);
                worldStateService.UpdateBotSpeed(bot);
            }

            return(true);
        }
コード例 #15
0
ファイル: Day10.cs プロジェクト: herromega/AdventOfCode
        public static void addValuesToBots(string[] instructions)
        {
            foreach (string instruction in instructions)
            {
                if (instruction.StartsWith("value"))
                {
                    string[] botData = instruction.Split(' ');

                    int value = int.Parse(botData[1]);
                    int botId = int.Parse(botData[5]);

                    BotObject tmpBot = bots.First(bot => bot.id == botId);

                    tmpBot.valueCollection.Add(value);
                }
            }
        }
コード例 #16
0
        public void GivenBot_WithMovement_AndAfterburnerStarted_ThenStopAfterburnerAndNormalSpeedCorrect()
        {
            SetupFakeWorld(true, false);
            var bot = new BotObject
            {
                Id             = Guid.NewGuid(),
                Size           = 60,
                Position       = new Position(0, 0),
                Speed          = 4,
                GameObjectType = GameObjectType.Player
            };

            WorldStateService.AddBotObject(bot);

            var firstAction  = FakeGameObjectProvider.GetForwardPlayerAction(bot.Id);
            var secondAction = FakeGameObjectProvider.GetStartAfterburnerPlayerAction(bot.Id);
            var thirdAction  = FakeGameObjectProvider.GetForwardPlayerAction(bot.Id);

            bot.PendingActions = new List <PlayerAction>
            {
                firstAction,
                secondAction,
                thirdAction
            };

            Assert.DoesNotThrow(() => engineService.SimulateTickForBots(WorldStateService.GetPlayerBots()));;
            Assert.DoesNotThrow(() => WorldStateService.ApplyAfterTickStateChanges());
            Assert.DoesNotThrow(() => engineService.SimulateTickForBots(WorldStateService.GetPlayerBots()));;
            Assert.DoesNotThrow(() => WorldStateService.ApplyAfterTickStateChanges());

            var activeEffect = WorldStateService.GetActiveEffectByType(bot.Id, Effects.Afterburner);

            Assert.AreEqual(59, bot.Size);
            Assert.AreEqual(8, bot.Speed);
            Assert.AreEqual(0, bot.Position.Y);
            Assert.AreEqual(12, bot.Position.X);

            Assert.DoesNotThrow(() => engineService.SimulateTickForBots(WorldStateService.GetPlayerBots()));
            Assert.DoesNotThrow(() => WorldStateService.ApplyAfterTickStateChanges());

            Assert.AreEqual(58, bot.Size);
            Assert.AreEqual(8, bot.Speed);
            Assert.AreEqual(0, bot.Position.Y);
            Assert.AreEqual(20, bot.Position.X);
        }
コード例 #17
0
        public string GetStartAttackMessage(PlayerCharacterObject player, NebulaObject enemy)
        {
            MmoWorld        world          = player.nebulaObject.mmoWorld();
            RaceableObject  playerRaceable = player.GetComponent <RaceableObject>();
            CharacterObject enemyCharacter = enemy.GetComponent <CharacterObject>();
            BotObject       botObject      = enemy.GetComponent <BotObject>();

            string systemName = world.Resource().Zones.GetZoneName(world.Name);
            string playerName = player.characterName;
            //string playerRaceName = world.Resource().Zones.GetRaceName(playerRaceable.getRace());
            string npcName  = GenerateStandardNpcName(systemName, enemy.Id);
            int    npcLevel = enemyCharacter.level;

            string coalitionName = player.guildName;

            if (coalitionName == null)
            {
                coalitionName = string.Empty;
            }


            switch (botObject.getSubType())
            {
            case BotItemSubType.Drill:
                return(string.Format("scm4:zone={0};chname={1};chrace={2};chcoal={3};enname={4};enlvl={5}",
                                     world.Name, playerName,
                                     playerRaceable.race, coalitionName,
                                     npcName, npcLevel));

            case BotItemSubType.Outpost:
                return(string.Format("scm5:zone={0};chname={1};chrace={2};chcoal={3};enname={4};enlvl={5}",
                                     world.Name, playerName,
                                     playerRaceable.race, coalitionName,
                                     npcName, npcLevel));

            case BotItemSubType.MainOutpost:
                return(string.Format("scm6:zone={0};chname={1};chrace={2};chcoal={3};enname={4};enlvl={5}",
                                     world.Name, playerName,
                                     playerRaceable.race, coalitionName,
                                     npcName, npcLevel));

            default:
                return(string.Empty);
            }
        }
コード例 #18
0
        public void ProcessAction(BotObject bot)
        {
            var torpedoSalvo = new TorpedoGameObject()
            {
                Id       = Guid.NewGuid(),
                Position = vectorCalculatorService.GetPositionFrom(bot.Position, bot.Size + engineConfig.Torpedo.Size + 1, bot.CurrentAction
                                                                   .Heading),
                Size           = engineConfig.Torpedo.Size,
                Speed          = engineConfig.Torpedo.Speed,
                CurrentHeading = bot.CurrentAction.Heading,
                FiringPlayerId = bot.Id
            };

            bot.Size -= engineConfig.Torpedo.Cost;
            worldStateService.UpdateBotSpeed(bot);

            worldStateService.AddGameObject(torpedoSalvo);
        }
コード例 #19
0
ファイル: ActionService.cs プロジェクト: juan-db/2021-Galaxio
        public void ApplyActionToBot(BotObject bot)
        {
            if (bot.PendingActions != null &&
                bot.PendingActions.Count > 0)
            {
                bot.CurrentAction = bot.PendingActions[0];
                bot.PendingActions.RemoveAt(0);
            }

            if (bot.CurrentAction == default)
            {
                return;
            }

            IActionHandler handler = actionHandlerResolver.ResolveHandler(bot.CurrentAction);

            handler.ProcessAction(bot);
            bot.LastAction = bot.CurrentAction;
        }
コード例 #20
0
        public void GivenBot_WithAfterburnerStarted_ThenStopAfterburnerAndNormalSpeedCorrect()
        {
            SetupFakeWorld(true, false);
            var food = FakeGameObjectProvider.GetFoodAt(new Position(60, 0));
            var id   = Guid.NewGuid();
            var bot  = new BotObject
            {
                Id             = id,
                Size           = 60,
                Position       = new Position(0, 0),
                Speed          = 4,
                GameObjectType = GameObjectType.Player,
                PendingActions = new List <PlayerAction>(),
                CurrentAction  = new PlayerAction
                {
                    Action   = PlayerActions.Stop,
                    Heading  = 0,
                    PlayerId = id
                },
                Score = 0
            };

            WorldStateService.AddBotObject(bot);

            var firstAction  = FakeGameObjectProvider.GetStartAfterburnerPlayerAction(bot.Id);
            var secondAction = FakeGameObjectProvider.GetForwardPlayerAction(bot.Id);

            bot.PendingActions = new List <PlayerAction>
            {
                firstAction,
                secondAction
            };

            Assert.DoesNotThrow(() => engineService.SimulateTickForBots(WorldStateService.GetPlayerBots()));;
            Assert.DoesNotThrow(() => WorldStateService.ApplyAfterTickStateChanges());
            Assert.DoesNotThrow(() => engineService.SimulateTickForBots(WorldStateService.GetPlayerBots()));;
            Assert.DoesNotThrow(() => WorldStateService.ApplyAfterTickStateChanges());

            Assert.AreEqual(59, bot.Size);
            Assert.AreEqual(8, bot.Speed);
            Assert.AreEqual(0, bot.Position.Y);
            Assert.AreEqual(8, bot.Position.X);
        }
コード例 #21
0
        public BotObject GetBigBotAt(Position position)
        {
            var id  = Guid.NewGuid();
            var bot = new BotObject
            {
                Id             = id,
                Size           = 20,
                Position       = position,
                Speed          = 10,
                GameObjectType = GameObjectType.Player,
                CurrentAction  = new PlayerAction
                {
                    Action   = PlayerActions.Stop,
                    Heading  = 0,
                    PlayerId = id
                }
            };

            worldStateService.AddBotObject(bot);
            return(bot);
        }
コード例 #22
0
ファイル: Day10.cs プロジェクト: herromega/AdventOfCode
        public static void runBotTransactions()
        {
            bool allTransactionsDone = false;

            while (!allTransactionsDone)
            {
                if (bots.Count(b => b.valueCollection.Count == 2) == bots.Count)
                {
                    allTransactionsDone = true;
                }

                botsWithTwoValues = bots.Where(b => b.valueCollection.Count == 2).ToList();

                foreach (BotObject bot in botsWithTwoValues)
                {
                    if (bot.valueCollection.Count == 2)
                    {
                        if (!bot.outputLow)
                        {
                            BotObject receiverBot = bots.First(b => b.id == bot.lowValueToId);

                            if (receiverBot.valueCollection.Count < 2)
                            {
                                receiverBot.valueCollection.Add(bot.valueCollection.Min());
                            }
                        }

                        if (!bot.outputHigh)
                        {
                            BotObject receiverBot = bots.First(b => b.id == bot.highValueToId);

                            if (receiverBot.valueCollection.Count < 2)
                            {
                                receiverBot.valueCollection.Add(bot.valueCollection.Max());
                            }
                        }
                    }
                }
            }
        }
コード例 #23
0
        public void ProcessAction(BotObject bot)
        {
            /* Bot does not have enough resources to consume for the afterburner. */
            if (bot.Size <= engineConfig.Afterburners.SizeConsumptionPerTick ||
                bot.Size <= engineConfig.MinimumPlayerSize)
            {
                return;
            }

            var currentEffect = new ActiveEffect
            {
                Bot    = bot,
                Effect = Effects.Afterburner
            };

            /* If the effect is not registered, add speed boost and add it to the list. */
            if (worldStateService.GetActiveEffectByType(bot.Id, Effects.Afterburner) == default)
            {
                worldStateService.AddActiveEffect(currentEffect);
                worldStateService.UpdateBotSpeed(bot);
            }
        }
コード例 #24
0
 public bool IsApplicable(GameObject gameObject, BotObject bot) => gameObject.GameObjectType == GameObjectType.GasCloud;
コード例 #25
0
 public void ProcessAction(BotObject bot)
 {
     // no-op
 }
コード例 #26
0
 public bool IsApplicable(GameObject gameObject, BotObject bot) => gameObject.GameObjectType == GameObjectType.AsteroidField;
コード例 #27
0
 public bool IsApplicable(GameObject gameObject, BotObject bot) => gameObject.GameObjectType == GameObjectType.Wormhole;
コード例 #28
0
 public void ProcessAction(BotObject bot)
 {
     bot.CurrentHeading = bot.CurrentAction.Heading;
     bot.IsMoving       = true;
 }
コード例 #29
0
 public void AddBotObject(BotObject bot)
 {
     state.PlayerGameObjects.Add(bot);
 }
コード例 #30
0
 public void ProcessAction(BotObject bot)
 {
     bot.IsMoving = false;
 }