Пример #1
0
        public override bool CanProcessTurn(GameContext context, Hero hero)
        {
            var targetItem = context.Items.Where(i => i.IsPotion && i.Health > 0).OrderByDescending(i => i.Health).FirstOrDefault(i => context.MyGold >= i.Cost);

            if (targetItem != null &&
                hero.ItemsOwned < Constants.MaxItemCountPerHero &&
                hero.Health <= hero.MaxHealth * 0.4)
            {
                context.Buy(targetItem.Name);
                context.MyGold -= targetItem.Cost;
                return(true);
            }

            return(false);
        }
Пример #2
0
        public override bool CanProcessTurn(GameContext context, Hero hero)
        {
            var targetItem = context.Items.Where(i => !i.IsPotion).OrderByDescending(i => i.Damage).FirstOrDefault(i => context.MyGold >= i.Cost);

            if (targetItem != null)
            {
                if (hero.ItemsOwned < Constants.MaxItemCountPerHero - 1)
                {
                    if (context.MyItems.ContainsKey(hero.UnitId))
                    {
                        context.MyItems[hero.UnitId].Add(targetItem);
                    }
                    else
                    {
                        context.MyItems.Add(hero.UnitId, new List <Item>()
                        {
                            targetItem
                        });
                    }
                    context.MyGold -= targetItem.Cost;
                    context.Buy(targetItem.Name);
                    return(true);
                }
                else if (context.MyItems.Count > 0 &&
                         !context.MyItems[hero.UnitId].Any(x => x.Name == targetItem.Name || x.Cost > targetItem.Cost))
                {
                    var sellItem = context.MyItems[hero.UnitId].OrderBy(i => i.Cost).FirstOrDefault();
                    context.Sell(sellItem.Name);
                    context.MyItems[hero.UnitId].Remove(sellItem);
                    context.MyGold += sellItem.Cost / 2;
                    return(true);
                }
            }

            return(false);
        }