Exemplo n.º 1
0
bool CombatSpell::castSpell(Creature* creature, Creature* target)
{
	if (scripted) {
		LuaVariant var;

		if (combat->hasArea()) {
			var.type = VARIANT_POSITION;

			if (needTarget) {
				var.pos = target->getPosition();
			} else if (needDirection) {
				var.pos = Spells::getCasterPosition(creature, creature->getDirection());
			} else {
				var.pos = creature->getPosition();
			}
		} else {
			var.type = VARIANT_NUMBER;
			var.number = target->getID();
		}
		return executeCastSpell(creature, var);
	}

	if (combat->hasArea()) {
		if (needTarget) {
			combat->doCombat(creature, target->getPosition());
		} else {
			return castSpell(creature);
		}
	} else {
		combat->doCombat(creature, target);
	}
	return true;
}
Exemplo n.º 2
0
void EoBCoreEngine::useMagicScroll(int charIndex, int type, int weaponSlot) {
	_openBookCharBackup = _openBookChar;
	_openBookTypeBackup = _openBookType;
	_castScrollSlot = weaponSlot + 1;
	_openBookChar = charIndex;
	_openBookType = type <= _clericSpellOffset ? 0 : 1;
	castSpell(type, weaponSlot);
}
	std::string doMagic(std::string wish){
		auto spell=searchForSpell(wish);
		if (! spell.empty()){
			castSpell(spell);
			return "wootsh";
		}
		auto potion=mixPotion(wish);
		applyPotion(potion);
		return "zapp";
	}
