void PlayerAi::handleActionKey(Actor *owner, int ascii)
{
    switch (ascii)
    {
        case 'd': // drop item
        {
            Actor *actor = choseFromInventory(owner);
            if(actor)
            {
                actor->pickable->drop(actor, owner);
                engine.gameStatus = Engine::NEW_TURN;
            }
        }
        break;
        case 'g': // pickup item
        {
            bool found = false;
            for(Actor **iterator = engine.actors.begin(); iterator != engine.actors.end(); iterator++)
            {
                Actor *actor = *iterator;
                if(actor->pickable && actor->x == owner->x && actor->y == owner->y)
                {
                    if(actor->pickable->pick(actor, owner))
                    {
                        found = true;
                        engine.gui->message(TCODColor::lightGrey, "You pick the %s.", actor->name);
                        break;
                    }
                    else if(!found)
                    {
                        found = true;
                        engine.gui->message(TCODColor::red, "Your inventory is full.");
                    }
                }
            }
            if(!found)
            {
                engine.gui->message(TCODColor::lightGrey, "There is nothing here that you can pick.");
            }
            engine.gameStatus = Engine::NEW_TURN;
        }
        break;
        case 'i': // display inventory
        {
            Actor *actor = choseFromInventory(owner);
            if(actor)
            {
                actor->pickable->use(actor, owner);
                engine.gameStatus = Engine::NEW_TURN;
            }
        }
        break;
        default: break;
    }
}
Example #2
0
void PlayerAi::handleActionKey(Actor *owner, int ascii, bool control, bool alt) {
	switch (ascii) {
		case 'g': //pickup item 
		{
			bool found = false;
			for (Actor **iterator = engine.actors.begin();
				iterator != engine.actors.end(); iterator++) {
				Actor *actor = *iterator;
				if (actor->pickable && actor->x == owner->x && actor->y == owner->y) {
					if (actor->pickable->pick(actor,owner)) {
						found = true;
						engine.gui->message(TCODColor::lightGrey,"You pick up the %s.",actor->getName());
						break;
					} else if (!found) {
						found = true;
						engine.gui->message(TCODColor::red,"Your inventory is full.");
					}
				}
			}
			if (!found) {
				engine.gui->message(TCODColor::lightGrey,"There's nothing interesting here.");
			}
			engine.gameStatus = Engine::NEW_TURN;
		}
		break;
		case 'i': //display inventory
		{
			Actor *actor = choseFromInventory(owner);
			if (actor) {
				engine.gui->message(TCODColor::lightGreen,"You use the %s",actor->getName());
				actor->pickable->use(actor,owner);
				engine.gameStatus = Engine::NEW_TURN;
			}
		}
		break;
		case 'd': //drop item
		{
			Actor *actor = choseFromInventory(owner);
			if (actor) {
				actor->pickable->drop(actor,owner);
				engine.gameStatus=Engine::NEW_TURN;
			}
		}
		break;
		case '>': //go down the stairs, if atop them
		{
			if (engine.stairs->x == owner->x && engine.stairs->y == owner->y) {
				owner->attacker->lastTarget = NULL;
				engine.nextLevel();
			} else {
				engine.gui->message(TCODColor::lightGrey,"There are no stairs here.");
			}
		}
		break;
		case 'l' : //use the 'l'ook function
		{
			engine.gui->renderKeyLook();
		}
		break;
		case 's':
		{
			if (control) {
				engine.save();
				engine.gui->message(TCODColor::lightPink, "SAVED");
			}
		}
		break;
		case 'c':
		{
			if (control){
				if (owner->caster) owner->caster->enterCantus();
			} else {
				if (owner->caster) {
					Spell *spell = owner->caster->chooseFromSpellBook();
					if (spell != NULL){
						bool spellSuccess = owner->caster->cast(owner, spell);
						if (spellSuccess){
							engine.gameStatus = Engine::NEW_TURN;
//							std::cout << "got to after spell cast" << std::endl;
						}
					}
				} 
			}
		break;
		}
		case 'C':
		{
			if (owner->caster) owner->caster->learnSpell(owner);
		}
		break;
	}
}