示例#1
0
void BattleListTab::OnHost( wxCommandEvent& /*unused*/ )
{
	if ( !ui().IsConnected() )
	{
		wxLogWarning( _T( "Trying to host while offline" ) );
		customMessageBoxNoModal( SL_MAIN_ICON, _( "You cannot host a game while being offline. Please connect to a lobby server." ), _( "Not Online." ), wxOK );
		ui().ShowConnectWindow();
		return;
	}
	if ( !ui().IsSpringCompatible() )
	{
		wxLogWarning( _T( "Hosting is disabled due to the incompatible version " ) );
		customMessageBoxNoModal( SL_MAIN_ICON, _( "Hosting is disabled due to the incompatible version you're using" ), _( "Spring error" ), wxICON_EXCLAMATION | wxOK );
		return;
	}
	Battle* battle = ui().mw().GetJoinTab().GetCurrentBattle();
	if ( battle != 0 )
	{
		if ( ui().Ask( _( "Already in a battle" ), _( "You are already in a battle.\n\nDo you want to leave current battle to start a new?" ) ) ) {
			battle->Leave();
			ui().mw().GetJoinTab().LeaveCurrentBattle();
		}
		else
		{
			return;
		}
	}

	SL::RunHostBattleDialog( this );
}
示例#2
0
void ServerEvents::OnUserQuit( const wxString& nick )
{
    wxLogDebugFunc( _T("") );
    try
    {
        User &user=m_serv.GetUser( nick );
				Battle* userbattle = user.GetBattle();
				if ( userbattle )
				{
					int battleid = userbattle->GetID();
					try
					{
						if ( &userbattle->GetFounder() == &user )
						{
							for ( int i = 0; i < int(userbattle->GetNumUsers()); i ++ )
							{
								User& battleuser = userbattle->GetUser( i );
								OnUserLeftBattle( battleid, battleuser.GetNick() );
							}
							 OnBattleClosed( battleid );
						}
						else OnUserLeftBattle( battleid, user.GetNick() );
					}catch(...){}
				}
        ui().OnUserOffline( user );
        m_serv._RemoveUser( nick );
        if ( useractions().DoActionOnUser( UserActions::ActNotifLogin, nick ) )
            actNotifBox( SL_MAIN_ICON, nick + _(" just went offline") );
    }
    catch (std::runtime_error &except)
    {
    }
}
示例#3
0
void SimpleServerEvents::OnUserQuit( const wxString& nick )
{
    wxLogDebugFunc( _T("") );
    try
    {
        User &user=m_serv.GetUser( nick );
				Battle* userbattle = user.GetBattle();
				if ( userbattle )
				{
					int battleid = userbattle->GetID();
					try
					{
						if ( &userbattle->GetFounder() == &user )
						{
							for ( int i = 0; i < int(userbattle->GetNumUsers()); i ++ )
							{
								User& battleuser = userbattle->GetUser( i );
								OnUserLeftBattle( battleid, battleuser.GetNick() );
							}
							 OnBattleClosed( battleid );
						}
						else OnUserLeftBattle( battleid, user.GetNick() );
					}catch(...){}
				}
//        ui().OnUserOffline( user );
        m_serv._RemoveUser( nick );
    }
    catch (std::runtime_error &except)
	{ }
}
示例#4
0
bool  judge_dragon_ship_btl_over(Player * player) {
	Battle * btl = player->btl;
	if (btl->pvp_lv() == pvp_dragon_ship && !btl->is_battle_ended()) {
		//failed 
		Player * player_1 = btl->get_one_player();

		if (player_1 && player_1->my_summon) {
			if (player_1->pos().x() + 10 >= player_1->my_summon->pos().x() &&
					player_1->my_summon->i_ai->common_flag1_) {
				end_pvp_on_player_dead(btl, player_1, player_1->team);
				return true;
			}
		}

		Player* player_2 =  btl->get_one_other_player(player_1);
		if (player_2 && player_2->my_summon) {
			if (player_2->pos().x() + 10 >= player_2->my_summon->pos().x() && 
					player_2->my_summon->i_ai->common_flag1_) {
				end_pvp_on_player_dead(btl, player_2, player_2->team);
				return true;
			}
		}
	}
	return false;
}
示例#5
0
bool    battle_mgr::is_battle_exist(uint32_t battle_id)
{
	std::list<Battle*>::iterator pItr = btl_list.begin();
	for(; pItr != btl_list.end(); ++pItr)
	{
		Battle* btl = *pItr;
		if(btl->get_battle_id() == battle_id)return true;
	}
	return false;
}
示例#6
0
void BattleEvent::start() {
	setViewString("A monster has appeared!");
	Battle *nb = new Battle();
	MonsterManager &mm = MonsterManager::getInstance();
	//Monster *mon = mm.getMonster("centaur"); //mm.randomMonster();
	Monster* mon = mm.randomMonster();

	rewardval = mon->getReward();
	nb->addMonster(mon);
	SceneManager::getInstance().push(nb);
}
示例#7
0
void BattleInfo::battleChanged(const Battle & battle)
{
    if (battle.id() == battleId_)
    {
        if (currentMapImage_ != battle.mapName())
        {
            setMapImage(battle);
        }
        setHeaderText(battle);
    }
}
示例#8
0
void ScourgeView::centerOnMonsterInTB() {
    scourge->getMap()->setMapCenterCreature( NULL );
    if ( scourge->inTurnBasedCombat() ) {
        Battle *battle = scourge->getCurrentBattle();
        Creature *c = battle->getCreature();
        if ( !c->isPartyMember() || c->getStateMod( StateMod::possessed ) ) {
            scourge->getMap()->setMapCenterCreature( c );
            scourge->getMap()->center( toint( c->getX() ), toint( c->getY() ), true );
        }
    }
}
示例#9
0
void main(int argc, char** argv) {
	/* TODO: Parsing and options */
	Battle battle;
	battle.initBattle();
	Game game;
	game.setBattle();
	while(!game.isFinished()) {
		game.limitFPS();
		game.step();
	}
	
	return 0;
};
示例#10
0
size_t AmbushEvent::failure() {
  Battle* battle = new Battle(_storage, _raid_participants, _raid_slaves, _raid_resources, _raid_loot);
  battle->generate_enemies(FS_MEDIUM);
  size_t battle_outcome = battle->play();
  delete battle;
  if (battle_outcome == BO_RAIDERS_WON) {
    increase_misc_stat(MI_MORALE, BATTLE_MORALE_BOOST);
    return EO_SUCCESS;
  } else {
    decrease_misc_stat(MI_MORALE, BATTLE_MORALE_BOOST);
    return EO_FAILURE;
  }
}
示例#11
0
Battle*  battle_mgr::get_battle_by_id(uint32_t battle_id)
{
	std::list<Battle*>::iterator pItr = btl_list.begin();
	for(; pItr != btl_list.end(); ++pItr)
	{
		Battle* btl = *pItr;
		if(btl->get_battle_id() == battle_id)
		{
			return btl;
		}
	}
	return NULL;
}
示例#12
0
文件: roll.cpp 项目: Zhanyin/taomee
int player_roll_item_cmd(Player* p, uint8_t* body, uint32_t bodylen)
{
	CHECK_VAL_EQ(bodylen, (uint32_t)sizeof(player_roll_item_t));
	player_roll_item_t* pRoll = reinterpret_cast<player_roll_item_t*>(body);	
	int32_t roll_point = 0;	
	bool ret = set_player_roll_point(p, pRoll->battle_id, pRoll->roll_id, pRoll->roll_flag, roll_point);
	if( !ret){
		return send_header_to_player(p, p->waitcmd, cli_err_roll_item_fail, 1); 
	}
	Battle *btl = p->btl;
	//notify the other team player execpt myself and not clear waitcmd
	btl->notify_team_roll_point(pRoll->roll_id, p->id, roll_point, p->id);
	//notify myself and clear waitcmd
	return send_roll_point(p, pRoll->roll_id, roll_point);
}
示例#13
0
bool EnemyCard::encounter(Character* character, Game* game)
{
  game->getUI()->announce("You have encountered a " + this->title() + "!");
  Battle * battle = new Battle();
  int results = battle->cardFight(character, this, game);
  if (results == 1) {
    //Player won! Card is added to trophies and removed from the tile.
    character->addTrophy(this);
    return true;
  }
  else {
    //Stand-off or player has lost. Do not remove card from the tile.
    return false;
  }
}
示例#14
0
void SimpleServerEvents::AutoCheckCommandSpam( Battle& battle, User& user )
{
    wxString nick = user.GetNick();
    MessageSpamCheck info = m_spam_check[nick];
    time_t now = time( 0 );
    if ( info.lastmessage == now ) info.count++;
    else info.count = 0;
    info.lastmessage = now;
    m_spam_check[nick] = info;
    if ( info.count == 7 )
    {
			battle.DoAction( _T("is autokicking ") + nick + _T(" due to command spam.") );
			battle.KickPlayer( user );
    }
}
示例#15
0
void BattleInfo::battle(Battle const & battle)
{
    battleId_ = battle.id();

    setMapImage(battle);
    setHeaderText(battle);
}
示例#16
0
void PrivateChatTab::userJoinedBattle(User const & user, Battle const & battle)
{
    if (user.name() == userName_)
    {
        append(userName_ + " joined " + battle.title(), -1);
    }
}
示例#17
0
void PrivateChatTab::userLeftBattle(User const & user, Battle const & battle)
{
    if (user.name() == userName_)
    {
        append(userName_ + " left " + battle.title(), -1);
    }
}
示例#18
0
Battle* BattleManager::alloc_battle(room_t* room)
{
    Battle* battle = new Battle(room);

    if (battle == NULL) {
        KERROR_LOG(0, "out of memory");
        return NULL; 
    }

    battle_list_[battle_idx_] = battle;
    battle->set_battleid(battle_idx_);

    battle_idx_++;

    return battle;
}
示例#19
0
void BattleInfo::setMapImage(Battle const & battle)
{
    Fl_Image * image = cache_.getMapImage(battle.mapName());
    if (image)
    {
        mapImageBox_->label(0);
        mapImageBox_->image(image);
        currentMapImage_ = battle.mapName();
    }
    else
    {
        mapImageBox_->image(0);
        mapImageBox_->label("map\nnot\nfound");
        currentMapImage_.clear();
    }
}
示例#20
0
void BattleInfo::userLeftBattle(User const & user, const Battle & battle)
{
    if (battle.id() == battleId_)
    {
        setHeaderText(battle);
    }
}
示例#21
0
void BattleInfo::battleClosed(const Battle & battle)
{
    if (battle.id() == battleId_)
    {
        reset();
    }
}
示例#22
0
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
						  LPSTR lpCmdLine, int nCmdShow)
