Пример #1
0
 /**
  * @param BuildingRepair $buildingRepair
  * @param int $time
  */
 public function repair(BuildingRepair $buildingRepair, $time = 60)
 {
     $building = $buildingRepair->getBuilding();
     $currentCondition = $building->getCurrentCondition();
     $startedCondition = $buildingRepair->getStartedCondition();
     $type = $buildingRepair->getType();
     $timeConstant = $this->buildingRepairPrice->getTimeConstant($type);
     $updateTimes = $timeConstant * (100 - $startedCondition) / $time;
     $step = (100 - $startedCondition) / $updateTimes;
     $building->setCurrentCondition($currentCondition + $step);
     $this->buildingRepository->update();
 }
 function it_can_start_repairing_building(GamerHasEnoughCash $gamerHasEnoughCash, Building $building, Gamer $gamer, BuildingRepairRepository $buildingRepairRepository, BuildingRepairPrice $buildingRepairPrice, ReduceCash $reduceCash, EventDispatcher $eventDispatcher, BuildingRepository $buildingRepository)
 {
     $amount = 3600;
     $type = BuildingRepair::TYPE_FAST_ID;
     $buildingRepairPrice->countPrice($building, $type)->willReturn($amount);
     $building->getGamer()->willReturn($gamer);
     $gamerHasEnoughCash->isSatisfiedBy($gamer, $amount)->willReturn(true);
     $buildingRepairRepository->countActiveBuildings($building)->willReturn(0);
     $buildingRepairPrice->getTimeConstant($type)->willReturn(0.8);
     $building->getCurrentCondition()->willReturn(50);
     $building->setStatus(Building::INACTIVE)->shouldBeCalled();
     $buildingRepository->update()->shouldBeCalled();
     $buildingRepairRepository->save(Argument::type('Mm\\AppBundle\\Entity\\BuildingRepair'))->shouldBeCalled();
     $reduceCash->reduce($gamer, $amount)->shouldBeCalled();
     $eventDispatcher->dispatch(BuildingRepairStarted::NAME, Argument::type('Mm\\Model\\Event\\BuildingRepairStarted'))->shouldBeCalled();
     $this->repair($building, $type);
 }
Пример #3
0
 function it_should_repair_building(BuildingRepository $buildingRepository, BuildingRepair $buildingRepair, Building $building, BuildingRepairPrice $buildingRepairPrice)
 {
     $time = 60;
     $type = BuildingRepair::TYPE_VERY_FAST_ID;
     $timeConstant = BuildingRepair::TYPE_VERY_FAST_TIME_CONSTANT;
     $startedCondition = 10;
     $currentCondition = 20;
     $buildingRepair->getBuilding()->willReturn($building);
     $building->getCurrentCondition()->willReturn($currentCondition);
     $buildingRepair->getType()->willReturn($type);
     $buildingRepair->getStartedCondition()->willReturn($startedCondition);
     $buildingRepairPrice->getTimeConstant($type)->willReturn($timeConstant);
     $updateTimes = BuildingRepair::TYPE_VERY_FAST_TIME_CONSTANT * (100 - $startedCondition) / $time;
     $step = (100 - $startedCondition) / $updateTimes;
     $building->setCurrentCondition($currentCondition + $step)->shouldBeCalled();
     $buildingRepository->update()->shouldBeCalled();
     $this->repair($buildingRepair, $time);
 }