Ejemplo n.º 1
0
void TreasuryManager::bankTipOnline(int32 amount, PlayerObject* playerObject, PlayerObject* targetObject )
{
    //check if we have enough money
    int32 surcharge = (int32)((amount/100)*5);

    if((amount+surcharge) > dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getCredits())
    {
        BString s;
        s = targetObject->getFirstName();
        s.convert(BSTRType_Unicode16);
        gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "prose_tip_nsf_cash", L"", s.getUnicode16(), L"", amount), playerObject);
        return;
    }

    Bank* playerBank = dynamic_cast<Bank*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank));
    Bank* targetBank = dynamic_cast<Bank*>(targetObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank));

    playerBank->setCredits(playerBank->getCredits() - (amount+surcharge));
    targetBank->setCredits(targetBank->getCredits() + amount);

    saveAndUpdateBankCredits(playerObject);
    saveAndUpdateBankCredits(targetObject);

    gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "prose_tip_pass_self", 0, targetObject->getId(), 0, amount), playerObject);
    gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "prose_tip_pass_target", 0, playerObject->getId(), 0, amount), targetObject);

    gMessageLib->sendBanktipMail(playerObject,targetObject,amount);
}
Ejemplo n.º 2
0
void TreasuryManager::bankTipOffline(int32 amount,PlayerObject* playerObject,BString targetName)
{

    //============================================
    //check whether we have sufficient funds
    //dont forget the surcharge
    Bank* bank = dynamic_cast<Bank*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank));
    int32 credits = bank->getCredits();

    int32 surcharge = (int32)((amount/100)*5);

    if((amount + surcharge) > credits)
    {
        BString uniName = targetName;
        uniName.convert(BSTRType_Unicode16);

        gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "prose_tip_nsf_bank", L"", L"", uniName.getUnicode16(), amount), playerObject);
        return;
    }
    //now get the player
    int8 name[50];
    mDatabase->Escape_String(name,targetName.getAnsi(),targetName.getLength());

    int8 sql[256];
    sprintf(sql,"SELECT id FROM characters WHERE firstname like '%s'",name);

    TreasuryManagerAsyncContainer* asyncContainer;
    asyncContainer = new TreasuryManagerAsyncContainer(TREMQuery_BankTipgetId,playerObject->getClient());
    asyncContainer->amount = amount;
    asyncContainer->surcharge = surcharge;
    asyncContainer->targetName = targetName;
    asyncContainer->player = playerObject;

    mDatabase->ExecuteSqlAsync(this,asyncContainer,sql);
}
Ejemplo n.º 3
0
void MissionManager::missionComplete(PlayerObject* player, MissionObject* mission)
{
	wchar_t sm[100];
	swprintf(sm,100, L"","mission/mission_generic",L"success_w_amount",mission->getReward());
	gMessageLib->sendSystemMessage(player,sm);

	//remove mission
	gMessageLib->sendSetWaypointActiveStatus(mission->getWaypoint(),false,player);
	gMessageLib->sendDestroyObject(mission->getId(),player);

	//Give the player the credit reward
	gMessageLib->sendPlayMusicMessage(2501,player); //sound/music_mission_complete.snd
	gMessageLib->sendMissionComplete(player);
	Bank* bank = dynamic_cast<Bank*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank));
	bank->setCredits(bank->getCredits() + mission->getReward());
	gTreasuryManager->saveAndUpdateBankCredits(player);

return;
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
void TreasuryManager::handleDatabaseJobComplete(void* ref,DatabaseResult* result)
{
    TreasuryManagerAsyncContainer* asynContainer = (TreasuryManagerAsyncContainer*)ref;


    switch(asynContainer->mQueryType)
    {

    case TREMQuery_BankTipgetId:
    {
        if(!result->getRowCount())
        {
            gMessageLib->SendSystemMessage(L"You may only /tip or /tip bank to other players.", asynContainer->player);
            return;
        }

        uint64 id;
        DataBinding* binding = mDatabase->CreateDataBinding(1);
        binding->addField(DFT_uint64,0,8);
        result->GetNextRow(binding,&id);

        //ok we just established that our target exists
        //we now need to update the bank on the db side
        TreasuryManagerAsyncContainer* asyncContainer = new TreasuryManagerAsyncContainer(TREMQuery_BankTipTransaction,asynContainer->player->getClient());

        asyncContainer->amount		= asynContainer->amount;
        asyncContainer->surcharge	= asynContainer->surcharge;
        asyncContainer->player		= asynContainer->player;
        asyncContainer->targetId	= id;
        asyncContainer->targetName = asynContainer->targetName;

        //=======================================================
        //now remind the other player of the surcharge
        gUIManager->createNewMessageBox(this,"","@base_player:tip_wire_title","@base_player:tip_wire_prompt",asynContainer->player, SUI_Window_Trade_BankTip_ConfirmSurcharge, SUI_MB_OKCANCEL,asyncContainer);

        break;


    }
    break;

    case TREMQuery_BankTipTransaction:
    {
        uint32 error;
        DataBinding* binding = mDatabase->CreateDataBinding(1);
        binding->addField(DFT_uint32,0,4);
        result->GetNextRow(binding,&error);

        if (error == 0)
        {
            Bank* bank = dynamic_cast<Bank*>(asynContainer->player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank));

            //update our own bankaccount
            bank->setCredits(bank->getCredits() - asynContainer->amount);

            gMessageLib->sendBankCreditsUpdate(asynContainer->player);
            gMessageLib->sendBankTipDustOff(asynContainer->player,asynContainer->targetId,asynContainer->amount,asynContainer->targetName);
            //notify the chatserver for the EMails and the off zone accounts

            int8 sql[1024];

            //CAVE galaxy id is hardcoded!!!!!!1
            int8 galaxyId = 2;

            sprintf(sql, "CALL sp_GalaxyAccountDepositCredits(%u, %u, %"PRIu64",%u",galaxyId, Account_TipSurcharge, asynContainer->player, asynContainer->surcharge);
            TreasuryManagerAsyncContainer* asyncContainer = new TreasuryManagerAsyncContainer(TREMQuery_BankTipUpdateGalaxyAccount,0);

            mDatabase->ExecuteProcedureAsync(this,asyncContainer,sql);
            
        }
        else
        {
            gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "bank_error"), asynContainer->player);
        }
    }
    break;

    case TREMQuery_BankTipUpdateGalaxyAccount:
    {
        uint32 error;
        DataBinding* binding = mDatabase->CreateDataBinding(1);
        binding->addField(DFT_uint32,0,4);
        result->GetNextRow(binding,&error);

        if (error > 0)
        {
            gLogger->log(LogManager::DEBUG,"TreasuryManager::Account_TipSurcharge: error %u", error);
        }
    }
    break;
    case TREMQuery_NULL:
    {

    }
    break;

    default:
        break;
    }

    delete(asynContainer);
}