123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #include "EntityType.h"
- #include "Entity.h"
- #include "Game.h"
- #include "ItemType.h"
- EntityType::EntityType(Framework::Text name, ModelInfo* model)
- : ReferenceCounter(),
- name(name),
- model(model),
- id(-1)
- {}
- EntityType::~EntityType()
- {
- if (model) model->release();
- }
- void EntityType::loadSuperEntity(
- Entity* zEntity, Framework::StreamReader* zReader) const
- {
- zEntity->loadInventory(zReader);
- zReader->lese((char*)&zEntity->id, 4);
- zReader->lese((char*)&zEntity->maxHP, 4);
- zReader->lese((char*)&zEntity->currentHP, 4);
- zReader->lese((char*)&zEntity->stamina, 4);
- zReader->lese((char*)&zEntity->maxStamina, 4);
- zReader->lese((char*)&zEntity->hunger, 4);
- zReader->lese((char*)&zEntity->maxHunger, 4);
- zReader->lese((char*)&zEntity->thirst, 4);
- zReader->lese((char*)&zEntity->chatSecurityLevel, 4);
- zReader->lese((char*)&zEntity->maxThirst, 4);
- zReader->lese((char*)&zEntity->speed.x, 4);
- zReader->lese((char*)&zEntity->speed.y, 4);
- zReader->lese((char*)&zEntity->speed.z, 4);
- zReader->lese((char*)&zEntity->faceDir.x, 4);
- zReader->lese((char*)&zEntity->faceDir.y, 4);
- zReader->lese((char*)&zEntity->dimensionId, 4);
- zReader->lese((char*)&zEntity->location.x, 4);
- zReader->lese((char*)&zEntity->location.y, 4);
- zReader->lese((char*)&zEntity->location.z, 4);
- if (zEntity->target) delete zEntity->target;
- zEntity->target = ActionTarget::load(zReader);
- // load item skills
- zEntity->skills.leeren();
- int skillCount;
- zReader->lese((char*)&skillCount, 4);
- for (int i = 0; i < skillCount; i++)
- {
- int type;
- zReader->lese((char*)&type, 4);
- ItemSkill* skill
- = Game::INSTANCE->zItemType(type)->createDefaultItemSkill();
- skill->load(zReader);
- zEntity->skills.add(skill);
- }
- }
- void EntityType::saveSuperEntity(
- Entity* zEntity, Framework::StreamWriter* zWriter) const
- {
- zEntity->saveInventory(zWriter);
- zWriter->schreibe((char*)&zEntity->id, 4);
- zWriter->schreibe((char*)&zEntity->maxHP, 4);
- zWriter->schreibe((char*)&zEntity->currentHP, 4);
- zWriter->schreibe((char*)&zEntity->stamina, 4);
- zWriter->schreibe((char*)&zEntity->maxStamina, 4);
- zWriter->schreibe((char*)&zEntity->hunger, 4);
- zWriter->schreibe((char*)&zEntity->maxHunger, 4);
- zWriter->schreibe((char*)&zEntity->thirst, 4);
- zWriter->schreibe((char*)&zEntity->chatSecurityLevel, 4);
- zWriter->schreibe((char*)&zEntity->maxThirst, 4);
- zWriter->schreibe((char*)&zEntity->speed.x, 4);
- zWriter->schreibe((char*)&zEntity->speed.y, 4);
- zWriter->schreibe((char*)&zEntity->speed.z, 4);
- zWriter->schreibe((char*)&zEntity->faceDir.x, 4);
- zWriter->schreibe((char*)&zEntity->faceDir.y, 4);
- zWriter->schreibe((char*)&zEntity->dimensionId, 4);
- zWriter->schreibe((char*)&zEntity->location.x, 4);
- zWriter->schreibe((char*)&zEntity->location.y, 4);
- zWriter->schreibe((char*)&zEntity->location.z, 4);
- ActionTarget::save(zEntity->target, zWriter);
- // save item skills
- int skillCount = zEntity->skills.getEintragAnzahl();
- zWriter->schreibe((char*)&skillCount, 4);
- for (ItemSkill* skill : zEntity->skills)
- {
- int type = skill->getItemTypeId();
- zWriter->schreibe((char*)&type, 4);
- skill->save(zWriter);
- }
- }
- void EntityType::createSuperEntity(Entity* zEntity) const {}
- bool EntityType::initialize(Game* zGame)
- {
- return true;
- }
- Entity* EntityType::loadEntity(Framework::StreamReader* zReader) const
- {
- Entity* entity = createEntity(Framework::Vec3<float>(0, 0, 0), 0, 0);
- loadSuperEntity(entity, zReader);
- return entity;
- }
- void EntityType::saveEntity(
- Entity* zEntity, Framework::StreamWriter* zWriter) const
- {
- saveSuperEntity(zEntity, zWriter);
- }
- Entity* EntityType::createEntityAt(
- Framework::Vec3<float> position, int dimensionId) const
- {
- Entity* entity = createEntity(
- position, dimensionId, Game::INSTANCE->getNextEntityId());
- createSuperEntity(entity);
- return entity;
- }
- int EntityType::getId() const
- {
- return id;
- }
- ModelInfo* EntityType::zModel() const
- {
- return model;
- }
- void EntityType::setTypeId(int id)
- {
- this->id = id;
- }
- Framework::Text EntityType::getName() const
- {
- return name;
- }
|