diff --git a/src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx b/src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx index 7847f439..f7a6792f 100644 --- a/src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx +++ b/src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx @@ -1,7 +1,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { FC } from 'react'; -import { AvatarInfoPet, LocalizeText } from '../../../../../api'; -import { Base, Column, Flex, LayoutPetImageView, Text, UserProfileIconView } from '../../../../../common'; +import { PetRespectComposer, PetType } from '@nitrots/nitro-renderer'; +import { FC, useEffect, useState } from 'react'; +import { AvatarInfoPet, ConvertSeconds, CreateLinkEvent, GetConfiguration, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../../../api'; +import { Base, Button, Column, Flex, LayoutCounterTimeView, LayoutPetImageView, LayoutRarityLevelView, Text, UserProfileIconView } from '../../../../../common'; +import { usePets, useRoom } from '../../../../../hooks'; interface InfoStandWidgetPetViewProps { @@ -12,72 +14,285 @@ interface InfoStandWidgetPetViewProps export const InfoStandWidgetPetView: FC = props => { const { avatarInfo = null, onClose = null } = props; + const { roomSession = null } = useRoom(); + const { petRespect, changePetRespect } = usePets(); + const [ remainingGrowTime, setRemainingGrowTime ] = useState(0); + const [ remainingTimeToLive, setRemainingTimeToLive ] = useState(0); if(!avatarInfo) return null; - return ( - - - - - { avatarInfo.name } - - - { LocalizeText(`pet.breed.${ avatarInfo.petType }.${ avatarInfo.petBreed }`) } -
-
- - - - + useEffect(() => + { + changePetRespect(avatarInfo.respectsPetLeft); + setRemainingGrowTime(avatarInfo.remainingGrowTime); + setRemainingTimeToLive(avatarInfo.remainingTimeToLive); + + }, [ avatarInfo ]); + + const processButtonAction = (action: string) => + { + let hideMenu = true; + + if (!action || action == '') return; + + switch (action) + { + case 'respect': + let newRespectsLeftChange = 0; + + changePetRespect(prevValue => + { + newRespectsLeftChange = (prevValue - 1); + + return newRespectsLeftChange; + }); + + GetSessionDataManager().givePetRespect(avatarInfo.id); + if(newRespectsLeftChange > 0) hideMenu = false; + break; + case 'buyfood': + CreateLinkEvent('catalog/open/' + GetConfiguration('catalog.links')['pets.buy_saddle']); + break; + case 'train': + // not coded + break; + case 'treat': + SendMessageComposer(new PetRespectComposer(avatarInfo.id)); + break; + case 'compost': + roomSession?.compostPlant(avatarInfo.id); + break; + case 'pick_up': + roomSession?.pickupPet(avatarInfo.id); + break; + } + + if(hideMenu) onClose(); + } + + useEffect(() => + { + changePetRespect(avatarInfo.respectsPetLeft); + setRemainingGrowTime(avatarInfo.remainingGrowTime); + setRemainingTimeToLive(avatarInfo.remainingTimeToLive); + + }, [ avatarInfo ]); + + useEffect(() => + { + if (avatarInfo.petType === PetType.MONSTERPLANT && !avatarInfo.dead) + { + const interval = setInterval(() => + { + let newRemaingGrowTime = 0; + let newRemaingLiveTime = 0; + + setRemainingGrowTime(prevValue => + { + newRemaingGrowTime = (prevValue - 1); + + return newRemaingGrowTime; + }); + + setRemainingTimeToLive(prevValue => + { + newRemaingLiveTime = (prevValue - 1); + + return newRemaingLiveTime; + }); + + }, 1000); + + return () => clearInterval(interval); + } + + }, [ avatarInfo ]); + + const InfoStandNormalPet = () => + { + return ( + + + + + + { avatarInfo.name } + + + { LocalizeText(`pet.breed.${ avatarInfo.petType }.${ avatarInfo.petBreed }`) } +
- - { LocalizeText('pet.level', [ 'level', 'maxlevel' ], [ avatarInfo.level.toString(), avatarInfo.maximumLevel.toString() ]) } - - { LocalizeText('infostand.pet.text.happiness') } - - - { avatarInfo.happyness + '/' + avatarInfo.maximumHappyness } - - - - - - { LocalizeText('infostand.pet.text.experience') } - - - { avatarInfo.experience + '/' + avatarInfo.levelExperienceGoal } - - - - - - { LocalizeText('infostand.pet.text.energy') } - - - { avatarInfo.energy + '/' + avatarInfo.maximumEnergy } - - - - + + + + + + + { LocalizeText('pet.level', [ 'level', 'maxlevel' ], [ avatarInfo.level.toString(), avatarInfo.maximumLevel.toString() ]) } + + { LocalizeText('infostand.pet.text.happiness') } + + + { avatarInfo.happyness + '/' + avatarInfo.maximumHappyness } + + + + + + { LocalizeText('infostand.pet.text.experience') } + + + { avatarInfo.experience + '/' + avatarInfo.levelExperienceGoal } + + + + + + { LocalizeText('infostand.pet.text.energy') } + + + { avatarInfo.energy + '/' + avatarInfo.maximumEnergy } + + + + + + +
-
-
-
- - { LocalizeText('infostand.text.petrespect', [ 'count' ], [ avatarInfo.respect.toString() ]) } - { LocalizeText('pet.age', [ 'age' ], [ avatarInfo.age.toString() ]) } -
-
- - - - - { LocalizeText('infostand.text.petowner', [ 'name' ], [ avatarInfo.ownerName ]) } - - + + { LocalizeText('pet.age', [ 'age' ], [ avatarInfo.age.toString() ]) } +
+
+ + + + + { LocalizeText('infostand.text.petowner', [ 'name' ], [ avatarInfo.ownerName ]) } + + + +
+ + + { avatarInfo.isOwner && + + } + { avatarInfo.isOwner && + + } + { (petRespect > 0) && + + } +
- + ); + } + + const InfoStandMonsterplantPet = () => + { + return ( + + + + + + { avatarInfo.name } + + + { LocalizeText(`pet.breed.${ avatarInfo.petType }.${ avatarInfo.petBreed }`) } +
+
+ + + + + + { !avatarInfo.dead && + + { LocalizeText('pet.level', [ 'level', 'maxlevel' ], [ avatarInfo.level.toString(), avatarInfo.maximumLevel.toString() ]) } + + } + +
+
+

+ + + { LocalizeText('infostand.pet.text.wellbeing') } + + + { avatarInfo.dead ? '00:00:00' : ConvertSeconds((remainingTimeToLive == 0 ? avatarInfo.remainingTimeToLive : remainingTimeToLive)).split(':')[1] + ':' + ConvertSeconds((remainingTimeToLive == null || remainingTimeToLive == undefined ? 0 : remainingTimeToLive)).split(':')[2] + ':' + ConvertSeconds((remainingTimeToLive == null || remainingTimeToLive == undefined ? 0 : remainingTimeToLive)).split(':')[3] } + + + + +

+

+ { remainingGrowTime != 0 && remainingGrowTime > 0 && + + { LocalizeText('infostand.pet.text.growth') }
+ +
+ } +

+

+ + { LocalizeText('Nivel de rareza:') } + + +

+ { LocalizeText('pet.age', [ 'age' ], [ avatarInfo.age.toString() ]) } +
+
+ + + + + { LocalizeText('infostand.text.petowner', [ 'name' ], [ avatarInfo.ownerName ]) } + + + +
+
+ + { !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) && + + } + { roomSession?.isRoomOwner && + + } + { avatarInfo.isOwner && + + } + +
+ ); + } + + return ( + <> + { avatarInfo.petType !== PetType.MONSTERPLANT && + + } + { avatarInfo.petType === PetType.MONSTERPLANT && + + } + ); }