Esempio n. 1
0
	void SpellSystem::affect(Entity& entity)
	{
		Spell*	spell;

		if ((spell = dynamic_cast<Spell*>(entity[ecs::AComponent::ComponentType::SPELL])) != nullptr)
		{
			Spell::SpellType	spellType = spell->getSpellType();
			if (spellType == lastSpellType)
				return;
			GraphicUtil&	graphics = GraphicUtil::getInstance();
			ecs::Position cameraPosition(graphics.getSceneManager()->getActiveCamera()->getAbsolutePosition(),
										graphics.getSceneManager()->getActiveCamera()->getTarget());
			if (spellType == Spell::SpellType::NOTHING)
			{
				switch (lastSpellType)
				{
				case ecs::Spell::BLIND:
					graphics.getBlindFx()->hide();
					break;
				case ecs::Spell::PARANOIA:
					PlayerManager::getInstance().loadNormalTeamTexture();
					break;
				case ecs::Spell::CONFUSION:
					graphics.getFPSCamera()->loadDefaultKeys();
					break;
				case ecs::Spell::DEAF:
					Audio::getInstance().setIsDeaf(false);
					break;
				case ecs::Spell::PARKINSON:
					Target::getInstance().setIsTrembling(false);
					break;
				case ecs::Spell::SLOW:
					graphics.getFPSCamera()->setSpeed(0.5f, 100.0f);
					break;
				default:
					break;
				}
			}
			else
			{
				switch (spellType)
				{
				case ecs::Spell::BLIND:
					GraphicUtil::getInstance().getBlindFx()->display();
					break;
				case ecs::Spell::PARANOIA:
					PlayerManager::getInstance().loadInvertTeamTexture();
					break;
				case ecs::Spell::CONFUSION:
					graphics.getFPSCamera()->loadInvertKeys();
					break;
				case ecs::Spell::DEAF:
					Audio::getInstance().setIsDeaf(true);
					break;
				case ecs::Spell::PARKINSON:
					Target::getInstance().setIsTrembling(true);
					break;
				case ecs::Spell::SLOW:
					graphics.getFPSCamera()->setSpeed(0.1f, 50.0f);
					break;
				default:
					break;
				}
			}
			lastSpellType = spellType;
		}
	}
Esempio n. 2
0
//Spell stuff
void GameEngine::useSpell(Point mouseLoc) {
	Spell spell = invLog.getSpell(mouseLoc);

	if (spell.isUnlocked()) {
		if (hero->getMana() < spell.getCost())
			log.registerEvent("Not enough mana!");
		else {
			log.registerEvent(spell.getTitle() + " activated!");

			Point start = hero->getLoc() + Point(-1, -1);
			Point end = hero->getLoc() + Point(2, 2);

			int type = spell.getSpellType();
			switch (type) {
				case 1: //Field of fire
				{
					spell.setTurnActivated(turns);

					lib.loop_portion(start, end, [&](Point p) {
						map[p.x()][p.y()].setSpell(spell);
					});
					break;
				}
				case 2: //Death Rattle
				{
					lib.loop_portion(start, end, [&](Point p) {
						Actor* a = map[p.x()][p.y()].getActor();

						if (a != NULL) {
							Point relToHero = p - hero->getLoc();
							Point d(p.x() + relToHero.x(), p.y() + relToHero.y());
							
							a->doDMG(2);
							if (a->getHP() <= 0)
								killMonster(a->getLoc());

							if (moveableCell(d)) {
								map[p.x()][p.y()].setActor(NULL);
								a->setLoc(d);
								map[d.x()][d.y()].setActor(a);
							}
						}
					});
					break;
				}
				case 3: //Blessing of Katar
				{
					hero->changeHP(10);
					break;
				}
				case 4: //Ice Block
				{
					spell.setTurnActivated(turns);

					lib.loop_portion(start, end, [&](Point p) {
						map[p.x()][p.y()].setSpell(spell);
					});
					break;
				}
				case 5: //Death Curse
				{
					spell.setTurnActivated(turns);

					lib.loop_portion(start, end, [&](Point p) {
						Actor* a = map[p.x()][p.y()].getActor();
						if (a != NULL) {
							a->setSpell(spell);
						}
					});
					break;
				}
				case 6: //Fist of Katar
				{
					map[hero->getLoc().x()][hero->getLoc().y()].setSpell(spell);
					break;
				}
			}

			hero->changeMana(-spell.getCost());
			lib.play("Spell" + to_string(spell.getSpellType()));
		}
	}
}