Entity.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. #include "Entity.h"
  2. #include <Text.h>
  3. #include "BlockType.h"
  4. #include "Dimension.h"
  5. #include "EntityRemovedUpdate.h"
  6. #include "Game.h"
  7. #include "ItemSkill.h"
  8. #include "NoBlock.h"
  9. ActionTarget::ActionTarget(Vec3<int> blockPos, Direction blockSide)
  10. : blockPos(blockPos),
  11. targetBlockSide(blockSide),
  12. entityId(-1)
  13. {}
  14. ActionTarget::ActionTarget(int entityId)
  15. : entityId(entityId)
  16. {}
  17. bool ActionTarget::isBlock(
  18. Framework::Vec3<int> blockPos, Direction blockSide) const
  19. {
  20. return this->entityId == -1 && this->blockPos == blockPos
  21. && (this->targetBlockSide == targetBlockSide
  22. || blockSide == NO_DIRECTION);
  23. }
  24. bool ActionTarget::isEntity(int entityId) const
  25. {
  26. return this->entityId == entityId;
  27. }
  28. bool ActionTarget::useItemSkillOnTarget(
  29. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem)
  30. {
  31. if (entityId >= 0)
  32. {
  33. Entity* target = Game::INSTANCE->zEntity(entityId);
  34. if (target)
  35. {
  36. return zItemSkill->use(zActor, zUsedItem, target);
  37. }
  38. }
  39. else
  40. {
  41. Block* block = Game::INSTANCE->zRealBlockInstance(
  42. blockPos, zActor->getDimensionId());
  43. if (block)
  44. {
  45. return zItemSkill->use(zActor, zUsedItem, block);
  46. }
  47. }
  48. return 0;
  49. }
  50. void ActionTarget::interactItemSkillOnTarget(
  51. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem)
  52. {
  53. if (zItemSkill)
  54. {
  55. if (entityId >= 0)
  56. {
  57. Entity* target = Game::INSTANCE->zEntity(entityId);
  58. if (target) zItemSkill->interact(zActor, zUsedItem, target);
  59. }
  60. else
  61. {
  62. Block* block = Game::INSTANCE->zRealBlockInstance(
  63. blockPos, zActor->getDimensionId());
  64. if (block) zItemSkill->interact(zActor, zUsedItem, block);
  65. }
  66. }
  67. else
  68. {
  69. if (entityId >= 0)
  70. {
  71. Block* block = Game::INSTANCE->zRealBlockInstance(
  72. blockPos, zActor->getDimensionId());
  73. if (block) block->interact(zUsedItem, zActor);
  74. }
  75. else
  76. {
  77. Block* block = Game::INSTANCE->zRealBlockInstance(
  78. blockPos, zActor->getDimensionId());
  79. if (block) block->interact(zUsedItem, zActor);
  80. }
  81. }
  82. }
  83. bool ActionTarget::placeBlock(Entity* zActor, Item* zItem)
  84. {
  85. if (zActor->getStamina() > 0.2f)
  86. {
  87. if (zItem->canBePlacedAt(zActor->getDimensionId(),
  88. blockPos + getDirection(targetBlockSide)))
  89. {
  90. Block* block = zItem->zPlacedBlockType()->createBlockAt(
  91. blockPos + getDirection(targetBlockSide),
  92. zActor->getDimensionId(),
  93. zItem);
  94. if (block)
  95. {
  96. Game::INSTANCE->zDimension(zActor->getDimensionId())
  97. ->placeBlock(block->getPos(), block);
  98. zItem->onPlaced();
  99. zActor->setStamina(zActor->getStamina() - 0.2f);
  100. return 1;
  101. }
  102. }
  103. }
  104. return 0;
  105. }
  106. void ActionTarget::toMessage(
  107. const ActionTarget* zTarget, int dimensionId, NetworkMessage* zMsg)
  108. {
  109. if (zTarget)
  110. {
  111. if (zTarget->entityId >= 0)
  112. {
  113. char* message = new char[6];
  114. message[0] = 3;
  115. message[1] = 1;
  116. *(int*)(message + 2) = zTarget->entityId;
  117. zMsg->setMessage(message, 6);
  118. }
  119. else
  120. {
  121. Framework::Text targetUIML = "";
  122. auto block
  123. = Game::INSTANCE->zBlockAt(zTarget->blockPos, dimensionId);
  124. if (block.isA())
  125. {
  126. targetUIML = block.getA()->getTargetUIML();
  127. }
  128. else if (block.isB())
  129. {
  130. targetUIML = StaticRegistry<BlockType>::INSTANCE
  131. .zElement(block.getB())
  132. ->getTargetUIML();
  133. }
  134. char* message = new char[18 + targetUIML.getLength() + 2];
  135. message[0] = 3;
  136. message[1] = 2;
  137. *(int*)(message + 2) = zTarget->blockPos.x;
  138. *(int*)(message + 6) = zTarget->blockPos.y;
  139. *(int*)(message + 10) = zTarget->blockPos.z;
  140. *(int*)(message + 14) = zTarget->targetBlockSide;
  141. short len = (short)targetUIML.getLength();
  142. *(short*)(message + 18) = len;
  143. memcpy(message + 20, targetUIML.getText(), len);
  144. zMsg->setMessage(message, 18 + len + 2);
  145. }
  146. }
  147. else
  148. {
  149. char* message = new char[2];
  150. message[0] = 3;
  151. message[1] = 0;
  152. zMsg->setMessage(message, 2);
  153. }
  154. }
  155. void ActionTarget::save(ActionTarget* zTarget, Framework::StreamWriter* zWriter)
  156. {
  157. if (zTarget)
  158. {
  159. if (zTarget->entityId >= 0)
  160. {
  161. char b = 1;
  162. zWriter->schreibe(&b, 1);
  163. zWriter->schreibe((char*)&zTarget->entityId, 4);
  164. }
  165. else
  166. {
  167. char b = 2;
  168. zWriter->schreibe(&b, 1);
  169. zWriter->schreibe((char*)&zTarget->blockPos.x, 4);
  170. zWriter->schreibe((char*)&zTarget->blockPos.y, 4);
  171. zWriter->schreibe((char*)&zTarget->blockPos.z, 4);
  172. zWriter->schreibe((char*)&zTarget->targetBlockSide, 4);
  173. }
  174. }
  175. else
  176. {
  177. char b = 0;
  178. zWriter->schreibe(&b, 1);
  179. }
  180. }
  181. ActionTarget* ActionTarget::load(Framework::StreamReader* zReader)
  182. {
  183. char b;
  184. zReader->lese(&b, 1);
  185. if (b == 1)
  186. {
  187. int id;
  188. zReader->lese((char*)&id, 4);
  189. return new ActionTarget(id);
  190. }
  191. else if (b == 2)
  192. {
  193. Framework::Vec3<int> pos;
  194. Direction side;
  195. zReader->lese((char*)&pos.x, 4);
  196. zReader->lese((char*)&pos.y, 4);
  197. zReader->lese((char*)&pos.z, 4);
  198. zReader->lese((char*)&side, 4);
  199. return new ActionTarget(pos, side);
  200. }
  201. return 0;
  202. }
  203. Entity::Entity(
  204. int typeId, Framework::Vec3<float> location, int dimensionId, int entityId)
  205. : Inventory(location, dimensionId, true),
  206. chatSecurityLevel(0),
  207. speed(0, 0, 0),
  208. faceDir(1, 0, 0),
  209. target(0),
  210. typeId(typeId),
  211. removed(0),
  212. gravityMultiplier(1.f),
  213. id(entityId),
  214. placeBlockCooldown(0)
  215. {}
  216. void Entity::onDeath()
  217. {
  218. removed = 1;
  219. Game::INSTANCE->requestWorldUpdate(
  220. new EntityRemovedUpdate(id, dimensionId, location));
  221. }
  222. bool Entity::useItem(int typeId, ItemStack* zStack, bool left)
  223. {
  224. if (left)
  225. {
  226. if (!zStack || !zStack->zItem() || zStack->zItem()->isUsable())
  227. {
  228. cs.lock();
  229. if (target)
  230. {
  231. ItemSkill* selected = zSkill(typeId);
  232. if (!selected)
  233. {
  234. selected
  235. = StaticRegistry<ItemType>::INSTANCE.zElement(typeId)
  236. ->createDefaultItemSkill();
  237. if (selected) skills.add(selected);
  238. }
  239. if (!selected)
  240. {
  241. selected = zSkill(ItemTypeEnum::PLAYER_HAND);
  242. }
  243. bool result = target->useItemSkillOnTarget(this,
  244. selected,
  245. !zStack || zStack->getSize() > 1 ? 0
  246. : (Item*)zStack->zItem());
  247. cs.unlock();
  248. return result;
  249. }
  250. cs.unlock();
  251. }
  252. else
  253. {
  254. useItem(ItemTypeEnum::PLAYER_HAND, 0, left);
  255. }
  256. }
  257. else
  258. {
  259. if (zStack && zStack->zItem() && zStack->zItem()->isEatable()
  260. && zStack->getSize() > 0)
  261. { // eat item
  262. if (zStack->getSize() == 1)
  263. {
  264. return ((Item*)zStack->zItem())->applyFoodEffects(this);
  265. }
  266. else
  267. {
  268. if (zStack->zItem()->canApplyFoodEffectsFully(this))
  269. {
  270. Item* item = zStack->extractFromStack();
  271. item->applyFoodEffects(this);
  272. item->release();
  273. return 1;
  274. }
  275. }
  276. }
  277. else if (zStack && zStack->zItem() && zStack->zItem()->isPlaceable()
  278. && zStack->getSize() > 0)
  279. { // place item
  280. if (placeBlockCooldown <= 0)
  281. {
  282. cs.lock();
  283. if (target)
  284. {
  285. Item* item = zStack->extractFromStack();
  286. if (!target->placeBlock(this, item))
  287. {
  288. if (!zStack->addToStack(item))
  289. {
  290. Game::INSTANCE->spawnItem(
  291. location, dimensionId, new ItemStack(item, 1));
  292. }
  293. cs.unlock();
  294. return 0;
  295. }
  296. item->release();
  297. placeBlockCooldown = 15;
  298. cs.unlock();
  299. return 1;
  300. }
  301. cs.unlock();
  302. }
  303. }
  304. }
  305. return 0;
  306. }
  307. void Entity::onTargetChange() {}
  308. bool Entity::interact(Item* zItem, Entity* zActor)
  309. {
  310. return false;
  311. }
  312. void Entity::addMovementFrame(MovementFrame& frame)
  313. {
  314. cs.lock();
  315. movements.add(frame);
  316. cs.unlock();
  317. NetworkMessage* message = new NetworkMessage();
  318. message->addressEntity(this);
  319. char* msg = new char[37];
  320. msg[0] = 0;
  321. *(float*)(msg + 1) = frame.direction.x;
  322. *(float*)(msg + 5) = frame.direction.y;
  323. *(float*)(msg + 9) = frame.direction.z;
  324. *(float*)(msg + 13) = frame.targetPosition.x;
  325. *(float*)(msg + 17) = frame.targetPosition.y;
  326. *(float*)(msg + 21) = frame.targetPosition.z;
  327. *(int*)(msg + 25) = frame.movementFlags;
  328. *(double*)(msg + 29) = frame.duration;
  329. message->setMessage(msg, 37);
  330. Game::INSTANCE->broadcastMessage(message);
  331. faceDir = frame.direction;
  332. // TODO implement subscription system to notify only interested clients
  333. }
  334. void Entity::calculateTarget(Framework::Vec3<float> basePos,
  335. Framework::Vec3<float> direction,
  336. const Item* zItem)
  337. {
  338. Vec3<float> headPosition = basePos + faceOffset;
  339. int px = (int)floor(headPosition.x);
  340. int py = (int)floor(headPosition.y);
  341. int pz = (int)floor(headPosition.z);
  342. direction.normalize();
  343. Direction dir = BOTTOM;
  344. while (true)
  345. {
  346. if (getDefaultBlock(
  347. Game::INSTANCE->zBlockAt(Vec3<int>{px, py, pz}, dimensionId))
  348. ->isInteractable(zItem))
  349. {
  350. if (!target || !target->isBlock({px, py, pz}, dir))
  351. {
  352. cs.lock();
  353. delete target;
  354. target = new ActionTarget({px, py, pz}, dir);
  355. cs.unlock();
  356. onTargetChange();
  357. }
  358. break;
  359. }
  360. // collision to neighbor of current block
  361. if (direction.x > 0)
  362. {
  363. float xt = ((float)px + 1.f - headPosition.x) / direction.x;
  364. Vec3<float> tmp = headPosition + direction * xt;
  365. if (xt <= targetDistanceLimit && tmp.y >= (float)py
  366. && tmp.y < (float)py + 1.f && tmp.z >= (float)pz
  367. && tmp.z < (float)pz + 1.f)
  368. {
  369. dir = WEST;
  370. px++;
  371. continue;
  372. }
  373. }
  374. if (direction.x < 0)
  375. {
  376. float xt = ((float)px - headPosition.x) / direction.x;
  377. Vec3<float> tmp = headPosition + direction * xt;
  378. if (xt <= targetDistanceLimit && tmp.y >= (float)py
  379. && tmp.y < (float)py + 1.f && tmp.z >= (float)pz
  380. && tmp.z < (float)pz + 1.f)
  381. {
  382. dir = EAST;
  383. px--;
  384. continue;
  385. }
  386. }
  387. if (direction.y > 0)
  388. {
  389. float yt = ((float)py + 1.f - headPosition.y) / direction.y;
  390. Vec3<float> tmp = headPosition + direction * yt;
  391. if (yt <= targetDistanceLimit && tmp.x >= (float)px
  392. && tmp.x < (float)px + 1.f && tmp.z >= (float)pz
  393. && tmp.z < (float)pz + 1.f)
  394. {
  395. dir = NORTH;
  396. py++;
  397. continue;
  398. }
  399. }
  400. if (direction.y < 0)
  401. {
  402. float yt = ((float)py - headPosition.y) / direction.y;
  403. Vec3<float> tmp = headPosition + direction * yt;
  404. if (yt <= targetDistanceLimit && tmp.x >= (float)px
  405. && tmp.x < (float)px + 1.f && tmp.z >= (float)pz
  406. && tmp.z < (float)pz + 1.f)
  407. {
  408. dir = SOUTH;
  409. py--;
  410. continue;
  411. }
  412. }
  413. if (direction.z > 0)
  414. {
  415. float zt = ((float)pz + 1.f - headPosition.z) / direction.z;
  416. Vec3<float> tmp = headPosition + direction * zt;
  417. if (zt <= targetDistanceLimit && tmp.x >= (float)px
  418. && tmp.x < (float)px + 1.f && tmp.y >= (float)py
  419. && tmp.y < (float)py + 1.f)
  420. {
  421. dir = BOTTOM;
  422. pz++;
  423. continue;
  424. }
  425. }
  426. if (direction.z < 0)
  427. {
  428. float zt = ((float)pz - headPosition.z) / direction.z;
  429. Vec3<float> tmp = headPosition + direction * zt;
  430. if (zt <= targetDistanceLimit && tmp.x >= (float)px
  431. && tmp.x < (float)px + 1.f && tmp.y >= (float)py
  432. && tmp.y < (float)py + 1)
  433. {
  434. dir = TOP;
  435. pz--;
  436. continue;
  437. }
  438. }
  439. if (target)
  440. {
  441. cs.lock();
  442. delete target;
  443. target = 0;
  444. cs.unlock();
  445. onTargetChange();
  446. }
  447. break;
  448. }
  449. }
  450. void Entity::removeStatusBarObserver(Entity* zSource, Framework::Text id)
  451. {
  452. cs.lock();
  453. int index = 0;
  454. for (auto observer : statusBarObservers)
  455. {
  456. if (observer.getFirst() == zSource->getId()
  457. && observer.getSecond().istGleich(id))
  458. {
  459. statusBarObservers.remove(index);
  460. break;
  461. }
  462. index++;
  463. }
  464. cs.unlock();
  465. }
  466. void Entity::addStatusBarObserver(Entity* zSource, Framework::Text id)
  467. {
  468. cs.lock();
  469. for (auto observer : statusBarObservers)
  470. {
  471. if (observer.getFirst() == zSource->getId()
  472. && observer.getSecond().istGleich(id))
  473. {
  474. cs.unlock();
  475. return;
  476. }
  477. }
  478. statusBarObservers.add(ImmutablePair<int, Text>(zSource->getId(), id));
  479. cs.unlock();
  480. }
  481. void Entity::notifyStatusBarObservers(NetworkMessage* msg)
  482. {
  483. cs.lock();
  484. int index = 0;
  485. Array<int> toDelete;
  486. for (auto observer : statusBarObservers)
  487. {
  488. Entity* e = Game::INSTANCE->zEntity(observer.getFirst());
  489. if (e)
  490. {
  491. msg->addressUIElement(observer.getSecond());
  492. Game::INSTANCE->sendMessage(msg->clone(), e);
  493. }
  494. else
  495. toDelete.add(index, 0);
  496. index++;
  497. }
  498. for (int i : toDelete)
  499. statusBarObservers.remove(i);
  500. cs.unlock();
  501. msg->release();
  502. }
  503. ItemSkill* Entity::zSkill(int itemType)
  504. {
  505. for (ItemSkill* skill : skills)
  506. {
  507. if (skill->getTypeId() == typeId)
  508. {
  509. return skill;
  510. }
  511. }
  512. return 0;
  513. }
  514. void Entity::prepareTick(const Dimension* zDimension) {}
  515. void Entity::tick(const Dimension* zDimension)
  516. {
  517. if (placeBlockCooldown > 0)
  518. {
  519. placeBlockCooldown--;
  520. }
  521. placeBlockCooldown--;
  522. if (time.isMeasuring())
  523. {
  524. time.messungEnde();
  525. if (movements.getEintragAnzahl() > 0)
  526. {
  527. MovementFrame currentFrame = movements.get(0);
  528. double seconds = time.getSekunden();
  529. while (seconds > 0)
  530. {
  531. if (currentFrame.duration <= 0)
  532. {
  533. cs.lock();
  534. movements.remove(0);
  535. cs.unlock();
  536. if (movements.getEintragAnzahl() > 0)
  537. currentFrame = movements.get(0);
  538. else
  539. break;
  540. }
  541. double t = MIN(currentFrame.duration, seconds);
  542. // TODO: add collision detection to reduce cheating capability
  543. location += (currentFrame.targetPosition - location)
  544. * (float)(t / currentFrame.duration);
  545. currentFrame.duration -= t;
  546. seconds -= t;
  547. if (currentFrame.duration <= 0)
  548. {
  549. location = currentFrame.targetPosition;
  550. }
  551. }
  552. if (currentFrame.duration > 0) movements.set(currentFrame, 0);
  553. if (getStamina() <= getMaxStamina() - 0.0025f)
  554. {
  555. if (getThirst() > 0 && getHunger() > 0)
  556. {
  557. setStamina(getStamina() + 0.0025f);
  558. setHunger(getHunger() - 0.0005f);
  559. setThirst(getThirst() - 0.0015f);
  560. }
  561. }
  562. }
  563. else
  564. {
  565. if (getStamina() <= getMaxStamina() - 0.005f)
  566. {
  567. if (getThirst() > 0 && getHunger() > 0)
  568. {
  569. setStamina(getStamina() + 0.005f);
  570. setHunger(getHunger() - 0.001f);
  571. setThirst(getThirst() - 0.003f);
  572. }
  573. }
  574. }
  575. }
  576. time.messungStart();
  577. }
  578. void Entity::api(Framework::StreamReader* zRequest,
  579. NetworkMessage* zResponse,
  580. Entity* zSource)
  581. {
  582. char type;
  583. zRequest->lese(&type, 1);
  584. switch (type)
  585. {
  586. case 0: // request status bar state
  587. {
  588. char len;
  589. zRequest->lese(&len, 1);
  590. char* guiId = new char[(int)len + 1];
  591. zRequest->lese(guiId, len);
  592. guiId[(int)len] = 0;
  593. zResponse->addressUIElement(guiId);
  594. addStatusBarObserver(zSource, guiId);
  595. char* msg = new char[33];
  596. msg[0] = 0;
  597. *(float*)(msg + 1) = getMaxHP();
  598. *(float*)(msg + 5) = getCurrentHP();
  599. *(float*)(msg + 9) = getMaxStamina();
  600. *(float*)(msg + 13) = getStamina();
  601. *(float*)(msg + 17) = getMaxHunger();
  602. *(float*)(msg + 21) = getHunger();
  603. *(float*)(msg + 25) = getMaxThirst();
  604. *(float*)(msg + 29) = getThirst();
  605. zResponse->setMessage(msg, 33);
  606. delete[] guiId;
  607. break;
  608. }
  609. case 1: // remove status bar observer
  610. {
  611. char len;
  612. zRequest->lese(&len, 1);
  613. char* guiId = new char[(int)len + 1];
  614. zRequest->lese(guiId, len);
  615. guiId[(int)len] = 0;
  616. removeStatusBarObserver(zSource, guiId);
  617. delete[] guiId;
  618. break;
  619. }
  620. }
  621. }
  622. void Entity::onFall(float collisionSpeed)
  623. {
  624. if (collisionSpeed > 5)
  625. {
  626. // TODO: take damage
  627. }
  628. }
  629. void Entity::setChatSecurityLevel(int level)
  630. {
  631. chatSecurityLevel = level;
  632. }
  633. void Entity::setPosition(Framework::Vec3<float> pos)
  634. {
  635. location = pos;
  636. }
  637. void Entity::setHP(float hp)
  638. {
  639. currentHP = MIN(MAX(hp, 0), maxHP);
  640. NetworkMessage* msg = new NetworkMessage();
  641. char* message = new char[9];
  642. message[0] = 1;
  643. *(float*)(message + 1) = getMaxHP();
  644. *(float*)(message + 5) = getCurrentHP();
  645. msg->setMessage(message, 9);
  646. notifyStatusBarObservers(msg);
  647. }
  648. void Entity::setStamina(float stamina)
  649. {
  650. this->stamina = MIN(MAX(stamina, 0), maxStamina);
  651. NetworkMessage* msg = new NetworkMessage();
  652. char* message = new char[9];
  653. message[0] = 2;
  654. *(float*)(message + 1) = getMaxStamina();
  655. *(float*)(message + 5) = getStamina();
  656. msg->setMessage(message, 9);
  657. notifyStatusBarObservers(msg);
  658. }
  659. void Entity::setHunger(float hunger)
  660. {
  661. this->hunger = MIN(MAX(hunger, 0), maxHunger);
  662. NetworkMessage* msg = new NetworkMessage();
  663. char* message = new char[9];
  664. message[0] = 3;
  665. *(float*)(message + 1) = getMaxHunger();
  666. *(float*)(message + 5) = getHunger();
  667. msg->setMessage(message, 9);
  668. notifyStatusBarObservers(msg);
  669. }
  670. void Entity::setThirst(float thirst)
  671. {
  672. this->thirst = MIN(MAX(thirst, 0), maxThirst);
  673. NetworkMessage* msg = new NetworkMessage();
  674. char* message = new char[9];
  675. message[0] = 4;
  676. *(float*)(message + 1) = getMaxThirst();
  677. *(float*)(message + 5) = getThirst();
  678. msg->setMessage(message, 9);
  679. notifyStatusBarObservers(msg);
  680. }
  681. float Entity::getMaxHP() const
  682. {
  683. return maxHP;
  684. }
  685. float Entity::getCurrentHP() const
  686. {
  687. return currentHP;
  688. }
  689. float Entity::getStamina() const
  690. {
  691. return stamina;
  692. }
  693. float Entity::getMaxStamina() const
  694. {
  695. return maxStamina;
  696. }
  697. float Entity::getHunger() const
  698. {
  699. return hunger;
  700. }
  701. float Entity::getMaxHunger() const
  702. {
  703. return maxHunger;
  704. }
  705. float Entity::getThirst() const
  706. {
  707. return thirst;
  708. }
  709. float Entity::getMaxThirst() const
  710. {
  711. return maxThirst;
  712. }
  713. Framework::Vec3<float> Entity::getSpeed() const
  714. {
  715. return speed;
  716. }
  717. Framework::Vec3<float> Entity::getFaceDir() const
  718. {
  719. return faceDir;
  720. }
  721. Framework::Vec3<float> Entity::getPosition() const
  722. {
  723. return location;
  724. }
  725. float Entity::getGravityMultiplier() const
  726. {
  727. return gravityMultiplier;
  728. }
  729. bool Entity::isRemoved() const
  730. {
  731. return removed;
  732. }
  733. const EntityType* Entity::zType() const
  734. {
  735. return StaticRegistry<EntityType>::INSTANCE.zElement(typeId);
  736. }
  737. const ActionTarget* Entity::zTarget() const
  738. {
  739. return target;
  740. }
  741. int Entity::getId() const
  742. {
  743. return id;
  744. }
  745. bool Entity::hasDefaultModel() const
  746. {
  747. return 1;
  748. }
  749. ModelInfo Entity::getSpecialModel() const
  750. {
  751. return ModelInfo("", "", 0);
  752. }
  753. float Entity::getMaxSpeed() const
  754. {
  755. return maxMovementSpeed;
  756. }
  757. bool Entity::isMoving() const
  758. {
  759. return movements.getEintragAnzahl() > 0;
  760. }
  761. int Entity::getChatSecurityLevel() const
  762. {
  763. return chatSecurityLevel;
  764. }