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); }
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); }
public bool ResolveCollision(GameObject go, MovableGameObject mover) { // 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(mover.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 (mover.Size > engineConfig.WorldFood.MaxConsumptionSize) { return(true); } if (mover is BotObject botObject) { var superFoodEffect = worldStateService.GetActiveEffectByType(botObject.Id, Effects.Superfood); if (superFoodEffect != null && superFoodEffect.EffectDuration > 0) { botObject.Size += go.Size * (int)engineConfig.ConsumptionRatio[GameObjectType.Superfood]; } else { botObject.Size += go.Size; } go.Size = 0; botObject.Score += engineConfig.ScoreRates[GameObjectType.Food]; worldStateService.RemoveGameObjectById(go.Id); worldStateService.UpdateBotSpeed(mover); } else { var moverStartingSize = mover.Size; mover.Size -= go.Size; go.Size -= moverStartingSize; if (go.Size <= 0) { go.Size = 0; worldStateService.RemoveGameObjectById(go.Id); } if (mover.Size <= 0) { mover.Size = 0; worldStateService.RemoveGameObjectById(mover.Id); } return(mover.Size > 0); } return(true); }