Exemplo n.º 1
0
bool Entity::attack(){

	if (Victim == NULL)
		return false;
	

	// Don't attack dead or hurt people
	if (Victim->Action == CHAR_DIE || Victim->Action == CHAR_HURT)
		return false;

	// Set attacker and victim
	Victim->Attacker = this;
	this->Victim = Victim;
	notify(*this, EVENT_ATTACK);

	// Return if hit missed
	if ((rand() % 1000) > getToHit(Victim)) {
		
		std::string miss_msg = getEntityType().c_str() + std::string(" missed!");
		log_message->setString(miss_msg);
		log_message->setColor(sf::Color::Yellow);
		addMessage(miss_msg.c_str(), 1000, sf::Color::Yellow);
		return false;
	}
	
	// Return if hit dodged
	if ((rand() % 1000) <= getAgility(Victim)) {
		std::string dodge_msg = getEntityType().c_str() + std::string(" dodged!");
		log_message->setString(dodge_msg);
		log_message->setColor(sf::Color::Yellow);
		addMessage(dodge_msg.c_str(), 1000, sf::Color::Yellow);
		return false;
	}

	// If this is asleep, randomly wake them up (50% chance)
	if (Victim->Ailments & AILMENT_SLEEP) {
		if ((rand() % 100) < 50)
			Victim->Ailments &= ~AILMENT_SLEEP;
	}

	// Attack landed, apply damage
	damage(Victim, true, getAttack(this), -1, -1);
	
	return true;

}
Exemplo n.º 2
0
float Archer::getCollisionPriority(Entity* e) const
{
	if (e->getEntityType() == getEntityType())
	{
		return -0.4f;
	}
	return 1.f;
}
Exemplo n.º 3
0
    bool operator<( FullID const& rhs ) const
    {
        // first look at the EntityType
        if( getEntityType() != rhs.getEntityType() )
        {
            return getEntityType() < rhs.getEntityType();
        }

        // then compare the SystemPaths
        // FIXME: should be faster is there is SystemPath::compare()
        if( getSystemPath() != rhs.getSystemPath() )
        {
            return getSystemPath() < rhs.getSystemPath();
        }

        // finally compare the ID strings
        return getID() < rhs.getID();
    }
Exemplo n.º 4
0
    bool operator==( FullID const& rhs ) const
    {
        // first look at the EntityType
        if( getEntityType() != rhs.getEntityType() )
        {
            return false;
        }

        // then compare the SystemPaths
        if( getSystemPath() != rhs.getSystemPath() )
        {
            return false;
        }

        // finally compare the ID strings
        return getID() == rhs.getID();
    }
