| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Module\AppGame\Proto;
- use Uraus\Kku\Common\DataPet;
- use Uraus\Kku\Common\PetLifeSkill;
- /**
- * 宠物数据DTO转换为Protobuf数据对象
- */
- class PetDataDto
- {
- /**
- * 将Pet模块的PetDataDto转换为Protobuf的DataPet对象
- *
- * @param \App\Module\Pet\Dtos\PetDataDto $petDataDto
- * @return DataPet
- */
- public static function toDataPet(\App\Module\Pet\Dtos\PetDataDto $petDataDto): DataPet
- {
- $dataPet = new DataPet();
-
- // 设置基本宠物信息
- $dataPet->setId($petDataDto->id);
- $dataPet->setTypeId($petDataDto->typeId);
- $dataPet->setName($petDataDto->name);
- $dataPet->setLevel($petDataDto->level);
- $dataPet->setExp($petDataDto->exp);
- $dataPet->setPower($petDataDto->power);
- $dataPet->setMaxpower($petDataDto->maxpower);
- $dataPet->setScore($petDataDto->score);
- $dataPet->setFightingCapacity($petDataDto->fightingCapacity);
- $dataPet->setGrade($petDataDto->grade);
- $dataPet->setStatus($petDataDto->status);
-
- // 设置生活技能
- if (!empty($petDataDto->lifeSkills)) {
- $lifeSkills = [];
- foreach ($petDataDto->lifeSkills as $skill) {
- $petLifeSkill = new PetLifeSkill();
- $petLifeSkill->setPetId($petDataDto->id);
- $petLifeSkill->setSkillId($skill->skillId ?? 0);
- $petLifeSkill->setCanuse($skill->canUse ?? false);
- $petLifeSkill->setCurnum($skill->currentCooldown ?? 0);
- $petLifeSkill->setMaxnum($skill->maxCooldown ?? 0);
- $lifeSkills[] = $petLifeSkill;
- }
- $dataPet->setLifeSkills($lifeSkills);
- }
-
- return $dataPet;
- }
- }
|