#endif
{
	sys.set_config_dir();

	//try to read from CONFIG.DAT, moved to AM.CPP

	if( !config.load("CONFIG.DAT") )
	{
		new_config_dat_flag = 1;
		config.init();
   }

   if( !sys.init() )
      return FALSE;

   err.set_extra_handler( extra_error_handler );   // set extra error handler, save the game when a error happens

   // set mouse cursor now to prevent bugginess later
   mouse_cursor.set_icon(CURSOR_NORMAL);

   // launch game directly
   game.init();
   battle.run(0);
   game.deinit();

   sys.deinit();

   return 1;
}
示例#23
0
void MapSelectDialog::LoadPopular()
{
	wxLogDebugFunc( _T("") );

	m_mapgrid->Clear();

	try {
		serverSelector().GetServer().battles_iter->IteratorBegin();
		while ( !serverSelector().GetServer().battles_iter->EOL() ) {
			Battle* b = serverSelector().GetServer().battles_iter->GetBattle();
			const wxString mapname = b->GetHostMapName();
			assert(!mapname.empty());
			if ( b != NULL ) m_mapgrid->AddMap( mapname );
		}
	}
	catch (...) {} // ui().GetServer may throw when disconnected...

	m_mapgrid->Refresh();
}
示例#24
0
文件: roll.cpp 项目: Zhanyin/taomee
bool set_player_roll_point(Player* p, uint32_t battle_id, uint32_t roll_id, int32_t roll_flag, int32_t& roll_point)
{
	Battle* btl = p->btl;
	if(btl->id() != battle_id){
		return false;
	}

	battle_roll_data *pdata = btl->get_battle_roll_data_by_roll_id(roll_id);
	if(pdata == NULL){
		return false;
	}
	
	bool ret = pdata->player_roll_point(roll_id, p->id, roll_point, roll_flag);
	if(ret == false){
		return false;
	}
	ret = pdata->is_roll_finish(roll_id);
	return pdata->check_delete();
}
示例#25
0
int main(int argc, char *argv[]){
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    QQmlContext *ctx = engine.rootContext();
    DataCreate dataMake;
    GameData data;
    Battle battle;
    //Loading game data
    data.loadMonster();
    data.loadSkill();
    data.loadTrainer();
    battle.setPlayer(data.player());
    battle.nextEnemy(100);
    battle.nextFront();
    ctx->setContextProperty("_battle",&battle);
    ctx->setContextProperty("_make",&dataMake);
    ctx->setContextProperty("_data",&data);
    QGuiApplication::setApplicationName("Battle Monster");
    QGuiApplication::setApplicationVersion("1.0");
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}
示例#26
0
Battle* battle_factory::create_battle(Player* creater, uint32_t battle_mode, uint32_t stage_id, uint32_t player_count)
{
	Battle* btl = NULL;
	switch(battle_mode)
	{
		case single_pvp_mode:
		{
			btl = new single_pvp_battle(creater, battle_mode, stage_id,  player_count);
			btl->init_battle();
		}
		break;

		case team_pvp_mode:
		{
			btl = new team_pvp_battle(creater, battle_mode, stage_id, player_count);
			btl->init_battle();
		}
		break;

		case single_pve_mode:
		{
			btl = new single_pve_battle(creater, battle_mode, stage_id, player_count);
			btl->init_battle();
		}
		break;

		case team_pve_mode:
		{
			btl = new team_pve_battle(creater, battle_mode, stage_id, player_count);
			btl->init_battle();
		}
		break;

		default :
			return btl;
	}
	return btl;
}
示例#27
0
void Random::attackPhase(Player* player)
{
	cout << "Performing battle phase for " << player->getName() << "." << endl;
	//iterate through all countries
	vector<Country*> countries = player->getCountries();
	for (size_t i = 0; i < countries.size(); i++)
	{
		if (countries[i]->getArmies() > 1)
		{
			for (size_t j = 0; j < countries[i]->getBorderCount(); j++)
			{
				if (countries[i]->borderCountries[j]->owner->getName() != player->getName())
				{
					if (rand() % 1)
					{
						Battle battle;
						battle.fight(countries[i], countries[i]->borderCountries[j]);
					}
				}
			}
		}
	}
}
示例#28
0
void     battle_mgr::on_battle_mgr_time( struct timeval cur_time )
{
	std::list<Battle*>::iterator pItr = btl_list.begin();
	
	while(pItr != btl_list.end())
	{
		Battle* btl = *pItr;	
		if(btl->check_btl_state(battle_destroy_state))
		{
			pItr = btl_list.erase(pItr);
			battle_factory::get_instance()->destroy_battle(btl);
			continue;
		}
		if(btl->check_btl_state(battle_running_state) || btl->check_btl_state(battle_end_state))
		{
			btl->on_battle_timer( cur_time );
			++pItr;
			continue;
		}
		++pItr;
	}

}
示例#29
0
bool Spring::Run( Battle& battle )
{

  wxString path = sett().GetCurrentUsedDataDir() + wxFileName::GetPathSeparator() + _T("script.txt");

  try
  {

    if ( !wxFile::Access( path , wxFile::write ) )
    {
      wxLogError( _T("Access denied to script.txt.") );
    }

    wxFile f( path, wxFile::write );
    battle.DisableHostStatusInProxyMode( true );
    f.Write( WriteScriptTxt(battle) );
    battle.DisableHostStatusInProxyMode( false );
    f.Close();

  }
    catch ( std::exception& e )
    {
        wxLogError( wxString::Format( _T("Couldn't write script.txt, exception caught:\n %s"), TowxString( e.what() ).c_str() ) );
        return false;
    }

  catch (...)
  {
    wxLogError( _T("Couldn't write script.txt") );
    return false;
  }

  #if 0 //TODO: BD, isn't this SUPER obsolete
  wxString CommandForAutomaticTeamSpeak = _T("SCRIPT|") + battle.GetFounder().GetNick() + _T("|");
  for ( UserList::user_map_t::size_type i = 0; i < battle.GetNumUsers(); i++ )
  {
    CommandForAutomaticTeamSpeak << TowxString<unsigned int>( battle.GetUser(i).BattleStatus().ally) << _T("|") << battle.GetUser(i).GetNick() << _T("|");
  }
//  torrent().SendMessageToCoordinator(CommandForAutomaticTeamSpeak); //this is gone too now, right?
  #endif

	wxString cmd;
	if ( battle.GetAutoHost().GetEnabled() )
	{
    // -m, --minimise          Start minimised
    // -q [T], --quit=[T]      Quit immediately on game over or after T seconds
	cmd = _T("--minimise");
	}
	cmd += _T(" \"") + path +  _T("\"");

	return LaunchSpring( cmd );
}
示例#30
0
void BattleInfo::setHeaderText(Battle const & battle)
{
    std::ostringstream oss;
    oss << battle.title() << " / " << battle.founder() << " / " << battle.engineVersion() <<"\n"
        << battle.mapName() << "\n"
        << battle.modName() << "\n"
        << "Users:";

    for (Battle::BattleUsers::value_type pair : battle.users())
    {
        assert(pair.second);
        User const & u = *pair.second;
        oss << "  " << u.name();
    }

    headerText_->value(oss.str().c_str());
}