Beispiel #1
0
void GroupManager::_processIsmGroupLootMasterResponse(Message* message)
{
	gLogger->logMsg("_processIsmGroupLootMasterResponse");
	PlayerObject* playerObject = gWorldManager->getPlayerByAccId(message->getUint32());  // the player whos group_id has changed
	if(playerObject == NULL)
	{
		gLogger->logMsg("GroupManager::_processIsmGroupLootMasterResponse PlayerAccId not found");
		return;
	}

	//send the SUI
	gLogger->logMsg("ok\n");

	PlayerList inRangeMembers	= playerObject->getInRangeGroupMembers(true);
	PlayerList::iterator it		= inRangeMembers.begin();

	BStringVector namesArray;

	while(it != inRangeMembers.end())
	{
		namesArray.push_back((*it)->getFirstName().getAnsi());
		++it;
	}

	gUIManager->createNewPlayerSelectListBox(playerObject,"handleSetLootMaster","@group:master_looter_sui_title","@group:set_loot_type_text",namesArray,inRangeMembers,playerObject);
}
Beispiel #2
0
void TicketCollector::_createTicketSelectMenu(PlayerObject* playerObject)
{
    BStringVector	availableTickets;
    uint32			zoneId = gWorldManager->getZoneId();

    ObjectIDList*			invObjects	= dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getObjects();
    ObjectIDList::iterator	it			= invObjects->begin();

    while(it != invObjects->end())
    {
        if(TravelTicket* ticket = dynamic_cast<TravelTicket*>(gWorldManager->getObjectById((*it))))
        {
            BString srcPoint		= (int8*)((ticket->getAttribute<std::string>("travel_departure_point")).c_str());
            uint16 srcPlanetId	= static_cast<uint16>(gWorldManager->getPlanetIdByName((int8*)((ticket->getAttribute<std::string>("travel_departure_planet")).c_str())));

            if(srcPlanetId == zoneId && strcmp(srcPoint.getAnsi(),mPortDescriptor.getAnsi()) == 0)
            {
                BString dstPoint = (int8*)((ticket->getAttribute<std::string>("travel_arrival_point")).c_str());

                availableTickets.push_back(dstPoint.getAnsi());
            }
        }
        ++it;
    }

    gUIManager->createNewListBox(this,"handleticketselect","select destination","Select destination",availableTickets,playerObject);
}
Beispiel #3
0
bool	ArtisanManager::setupSampleEvent(PlayerObject* player, CurrentResource* resource, SurveyTool* tool)
{
    //EVENT WINDOW CASE
    int32 eventRoll = int(gRandom->getRand()%2)+1;
    //eventRoll = 2;
    //do event 1 or event 2 based on roll
    if(eventRoll == 1)
    {
        // setup gamble event
        //GAMBLE Event
        WindowAsyncContainerCommand* asyncContainer = new  WindowAsyncContainerCommand(Window_Query_Radioactive_Sample);
        asyncContainer->PlayerId		= player->getId();
        asyncContainer->ToolId			= tool->getId();
        asyncContainer->CurrentResource	= resource;

        BStringVector items;
        items.push_back("Ignore the concentration and continue working.");
        items.push_back("Attempt to recover the resources. (300 Action)");
        gUIManager->createNewListBox(this,"gambleSample","@survey:gnode_t","@survey:gnode_d",items,player,SUI_Window_SmplGamble_ListBox,SUI_LB_OKCANCEL,0,0,asyncContainer);
            
        player->getSampleData()->mPendingSample = false;
        return true;
    }
    else
    {
        WindowAsyncContainerCommand* asyncContainer = new  WindowAsyncContainerCommand(Window_Query_Radioactive_Sample);
        asyncContainer->PlayerId		= player->getId();
        asyncContainer->ToolId			= tool->getId();
        asyncContainer->CurrentResource	= resource;

        //WAYP CONCENTRATION
        BStringVector items;
        items.push_back("Ignore the concentration and continue working.");
        items.push_back("Focus the device on the concentration");
        gUIManager->createNewListBox(this,"waypNodeSample","@survey:cnode_t","@survey:cnode_d",items,player,SUI_Window_SmplWaypNode_ListBox,SUI_LB_OKCANCEL,0,0,asyncContainer);
        
        //Pause sampling
        player->getSampleData()->mPendingSample = false;
        player->getSampleData()->mSampleEventFlag = true;
            
        return true;
    }
    return false;
}
Beispiel #4
0
void GroupManager::_processIsmGroupLootModeResponse(Message* message)
{
	gLogger->logMsg("_processIsmGroupLootModeResponse");
	PlayerObject* playerObject = gWorldManager->getPlayerByAccId(message->getUint32());  // the player whos group_id has changed
	if(playerObject == NULL)
	{
		gLogger->logMsg("GroupManager::processIsmGroupLootModeResponse PlayerAccId not found");
		return;
	}

	//send the SUI

	BStringVector availableLootModes;
	availableLootModes.push_back("Free for all");
	availableLootModes.push_back("Master Looter");
	availableLootModes.push_back("Lottery");
	availableLootModes.push_back("Random");

	gUIManager->createNewListBox(playerObject,"handleSetLootMode","@group:set_loot_type_title","@group:set_loot_type_text",availableLootModes,playerObject,SUI_Window_SelectGroupLootMode_Listbox);
}
Beispiel #5
0
void SurveyTool::_createRangeMenu(PlayerObject* playerObject, bool sample)
{
    int32 surveyMod = playerObject->getSkillModValue(SMod_surveying);

    BStringVector availableRanges;

    availableRanges.push_back("64m x 3pts");

    if(surveyMod >= 35)
        availableRanges.push_back("128m x 4pts");

    if(surveyMod >= 55)
        availableRanges.push_back("192m x 4pts");

    if(surveyMod >= 75)
        availableRanges.push_back("256m x 5pts");

    if(surveyMod >= 100)
        availableRanges.push_back("320m x 5pts");

    if(!sample)
        mSampleAfterSet = false;
    else
        mSampleAfterSet = true;

    gUIManager->createNewListBox(this,"handleSetRange","Survey Device","@survey:select_range",availableRanges,playerObject);
}
bool MessageLib::sendBanList(PlayerStructure* structure, PlayerObject* playerObject)
{
    if(!(playerObject->isConnected()))
        return(false);

    Message* newMessage;

    mMessageFactory->StartMessage();
    mMessageFactory->addUint32(opSendPermissionList);
    mMessageFactory->addUint32(structure->getStrucureBanList().size() );

    BString name;
    BStringVector vector = 	structure->getStrucureBanList();
    BStringVector::iterator it = vector.begin();
    while(it != vector.end())
    {
        name = (*it);
        name.convert(BSTRType_Unicode16);
        mMessageFactory->addString(name);

        it++;
    }

    mMessageFactory->addUint32(0); // ???
    //mMessageFactory->addUint16(0);	// unknown
    name = "BAN";
    name.convert(BSTRType_Unicode16);
    mMessageFactory->addString(name);
    mMessageFactory->addUint32(0); // ???

    newMessage = mMessageFactory->EndMessage();

    (playerObject->getClient())->SendChannelA(newMessage, playerObject->getAccountId(), CR_Client, 5);

    structure->resetStructureAdminList();

    return(true);
}
Beispiel #7
0
void CSRManager::_processSearchKnowledgeBaseMessage(Message *message, DispatchClient* client)
{
    BString search;
    message->getStringUnicode16(search);
    search.convert(BSTRType_ANSI);
    BStringVector splitstring;
    search.split(splitstring, ' ');
    BStringVector::iterator iter = splitstring.begin();

    BString sql = "%";
    while (iter != splitstring.end())
    {
        int8 cleanSearchString[4000];
        mDatabase->Escape_String(cleanSearchString, (*iter).getAnsi(), (*iter).getLength());
        sql << cleanSearchString;
        sql << "%";
        ++iter;
    }

    CSRAsyncContainer* asynccontainer = new CSRAsyncContainer(CSRQuery_SearchKB);
    asynccontainer->mClient = client;
    mDatabase->ExecuteProcedureAsync(this, asynccontainer, "CALL sp_CSRKnowledgeBaseArticleFind ('%s');", sql.getAnsi());
    
}
Beispiel #8
0
bool Trainer::preProcessfilterConversation(ActiveConversation* av,Conversation* conversation,PlayerObject* player)
{
    bool continueConversation = true;
    ConversationPage *page = conversation->getPage(2);	// Page 2 is where WE have the interesting skill-options to check.

    // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: page->mId = %u",page->mId);

    setLastConversationTarget(player->getId());

    std::vector<ConversationOption*>::iterator optionIt = page->mOptions.begin();

    switch(page->mId)
    {
        // Lets see if we have the requriments met by this trainer.
    case 2:
    {
        bool noviceSkill = false;
        bool gotAllSkills = true;	// As long as we have not detected any missing skills.
        uint32 skillsToLearn = 0;
        BStringVector skillsRequired;

        bool gotRequirementsForSomeSkill = false;

        while (optionIt != page->mOptions.end())
        {
            Skill* skill = gSkillManager->getSkillByName((*optionIt)->mStfVariable);
            // requirementsMet = false;

            // its no skill option
            if (!skill)
            {
                // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: Its no skill option");
            }

            // see if we have it already and check xp
            // Note: We do not handle lack of SP as an error now... that's done later in this chain of events.
            else if (player->checkSkill(skill->mId))
            {
                // We already have this skill.
                // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: We already have this skill");
            }
            else if (!skill->mSkillsRequired.size())
            {
                // No skill requirements, we got a "Novice" skill from a basic profession.
                // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: Novice");
                skillsToLearn++;
                gotAllSkills = false;	// Do not have all skills if we end up here.
                noviceSkill = true;
            }
            else
            {
                // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: Do not have all skills if we end up here");
                gotAllSkills = false;	// Do not have all skills if we end up here.

                // see if we got the required skills
                SkillsRequiredList::iterator reqSkillIt = skill->mSkillsRequired.begin();
                bool requirementsMet = true;
                skillsToLearn++;

                int8 str[128];

                while (reqSkillIt != skill->mSkillsRequired.end())
                {
                    if (!player->checkSkill(*reqSkillIt))
                    {
                        // we don't have the requirements
                        // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: We don't have the requirements");
                        requirementsMet = false;

                        // We should only add requirements for Novice skills (and then only for Elite Professions).
                        if (strstr(gSkillManager->getSkillById(skill->mId)->mName.getAnsi(),"novice"))
                        {
                            // add it to our list
                            sprintf(str,"@%s:%s","skl_n", gSkillManager->getSkillById(*reqSkillIt)->mName.getAnsi());
                            // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Skills missing = %u %s", *reqSkillIt, gSkillManager->getSkillById(*reqSkillIt)->mName.getAnsi());
                            skillsRequired.push_back(str);
                        }
                        else
                        {
                            break;
                        }
                    }
                    ++reqSkillIt;
                }

                if (requirementsMet)
                {
                    // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: We DO have the requirements, check if we have the xp for next level");
                    gotRequirementsForSomeSkill = true;

                    // We DO have the requirements, check if we have the xp for next level.
                    if (player->getXpAmount(skill->mXpType) < skill->mXpCost)
                    {
                        // We do not have enough of XP for training this skill.
                        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Missing XP");
                        skillsToLearn--;
                    }
                }
                else
                {
                    skillsToLearn--;
                }
            }
            ++optionIt;
        }

        // Now we must return status of this session.
        if (skillsToLearn == 0)
        {
            // Either we have them all, i.e. we are a Master, or we lack xp for training OR we lack the required skills to train it.
            if (gotAllSkills)
            {
                // We are a Master!
                // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: We are a Master!");
                if (!gWorldConfig->isInstance())
                {
                    gMessageLib->sendCreatureAnimation(av->getNpc(),gWorldManager->getNpcConverseAnimation(16)); // giveup
                }
                else
                {
                    gMessageLib->sendCreatureAnimation(av->getNpc(),gWorldManager->getNpcConverseAnimation(16), player); // giveup
                }

                OutOfBand prose("skill_teacher", "topped_out");

                if (!gWorldConfig->isInstance())
                {
                    gMessageLib->SendSpatialChat(this, prose);
                }
                else
                {
                    gMessageLib->SendSpatialChat(this, prose, player);
                }

                continueConversation = false;
            }
            else if (gotRequirementsForSomeSkill)
            {
                // We lack xp for training.
                // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: We lack xp for training");
            }
            else
            {
                // We do not have requirements for any skill, sounds like we are attempting an elite trainers novice skill.
                // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: sounds like we are attempting an elite trainers novice skill");

                // createNewMessageBox(UICallback* callback,const int8* eventStr,const int8* caption,const int8* text,PlayerObject* playerObject,ui_window_types windowType = SUI_Window_MessageBox,uint8 mbType = SUI_MB_OK);

                // gUIManager->createNewMessageBox(NULL,"no_qualify_title","@skill_teacher:no_qualify_title","@skill_teacher:no_qualify_prompt",player,SUI_Window_MessageBox, SUI_MB_OK);
                // BStringVector skillsRequired;

                // add it to our list
                // int8 str[128];
                // sprintf(str,"@%s:%s","cmd_n",gSkillManager->getSkillCmdById(*dancerIt).getAnsi());
                // sprintf(str,"@skl_n:crafting_artisan_engineering_04");
                // skillsRequired.push_back(str);

                if (!gWorldConfig->isInstance())
                {
                    gMessageLib->sendCreatureAnimation(av->getNpc(),gWorldManager->getNpcConverseAnimation(27)); // poke
                }
                else
                {
                    gMessageLib->sendCreatureAnimation(av->getNpc(),gWorldManager->getNpcConverseAnimation(27), player); // poke
                }

                OutOfBand prose("skill_teacher", "no_qualify");

                if (!gWorldConfig->isInstance())
                {
                    gMessageLib->SendSpatialChat(this, prose);
                }
                else
                {
                    gMessageLib->SendSpatialChat(this, prose, player);
                }



                gUIManager->createNewListBox(NULL,"","@skill_teacher:no_qualify_title","@skill_teacher:no_qualify_prompt",skillsRequired,player);
                continueConversation = false;
            }
        }
        else
        {
            if (noviceSkill) // avaliableSkills should be 1
            {
                if (gWorldConfig->isTutorial())
                {
                    // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: We train to Novice.");
                    // Not implemented yet. Special handling for the Space Station Tutorial Only.
                }
            }
            else
            {
                // Let's select a skill to train. This is the default path.
                // retLinkPage = 0;	// Use caller default linkPage.
                // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: We have some skills to train.");
            }
        }
    }
    break;

    default:
    {
        // gLogger->log(LogManager::DEBUG,"Trainer::preProcessfilterConversation: Default, bad page input");
    }
    break;
    }
    return continueConversation;
}
Beispiel #9
0
// Return pageLink for next conversation.
uint32 Trainer::handleConversationEvent(ActiveConversation* av,ConversationPage* page,ConversationOption* option,PlayerObject* player)
{
    // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: page->mId = %u",page->mId);

    std::vector<ConversationOption*>::iterator optionIt = page->mOptions.begin();
    uint32 pageLink = page->mId;

    switch(page->mId)
    {
        // Select currently learnable skills
    case 2:
    {
        mPlayerGotRequirementsForMasterSkill = false;
        bool noviceSkill = false;
        bool gotAllSkills = true;	// As long as we have not detected any missing skills.
        bool gotRequirementsForSomeSkill = false;
        uint32 skillsToLearn = 0;

        uint32 numberOfSkills = 0;
        uint32 knownSkills = 0;

        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Currently learnable skills (case 2)");
        while (optionIt != page->mOptions.end())
        {
            Skill* skill = gSkillManager->getSkillByName((*optionIt)->mStfVariable);
            numberOfSkills++;

            // its no skill option
            if (!skill)
            {
                numberOfSkills--;
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Its no skill option");
            }

            // see if we have it already and check xp
            // Note: We do not handle lack of SP as an error now... that's done later in this chain of events.
            else if (player->checkSkill(skill->mId))
            {
                // We already have this skill.
                knownSkills++;
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We already have this skill");
            }
            else if (!skill->mSkillsRequired.size())
            {
                // No skill requirements, we got a "Novice" skill from a basic profession.
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Novice");
                skillsToLearn++;
                gotAllSkills = false;	// Do not have all skills if we end up here.
                noviceSkill = true;
            }
            else
            {
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Do not have all skills if we end up here");
                gotAllSkills = false;	// Do not have all skills if we end up here.

                // see if we got the required skills
                SkillsRequiredList::iterator reqSkillIt = skill->mSkillsRequired.begin();
                bool requirementsMet = true;
                skillsToLearn++;

                while (reqSkillIt != skill->mSkillsRequired.end())
                {
                    if (!player->checkSkill(*reqSkillIt))
                    {
                        // we don't have the requirements
                        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We don't have the requirements");
                        requirementsMet = false;
                        break;
                    }
                    ++reqSkillIt;
                }

                if (requirementsMet)
                {
                    // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We DO have the requirements, check if we have the xp for next level");
                    gotRequirementsForSomeSkill = true;

                    // We DO have the requirements, check if we have the xp for next level.
                    if (player->getXpAmount(skill->mXpType) < skill->mXpCost)
                    {
                        // We do not have enough of XP for training this skill.
                        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Missing XP");
                        skillsToLearn--;
                    }
                }
                else
                {
                    skillsToLearn--;
                }
            }
            ++optionIt;
        }

        // Now we must return status of this session.
        if (skillsToLearn == 0)
        {
            // Either we have them all, i.e. we are a Master, or we lack xp for training OR we lack the required skills to train it.
            if (gotAllSkills)
            {
                // We are a Master!
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We are a Master!");
                pageLink = 9;
            }
            else if (gotRequirementsForSomeSkill)
            {
                // We lack xp for training.
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We lack xp for training");
                pageLink = 8;
            }
            else
            {
                // This is not a valid state any more.
                // We do not have requirements for any skill, sounds like we are attempting an elite trainers novice skill.
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: ERROR: Sounds like we are attempting an elite trainers novice skill");
                pageLink = 12;
            }
        }
        else
        {
            if (noviceSkill) // avaliableSkills should be 1
            {
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We train to Novice.");
                // Not implemented yet. Special handling for the Space Station Tutorial Only.
            }
            else
            {

                if ((knownSkills + 1) ==  numberOfSkills)
                {
                    // We have all skills except the last one, we are going for a Master skill...
                    mPlayerGotRequirementsForMasterSkill = true;
                }

                // Let's select a skill to train. This is the default path.
                // retLinkPage = 0;	// Use caller default linkPage.
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Default, we have some skills to train.");
            }
        }
    }
    break;


    // Skill is selected.
    case 3:
    {
        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Skill selected");
        bool failed = true;
        Skill* skill = gSkillManager->getSkillByName(av->getTOStfVariable());

        // its no skill option
        if (!skill)
        {
            // This is a system error.
            DLOG(INFO) << "Trainer::conversationEvent: ERROR: It's no skill option";
        }
        // no skill requirements, Novice Skills have no requirements.
        /*
        else if (!skill->mSkillsRequired.size())
        {
        	// This is a system error.
        	gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: ERROR: No skill requirements");
        	break;
        }
        */
        else if(player->checkSkill(skill->mId))
        {
            // This is a system failure.
            DLOG(INFO) << "Trainer::conversationEvent: ERROR: Player already have the skill";
        }
        else if (player->getXpAmount(skill->mXpType) < skill->mXpCost)
        {
            // This is a system failure.
            DLOG(INFO) << "Trainer::conversationEvent: ERROR: Player need "<<player->getXpAmount(skill->mXpType)<<" XP, but only have "<< skill->mXpCost;
        }
        // see if we got the required skills
        else
        {
            SkillsRequiredList::iterator reqSkillIt = skill->mSkillsRequired.begin();
            failed = false;
            while(reqSkillIt != skill->mSkillsRequired.end())
            {
                // we don't have the requirements
                if (!player->checkSkill(*reqSkillIt))
                {
                    // This is a system failure.
                    failed = true;
                    break;
                }
                ++reqSkillIt;
            }
        }
        if (failed)
        {
            // This is a system failure.
            gMessageLib->SendSystemMessage(::common::OutOfBand("teaching", "learning_failed"), player);
            pageLink = 0;
            break;
        }

        // Here we start the non-fatal error processing.
        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Start the non-fatal error processing");
        if (player->getSkillPointsLeft() < skill->mSkillPointsRequired)
        {
            // Player lack skillpoints for training this skill.
            // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Player need %u skillpoints, but only have %u",skill->mSkillPointsRequired, player->getSkillPointsLeft());
            pageLink = 10;	// pageLink for this condition.
            break;
        }

        if (gWorldConfig->isTutorial())
        {
            // We do not charge any cost for training in the Tutorial.
            pageLink = 15;
        }
        else if ((dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getCredits() < av->getDI())
                 && (dynamic_cast<Bank*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank))->getCredits() < av->getDI())
                )
        {
            // Player lack credits in both inventory and bank.

            pageLink = 11;	// pageLink for this situation.
            // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Player needs %u credits, but only have %u as cash", av->getDI(),
            // 				dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getCredits());
            // System message: You lack the %DI credits required for training in %TO.
            gMessageLib->SendSystemMessage(::common::OutOfBand("skill_teacher", "prose_nsf", "", "", "", "", av->getTOStfFile().getAnsi(), av->getTOStfVariable().getAnsi(), av->getDI()), player);

            break;
        }
        else
        {
            // Let's start credit transaction for this skill...
            // Do that in next state...
        }
    }
    break;

    // View info about skills
    case 4:
    {
        bool noviceSkill = false;
        bool gotAllSkills = true;	// As long as we have not detected any missing skills.

        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: View info about skills");
        while(optionIt != page->mOptions.end())
        {
            Skill* skill = gSkillManager->getSkillByName((*optionIt)->mStfVariable);

            // its no skill option
            if (skill && ! player->checkSkill(skill->mId))
            {
                // If we end up here, we have at least some skill to train.
                gotAllSkills = false;

                // no skill requirements
                if (!skill->mSkillsRequired.size())
                {
                    // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Novice");
                    noviceSkill = true;
                }
                // see if we got the required skills
                else
                {
                    SkillsRequiredList::iterator reqSkillIt = skill->mSkillsRequired.begin();

                    while(reqSkillIt != skill->mSkillsRequired.end())
                    {
                        // we don't have the requirements
                        if(!player->checkSkill(*reqSkillIt))
                        {
                            break;
                        }
                        ++reqSkillIt;
                    }
                }
            }
            ++optionIt;
        }

        // Now we must return status of this session.
        // We have them all, i.e. we are a Master.
        if (gotAllSkills)
        {
            // We are a Master!
            // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We are a Master!");
            pageLink = 9;
        }
        else
        {
            if (noviceSkill) // avaliableSkills should be 1
            {
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We train to Novice.");
                // Not implemented yet. Special handling for the Space Station Tutorial Only.
            }
            else
            {
                // Let's select a skill to train. This is the default path.
                // retLinkPage = 0;	// Use caller default linkPage.
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Default, we have some skills to train.");
            }
        }
    }
    break;


    // Train the skill
    case 5:
    {
        bool failed = true;

        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Learn request");
        Skill* skill = gSkillManager->getSkillByName(av->getTOStfVariable());

        // its no skill option
        if (!skill)
        {
            // This is a system error.
        }
        else if(player->checkSkill(skill->mId))
        {
            // This is a system failure.
        }
        else if (player->getXpAmount(skill->mXpType) < skill->mXpCost)
        {
            // This is a system failure.
        }
        // see if we got the required skills
        else
        {
            failed = false;
            SkillsRequiredList::iterator reqSkillIt = skill->mSkillsRequired.begin();

            while(reqSkillIt != skill->mSkillsRequired.end())
            {
                // We don't have the requirements
                if (!player->checkSkill(*reqSkillIt))
                {
                    // This is a system failure.
                    failed = true;
                    break;
                }
                ++reqSkillIt;
            }
        }
        if (!failed)
        {
            // Let's train this skill...
            // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Processing %DI credit payment for %TO training.");
            gMessageLib->SendSystemMessage(::common::OutOfBand("skill_teacher", "prose_pay", "", "", "", "", av->getTOStfFile().getAnsi(), av->getTOStfVariable().getAnsi(), av->getDI()), player);

            // if (strstr(skill->mName.getAnsi(),"master"))
            if (mPlayerGotRequirementsForMasterSkill)
            {
                // We are going to train to Master...
                // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: We are going to train to Master...");
                // postProcessfilter(av, page, player, 13);
                postProcessfilter(av, player, 13);
                pageLink = 0;	// Terminate conversation
            }

            if (!(dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->updateCredits(-skill->mMoneyRequired)))
            {
                if (!(dynamic_cast<Bank*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank))->updateCredits(-skill->mMoneyRequired)))
                {
                    // This is a system error.
                    gMessageLib->SendSystemMessage(::common::OutOfBand("skill_teacher", "prose_nsf"), player);
                    pageLink = 0;
                }
            }
        }
        else
        {
            // This is a system error.
            gMessageLib->SendSystemMessage(::common::OutOfBand("teaching", "learning_failed"), player);
            // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Error verifying credits");
            pageLink = 0;
        }
    }
    break;


    // Train the skill in the Tutorial
    // NOTE: This case is never called, not even from Tutorial.
    case 15:
    {
        bool failed = true;

        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Learn request");
        Skill* skill = gSkillManager->getSkillByName(av->getTOStfVariable());

        // its no skill option
        if (!skill)
        {
            // This is a system error.
        }
        // no skill requirements, Novice Skills have no requirements.
        else if(player->checkSkill(skill->mId))
        {
            // This is a system failure.
        }
        else if (player->getXpAmount(skill->mXpType) < skill->mXpCost)
        {
            // This is a system failure.
        }
        // see if we got the required skills
        else
        {
            failed = false;
            SkillsRequiredList::iterator reqSkillIt = skill->mSkillsRequired.begin();

            while(reqSkillIt != skill->mSkillsRequired.end())
            {
                // We don't have the requirements
                if (!player->checkSkill(*reqSkillIt))
                {
                    // This is a system failure.
                    failed = true;
                    break;
                }
                ++reqSkillIt;
            }
        }
        if (!failed)
        {
            // We do not charge any cost for training in the Tutorial.
        }
        else
        {
            // This is a system error.
            gMessageLib->SendSystemMessage(::common::OutOfBand("teaching", "learning_failed"), player);
            // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Error verifying credits");
            pageLink = 0;
        }
    }
    break;

    case 7:
    {
        // Selected more info about this skill.
        Skill* skill = gSkillManager->getSkillByName(av->getTOStfVariable());
        if (skill)
        {

            int8 str[800];

            BStringVector populatedListBox;
            int8 strCaption[128];
            sprintf(strCaption,"@%s:%s","skl_n", skill->mName.getAnsi());

            sprintf(str,"MONETARY COST");
            populatedListBox.push_back(str);

            if (gWorldConfig->isTutorial() && (!skill->mSkillsRequired.size()))
            {
                sprintf(str,"%u credits", 0);
            }
            else
            {
                sprintf(str,"%u credits", skill->mMoneyRequired);
            }
            populatedListBox.push_back(str);

            sprintf(str,"SKILL POINT COST");
            populatedListBox.push_back(str);

            sprintf(str,"%u points", skill->mSkillPointsRequired);
            populatedListBox.push_back(str);

            sprintf(str,"REQUIRED SKILLS");
            populatedListBox.push_back(str);

            SkillsRequiredList::iterator reqSkillIt = skill->mSkillsRequired.begin();
            while (reqSkillIt != skill->mSkillsRequired.end())
            {
                // Add all skills required.
                // if (!player->checkSkill(*reqSkillIt))
                {
                    // We don't have this required skill
                    sprintf(str,"@%s:%s","skl_n", gSkillManager->getSkillById(*reqSkillIt)->mName.getAnsi());
                    populatedListBox.push_back(str);
                }
                ++reqSkillIt;
            }

            sprintf(str,"XP COST");
            populatedListBox.push_back(str);

            // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Skill type = %u named %s", skill->mXpType, gSkillManager->getXPTypeById(skill->mXpType).getAnsi());

            if (skill->mXpCost > 0)
            {
                sprintf(str,"%s = %u", gSkillManager->getXPTypeExById(skill->mXpType).getAnsi(), skill->mXpCost);
            }
            else
            {
                sprintf(str,"%s", gSkillManager->getXPTypeExById(skill->mXpType).getAnsi());
            }
            populatedListBox.push_back(str);

            sprintf(str,"You do not have this skill.\n\nDescription:\n%s", gSkillManager->getSkillInfoById(skill->mId).getAnsi());

            gUIManager->createNewListBox(NULL,"",strCaption,str,populatedListBox,player);
            // gUIManager->createNewListBox(NULL,"",strCaption,"@ui_attrib_mod:description \n\n@ui_attrib_mod:description \n@skl_d:combat_1hsword_ability_01",populatedListBox,player);
            // gUIManager->createNewListBox(NULL,"",strCaption,"@ui_attrib_mod:description \n@skl_d:combat_1hsword_ability_01 Testing",populatedListBox,player);
            // pageLink = 4;	// Back to where we come from...
        }
        else
        {
            DLOG(INFO) << "Trainer: No skill avaliable";
        }
    }
    break;

    default:
    {
        // gLogger->log(LogManager::DEBUG,"Trainer::conversationEvent: Default Nothing");
    }
    }
    return pageLink;
}
void InsuranceTerminal::handleObjectMenuSelect(uint8 messageType,Object* srcObject)
{
	PlayerObject* playerObject = (PlayerObject*)srcObject;

	if (playerObject && playerObject->isConnected())
	{
		// Fetch all items that can be insured.
		BStringVector insuranceList;
		this->getUninsuredItems(playerObject, &insuranceList);

		if (gWorldConfig->isTutorial())
		{
			// We do a simpleified version of insurance when using the terminal in the Tutorial.
			if (this->getParentId() && gWorldManager->getObjectById(this->getParentId())->getParentId())
			{
				// We are located inside a building.

				// Insure all insurable items.
				if (mSortedInsuranceList.size() ==  0)
				{
					// You do not have any items that can be insured. BUT.. we ignore this for now when running the tutorial.
					// gMessageLib->sendSystemMessage(playerObject, L"", "terminal_ui", "no_insurable_items");
				}
				else
				{
					// Insure all the items.

					// Let's warn about the fatal error conditions first (object destroyed or invalid type),
					SortedInventoryItemList::iterator it = mSortedInsuranceList.begin();
					while (it != mSortedInsuranceList.end())
					{
						string selectedItemm = (*it).first;
						selectedItemm.convert(BSTRType_Unicode16);

						Object* object = gWorldManager->getObjectById((*it).second);
						if (!object)
						{
							// Invalid object, we send a warning about this error.
							gMessageLib->sendSystemMessage(playerObject, L"", "error_message", "insure_fail");
						}
						else 
						{
							TangibleObject* tangibleObject = dynamic_cast<TangibleObject*>(object);
							if (!tangibleObject)
							{
								// Not a tangible object, we send a warning about this error.
									gMessageLib->sendSystemMessage(playerObject, L"", "error_message", "insure_fail");
							}
							else if (!tangibleObject->hasInternalAttribute("insured"))
							{
								// This is not a fatal error, but should never happen.

								// [Insurance] Item uninsurable: %TT.
								gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_item_uninsurable", "","", L"", 0, "", "", selectedItemm);
							}
							else if (tangibleObject->getInternalAttribute<bool>("insured"))
							{
								// This is not a fatal error, but should never happen.

								// [Insurance] Item already insured: %TT. 
								gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_item_already_insured", "","", L"", 0, "", "", selectedItemm);
							}
							else
							{
								// Update attribute.
								tangibleObject->setInternalAttribute("insured","1");
								gWorldManager->getDatabase()->ExecuteSqlAsync(NULL,NULL,"UPDATE item_attributes SET value=1 WHERE item_id=%"PRIu64" AND attribute_id=%u",tangibleObject->getId(), 1270);

								tangibleObject->setTypeOptions(tangibleObject->getTypeOptions() | 4);

								// Update insurance status.
								(void)gMessageLib->sendUpdateTypeOption(tangibleObject, playerObject);
							}
						}
						it++;
					}
				}
				// Always display success when doing the tutorial.

				// Insurance transaction successfully completed. 
				gMessageLib->sendSystemMessage(playerObject,L"","base_player","insure_success");

				// Inform Tutorial about the insurance.
				playerObject->getTutorial()->tutorialResponse("insureItemsDone");
			}
		}
		else
		{
			switch(messageType)
			{
				case radId_itemUse:
				{
					if (playerObject->getNewPlayerExemptions())	
					{
						// player have free deatchs left.
						gUIManager->createNewMessageBox(this,"","@base_player:noob_confirm_insure_title","@base_player:noob_confirm_insure_prompt",playerObject, SUI_Window_Insurance_Newbie_MessageBox, SUI_MB_YESNO);
					}
					else
					{
						// We should display all uninsured items that can be insured, and that are wearing or carrying in our inventory.
						// Items in backpackage or in other containers within our inventory shall also be handled.
						gUIManager->createNewListBox(this,"insure","@sui:mnu_insure","Select an item to insure.",insuranceList,playerObject,SUI_Window_Insurance_ListBox, SUI_MB_OKCANCEL);
					}
				}
				break;

				case radId_Unknown:	// Insure All
				{
					if (insuranceList.size() == 0)
					{
						// You do not have any items that can be insured. 
						gMessageLib->sendSystemMessage(playerObject, L"", "terminal_ui", "no_insurable_items");
					}
					else
					{
						if (playerObject->getNewPlayerExemptions())	
						{
							// player have free deatchs left.
							gUIManager->createNewMessageBox(this,"","@base_player:noob_confirm_insure_title","@base_player:noob_confirm_insure_prompt",playerObject, SUI_Window_InsureAll_Newbie_MessageBox, SUI_MB_YESNO);
						}
						else
						{
							uint32 insuranceFee = insuranceList.size() * 100;
							int8 sql[256];
							sprintf(sql,"@terminal_ui:insure_all_d_prefix %u @terminal_ui:insure_all_d_suffix \n\n @terminal_ui:insure_all_confirm", insuranceFee);
							gUIManager->createNewMessageBox(this,"","@terminal_ui:insure_all_t",sql,playerObject, SUI_Window_InsuranceAll_MessageBox, SUI_MB_YESNO);
						}
					}
				}
				break;

				default:
				{
					gLogger->logMsgF("InsuranceTerminal::handleObjectMenuSelect Unhandled MenuSelect: %u",MSG_NORMAL,messageType);
				}
				break;
			}
		}
	}
}
void InsuranceTerminal::handleUIEvent(uint32 action,int32 element,string inputStr,UIWindow* window)
{
	// gLogger->logMsgF("InsuranceTerminal::handleUIEvent You are here!",MSG_NORMAL);

	if(window == NULL)
	{
		return;
	}

	PlayerObject* playerObject = window->getOwner(); // window owner

	if(playerObject == NULL || !playerObject->isConnected() || playerObject->getSamplingState() || playerObject->isIncapacitated() || playerObject->isDead()|| playerObject->checkState(CreatureState_Combat))
	{
		return;
	}

	switch(window->getWindowType())
	{
		case SUI_Window_Insurance_Newbie_MessageBox:		// Tried to insure item when still having free rounds left.
		{
			switch(action)
			{
				case 0: // Yes
				{
					// Player selected to continue with insurance of item even if no need for.
					// gLogger->logMsgF("SUI_Window_Insurance_Newbie_MessageBox Yes",MSG_NORMAL);

					// Build the items list and optional use error-messages if needed.
					BStringVector insuranceList;
					this->getUninsuredItems(playerObject, &insuranceList);
					
					// We should display all uninsured items that can be insured, and that are wearing or carrying in our inventory.
					// Items in backpackage or in other containers within our inventory shall also be handled.
					gUIManager->createNewListBox(this,"insure","@sui:mnu_insure","Select an item to insure.",insuranceList,playerObject,SUI_Window_Insurance_ListBox, SUI_MB_OKCANCEL);
				}
				break;

				case 1: // No
				{
					// Player selected to abort, since all items are still treated as insured.
					// gLogger->logMsgF("SUI_Window_Insurance_Newbie_MessageBox No",MSG_NORMAL);
				}
				break;

				default:
				{
					gLogger->logMsgF("SUI_Window_Insurance_Newbie_MessageBox Invalid selection!",MSG_NORMAL);
				}
				break;
			}
		}
		break;

		case SUI_Window_Insurance_ListBox:
		{
			switch (action)
			{
				case 0: // OK
				{
					// Insure one item.
					// gLogger->logMsgF("SUI_Window_Insurance_ListBox OK",MSG_NORMAL);
					
					Inventory* inventoryObject = dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); 
					Bank* bankObject = dynamic_cast<Bank*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank));

					if(!inventoryObject || !bankObject)
						return;

					int32 creditsInInventory = inventoryObject->getCredits();
					int32 creditsAtBank = bankObject->getCredits();

					if (mSortedInsuranceList.size() ==  0)
					{
						// You have no insurable items.
						gMessageLib->sendSystemMessage(playerObject, L"", "error_message", "no_insurables");
					}
					else if (element > (int32)mSortedInsuranceList.size() - 1 || element < 0)
					{
						// Unable to process insure item request.
						gMessageLib->sendSystemMessage(playerObject, L"", "error_message", "bad_insure_request");
					}
					else
					{
						string selectedItemm((mSortedInsuranceList.at(element).first).getAnsi());
						selectedItemm.convert(BSTRType_Unicode16);

						Object* object = gWorldManager->getObjectById(mSortedInsuranceList.at(element).second);
						if (!object)
						{
							// Invalid object.
							// Insure attempt failed.
							gMessageLib->sendSystemMessage(playerObject, L"", "error_message", "insure_fail");
							break;
						}
						TangibleObject* tangibleObject = dynamic_cast<TangibleObject*>(object);
						if (!tangibleObject)
						{
							// Not a tangible object.
							// Insure attempt failed.
							gMessageLib->sendSystemMessage(playerObject, L"", "error_message", "insure_fail");
						}
						else if (!tangibleObject->hasInternalAttribute("insured"))
						{
							// [Insurance] Item uninsurable: %TT.
							gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_item_uninsurable", "","", L"", 0, "", "", selectedItemm);
						}
						else if (tangibleObject->getInternalAttribute<bool>("insured"))
						{
							// [Insurance] Item already insured: %TT. 
							gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_item_already_insured", "","", L"", 0, "", "", selectedItemm);
						}
						else if ((creditsAtBank+creditsInInventory) < mInsuranceFee)
						{
							// You have insufficient funds to insure your %TT. 
							gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_nsf_insure", "","", L"", 0, "", "", selectedItemm);
						}
						else
						{
							int32 delta = creditsInInventory - mInsuranceFee;

							if(delta >= 0)
							{
								inventoryObject->updateCredits(-mInsuranceFee);
							}
							else if(delta < 0 && creditsAtBank >= (-delta))
							{
								inventoryObject->updateCredits(mInsuranceFee + delta);
								bankObject->updateCredits(delta);
							}

							// The credits is drawn from the player inventory and/or bank.
							// System message: You successfully make a payment of %DI credits to %TO.
							gMessageLib->sendSystemMessage(playerObject, L"", "base_player", "prose_pay_acct_success", "terminal_name", "terminal_insurance", L"", mInsuranceFee);

							// Update attribute.
							// string str("insured");
							tangibleObject->setInternalAttribute("insured","1");
							gWorldManager->getDatabase()->ExecuteSqlAsync(NULL,NULL,"UPDATE item_attributes SET value=1 WHERE item_id=%"PRIu64" AND attribute_id=%u",tangibleObject->getId(), 1270);

							//gLogger->logMsgF("UPDATE item_attributes SET value=1 WHERE item_id=%"PRIu64" AND attribute_id=%u", MSG_NORMAL, tangibleObject->getId(), 1270);
							
							tangibleObject->setTypeOptions(tangibleObject->getTypeOptions() | 4);

							// Update insurance status.
							(void)gMessageLib->sendUpdateTypeOption(tangibleObject, playerObject);

							// You successfully insure your %TT. 
							gMessageLib->sendSystemMessage(playerObject,L"","base_player","prose_insure_success", "","", L"", 0, "", "", selectedItemm);
						}
						/*else
						{
							// An attempt to insure your %TT has failed. Most likely, this is due to lack of funds. 
							gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_insure_fail", "","", L"", 0, "", "", selectedItemm);
						}*/
					}
				}
				break;

				case 1: // Cancel
				{
					// gLogger->logMsgF("SUI_Window_Insurance_ListBox Cancel",MSG_NORMAL);
				}
				break;

				default:
				{
					// gLogger->logMsgF("SUI_Window_Insurance_ListBox Invalid selection!",MSG_NORMAL);
				}
				break;
			}
		}
		break;

		case SUI_Window_InsureAll_Newbie_MessageBox:
		{
			switch(action)
			{
				case 0: // Yes
				{
					// Player selected to continue with insurance of item even if no need for.
					// gLogger->logMsgF("SUI_Window_InsureAll_Newbie_MessageBox Yes",MSG_NORMAL);

					// Fetch all items that can be insured.
					BStringVector insuranceList;
					this->getUninsuredItems(playerObject, &insuranceList);

					uint32 insuranceFee = insuranceList.size() * mInsuranceFee;
					int8 sql[256];
					sprintf(sql,"@terminal_ui:insure_all_d_prefix %u @terminal_ui:insure_all_d_suffix \n\n @terminal_ui:insure_all_confirm", insuranceFee);
					gUIManager->createNewMessageBox(this,"","@terminal_ui:insure_all_t",sql,playerObject, SUI_Window_InsuranceAll_MessageBox, SUI_MB_YESNO);
				}
				break;

				case 1: // No
				{
					// Player selected to abort, since all items are still treated as insured.
					// gLogger->logMsgF("SUI_Window_InsureAll_Newbie_MessageBox No",MSG_NORMAL);
				}
				break;

				default:
				{
					gLogger->logMsgF("SUI_Window_InsureAll_Newbie_MessageBox Invalid selection!",MSG_NORMAL);
				}
				break;
			}
		}
		break;

		case SUI_Window_InsuranceAll_MessageBox:
		{
			switch(action)
			{
				case 0: // Yes
				{
					// Insure all insurable items.
					int32 creditsAtBank = (dynamic_cast<Bank*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank))->getCredits());
					string selectedItemm;
					int32 fee = mSortedInsuranceList.size() * mInsuranceFee;

					if (mSortedInsuranceList.size() ==  0)
					{
						// You do not have any items that can be insured. 
						gMessageLib->sendSystemMessage(playerObject, L"", "terminal_ui", "no_insurable_items");
					}
					else if (creditsAtBank < fee)
					{
						// You have insufficient funds to insure your %TT. 
						gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_nsf_insure", "","", L"", 0, "", "", L"items");
					}
					else
					{
						// Insure all the items.
						bool abortInsurance = false;

						// Let's clear the fatal error conditions first (object destroyed or invalid type),
						SortedInventoryItemList::iterator it = mSortedInsuranceList.begin();
						while (it != mSortedInsuranceList.end())
						{
							Object* object = gWorldManager->getObjectById((*it).second);
							if (!object)
							{
								// Invalid object, we abort this transaction.

								// Insure attempt failed.
								gMessageLib->sendSystemMessage(playerObject, L"", "error_message", "insure_fail");
								abortInsurance = true;
								break;
							}
		
							TangibleObject* tangibleObject = dynamic_cast<TangibleObject*>(object);
							if (!tangibleObject)
							{
								// Not a tangible object, we abort this transaction.
								// Insure attempt failed.
								gMessageLib->sendSystemMessage(playerObject, L"", "error_message", "insure_fail");
								abortInsurance = true;
								break;
							}
							it++;
						}

						if (abortInsurance)
						{
							break;
						}

						if ((dynamic_cast<Bank*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank))->updateCredits(-fee)))
						{
							// The credits is drawn from the player bank.
							// System message: You successfully make a payment of %DI credits to %TO.
							gMessageLib->sendSystemMessage(playerObject, L"", "base_player", "prose_pay_acct_success", "terminal_name", "terminal_insurance", L"", fee);

							it = mSortedInsuranceList.begin();
							while (it != mSortedInsuranceList.end())
							{
								selectedItemm = (*it).first;
								selectedItemm.convert(BSTRType_Unicode16);

								Object* object = gWorldManager->getObjectById((*it).second);
								TangibleObject* tangibleObject = dynamic_cast<TangibleObject*>(object);

								if (!tangibleObject->hasInternalAttribute("insured"))
								{
									// This is not a fatal error, but should never happen.

									// [Insurance] Item uninsurable: %TT.
									gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_item_uninsurable", "","", L"", 0, "", "", selectedItemm);
									// fee -= insuranceFee;
									it++;
									continue;
								}

								if (tangibleObject->getInternalAttribute<bool>("insured"))
								{
									// This is not a fatal error, but should never happen.

									// [Insurance] Item already insured: %TT. 
									gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_item_already_insured", "","", L"", 0, "", "", selectedItemm);
									// fee -= insuranceFee;
									it++;
									continue;
								}

								// Insure the item.
								// Update attribute.
								tangibleObject->setInternalAttribute("insured","1");
								gWorldManager->getDatabase()->ExecuteSqlAsync(NULL,NULL,"UPDATE item_attributes SET value=1 WHERE item_id=%"PRIu64" AND attribute_id=%u",tangibleObject->getId(), 1270);

								tangibleObject->setTypeOptions(tangibleObject->getTypeOptions() | 4);

								// Update insurance status.
								(void)gMessageLib->sendUpdateTypeOption(tangibleObject, playerObject);

								it++;
							}

							// Insurance transaction successfully completed. 
							gMessageLib->sendSystemMessage(playerObject,L"","base_player","insure_success");

						}
						else
						{
							// An attempt to insure your %TT has failed. Most likely, this is due to lack of funds. 
							gMessageLib->sendSystemMessage(playerObject,L"","error_message","prose_insure_fail", "","", L"", 0, "", "", L"items");
						}
					}

				}
				break;

				case 1: // No
				{
					// gLogger->logMsgF("SUI_Window_InsuranceAll_MessageBox No",MSG_NORMAL);
				}
				break;

				default:
				{
					gLogger->logMsgF("SUI_Window_InsuranceAll_MessageBox Invalid selection!",MSG_NORMAL);
				}
				break;
			}
		}
		break;

		default:
		{
		}
		break;
	}
	
	// gLogger->logMsgF("CloningTerminal::handleUIEvent You sure handled this UI-event!, Action = %d",MSG_NORMAL, action);
}
Beispiel #12
0
void TicketCollector::handleUIEvent(uint32 action,int32 element,BString inputStr,UIWindow* window)
{
    if (!action && element != -1 && mShuttle != NULL && mShuttle->availableInPort())
    {
        uint32			zoneId			= gWorldManager->getZoneId();
        PlayerObject*	playerObject	= window->getOwner();

        if(playerObject->getSurveyState() || playerObject->getSamplingState() || playerObject->isIncapacitated() || playerObject->isDead())
        {
            return;
        }

        // in range check
        if(playerObject->getParentId() != mParentId || (glm::distance(playerObject->mPosition, this->mPosition) > 10.0f))
        {
            gMessageLib->SendSystemMessage(::common::OutOfBand("travel", "boarding_too_far"), playerObject);
            return;
        }

        ObjectIDList*			invObjects	= dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getObjects();
        ObjectIDList::iterator	it			= invObjects->begin();

        while(it != invObjects->end())
        {
            if(TravelTicket* ticket = dynamic_cast<TravelTicket*>(gWorldManager->getObjectById((*it))))
            {
                BString srcPoint		= (int8*)((ticket->getAttribute<std::string>("travel_departure_point")).c_str());
                BString dstPointStr	= (int8*)((ticket->getAttribute<std::string>("travel_arrival_point")).c_str());
                uint16 srcPlanetId	= static_cast<uint16>(gWorldManager->getPlanetIdByName((int8*)((ticket->getAttribute<std::string>("travel_departure_planet")).c_str())));
                uint16 dstPlanetId	= static_cast<uint16>(gWorldManager->getPlanetIdByName((int8*)((ticket->getAttribute<std::string>("travel_arrival_planet")).c_str())));

                BStringVector* items = (dynamic_cast<UIListBox*>(window))->getDataItems();
                BString selectedDst = items->at(element);
                selectedDst.convert(BSTRType_ANSI);

                if(srcPlanetId == zoneId && (strcmp(srcPoint.getAnsi(),mPortDescriptor.getAnsi()) == 0)
                        && (strcmp(dstPointStr.getAnsi(),selectedDst.getAnsi()) == 0))
                {
                    if(TravelPoint* dstPoint = gTravelMapHandler->getTravelPoint(dstPlanetId,dstPointStr))
                    {
                        glm::vec3 destination;
                        // getRand(5) return 0-4, then sub 2, and you get equal of random values at both sides of zero. (-2, -1, 0, 1, 2)
                        destination.x = dstPoint->spawnX + (gRandom->getRand()%5 - 2);
                        destination.y = dstPoint->spawnY;
                        destination.z = dstPoint->spawnZ + (gRandom->getRand()%5 - 2);

                        // If it's on this planet, then just warp, otherwize zone
                        if(dstPlanetId == zoneId)
                        {
                            // only delete the ticket if we are warping on this planet.
							TangibleObject* tO = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(ticket->getParentId()));
							gContainerManager->deleteObject(ticket, tO);
                            
                            gWorldManager->warpPlanet(playerObject,destination,0);
                        }
                        else
                        {
                            gMessageLib->sendClusterZoneTransferRequestByTicket(playerObject, ticket->getId(), dstPoint->planetId);

                        }
                    }
                    else
                    {
                        DLOG(info) << "TicketCollector: Error getting TravelPoint";
                    }
                    break;
                }
            }

            ++it;
        }
    }
}
void CreatureObject::die()
{
	mIncapCount			= 0;
	mCurrentIncapTime	= 0;
	mFirstIncapTime		= 0;

	// gLogger->logMsg("CreatureObject::die I'm dead");

	gMessageLib->sendIncapTimerUpdate(this);

	if(PlayerObject* player = dynamic_cast<PlayerObject*>(this))
	{
		gMessageLib->sendSystemMessage(player,L"","base_player","victim_dead");
		player->disableAutoAttack();
	}

	mPosture = CreaturePosture_Dead;

	// reset ham regeneration
	mHam.updateRegenRates();
	gWorldManager->removeCreatureHamToProcess(mHam.getTaskId());
	mHam.setTaskId(0);

	updateMovementProperties();

	// clear states
	mState = 0;

	gMessageLib->sendPostureAndStateUpdate(this);

	if(PlayerObject* player = dynamic_cast<PlayerObject*>(this))
	{
		gMessageLib->sendUpdateMovementProperties(player);
		gMessageLib->sendSelfPostureUpdate(player);

		// update duel lists
		PlayerList::iterator duelIt = player->getDuelList()->begin();

		while(duelIt != player->getDuelList()->end())
		{
			if((*duelIt)->checkDuelList(player))
			{
				PlayerObject* duelPlayer = (*duelIt);

				duelPlayer->removeFromDuelList(player);

				gMessageLib->sendUpdatePvpStatus(player,duelPlayer);
				gMessageLib->sendUpdatePvpStatus(duelPlayer,player);
			}

			++duelIt;
		}
		player->getDuelList()->clear();

		// update defender lists
		ObjectIDList::iterator defenderIt = mDefenders.begin();
		while (defenderIt != mDefenders.end())
		{
			if (CreatureObject* defenderCreature = dynamic_cast<CreatureObject*>(gWorldManager->getObjectById((*defenderIt))))
			{
				defenderCreature->removeDefenderAndUpdateList(this->getId());

				if (PlayerObject* defenderPlayer = dynamic_cast<PlayerObject*>(defenderCreature))
				{
					gMessageLib->sendUpdatePvpStatus(this,defenderPlayer);
					// gMessageLib->sendDefenderUpdate(defenderPlayer,0,0,this->getId());
				}

				// Defender not hostile to me any more.
				gMessageLib->sendUpdatePvpStatus(defenderCreature, player);

				// if no more defenders, clear combat state
				if (!defenderCreature->getDefenders()->size())
				{
					defenderCreature->toggleStateOff((CreatureState)(CreatureState_Combat + CreatureState_CombatAttitudeNormal));
					gMessageLib->sendStateUpdate(defenderCreature);
				}
			}
			// If we remove self from all defenders, then we should remove all defenders from self. Remember, we are dead.
			defenderIt = mDefenders.erase(defenderIt);
		}

		// bring up the clone selection window
		ObjectSet inRangeBuildings;
		BStringVector buildingNames;
		std::vector<BuildingObject*> buildings;
		BuildingObject*	nearestBuilding = NULL;
		BuildingObject* preDesignatedBuilding = NULL;

		// Search for cloning facilities.
		gWorldManager->getSI()->getObjectsInRange(this,&inRangeBuildings,ObjType_Building,8192);

		ObjectSet::iterator buildingIt = inRangeBuildings.begin();

		while (buildingIt != inRangeBuildings.end())
		{
			BuildingObject* building = dynamic_cast<BuildingObject*>(*buildingIt);
			if (building)
			{
				// Do we have any personal clone location?
				if (building->getId() == player->getPreDesignatedCloningFacilityId())
				{
					// gLogger->logMsg("Found a pre-designated cloning facility");
					preDesignatedBuilding = building;
				}

				if (building->getBuildingFamily() == BuildingFamily_Cloning_Facility)
				{
					// gLogger->logMsg("Found a cloning facility");
					// TODO: This code is not working as intended if player dies inside, since buildings use world coordinates and players inside have cell coordinates.
					// Tranformation is needed before the correct distance can be calculated.
					if(!nearestBuilding	||
                        (nearestBuilding != building && (glm::distance(mPosition, building->mPosition) < glm::distance(mPosition, nearestBuilding->mPosition))))
					{
						nearestBuilding = building;
					}
				}
			}
			++buildingIt;
		}

		if (nearestBuilding)
		{
			if (nearestBuilding->getSpawnPoints()->size())
			{
				// buildingNames.push_back(nearestBuilding->getRandomSpawnPoint()->mName.getAnsi());
				// buildingNames.push_back("Closest Cloning Facility");
				buildingNames.push_back("@base_player:revive_closest");
				buildings.push_back(nearestBuilding);

				// Save nearest building in case we need to clone when reviev times out.
				player->saveNearestCloningFacility(nearestBuilding);
			}
		}

		if (preDesignatedBuilding)
		{
			if (preDesignatedBuilding->getSpawnPoints()->size())
			{
				// buildingNames.push_back("Pre-Designated Facility");
				buildingNames.push_back("@base_player:revive_bind");
				buildings.push_back(preDesignatedBuilding);
			}
		}

		if (buildings.size())
		{
			// Set up revive timer in case of user don't clone.
			gWorldManager->addPlayerObjectForTimedCloning(player->getId(), 10 * 60 * 1000);	// TODO: Don't use hardcoded value.
			gUIManager->createNewCloneSelectListBox(player,"cloneSelect","Select Clone Destination","Select clone destination",buildingNames,buildings,player);
		}
		else
		{
			gLogger->logMsg("No cloning facility available\n");
		}
	}
	else // if(CreatureObject* creature = dynamic_cast<CreatureObject*>(this))
	{
		// gMessageLib->sendUpdateMovementProperties(player);
		// gMessageLib->sendSelfPostureUpdate(player);

		// Who killed me
		// this->prepareCustomRadialMenu(this,0);

		//
		// update defender lists
		ObjectIDList::iterator defenderIt = mDefenders.begin();

		while(defenderIt != mDefenders.end())
		{
			// This may be optimized, but rigth now THIS code does the job.
			this->makePeaceWithDefender(*defenderIt);
			defenderIt = mDefenders.begin();
		}

		// I'm dead. De-spawn after "loot-timer" has expired, if any.
		// 3-5 min.
		uint64 timeBeforeDeletion = (180 + (gRandom->getRand() % (int32)120)) * 1000;
		if (this->getCreoGroup() == CreoGroup_AttackableObject)
		{
			// timeBeforeDeletion = 2 * 1000;
			// Almost NOW!
			timeBeforeDeletion = 500;

			// Play the death-animation, if any.
			if (AttackableStaticNpc* staticNpc = dynamic_cast<AttackableStaticNpc*>(this))
			{
				staticNpc->playDeathAnimation();
			}
		}
		else if (this->getCreoGroup() == CreoGroup_Creature)
		{
			if (AttackableCreature* creature = dynamic_cast<AttackableCreature*>(this))
			{
				creature->unequipWeapon();

				// Give XP to the one(s) attacking me.
				// creature->updateAttackersXp();
			}
		}

		if (NPCObject* npc = dynamic_cast<NPCObject*>(this))
		{
			// Give XP to the one(s) attacking me.
			npc->updateAttackersXp();
		}

		// Put this creature in the pool of delayed destruction.
		gWorldManager->addCreatureObjectForTimedDeletion(this->getId(), timeBeforeDeletion);
		// this->killEvent();
	}
}
Beispiel #14
0
void TravelMapHandler::handleUIEvent(uint32 action,int32 element,BString inputStr,UIWindow* window)
{
    if(!action && element != -1 )
    {
        uint32					zoneId			= gWorldManager->getZoneId();
        PlayerObject*			playerObject	= window->getOwner();
        UITicketSelectListBox*	listBox			= dynamic_cast<UITicketSelectListBox*>(window);

        if(playerObject->getSurveyState() || playerObject->getSamplingState() || !listBox)
            return;

        Shuttle* shuttle = listBox->getShuttle();

        if(!shuttle)
        {
            return;
        }

        if (!shuttle->availableInPort())
        {
            gMessageLib->SendSystemMessage(::common::OutOfBand("travel", "shuttle_not_available"), playerObject);
            return;
        }

        if((playerObject->getParentId() != shuttle->getParentId()) || (glm::distance(playerObject->mPosition, shuttle->mPosition) > 25.0f))
        {
            gMessageLib->SendSystemMessage(::common::OutOfBand("travel", "boarding_too_far"), playerObject);

            return;
        }

        ObjectIDList*			invObjects		= dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getObjects();
        ObjectIDList::iterator	it				= invObjects->begin();

        while(it != invObjects->end())
        {
            TravelTicket* ticket = dynamic_cast<TravelTicket*>(gWorldManager->getObjectById((*it)));
            if(ticket)
            {
                BString srcPoint		= (int8*)((ticket->getAttribute<std::string>("travel_departure_point")).c_str());
                BString dstPointStr	= (int8*)((ticket->getAttribute<std::string>("travel_arrival_point")).c_str());
                uint16 srcPlanetId	= static_cast<uint8>(gWorldManager->getPlanetIdByName((int8*)((ticket->getAttribute<std::string>("travel_departure_planet")).c_str())));
                uint16 dstPlanetId	= static_cast<uint8>(gWorldManager->getPlanetIdByName((int8*)((ticket->getAttribute<std::string>("travel_arrival_planet")).c_str())));

                BStringVector* items = (dynamic_cast<UIListBox*>(window))->getDataItems();
                BString selectedDst = items->at(element);
                selectedDst.convert(BSTRType_ANSI);

                if(srcPlanetId == zoneId && (strcmp(dstPointStr.getAnsi(),selectedDst.getAnsi()) == 0)&&(strcmp(srcPoint.getAnsi(),listBox->getPort().getAnsi()) == 0))
                {
                    TravelPoint* dstPoint = gTravelMapHandler->getTravelPoint(dstPlanetId,dstPointStr);

                    if(dstPoint != NULL)
                    {
                        glm::vec3 destination;
                        destination.x = dstPoint->spawnX + (gRandom->getRand()%5 - 2);
                        destination.y = dstPoint->spawnY;
                        destination.z = dstPoint->spawnZ + (gRandom->getRand()%5 - 2);

                        // If it's on this planet, then just warp, otherwize zone
                        if(dstPlanetId == zoneId)
                        {
                            // only delete the ticket if we are warping on this planet.
							TangibleObject* tO = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(ticket->getParentId()));
							gContainerManager->deleteObject(ticket, tO);

							gWorldManager->warpPlanet(playerObject,destination,0);
                        }
                        else
                        {
                            gMessageLib->sendClusterZoneTransferRequestByTicket(playerObject,ticket->getId(), dstPoint->planetId);
                        }
                    }
                    else
                    {
                    }
                    break;
                }
            }
            ++it;
        }
    }
}
//======================================================================================================================
void UIManager::createNewDiagnoseListBox(UICallback* callback,PlayerObject* Medic, PlayerObject* Patient)
{
	BStringVector attributesMenu;

	BString FirstName = Patient->getFirstName(); FirstName.toUpper();
	BString LastName = Patient->getLastName(); LastName.toUpper();

	int8 title[64];
	sprintf(title,"PATIENT %s %s'S WOUNDS",FirstName.getAnsi(), LastName.getAnsi());

	int8 desc[512];
	sprintf(desc, "Below is a listing of the Wound and Battle Fatigue levels of %s %s. Wounds are healed through /tendWound or use of Wound Medpacks. High levels of Battle Fatigue can inhibit the healing process, and Battle Fatigue can only be healed by the patient choosing to watch performing entertainers",Patient->getFirstName().getAnsi(), Patient->getLastName().getAnsi());

	int8 Health[32];
	sprintf(Health,"Health -- %i",Patient->getHam()->mHealth.getWounds());
	attributesMenu.push_back(Health);

	int8 Strength[32];
	sprintf(Strength,"Strength -- %i",Patient->getHam()->mStrength.getWounds());
	attributesMenu.push_back(Strength);
	
	int8 Constitution[32];
	sprintf(Constitution,"Constitution -- %i",Patient->getHam()->mConstitution.getWounds());
	attributesMenu.push_back(Constitution);
	
	int8 Action[32];
	sprintf(Action,"Action -- %i",Patient->getHam()->mAction.getWounds());
	attributesMenu.push_back(Action);

	int8 Quickness[32];
	sprintf(Quickness,"Quickness -- %i",Patient->getHam()->mQuickness.getWounds());
	attributesMenu.push_back(Quickness);

	int8 Stamina[32];
	sprintf(Stamina,"Stamina -- %i",Patient->getHam()->mStamina.getWounds());
	attributesMenu.push_back(Stamina);

	int8 Mind[32];
	sprintf(Mind,"Mind -- %i",Patient->getHam()->mMind.getWounds());
	attributesMenu.push_back(Mind);

	int8 Focus[32];
	sprintf(Focus,"Focus -- %i",Patient->getHam()->mFocus.getWounds());
	attributesMenu.push_back(Focus);

	int8 Willpower[32];
	sprintf(Willpower,"Willpower -- %i",Patient->getHam()->mWillpower.getWounds());
	attributesMenu.push_back(Willpower);

	int8 BattleFatigue[32];
	sprintf(BattleFatigue,"Battle Fatigue -- %i",Patient->getHam()->getBattleFatigue());
	attributesMenu.push_back(BattleFatigue);

	createNewListBox(callback,"handleDiagnoseMenu",title, desc, attributesMenu, Medic, SUI_Window_ListBox,SUI_LB_OK,Patient->getId());
}