1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "nel/misc/vectord.h"
30 #include "nel/misc/matrix.h"
31 #include "nel/misc/quat.h"
33 #include "nel/3d/u_scene.h"
34 #include "nel/3d/u_visual_collision_manager.h"
35 #include "nel/3d/viewport.h"
36 #include "nel/3d/u_bone.h"
37 #include "nel/3d/u_instance_material.h"
38 #include "nel/3d/u_play_list.h"
39 #include "nel/3d/u_point_light.h"
40 #include "nel/3d/u_particle_system_instance.h"
41 #include "nel/3d/u_camera.h"
43 #include "nel/pacs/u_global_position.h"
45 #include "user_entity.h"
46 #include "motion/user_controls.h"
47 #include "pacs_client.h"
48 #include "net_manager.h"
49 #include "time_client.h"
50 #include "entity_animation_manager.h"
51 #include "sheet_manager.h"
52 #include "sound_manager.h"
53 #include "interface_v3/interface_manager.h"
55 #include "debug_client.h"
57 #include "interface_v3/bot_chat_manager.h"
58 #include "fx_manager.h"
59 #include "main_loop.h"
60 #include "interface_v3/group_in_scene_bubble.h"
61 #include "interface_v3/inventory_manager.h"
62 #include "nel/gui/group_html.h"
63 #include "interface_v3/people_interraction.h"
64 #include "init_main_loop.h"
66 #include "interface_v3/sphrase_manager.h"
67 #include "interface_v3/sbrick_manager.h"
68 #include "interface_v3/action_phrase_faber.h"
69 #include "interface_v3/bar_manager.h"
70 #include "interface_v3/skill_manager.h"
74 #include "game_share/slot_types.h"
75 #include "game_share/player_visual_properties.h"
76 #include "game_share/mode_and_behaviour.h"
77 #include "game_share/inventories.h"
78 #include "game_share/animal_type.h"
79 #include "game_share/bot_chat_types.h"
81 #include "nel/sound/sound_anim_manager.h"
82 #include "nel/sound/sound_animation.h"
83 #include "nel/sound/sound_anim_marker.h"
85 #include "r2/editor.h"
94 using namespace NLMISC
;
95 using namespace NLPACS
;
98 using NL3D::UVisualCollisionManager
;
99 using NL3D::UTextContext
;
105 extern UScene
*Scene
;
106 extern UVisualCollisionManager
*CollisionManager
;
107 extern CEntityAnimationManager
*EAM
;
108 extern UTextContext
*TextContext
;
109 extern NL3D::UCamera MainCam
;
112 extern void contextHelp (const std::string
&help
);
114 extern void beastOrder (const std::string
&orderStr
, const std::string
&beastIndexStr
, bool confirmFree
= true);
116 // Out game received position
117 NLMISC::CVectorD UserEntityInitPos
;
118 NLMISC::CVector UserEntityInitFront
;
119 CUserEntity
*UserEntity
= NULL
;
121 uint32 CharFirstConnectedTime
= 0;
122 uint32 CharPlayedTime
= 0;
124 const double MaxExtractionDistance
= 1.0f
;
130 // Hierarchical timer
131 H_AUTO_DECL ( RZ_Client_Update_Sound
)
136 //string chooseRandom( const vector<string>& sounds, uint32& previousIndex );
138 //-----------------------------------------------
141 //-----------------------------------------------
142 CUserEntity::CUserEntity()
147 _RunWhenAble
= false;
148 _WalkVelocity
= 1.0f
;
150 _CurrentVelocity
= _WalkVelocity
;
152 _FrontVelocity
= 0.0f
;
153 _LateralVelocity
= 0.0f
;
155 _SpeedServerAdjust
= 1.0f
;
157 // \todo GUIGUI : do it more generic.
160 // No selection, trader, interlocutor at the beginning.
161 _Selection
= CLFECOMMON::INVALID_SLOT
;
162 _Trader
= CLFECOMMON::INVALID_SLOT
;
163 _Interlocutor
= CLFECOMMON::INVALID_SLOT
;
165 // Not selectable at the beginning.
168 // Your are not on a mount at the beginning.
170 _HiddenMount
= CLFECOMMON::INVALID_SLOT
;
172 _AnimAttackOn
= false;
175 _PermanentDeath
= false;
179 // The user is not in collision with someone else.
181 // Collisions are not removed.
184 // No Move To at the beginning.
185 _MoveToSlot
= CLFECOMMON::INVALID_SLOT
;
186 _MoveToAction
= CUserEntity::None
;
188 _MoveToColStartTime
= 0;
190 _FollowForceHeadPitch
= false;
192 _ForceLookSlot
= CLFECOMMON::INVALID_SLOT
;
193 _LastExecuteCombatSlot
= CLFECOMMON::INVALID_SLOT
;
195 _R2CharMode
= R2::TCharMode::Player
;
200 //-----------------------------------------------
203 //-----------------------------------------------
204 CUserEntity::~CUserEntity()
207 _SpeedFactor
.release();
208 _MountHunger
.release();
209 _MountSpeeds
.release();
211 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
214 CCDBNodeLeaf
*node
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:IS_INVISIBLE", false);
217 ICDBNode::CTextId textId
;
218 node
->removeObserver(&_InvisibleObs
, textId
);
222 for(uint i
=0;i
<EGSPD::CSPType::EndSPType
;i
++)
224 CCDBNodeLeaf
*node
= NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:USER:SKILL_POINTS_%d:VALUE", i
), false);
227 ICDBNode::CTextId textId
;
228 node
->removeObserver(_SkillPointObs
+i
, textId
);
232 for( uint i
=0; i
<_FamesObs
.size(); ++i
)
234 uint32 factionIndex
= _FamesObs
[i
]->FactionIndex
;
235 uint32 fameIndexInDatabase
= CStaticFames::getInstance().getDatabaseIndex(factionIndex
);
236 string sDBPath
= toString("SERVER:FAME:PLAYER%d:VALUE",fameIndexInDatabase
);
238 CCDBNodeLeaf
* node
= NLGUI::CDBManager::getInstance()->getDbProp(sDBPath
, false);
241 ICDBNode::CTextId textId
;
242 node
->removeObserver(_FamesObs
[i
], textId
);
245 contReset(_FamesObs
);
247 CNPCIconCache::getInstance().removeObservers();
249 // Remove the Primitive used for check (because ~CEntityCL() will call CEntityCL::removePrimitive(), not CUserEntity::removePrimitive())
250 removeCheckPrimitive();
252 CNPCIconCache::release();
256 //-----------------------------------------------
258 // Initialize properties of the entity (according to the class).
259 //-----------------------------------------------
260 void CUserEntity::initProperties()
262 properties().selectable(true);
263 }// initProperties //
266 //-----------------------------------------------
268 // Build the entity from a sheet.
269 //-----------------------------------------------
270 bool CUserEntity::build(const CEntitySheet
*sheet
) // virtual
272 // Init received position
273 pos(UserEntityInitPos
);
274 front(UserEntityInitFront
);
278 // Cast the sheet in the right type.
279 _PlayerSheet
= dynamic_cast<const CRaceStatsSheet
*>(sheet
);
280 if(_PlayerSheet
== 0)
282 pushDebugStr("User Sheet is not a valid '.race_stats'.");
286 pushInfoStr("User Sheet is a valid '.race_stats'.");
288 if(IngameDbMngr
.getNodePtr())
290 CCDBNodeBranch
*nodeRoot
= dynamic_cast<CCDBNodeBranch
*>(IngameDbMngr
.getNodePtr()->getNode(0));
293 _DBEntry
= dynamic_cast<CCDBNodeBranch
*>(nodeRoot
->getNode(_Slot
));
295 pushDebugStr("Cannot get a pointer on the DB entry.");
301 if(ClientCfg
.RunAtTheBeginning
!= _Run
)
304 // Set the up of the user.
308 eyesHeight(ClientCfg
.EyesHeight
);
309 walkVelocity(ClientCfg
.Walk
);
310 runVelocity(ClientCfg
.Run
);
312 // Compute the first automaton.
313 _CurrentAutomaton
= automatonType() + "_normal.automaton";
315 // Build the PACS Primitive.
316 if(initPrimitive(0.5f
, 2.0f
, 0.0f
, 0.0f
, UMovePrimitive::Slide
, (UMovePrimitive::TTrigger
)(UMovePrimitive::OverlapTrigger
| UMovePrimitive::EnterTrigger
), MaskColPlayer
, MaskColPlayer
| MaskColNpc
| MaskColDoor
))
317 _Primitive
->insertInWorldImage(dynamicWI
);
319 // Compute the element to be able to snap the entity to the ground.
320 computeCollisionEntity();
322 // Initialize properties of the client.
325 // Initialize the observer for the speed factor and mount stuff
330 // Create the user playlist
333 // Initialize the internal time.
334 _LastFrameTime
= ((double)T1
) * 0.001;
336 // Set the gender in local mode.
339 _Mode
= MBEHAV::NORMAL
;
340 _ModeWanted
= MBEHAV::NORMAL
;
341 _Gender
= ClientCfg
.Sex
;
342 SPropVisualA visualA
= buildPropVisualA(_PlayerSheet
->GenderInfos
[_Gender
]);
343 SPropVisualB visualB
= buildPropVisualB(_PlayerSheet
->GenderInfos
[_Gender
]);
344 SPropVisualC visualC
;
345 visualA
.PropertySubData
.Sex
= _Gender
;
346 visualC
.PropertyC
= 0;
347 visualC
.PropertySubData
.CharacterHeight
= 0;
348 visualC
.PropertySubData
.ArmsWidth
= 7;
349 visualC
.PropertySubData
.LegsWidth
= 7;
350 visualC
.PropertySubData
.TorsoWidth
= 7;
351 visualC
.PropertySubData
.BreastSize
= 7;
353 sint64
*prop
= (sint64
*)&visualA
;
354 NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P"+toString("%d", CLFECOMMON::PROPERTY_VPA
))->setValue64(*prop
); // Set the database
355 prop
= (sint64
*)&visualB
;
356 NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P"+toString("%d", CLFECOMMON::PROPERTY_VPB
))->setValue64(*prop
); // Set the database
357 prop
= (sint64
*)&visualC
;
358 NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P"+toString("%d", CLFECOMMON::PROPERTY_VPC
))->setValue64(*prop
); // Set the database
360 updateVisualProperty(0, CLFECOMMON::PROPERTY_VPA
);
362 // \todo GUIGUI Retrieve the player's appearence during the avatar selection.
363 // Get Visual Properties From the character selection window.
369 buildInSceneInterface ();
371 // Add observer on invisible property
372 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
374 CCDBNodeLeaf
*node
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:IS_INVISIBLE", false);
377 ICDBNode::CTextId textId
;
378 node
->addObserver(&_InvisibleObs
, textId
);
382 // Add an observer on skill points
383 for(uint i
=0;i
<EGSPD::CSPType::EndSPType
;i
++)
385 _SkillPointObs
[i
].SpType
= i
;
386 CCDBNodeLeaf
*node
= NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:USER:SKILL_POINTS_%d:VALUE", i
), false);
389 ICDBNode::CTextId textId
;
390 node
->addObserver(_SkillPointObs
+i
, textId
);
394 // Add an observer on Fames
395 for( uint i
=(uint
)PVP_CLAN::BeginClans
; i
<=(uint
)PVP_CLAN::EndClans
; ++i
)
397 uint32 factionIndex
= PVP_CLAN::getFactionIndex((PVP_CLAN::TPVPClan
)i
);
398 uint32 fameIndexInDatabase
= CStaticFames::getInstance().getDatabaseIndex(factionIndex
);
399 string sDBPath
= toString("SERVER:FAME:PLAYER%d:VALUE",fameIndexInDatabase
);
401 CFameObserver
* fameObs
= new CFameObserver();
404 fameObs
->FactionIndex
= factionIndex
;
405 CCDBNodeLeaf
* node
= NLGUI::CDBManager::getInstance()->getDbProp(sDBPath
, false);
408 ICDBNode::CTextId textId
;
409 node
->addObserver(fameObs
, textId
);
411 _FamesObs
.push_back(fameObs
);
415 // Add an observer on Mission Journal
416 CNPCIconCache::getInstance().addObservers();
418 // Initialize the camera distance.
419 View
.cameraDistance(ClientCfg
.CameraDistance
);
421 // char and account time properties
422 CSkillManager
*pSM
= CSkillManager::getInstance();
425 pSM
->tryToUnblockTitleFromCharOldness( CharFirstConnectedTime
);
426 pSM
->tryToUnblockTitleFromCharPlayedTime( CharPlayedTime
);
434 //-----------------------------------------------
436 // \todo GUIGUI : do it better in mount mode
437 //-----------------------------------------------
438 float CUserEntity::eyesHeight()
441 return _EyesHeight
* _CharacterScalePos
;
443 return _EyesHeight
* _CharacterScalePos
;
447 /////////////////////////////////////////////////
448 /////////////////////////////////////////////////
449 /////////////// VISUAL PROPERTIES ///////////////
450 /////////////////////////////////////////////////
451 /////////////////////////////////////////////////
452 //-----------------------------------------------
453 // updateVisualPropertyPos :
454 // Update Entity Position.
455 //-----------------------------------------------
456 void CUserEntity::updateVisualPropertyPos(const NLMISC::TGameCycle
&/* gameCycle */, const sint64
&/* prop */, const NLMISC::TGameCycle
&/* pI */)
458 }// updateVisualPropertyPos //
460 //-----------------------------------------------
461 // updateVisualPropertyOrient :
462 // Update Entity Orientation.
463 //-----------------------------------------------
464 void CUserEntity::updateVisualPropertyOrient(const NLMISC::TGameCycle
&/* gameCycle */, const sint64
&/* prop */)
466 }// updateVisualPropertyOrient //
469 void CUserEntity::updateVisualPropertyTargetList(const NLMISC::TGameCycle
&/* gameCycle */, const sint64
&/* prop */, uint
/* listIndex */)
473 void CUserEntity::updateVisualPropertyVisualFX(const NLMISC::TGameCycle
&/* gameCycle */, const sint64
&prop
)
478 //-----------------------------------------------
479 // updateVisualPropertyBehaviour :
480 // Update Entity Behaviour.
481 //-----------------------------------------------
482 void CUserEntity::updateVisualPropertyBehaviour(const NLMISC::TGameCycle
&/* gameCycle */, const sint64
&prop
)
484 // Compute the behaviour.
485 CBehaviourContext bc
;
486 bc
.Behav
= MBEHAV::CBehaviour(prop
);
487 bc
.BehavTime
= TimeInSec
;
490 nlinfo("UE::updateVPBeha: '%d(%s)'.", (sint
)bc
.Behav
.Behaviour
, MBEHAV::behaviourToString(bc
.Behav
.Behaviour
).c_str());
492 CCDBNodeLeaf
*targetList0
= dynamic_cast<CCDBNodeLeaf
*>(_DBEntry
->getNode(CLFECOMMON::PROPERTY_TARGET_LIST_0
));
493 CCDBNodeLeaf
*targetList1
= dynamic_cast<CCDBNodeLeaf
*>(_DBEntry
->getNode(CLFECOMMON::PROPERTY_TARGET_LIST_1
));
494 CCDBNodeLeaf
*targetList2
= dynamic_cast<CCDBNodeLeaf
*>(_DBEntry
->getNode(CLFECOMMON::PROPERTY_TARGET_LIST_1
));
495 CCDBNodeLeaf
*targetList3
= dynamic_cast<CCDBNodeLeaf
*>(_DBEntry
->getNode(CLFECOMMON::PROPERTY_TARGET_LIST_1
));
496 if (targetList0
&& targetList1
&& targetList2
&& targetList3
)
500 (uint64
) targetList0
->getValue64(),
501 (uint64
) targetList1
->getValue64(),
502 (uint64
) targetList2
->getValue64(),
503 (uint64
) targetList3
->getValue64()
505 bc
.Targets
.unpack(vp
, 4);
508 }// updateVisualPropertyBehaviour //
510 //-----------------------------------------------
511 // updateVisualPropertyName :
512 // Update Entity Name.
513 //-----------------------------------------------
514 void CUserEntity::updateVisualPropertyName(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
516 uint32 oldNameId
= _NameId
;
518 CPlayerCL::updateVisualPropertyName(gameCycle
, prop
);
521 /* if (oldNameId != _NameId)
523 CInterfaceManager *pIM = CInterfaceManager::getInstance();
524 CInterfaceElement *element = CWidgetManager::getInstance()->getElementFromId("ui:interface:mailbox:content:html");
527 CGroupHTML *html = dynamic_cast<CGroupHTML*>(element);
529 html->browse("home");
533 }// updateVisualPropertyName //
535 //-----------------------------------------------
536 // updateVisualPropertyTarget :
537 // Update Entity Target.
538 //-----------------------------------------------
539 void CUserEntity::updateVisualPropertyTarget(const NLMISC::TGameCycle
&/* gameCycle */, const sint64
&/* prop */)
541 // Don't override the Player Target, cause client side entirely => no lag.
542 //targetSlot((CLFECOMMON::TCLEntityId)prop);
543 }// updateVisualPropertyTarget //
545 //-----------------------------------------------
546 // updateVisualPropertyMode :
547 // New mode received -> immediately change the mode for the user.
548 // \warning Read the position or orientation from the database when reading the mode (no more updated in updateVisualPropertyPos and updateVisualPropertyOrient).
549 //-----------------------------------------------
550 void CUserEntity::updateVisualPropertyMode(const NLMISC::TGameCycle
&/* gameCycle */, const sint64
&prop
)
552 // Combat Float Check
553 if((MBEHAV::EMode
)prop
== MBEHAV::COMBAT_FLOAT
)
555 nlwarning("UE:updateVPMode: the user should never have the COMBAT_FLOAT mode.");
558 // New Mode Received.
559 _TheoreticalMode
= (MBEHAV::EMode
)prop
;
560 // Change the user mode.
561 mode(_TheoreticalMode
);
562 }// updateVisualPropertyMode //
564 //-----------------------------------------------
565 // updateVisualPropertyVpa :
566 // Update Entity Visual Property A
567 //-----------------------------------------------
568 void CUserEntity::updateVisualPropertyVpa(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
570 CPlayerCL::updateVisualPropertyVpa(gameCycle
, prop
);
572 // Special for user: Disable Character Lod, because always want it at full rez.
573 if(!_Skeleton
.empty())
575 _Skeleton
.setLodCharacterShape(-1);
578 updateVisualDisplay();
579 }// updateVisualPropertyVpa //
581 //-----------------------------------------------
582 // updateVisualPropertyVpb :
583 // Update Entity Visual Property B
584 //-----------------------------------------------
585 void CUserEntity::updateVisualPropertyVpb(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
587 CPlayerCL::updateVisualPropertyVpb(gameCycle
, prop
);
588 updateVisualDisplay();
589 }// updateVisualPropertyVpb //
591 //-----------------------------------------------
592 // updateVisualPropertyVpc :
593 // Update Entity Visual Property C
594 //-----------------------------------------------
595 void CUserEntity::updateVisualPropertyVpc(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
597 CPlayerCL::updateVisualPropertyVpc(gameCycle
, prop
);
598 updateVisualDisplay();
599 }// updateVisualPropertyVpc //
601 //-----------------------------------------------
602 // updateVisualPropertyEntityMounted :
603 // Update Entity Mount
604 //-----------------------------------------------
605 void CUserEntity::updateVisualPropertyEntityMounted(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
608 CPlayerCL::updateVisualPropertyEntityMounted(gameCycle
, prop
);
610 _Mount
= (CLFECOMMON::TCLEntityId
)prop
;
611 }// updateVisualPropertyEntityMounted //
613 //-----------------------------------------------
614 // updateVisualPropertyRiderEntity :
615 // Update Entity Rider
616 //-----------------------------------------------
617 void CUserEntity::updateVisualPropertyRiderEntity(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
620 CPlayerCL::updateVisualPropertyRiderEntity(gameCycle
, prop
);
622 _Rider
= (CLFECOMMON::TCLEntityId
)prop
;
623 }// updateVisualPropertyRiderEntity //
625 //-----------------------------------------------
626 //-----------------------------------------------
627 void CUserEntity::updateVisualPropertyPvpMode(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
629 CPlayerCL::updateVisualPropertyPvpMode(gameCycle
, prop
);
630 // Additionaly, inform interface of the change
631 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
632 // For PVP ZoneFaction
633 CCDBNodeLeaf
*pDB
= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:TRACK_PVP_CHANGE_MODE");
636 sint32 val
= pDB
->getValue32();
637 pDB
->setValue32(val
+1);
639 // For Any PVP change
640 pDB
= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:TRACK_PVP_CHANGE_ANY");
643 sint32 val
= pDB
->getValue32();
644 pDB
->setValue32(val
+1);
648 //-----------------------------------------------
649 //-----------------------------------------------
650 void CUserEntity::updateVisualPropertyOutpostInfos(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
652 CPlayerCL::updateVisualPropertyOutpostInfos(gameCycle
, prop
);
653 // For Any PVP change
654 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
655 CCDBNodeLeaf
*pDB
= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:TRACK_PVP_CHANGE_ANY");
658 sint32 val
= pDB
->getValue32();
659 pDB
->setValue32(val
+1);
663 //-----------------------------------------------
664 //-----------------------------------------------
665 void CUserEntity::updateVisualPropertyPvpClan(const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
)
667 CPlayerCL::updateVisualPropertyPvpClan(gameCycle
, prop
);
668 // For Any PVP change
669 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
670 CCDBNodeLeaf
*pDB
= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:TRACK_PVP_CHANGE_ANY");
673 sint32 val
= pDB
->getValue32();
674 pDB
->setValue32(val
+1);
679 /////////////////////////////////////////////////
680 /////////////////////////////////////////////////
681 /////////////////////////////////////////////////
682 /////////////////////////////////////////////////
685 //-----------------------------------------------
687 // Method called to change the mode (Combat/Mount/etc.).
688 // \todo GUIGUI : apply stage in combat modes instead of just removing them.
689 // \todo GUIGUI : go or teleport the player to the mode position (see how to manage it).
690 //-----------------------------------------------
691 bool CUserEntity::mode(MBEHAV::EMode m
)
693 if(Verbose
& VerboseAnim
)
694 nlinfo("UE::mode: old mode '%s(%d)' new mode '%s(%d)'.", MBEHAV::modeToString(_Mode
).c_str(), _Mode
, MBEHAV::modeToString(m
).c_str(), m
);
695 // Nothing to do if the mode is the same as the previous one.
698 // Release the old Mode.
703 case MBEHAV::COMBAT_FLOAT
:
705 // If there are some stage not complete -> remove them
706 if(_Stages
._StageSet
.size() != 0)
707 _Stages
._StageSet
.clear();
710 // Leave MOUNTED Mode
711 case MBEHAV::MOUNT_NORMAL
:
712 case MBEHAV::MOUNT_SWIM
:
714 if ( m
== MBEHAV::REST
)
716 // can't go afk while mounting
720 // if changing mode for another mount mode, do nothing
721 if (m
!= MBEHAV::MOUNT_NORMAL
&& m
!= MBEHAV::MOUNT_SWIM
)
723 // Display the mount again.
724 CCharacterCL
*mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(_Mount
));
728 mount
->rider(CLFECOMMON::INVALID_SLOT
);
729 mount
->_Stages
._StageSet
.clear();
730 mount
->setMode(MBEHAV::NORMAL
);
731 mount
->computeAutomaton();
732 mount
->computeAnimSet();
733 mount
->setAnim(CAnimationStateSheet::Idle
);
734 if(mount
->getPrimitive())
735 mount
->getPrimitive()->setOcclusionMask(MaskColNpc
); // the mount is an npc
736 mount
->_ForbidClipping
= false;
739 _Mount
= CLFECOMMON::INVALID_SLOT
;
740 // Restore the user Primitive
743 _Primitive
->setRadius( std::min(0.5f
, (float)(RYZOM_ENTITY_SIZE_MAX
/2)) );
744 _Primitive
->setHeight(2);
748 // Shift the player position (not to stand inside the mount)
749 CVectorD unmountShift
;
750 unmountShift
.sphericToCartesian(1.0, frontYaw() + NLMISC::Pi
/2, 0);
751 pacsPos(pos() + unmountShift
);
753 // Restore running if necessary
754 if (!_Run
&& _RunWhenAble
)
760 if (_Mode
== MBEHAV::MOUNT_SWIM
&& ( m
== MBEHAV::COMBAT
|| m
== MBEHAV::COMBAT_FLOAT
))
762 //TODO : display "you can't fight while swimming"
769 // Restore the last view.
770 viewMode(viewMode());
773 if( m
== MBEHAV::COMBAT
|| m
== MBEHAV::COMBAT_FLOAT
)
775 //TODO : display "you can't fight while swimming"
780 nlwarning("Invalid behaviour change.");
783 // Reset Parent, unless we stay in mount mode
784 if ((_Mode
!= MBEHAV::MOUNT_SWIM
&& _Mode
!= MBEHAV::MOUNT_NORMAL
)
785 || (m
!= MBEHAV::MOUNT_SWIM
&& m
!= MBEHAV::MOUNT_NORMAL
)
788 parent(CLFECOMMON::INVALID_SLOT
);
791 // Change the Mode for the user ( if user sits down or stands up we wait in order to play the sit/stand transition anim)
792 if( m
!= MBEHAV::SIT
&& _Mode
!= MBEHAV::SIT
)
796 // Initialize the new Mode.
801 case MBEHAV::COMBAT_FLOAT
:
806 const string propName
= toString("SERVER:Entities:E%d:P%d", _Slot
, CLFECOMMON::PROPERTY_ORIENTATION
);
807 rot
.i64
[0] = NLGUI::CDBManager::getInstance()->getDbProp(propName
)->getValue64();
808 _TargetAngle
= rot
.f
[0];
810 // Initialize controls for the combat.
811 UserControls
.startCombat();
814 contextHelp ("action_bar");
818 // Mount Normal or mount swim
819 case MBEHAV::MOUNT_NORMAL
:
821 CCharacterCL
*mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(parent()));
824 mount
->_Stages
.removePosWithNoMode();
828 case MBEHAV::MOUNT_SWIM
:
830 // Hide the mount unless we come from another mounted mode
831 if (_Mode
!= MBEHAV::MOUNT_SWIM
&& _Mode
!= MBEHAV::MOUNT_NORMAL
)
833 if(_Mount
!= CLFECOMMON::INVALID_SLOT
) // if _Mount is still invalid, the following code will be done in updatePos()
839 UserEntity
->selection(_Selection
);
847 _Mode
= MBEHAV::SWIM_DEATH
;
850 // Normal or Default mode.
852 _CurrentBehaviour
.Behaviour
= MBEHAV::IDLE
;
856 viewMode(viewMode());
860 bool doSetAnim
= true;
861 // if user sits down or stands up we set transition anim before changing animset
862 if( m
== MBEHAV::SIT
)
864 setAnim(CAnimationStateSheet::SitMode
);
869 if( _Mode
== MBEHAV::SIT
&& m
!=MBEHAV::DEATH
)
871 setAnim(CAnimationStateSheet::SitEnd
);
876 // Show/Hide all or parts of the body.
877 updateVisualDisplay();
878 if( ClientCfg
.AutomaticCamera
)
880 // Set the direction as the front.
883 // Compute the current automaton
885 // Update the animation set according to the mode.
890 // Animset changed -> update current animation
891 setAnim(CAnimationStateSheet::Idle
);
894 // Changing the mode well done.
900 * Mount the mount in _Mount
902 void CUserEntity::setOnMount()
904 CCharacterCL
*mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(_Mount
));
907 // Update primitives for the mount and the rider.
908 if(_Primitive
&& mount
->getPrimitive())
910 _Primitive
->setRadius( std::min(mount
->getPrimitive()->getRadius(), (float)(RYZOM_ENTITY_SIZE_MAX
/2)) );
911 _Primitive
->setHeight(mount
->getPrimitive()->getHeight());
912 mount
->getPrimitive()->setOcclusionMask(MaskColNone
); // Remove collisions.
916 // Link the mount and the user.
918 // Refresh the View Mode
919 viewMode(viewMode());
920 // Close the crafting window if open
921 closeFaberCastWindow();
926 mount
->_ForbidClipping
= true;
932 //-----------------------------------------------
934 // compute and return the entity velocity
935 //-----------------------------------------------
936 CVector
CUserEntity::getVelocity() const
938 static const CVector
lateral(0,0,1);
939 static CVector velocity
;
940 velocity
= front() * _FrontVelocity
+ ( lateral
^ front()) * _LateralVelocity
;
941 velocity
.normalize();
953 else if(isSwimming())
955 // We are a Ring DM so speed up a litle
958 // Forward Run or Walk
959 if(_FrontVelocity
> 0.0f
)
966 // Lateral or Backward Walk
970 if (_R2CharMode
== R2::TCharMode::Editer
|| _R2CharMode
== R2::TCharMode::Dm
)
972 velocity
*= (float(ClientCfg
.DmRun
) / 6.0f
); // velocity max = max run / 2
978 // Forward Run or Walk
979 if(_FrontVelocity
> 0.0f
)
982 velocity
*= getMountRunVelocity();
984 velocity
*= getMountWalkVelocity();
986 // Lateral or Backward Walk (currently, not used)
988 velocity
*= 0.66f
;//getMountWalkVelocity();
992 // Forward Run or Walk
993 if(_FrontVelocity
> 0.0f
)
994 velocity
*= currentVelocity();
995 // Lateral or Backward Walk
997 velocity
*= _WalkVelocity
;
1002 //-----------------------------------------------
1004 // Return the Entity Current Speed.
1005 //-----------------------------------------------
1006 double CUserEntity::speed() const // virtual
1008 return CPlayerCL::speed();
1009 // return (double)getVelocity().norm();
1012 //-----------------------------------------------
1014 // Apply the motion to the entity.
1015 //-----------------------------------------------
1016 void CUserEntity::applyMotion(CEntityCL
*target
)
1018 // default each frame
1019 _ForceLookSlot
= CLFECOMMON::INVALID_SLOT
;
1021 bool lastHasMoved
= _HasMoved
;
1023 // Remove Positions in stages
1024 _Stages
.removePosWithNoMode();
1025 // Remove Positions in stages for the mount.
1026 CCharacterCL
*mount
= 0;
1027 if(parent() != CLFECOMMON::INVALID_SLOT
)
1029 mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(parent()));
1031 mount
->_Stages
.removePosWithNoMode();
1033 // NO PRIMITIVE -> NO MOVE
1036 // BAD CONNECTION -> NO MOVE
1037 if(NetMngr
.getConnectionQuality() == false)
1039 // MS per TICK <=0 -> NO MOVE
1040 if(NetMngr
.getMsPerTick() <= 0)
1042 // Compute Speed Vector
1043 NLMISC::CVectorD speed
;
1044 if(_MoveToSlot
!= CLFECOMMON::INVALID_SLOT
)
1046 // Check the Target.
1047 if(target
== 0 || target
== this)
1049 // Compute the vector between the user and the target.
1050 CVectorD dir2targ
= target
->pos() - pos();
1052 if(dir2targ
== CVectorD::Null
)
1054 const double angToTarget
= atan2(dir2targ
.y
, dir2targ
.x
);
1055 CVectorD aimingPos
= target
->getAttackerPos(angToTarget
, attackRadius() + ClientCfg
.AttackDist
);
1057 CVectorD dirToAimingPos
= aimingPos
-pos();
1058 dirToAimingPos
.z
= 0.0;
1059 const double distToAimingPos
= dirToAimingPos
.norm();
1061 // Decide if the target is reached or not
1062 bool targetReached
= false;
1063 if(distToAimingPos
> 0.5)
1065 // Because of Tryker Counter, may increase the Threshold, when the player is stalled
1066 if(distToAimingPos
<_MoveToDist
)
1068 // If the player is stalled too much time, abort the move and launch the action
1069 float actualSpeed
= float((_Position
- _LastFramePos
).norm() / DT
);
1071 // if player effectively runs twice slower, start colision timer
1072 if( actualSpeed
*2 < getMaxSpeed() )
1074 if(!_MoveToColStartTime
)
1075 _MoveToColStartTime
= T1
;
1077 // else ok, reset colision timer
1079 _MoveToColStartTime
= 0;
1081 // if too much time stalled, stop run.
1082 if(_MoveToColStartTime
&& (T1
- _MoveToColStartTime
>= ClientCfg
.MoveToTimeToStopStall
) )
1083 targetReached
= true;
1086 _MoveToColStartTime
= 0;
1089 targetReached
= true;
1091 // If the target is reached
1094 // stop and execute action
1095 speed
= CVectorD::Null
;
1096 moveToAction(target
);
1098 // else continue follow
1101 // Look at the entity. delay it after pacs evalCollision(), for correct orientation
1102 _ForceLookSlot
= target
->slot();
1103 // but still estimate now an approximative front (may be used between now and applyForceLook())
1104 forceLookEntity(dir2targ
, false);
1107 dirToAimingPos
.normalize();
1108 // Set the Velocity Direction
1109 speed
= dirToAimingPos
*distToAimingPos
;
1111 if(speed
.norm() > getMaxSpeed())
1112 speed
= dirToAimingPos
*getMaxSpeed();
1117 // Check the Target.
1118 if(target
== 0 || target
== this)
1120 // If the target is moving, orientate the user to the target.
1121 // if(target->hasMoved())
1123 // Compute the vector between the user and the target.
1124 CVectorD dir2targ
= target
->pos() - pos();
1126 if(dir2targ
!= CVectorD::Null
)
1128 // Look at the entity. delay it after pacs evalCollision(), for correct orientation
1129 _ForceLookSlot
= target
->slot();
1130 // but still estimate now an approximative front (may be used between now and applyForceLook())
1131 forceLookEntity(dir2targ
, false);
1134 // Compute the angle in the world to attack the target.
1135 const double angToTarget
= frontYaw();
1136 // Get the best position to attack the target with the given angle.
1137 const CVectorD aimingPos
= target
->getAttackerPos(angToTarget
, attackRadius() + ClientCfg
.AttackDist
);
1139 CVectorD dirToAimingPos
= aimingPos
-pos();
1140 dirToAimingPos
.z
= 0.0;
1141 const double distToAimingPos
= dirToAimingPos
.norm();
1142 // If the User was not moving and the distance to re-move is not enough big, stay idle
1144 || (isFighting() && distToAimingPos
>= 0.5)
1145 || (!isFighting() && distToAimingPos
>= 3.0))
1147 dirToAimingPos
.normalize();
1148 // User is in combat mode -> follow as close as possible.
1152 if(target
->hasMoved())
1154 // Get closer if too far.
1155 if(distToAimingPos
>= 0.2)
1157 // Set the Velocity Direction
1158 speed
= dirToAimingPos
*distToAimingPos
;
1160 if(speed
.norm() > getMaxSpeed())
1161 speed
= dirToAimingPos
*getMaxSpeed();
1165 // Try to have the same speed as the target.
1166 if(target
->getSpeed() > getMaxSpeed())
1167 speed
= target
->dir()* ((float)getMaxSpeed());
1169 speed
= target
->dir()* ((float)target
->getSpeed());
1172 // Target is not moving.
1175 // Get closer if too far.
1176 if(distToAimingPos
>= 0.1)
1178 // Set the Velocity Direction
1179 speed
= dirToAimingPos
*distToAimingPos
;
1181 if(speed
.norm() > getMaxSpeed())
1182 speed
= dirToAimingPos
*getMaxSpeed();
1185 speed
= CVectorD::Null
;
1188 // User is not in combat mode -> follow not so close.
1191 // Too far, get closer as fast as possible
1192 if(distToAimingPos
>= 3.0)
1194 // Set the Velocity Direction
1195 speed
= dirToAimingPos
*distToAimingPos
;
1197 if(speed
.norm() > getMaxSpeed())
1198 speed
= dirToAimingPos
*getMaxSpeed();
1200 // Just far enough, adjust the user speed to the target
1201 else if(target
->hasMoved() && distToAimingPos
>= 1.0)
1203 // Try to have the same speed as the target.
1204 if(target
->getSpeed() > getMaxSpeed())
1205 speed
= target
->dir()* ((float)getMaxSpeed());
1207 speed
= target
->dir()* ((float)target
->getSpeed());
1211 speed
= CVectorD::Null
;
1214 // User was stop and the next pos is to close to begin to move.
1216 speed
= CVectorD::Null
;
1220 speed
= getVelocity()*_SpeedFactor
.getValue();
1221 _SpeedFactor
.addFactorValue(0.005f
);
1224 // SPEED VECTOR NULL -> NO MOVE
1225 if(speed
== CVectorD::Null
)
1228 // First Person View
1229 if(UserControls
.isInternalView())
1231 // If the server is slow, the client move slower too (only needed in FPV).
1232 double modif
= (100.0f
/(float)NetMngr
.getMsPerTick());
1233 // don't increase speed
1234 clamp(modif
, 0.0, 1.0);
1238 _Primitive
->move(speed
, dynamicWI
);
1239 if(mount
&& mount
->getPrimitive())
1240 mount
->getPrimitive()->move(speed
, dynamicWI
);
1242 // Third Person View
1245 double modif
= (100.0f
/(float)NetMngr
.getMsPerTick());
1246 clamp(modif
, 0.0, 1.0);
1249 sint64 x
= (sint64
)((sint32
)(speed
.x
* 1000.0));
1250 sint64 y
= (sint64
)((sint32
)(speed
.y
* 1000.0));
1251 sint64 z
= (sint64
)((sint32
)(speed
.z
* 1000.0));
1252 const uint time
= 10; // = 1sec because the speed is in Meter per Sec.
1253 _Stages
.addStage(NetMngr
.getCurrentClientTick()+time
, CLFECOMMON::PROPERTY_POSX
, x
, 0);
1254 _Stages
.addStage(NetMngr
.getCurrentClientTick()+time
, CLFECOMMON::PROPERTY_POSY
, y
);
1255 _Stages
.addStage(NetMngr
.getCurrentClientTick()+time
, CLFECOMMON::PROPERTY_POSZ
, z
);
1259 mount
->_Stages
.addStage(NetMngr
.getCurrentClientTick()+time
, CLFECOMMON::PROPERTY_POSX
, x
, 0);
1260 mount
->_Stages
.addStage(NetMngr
.getCurrentClientTick()+time
, CLFECOMMON::PROPERTY_POSY
, y
);
1261 mount
->_Stages
.addStage(NetMngr
.getCurrentClientTick()+time
, CLFECOMMON::PROPERTY_POSZ
, z
);
1269 //---------------------------------------------------
1270 //---------------------------------------------------
1271 void CUserEntity::applyForceLook()
1273 if(_ForceLookSlot
!=CLFECOMMON::INVALID_SLOT
)
1275 CEntityCL
*target
= EntitiesMngr
.entity(_ForceLookSlot
);
1276 if(target
&& target
!=this)
1278 // Compute the vector between the user and the target.
1279 CVectorD dir2targ
= target
->pos() - pos();
1281 if(dir2targ
== CVectorD::Null
)
1283 // Look at the entity
1284 forceLookEntity(dir2targ
, true);
1290 //---------------------------------------------------
1291 // updatePosCombatFloatChanged :
1292 //---------------------------------------------------
1293 void CUserEntity::updatePosCombatFloatChanged(CEntityCL
* /* target */) // virtual
1295 if(viewMode() == FirstPV
)
1299 }// updatePosCombatFloatChanged //
1302 //-----------------------------------------------
1303 // forceIndoorFPV //
1304 // Return true if the user is indoor and the CFG want to force the FPV Indoor.
1305 //-----------------------------------------------
1306 bool CUserEntity::forceIndoorFPV()
1308 return (ClientCfg
.ForceIndoorFPV
&& indoor());
1309 }// forceIndoorFPV //
1312 //-----------------------------------------------
1314 //-----------------------------------------------
1315 void CUserEntity::disableFollow()
1317 if (_FollowMode
==false)
1320 _FollowMode
= false;
1322 // Send the message to the server.
1324 if(GenericMsgHeaderMngr
.pushNameToStream("TARGET:NO_FOLLOW", out
))
1327 nlwarning("UE:follow: unknown message named 'TARGET:NO_FOLLOW'.");
1332 //-----------------------------------------------
1334 //-----------------------------------------------
1335 void CUserEntity::enableFollow(bool resetCameraRot
)
1337 if (_FollowMode
== true)
1340 if( _Mode
== MBEHAV::DEATH
)
1345 // Send the message to the server.
1347 if(GenericMsgHeaderMngr
.pushNameToStream("TARGET:FOLLOW", out
))
1350 nlwarning("UE:follow: unknown message named 'TARGET:FOLLOW'.");
1352 // Disable any autowalk (else when follow re-disabled, it will effect, which is weird)
1353 UserControls
.autowalkState(false);
1358 // if want to reset camera rotation
1360 startForceLookEntity(targetSlot());
1365 //-----------------------------------------------
1367 //-----------------------------------------------
1368 void CUserEntity::resetAnyMoveTo()
1370 // if we cancel a MoveToPhrase action, MUST dec the action counter, and hide the Action Icon
1371 if(_MoveToAction
==CUserEntity::CombatPhrase
|| _MoveToAction
==CUserEntity::ExtractRM
)
1373 // the clientExecute has not been called in case of "ExtractRM autoFind"
1374 bool autoFindExtractRM
= _MoveToAction
==CUserEntity::ExtractRM
&& _MoveToPhraseMemoryLine
== std::numeric_limits
<uint
>::max();
1375 if(!autoFindExtractRM
)
1377 CSPhraseManager
*pPM
= CSPhraseManager::getInstance();
1378 pPM
->cancelClientExecute(_MoveToPhraseCyclic
);
1382 // reset to no moveTo
1383 _MoveToSlot
= CLFECOMMON::INVALID_SLOT
;
1384 _MoveToAction
= CUserEntity::None
;
1386 _MoveToColStartTime
= 0;
1389 //-----------------------------------------------
1390 // moveToCheckStartDist :
1391 // Check if the user is not already well placed.
1392 //-----------------------------------------------
1393 void CUserEntity::moveToCheckStartDist(CLFECOMMON::TCLEntityId slot
, double dist
, TMoveToAction
/* action */)
1395 if(_MoveToSlot
!= CLFECOMMON::INVALID_SLOT
)
1397 // Start a new Force Look entity
1398 startForceLookEntity(_MoveToSlot
);
1400 // Disable any autowalk (else when moveTo re-disabled, it will effect, which is weird)
1401 UserControls
.autowalkState(false);
1406 }// moveToCheckStartDist //
1408 //-----------------------------------------------
1410 // Method to move to someone else.
1411 //-----------------------------------------------
1412 void CUserEntity::moveTo(CLFECOMMON::TCLEntityId slot
, double dist
, TMoveToAction action
)
1419 _MoveToAction
= action
;
1421 moveToCheckStartDist(_MoveToSlot
, _MoveToDist
, _MoveToAction
);
1424 //-----------------------------------------------
1426 // Method to move to someone else for a mission. NB: if prec action was a CombatPhrase action, action counter are decremented
1427 //-----------------------------------------------
1428 void CUserEntity::moveToMission(CLFECOMMON::TCLEntityId slot
, double dist
, uint32 id
)
1435 _MoveToAction
= CUserEntity::Mission
;
1436 _MoveToMissionId
= id
;
1438 moveToCheckStartDist(_MoveToSlot
, _MoveToDist
, _MoveToAction
);
1439 }// moveToMission //
1441 //-----------------------------------------------
1442 // moveToMissionRing :
1443 // Method to move to someone else for a ring mission. NB: if prec action was a CombatPhrase action, action counter are decremented
1444 //-----------------------------------------------
1445 void CUserEntity::moveToMissionRing(CLFECOMMON::TCLEntityId slot
, double dist
, uint32 id
)
1452 _MoveToAction
= CUserEntity::MissionRing
;
1453 _MoveToMissionId
= id
;
1455 moveToCheckStartDist(_MoveToSlot
, _MoveToDist
, _MoveToAction
);
1456 }// moveToMissionRing //
1458 //-----------------------------------------------
1460 // Method to move to someone else.
1461 //-----------------------------------------------
1462 void CUserEntity::moveToCombatPhrase(CLFECOMMON::TCLEntityId slot
, double dist
, uint phraseMemoryLine
, uint phraseMemorySlot
, bool phraseCyclic
)
1469 _MoveToAction
= CUserEntity::CombatPhrase
;
1470 _MoveToPhraseMemoryLine
= phraseMemoryLine
;
1471 _MoveToPhraseMemorySlot
= phraseMemorySlot
;
1472 _MoveToPhraseCyclic
= phraseCyclic
;
1474 moveToCheckStartDist(_MoveToSlot
, _MoveToDist
, _MoveToAction
);
1477 //-----------------------------------------------
1478 // Method to move to someone else, for foraging extraction
1479 // The caller MUST call after CSPhraseManager::clientExecute(), to increment action counter
1480 //-----------------------------------------------
1481 void CUserEntity::moveToExtractionPhrase(CLFECOMMON::TCLEntityId slot
, double dist
, uint phraseMemoryLine
, uint phraseMemorySlot
, bool cyclic
)
1483 // Test if forage tool in hand, otherwise auto-equip with it
1484 bool validForageToolInHand
= false;
1485 CInventoryManager
* inv
= CInventoryManager::getInstance();
1490 uint32 rightHandSheet
= inv
->getRightHandItemSheet();
1491 if ( rightHandSheet
)
1493 validForageToolInHand
= inv
->isForageToolItem( rightHandSheet
);
1495 if ( !validForageToolInHand
)
1497 // Find a forage tool in the bag
1499 for ( i
=0; i
<MAX_BAGINV_ENTRIES
; ++i
)
1501 uint32 itemSheet
= inv
->getBagItem(i
).getSheetID();
1502 if ( itemSheet
&& inv
->isForageToolItem(itemSheet
) )
1507 if ( i
!= MAX_BAGINV_ENTRIES
&& ClientCfg
.AutoEquipTool
)
1509 // remember last used weapon(s)
1510 rememberWeaponsInHand();
1513 inv
->unequip( "LOCAL:INVENTORY:HAND:1" );
1514 inv
->unequip( "LOCAL:INVENTORY:HAND:0" );
1517 string bagPath
= toString( "LOCAL:INVENTORY:BAG:%u", i
);
1518 inv
->equip( bagPath
, "LOCAL:INVENTORY:HAND:0" );
1522 // No forage tool in bag
1523 CInterfaceManager::getInstance()->displaySystemInfo( CI18N::get("uiForageToolMissing"), "CHK" );
1533 _MoveToAction
= CUserEntity::ExtractRM
;
1534 _MoveToPhraseMemoryLine
= phraseMemoryLine
;
1535 _MoveToPhraseMemorySlot
= phraseMemorySlot
;
1536 _MoveToPhraseCyclic
= cyclic
;
1538 moveToCheckStartDist(_MoveToSlot
, _MoveToDist
, _MoveToAction
);
1541 //-----------------------------------------------
1542 // Method to begin a spire construction
1543 // The caller MUST call after CSPhraseManager::clientExecute(), to increment action counter
1544 //-----------------------------------------------
1545 void CUserEntity::moveToTotemBuildingPhrase(CLFECOMMON::TCLEntityId slot
, double dist
, uint phraseMemoryLine
, uint phraseMemorySlot
, bool cyclic
)
1552 _MoveToAction
= CUserEntity::BuildTotem
;
1553 _MoveToPhraseMemoryLine
= phraseMemoryLine
;
1554 _MoveToPhraseMemorySlot
= phraseMemorySlot
;
1555 _MoveToPhraseCyclic
= cyclic
;
1557 moveToCheckStartDist(_MoveToSlot
, _MoveToDist
, _MoveToAction
);
1560 //-----------------------------------------------
1562 // Launch the Action Once the Move is done.
1563 // \param CEntityCL * : pointer on the destination entity.
1564 // \warning entity pointer must be valid(allocated).
1565 //-----------------------------------------------
1566 void CUserEntity::moveToAction(CEntityCL
*ent
)
1568 // Check entity pointer
1571 UserControls
.needReleaseForward();
1573 // Get the interface instance.
1574 CInterfaceManager
*IM
= CInterfaceManager::getInstance();
1575 switch(_MoveToAction
)
1578 case CUserEntity::Attack
:
1579 UserEntity
->attack();
1582 case CUserEntity::Quarter
:
1583 if((ent
->properties()).harvestable())
1584 CAHManager::getInstance()->runActionHandler("context_quartering", 0);
1587 case CUserEntity::Loot
:
1588 if((ent
->properties()).lootable())
1589 CAHManager::getInstance()->runActionHandler("context_loot", 0);
1592 case CUserEntity::PickUp
:
1593 nlwarning("UE:checkMoveTo: not yet implemented");
1595 case CUserEntity::ExtractRM
:
1599 case CUserEntity::TradeItem
:
1600 CAHManager::getInstance()->runActionHandler("context_trade_item", 0);
1603 case CUserEntity::TradePhrase
:
1604 CAHManager::getInstance()->runActionHandler("context_trade_phrase", 0);
1607 case CUserEntity::TradePact
:
1608 CAHManager::getInstance()->runActionHandler("context_trade_pact", 0);
1611 case CUserEntity::Mission
:
1613 string param
= toString("id=%d", _MoveToMissionId
);
1614 CAHManager::getInstance()->runActionHandler("mission_option", 0, param
);
1618 case CUserEntity::DynamicMission
:
1619 CAHManager::getInstance()->runActionHandler("context_dynamic_mission", 0);
1622 case CUserEntity::StaticMission
:
1623 CAHManager::getInstance()->runActionHandler("context_choose_mission", 0);
1626 case CUserEntity::MissionRing
:
1628 string param
= toString("id=%d", _MoveToMissionId
);
1629 CAHManager::getInstance()->runActionHandler("mission_ring", 0, param
);
1633 case CUserEntity::CreateGuild
:
1634 CAHManager::getInstance()->runActionHandler("context_create_guild", 0);
1637 case CUserEntity::News
:
1638 CAHManager::getInstance()->runActionHandler("context_talk", 0);
1641 case CUserEntity::TradeTeleport
:
1642 CAHManager::getInstance()->runActionHandler("context_trade_teleport", 0);
1644 // Trade Faction items
1645 case CUserEntity::TradeFaction
:
1646 CAHManager::getInstance()->runActionHandler("context_trade_faction", 0);
1649 case CUserEntity::TradeCosmetic
:
1650 CAHManager::getInstance()->runActionHandler("context_trade_cosmetic", 0);
1653 case CUserEntity::Talk
:
1654 nlwarning("UE:checkMoveTo: not yet implemented");
1657 case CUserEntity::CombatPhrase
:
1658 UserEntity
->attackWithPhrase();
1661 case CUserEntity::Mount
:
1663 string orderStr
= "mount";
1664 string beastIndexStr
= "@UI:GCM_BEAST_SELECTED";
1665 bool confirmFree
= true;
1666 beastOrder(orderStr
,beastIndexStr
,confirmFree
);
1670 case CUserEntity::WebPage
:
1671 CAHManager::getInstance()->runActionHandler("context_web_page", 0);
1674 case CUserEntity::Outpost
:
1675 CLuaManager::getInstance().executeLuaScript("game:outpostBCOpenStateWindow()", 0);
1678 case CUserEntity::BuildTotem
:
1690 //-----------------------------------------------
1692 // Send the position and orientation to the server.
1693 //-----------------------------------------------
1694 bool CUserEntity::sendToServer(CBitMemStream
&out
)
1696 if(GenericMsgHeaderMngr
.pushNameToStream("POSITION", out
))
1698 // Backup the position sent.
1699 if (_Primitive
) _Primitive
->getGlobalPosition(_LastGPosSent
, dynamicWI
);
1700 // Send Position & Orientation
1701 CPositionMsg positionMsg
;
1702 positionMsg
.X
= (sint32
)(pos().x
* 1000);
1703 positionMsg
.Y
= (sint32
)(pos().y
* 1000);
1704 positionMsg
.Z
= (sint32
)(pos().z
* 1000);
1705 positionMsg
.Heading
= frontYaw();
1706 out
.serial(positionMsg
);
1711 nlwarning("UE:sendToServer: unknown message named 'POSITION'.");
1716 //-----------------------------------------------
1717 // msgForCombatPos :
1718 // Fill the msg to know if the user is well placed to fight.
1719 //-----------------------------------------------
1720 bool CUserEntity::msgForCombatPos(NLMISC::CBitMemStream
&out
)
1722 static bool wellPosition
= false;
1726 // Is the user well Placed
1727 CEntityCL
*target
= EntitiesMngr
.entity(UserEntity
->targetSlot());
1729 wellP
= target
->isPlacedToFight(UserEntity
->pos(), front(), attackRadius() + ClientCfg
.AttackDist
);
1731 // If different from the last time
1732 if(wellPosition
!= wellP
)
1734 wellPosition
= wellP
;
1735 // Send state to server.
1736 if(GenericMsgHeaderMngr
.pushNameToStream("COMBAT:VALIDATE_MELEE", out
))
1738 uint8 flag
= wellP
?1:0;
1743 nlwarning("UE:msgForCombatPos: unknown message named 'COMBAT:TOGGLE_COMBAT_FLOAT_MODE'.");
1745 // Do not send the msg.
1747 }// msgForCombatPos //
1750 //-----------------------------------------------
1752 // Check the User Position according to the server code.
1753 // \todo GUIGUI : put checks on GPos
1754 // \todo GUIGUI : refact the check primitive when creating a PACS again
1755 //-----------------------------------------------
1756 void CUserEntity::checkPos()
1758 if(PACS
&& _Primitive
)
1763 UGlobalPosition gPos
;
1764 _Primitive
->getGlobalPosition(gPos
, dynamicWI
);
1766 if(GR
->isWaterPosition(gPos
, waterHeight
))
1768 if(isSwimming() == false)
1770 // Player is Dead set the right mode (swim and dead)
1772 mode(MBEHAV::SWIM_DEATH
);
1775 // Do not swim when in combat mode.
1779 pacsPos(_LastPositionValidated
, _LastGPosValidated
);
1781 // \todo GUIGUI : if the move was cancelled, do not switch to swimming mode.
1782 else if (isRiding())
1784 mode(MBEHAV::MOUNT_SWIM
);
1785 // also change mounted entity mode
1786 CCharacterCL
*mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(_Mount
));
1790 mount
->setMode(MBEHAV::MOUNT_SWIM
);
1791 mount
->computeAutomaton();
1792 mount
->computeAnimSet();
1793 mount
->setAnim(CAnimationStateSheet::Idle
);
1809 mode(MBEHAV::DEATH
);
1811 else if (isRiding())
1813 mode(MBEHAV::MOUNT_NORMAL
);
1814 // also change mounted entity mode
1815 CCharacterCL
*mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(_Mount
));
1819 mount
->setMode(MBEHAV::MOUNT_NORMAL
);
1820 mount
->computeAutomaton();
1821 mount
->computeAnimSet();
1822 mount
->setAnim(CAnimationStateSheet::Idle
);
1827 mode(MBEHAV::NORMAL
);
1833 // Create the Primitive used to check if the move will be accepted by the server
1834 if(_CheckPrimitive
== 0)
1836 _Primitive
->getGlobalPosition(_LastGPosSent
, dynamicWI
);
1837 _Primitive
->getGlobalPosition(_LastGPosValidated
, dynamicWI
);
1838 _CheckPrimitive
= PACS
->addNonCollisionablePrimitive(_Primitive
);
1839 _CheckPrimitive
->setOcclusionMask(MaskColNone
); // Collide with nothing
1840 _CheckPrimitive
->setCollisionMask(MaskColNone
); // Collide with nothing
1841 _LastPositionValidated
= pos();
1845 _CheckPrimitive
->setGlobalPosition(_LastGPosSent
, dynamicWI
);
1846 CVectorD speed
= _Primitive
->getFinalPosition(dynamicWI
) - _CheckPrimitive
->getFinalPosition(dynamicWI
);
1848 _CheckPrimitive
->move(speed
, dynamicWI
);
1849 if(PACS
->evalNCPrimitiveCollision(1.0, _CheckPrimitive
, dynamicWI
) == false)
1850 nlwarning("UE:checkPos: _CheckPrimitive is a collisionable primitive !!!");
1852 CVectorD vectDist
= _Primitive
->getFinalPosition(dynamicWI
) - _CheckPrimitive
->getFinalPosition(dynamicWI
);
1853 if(vectDist
.norm() > 0.001)
1855 // The server will not be able to reproduce this move, restoring the last one.
1857 pacsPos(_LastPositionValidated
,_LastGPosValidated
);
1861 _LastPositionValidated
= _Primitive
->getFinalPosition(dynamicWI
);
1862 _Primitive
->getGlobalPosition(_LastGPosValidated
, dynamicWI
);
1869 //-----------------------------------------------
1871 // test the move from posToTest to current pos
1872 //-----------------------------------------------
1873 bool CUserEntity::testPacsPos( CVectorD
& posToTest
)
1875 if(PACS
&& _Primitive
&& _CheckPrimitive
)
1877 _CheckPrimitive
->setGlobalPosition(posToTest
, dynamicWI
);
1878 CVectorD speed
= _Primitive
->getFinalPosition(dynamicWI
) - _CheckPrimitive
->getFinalPosition(dynamicWI
);
1880 _CheckPrimitive
->move(speed
, dynamicWI
);
1881 if(PACS
->evalNCPrimitiveCollision(1.0, _CheckPrimitive
, dynamicWI
) == false)
1882 nlwarning("UE:testPacsPos: _CheckPrimitive is a collisionable primitive !!!");
1884 CVectorD vectDist
= _Primitive
->getFinalPosition(dynamicWI
) - _CheckPrimitive
->getFinalPosition(dynamicWI
);
1885 if(vectDist
.norm() > 0.001)
1897 //-----------------------------------------------
1899 // Teleport the player (remove selection, re-init checkPos, etc.).
1900 //-----------------------------------------------
1901 void CUserEntity::tp(const CVectorD
&dest
)
1903 // Remove the selection.
1904 UserEntity
->selection(CLFECOMMON::INVALID_SLOT
);
1907 // Update the primitive useful to check the user position.
1908 _LastPositionValidated
= dest
;
1909 // Get the Global position
1912 // this is the last PACS position validated too
1913 _Primitive
->getGlobalPosition(_LastGPosValidated
, dynamicWI
);
1914 // consider this is the last position sent to server (since actually received!)
1915 _Primitive
->getGlobalPosition(_LastGPosSent
, dynamicWI
);
1916 // Set the new position of the 'check' primitive
1918 _CheckPrimitive
->setGlobalPosition(_LastGPosSent
, dynamicWI
);
1921 nlwarning("UE:tp: the entity has a Null primitive.");
1922 // Return to interface mode.
1923 viewMode(UserEntity
->viewMode());
1924 // User well oriented.
1925 dir(UserEntity
->front());
1926 // Set Normal Mode after a teleport.
1927 mode(MBEHAV::NORMAL
);
1928 // Set animation with idle.
1929 setAnim(CAnimationStateSheet::Idle
);
1932 //-----------------------------------------------
1934 // Teleport the player to correct his position.
1935 //-----------------------------------------------
1936 void CUserEntity::correctPos(const NLMISC::CVectorD
&dest
)
1938 nlinfo("UE:correctPos: new user position %f %f %f", dest
.x
, dest
.y
, dest
.z
);
1939 // Change the user poisition.
1940 UserEntity
->pacsPos(dest
);
1941 // Update the primitive useful to check the user position.
1942 _LastPositionValidated
= dest
;
1943 // Get the Global position
1946 // this is the last PACS position validated too
1947 _Primitive
->getGlobalPosition(_LastGPosValidated
, dynamicWI
);
1948 // consider this is the last position sent to server (since actually received!)
1949 _Primitive
->getGlobalPosition(_LastGPosSent
, dynamicWI
);
1950 // Set the new position of the 'check' primitive
1952 _CheckPrimitive
->setGlobalPosition(_LastGPosSent
, dynamicWI
);
1955 nlwarning("UE:correctPos: the entity has a Null primitive.");
1957 // Correct the pos of the mount, if riding
1960 if ( _Mount
< EntitiesMngr
.entities().size() )
1962 CEntityCL
*mount
= EntitiesMngr
.entities()[_Mount
];
1964 mount
->pacsPos( dest
);
1971 * Check if the mount is able to run, and force walking mode if not
1972 * (if the player clicked on run, set back to walk).
1974 void CUserEntity::checkMountAbleToRun()
1980 // Make the mount walk if she's hungry
1981 if ( ! _MountHunger
.canRun() )
1982 switchVelocity( false );
1986 // Make the mount run if she's not hungry anymore
1987 if ( _RunWhenAble
&& _MountHunger
.canRun() )
1988 switchVelocity( false );
1994 //-----------------------------------------------
1995 // Update the position of the entity after the motion.
1996 // \param t : Time for the position of the entity after the motion.
1997 // \param target : pointer on the current target.
1998 //-----------------------------------------------
1999 void CUserEntity::updatePos(const TTime
&t
, CEntityCL
*target
)
2001 // Update Mount if mounting (if _Mount was still not valid when mode received)
2002 if((_Mount
!= CLFECOMMON::INVALID_SLOT
&& isRiding()) && _OnMount
==false)
2006 // External view are managed like other entities.
2007 if(!UserControls
.isInternalView())
2009 // Update position according to the animations.
2010 CPlayerCL::updatePos(t
, target
);
2011 _LastFrameTime
= t
*0.001;
2012 // Set The FPV when indoor.
2013 if(forceIndoorFPV())
2014 viewMode(FirstPV
, false);
2020 // update anim state at least (needed when a spell is cast to play the cast fx at the right time, because they may be visible)
2021 updateAnimationState();
2024 // Compute the Time Step.
2025 double frameTimeRemaining
= computeTimeStep(((double)t
)*0.001);
2026 // Do not update animation if Client Light
2027 if (!ClientCfg
.Light
)
2029 // Attack Animation.
2032 if(animIndex(MOVE
) != ::CAnimation::UnknownAnim
)
2034 if(animOffset(MOVE
) >= EAM
->getAnimationLength(animId(MOVE
)))
2036 _AnimAttackOn
= false;
2037 updateVisualDisplay();
2042 // Increase the time in the current animation.
2043 double previousTimeOffset
= animOffset(MOVE
);
2044 double offset
= previousTimeOffset
+ frameTimeRemaining
;
2045 // Check Anim length
2046 double animLength
= EAM
->getAnimationLength(animId(MOVE
));
2047 if(offset
> animLength
)
2048 animOffset(MOVE
, animLength
);
2050 animOffset(MOVE
, offset
);
2051 // Manage Events that could be created by the animation (like sound).
2052 animEventsProcessing(previousTimeOffset
, animOffset(MOVE
));
2054 // Get the right pos from PACS.
2055 if(_Primitive
&& GR
)
2057 UGlobalPosition gPos
;
2058 _Primitive
->getGlobalPosition(gPos
, dynamicWI
);
2060 // Set the new current pos.
2061 pos(GR
->getGlobalPosition(gPos
));
2063 // Set the direction.
2064 if( ClientCfg
.AutomaticCamera
)
2068 // Reset the TPV when outdoor if needed.
2069 if(_Primitive
&& GR
)
2071 UGlobalPosition gPos
;
2072 _Primitive
->getGlobalPosition(gPos
, dynamicWI
);
2073 if(!GR
->isInterior(gPos
))
2075 viewMode(ThirdPV
, false);
2077 // Current time is now the entity time too.
2078 _LastFrameTime
= t
*0.001;
2081 //-----------------------------------------------
2083 // Update the PACS position after the evalCollision. The entity position is set too. This is fast.
2084 // If the entity position is too far from its PACS position, setGlobalPosition is called.
2085 // After this call, the position.z is valid.
2086 //-----------------------------------------------
2087 void CUserEntity::pacsFinalizeMove() // virtual
2092 // Get the global position
2093 _FinalPacsPos
= _Primitive
->getFinalPosition(dynamicWI
);
2095 // Get the global position
2096 UGlobalPosition gPos
;
2097 _Primitive
->getGlobalPosition(gPos
, dynamicWI
);
2098 if(gPos
.InstanceId
!= -1)
2101 if(_Mount
!= CLFECOMMON::INVALID_SLOT
)
2103 CEntityCL
*mount
= EntitiesMngr
.entity(_Mount
);
2105 mount
->pacsPos(pos());
2109 _SetGlobalPositionDone
= false;
2110 }// pacsFinalizeMove //
2113 //-----------------------------------------------
2115 // Apply the behaviour for the user.
2116 //-----------------------------------------------
2117 void CUserEntity::applyBehaviour(const CBehaviourContext
&behaviourContext
) // virtual
2119 const MBEHAV::CBehaviour
&behaviour
= behaviourContext
.Behav
;
2120 // Special code for the First Person View
2121 if((viewMode() == FirstPV
) && behaviour
.isCombat())
2123 // Backup the current behaviour.
2124 _CurrentBehaviour
= behaviourContext
.Behav
;
2127 // check if self-target
2128 bool selfSpell
= false;
2129 if (behaviourContext
.Targets
.Targets
.size() == 1)
2131 if (behaviourContext
.Targets
.Targets
[0].TargetSlot
== 0)
2137 switch(behaviour
.Behaviour
)
2139 case MBEHAV::CAST_OFF
:
2140 case MBEHAV::CAST_OFF_FAIL
:
2141 case MBEHAV::CAST_OFF_SUCCESS
:
2142 case MBEHAV::CAST_OFF_LINK
:
2150 // Default target hit dates
2151 static vector
<double> targetHitDates
;
2152 targetHitDates
.clear();
2153 targetHitDates
.resize(behaviourContext
.Targets
.Targets
.size(), TimeInSec
);
2155 // cast projectiles/impact linked to behaviour
2156 updateCurrentAttack();
2157 if (isCurrentBehaviourAttackEnd())
2159 // In First Person (don't care), use a default animation => will choose a default delay of 0.5
2160 performCurrentAttackEnd(behaviourContext
, selfSpell
&& isOffensif
,
2161 targetHitDates
, CAnimationStateSheet::UnknownState
);
2164 _RightFXActivated
= false;
2165 _LeftFXActivated
= false;
2168 animState (MOVE
, CAnimationStateSheet::FirstPersonAttack
);
2169 animIndex (MOVE
, CAnimation::UnknownAnim
);
2170 animOffset(MOVE
, 0.0);
2171 _CurrentState
= EAM
->mState(_CurrentAutomaton
, animState(MOVE
));
2172 if(_CurrentState
&& _CurrentAnimSet
[MOVE
])
2174 const CAnimationState
*animStatePtr
= _CurrentAnimSet
[MOVE
]->getAnimationState(animState(MOVE
));
2177 animIndex(MOVE
, animStatePtr
->chooseAnim(_AnimJobSpecialisation
, people(), getGender(), 0.0));
2178 if(animIndex(MOVE
) != CAnimation::UnknownAnim
)
2182 _PlayList
->setAnimation (MOVE
, animId(MOVE
));
2183 _PlayList
->setTimeOrigin (MOVE
, ryzomGetLocalTime ()*0.001);//_LastFrameTime);
2184 _AnimAttackOn
= true;
2185 updateVisualDisplay();
2191 // Start FX to play at the animation beginning like trails.
2192 if(_CurrentBehaviour
.Behaviour
== MBEHAV::RANGE_ATTACK
)
2194 startItemAttackFXs(_CurrentBehaviour
.Range
.ImpactIntensity
!= 0, _CurrentBehaviour
.Range
.ImpactIntensity
);
2198 startItemAttackFXs(_CurrentBehaviour
.Combat
.ImpactIntensity
!= 0 && _CurrentBehaviour
.Combat
.HitType
!= HITTYPE::Failed
, _CurrentBehaviour
.Combat
.ImpactIntensity
);
2201 applyBehaviourFlyingHPs(behaviourContext
, behaviour
, targetHitDates
);
2203 // In third person view (or camera mode), play the same way than for the others.
2205 CPlayerCL::applyBehaviour(behaviourContext
);
2206 }// applyBehaviour //
2208 //---------------------------------------------------
2210 // Method to Flag the character as dead and do everything needed.
2211 //---------------------------------------------------
2212 void CUserEntity::setDead() // virtual
2214 // User is dead -> NO FOLLOW
2216 // Remove the selection.
2217 UserEntity
->selection(CLFECOMMON::INVALID_SLOT
);
2218 // Death Mode Control and view.
2219 UserControls
.mode(CUserControls::DeathMode
);
2220 // Play the FX for the death
2221 NL3D::UParticleSystemInstance deathFX
= FXMngr
.instantFX(ClientCfg
.DeadFXName
);
2222 if(!deathFX
.empty())
2223 deathFX
.setPos(selectBox().getCenter());
2225 // Last teleport is a death
2227 // get player's kami fame
2228 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
2230 uint kamiFameIndex
= CStaticFames::getInstance().getFactionIndex("kami");
2231 if (pIM
&& kamiFameIndex
!= CStaticFames::INVALID_FACTION_INDEX
)
2233 CCDBNodeLeaf
*pLeafKamiFame
= NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:FAME:PLAYER%d:VALUE", kamiFameIndex
- 1), false);
2234 if (pLeafKamiFame
!= NULL
)
2235 kamiFame
= pLeafKamiFame
->getValue8();
2238 // get player's karavan fame
2239 sint8 karavanFame
= 0;
2240 uint karavanFameIndex
= CStaticFames::getInstance().getFactionIndex("karavan");
2241 if (pIM
&& karavanFameIndex
!= CStaticFames::INVALID_FACTION_INDEX
)
2243 CCDBNodeLeaf
*pLeafKaravanFame
= NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:FAME:PLAYER%d:VALUE", karavanFameIndex
- 1), false);
2244 if (pLeafKaravanFame
!= NULL
)
2245 karavanFame
= pLeafKaravanFame
->getValue8();
2248 // set loading background depending on player's faction fame
2249 if (kamiFame
> karavanFame
)
2250 LoadingBackground
= ResurectKamiBackground
;
2252 LoadingBackground
= ResurectKaravanBackground
;
2254 // disable or enable shadowing
2255 updateCastShadowMap();
2257 // enable death warning popup
2258 //CInterfaceManager * pIM = CInterfaceManager::getInstance();
2261 CAHManager::getInstance()->runActionHandler("set",NULL
,"dblink=UI:VARIABLES:DEATH_WARNING_WANTED|value=1");
2265 //-----------------------------------------------
2268 //-----------------------------------------------
2269 void CUserEntity::skillUp()
2271 // Play the FX for the death
2272 NL3D::UParticleSystemInstance skillUpFX
= FXMngr
.instantFX(ClientCfg
.SkillUpFXName
);
2273 skillUpFX
.setClusterSystem(getClusterSystem());
2274 if(!skillUpFX
.empty())
2275 skillUpFX
.setPos(pos());
2278 //-----------------------------------------------
2280 // After a few time, if the user is still in collision with someone else, remove collisions with other entitites.
2281 //-----------------------------------------------
2282 void CUserEntity::startColTimer()
2286 if(_ColRemoved
==false)
2288 if((T1
-_ColStartTime
) > ClientCfg
.TimeToRemoveCol
)
2290 EntitiesMngr
.removeColUserOther();
2300 }// startColTimer //
2302 //-----------------------------------------------
2304 // Called when the user is no more in collision with another entity.
2305 //-----------------------------------------------
2306 void CUserEntity::stopColTimer()
2308 // Restore collisions.
2311 EntitiesMngr
.restoreColUserOther();
2312 _ColRemoved
= false;
2319 //-----------------------------------------------
2321 // Return the current max speed for the entity in meter per sec
2322 // The method return a max according to the speed factor (given by the server)
2323 // It's also return a value according to the landscape (water)
2324 // Also managed mounts
2325 //-----------------------------------------------
2326 double CUserEntity::getMaxSpeed() const // virtual
2328 // Max Defined speed according to the current factor (slow, or speed increased)
2329 double maxSpeed
= _SpeedFactor
.getValue();
2341 else if(isSwimming())
2344 // We are a Ring DM so speed up a litle
2345 if (_R2CharMode
== R2::TCharMode::Editer
|| _R2CharMode
== R2::TCharMode::Dm
)
2347 maxSpeed
*= ClientCfg
.DmRun
/ 2;
2357 // Run if mount not hungry, otherwise, use walk velocity
2358 if (_MountHunger
.canRun())
2359 maxSpeed
*= (double)getMountRunVelocity();
2361 maxSpeed
*= (double)getMountWalkVelocity();
2366 maxSpeed
*= runVelocity();
2368 // Return the current max
2370 // return ClientCfg.Run * _SpeedFactor.getValue();
2374 //-----------------------------------------------
2376 // Snap the user to the ground.
2377 //-----------------------------------------------
2378 void CUserEntity::snapToGround()
2380 CEntityCL::snapToGround();
2382 updateSound (ryzomGetLocalTime ());
2383 }// // snapToGround //
2386 //-----------------------------------------------
2388 //-----------------------------------------------
2389 void CUserEntity::updateSound(const TTime
&time
)
2391 H_AUTO_USE ( RZ_Client_Update_Sound
);
2393 // no sound manager, no need to update sound
2394 if (SoundMngr
== NULL
)
2397 if (!(StereoHMD
&& true)) // TODO: ClientCfg.Headphone
2399 // NOTE: StereoHMD+Headphone impl in main_loop.cpp
2400 SoundMngr
->setListenerPos(pos());
2401 const CMatrix
&camMat
= MainCam
.getMatrix();
2402 SoundMngr
->setListenerOrientation(camMat
.getJ(), camMat
.getK());
2405 if (ClientCfg
.Light
)
2408 // step sound of self : refind the sound animations associated to the walk and run animation
2410 static bool computeAnim
= true;
2411 static bool lastMode
= false;
2412 static TTime previousTime
= 0;
2413 static TTime stepTime
= 0;
2414 static bool leftRight
= false;
2415 static NLSOUND::CSoundAnimMarker
*leftStep
= 0;
2416 static NLSOUND::CSoundAnimMarker
*rightStep
= 0;
2418 // TODO : Remove when bug corrected:
2419 if (_Gender
== GSGENDER::unknown
)
2421 nlwarning("CUserEntity::updateSound : The gender is unknown, forcing it to male");
2422 _Gender
= GSGENDER::male
;
2425 // force recompute of anim if walk/run change.
2426 computeAnim
= computeAnim
|| (lastMode
!= _Run
);
2428 // Check the sound animation to find the time between to step
2429 if(computeAnim
&& SoundMngr
&& _CurrentAnimSet
[MOVE
] != 0) // && _SoundId[MOVE] != NLSOUND::CSoundAnimationNoId)
2432 TAnimStateId mode
= _Run
? CAnimationStateSheet::Run
: CAnimationStateSheet::Walk
;
2433 const CAnimationState
*animStatePtr
= _CurrentAnimSet
[MOVE
]->getAnimationState (mode
);
2436 ::CAnimation::TAnimId animId
= animStatePtr
->chooseAnim (_AnimJobSpecialisation
, people(), getGender(), 0);
2437 if (animId
!= ::CAnimation::UnknownAnim
)
2439 const ::CAnimation
*anim
= animStatePtr
->getAnimation (animId
);
2442 // Select the sound ID
2443 _SoundId
[MOVE
] = anim
->soundId();
2445 if (_SoundId
[MOVE
] != NLSOUND::CSoundAnimationNoId
)
2447 // retrieve the anim
2448 NLSOUND::CSoundAnimManager
*mgr
= NLSOUND::CSoundAnimManager::instance();
2450 string name
= mgr
->idToName(_SoundId
[MOVE
]);
2454 NLSOUND::CSoundAnimation
*sanim
= mgr
->findAnimation(name
);
2455 if (sanim
->countMarkers() != 2)
2457 static set
<string
> warnOnce
;
2458 if (warnOnce
.find(sanim
->getName()) == warnOnce
.end())
2460 nlwarning("Sound animation '%s' has not 2 markers, not a biped ? (Display Once)", sanim
->getName().c_str());
2461 warnOnce
.insert(sanim
->getName());
2466 stepTime
= TTime((sanim
->getMarker(1)->getTime() - sanim
->getMarker(0)->getTime()) * 1000);
2467 rightStep
= sanim
->getMarker(0);
2468 leftStep
= sanim
->getMarker(1);
2469 computeAnim
= false;
2478 if( SoundMngr
&& _Mode
== MBEHAV::NORMAL
)
2480 if (!getVelocity().isNull())
2482 if (stepTime
> 0 && time
-previousTime
>=stepTime
)
2484 previousTime
= time
;
2486 // set the sound 1 meter below listener
2487 _SoundContext
.Position
= pos() + CVector(0,0,-1);
2488 _SoundContext
.RelativeGain
= SoundMngr
->getUserEntitySoundLevel();;
2490 uint32 matId
= getGroundType();
2491 //nldebug("Current material = %u", matId);
2492 _SoundContext
.Args
[0] = matId
;
2497 // TODO : find the correct cluster
2498 leftStep
->play(SoundMngr
->getMixer(), NULL
, _SoundContext
);
2503 // TODO : find the correct cluster
2504 rightStep
->play(SoundMngr
->getMixer(), NULL
, _SoundContext
);
2506 // recompute a new sound anim
2510 leftRight
= !leftRight
;
2515 // resets the counter
2522 //-----------------------------------------------
2524 // rotate the body on the left or right (front changes).
2525 //-----------------------------------------------
2526 void CUserEntity::rotate(float ang
)
2532 front(m
* front().normed());
2536 //-----------------------------------------------
2537 // rotHeadVertically :
2538 // rotate the head vertically.
2539 //-----------------------------------------------
2540 void CUserEntity::rotHeadVertically(float ang
)
2542 setHeadPitch(_HeadPitch
+ang
);
2543 }// rotHeadVertically //
2546 //-----------------------------------------------
2547 // setHeadPitch(double hp)
2548 //-----------------------------------------------
2549 void CUserEntity::setHeadPitch(double hp
)
2552 const double bound
= Pi
/2 - 0.01; // epsilon to avoid gimbal lock
2553 clamp(_HeadPitch
, -bound
, bound
);
2556 //---------------------------------------------------
2558 // To Inform about an entity removed (to remove from selection for example).
2559 // This will remove the entity from the target.
2560 // \param slot : Slot of the entity that will be removed.
2561 //---------------------------------------------------
2562 void CUserEntity::slotRemoved(const CLFECOMMON::TCLEntityId
&slot
)
2565 CPlayerCL::slotRemoved(slot
);
2567 // reset also selection
2568 if(selection() == slot
)
2569 selection(CLFECOMMON::INVALID_SLOT
);
2572 //---------------------------------------------------
2574 // Change the entity selected.
2575 // \param slot : slot now selected (CLFECOMMON::INVALID_SLOT for an empty selection).
2576 // \warning Can be different from the entity targeted (in combat mode for example).
2577 //---------------------------------------------------
2578 void CUserEntity::selection(const CLFECOMMON::TCLEntityId
&slot
) // virtual
2580 //allows reselection in Ring client: even if the selected slots is equal to the selection,
2581 //the client must send the messages.
2582 if ((_Selection
== slot
) && !ClientCfg
.R2EDEnabled
)
2585 // The selection will be the entity to watch
2586 WatchedEntitySlot
= slot
;
2589 // Send the entity selected to the server.
2590 NetMngr
.pushTarget(slot
);
2593 // Target the slot on client, don't wait NetWork response
2595 _TargetSlotNoLag
= slot
;
2597 if (ClientCfg
.R2EDEnabled
)
2599 R2::getEditor().inGameSelection(slot
);
2603 // Change the current selection so un color the current selection.
2604 CEntityCL
*sel
= EntitiesMngr
.entity(_Selection
);
2606 sel
->visualSelectionStop(); // Blink off == restore to normal
2608 // Set the entity selected
2611 // Update visual selection and interface
2612 if ( sel
&& sel
->isForageSource() )
2613 sel
->buildInSceneInterface(); // remove focus on previous selected source
2614 sel
= EntitiesMngr
.entity(_Selection
);
2617 sel
->visualSelectionStart();
2618 if ( sel
->isForageSource() )
2619 sel
->buildInSceneInterface(); // set focus on new selected source
2623 // **** Update Target interface
2624 //get the new target slot and set it in the database
2625 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
2626 NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:TARGET:SLOT")->setValue64(slot
);
2628 // Get the new target UID, and set in Database
2629 uint tgtSlot
= _Selection
;
2630 uint32 tgtEntityId
= CLFECOMMON::INVALID_CLIENT_DATASET_INDEX
;
2631 CEntityCL
*entity
= NULL
;
2632 if (tgtSlot
!=CLFECOMMON::INVALID_SLOT
)
2634 entity
= EntitiesMngr
.entity(tgtSlot
);
2636 tgtEntityId
= entity
->dataSetId();
2639 // Set the User Target
2640 CCDBNodeLeaf
*prop
= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:TARGET:UID", false);
2642 prop
->setValue32(tgtEntityId
);
2644 // Bar Manager. Update now the Target View (so it takes VP if data available or 0... but result is immediate)
2645 CBarManager::getInstance()->setLocalTarget(tgtEntityId
);
2647 // **** Update DB for InGameMenu
2648 // clear the entries for mission option
2649 for(uint k
= 0; k
< NUM_MISSION_OPTIONS
; ++k
)
2651 CCDBNodeLeaf
*missionOption
= NLGUI::CDBManager::getInstance()->getDbProp(toString("LOCAL:TARGET:CONTEXT_MENU:MISSIONS_OPTIONS:%d:TITLE", (int) k
), false);
2654 missionOption
->setValue32(0);
2656 CCDBNodeLeaf
*playerGiftNeeded
= NLGUI::CDBManager::getInstance()->getDbProp(toString("LOCAL:TARGET:CONTEXT_MENU:MISSIONS_OPTIONS:%d:PLAYER_GIFT_NEEDED", (int) k
), false);
2657 if (playerGiftNeeded
)
2659 playerGiftNeeded
->setValue32(0);
2662 /* TODO ULU : Add RP tags */
2665 if ((tgtSlot
!=CLFECOMMON::INVALID_SLOT
) && entity
)
2667 CPlayerCL
*pPlayer
= dynamic_cast<CPlayerCL
*>(entity
);
2672 CViewBitmap * tagMode = dynamic_cast<CViewBitmap*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:target:pvp_tags:mode"));
2675 if (pPlayer->getPvpMode()&PVP_MODE::PvpFaction)
2676 tagMode->setTexture("pvp_orange.tga");
2677 else if (pPlayer->getPvpMode()&PVP_MODE::PvpFactionFlagged)
2678 tagMode->setTexture("pvp_red.tga");
2680 tagMode->setTexture("alpha_10.tga");
2683 /*// Pvp available actions (attack, heal, both)
2684 CViewBitmap * tagMode = dynamic_cast<CViewBitmap*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:target:pvp_tags:actions"));
2687 if (pPlayer->getPvpMode()&PVP_MODE::PvpFaction)
2688 tag->setTexture("pvp_orange.tga");
2689 else if (pPlayer->getPvpMode()&PVP_MODE::PvpFactionFlagged)
2690 tag->setTexture("pvp_red.tga");
2692 tag->setTexture("alpha_10.tga");
2699 prop
= NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:TARGET:CONTEXT_MENU:WEB_PAGE_URL", false);
2700 if(prop
) prop
->setValue32(0);
2701 prop
= NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:TARGET:CONTEXT_MENU:WEB_PAGE_TITLE", false);
2702 if(prop
) prop
->setValue32(0);
2704 // clear mission ring
2705 for(uint k
= 0; k
< BOTCHATTYPE::MaxR2MissionEntryDatabase
; ++k
)
2707 prop
= NLGUI::CDBManager::getInstance()->getDbProp(toString("LOCAL:TARGET:CONTEXT_MENU:MISSION_RING:%d:TITLE", k
), false);
2708 if(prop
) prop
->setValue32(0);
2712 prop
= NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:TARGET:CONTEXT_MENU:PROGRAMMES", false);
2713 if(prop
) prop
->setValue32(0);
2714 prop
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:TARGET:CONTEXT_MENU:PROGRAMMES");
2715 if(prop
) prop
->setValue32(0);
2716 // increment db counter for context menu
2717 pIM
->incLocalSyncActionCounter();
2721 //---------------------------------------------------
2723 // Method to place the user to attack the target and attack.
2724 //---------------------------------------------------
2725 void CUserEntity::moveToAttack()
2727 // **** For clarity, try to launch a "default attack" found in the memory bar instead of an "anonymous" action
2728 CSPhraseManager
*pPM
= CSPhraseManager::getInstance();
2729 uint32 memLine
, memSlot
;
2730 CEntityCL
*target
= EntitiesMngr
.entity(selection());
2732 CInventoryManager
*inv
= CInventoryManager::getInstance();
2734 // auto-equip with valid weapon
2735 if( ClientCfg
.AutoEquipTool
)
2739 // if no valid weapons in had -> auto-equip with last used weapons
2740 bool validWeaponInHand
= true;
2741 uint32 rightHandSheet
= inv
->getRightHandItemSheet();
2744 validWeaponInHand
= inv
->isMeleeWeaponItem(rightHandSheet
) || inv
->isRangeWeaponItem(rightHandSheet
);
2746 if( !validWeaponInHand
)
2748 autoEquipWithLastUsedWeapons();
2751 // remember last used weapon(s)
2752 rememberWeaponsInHand();
2756 if(target
&& pPM
->findDefaultAttack(memLine
, memSlot
))
2758 // launch instead a phrase execution with this phrase
2759 executeCombatWithPhrase(target
, memLine
, memSlot
, true);
2761 // **** Else launch an anonymous "default attack"
2768 uint32 rightHandSheet
= inv
->getRightHandItemSheet();
2770 melee
= inv
->isMeleeWeaponItem(rightHandSheet
);
2773 // Move to target if melee weapon
2775 moveTo(selection(), 2.0, CUserEntity::Attack
);
2776 // Just attack if range weapon.
2782 //---------------------------------------------------
2784 // Method to attack the target.
2785 //---------------------------------------------------
2786 void CUserEntity::attack()
2788 // execute the default attack
2789 CSPhraseManager
*pPM
= CSPhraseManager::getInstance();
2790 pPM
->executeDefaultAttack();
2793 CInventoryManager
*inv
= CInventoryManager::getInstance();
2796 uint32 rightHandSheet
= inv
->getRightHandItemSheet();
2798 melee
= inv
->isMeleeWeaponItem(rightHandSheet
);
2801 // If option ON, follow when attacking.
2802 if(ClientCfg
.FollowOnAtk
)
2804 // Follow only if attacking with a melee weapon
2806 // enable, but don't reset camera rotation
2807 enableFollow(false);
2811 //---------------------------------------------------
2813 // Method to attack the target, with a special phrase
2814 //---------------------------------------------------
2815 void CUserEntity::attackWithPhrase()
2817 if( !canEngageCombat() )
2820 CSPhraseManager
*pPM
= CSPhraseManager::getInstance();
2822 // validate the execution on server
2823 pPM
->sendExecuteToServer(_MoveToPhraseMemoryLine
, _MoveToPhraseMemorySlot
, _MoveToPhraseCyclic
);
2825 // If the Attack is a "Next", and not a cycle, do a default attack
2826 if(!_MoveToPhraseCyclic
)
2827 pPM
->executeDefaultAttack();
2829 // If option ON, follow when attacking.
2830 if(ClientCfg
.FollowOnAtk
)
2833 CInventoryManager
*inv
= CInventoryManager::getInstance();
2836 uint32 rightHandSheet
= inv
->getRightHandItemSheet();
2838 melee
= inv
->isMeleeWeaponItem(rightHandSheet
);
2840 // Follow only if attacking with a melee weapon
2842 // enable, but don't reset camera rotation
2843 enableFollow(false);
2846 // Because sendExecuteToServer() has been called, must NOT cancelClientExecute() at resetAnyMoveTo()
2847 _MoveToAction
= CUserEntity::None
;
2850 //-----------------------------------------------
2852 // your current target become the target of your current one.
2853 //-----------------------------------------------
2854 void CUserEntity::assist()
2856 assist(targetSlot());
2859 //-----------------------------------------------
2861 void CUserEntity::assist(uint slot
)
2863 // Check the current target
2864 if(slot
== CLFECOMMON::INVALID_SLOT
|| slot
== _Slot
)
2867 CEntityCL
*target
= EntitiesMngr
.entity(slot
);
2870 // Check the new slot.
2871 CLFECOMMON::TCLEntityId newSlot
= target
->targetSlot();
2872 if(newSlot
== CLFECOMMON::INVALID_SLOT
|| newSlot
== _Slot
)
2874 // Select the new target.
2878 //---------------------------------------------------
2880 // Method to disengage the target.
2881 //---------------------------------------------------
2882 void CUserEntity::disengage()
2884 // Set the database in local.
2887 IngameDbMngr
.setProp("Entities:E0:P" + toString(CLFECOMMON::PROPERTY_MODE
), MBEHAV::NORMAL
); // Mode
2888 IngameDbMngr
.setProp("Entities:E0:P" + toString(CLFECOMMON::PROPERTY_TARGET_ID
), _Selection
); // Target
2889 UserEntity
->updateVisualProperty(0, CLFECOMMON::PROPERTY_MODE
);
2890 UserEntity
->updateVisualProperty(0, CLFECOMMON::PROPERTY_TARGET_ID
);
2895 const string msgName
= "COMBAT:DISENGAGE";
2897 if(GenericMsgHeaderMngr
.pushNameToStream(msgName
, out
))
2900 nlwarning("UE::disengage: unknown message named '%s'.", msgName
.c_str());
2902 // Change the current mode.
2903 mode(MBEHAV::NORMAL
);
2906 //-----------------------------------------------
2908 // Ask for the client to sit/stand ('true' to sit).
2909 //-----------------------------------------------
2910 bool CUserEntity::sit(bool s
)
2917 if(canSit() == true)
2923 if(mode(MBEHAV::SIT
))
2925 // autowalk disabled
2926 UserControls
.autowalkState(false);
2928 static const string msgName
= "COMMAND:SIT";
2930 if(GenericMsgHeaderMngr
.pushNameToStream(msgName
, out
))
2936 nlwarning("UE:sit: unknown message named '%s'.", msgName
.c_str());
2942 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
2943 string msg
= CI18N::get("msgUserIsSitting");
2944 string cat
= getStringCategory(msg
, msg
);
2945 pIM
->displaySystemInfo(msg
, cat
);
2952 if(_Mode
== MBEHAV::SIT
)
2954 if(mode(MBEHAV::NORMAL
))
2956 static const string msgName
= "COMMAND:SIT";
2958 if(GenericMsgHeaderMngr
.pushNameToStream(msgName
, out
))
2964 nlwarning("UE:sit: unknown message named '%s'.", msgName
.c_str());
2969 // display stand msg
2970 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
2971 string msg
= CI18N::get("msgUserIsStanding");
2972 string cat
= getStringCategory(msg
, msg
);
2973 pIM
->displaySystemInfo(msg
, cat
);
2978 // if mode changed, Write to the UI database, to update views
2981 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
2982 CCDBNodeLeaf
*node
= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:PLAYER_STAND", false);
2984 node
->setValue32(_Mode
!= MBEHAV::SIT
);
2991 //-----------------------------------------------
2993 // Return true if the user can sit.
2994 //-----------------------------------------------
2995 bool CUserEntity::canSit() const
2997 // If the user is not already sitting or is on a mount
2998 if(!isSit() && (!isRiding()) && !isDead() && !isSwimming())
3006 //-----------------------------------------------
3008 //-----------------------------------------------
3009 void CUserEntity::setAFK(bool b
, string afkTxt
)
3011 if( isAFK() == b
) return;
3015 if( isDead() || isRiding() || moveTo() || follow() )
3018 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
3019 //sint64 start = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_TSTART")->getValue64();
3020 //sint64 end = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_TEND")->getValue64();
3021 //sint64 type = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_TYPE")->getValue64();
3022 //sint64 num = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_NUMBER")->getValue64();
3025 if( NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_TYPE")->getValue64() != 0 )
3029 if( !isSit() && !isSwimming() )
3031 if( !mode(MBEHAV::REST
) )
3037 if( !isSit() && !isSwimming() )
3042 mode(MBEHAV::NORMAL
);
3047 static const string msgName
= "COMMAND:AFK";
3049 if(GenericMsgHeaderMngr
.pushNameToStream(msgName
, out
))
3055 nlwarning("CUserEntity:setAFK: unknown message named '%s'.", msgName
.c_str());
3058 ucstring ucstr
; // TODO: UTF-8 (serial)
3059 ucstr
.fromUtf8( afkTxt
);
3060 CBitMemStream outTxt
;
3061 static const string msgNameTxt
= "STRING:AFK_TXT";
3062 if( GenericMsgHeaderMngr
.pushNameToStream(msgNameTxt
,outTxt
) )
3064 outTxt
.serial( ucstr
);
3065 NetMngr
.push( outTxt
);
3069 nlwarning("CUserEntity:setAFK: unknown message named '%s'.", msgNameTxt
.c_str());
3075 //-----------------------------------------------
3077 //-----------------------------------------------
3078 void CUserEntity::rollDice(sint16 min
, sint16 max
, bool local
)
3082 // no need to broadcast over network here
3083 static NLMISC::CRandom
* dice
= (NLMISC::CRandom
*)NULL
;
3086 dice
= new NLMISC::CRandom
;
3087 dice
->srand(CTickEventHandler::getGameCycle());
3089 sint16 roll
= min
+ (sint16
)dice
->rand(max
-min
);
3091 string msg
= CI18N::get("msgRollDiceLocal");
3092 strFindReplace(msg
, "%min", toString(min
));
3093 strFindReplace(msg
, "%max", toString(max
));
3094 strFindReplace(msg
, "%roll", toString(roll
));
3096 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
3098 pIM
->displaySystemInfo(msg
, getStringCategory(msg
, msg
));
3101 const string msgName
= "COMMAND:RANDOM";
3103 if (GenericMsgHeaderMngr
.pushNameToStream(msgName
, out
))
3110 nlwarning("CUserEntity:rollDice: unknown message named '%s'.", msgName
.c_str());
3113 //---------------------------------------------------
3114 // canEngageCombat :
3115 // return true if user can engage melee combat, else return false and display system msg
3116 //---------------------------------------------------
3117 bool CUserEntity::canEngageCombat()
3121 // display "you can't fight while sitting" message)
3122 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
3123 string msg
= CI18N::get("msgCantFightSit");
3124 string cat
= getStringCategory(msg
, msg
);
3125 pIM
->displaySystemInfo(msg
, cat
);
3132 // display "you can't fight while swiming" message)
3133 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
3134 string msg
= CI18N::get("msgCantFightSwim");
3135 string cat
= getStringCategory(msg
, msg
);
3136 pIM
->displaySystemInfo(msg
, cat
);
3143 // display "you can't fight while swimming" message)
3144 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
3145 string msg
= CI18N::get("msgCantFightRide");
3146 string cat
= getStringCategory(msg
, msg
);
3147 pIM
->displaySystemInfo(msg
, cat
);
3153 } // canEngageCombat //
3156 //---------------------------------------------------
3158 // Change the View (First/Third Person View).
3159 //---------------------------------------------------
3160 void CUserEntity::viewMode(CUserEntity::TView viewMode
, bool changeView
)
3164 // First Person View
3167 ClientCfg
.FPV
= true;
3168 if(_Mount
!= CLFECOMMON::INVALID_SLOT
)
3170 CEntityCL
*mount
= EntitiesMngr
.entity(_Mount
);
3172 mount
->displayable(false);
3174 _HiddenMount
= _Mount
;
3179 bool autoWalk
= UserControls
.autowalkState();
3180 UserControls
.mode(CUserControls::MountMode
);
3182 UserControls
.autowalkState( true );
3185 UserControls
.mode(CUserControls::InterfaceMode
);
3188 // Third Person View
3191 ClientCfg
.FPV
= false;
3193 if(_HiddenMount
!= CLFECOMMON::INVALID_SLOT
)
3195 CEntityCL
*mount
= EntitiesMngr
.entity(_HiddenMount
);
3197 mount
->displayable(true);
3199 _HiddenMount
= CLFECOMMON::INVALID_SLOT
;
3202 UserControls
.mode(CUserControls::ThirdMode
);
3207 nlwarning("UE:viewMode: Unknown View Asked '%d'.", (sint
)viewMode
);
3211 // Change the current View like asked.
3212 _ViewMode
= viewMode
;
3214 // disable or enable shadowing
3215 updateCastShadowMap();
3218 //-----------------------------------------------
3220 // Toggle Camera (First/Third Person)
3221 //-----------------------------------------------
3222 void CUserEntity::toggleCamera()
3224 // You cannot change the camera view when dead.
3227 // Only if not inside a building.
3228 if(!UserEntity
->forceIndoorFPV())
3230 // Leave the 1st Person Mode -> Enter the 3rd Person View Mode
3231 if (UserEntity
->viewMode() == CUserEntity::FirstPV
)
3232 UserEntity
->viewMode(CUserEntity::ThirdPV
);
3233 // Leave the 3rd Person Mode -> Enter the 1st Person View Mode
3235 UserEntity
->viewMode(CUserEntity::FirstPV
);
3239 //-----------------------------------------------
3240 // forceCameraFirstPerson :
3241 // Force Camera to First Person View
3242 //-----------------------------------------------
3243 void CUserEntity::forceCameraFirstPerson()
3245 // You cannot change the camera view when dead.
3248 // Only if not inside a building.
3249 if(!UserEntity
->forceIndoorFPV())
3251 if (UserEntity
->viewMode() != CUserEntity::FirstPV
)
3252 //Enter the 1st Person View Mode
3253 UserEntity
->viewMode(CUserEntity::FirstPV
);
3255 }// forceCameraFirstPerson //
3257 //---------------------------------------------------
3259 // Return the entity scale. (return 1.0 if there is any problem).
3260 // \todo GUIGUI : do we have to take care of the user's race kwnowing it can favour him ?
3261 //---------------------------------------------------
3262 float CUserEntity::getScale() const // virtual
3268 //---------------------------------------------------
3269 // removeCheckPrimitive :
3270 // Remove the check primitive
3271 //---------------------------------------------------
3272 void CUserEntity::removeCheckPrimitive()
3274 if(PACS
&& _CheckPrimitive
)
3275 PACS
->removePrimitive(_CheckPrimitive
);
3276 _CheckPrimitive
= 0;
3279 //---------------------------------------------------
3280 // removePrimitive :
3281 // Remove the primitive
3282 //---------------------------------------------------
3283 void CUserEntity::removePrimitive() // virtual (will not be called by ~CEntityCL())
3285 // Remove the Primitive used for check
3286 removeCheckPrimitive();
3288 // Remove the other primitive
3289 CPlayerCL::removePrimitive();
3290 }// removePrimitive //
3292 //---------------------------------------------------
3293 // computePrimitive :
3294 // Create a primitive for the entity.
3295 //---------------------------------------------------
3296 void CUserEntity::computePrimitive() // virtual
3298 // Initialize the primitive.
3299 if(initPrimitive(0.5f
, 2.0f
, 0.0f
, 0.0f
, UMovePrimitive::Slide
, (UMovePrimitive::TTrigger
)(UMovePrimitive::OverlapTrigger
| UMovePrimitive::EnterTrigger
), MaskColPlayer
, MaskColPlayer
| MaskColNpc
| MaskColDoor
))
3300 _Primitive
->insertInWorldImage(dynamicWI
);
3301 // Set the position.
3303 }// computePrimitive //
3306 //---------------------------------------------------
3308 // Return if the user is already busy (combat/bo chat/loot/ etc.).
3309 //---------------------------------------------------
3310 bool CUserEntity::isBusy() const
3312 CInterfaceManager
*IM
= CInterfaceManager::getInstance ();
3315 // TODO : put the right DB entry !
3317 CCDBNodeLeaf
*nod
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:INVENTORY:EXCHANGE:BEGUN", false);
3320 if(nod
->getValueBool())
3324 // nlwarning("UE:isBusy: Cannot get the nod 'SERVER:INVENTORY:EXCHANGE:BEGUN'.");
3328 static const uint nbSlot = 4;
3330 for(i=0; i<nbSlot; ++i)
3332 nod = NLGUI::CDBManager::getInstance()->getDbProp(NLMISC::toString("SERVER:INVENTORY:%d:%d:SHEET", INVENTORIES::pickup, i), false);
3335 if(nod->getValue32() != 0)
3339 nlwarning("UE:isBusy: Cannot get the nod 'SERVER:INVENTORY:%d:%d:SHEET'.", INVENTORIES::pickup, i);
3343 for(i=0; i<nbSlot; ++i)
3345 nod = NLGUI::CDBManager::getInstance()->getDbProp(NLMISC::toString("SERVER:INVENTORY:%d:%d:SHEET", INVENTORIES::harvest, i), false);
3348 if(nod->getValue32() != 0)
3352 nlwarning("UE:isBusy: Cannot get the nod 'SERVER:INVENTORY:%d:%d:SHEET'.", INVENTORIES::harvest, i);
3357 CBotChatPage
* currPage
= CBotChatManager::getInstance()->getCurrPage();
3358 if( currPage
!= NULL
)
3368 //---------------------------------------------------
3369 // updateVisualDisplay :
3370 // Show/Hide all or parts of the user body.
3371 // todo GUIGUI : it's bad for the _Face to be a separated instance
3372 //---------------------------------------------------
3373 void CUserEntity::updateVisualDisplay()
3375 // We need a skeleton.
3376 if(_Skeleton
.empty())
3380 if(UserControls
.isInternalView() || View
.forceFirstPersonView())
3383 if (_Mount
!= CLFECOMMON::INVALID_SLOT
)
3385 CCharacterCL
*mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(_Mount
));
3387 mount
->displayable(false);
3389 _HiddenMount
= _Mount
;
3391 else if (_HiddenMount
!= CLFECOMMON::INVALID_SLOT
)
3393 // not on mount anymore, but still in FPV
3394 CCharacterCL
*mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(_HiddenMount
));
3396 mount
->displayable(true);
3398 _HiddenMount
= CLFECOMMON::INVALID_SLOT
;
3401 // Hide all user body parts.
3402 for(uint i
=0; i
<_Instances
.size(); ++i
)
3403 if(!_Instances
[i
].Current
.empty())
3405 _Instances
[i
].Current
.hide();
3406 _Instances
[i
].hideStaticFXs();
3409 if(!_Face
.Current
.empty())
3410 _Face
.Current
.hide();
3412 // We want to display weapons in 1st person view when attacking.
3413 if(modeWithHiddenItems() == false)
3415 if( _Mode
== MBEHAV::COMBAT_FLOAT
|| _Mode
== MBEHAV::COMBAT
)
3417 if( _ObjectsVisible
)
3419 // Show just Few parts
3420 if(!_Instances
[SLOTTYPE::HANDS_SLOT
].Current
.empty())
3422 _Instances
[SLOTTYPE::HANDS_SLOT
].Current
.show();
3423 _Instances
[SLOTTYPE::HANDS_SLOT
].showStaticFXs();
3425 if(!_Instances
[SLOTTYPE::ARMS_SLOT
].Current
.empty())
3427 _Instances
[SLOTTYPE::ARMS_SLOT
].Current
.show();
3428 _Instances
[SLOTTYPE::ARMS_SLOT
].showStaticFXs();
3430 if(!_Instances
[SLOTTYPE::RIGHT_HAND_SLOT
].Current
.empty())
3432 _Instances
[SLOTTYPE::RIGHT_HAND_SLOT
].Current
.show();
3433 _Instances
[SLOTTYPE::RIGHT_HAND_SLOT
].showStaticFXs();
3435 if(!_Instances
[SLOTTYPE::LEFT_HAND_SLOT
].Current
.empty())
3437 _Instances
[SLOTTYPE::LEFT_HAND_SLOT
].Current
.show();
3438 _Instances
[SLOTTYPE::LEFT_HAND_SLOT
].showStaticFXs();
3447 CCharacterCL
*mount
= dynamic_cast<CCharacterCL
*>(EntitiesMngr
.entity(_Mount
));
3450 mount
->displayable(true);
3452 showOrHideBodyParts( objectsVisible() );
3457 if(!_Face.Current.empty())
3458 _Face.Current.show();
3461 }// updateVisualDisplay //
3463 //---------------------------------------------------
3465 // Show/Hide the user light.
3466 //---------------------------------------------------
3467 void CUserEntity::light()
3472 // Check there is a skeleton and a bone to stick the light before to create it.
3473 if(!_Skeleton
.empty() && _NameBoneId
!=-1)
3475 _Light
= Scene
->createPointLight();
3478 // front of the player
3479 _Light
.setPos(0.f
,0.3f
,0.f
);
3481 _Light
.setupAttenuation(12.0f
, 20.0f
);
3483 _Skeleton
.stickObject(_Light
, _NameBoneId
);
3484 // The player light is the only one who can interact with Lightmapped objects
3485 _Light
.setInfluenceLightMap(true);
3489 NL3D::UInstance inst;
3490 inst= Scene->createInstance("box.shape");
3493 inst.setScale(0.2f, 0.2f, 0.2f);
3494 inst.parent(_Light);
3500 nlwarning("UE:light: there is no skeleton or Name Bone to stick the light.");
3502 // Turn On/Off the Light
3503 _LightOn
= !_LightOn
;
3513 //---------------------------------------------------
3514 // CSpeedFactor::init :
3515 // Initialize the Observer for the Speed Factor.
3516 //---------------------------------------------------
3517 void CUserEntity::CSpeedFactor::init()
3519 _Value
= 1.0f
; // Default speed factor is 1.
3520 _ServerFactor
= 1.0f
;
3521 CInterfaceManager
*IM
= CInterfaceManager::getInstance ();
3522 CCDBNodeLeaf
*pNodeLeaf
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:SPEED_FACTOR", false);
3525 /* if(!pNodeLeaf->addToLeaves(this))
3526 nlwarning("UE:SP:init: cannot add the observer");*/
3527 ICDBNode::CTextId textId
;
3528 pNodeLeaf
->addObserver(this, textId
);
3529 if ( pNodeLeaf
->getValue64() != 0 )
3530 _Value
= ((float)pNodeLeaf
->getValue64())/100.0f
; // may have been received before
3533 nlwarning("UE:SP:init: 'SERVER:USER:SPEED_FACTOR' does not exist.");
3534 }// CSpeedFactor::init //
3536 //---------------------------------------------------
3537 // CMountHunger::init :
3538 //---------------------------------------------------
3539 void CUserEntity::CMountHunger::init()
3542 //---------------------------------------------------
3543 // CMountSpeeds::init :
3544 //---------------------------------------------------
3545 void CUserEntity::CMountSpeeds::init()
3547 CInterfaceManager
*IM
= CInterfaceManager::getInstance ();
3548 CCDBNodeLeaf
*pNodeLeaf
= NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:USER:MOUNT_WALK_SPEED", false );
3549 BOMB_IF( ! pNodeLeaf
, "MOUNT_WALK_SPEED not found", return );
3552 ICDBNode::CTextId textId
;
3553 pNodeLeaf
->addObserver(this, textId
);
3554 _WalkSpeed
= ((float)pNodeLeaf
->getValue32()) / 1000.0f
; // may have been received before
3556 pNodeLeaf
= NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:USER:MOUNT_RUN_SPEED", false );
3557 BOMB_IF( ! pNodeLeaf
, "MOUNT_RUN_SPEED not found", return );
3560 ICDBNode::CTextId textId
;
3561 pNodeLeaf
->addObserver(this, textId
);
3562 _RunSpeed
= ((float)pNodeLeaf
->getValue32()) / 1000.0f
; // may have been received before
3566 //---------------------------------------------------
3568 void CUserEntity::CSpeedFactor::release()
3570 CInterfaceManager
*IM
= CInterfaceManager::getInstance ();
3571 CCDBNodeLeaf
*pNodeLeaf
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:SPEED_FACTOR", false);
3574 /* if(!pNodeLeaf->addToLeaves(this))
3575 nlwarning("UE:SP:init: cannot add the observer");*/
3576 ICDBNode::CTextId textId
;
3577 pNodeLeaf
->removeObserver(this, textId
);
3580 nlwarning("UE:SP:init: 'SERVER:USER:SPEED_FACTOR' does not exist.");
3581 }// CSpeedFactor::init //
3583 void CUserEntity::CMountHunger::release()
3586 void CUserEntity::CMountSpeeds::release()
3588 CInterfaceManager
*IM
= CInterfaceManager::getInstance ();
3589 CCDBNodeLeaf
*pNodeLeaf
= NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:USER:MOUNT_WALK_SPEED", false );
3590 BOMB_IF( ! pNodeLeaf
, "MOUNT_WALK_SPEED not found", return );
3593 ICDBNode::CTextId textId
;
3594 pNodeLeaf
->removeObserver(this, textId
);
3596 pNodeLeaf
= NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:USER:MOUNT_RUN_SPEED", false );
3597 BOMB_IF( ! pNodeLeaf
, "MOUNT_RUN_SPEED not found", return );
3600 ICDBNode::CTextId textId
;
3601 pNodeLeaf
->removeObserver(this, textId
);
3606 //---------------------------------------------------
3607 // CSpeedFactor::update :
3608 // Callback called to update the speed factor.
3609 //---------------------------------------------------
3610 void CUserEntity::CSpeedFactor::update(ICDBNode
*node
) // virtual
3612 CCDBNodeLeaf
*leaf
= safe_cast
<CCDBNodeLeaf
*>(node
);
3613 _Value
= ((float)leaf
->getValue64())/100.0f
;
3614 //nlinfo("SpeedFactor changed to %f / %" NL_I64 "u", _Value, leaf->getValue64());
3616 // clamp the value (2.0 is the egg item or the level 6 speed up power up, nothing should be faster)
3617 // commented because ring editor speed is in fact faster
3620 //nlwarning("HACK: you try to change the speed factor to %f", _Value);
3624 }// CSpeedFactor::update //
3628 * Return true if the mount can run. Precondition: UserEntity->isRiding().
3630 bool CUserEntity::CMountHunger::canRun() const
3632 CEntityCL
*mountEntity
= UserEntity
->getMountEntity();
3633 if ( ! mountEntity
)
3636 // Find the mount's db leaf and check hunger
3637 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
3638 CCDBNodeBranch
*animalsNode
= safe_cast
<CCDBNodeBranch
*>(NLGUI::CDBManager::getInstance()->getDB()->getNode( ICDBNode::CTextId( "SERVER:PACK_ANIMAL" ), false ));
3639 BOMB_IF( ! animalsNode
, "! animalsNode", return false; );
3640 uint nbAnimals
= (uint
)animalsNode
->getNbNodes();
3641 for ( uint i
=0; i
!=nbAnimals
; ++i
)
3643 ICDBNode
*beastNode
= animalsNode
->getNode( i
);
3644 CCDBNodeLeaf
*uidLeaf
= safe_cast
<CCDBNodeLeaf
*>(beastNode
->getNode( ICDBNode::CTextId( "UID" ) ));
3645 if ( ((CLFECOMMON::TClientDataSetIndex
)uidLeaf
->getValue32()) == mountEntity
->dataSetId() )
3647 CCDBNodeLeaf
*hungerLeaf
= safe_cast
<CCDBNodeLeaf
*>(beastNode
->getNode( ICDBNode::CTextId( "HUNGER" ) ));
3648 return (hungerLeaf
->getValue32() != (sint
)ANIMAL_TYPE::DbHungryValue
);
3656 //---------------------------------------------------
3657 // CMountSpeeds::update :
3658 // Callback called to update the mount speed.
3659 //---------------------------------------------------
3660 void CUserEntity::CMountSpeeds::update(ICDBNode
* /* node */) // virtual
3662 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
3663 _WalkSpeed
= ((float)(NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:MOUNT_WALK_SPEED")->getValue32())) / 1000.0f
;
3664 _RunSpeed
= ((float)(NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:MOUNT_RUN_SPEED")->getValue32())) / 1000.0f
;
3669 * Return the mount entity if the user is riding, otherwise NULL
3671 CEntityCL
* CUserEntity::getMountEntity()
3673 if ( _Mount
< EntitiesMngr
.entities().size() )
3675 return EntitiesMngr
.entities()[_Mount
];
3681 * Return the DB entry for the specified user's animal (NULL if not found)
3683 CCDBNodeBranch
*CUserEntity::getBeastDBEntry( CLFECOMMON::TClientDataSetIndex uid
)
3685 // Find animal entry corresponding to datasetId
3686 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
3687 CCDBNodeBranch
*animalsNode
= safe_cast
<CCDBNodeBranch
*>(NLGUI::CDBManager::getInstance()->getDB()->getNode( ICDBNode::CTextId( "SERVER:PACK_ANIMAL" ), false ));
3688 BOMB_IF( ! animalsNode
, "! animalsNode", return NULL
);
3689 uint nbAnimals
= (uint
)animalsNode
->getNbNodes();
3690 for ( uint i
=0; i
!=nbAnimals
; ++i
)
3692 ICDBNode
*beastNode
= animalsNode
->getNode( i
);
3693 CCDBNodeLeaf
*pNodeLeaf
= safe_cast
<CCDBNodeLeaf
*>(beastNode
->getNode( ICDBNode::CTextId( "UID" ) ));
3694 if ( pNodeLeaf
&& (pNodeLeaf
->getValue32() == (sint32
)uid
) )
3695 return (CCDBNodeBranch
*)beastNode
;
3701 //---------------------------------------------------
3703 // Display Debug Information.
3704 //---------------------------------------------------
3705 void CUserEntity::displayDebug(float x
, float &y
, float lineStep
) // virtual
3707 CPlayerCL::displayDebug(x
, y
, lineStep
);
3710 //---------------------------------------------------
3711 // displayModifiers :
3712 // Display dmg/heal numbers above the head.
3713 //---------------------------------------------------
3714 void CUserEntity::displayModifiers() // virtual
3716 if(!UserControls
.isInternalView())
3717 CPlayerCL::displayModifiers();
3718 }// displayModifiers //
3720 //---------------------------------------------------
3722 // Return 'true' is the entity is displayed.
3723 //---------------------------------------------------
3724 bool CUserEntity::isVisible() const // virtual
3726 return !UserControls
.isInternalView();
3734 //---------------------------------------------------
3736 // Read/Write Variables from/to the stream.
3737 //---------------------------------------------------
3738 void CUserEntity::readWrite(NLMISC::IStream
&f
)
3740 CPlayerCL::readWrite(f
);
3743 f
.serial(_SpeedFactor
);
3744 f
.serial(_FrontVelocity
);
3745 f
.serial(_LateralVelocity
);
3747 f
.serial(dummyHead
);
3748 f
.serial(_HeadPitch
);
3749 f
.serial(_EyesHeight
);
3751 f
.serial(_WalkVelocity
);
3752 f
.serial(_RunVelocity
);
3753 f
.serial(_CurrentVelocity
);
3754 f
.serial(_Selection
);
3756 f
.serial(_Interlocutor
);
3757 f
.serial(_Selectable
);
3761 f
.serial(_AnimAttackOn
);
3762 // f.serialEnum(_ViewMode);
3765 //---------------------------------------------------
3767 // To call after a read from a stream to re-initialize the entity.
3768 //---------------------------------------------------
3769 void CUserEntity::load() // virtual
3771 CInterfaceManager
*IM
= CInterfaceManager::getInstance ();
3772 // Insert the user into PACS at his saved position
3776 if(!_WaitForAppearance
)
3778 // Visual properties A
3779 sint64 prop
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", _Slot
)+":P"+toString("%d", CLFECOMMON::PROPERTY_VPA
))->getValue64();
3780 updateVisualPropertyVpa(0, prop
); // Vpa udapte vpb and vpc too.
3785 //---------------------------------------------------
3786 void CUserEntity::CInvisibleObserver::update(ICDBNode
* node
)
3788 UserEntity
->buildInSceneInterface();
3791 //---------------------------------------------------
3792 void CUserEntity::CSkillPointsObserver::update(ICDBNode
* node
)
3794 if (FarTP
.isFarTPInProgress() || IngameDbMngr
.initInProgress()) // prevent from displaying at the beginning of a FarTP (due to RESET_BANK or CDB resetData())
3797 CInterfaceManager
*pIM
= CInterfaceManager::getInstance ();
3798 CCDBNodeLeaf
*leaf
= dynamic_cast<CCDBNodeLeaf
*>(node
);
3801 sint32 oldValue
= leaf
->getOldValue32();
3804 sint delta
= leaf
->getValue32()-oldValue
;
3805 string deltaStr
= toString("%+d", delta
);
3808 const string
&spTitle
= CI18N::get(toString("uiSkillPointsBold%d",SpType
));
3811 CAHManager::getInstance()->runActionHandler("message_popup", NULL
, "text1="+deltaStr
+"|text0="+spTitle
);
3814 contextHelp ("skill_point");
3820 //---------------------------------------------------
3821 // CFameObserver::update
3822 //---------------------------------------------------
3823 void CUserEntity::CFameObserver::update(ICDBNode
* node
)
3825 CSkillManager
*pSM
= CSkillManager::getInstance();
3826 CCDBNodeLeaf
*leaf
= dynamic_cast<CCDBNodeLeaf
*>(node
);
3829 sint32 fameValue
= leaf
->getValue32();
3830 pSM
->tryToUnblockTitleFromMinFames( FactionIndex
, fameValue
);
3831 pSM
->tryToUnblockTitleFromMaxFames( FactionIndex
, fameValue
);
3836 //---------------------------------------------------
3837 void CUserEntity::makeTransparent(bool t
)
3839 CPlayerCL::makeTransparent(t
);
3841 uint32 opaMin
= getOpacityMin();
3842 uint8 opacity
= (uint8
)(opaMin
+ (255-opaMin
) * (1.0 - _TranspFactor
));
3844 getFace()->makeInstanceTransparent(opacity
, (uint8
)opaMin
);
3845 }// makeTransparent //
3847 //---------------------------------------------------
3848 void CUserEntity::setDiffuse(bool onOff
, NLMISC::CRGBA diffuse
)
3850 CPlayerCL::setDiffuse(onOff
, diffuse
);
3851 getFace()->setDiffuse(onOff
, diffuse
);
3857 // Helper for CUserEntity::extractRM()
3858 bool findExtractionActionInMemory( CSPhraseManager
*pm
, CSBrickManager
*bm
, uint memoryLine
, uint
& index
)
3861 for ( x
=0; x
!=PHRASE_MAX_MEMORY_SLOT
; ++x
)
3863 uint32 phraseSlot
= pm
->getMemorizedPhrase( memoryLine
, x
);
3864 const CSPhraseCom
& phraseCom
= pm
->getPhrase( phraseSlot
);
3865 if ( ! phraseCom
.empty() )
3867 CSBrickSheet
*brickSheet
= bm
->getBrick( phraseCom
.Bricks
[0] );
3868 if ( brickSheet
->isForageExtraction() && (!brickSheet
->MandatoryFamilies
.empty()) ) // assumes care root bricks have not mandatories
3878 //---------------------------------------------------
3879 void CUserEntity::extractRM()
3881 CSPhraseManager
*pm
= CSPhraseManager::getInstance();
3884 bool autoFindPhrase
= (_MoveToPhraseMemoryLine
== std::numeric_limits
<uint
>::max());
3885 if ( ! autoFindPhrase
)
3887 // Use clicked phrase
3888 memoryLine
= _MoveToPhraseMemoryLine
;
3889 index
= _MoveToPhraseMemorySlot
;
3893 // Find the first extraction phrase in the memory bar
3894 CSBrickManager
*bm
= CSBrickManager::getInstance();
3895 memoryLine
= pm
->getSelectedMemoryLineDB();
3896 if ( ! findExtractionActionInMemory( pm
, bm
, memoryLine
, index
) )
3898 // Search in other memory bar lines (because the auto-equip does not set the current line at once)
3899 memoryLine
= std::numeric_limits
<uint
>::max();
3900 uint nbLines
= pm
->getNbMemoryLines();
3901 for ( uint j
=0; j
!=nbLines
; ++j
)
3903 if ( j
== memoryLine
)
3905 if ( findExtractionActionInMemory( pm
, bm
, j
, index
) )
3914 if ( memoryLine
!= std::numeric_limits
<uint
>::max() )
3916 // Open the forage (but not for care actions). Necessary for the case of redoing an extraction after a Drop All on the same source.
3917 uint32 phraseId
= pm
->getMemorizedPhrase( memoryLine
, index
);
3918 if ( phraseId
!= 0 )
3920 const CSPhraseCom
& phraseCom
= pm
->getPhrase( phraseId
);
3921 if ( ! phraseCom
.empty() )
3923 CSBrickSheet
*rootBrick
= CSBrickManager::getInstance()->getBrick( phraseCom
.Bricks
[0] );
3926 if ( rootBrick
->IndexInFamily
== 1 ) // only extracting actions
3927 CTempInvManager::getInstance()->open( TEMP_INV_MODE::Forage
);
3932 // Cast the extraction. if autoFindPhrase, clientExecute() not already called.
3933 if ( autoFindPhrase
)
3935 // decide now if cyclic or not
3936 _MoveToPhraseCyclic
= true;
3937 if(pm
->avoidCyclicForPhrase(pm
->getMemorizedPhrase(memoryLine
, index
)))
3938 _MoveToPhraseCyclic
= false;
3940 // execute on client now
3941 pm
->clientExecute( memoryLine
, index
, _MoveToPhraseCyclic
);
3944 // execute on server
3945 pm
->sendExecuteToServer( memoryLine
, index
, _MoveToPhraseCyclic
);
3947 // Because sendExecuteToServer() has been called, must NOT cancelClientExecute() at resetAnyMoveTo()
3948 _MoveToAction
= CUserEntity::None
;
3952 CInterfaceManager::getInstance()->displaySystemInfo( CI18N::get("uiExtractionPhraseMissing"), "CHK" );
3958 // ***************************************************************************
3959 bool CUserEntity::canCastShadowMap() const
3961 if(!CCharacterCL::canCastShadowMap())
3964 // don't cast shadow in first person, but in death mode (third person actually...)
3965 return viewMode() != FirstPV
|| UserControls
.mode() == CUserControls::DeathMode
;
3969 // ***************************************************************************
3970 void CUserEntity::forceLookEntity(const NLMISC::CVectorD
&dir2targIn
, bool updateHeadPitch
, bool /* start */)
3972 CVectorD dir2targ
= dir2targIn
;
3973 float frontYawBefore
= 0.f
;
3974 float frontYawAfter
;
3976 // Third person: bkup current yaw
3977 if(viewMode()==ThirdPV
)
3979 frontYawBefore
= frontYaw();
3983 // **** Look at the entity
3984 dir2targ
.normalize();
3985 front(dir2targ
, false, false);
3989 if(viewMode() == FirstPV
)
3991 if(updateHeadPitch
&& _FollowForceHeadPitch
)
3993 // rotate the head to the target
3994 CEntityCL
*target
= EntitiesMngr
.entity(targetSlot());
3997 // Both Z must be correct
3999 target
->snapToGround();
4001 // don't update to the real head position each frame (else jitter too much cause of target anim)
4002 CVector targetPos
= target
->pos() + CVector(0,0,_FollowHeadOffset
);
4004 // then look at this target
4005 CVector dirToTarget
= targetPos
- (pos()+CVector(0,0, UserEntity
->eyesHeight()));
4006 if((dirToTarget
.x
!= 0.0f
) || (dirToTarget
.y
!=0.0f
))
4008 dirToTarget
.normalize();
4009 setHeadPitch(atan2(dirToTarget
.z
, sqrt(sqr(dirToTarget
.x
)+sqr(dirToTarget
.y
))));
4013 /*if(ClientCfg.Fly!=0.f)
4015 nlinfo("Uy: %.3f. Hp: %.3f. UPos:(%.3f,%.3f,%.3f). TPos:(%.3f,%.3f,%.3f)",
4016 UserEntity->frontYaw(), UserEntity->getHeadPitch(), pos().x, pos().y, pos().z,
4017 targetPos.x, targetPos.y, targetPos.z);
4018 static float uy=0.f;
4019 static float hp=0.f;
4020 if( fabs(fmod(UserEntity->frontYaw()-uy, 2*Pi))>ClientCfg.Fly ||
4021 fabs(fmod(UserEntity->getHeadPitch()-hp, 2*Pi))>ClientCfg.Fly )
4023 nlinfo("YOYOBREAK: ^^^^^^^^^^");
4025 uy=UserEntity->frontYaw();
4026 hp=UserEntity->getHeadPitch();
4031 // **** Third person
4032 else if(viewMode()==ThirdPV
)
4034 // keep the current effective yaw. ONLY if no SmoothResetCameraYaw forced
4035 if(!UserControls
.isResetSmoothCDYForced())
4037 frontYawAfter
= frontYaw();
4038 float deltaYaw
= frontYawAfter
- frontYawBefore
;
4040 // compensate rotation (NB: it stops also any SmoothReset)
4041 UserControls
.appendCameraDeltaYaw(-deltaYaw
);
4045 // when looking to an entity, if automatic camera, center the view on it.
4046 if( ClientCfg
.AutomaticCamera
/*&& start*/ )
4048 UserControls
.resetSmoothCameraDeltaYaw();
4053 // ***************************************************************************
4054 void CUserEntity::startForceLookEntity(CLFECOMMON::TCLEntityId slot
)
4056 // Start a new follow: force head pitch to follow by default
4057 _FollowForceHeadPitch
= true;
4058 // if a follow is started in first person, reset CameraYaw
4059 if(viewMode()==FirstPV
)
4060 UserControls
.resetCameraDeltaYaw();
4062 // reorient now (important else may have a time shift because of resetCameraDeltaYaw above)
4063 CEntityCL
*target
= EntitiesMngr
.entity(slot
);
4066 /* For complex reason, the target may not be still snapped on the ground. snap it now
4067 - this is because in common case, entities are snap only if they are visible (for speed up)
4068 => depends on camera
4069 - but in this case, the camera depends on real entity position (headPitch in first person)
4071 target
->snapToGround();
4073 // For FirstPerson targeting. Get the current target head offset
4074 _FollowHeadOffset
= 0.f
;
4076 if(target
->getHeadPos(headPos
))
4078 _FollowHeadOffset
= headPos
.z
- float(target
->pos().z
);
4081 // Look at the entity
4082 CVectorD dir2targ
= target
->pos() - pos();
4084 if(dir2targ
!=CVectorD::Null
)
4086 forceLookEntity(dir2targ
, true, true);
4092 // ***************************************************************************
4093 void CUserEntity::stopForceHeadPitchInFollow()
4095 _FollowForceHeadPitch
= false;
4098 // ***************************************************************************
4099 void CUserEntity::switchVelocity(bool userRequest
)
4101 if (ClientCfg
.R2EDEnabled
&& R2::getEditor().getMode() == R2::CEditor::EditionMode
)
4103 // when in the R2 editor, force to run all the time
4110 _CurrentVelocity
= _Run
? runVelocity() : walkVelocity();
4114 _RunWhenAble
= _Run
;
4117 // display message : your are running, you are walking
4118 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
4121 msg
= CI18N::get("msgUserIsRunning");
4123 msg
= CI18N::get("msgUserIsWalking");
4124 string cat
= getStringCategory(msg
, msg
);
4125 pIM
->displaySystemInfo(msg
, cat
);
4127 // Write to the UI database, to update views
4128 CCDBNodeLeaf
*node
= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:PLAYER_RUNNING", false);
4130 node
->setValue32(_Run
);
4133 //-----------------------------------------------
4134 // autoEquipWithLastUsedWeapons
4136 //-----------------------------------------------
4137 void CUserEntity::autoEquipWithLastUsedWeapons()
4139 CInventoryManager
*inv
= CInventoryManager::getInstance();
4146 inv
->unequip( "LOCAL:INVENTORY:HAND:1" );
4147 inv
->unequip( "LOCAL:INVENTORY:HAND:0" );
4151 if( _PreviousRightHandItem
.Sheet
!= 0 )
4153 // find item in bag with same properties than last used one in right hand
4154 for ( ir
=0; ir
<MAX_BAGINV_ENTRIES
; ++ir
)
4156 if( _PreviousRightHandItem
.Sheet
== inv
->getBagItem(ir
).getSheetID() &&
4157 _PreviousRightHandItem
.Quality
== inv
->getBagItem(ir
).getQuality() &&
4158 _PreviousRightHandItem
.Weight
== inv
->getBagItem(ir
).getWeight() &&
4159 _PreviousRightHandItem
.NameId
== inv
->getBagItem(ir
).getNameId() )
4164 if ( ir
!= MAX_BAGINV_ENTRIES
)
4167 string bagPath
= toString( "LOCAL:INVENTORY:BAG:%u", ir
);
4168 inv
->equip( bagPath
, "LOCAL:INVENTORY:HAND:0" );
4170 // Equip left hand if needed
4171 if( _PreviousLeftHandItem
.Sheet
!= 0 )
4173 for ( il
=0; il
<MAX_BAGINV_ENTRIES
; ++il
)
4176 _PreviousLeftHandItem
.Sheet
== inv
->getBagItem(il
).getSheetID() &&
4177 _PreviousLeftHandItem
.Quality
== inv
->getBagItem(il
).getQuality() &&
4178 _PreviousLeftHandItem
.Weight
== inv
->getBagItem(il
).getWeight() &&
4179 _PreviousLeftHandItem
.NameId
== inv
->getBagItem(il
).getNameId() )
4184 if ( il
!= MAX_BAGINV_ENTRIES
)
4186 bagPath
= toString( "LOCAL:INVENTORY:BAG:%u", il
);
4187 inv
->equip( bagPath
, "LOCAL:INVENTORY:HAND:1" );
4195 // TODO : choose the best one
4200 // ***************************************************************************
4201 void CUserEntity::executeCombatWithPhrase(CEntityCL
*target
, uint32 memoryLine
, uint32 memoryIndex
, bool cyclic
)
4204 CSPhraseManager
*pPM
= CSPhraseManager::getInstance();
4206 // is a melee combat?
4207 bool meleeCombat
= false;
4208 // empty hand => yes!
4210 uint32 rightHandSheet
= getInventory().getRightHandItemSheet();
4212 meleeCombat
= getInventory().isMeleeWeaponItem(rightHandSheet
);
4214 // If melee combat, and if the user entity is not well placed for fight, or if it has changed his target
4217 !target
->isPlacedToFight(pos(), front(), attackRadius() + ClientCfg
.AttackDist
) ||
4218 target
->slot()!=_LastExecuteCombatSlot
4222 _LastExecuteCombatSlot
= target
->slot();
4224 // Cancel any follow
4227 // Launch the moveToCombatPhrase, canceling any old action client execution.
4228 // NB: this will also force him to look at the entity
4229 moveToCombatPhrase(target
->slot(), 2.0, memoryLine
, memoryIndex
, cyclic
);
4231 // And after (order is important), start the phrase execution on client
4232 pPM
->clientExecute(memoryLine
, memoryIndex
, cyclic
);
4236 // Cancel any moveTo(), because don't want to continue reaching the prec entity
4237 // VERY important if previous MoveTo was a SPhrase MoveTo (because cancelClientExecute() must be called)
4240 // start client execution: NB: start client execution even if it
4241 pPM
->clientExecute(memoryLine
, memoryIndex
, cyclic
);
4243 // inform Server of phrase cast
4244 pPM
->sendExecuteToServer(memoryLine
, memoryIndex
, cyclic
);
4246 if( !meleeCombat
&& !cyclic
)
4248 pPM
->executeDefaultAttack();
4253 // ***************************************************************************
4254 void CUserEntity::beginCast(const MBEHAV::CBehaviour
&behaviour
)
4256 if(viewMode()==ThirdPV
)
4259 float frontYawBefore
= frontYaw();
4261 CCharacterCL::beginCast( behaviour
);
4262 // compensate the front change using a camera move
4263 float frontYawAfter
= frontYaw();
4264 float deltaYaw
= frontYawAfter
- frontYawBefore
;
4265 UserControls
.appendCameraDeltaYaw(-deltaYaw
);
4266 // if automatic camera, center the view behind the user
4267 if( ClientCfg
.AutomaticCamera
)
4269 UserControls
.resetSmoothCameraDeltaYaw();
4274 // in first person mode, reset the delta yaw
4275 UserControls
.resetCameraDeltaYaw();
4276 CCharacterCL::beginCast( behaviour
);
4280 // ***************************************************************************
4281 void CUserEntity::updatePreCollision(const NLMISC::TTime
&time
, CEntityCL
*target
)
4283 CPlayerCL::updatePreCollision(time
, target
);
4285 // test each frame if the mode has changed
4288 // Play/stop music if comes from or goes to dead
4289 bool isDead
= _Mode
== MBEHAV::DEATH
|| _Mode
== MBEHAV::SWIM_DEATH
;
4291 // must start music?
4292 if (isDead
&& SoundMngr
->getEventMusicPlayed() != ClientCfg
.DeathMusic
)
4294 SoundMngr
->playEventMusic(ClientCfg
.DeathMusic
, 0, true);
4298 if (!isDead
&& SoundMngr
->getEventMusicPlayed() == ClientCfg
.DeathMusic
)
4300 SoundMngr
->stopEventMusic(ClientCfg
.DeathMusic
, CSoundManager::LoadingMusicXFade
);
4305 // ***************************************************************************
4306 void CUserEntity::buildTotem()
4308 const string msgName
= "TOTEM:BUILD";
4310 if( GenericMsgHeaderMngr
.pushNameToStream( msgName
, out
) )
4312 NetMngr
.push( out
);
4313 nlinfo( "sending TOTEM:build message to server" );
4317 // ***************************************************************************
4318 void CUserEntity::setR2CharMode(R2::TCharMode mode
)
4320 if (mode
== R2::TCharMode::Editer
|| mode
== R2::TCharMode::Dm
)
4323 walkVelocity(ClientCfg
.DmWalk
);
4324 runVelocity(ClientCfg
.DmRun
);
4325 View
.setCameraDistanceMaxForDm();
4326 CEntityCL
*user
= EntitiesMngr
.entity(0);
4327 NLPACS::UMovePrimitive
* prim
= user
?user
->getPrimitive():0;
4330 prim
->setObstacle(false);
4334 else if (mode
== R2::TCharMode::Player
|| mode
== R2::TCharMode::Tester
)
4337 walkVelocity(ClientCfg
.Walk
);
4338 runVelocity(ClientCfg
.Run
);
4339 View
.setCameraDistanceMaxForPlayer();
4340 CEntityCL
*user
= EntitiesMngr
.entity(0);
4341 NLPACS::UMovePrimitive
* prim
= user
?user
->getPrimitive():0;
4344 prim
->setObstacle(true);
4349 nlwarning("R2Ed: Error Char Mode not handled %u", (uint32
)mode
.getValue());
4353 bool CUserEntity::isInNpcControl() const
4355 CInterfaceManager
* pIM
= CInterfaceManager::getInstance();
4356 CCDBNodeLeaf
*sheet
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:NPC_CONTROL:SHEET", false);
4357 return sheet
&& NLMISC::CSheetId(sheet
->getValue32())!=NLMISC::CSheetId::Unknown
;
4361 void CUserEntity::updateNpcContolSpeed()
4363 CInterfaceManager
* pIM
= CInterfaceManager::getInstance();
4364 CCDBNodeLeaf
*sheet
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:NPC_CONTROL:SHEET", false);
4365 CCDBNodeLeaf
*walk
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:NPC_CONTROL:WALK", false);
4366 CCDBNodeLeaf
*run
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:NPC_CONTROL:RUN", false);
4367 if (!sheet
|| !walk
|| !run
)
4372 static NLMISC::CSheetId oldSheet
= NLMISC::CSheetId::Unknown
;
4373 static float oldRun
=0.f
;
4374 static float oldWalk
=0.f
;
4376 NLMISC::CSheetId
sheetId(sheet
->getValue32());
4377 float newRun
= float(run
->getValue32()) / 1000.0f
;
4378 float newWalk
= float(walk
->getValue32()) / 1000.0f
;
4380 if (sheetId
== oldSheet
&& oldRun
== newRun
&& oldWalk
== newWalk
)
4389 if (sheetId
!= NLMISC::CSheetId::Unknown
)
4391 walkVelocity(newWalk
);
4392 runVelocity(newRun
);
4396 setR2CharMode(_R2CharMode
);
4401 //-----------------------------------------------
4403 //-----------------------------------------------
4404 void CUserEntity::cancelAllPhrases()
4407 if(GenericMsgHeaderMngr
.pushNameToStream("PHRASE:CANCEL_ALL", out
))
4413 nlwarning("<CUserEntity::cancelAllPhrases> unknown message name '%s'", "PHRASE:CANCEL_ALL");
4418 //-----------------------------------------------
4420 //-----------------------------------------------
4421 bool CUserEntity::canChangeFront()
4423 return !(_CurrentBehaviour
.Behaviour
== MBEHAV::EXTRACTING
4424 || (_CurrentBehaviour
.Behaviour
== MBEHAV::RANGE_ATTACK
&& _Mode
==MBEHAV::COMBAT
&& !UserControls
.isMoving())
4425 || (_CurrentBehaviour
.Behaviour
>= MBEHAV::MAGIC_CASTING_BEHAVIOUR_BEGIN
&& _CurrentBehaviour
.Behaviour
<= MBEHAV::MAGIC_CASTING_BEHAVIOUR_END
));
4429 //-----------------------------------------------
4430 // rememberWeaponsInHand
4432 //-----------------------------------------------
4433 void CUserEntity::rememberWeaponsInHand()
4435 CInventoryManager
* inv
= CInventoryManager::getInstance();
4441 // keep right hand item
4442 CItemImage
* rightItemImg
= inv
->getHandItem(0);
4445 if( inv
->isMeleeWeaponItem(rightItemImg
->getSheetID()) || inv
->isRangeWeaponItem(rightItemImg
->getSheetID()) )
4447 _PreviousRightHandItem
= CItemSnapshot(*rightItemImg
);
4449 // keep left hand item too (could be ammo, second weapon, etc ..)
4450 CItemImage
* leftItemImg
= inv
->getHandItem(1);
4453 _PreviousLeftHandItem
= CItemSnapshot(*leftItemImg
);
4457 _PreviousLeftHandItem
= CItemSnapshot();
4464 //-----------------------------------------------
4465 // snapshot of a CItemImage
4467 //-----------------------------------------------
4468 CUserEntity::CItemSnapshot::CItemSnapshot( const CItemImage
& i
)
4470 Sheet
= i
.getSheetID();
4471 Quality
= i
.getQuality();
4472 Quantity
= i
.getQuantity();
4473 UserColor
= i
.getUserColor();
4474 Price
= i
.getPrice();
4475 Weight
= i
.getWeight();
4476 NameId
= i
.getNameId();
4477 InfoVersion
= i
.getInfoVersion();
4480 sint
CUserEntity::getLevel() const
4482 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
4484 for(uint i
=0;i
<EGSPD::CSPType::EndSPType
;i
++)
4486 CCDBNodeLeaf
*node
= NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:USER:SKILL_POINTS_%d:VALUE", i
), false);
4489 level
= std::max(level
, (sint
) node
->getValue32());
4495 //-----------------------------------------------
4497 //-----------------------------------------------
4498 void CUserEntity::interlocutor( const CLFECOMMON::TCLEntityId
&slot
)
4500 CLFECOMMON::TCLEntityId prevInterlocutor
= _Interlocutor
;
4501 _Interlocutor
= slot
;
4503 // Refresh (hide or unhide) the icon for the interlocutor NPC
4504 if (prevInterlocutor
!= CLFECOMMON::INVALID_SLOT
)
4505 EntitiesMngr
.refreshInsceneInterfaceOfFriendNPC(prevInterlocutor
);
4506 if (_Interlocutor
!= CLFECOMMON::INVALID_SLOT
)
4507 EntitiesMngr
.refreshInsceneInterfaceOfFriendNPC(_Interlocutor
);
4510 //-----------------------------------------------
4512 //-----------------------------------------------
4513 void CUserEntity::trader(const CLFECOMMON::TCLEntityId
&slot
)
4515 CLFECOMMON::TCLEntityId prevTrader
= _Trader
;
4518 // Refresh (hide or unhide) the icon for the trader NPC
4519 if (prevTrader
!= CLFECOMMON::INVALID_SLOT
)
4520 EntitiesMngr
.refreshInsceneInterfaceOfFriendNPC(prevTrader
);
4521 if (_Trader
!= CLFECOMMON::INVALID_SLOT
)
4522 EntitiesMngr
.refreshInsceneInterfaceOfFriendNPC(_Trader
);