Exemplo n.º 4
0
bool InstantSpell::castSpell(Creature* creature, Creature* target)
{
	if (needTarget) {
		LuaVariant var;
		var.type = VARIANT_NUMBER;
		var.number = target->getID();
		return internalCastSpell(creature, var);
	} else {
		return castSpell(creature);
	}
}
std::string WizardImpl::doMagic(std::string const &wish) {
	auto spell=searchForSpell(wish);
	if (! spell.empty()){
		castSpell(spell);
		return "wootsh";
	}
	auto potion=mixPotion(wish);
	if (!potion.empty()){
		applyPotion(potion);
		return "zapp";
	}
	throw std::logic_error{"magic failed"};
}
//catch users input key
bool Pongplayer::keyPress(char c)
{
    //catch the users input key press
    bool isKey = Character::keyPress(c);
    //if that key is not defined in the char class
    if(!isKey)
    {
        //check if that key may be the spell key and check if the ball hasnt moved yet
        if(c == spellKey && ball->getBallStatus() == false)
        {
            //if its a spell key run the castSpell method
            castSpell();
            return true;
        }
        return false;
    }
    return isKey;
}
Exemplo n.º 7
0
void spellcastingAnimationManager_completeSpell(spellcasting_animation_manager_t *animation_manager) {
	castSpell(animation_manager->caster, animation_manager->spell, FALSE, FALSE); //Actually cast the spell.

	spellcastingAnimationManager_deactivate(animation_manager);
}
Exemplo n.º 8
0
void Game::play(string path)
{
    pathTest=path;
    ini();

    //SDL_EnableKeyRepeat(10, 0);


    playLoop=true;
    fadingToLeave=false;

    while (playLoop)
    {

        if(m_chat.boxOpened())
            m_chat.checkKeyboard();
        else
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_QUIT:
                fadingToLeave=true;
                playLoop=false;
                command="quit";
                break;

                case SDL_MOUSEMOTION:
                m_camera.onMouseMotion(event.motion);
                break;

                case SDL_MOUSEBUTTONUP:
                if(event.button.button==SDL_BUTTON_LEFT)
                {
                    if(m_mode=="play")
                    {
                        if(playerList[0]->getLife()>0)
                        {
                            Vector3D dir=(m_camera.getTarget()-(playerList[0]->getPos()+Vector3D(0,0,1))).normalize();

                            if(castSpell(playerList[0],"rope",dir))
                            {
                                infosSocket s;
                                s.confirmationID=-1;
                                s.type=2;

                                s.variable[1]=playerList[0]->getPos().X;
                                s.variable[2]=playerList[0]->getPos().Y;
                                s.variable[3]=playerList[0]->getPos().Z;
                                s.variable[4]=dir.X;
                                s.variable[5]=dir.Y;
                                s.variable[6]=dir.Z;

                                m_online->sendSocket(s);//add socket to queue
                            }
                        }

                    }
                    else if(m_mode=="spectate")
                    {
                        switchSpectate(1);
                    }
                }
                if(event.button.button==SDL_BUTTON_RIGHT)
                {
                    if(m_mode=="play")
                    {
                        if(playerList[0]->getLife()>0)
                        {
                            playerList[0]->unlinkRope();

                            infosSocket s;
                            s.confirmationID=-1;
                            s.type=3;
                            m_online->sendSocket(s);//add socket to queue
                        }
                    }
                    else if(m_mode=="spectate")
                    {
                        switchSpectate(-1);
                    }
                }
                if(event.button.button==SDL_BUTTON_WHEELUP)
                {
                    Video::getInstance()->incrFOV(1);
                }
                if(event.button.button==SDL_BUTTON_WHEELDOWN)
                {
                    Video::getInstance()->incrFOV(-1);
                }
                break;

                case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                    case SDLK_KP_ENTER:
                    if(m_chat.active())
                        m_chat.openTextBox(playerList[0]->getIdOnline(),0.1);
                    break;
                    case SDLK_RETURN:
                    if(m_chat.active())
                        m_chat.openTextBox(playerList[0]->getIdOnline(),0.1);
                    break;
                    case SDLK_a:
                    playerList[0]->pressKey(LEFT,true);
                    break;
                    case SDLK_d:
                    playerList[0]->pressKey(RIGHT,true);
                    break;
                    case SDLK_w:
                    playerList[0]->pressKey(UP,true);
                    break;
                    case SDLK_s:
                    playerList[0]->pressKey(DOWN,true);
                    break;
                    case SDLK_e:
                    playerList[0]->pressKey(KEY_E,true);
                    break;
                    case SDLK_SPACE:
                    if(playerList[0]->getLife()>0)
                    {
                        if(shiftPushed)
                        {
                            if(castSpell(playerList[0],"longjump"))
                            {
                                infosSocket s;
                                s.confirmationID=-1;
                                s.type=15;

                                s.variable[1]=playerList[0]->getPos().X;
                                s.variable[2]=playerList[0]->getPos().Y;
                                s.variable[3]=playerList[0]->getPos().Z;

                                m_online->sendSocket(s);//add socket to queue
                            }

                        }
                        else
                            castSpell(playerList[0],"jump");
                    }
                    break;

                    case SDLK_LSHIFT:
                        playerList[0]->setGasing(true);
                        shiftPushed=true;
                    break;
                    default:
                    break;
                }
                break;

                case SDL_KEYUP:
                switch(event.key.keysym.sym)
                {
                    case SDLK_KP_ENTER:
                    if(m_chat.active())
                        m_chat.enterUp();
                    break;
                    case SDLK_RETURN:
                    if(m_chat.active())
                        m_chat.enterUp();
                    break;
                    case SDLK_ESCAPE:
                    fadingToLeave=true;
                    command="menu";
                    break;
                    case SDLK_a:
                    playerList[0]->pressKey(LEFT,false);
                    break;
                    case SDLK_d:
                    playerList[0]->pressKey(RIGHT,false);
                    break;
                    case SDLK_w:
                    playerList[0]->pressKey(UP,false);
                    break;
                    case SDLK_s:
                    playerList[0]->pressKey(DOWN,false);
                    break;
                    case SDLK_e:
                    playerList[0]->pressKey(KEY_E,false);
                    break;
                    case SDLK_r:
                    if(playerList.size()==1 &&
                       (!Online::getInstance()->active() || Online::getInstance()->inControl()))//if youre alone its ok
                    {
                        infosSocket s;
                        s.confirmationID=m_online->nextConfirmationID();
                        s.type=6;
                        m_online->sendSocket(s);//add socket to queue


                        Map::getInstance()->restart();

                        Interface::getInstance()->setTarget(playerList[0]);
                        m_camera.setCible(playerList[0]);
                        m_camera.setMode("play");
                        m_mode="play";

                        m_chat.newMessage("Map reset.",-2);
                    }
                    break;
                    case SDLK_k:
                    break;
                    case SDLK_c:
                    if(grabCursor)
                    {
                        SDL_ShowCursor(SDL_ENABLE);//pas de curseur
                        SDL_WM_GrabInput(SDL_GRAB_OFF);
                        grabCursor=false;
                    }
                    else
                    {
                        SDL_ShowCursor(SDL_DISABLE);//pas de curseur
                        SDL_WM_GrabInput(SDL_GRAB_ON);
                        grabCursor=true;
                    }
                    break;
                    case SDLK_LSHIFT:
                        playerList[0]->setGasing(false);
                        shiftPushed=false;
                    break;
                    case SDLK_SPACE:
                    if(playerList[0]->getLife()>0)
                    {
                        if(shiftPushed)
                        {
                            if(castSpell(playerList[0],"longjump"))
                            {
                                infosSocket s;
                                s.confirmationID=-1;
                                s.type=15;

                                s.variable[1]=playerList[0]->getPos().X;
                                s.variable[2]=playerList[0]->getPos().Y;
                                s.variable[3]=playerList[0]->getPos().Z;

                                m_online->sendSocket(s);//add socket to queue
                            }

                        }
                        else
                            castSpell(playerList[0],"jump");
                    }
                    break;
                    default:
                    break;
                }
                break;
            }
        }

        //update stuff
        updateTimes();
        updateMultiplayer();
        m_online->update();

        Gsounds::getInstance()->update(m_camera.getPos().toLeft(),Vector3D(0,0,0),m_camera.getDir().toLeft(),Vector3D(0,0,1));

        m_video->update(ft);
        Map::getInstance()->update(ft);

        Effects::getInstance()->update(ft);

        Tracer::getInstance()->traceCerr("debug","1");

        Interface::getInstance()->setMode(m_mode);
        Interface::getInstance()->update(ft);
        handleCommands();
        handleTracer();

        Tracer::getInstance()->traceCerr("debug","2");

        updateCamMode();

        //you just died
        if(playerList[0]->getLife()<=0 && !alreadyDead)
        {
            alreadyDead=true;
            Interface::getInstance()->warning("../data/textures/interface/warning/died.png",0.03);


            //send chat msg
            stringstream ss;
            int dc=playerList[0]->getDeathCause();

            if(dc==0)
                ss << playerList[0]->getOnlineName() << " mysteriously died.";
            else if(dc==1)
                ss << playerList[0]->getOnlineName() << " burned to death.";
            else if(dc==2)
                ss << playerList[0]->getOnlineName() << " committed suicide.";
            else if(dc==3)
                ss << playerList[0]->getOnlineName() << " exploded in pieces.";

            char* tempChar=stringtochar(ss.str());
            m_chat.newMessage(tempChar,-2);
            delete tempChar;
        }
        else if(playerList[0]->getLife()>0)
            alreadyDead=false;

        Tracer::getInstance()->traceCerr("debug","3");

        //endlevel
        if(checkEndLevel())
            endLevel();

        //crosshair
        Map::getInstance()->simulateRopeForCrosshair(playerList[0],
                                       (m_camera.getTarget()-(playerList[0]->getPos()+Vector3D(0,0,1))).normalize(),
                                       Interface::getInstance()->getCrosshair());

        draw();

        m_video->afterDraw();

        //fps calcul
        m_fps++;
        m_fpsTime.couler();
        if(m_fpsTime.ecouler(1000))
        {
            Interface::getInstance()->setFPS(m_fps);
            m_fps=0;
            m_fpsTime.reset();
        }

        Tracer::getInstance()->traceCerr("debug","8");

        SDL_Delay(10);



        if(fadingToLeave)
        {
            if(Video::getInstance()->getFade()->getFading()==false)
            {
                Video::getInstance()->getFade()->setR(0);
                Video::getInstance()->getFade()->setG(0);
                Video::getInstance()->getFade()->setB(0);
                Video::getInstance()->getFade()->startFadeIn();
            }
            if(Video::getInstance()->getFade()->getAlpha()>=1)
            {
                playLoop=false;
                fadingToLeave=false;
            }
        }
    }


    close();
}
Exemplo n.º 9
0
int World::handleMessage(Message& msg)
{
	std::string type = msg.getString("msgtype");
	if(type=="startturn")
	{
		int plyr = msg.getInt("player");
		ManaCap[plyr] += 1;
		Mana[plyr] = ManaCap[plyr];
		for(int i = 0;i<VerticalTileCount;i++)
		{
			for(int j = 0;j<HorizontalTileCount;j++)
			{
				int id = getUnitAt(j,i);
				if(id!=-1)
				{
					if(plyr==units.at(id).Owner)
					{
						for(int k = 0;k<units.at(id).abilityCount;k++) //lower cooldowns
						{
							if(units.at(id).abilities.at(k).currCooldown>0)
							{
								units.at(id).abilities.at(k).currCooldown -= 1;
							}
						}
						if(getUnitCanReady(id))
						{
							Message msg("unitready");
							msg.addValue("unit",std::to_string(id));
							MsgMngr.sendMessage(msg);
						}
					}
				}
			}
		}
	}
	else if(type=="endturn")
	{
		int plyr = msg.getInt("player");
		for(int i = 0;i<VerticalTileCount;i++)
		{
			for(int j = 0;j<HorizontalTileCount;j++)
			{
				int id = getUnitAt(j,i);
				if(id!=-1)
				{
					for(int i = 0;i<units.at(id).buffs.size();i++)
					{
						if(units.at(id).buffs.at(i).Duration!=-1)
						{
							units.at(id).buffs.at(i).Duration--; //reduce buff duration
							if(units.at(id).buffs.at(i).Duration==0)
							{
								units.at(id).buffs.erase(units.at(id).buffs.begin()+i);
								i--;
							}
						}
					}
					if(units.at(id).timedLife>0)
					{
						units.at(id).timedLife--;
					}
				}
			}
		}
		deadUnitCheck();
	}
	else if(type=="unitcast")
	{
		castSpell(msg.getInt("caster"),msg.getInt("spell"),msg.getInt("targetx"),msg.getInt("targety"));
	}
	else if(type=="dodeadunitcheck")
	{
		deadUnitCheck();
	}
	else if(type=="unitsummon")
	{
		summonUnit(msg.getString("unittype"),msg.getInt("x"),msg.getInt("y"),msg.getInt("owner"));
	}
	else if(type=="unitmove")
	{
		int uid = msg.getInt("unit");
		int j = msg.getInt("targetx");
		int i = msg.getInt("targety");
		units.at(uid).MovePoints -= getUnitTileEnterCost(uid,units.at(uid).x,units.at(uid).y,j,i)
			+ getUnitTileExitCost(uid,units.at(uid).x,units.at(uid).y,j,i);
		moveUnit(uid,j,i);
	}
	else if(type=="unitattack")
	{
		int uid = msg.getInt("unit");
		int target = msg.getInt("target");

		int attack = getUnitAttack(uid);
		if(attack>0)
		{
			Message msg("unitdamage");
			msg.addValue("source",uid);
			msg.addValue("target",target);
			msg.addValue("amount",attack);
			msg.addValue("damagetype",DAMAGETYPE_ATTACK);
			MsgMngr.sendMessage(msg);
		}

		units.at(uid).hasAttacked = 1;
		units.at(uid).MovePoints -= getUnitAttackCost(uid);

		Animation a("Attack1","Attack",getSpritePos(units.at(target).x,units.at(target).y),1);
		ActiveAnimations.push_back(a);
		ActiveAnimations.at(ActiveAnimations.size()-1).play();
	}
	else if(type=="unitdamage")
	{
		int src = msg.getInt("source");
		int target = msg.getInt("target");
		int amt = msg.getInt("amount");
		damageUnit(src,target,amt);
		deadUnitCheck();
	}
	else if(type=="unitdamagearea")
	{
		int src = msg.getInt("source");
		int tx = msg.getInt("targetx");
		int ty = msg.getInt("targety");
		int range = msg.getInt("range");
		int amt = msg.getInt("amount");
		int dmgtype = msg.getInt("damagetype");
		int flags = msg.getInt("targetflags");
		damageUnitArea(src,tx,ty,range,amt,dmgtype,flags);
		deadUnitCheck();
	}
	else if(type=="unitheal")
	{
		healUnit(msg.getInt("source"),msg.getInt("target"),msg.getInt("amount"));
		deadUnitCheck();
	}
	else if(type=="unithealarea")
	{
		int src = msg.getInt("source");
		int tx = msg.getInt("targetx");
		int ty = msg.getInt("targety");
		int range = msg.getInt("range");
		int amt = msg.getInt("amount");
		int flags = msg.getInt("targetflags");
		healUnitArea(src,tx,ty,range,amt,flags);
		deadUnitCheck();
	}
	else if(type=="unitdestroy")
	{
		units.at(msg.getInt("unit")).Life = 0;
		deadUnitCheck();
	}
	else if(type=="unitteleport")
	{
		moveUnit(msg.getInt("unit"),msg.getInt("targetx"),msg.getInt("targety"));
	}
	else if(type=="unitdeath")
	{
		int uid = msg.getInt("unit");
		tiles[units.at(uid).x][units.at(uid).y].isOccupied = false;
		//units.erase(uid);
		units.at(uid).UniqueId = -1;
		if(SelectionId == uid)
		{
			SelectionId = -1;
		}
	}
	else if(type=="unitready")
	{
		units.at(msg.getInt("unit")).hasAttacked = 0; //refresh attack status
		units.at(msg.getInt("unit")).MovePoints = 6;
	}
	else if(type=="unitsetlife")
	{
		units.at(msg.getInt("unit")).Life = msg.getInt("amount");
	}
	else if(type=="unitsetmaxlife")
	{
		units.at(msg.getInt("unit")).maxLife = msg.getInt("amount");
	}
	else if(type=="unitsetbaseattack")
	{
		units.at(msg.getInt("unit")).Attack = msg.getInt("amount");
	}
	else if(type=="unitsetmovepoints")
	{
		units.at(msg.getInt("unit")).MovePoints = msg.getInt("amount");
	}
	else if(type=="unitchangeowner")
	{
		units.at(msg.getInt("unit")).Owner = msg.getInt("owner");
	}
	else if(type=="unitsettimedlife")
	{
		units.at(msg.getInt("unit")).timedLife = msg.getInt("amount");
	}
	else if(type=="buffcreate")
	{
		Buff b(msg.getInt("bufftype"),msg.getInt("target"),msg.getInt("duration"),msg.getInt("owner"),msg.getInt("ispermanent"),0,0);
		units.at(msg.getInt("target")).buffs.push_back(b);
	}
	else if(type=="buffremove")
	{
		int uid = msg.getInt("target");
		int bid = msg.getInt("bufftype");
		for(int i = 0;i<world.units.at(uid).buffs.size();i++)
		{
			if(world.units.at(uid).buffs.at(i).BuffType==bid)
			{
				units.at(uid).buffs.erase(world.units.at(uid).buffs.begin()+i);
				i--;
			}
		}
	}
	else if(type=="buffdispel")
	{
		dispelUnit(msg.getInt("unit"),msg.getInt("targetflags"));
	}
	else if(type=="buffsetduration")
	{
		units.at(msg.getInt("unit")).buffs.at(msg.getInt("buff")).Duration = msg.getInt("duration");
	}
	else if(type=="spellsetcurrentcooldown")
	{
		units.at(msg.getInt("unit")).abilities.at(msg.getInt("spell")).currCooldown = msg.getInt("cooldown");
	}
	else if(type=="tiletypechange")
	{
		world.tiles[msg.getInt("x")][msg.getInt("y")].setType(msg.getInt("tiletype"));
	}
	else if(type=="playanimation")
	{
		Animation a(msg.getString("animation"),msg.getString("sound"),getSpritePos(msg.getInt("x"),msg.getInt("y")),atof(msg.getString("scalingfactor").c_str()));
		ActiveAnimations.push_back(a);
		ActiveAnimations.at(ActiveAnimations.size()-1).play();
	}
	else if(type=="playsound")
	{
		ActiveAnimations.push_back(Animation("Attack1",msg.getString("sound"),0,0,1.0,1));
		ActiveAnimations.at(ActiveAnimations.size()-1).play();
	}
	return 0;
}