Entity.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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. if (!removed)
  219. {
  220. Game::INSTANCE->requestWorldUpdate(
  221. new EntityRemovedUpdate(id, dimensionId, location));
  222. removed = 1;
  223. }
  224. }
  225. bool Entity::useItem(int typeId, ItemStack* zStack, bool left)
  226. {
  227. if (left)
  228. {
  229. if (!zStack || !zStack->zItem() || zStack->zItem()->isUsable())
  230. {
  231. cs.lock();
  232. if (target)
  233. {
  234. ItemSkill* selected = zSkill(typeId);
  235. if (!selected)
  236. {
  237. selected
  238. = StaticRegistry<ItemType>::INSTANCE.zElement(typeId)
  239. ->createDefaultItemSkill();
  240. if (selected) skills.add(selected);
  241. }
  242. if (!selected)
  243. {
  244. selected = zSkill(ItemTypeEnum::PLAYER_HAND);
  245. }
  246. bool result = target->useItemSkillOnTarget(this,
  247. selected,
  248. !zStack || zStack->getSize() > 1 ? 0
  249. : (Item*)zStack->zItem());
  250. cs.unlock();
  251. return result;
  252. }
  253. cs.unlock();
  254. }
  255. else
  256. {
  257. useItem(ItemTypeEnum::PLAYER_HAND, 0, left);
  258. }
  259. }
  260. else
  261. {
  262. if (zStack && zStack->zItem() && zStack->zItem()->isEatable()
  263. && zStack->getSize() > 0)
  264. { // eat item
  265. if (zStack->getSize() == 1)
  266. {
  267. return ((Item*)zStack->zItem())->applyFoodEffects(this);
  268. }
  269. else
  270. {
  271. if (zStack->zItem()->canApplyFoodEffectsFully(this))
  272. {
  273. Item* item = zStack->extractFromStack();
  274. item->applyFoodEffects(this);
  275. item->release();
  276. return 1;
  277. }
  278. }
  279. }
  280. else if (zStack && zStack->zItem() && zStack->zItem()->isPlaceable()
  281. && zStack->getSize() > 0)
  282. { // place item
  283. if (placeBlockCooldown <= 0)
  284. {
  285. cs.lock();
  286. if (target)
  287. {
  288. Item* item = zStack->extractFromStack();
  289. if (!target->placeBlock(this, item))
  290. {
  291. if (!zStack->addToStack(item))
  292. {
  293. Game::INSTANCE->spawnItem(
  294. location, dimensionId, new ItemStack(item, 1));
  295. }
  296. cs.unlock();
  297. return 0;
  298. }
  299. item->release();
  300. placeBlockCooldown = 15;
  301. cs.unlock();
  302. return 1;
  303. }
  304. cs.unlock();
  305. }
  306. }
  307. }
  308. return 0;
  309. }
  310. void Entity::onTargetChange() {}
  311. bool Entity::interact(Item* zItem, Entity* zActor)
  312. {
  313. return false;
  314. }
  315. void Entity::addMovementFrame(MovementFrame& frame)
  316. {
  317. cs.lock();
  318. movements.add(frame);
  319. cs.unlock();
  320. NetworkMessage* message = new NetworkMessage();
  321. message->addressEntity(this);
  322. char* msg = new char[37];
  323. msg[0] = 0;
  324. *(float*)(msg + 1) = frame.direction.x;
  325. *(float*)(msg + 5) = frame.direction.y;
  326. *(float*)(msg + 9) = frame.direction.z;
  327. *(float*)(msg + 13) = frame.targetPosition.x;
  328. *(float*)(msg + 17) = frame.targetPosition.y;
  329. *(float*)(msg + 21) = frame.targetPosition.z;
  330. *(int*)(msg + 25) = frame.movementFlags;
  331. *(double*)(msg + 29) = frame.duration;
  332. message->setMessage(msg, 37);
  333. Game::INSTANCE->broadcastMessage(message);
  334. faceDir = frame.direction;
  335. // TODO implement subscription system to notify only interested clients
  336. }
  337. void Entity::calculateTarget(Framework::Vec3<float> basePos,
  338. Framework::Vec3<float> direction,
  339. const Item* zItem)
  340. {
  341. Vec3<float> headPosition = basePos + faceOffset;
  342. int px = (int)floor(headPosition.x);
  343. int py = (int)floor(headPosition.y);
  344. int pz = (int)floor(headPosition.z);
  345. direction.normalize();
  346. Direction dir = BOTTOM;
  347. while (true)
  348. {
  349. if (getDefaultBlock(
  350. Game::INSTANCE->zBlockAt(Vec3<int>{px, py, pz}, dimensionId))
  351. ->isInteractable(zItem))
  352. {
  353. if (!target || !target->isBlock({px, py, pz}, dir))
  354. {
  355. cs.lock();
  356. delete target;
  357. target = new ActionTarget({px, py, pz}, dir);
  358. cs.unlock();
  359. onTargetChange();
  360. }
  361. break;
  362. }
  363. // collision to neighbor of current block
  364. if (direction.x > 0)
  365. {
  366. float xt = ((float)px + 1.f - headPosition.x) / direction.x;
  367. Vec3<float> tmp = headPosition + direction * xt;
  368. if (xt <= targetDistanceLimit && tmp.y >= (float)py
  369. && tmp.y < (float)py + 1.f && tmp.z >= (float)pz
  370. && tmp.z < (float)pz + 1.f)
  371. {
  372. dir = WEST;
  373. px++;
  374. continue;
  375. }
  376. }
  377. if (direction.x < 0)
  378. {
  379. float xt = ((float)px - headPosition.x) / direction.x;
  380. Vec3<float> tmp = headPosition + direction * xt;
  381. if (xt <= targetDistanceLimit && tmp.y >= (float)py
  382. && tmp.y < (float)py + 1.f && tmp.z >= (float)pz
  383. && tmp.z < (float)pz + 1.f)
  384. {
  385. dir = EAST;
  386. px--;
  387. continue;
  388. }
  389. }
  390. if (direction.y > 0)
  391. {
  392. float yt = ((float)py + 1.f - headPosition.y) / direction.y;
  393. Vec3<float> tmp = headPosition + direction * yt;
  394. if (yt <= targetDistanceLimit && tmp.x >= (float)px
  395. && tmp.x < (float)px + 1.f && tmp.z >= (float)pz
  396. && tmp.z < (float)pz + 1.f)
  397. {
  398. dir = NORTH;
  399. py++;
  400. continue;
  401. }
  402. }
  403. if (direction.y < 0)
  404. {
  405. float yt = ((float)py - headPosition.y) / direction.y;
  406. Vec3<float> tmp = headPosition + direction * yt;
  407. if (yt <= targetDistanceLimit && tmp.x >= (float)px
  408. && tmp.x < (float)px + 1.f && tmp.z >= (float)pz
  409. && tmp.z < (float)pz + 1.f)
  410. {
  411. dir = SOUTH;
  412. py--;
  413. continue;
  414. }
  415. }
  416. if (direction.z > 0)
  417. {
  418. float zt = ((float)pz + 1.f - headPosition.z) / direction.z;
  419. Vec3<float> tmp = headPosition + direction * zt;
  420. if (zt <= targetDistanceLimit && tmp.x >= (float)px
  421. && tmp.x < (float)px + 1.f && tmp.y >= (float)py
  422. && tmp.y < (float)py + 1.f)
  423. {
  424. dir = BOTTOM;
  425. pz++;
  426. continue;
  427. }
  428. }
  429. if (direction.z < 0)
  430. {
  431. float zt = ((float)pz - headPosition.z) / direction.z;
  432. Vec3<float> tmp = headPosition + direction * zt;
  433. if (zt <= targetDistanceLimit && tmp.x >= (float)px
  434. && tmp.x < (float)px + 1.f && tmp.y >= (float)py
  435. && tmp.y < (float)py + 1)
  436. {
  437. dir = TOP;
  438. pz--;
  439. continue;
  440. }
  441. }
  442. if (target)
  443. {
  444. cs.lock();
  445. delete target;
  446. target = 0;
  447. cs.unlock();
  448. onTargetChange();
  449. }
  450. break;
  451. }
  452. }
  453. void Entity::removeStatusBarObserver(Entity* zSource, Framework::Text id)
  454. {
  455. cs.lock();
  456. int index = 0;
  457. for (auto observer : statusBarObservers)
  458. {
  459. if (observer.getFirst() == zSource->getId()
  460. && observer.getSecond().istGleich(id))
  461. {
  462. statusBarObservers.remove(index);
  463. break;
  464. }
  465. index++;
  466. }
  467. cs.unlock();
  468. }
  469. void Entity::addStatusBarObserver(Entity* zSource, Framework::Text id)
  470. {
  471. cs.lock();
  472. for (auto observer : statusBarObservers)
  473. {
  474. if (observer.getFirst() == zSource->getId()
  475. && observer.getSecond().istGleich(id))
  476. {
  477. cs.unlock();
  478. return;
  479. }
  480. }
  481. statusBarObservers.add(ImmutablePair<int, Text>(zSource->getId(), id));
  482. cs.unlock();
  483. }
  484. void Entity::notifyStatusBarObservers(NetworkMessage* msg)
  485. {
  486. cs.lock();
  487. int index = 0;
  488. Array<int> toDelete;
  489. for (auto observer : statusBarObservers)
  490. {
  491. Entity* e = Game::INSTANCE->zEntity(observer.getFirst());
  492. if (e)
  493. {
  494. msg->addressUIElement(observer.getSecond());
  495. Game::INSTANCE->sendMessage(msg->clone(), e);
  496. }
  497. else
  498. toDelete.add(index, 0);
  499. index++;
  500. }
  501. for (int i : toDelete)
  502. statusBarObservers.remove(i);
  503. cs.unlock();
  504. msg->release();
  505. }
  506. ItemSkill* Entity::zSkill(int itemType)
  507. {
  508. for (ItemSkill* skill : skills)
  509. {
  510. if (skill->getTypeId() == typeId)
  511. {
  512. return skill;
  513. }
  514. }
  515. return 0;
  516. }
  517. void Entity::prepareTick(const Dimension* zDimension) {}
  518. void Entity::tick(const Dimension* zDimension)
  519. {
  520. if (placeBlockCooldown > 0)
  521. {
  522. placeBlockCooldown--;
  523. }
  524. placeBlockCooldown--;
  525. if (time.isMeasuring())
  526. {
  527. time.messungEnde();
  528. if (movements.getEintragAnzahl() > 0)
  529. {
  530. MovementFrame currentFrame = movements.get(0);
  531. double seconds = time.getSekunden();
  532. while (seconds > 0)
  533. {
  534. if (currentFrame.duration <= 0)
  535. {
  536. cs.lock();
  537. movements.remove(0);
  538. cs.unlock();
  539. if (movements.getEintragAnzahl() > 0)
  540. currentFrame = movements.get(0);
  541. else
  542. break;
  543. }
  544. double t = MIN(currentFrame.duration, seconds);
  545. // TODO: add collision detection to reduce cheating capability
  546. location += (currentFrame.targetPosition - location)
  547. * (float)(t / currentFrame.duration);
  548. currentFrame.duration -= t;
  549. seconds -= t;
  550. if (currentFrame.duration <= 0)
  551. {
  552. location = currentFrame.targetPosition;
  553. }
  554. }
  555. if (currentFrame.duration > 0) movements.set(currentFrame, 0);
  556. if (getStamina() <= getMaxStamina() - 0.0025f)
  557. {
  558. if (getThirst() > 0 && getHunger() > 0)
  559. {
  560. setStamina(getStamina() + 0.0025f);
  561. setHunger(getHunger() - 0.0005f);
  562. setThirst(getThirst() - 0.0015f);
  563. }
  564. }
  565. }
  566. else
  567. {
  568. if (getStamina() <= getMaxStamina() - 0.005f)
  569. {
  570. if (getThirst() > 0 && getHunger() > 0)
  571. {
  572. setStamina(getStamina() + 0.005f);
  573. setHunger(getHunger() - 0.001f);
  574. setThirst(getThirst() - 0.003f);
  575. }
  576. }
  577. }
  578. }
  579. time.messungStart();
  580. }
  581. void Entity::api(Framework::StreamReader* zRequest,
  582. NetworkMessage* zResponse,
  583. Entity* zSource)
  584. {
  585. char type;
  586. zRequest->lese(&type, 1);
  587. switch (type)
  588. {
  589. case 0: // request status bar state
  590. {
  591. char len;
  592. zRequest->lese(&len, 1);
  593. char* guiId = new char[(int)len + 1];
  594. zRequest->lese(guiId, len);
  595. guiId[(int)len] = 0;
  596. zResponse->addressUIElement(guiId);
  597. addStatusBarObserver(zSource, guiId);
  598. char* msg = new char[33];
  599. msg[0] = 0;
  600. *(float*)(msg + 1) = getMaxHP();
  601. *(float*)(msg + 5) = getCurrentHP();
  602. *(float*)(msg + 9) = getMaxStamina();
  603. *(float*)(msg + 13) = getStamina();
  604. *(float*)(msg + 17) = getMaxHunger();
  605. *(float*)(msg + 21) = getHunger();
  606. *(float*)(msg + 25) = getMaxThirst();
  607. *(float*)(msg + 29) = getThirst();
  608. zResponse->setMessage(msg, 33);
  609. delete[] guiId;
  610. break;
  611. }
  612. case 1: // remove status bar observer
  613. {
  614. char len;
  615. zRequest->lese(&len, 1);
  616. char* guiId = new char[(int)len + 1];
  617. zRequest->lese(guiId, len);
  618. guiId[(int)len] = 0;
  619. removeStatusBarObserver(zSource, guiId);
  620. delete[] guiId;
  621. break;
  622. }
  623. }
  624. }
  625. void Entity::onFall(float collisionSpeed)
  626. {
  627. if (collisionSpeed > 5)
  628. {
  629. // TODO: take damage
  630. }
  631. }
  632. void Entity::setChatSecurityLevel(int level)
  633. {
  634. chatSecurityLevel = level;
  635. }
  636. void Entity::setPosition(Framework::Vec3<float> pos)
  637. {
  638. location = pos;
  639. }
  640. void Entity::setHP(float hp)
  641. {
  642. currentHP = MIN(MAX(hp, 0), maxHP);
  643. NetworkMessage* msg = new NetworkMessage();
  644. char* message = new char[9];
  645. message[0] = 1;
  646. *(float*)(message + 1) = getMaxHP();
  647. *(float*)(message + 5) = getCurrentHP();
  648. msg->setMessage(message, 9);
  649. notifyStatusBarObservers(msg);
  650. }
  651. void Entity::setStamina(float stamina)
  652. {
  653. this->stamina = MIN(MAX(stamina, 0), maxStamina);
  654. NetworkMessage* msg = new NetworkMessage();
  655. char* message = new char[9];
  656. message[0] = 2;
  657. *(float*)(message + 1) = getMaxStamina();
  658. *(float*)(message + 5) = getStamina();
  659. msg->setMessage(message, 9);
  660. notifyStatusBarObservers(msg);
  661. }
  662. void Entity::setHunger(float hunger)
  663. {
  664. this->hunger = MIN(MAX(hunger, 0), maxHunger);
  665. NetworkMessage* msg = new NetworkMessage();
  666. char* message = new char[9];
  667. message[0] = 3;
  668. *(float*)(message + 1) = getMaxHunger();
  669. *(float*)(message + 5) = getHunger();
  670. msg->setMessage(message, 9);
  671. notifyStatusBarObservers(msg);
  672. }
  673. void Entity::setThirst(float thirst)
  674. {
  675. this->thirst = MIN(MAX(thirst, 0), maxThirst);
  676. NetworkMessage* msg = new NetworkMessage();
  677. char* message = new char[9];
  678. message[0] = 4;
  679. *(float*)(message + 1) = getMaxThirst();
  680. *(float*)(message + 5) = getThirst();
  681. msg->setMessage(message, 9);
  682. notifyStatusBarObservers(msg);
  683. }
  684. float Entity::getMaxHP() const
  685. {
  686. return maxHP;
  687. }
  688. float Entity::getCurrentHP() const
  689. {
  690. return currentHP;
  691. }
  692. float Entity::getStamina() const
  693. {
  694. return stamina;
  695. }
  696. float Entity::getMaxStamina() const
  697. {
  698. return maxStamina;
  699. }
  700. float Entity::getHunger() const
  701. {
  702. return hunger;
  703. }
  704. float Entity::getMaxHunger() const
  705. {
  706. return maxHunger;
  707. }
  708. float Entity::getThirst() const
  709. {
  710. return thirst;
  711. }
  712. float Entity::getMaxThirst() const
  713. {
  714. return maxThirst;
  715. }
  716. Framework::Vec3<float> Entity::getSpeed() const
  717. {
  718. return speed;
  719. }
  720. Framework::Vec3<float> Entity::getFaceDir() const
  721. {
  722. return faceDir;
  723. }
  724. Framework::Vec3<float> Entity::getPosition() const
  725. {
  726. return location;
  727. }
  728. float Entity::getGravityMultiplier() const
  729. {
  730. return gravityMultiplier;
  731. }
  732. bool Entity::isRemoved() const
  733. {
  734. return removed;
  735. }
  736. const EntityType* Entity::zType() const
  737. {
  738. return StaticRegistry<EntityType>::INSTANCE.zElement(typeId);
  739. }
  740. const ActionTarget* Entity::zTarget() const
  741. {
  742. return target;
  743. }
  744. int Entity::getId() const
  745. {
  746. return id;
  747. }
  748. bool Entity::hasDefaultModel() const
  749. {
  750. return 1;
  751. }
  752. ModelInfo Entity::getSpecialModel() const
  753. {
  754. return ModelInfo("", "", 0);
  755. }
  756. float Entity::getMaxSpeed() const
  757. {
  758. return maxMovementSpeed;
  759. }
  760. bool Entity::isMoving() const
  761. {
  762. return movements.getEintragAnzahl() > 0;
  763. }
  764. int Entity::getChatSecurityLevel() const
  765. {
  766. return chatSecurityLevel;
  767. }