PetDataDto.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Module\AppGame\Proto;
  3. use Uraus\Kku\Common\DataPet;
  4. use Uraus\Kku\Common\PetLifeSkill;
  5. /**
  6. * 宠物数据DTO转换为Protobuf数据对象
  7. */
  8. class PetDataDto
  9. {
  10. /**
  11. * 将Pet模块的PetDataDto转换为Protobuf的DataPet对象
  12. *
  13. * @param \App\Module\Pet\Dtos\PetDataDto $petDataDto
  14. * @return DataPet
  15. */
  16. public static function toDataPet(\App\Module\Pet\Dtos\PetDataDto $petDataDto): DataPet
  17. {
  18. $dataPet = new DataPet();
  19. // 设置基本宠物信息
  20. $dataPet->setId($petDataDto->id);
  21. $dataPet->setTypeId($petDataDto->typeId);
  22. $dataPet->setName($petDataDto->name);
  23. $dataPet->setLevel($petDataDto->level);
  24. $dataPet->setExp($petDataDto->exp);
  25. $dataPet->setPower($petDataDto->power);
  26. $dataPet->setMaxpower($petDataDto->maxpower);
  27. $dataPet->setScore($petDataDto->score);
  28. // $dataPet->setFightingCapacity($petDataDto->fightingCapacity);// 暂不处理
  29. // $dataPet->setGrade($petDataDto->grade); // 暂不处理
  30. // $dataPet->setStatus($petDataDto->status);// 暂不处理
  31. // 设置生活技能
  32. if (!empty($petDataDto->lifeSkills)) {
  33. $lifeSkills = [];
  34. foreach ($petDataDto->lifeSkills as $skill) {
  35. $petLifeSkill = new PetLifeSkill();
  36. $petLifeSkill->setSkillId($skill->skillId ?? 0);
  37. // $petLifeSkill->setCanuse($skill->canuse ?? false); // 不再处理
  38. $petLifeSkill->setCurnum($skill->curnum ?? 0);
  39. $petLifeSkill->setMaxnum($skill->maxnum ?? 0);
  40. $petLifeSkill->setEndTimes($skill->end_times ?? 0);
  41. $lifeSkills[] = $petLifeSkill;
  42. }
  43. $dataPet->setLifeSkills($lifeSkills);
  44. }
  45. return $dataPet;
  46. }
  47. }