void FacadeDocumentProviderImpl::GetDocument(const std::wstring& id, long flags, WSDocNonCom& wsDoc)
{	     
	Artifact document = GetArtifactByWorkshareId(id);

	if(!(flags & DF_INFO_ONLY))
	{
		document.Download();
		wsDoc.SetLocalFile(document.WorkingFileName);
	}

	if(flags & DF_LOCK)
	{
		// TODO: Artifact.Lock() should return a value wether lock was successful,
		// it might have already been locked by other user.
		document.Lock();
		wsDoc.SetFlags(DOCUMENT_LOCKED_BY_US);
	}
	else
	{
		// If not require locking, set this flag accordingly
		wsDoc.SetFlags(DOCUMENT_NOT_LOCKED);
	}

	PopulateWSDocMembersFromArtifact(document, wsDoc);
}
void FacadeDocumentProviderImpl::SaveDocument(WSDocNonCom& wsDoc, long /*flags*/)
{
	USES_CONVERSION;   
	Artifact artifact = GetArtifactByWorkshareId(wsDoc.GetDocId());

	artifact.Upload(wsDoc.GetLocalFile().c_str());
	PopulateWSDocMembersFromArtifact(artifact, wsDoc);
}
void FacadeDocumentProviderImpl::LockDocument(const std::wstring& id, long flags)
{   
	Artifact artifact = GetArtifactByWorkshareId(id);
	if(flags & LOCK_DOCUMENT)
		artifact.Lock();
	else if(flags & UNLOCK_DOCUMENT)
		artifact.Unlock();
}
Пример #4
0
void TestComArtifacts::TestGetAt()
{
	extern bool g_bCalledArtifacts_GetItem;
	_ArtifactsPtr spArtifacts = CreateMockArtifacts(_T("mock://123/123"));  
	ComArtifacts artifacts(spArtifacts);
	Artifact bridge = artifacts.GetAt(0);
	assertTypeOf(bridge.GetImplementor(), const ComArtifact*);   
	assertMessage(g_bCalledArtifacts_GetItem, _T("Expected ComArtifacts::GetAt to call _Artifacts::get_Item"));
}
void FacadeDocumentProviderImpl::RelateDocument(WSDocNonCom& newDocument,  const std::wstring& sExistingDocumentID)
{
	Artifact artifact = GetArtifactByWorkshareId(sExistingDocumentID);	
	Artifact related = artifact.CreateRelatedItem(newDocument.GetLocalFile(), CStdStringW(newDocument.GetExtension()), L"", false );
	PopulateWSDocMembersFromArtifact(related, newDocument);

	newDocument.SetFlags(DOCUMENT_LOCKED_BY_US);
	related.Lock();
}
Пример #6
0
void GameOver::DialogWins(u16 cond)
{
    const Settings & conf = Settings::Get();
    std::string body;

    switch(cond)
    {
	case WINS_ALL:
	    break;

	case WINS_TOWN:
	{
	    body = _("You captured %{name}!\nYou are victorious.");
	    const Castle* town = world.GetCastle(conf.WinsMapsIndexObject());
	    if(town) String::Replace(body, "%{name}", town->GetName());
	}
	break;

	case WINS_HERO:
	{
	    body = _("You have captured the enemy hero %{name}!\nYour quest is complete.");
	    const Heroes* hero = world.GetHeroesCondWins();
	    if(hero) String::Replace(body, "%{name}", hero->GetName());
	    break;
	}

	case WINS_ARTIFACT:
	{
	    body = _("You have found the %{name}.\nYour quest is complete.");
	    if(conf.WinsFindUltimateArtifact())
		String::Replace(body, "%{name}", "Ultimate Artifact");
	    else
	    {
		const Artifact art = conf.WinsFindArtifactID();
		String::Replace(body, "%{name}", art.GetName());
	    }
	    break;
        }

        case WINS_SIDE:
    	    body = _("The enemy is beaten.\nYour side has triumphed!");
    	    break;

        case WINS_GOLD:
        {
    	    body = _("You have built up over %{count} gold in your treasury.\nAll enemies bow before your wealth and power.");
	    String::Replace(body, "%{count}", conf.WinsAccumulateGold());
    	    break;
	}

    	default: break;
    }

    AGG::PlayMusic(MUS::VICTORY, false);

    if(body.size()) Dialog::Message("", body, Font::BIG, Dialog::OK);
}
Пример #7
0
void TestComArtifact::TestCreateRelatedItem()
{
    extern bool g_bCalledArtifact_CreateRelatedItem;

    _ArtifactPtr spArtifact = CreateMockArtifact(L"mock://123/123");
    ComArtifact artifact(spArtifact);
    Artifact bridge = artifact.CreateRelatedItem(L"", L"", L"", false);

    assertTypeOf(bridge.GetImplementor(), const ComArtifact*);
    assertMessage(g_bCalledArtifact_CreateRelatedItem, _T("Expected MockArtifact::CreateRelatedArtifact to be called from ComArtifact::CreateRelatedArtifact"));
}
Пример #8
0
void TestDominoDocArtifact::TestCreateNewVersion()
{
	DomDocHelper testDominoDocument(TEST_ARTIFACT_FILE);
	DominoDocArtifact artifact(m_spLibrary, testDominoDocument.DocumentId, testDominoDocument.GetVersionLabel());
	long originalVersionCount = artifact.GetVersions().Count;
	std::wstring originalVersion = artifact.VersionLabel;

	Artifact newVersion = artifact.CreateNewVersion(L"This version was created by TestDominoDocArtifact::TestCreateNewVersion().", L"formats");
	assertMessage(!newVersion.IsNull(), _T("Expect a non-null artifact representing the new version."));
	assertMessage((originalVersionCount + 1) == artifact.GetVersions().Count, _T("Creating a new version should increase the version count by one."));
	assertMessage(0 != newVersion.VersionLabel.compare(originalVersion), _T("The new artifact has the same version label as the original artifact."));
}
Пример #9
0
void Transformer::setupInputs(QScriptValue targetScriptValue, const ArtifactSet &inputs,
        const QString &defaultModuleName)
{
    const auto scriptEngine = static_cast<ScriptEngine *>(targetScriptValue.engine());
    QScriptValue scriptValue = translateInOutputs(scriptEngine, inputs, defaultModuleName);
    targetScriptValue.setProperty(StringConstants::inputsVar(), scriptValue);
    QScriptValue inputScriptValue;
    if (inputs.size() == 1) {
        Artifact *input = *inputs.cbegin();
        const FileTags &fileTags = input->fileTags();
        QBS_ASSERT(!fileTags.empty(), return);
        QScriptValue inputsForFileTag = scriptValue.property(fileTags.cbegin()->toString());
        inputScriptValue = inputsForFileTag.property(0);
    }
std::wstring FacadeDocumentProviderImpl::TranslateOdmaID(const std::wstring& id)
{
	std::wstring repositoryId, artifactId, artifactVersionLabel;
	bool supports = GetConnector().GetInfoFromOdmaId(id, repositoryId, artifactId, artifactVersionLabel);     
	if(supports)
	{
		// TODO: We do the following to ensure that we always have a fully qualified workshare id.
		// Some connectors may not include the version label for the most current document in the ODMA id
		Artifact artifact = GetConnector().GetRepositoryById(repositoryId).GetArtifactById(artifactId, artifactVersionLabel);
		return EncodeWorkshareId(artifact.Id, artifact.VersionLabel, artifact.GetRepository().Id);
	}
	else
		return L"";

}
void FacadeDocumentProviderImpl::GetRelatedDocuments(const std::wstring& id, std::vector<WSDocNonCom>& vRelatedDocs)
{
	vRelatedDocs.clear();   
	Artifact artifact = GetArtifactByWorkshareId(id);
	Artifacts& artifacts = artifact.GetRelatedArtifacts();

	for(long index = 0; index < artifacts.Count; index++)
	{
		Artifact artifact = artifacts[index];
		WSDocNonCom document;

		PopulateWSDocMembersFromArtifact(artifact, document);

		vRelatedDocs.push_back(document);
	}
}
Пример #12
0
void BagArtifacts::RemoveScroll(const Artifact & art)
{
    Spell spell(art.GetSpell());
    if(spell.isValid())
    {
	iterator it = std::find(begin(), end(), spell);
	if(it != end()) (*it).Reset();
    }
}
bool FacadeDocumentProviderImpl::SelectDocumentEx(LONG_PTR lHwnd, const std::wstring& formatString, const std::wstring& /*previousSelectedDocumentId*/, std::wstring& documentId)
{
	// TODO: We need a SelectArtifactVersion if previousSelectedDocumentId has something.
	LOG_WS_FUNCTION_SCOPE();

	Connector& connector = GetConnector();
	LOG_WS_INFO(L"Retrieved connector" );
	
	Artifact document = connector.SelectArtifact((HWND)lHwnd, formatString);
	if(document.IsNull())
	{
		LOG_WS_INFO(L"document == NULL" );
		return false;
	}

	documentId = EncodeWorkshareId(document.Id, document.VersionLabel, document.GetRepository().Id);	
	return true;
}
void FacadeDocumentProviderImpl::PopulateWSDocMembersFromArtifact(Artifact artifact, WSDocNonCom& wsdoc)
{   
	std::tostringstream msg;
	msg << _T("The following artifact will be returned to Workshare:") << std::endl;
	msg << _T("Name:") << artifact.Name << std::endl;
	std::wstring id = EncodeWorkshareId(artifact.Id, artifact.VersionLabel, artifact.GetRepository().Id);
	msg << _T("Artifact Id:") << artifact.Id << std::endl;
	msg << _T("Artifact Version Label:") << artifact.VersionLabel << std::endl;
	msg << _T("Repository Id:") << artifact.GetRepository().Id << std::endl;
	msg << _T("Workshare Id:") << id << std::endl;
	msg << _T("Extension:") << artifact.FileExtension << std::endl;

	wsdoc.SetDescription(artifact.Name);
	wsdoc.SetDocId(id);
	wsdoc.SetExtension(artifact.FileExtension.c_str());
	CStdString sWorkingFile;
	try
	{
		sWorkingFile = artifact.WorkingFileName;
	}
	catch(...)
	{
		//dont worry if there is no working file just continue
	}
	if(sWorkingFile.IsEmpty())
	{
		wsdoc.SetModifiedTime(0);
		wsdoc.SetFileSizeLow(0);
		wsdoc.SetFileSizeHigh(0);
		msg << _T("Working File Name: <none>") << std::endl;
	}
	else
	{
		wsdoc.SetLocalFile(artifact.WorkingFileName);
		wsdoc.SetModifiedTime((DATE)artifact.ModifiedTime);
		wsdoc.SetFileSizeLow(artifact.FileSize);
		wsdoc.SetFileSizeHigh(0);
		msg << _T("Working File Name: ") << artifact.WorkingFileName << std::endl;
		msg << _T("File Size: ") << artifact.FileSize << std::endl;
		msg << _T("Modified Time: ") << artifact.ModifiedTime << std::endl;
	}
	msg << std::ends;
	LOG_WS_INFO(msg.str().c_str());
}
void FacadeDocumentProviderImpl::CloseDocument(WSDocNonCom& wsDoc, long flags)
{   
	Artifact artifact = GetArtifactByWorkshareId(wsDoc.GetDocId());

	// only unlock if the document was locked by current user.
	if( wsDoc.GetFlags() == DOCUMENT_LOCKED_BY_CURRENT_USER )
	{
		artifact.Unlock();
	}

	if(!(flags & DF_UNLOCK_ONLY))
	{
		artifact.Close();
		LONG oldFlags = wsDoc.GetFlags();
		wsDoc.SetFlags(oldFlags & ~DOCUMENT_LOCKED_BY_US);
	}

	PopulateWSDocMembersFromArtifact(artifact, wsDoc);
}
Пример #16
0
void UltimateArtifact::Set(s32 pos, const Artifact & a)
{
    Artifact & art = *this;
    art = a.isValid() ? a : Artifact::Rand(Artifact::ART_ULTIMATE);
    index = pos;
    isfound = false;

    if(Maps::isValidAbsIndex(index))
	Interface::GameArea::GenerateUltimateArtifactAreaSurface(index, puzzlemap);
    else
	Surface::FreeSurface(puzzlemap);
}
Пример #17
0
bool HeroBase::CanTranscribeScroll(const Artifact & art) const
{
    Spell spell = art.GetSpell();

    if(spell.isValid() && CanCastSpell(spell))
    {
	int learning = GetLevelSkill(Skill::Secondary::LEARNING);

	return ((3 <  spell.Level() && Skill::Level::EXPERT == learning) ||
	    (3 == spell.Level() && Skill::Level::ADVANCED <= learning) ||
	    (3 > spell.Level() && Skill::Level::BASIC <= learning));
    }

    return false;
}
Пример #18
0
u32 HeroBase::HasArtifact(const Artifact & art) const
{
    bool unique = true;

    switch(art.Type())
    {
	case 1:	unique = Settings::Get().ExtWorldUseUniqueArtifactsML(); break; /* morale/luck arts. */
	case 2:	unique = Settings::Get().ExtWorldUseUniqueArtifactsRS(); break; /* resource affecting arts. */
	case 3:	unique = Settings::Get().ExtWorldUseUniqueArtifactsPS(); break; /* primary/mp/sp arts. */
	case 4:	unique = Settings::Get().ExtWorldUseUniqueArtifactsSS(); break; /* sec. skills arts. */
	default: break;
    }

    return ! unique ? bag_artifacts.Count(art) :
        (bag_artifacts.isPresentArtifact(art) ? 1 : 0);
}
Пример #19
0
void HeroBase::TranscribeScroll(const Artifact & art)
{
    Spell spell = art.GetSpell();

    if(spell.isValid())
    {
	// add spell
	spell_book.Append(spell);

	// remove art
	bag_artifacts.RemoveScroll(art);

	// reduce mp and resource
	SpellCasted(spell);
    }
}
HRESULT FacadeDocumentProviderImpl::GetSaveInfo(HWND hWnd, const std::wstring& formatString, long lFlags, long& lFormatIndex, WSDocNonCom& wsDoc)
{
	//-- ArtifactImpl
	//TODO: Replace Existing Version
	//TODO: Create a relation

	//-- Connector
	// Create new artifact (Add Files)
	UNREFERENCED_PARAMETER(lFormatIndex);
	if(DF_NEW_DOCUMENT & lFlags)
	{
		std::wstring newFileName = wsDoc.GetDescription();
		Artifact artifact = GetConnector().CreateArtifact(hWnd, formatString, newFileName);
		if (artifact.IsNull())
			return E_DOCUMENT_NOT_FOUND;
		PopulateWSDocMembersFromArtifact(artifact, wsDoc);
		wsDoc.SetFlags(DOCUMENT_LOCKED_BY_US);
		lFormatIndex = CalculateFormatIndex(formatString, artifact.GetFileExtension());
		artifact.Lock();
	}
	// Create a relation
	else if(DF_ATTACH & lFlags)
	{
		Artifact existing = GetArtifactByWorkshareId(wsDoc.GetDocId());	

		if (existing.IsNull())
			return E_DOCUMENT_NOT_FOUND;

		CStdString sDummyFile = CTempFileManager::GetTempFileName();;
		CStdString sExt; 
		DocUtilities::GetExtensionFromFileName(sDummyFile,sExt);

		Artifact related = existing.CreateRelatedItem(CStdStringW(sDummyFile),GetDefaultSaveExtensionFromFormatString(formatString, lFormatIndex), formatString, true);

		if (related.IsNull())
			return E_DOCUMENT_NOT_FOUND;

		related.Lock();

		PopulateWSDocMembersFromArtifact(related, wsDoc);
		lFormatIndex = CalculateFormatIndex(formatString, related.GetFileExtension());

		wsDoc.SetFlags(DOCUMENT_LOCKED_BY_US);
	}
	// Create a new version
	else if(DF_VERSION & lFlags)
	{
		std::wstring repositoryId;
		std::wstring artifactId;
		std::wstring versionLabel;
		DecodeWorkshareId(wsDoc.GetDocId().c_str(), artifactId, versionLabel, repositoryId);
		Repository repository = GetConnector().GetRepositoryById(repositoryId.c_str());
		Artifact artifact = repository.GetArtifactById(artifactId.c_str(), versionLabel.c_str());
		Artifact artifactVersion = artifact.CreateNewVersion(L"", formatString);
		PopulateWSDocMembersFromArtifact(artifactVersion, wsDoc);
		artifactVersion.Lock(); 
		wsDoc.SetFlags(DOCUMENT_LOCKED_BY_US);
		lFormatIndex = CalculateFormatIndex(formatString, artifactVersion.GetFileExtension());

	}
	return S_OK;
}
Пример #21
0
void GameOver::DialogLoss(u16 cond)
{
    const Settings & conf = Settings::Get();
    std::string body;

    switch(cond)
    {
	case WINS_ARTIFACT:
	{
	    body = _("The enemy has found the %{name}.\nYour quest is a failure.");
	    const Artifact art = conf.WinsFindArtifactID();
	    String::Replace(body, "%{name}", art.GetName());
	    break;
        }

        case WINS_SIDE:
        {
    	    body = _("%{color} has fallen!\nAll is lost.");
	    String::Replace(body, "%{color}", Color::String(conf.CurrentColor()));
    	    break;
    	}

        case WINS_GOLD:
        {
    	    body = _("The enemy has built up over %{count} gold in his treasury.\nYou must bow done in defeat before his wealth and power.");
	    String::Replace(body, "%{count}", conf.WinsAccumulateGold());
    	    break;
	}

	case LOSS_ALL:
	    body = _("You have been eliminated from the game!!!");
	    break;

	case LOSS_TOWN:
	{
	    body = _("The enemy has captured %{name}!\nThey are triumphant.");
	    const Castle* town = world.GetCastle(conf.WinsMapsIndexObject());
	    if(town) String::Replace(body, "%{name}", town->GetName());
	}

	case LOSS_STARTHERO:
	{
	    const Heroes* hero = world.GetKingdom(conf.CurrentColor()).GetFirstHeroStartCondLoss();
	    body = _("You have lost the hero %{name}.\nYour quest is over.");
	    if(hero) String::Replace(body, "%{name}", hero->GetName());
	    break;
	}

	case LOSS_HERO:
	{
	    body = _("You have lost the hero %{name}.\nYour quest is over.");
	    const Heroes* hero = world.GetHeroesCondLoss();
	    if(hero) String::Replace(body, "%{name}", hero->GetName());
	    break;
	}

	case LOSS_TIME:
	    body = _("You have failed to complete your quest in time.\nAll is lost.");
	    break;

    	default: break;
    }

    AGG::PlayMusic(MUS::LOSTGAME, false);

    if(body.size()) Dialog::Message("", body, Font::BIG, Dialog::OK);
}
Пример #22
0
std::string GameOver::GetActualDescription(u16 cond)
{
    const Settings & conf = Settings::Get();
    std::string msg;

    if(WINS_ALL == cond || WINS_SIDE == cond)
	msg = GetString(WINS_ALL);
    else
    if(WINS_TOWN & cond)
    {
	const Castle* town = world.GetCastle(conf.WinsMapsIndexObject());
	if(town)
	{
    	    msg = town->isCastle() ? _("Capture the castle '%{name}'") : _("Capture the town '%{name}'");;
	    String::Replace(msg, "%{name}", town->GetName());
	}
    }
    else
    if(WINS_HERO & cond)
    {
	const Heroes* hero = world.GetHeroesCondWins();
	if(hero)
	{
	    msg = _("Defeat the hero '%{name}'");
	    String::Replace(msg, "%{name}", hero->GetName());
	}
    }
    else
    if(WINS_ARTIFACT & cond)
    {
	if(conf.WinsFindUltimateArtifact())
	    msg = _("Find the ultimate artifact");
	else
	{
	    const Artifact art = conf.WinsFindArtifactID();
	    msg = _("Find the '%{name}' artifact");
	    String::Replace(msg, "%{name}", art.GetName());
	}
    }
    else
    if(WINS_GOLD & cond)
    {
	msg = _("Accumulate %{count} gold");
	String::Replace(msg, "%{count}", conf.WinsAccumulateGold());
    }

    if(WINS_ALL != cond && (WINS_ALL & cond)) msg.append(_(", or you may win by defeating all enemy heroes and capturing all enemy towns and castles."));

    if(LOSS_ALL == cond)
	msg = GetString(WINS_ALL);
    else
    if(LOSS_TOWN & cond)
    {
	const Castle* town = world.GetCastle(conf.LossMapsIndexObject());
	if(town)
	{
    	    msg = town->isCastle() ? _("Lose the castle '%{name}'.") : _("Lose the town '%{name}'.");
	    String::Replace(msg, "%{name}", town->GetName());
	}
    }
    else
    if(LOSS_HERO & cond)
    {
    	const Heroes* hero = world.GetHeroesCondLoss();
	if(hero)
	{
	    msg = _("Lose the hero: %{name}.");
	    String::Replace(msg, "%{name}", hero->GetName());
	}
    }
    else
    if(LOSS_TIME & cond)
    {
	msg = _("Fail to win by the end of month %{month}, week %{week}, day %{day}.");
        String::Replace(msg, "%{day}", (conf.LossCountDays() % DAYOFWEEK));
        String::Replace(msg, "%{week}", (conf.LossCountDays() / DAYOFWEEK) + 1);
        String::Replace(msg, "%{month}", (conf.LossCountDays() / (DAYOFWEEK * WEEKOFMONTH)) + 1);
    }

    if(conf.ExtWorldStartHeroLossCond4Humans())
    {
	const std::string names = world.GetKingdom(conf.CurrentColor()).GetNamesHeroStartCondLoss();
        std::string str = std::string::npos == names.find(',') ? _("Lose the hero: %{name}.") : _("Lose the heroes: %{name}.");
        String::Replace(str, "%{name}", names);
	msg.append("\n");
	msg.append(str);
    }

    return msg;
}
Пример #23
0
void DominoDocManager::SetDocumentToDelete(Artifact artifact)
{
   m_documentId = artifact.Id;
   m_versionLabel = artifact.VersionLabel;
   m_libraryUrl = artifact.GetRepository().Id;
}
Пример #24
0
// -----------------------------------------------------------------
// Name : autoStartGame
// -----------------------------------------------------------------
void DebugManager::autoStartGame()
{
    // Build client data
    int nbClients = 1;
    ClientData * clients = new ClientData[nbClients];
    int iClient = 0;
    clients[iClient].bLocal = true;

    // Re-init map data
    MapReader * pMapReader = new MapReader(m_pLocalClient);
    pMapReader->init("standard.lua");
    ObjectList * pMapParameters = new ObjectList(true);
    pMapReader->getMapParameters(pMapParameters, LABEL_MAX_CHARS);

    int * pCustomParams = NULL;
    if (pMapParameters->size > 0)
        pCustomParams = new int[pMapParameters->size];

    // Map custom parameters
    int i = 0;
    MapReader::MapParameters * pParam = (MapReader::MapParameters*) pMapParameters->getFirst(0);
    while (pParam != NULL)
    {
        pCustomParams[i++] = pParam->defaultValueIndex;
        pParam = (MapReader::MapParameters*) pMapParameters->getNext(0);
    }

    // Init map generator (we will not delete it here, as the pointer now belong to Server object)
    pMapReader->setMapParameters(pCustomParams, pMapParameters->size, 2);
    delete[] pCustomParams;
    MapReader::deleteMapParameters(pMapParameters);
    delete pMapParameters;

    // Init server
    Server * pServer = m_pLocalClient->initServer("", 1, clients, pMapReader, -1, -1);
    delete[] clients;
    if (pServer == NULL)
    {
        notifyErrorMessage("Error: server could not be initialized.");
        return;
    }

    // Build players data
    ObjectList * pServerPlayers = pServer->getSolver()->getPlayersList();
    // Create neutral player
    char sName[NAME_MAX_CHARS];
    i18n->getText("NEUTRA", sName, NAME_MAX_CHARS);
    Player * pPlayer = new Player(0, 0, pServer->getSolver()->getGlobalSpellsPtr());
    wsafecpy(pPlayer->m_sProfileName, NAME_MAX_CHARS, sName);
    pPlayer->m_Color = rgb(0.5, 0.5, 0.5);
    wsafecpy(pPlayer->m_sBanner, 64, "blason1");
    pServer->getSolver()->setNeutralPlayer(pPlayer);
    // Human players
    int playerId = 1;
    for (int fdfdf = 0; fdfdf < 2; fdfdf++)
    {
        // Create player object
        pPlayer = new Player(playerId, 0, pServer->getSolver()->getGlobalSpellsPtr());
        snprintf(pPlayer->m_sProfileName, NAME_MAX_CHARS, "test%d", playerId);
        Profile * pProfile = m_pLocalClient->getDataFactory()->findProfile(pPlayer->m_sProfileName);
        AvatarData * pAvatar = (AvatarData*) pProfile->getAvatarsList()->getFirst(0);
        pPlayer->m_Color = rgb(1, 1, 1);
        pAvatar->getBanner(pPlayer->m_sBanner, 64);
        pServerPlayers->addLast(pPlayer);
        // Set Avatar
        CoordsMap pos = pMapReader->getPlayerPosition(playerId-1);
        pServer->getSolver()->setInitialAvatar(pAvatar->clone(m_pLocalClient), pPlayer, pos);
        // Add spells that are equipped
        Profile::SpellData * pSpellDesc = (Profile::SpellData*) pProfile->getSpellsList()->getFirst(0);
        while (pSpellDesc != NULL)
        {
            AvatarData * pOwner = pSpellDesc->m_pOwner;
            if (pOwner != NULL && strcmp(pAvatar->m_sEdition, pOwner->m_sEdition) == 0
                    && strcmp(pAvatar->m_sObjectId, pOwner->m_sObjectId) == 0)
                pServer->getSolver()->addInitialPlayerSpell(pPlayer, pSpellDesc->m_sEdition, pSpellDesc->m_sName);
            pSpellDesc = (Profile::SpellData*) pProfile->getSpellsList()->getNext(0);
        }
        // Add equipped artifacts
        Artifact * pArtifact = (Artifact*) pProfile->getArtifactsList()->getFirst(0);
        while (pArtifact != NULL)
        {
            AvatarData * pOwner = pArtifact->m_pOwner;
            if (pOwner != NULL && strcmp(pAvatar->m_sEdition, pOwner->m_sEdition) == 0
                    && strcmp(pAvatar->m_sObjectId, pOwner->m_sObjectId) == 0)
            {
                Unit * pAvatarInGame = pPlayer->getAvatar();
                assert(pAvatarInGame != NULL);
                ArtifactEffect * pEffect = (ArtifactEffect*) pArtifact->getArtifactEffects()->getFirst(0);
                while (pEffect != NULL)
                {
                    switch (pEffect->getType())
                    {
                    case ARTIFACT_EFFECT_CHARAC:
                    {
                        bool bFound = true;
                        long val = pAvatarInGame->getValue(((ArtifactEffect_Charac*)pEffect)->m_sKey, false, &bFound);
                        if (bFound)
                            pAvatarInGame->setBaseValue(((ArtifactEffect_Charac*)pEffect)->m_sKey, max(0, val + ((ArtifactEffect_Charac*)pEffect)->m_iModifier));
                        else
                        {
                            char sError[1024];
                            snprintf(sError, 1024, "Warning: artifact %s tries to modify characteristic that doesn't exist (%s)", pArtifact->m_sObjectId, ((ArtifactEffect_Charac*)pEffect)->m_sKey);
                            m_pLocalClient->getDebug()->notifyErrorMessage(sError);
                        }
                        break;
                    }
                    case ARTIFACT_EFFECT_SPELL:
                    {
                        Spell * pSpell = m_pLocalClient->getDataFactory()->findSpell(((ArtifactEffect_Spell*)pEffect)->m_sSpellEdition, ((ArtifactEffect_Spell*)pEffect)->m_sSpellName);
                        if (pSpell != NULL)
                            pServer->getSolver()->addInitialPlayerSpell(pPlayer, ((ArtifactEffect_Spell*)pEffect)->m_sSpellEdition, ((ArtifactEffect_Spell*)pEffect)->m_sSpellName);
                        else
                        {
                            char sError[1024];
                            snprintf(sError, 1024, "Warning: artifact %s tries to add spell that doesn't exist (%s)", pArtifact->m_sObjectId, ((ArtifactEffect_Spell*)pEffect)->m_sSpellName);
                            m_pLocalClient->getDebug()->notifyErrorMessage(sError);
                        }
                        break;
                    }
                    case ARTIFACT_EFFECT_SKILL:
                    {
                        Skill * pSkill = new Skill(((ArtifactEffect_Skill*)pEffect)->m_sSkillEdition, ((ArtifactEffect_Skill*)pEffect)->m_sSkillName, ((ArtifactEffect_Skill*)pEffect)->m_sSkillParameters, pServer->getDebug());
                        if (pSkill != NULL && pSkill->isLoaded())
                            pAvatarInGame->addSkill(pSkill);
                        else
                        {
                            char sError[1024];
                            snprintf(sError, 1024, "Warning: artifact %s tries to add skill that doesn't exist or that can't be loaded (%s)", pArtifact->m_sObjectId, ((ArtifactEffect_Skill*)pEffect)->m_sSkillName);
                            m_pLocalClient->getDebug()->notifyErrorMessage(sError);
                        }
                        break;
                    }
                    }
                    pEffect = (ArtifactEffect*) pArtifact->getArtifactEffects()->getNext(0);
                }
            }
            pArtifact = (Artifact*) pProfile->getArtifactsList()->getNext(0);
        }
        playerId++;
    }
    delete pMapReader;
    pServer->onInitFinished();
}