private float GetChickenFallSpeed(ChickenType chickenType) { switch (chickenType) { case ChickenType.LARGE: return(LargeChicken.FallSpeed); case ChickenType.MEDIUM: return(MediumChicken.FallSpeed); case ChickenType.SMALL: return(SmallChicken.FallSpeed); } return(0f); }
private SoundEffect GetChickenHitSfx(ChickenType chickenType) { switch (chickenType) { case ChickenType.LARGE: return(Assets.SfxHitLargeChicken); case ChickenType.MEDIUM: return(Assets.SfxHitMediumChicken); case ChickenType.SMALL: return(Assets.SfxHitSmallChicken); } return(null); }
private async Task TryBuyInternalAsync(CommandContext ctx, ChickenType type, string name) { if (string.IsNullOrWhiteSpace(name)) { throw new InvalidCommandUsageException("Name for your chicken is missing."); } if (name.Length < 2 || name.Length > 30) { throw new InvalidCommandUsageException("Name cannot be shorter than 2 and longer than 30 characters."); } if (!name.All(c => char.IsLetterOrDigit(c) || char.IsWhiteSpace(c))) { throw new InvalidCommandUsageException("Name cannot contain characters that are not letters or digits."); } if (!(Chicken.FromDatabase(this.Database, ctx.Guild.Id, ctx.User.Id) is null)) { throw new CommandFailedException("You already own a chicken!"); } if (!await ctx.WaitForBoolReplyAsync($"{ctx.User.Mention}, are you sure you want to buy a chicken for {Formatter.Bold(Chicken.Price(type).ToString())} {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}?")) { return; } using (DatabaseContext db = this.Database.CreateContext()) { if (!await db.TryDecreaseBankAccountAsync(ctx.User.Id, ctx.Guild.Id, Chicken.Price(type))) { throw new CommandFailedException($"You do not have enough {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"} to buy a chicken ({Chicken.Price(type)} needed)!"); } ChickenStats stats = Chicken.StartingStats[type]; db.Chickens.Add(new DatabaseChicken { GuildId = ctx.Guild.Id, MaxVitality = stats.BareMaxVitality, Name = name, Strength = stats.BareStrength, UserId = ctx.User.Id, Vitality = stats.BareVitality }); await db.SaveChangesAsync(); } await this.InformAsync(ctx, StaticDiscordEmoji.Chicken, $"{ctx.User.Mention} bought a chicken named {Formatter.Bold(name)}"); }
public void HatchEgg_Ok(double[] wormWeights, ChickenType chieckenType, int epxectedEggCount) { var chic = _hatchery.Create(chieckenType); var worms = new List <Worm>(); foreach (var weight in wormWeights) { var worm = new Worm(weight); worms.Add(worm); } var eggs = chic.LayEggs(worms); eggs.Should().NotContainNulls() .And.HaveCount(epxectedEggCount); }
private async Task TryBuyInternalAsync(CommandContext ctx, ChickenType type, string name) { if (string.IsNullOrWhiteSpace(name)) { throw new InvalidCommandUsageException(ctx, "cmd-err-missing-name"); } if (name.Length > Chicken.NameLimit) { throw new InvalidCommandUsageException(ctx, "cmd-err-name", Chicken.NameLimit); } if (!name.All(c => char.IsLetterOrDigit(c) || char.IsWhiteSpace(c))) { throw new InvalidCommandUsageException(ctx, "cmd-err-name-alnum"); } if (await this.Service.ContainsAsync(ctx.Guild.Id, ctx.User.Id)) { throw new CommandFailedException(ctx, "cmd-err-chicken-dup"); } CachedGuildConfig gcfg = ctx.Services.GetRequiredService <GuildConfigService>().GetCachedConfig(ctx.Guild.Id); long price = Chicken.Price(type); if (!await ctx.WaitForBoolReplyAsync("q-chicken-buy", args: new object[] { ctx.User.Mention, price, gcfg.Currency })) { return; } if (!await ctx.Services.GetRequiredService <BankAccountService>().TryDecreaseBankAccountAsync(ctx.Guild.Id, ctx.User.Id, price)) { throw new CommandFailedException(ctx, "cmd-err-funds", gcfg.Currency, price); } await this.Service.AddAsync(new Chicken(type) { GuildId = ctx.Guild.Id, Name = name, UserId = ctx.User.Id, }); await ctx.ImpInfoAsync(this.ModuleColor, Emojis.Chicken, "fmt-chicken-buy", ctx.User.Mention, type.Humanize(LetterCasing.LowerCase), name); }
public Chicken Create(ChickenType chickenType) { var energyNeededPerEgg = 0; switch (chickenType) { case ChickenType.Lazy: energyNeededPerEgg = 10; break; case ChickenType.Productive: energyNeededPerEgg = 1; break; default: throw new NotImplementedException("No chicken of the type provided"); } return(new Chicken(energyNeededPerEgg)); }
public Entity CreateChicken(ChickenType chickenType) { var spriteSheet = _chickenSpriteSheets[chickenType]; var entity = _world.CreateEntity(); entity.AttachComponent(new Transform2D()); entity.AttachComponent(new RigidBody2D()); entity.AttachComponent(new ChickenComponent() { ChickenType = chickenType }); entity.AttachComponent(new AnimatedSprite(spriteSheet)); entity.AttachComponent(new RenderFormComponent() { Name = "Chicken" }); return(entity); }
private async Task TryBuyInternalAsync(CommandContext ctx, ChickenType type, string name) { if (string.IsNullOrWhiteSpace(name)) { throw new InvalidCommandUsageException("Name for your chicken is missing."); } if (name.Length < 2 || name.Length > 30) { throw new InvalidCommandUsageException("Name cannot be shorter than 2 and longer than 30 characters."); } if (!name.All(c => Char.IsLetterOrDigit(c) || Char.IsWhiteSpace(c))) { throw new InvalidCommandUsageException("Name cannot contain characters that are not letters or digits."); } if (await this.Database.GetChickenAsync(ctx.User.Id, ctx.Guild.Id) != null) { throw new CommandFailedException("You already own a chicken!"); } if (!await ctx.WaitForBoolReplyAsync($"{ctx.User.Mention}, are you sure you want to buy a chicken for {Formatter.Bold(Chicken.Price(type).ToString())} {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}?")) { return; } if (!await this.Database.DecreaseBankAccountBalanceAsync(ctx.User.Id, ctx.Guild.Id, Chicken.Price(type))) { throw new CommandFailedException($"You do not have enough {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"} to buy a chicken ({Chicken.Price(type)} needed)!"); } await this.Database.AddChickenAsync(ctx.User.Id, ctx.Guild.Id, name, Chicken.StartingStats[type]); await this.InformAsync(ctx, StaticDiscordEmoji.Chicken, $"{ctx.User.Mention} bought a chicken named {Formatter.Bold(name)}"); }
public static long Price(ChickenType type) => PriceForAttribute(StartingStats[type].BareStrength);
public int GetChickenTypeCnt(ChickenType chickenType) { return(ActiveEntities .Where(id => _chickenInfoMapper.Get(id).ChickenType.Equals(chickenType)) .Count()); }
private Entity SpawnChicken(ChickenType chickenType) { var chicken = _entityFactory.CreateChicken(chickenType); var transform = chicken.GetComponent <Transform2D>(); var rigidbody = chicken.GetComponent <RigidBody2D>(); var animatedSprite = chicken.GetComponent <AnimatedSprite>(); Vector2 size = Vector2.Zero; float depth = 0f; float speed = 0f; ChickenSpawnBounds spawning = null; float posY; float posX; SpriteEffects effects; Vector2 velocity; switch (chickenType) { case ChickenType.LARGE: { size = new Vector2(LargeChicken.Width, LargeChicken.Height); speed = LargeChicken.Speed; depth = LargeChicken.Depth; spawning = _largeChickenSpawning; break; } case ChickenType.MEDIUM: { size = new Vector2(MediumChicken.Width, MediumChicken.Height); speed = MediumChicken.Speed; depth = MediumChicken.Depth; spawning = _mediumChickenSpawning; break; } case ChickenType.SMALL: { size = new Vector2(SmallChicken.Width, SmallChicken.Height); speed = SmallChicken.Speed; depth = SmallChicken.Depth; spawning = _smallChickenSpawning; break; } } transform.Size = size; animatedSprite.Depth = depth; animatedSprite.Play("fly"); // Random Y Position posY = _r.Next(spawning.MinY, spawning.MaxY + 1); // Random Direction if (GetRandomChickenFlyDirection() == ChickenFlyDirection.LEFT) { //LEFT posX = _mapInfo.Right; effects = SpriteEffects.None; velocity = Transform2D.Left; } else { // RIGHT posX = _mapInfo.Left - transform.Bounds.Width; effects = SpriteEffects.FlipHorizontally; velocity = Transform2D.Right; } transform.Position = new Vector2(posX, posY); animatedSprite.Effects = effects; rigidbody.Velocity = velocity * speed; return(chicken); }