예제 #1
0
        private IClassEquipment buyClassEquipment(BattlefieldRobot r, int classEquipmentId)
        {
            IClassEquipment classEquipment = null;

            {
                Tank tank = r as Tank;
                if (tank != null)
                {
                    classEquipment = tank.Gun;
                    if (gunsById.TryGetValue(classEquipmentId, out Gun wantedBuy) && !wantedBuy.Equals(classEquipment))
                    {
                        if (r.Gold >= wantedBuy.COST)
                        {
                            r.Gold  -= wantedBuy.COST;
                            tank.Gun = wantedBuy;
                        }
                    }
                }
            }

            {
                MineLayer mineLayer = r as MineLayer;
                if (mineLayer != null)
                {
                    classEquipment = mineLayer.MineGun;
                    if (mineGunsById.TryGetValue(classEquipmentId, out MineGun wantedBuy) && !wantedBuy.Equals(classEquipment))
                    {
                        if (r.Gold >= wantedBuy.COST)
                        {
                            r.Gold           -= wantedBuy.COST;
                            mineLayer.MineGun = wantedBuy;
                        }
                    }
                }
            }

            {
                Repairman repairman = r as Repairman;
                if (repairman != null)
                {
                    classEquipment = repairman.RepairTool;
                    if (repairToolsById.TryGetValue(classEquipmentId, out RepairTool wantedBuy) && !wantedBuy.Equals(classEquipment))
                    {
                        if (r.Gold >= wantedBuy.COST)
                        {
                            r.Gold -= wantedBuy.COST;
                            repairman.RepairTool = wantedBuy;
                        }
                    }
                }
            }
            return(classEquipment);
        }
예제 #2
0
        /// <summary>
        /// It buy and repair hit-points for robot r. Robot can only buy equipment witch is cheaper then robot gold.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="motorId"></param>
        /// <param name="armorId"></param>
        /// <param name="classEquipmentID"></param>
        /// <param name="hp"></param>
        /// <returns></returns>
        public MerchantAnswerCommand Buy(BattlefieldRobot r, int motorId, int armorId, int classEquipmentID, int hp)
        {
            repairHp(r, r.Armor.MAX_HP / 10);


            {
                if (armorsById.TryGetValue(classEquipmentID, out Armor wantedBuy) && !wantedBuy.Equals(r.Armor))
                {
                    if (r.Gold >= wantedBuy.COST)
                    {
                        r.Gold -= wantedBuy.COST;
                        r.Armor = wantedBuy;
                        repairHp(r, r.Armor.MAX_HP);
                    }
                }
            }

            if (hp - r.HitPoints > 0)
            {
                int possibleToRepairHP = Math.Min(hp - r.HitPoints, r.Gold * 4);
                r.Gold -= (possibleToRepairHP + 3) / 4;
                repairHp(r, possibleToRepairHP);
            }

            {
                if (motorsById.TryGetValue(motorId, out Motor wantedBuy) && !wantedBuy.Equals(r.Motor))
                {
                    if (r.Gold >= wantedBuy.COST)
                    {
                        r.Gold -= wantedBuy.COST;
                        r.Motor = wantedBuy;
                    }
                }
            }

            IClassEquipment classEquipment = buyClassEquipment(r, classEquipmentID);

            return(new MerchantAnswerCommand(r.Motor.ID, r.Armor.ID, classEquipment.ID));
        }
예제 #3
0
 private static void repairHp(BattlefieldRobot r, int hp)
 {
     r.HitPoints += hp;
     r.HitPoints  = Math.Min(r.HitPoints, r.Armor.MAX_HP);
 }