Exemplo n.º 5
0
Atlas::Message::MapType EntityRecipe::createEntity(Eris::TypeService& typeService)
{
	S_LOG_VERBOSE("Creating entity.");

	ScriptingService& scriptingService = EmberServices::getSingleton().getScriptingService();
	// Loading script code
	scriptingService.executeCode(mScript, "LuaScriptingProvider");

	// Walking through adapter bindings
	for (BindingsStore::iterator I = mBindings.begin(); I != mBindings.end(); ++I) {
		const std::string& func = I->second->getFunc();

		S_LOG_VERBOSE(" binding: " << I->first << " to func " << func);

		if (func.empty()) {
			std::vector<std::string>& adapters = I->second->getAdapters();

			if (adapters.size() == 1) {
				std::string adapterName = adapters[0];
				Atlas::Message::Element val = mGUIAdapters[adapterName]->getValue();
				I->second->setValue(val);
			} else {
				S_LOG_WARNING("Should be only one adapter without calling function.");
			}
		} else {
			Lua::LuaScriptingCallContext callContext;

			lua_State* L = static_cast<Lua::LuaScriptingProvider*> (scriptingService.getProviderFor("LuaScriptingProvider"))->getLuaState();

			// Pushing function params
			std::vector<std::string>& adapters = I->second->getAdapters();
			for (std::vector<std::string>::iterator J = adapters.begin(); J != adapters.end(); J++) {
				std::string adapterName = *J;
				Atlas::Message::Element* val = new Atlas::Message::Element(mGUIAdapters[adapterName]->getValue());
				tolua_pushusertype_and_takeownership(L, val, "Atlas::Message::Element");
			}

			// Calling test function
			scriptingService.callFunction(func, adapters.size(), "LuaScriptingProvider", &callContext);

			LuaRef returnValue(callContext.getReturnValue());

			Atlas::Message::Element returnObj;
			returnObj = returnValue.asObject<Atlas::Message::Element> ("Atlas::Message::Element");
			I->second->setValue(returnObj);
		}
	}
	//Inject all default attributes that aren't yet added.
	// 	TiXmlElement *elem = mEntitySpec->FirstChildElement("atlas");
	// 	if (elem)
	// 	{
	// 		Eris::TypeInfo* erisType = mConn->getTypeService()->getTypeByName(getEntityType());
	// 		if (erisType) {
	// 			const Atlas::Message::MapType& defaultAttributes = erisType->getAttributes();
	// 			for (Atlas::Message::MapType::const_iterator I = defaultAttributes.begin(); I != defaultAttributes.end(); ++I) {
	// 				bool hasAttribute = false;
	// 				TiXmlNode* child(0);
	// 				while(child = elem->IterateChildren(child)) {
	// 					if (child->ToElement()) {
	// 						if (std::string(child->ToElement()->Attribute("name")) == I->first) {
	// 							hasAttribute = true;
	// 							break;
	// 						}
	// 					}
	// 				}
	//
	// 				if (!hasAttribute) {
	// 					//The attribute isn't present, we'll inject it
	// 					//This a bit contrived, since we'll now first convert the atlas into xml and inject it into the TiXmlElement (which will convert the xml strings into TiXml structures). And then later on we'll parse the xml again and create the final atlas data from it. However, the main reason for doing it this way is that in the future we would want to have nested child elements, which could be repeated. And in those cases we'll want to work directly with xml.
	// 				}
	// 			}
	// 		}
	// 	}
	/*
	 std::stringstream str;

	 Atlas::Message::Element element(message);

	 Atlas::Message::QueuedDecoder decoder;

	 Atlas::Codecs::XML codec(str, decoder);
	 Atlas::Formatter formatter(str, codec);
	 Atlas::Message::Encoder encoder(formatter);
	 formatter.streamBegin();
	 encoder.streamMessageElement(message);
	 formatter.streamEnd();
	 */
	if (mEntitySpec) {
		// Print entity into string
		TiXmlPrinter printer;
		printer.SetStreamPrinting();
		mEntitySpec->Accept(&printer);

		S_LOG_VERBOSE("Composed entity: " << printer.Str());

		std::stringstream strStream(printer.CStr(), std::ios::in);

		// Create objects
		Atlas::Message::QueuedDecoder decoder;
		Atlas::Codecs::XML codec(strStream, decoder);

		// Read whole stream into decoder queue
		while (!strStream.eof()) {
			codec.poll();
		}

		// Read decoder queue
		while (decoder.queueSize() > 0) {
			Atlas::Message::MapType m = decoder.popMessage();
			Eris::TypeInfo* erisType = typeService.getTypeByName(getEntityType());
			if (erisType) {
				const Atlas::Message::MapType& defaultAttributes = erisType->getAttributes();
				for (Atlas::Message::MapType::const_iterator I = defaultAttributes.begin(); I != defaultAttributes.end(); ++I) {
					if (m.find(I->first) == m.end()) {
						m.insert(Atlas::Message::MapType::value_type(I->first, I->second));
					}
				}
			}
			return m;
		}
	} else {
		Atlas::Message::MapType msg;
		msg["parents"] = Atlas::Message::ListType(1, mEntityType);
		msg["name"] = getName();
		return msg;
	}
	S_LOG_WARNING("No entity composed");
	return Atlas::Message::MapType();
}
Exemplo n.º 6
0
bool Entity::damage(Entity *Victim, bool PhysicalAttack, long Amount, long DmgClass, long CureClass){

	char Text[128];
	float Resist;
	float Range;
	long  DmgAmount;

	// Error checking
	if (Victim == NULL)
		return false;

	// Can't attack if already dead or being hurt (or not enabled)
	if ( Victim->Action == CHAR_DIE ||	Victim->Action == CHAR_HURT)
		return false;

	// Adjust for definition if physical attack
	if (PhysicalAttack == true) {

		// Random value for less/more damage (-+20%)
		Range = (float)((rand() % 20) + 90) / 100.0f;
		DmgAmount = (long)((float)Amount * Range);

		// Subtract for defense of victim (allow -20% difference)
		Range = (float)((rand() % 20) + 80) / 100.0f;
		DmgAmount -= (long)((float)getDefense(Victim) * Range);
	}
	else {
		// Adjust for magical attack
		Resist = 1.0f - ((float)getResistance(Victim) / 100.0f);
		DmgAmount = (long)((float)Amount * Resist);
	}

	// Bounds check value
	if (DmgAmount < 0)
		DmgAmount = 0;

	// Check for double damage
	if (Victim->definition.Class == DmgClass)
		DmgAmount *= 2;

	// Check for cure damage
	if (Victim->definition.Class == CureClass)
		DmgAmount = -(labs(DmgAmount) / 2);

	// If no physical damage is dealt then randomly deal 
	// 10-20% of damage from the original amount.
	if (!DmgAmount && PhysicalAttack == true) {
		Range = (float)((rand() % 10) + 10) / 100.0f;
		DmgAmount = (long)((float)Amount * Range);
	}

	// Subtract damage amount
	Victim->current_health -=  DmgAmount;

	// Set hurt status and display message
	if (DmgAmount > 0) {
		

		sprintf_s(Text, "-%lu HP", DmgAmount);
		std::string msg = Victim->getEntityType() + " loss " + std::to_string(DmgAmount) + " HP";
		log_message->setString(msg);
		log_message->setColor(sf::Color::Red);
		Victim->addMessage(Text, 1000, sf::Color::Red);

		// Only set hurt if any damage (and idle or moving)
		if (DmgAmount) {
			if (Victim->Action == CHAR_MOVE || Victim->Action == CHAR_IDLE)
				setAction( CHAR_HURT);
				notify(*Victim, EVENT_HURT);

		}
	}

	// Display cure amount
	if (DmgAmount < 0) {

		sprintf_s(Text, "+%lu HP", -DmgAmount);
		std::string msg = getEntityType() + " gained " +  std::to_string(DmgAmount) + " HP" ;
		log_message->setString(msg);
		log_message->setColor(sf::Color::Green);
		addMessage(Text, 1000, sf::Color::Green);
	}

	return true;

}
Exemplo n.º 7
0
FullID Entity::getFullID() const
{
    return FullID( getEntityType(), getSystemPath(), getID() );
}
Exemplo n.º 8
0
int StreamStore::getInformation(std::shared_ptr<InformationSpecification> request,
                                std::vector<std::shared_ptr<InformationElement<GContainer>>> &outInfo,
                                bool useTransfromation)
{
  int count = 0;

  for (auto &stream : this->collections)
  {
    auto gstream = std::static_pointer_cast<InformationStream<GContainer>>(stream);

    auto infoSpec = stream->getDescription()->getInformationSpecification();

    if (request->getEntity() != "*" && request->getEntity() != infoSpec->getEntity())
    {
      continue;
    }
    if (request->getEntityType() != infoSpec->getEntityType())
    {
      continue;
    }
    if (request->getScope() != infoSpec->getScope())
    {
      continue;
    }
    if (request->getRepresentation() != infoSpec->getRepresentation())
    {
      if (useTransfromation && request->getRelatedEntity() == ""
          && infoSpec->getRelatedEntity() == "")
      {
        // check if transformation exists
        auto rep = this->gcontainerFactory->getTransformation(infoSpec->getRepresentation(),
                                                              request->getRepresentation());

        if (rep == nullptr)
          continue;

        std::shared_ptr<GContainer> input[1];
        input[0] = gstream->getLast()->getInformation();
        auto transInfo = rep->transform(input);

        if (transInfo == nullptr)
          continue;

        auto spec = std::make_shared<InformationSpecification>(infoSpec->getEntity(),
                                                               infoSpec->getEntityType(),
                                                               infoSpec->getScope(),
                                                               request->getRepresentation(),
                                                               infoSpec->getRelatedEntity());
        auto element = std::make_shared<InformationElement<GContainer>>(spec, transInfo);
        outInfo.push_back(element);
        ++count;
      }

      continue;
    }
    if (request->getRelatedEntity() != infoSpec->getRelatedEntity())
    {
      continue;
    }

    outInfo.push_back(gstream->getLast());
    ++count;
  }

  return count;
}