Browse Source

Status is supported for housing now, purchase, upkeep, escrow

Fix #138
Image 3 years ago
parent
commit
dffca17379

+ 1 - 1
EQ2/source/WorldServer/ClientPacketFunctions.h

@@ -77,7 +77,7 @@ public:
 	static void SendAchievementList(Client* client);
 
 	/* Housing (/Housing/HousingPackets.cpp) */
-	static void SendHousePurchace(Client* client, HouseZone* hz, int32 spawnID);
+	static void SendHousePurchase(Client* client, HouseZone* hz, int32 spawnID);
 	static void SendHousingList(Client* client);
 	static void SendBaseHouseWindow(Client* client, HouseZone* hz, PlayerHouse* ph, int32 spawnID);
 	static void SendHouseVisitWindow(Client* client, vector<PlayerHouse*> houses);

+ 1 - 0
EQ2/source/WorldServer/Entity.h

@@ -712,6 +712,7 @@ struct InfoStruct{
 
 	void	set_status_points(int32 value) { std::lock_guard<std::mutex> lk(classMutex); status_points_ = value; }
 	void	add_status_points(int32 value) { std::lock_guard<std::mutex> lk(classMutex); status_points_ += value; }
+	bool	subtract_status_points(int32 value) { std::lock_guard<std::mutex> lk(classMutex); if(value > status_points_) return false; status_points_ -= value; return true; }
 	
 	void	set_mitigation_skill1(int16 value) { std::lock_guard<std::mutex> lk(classMutex); mitigation_skill1_ = value; }
 	void	set_mitigation_skill2(int16 value) { std::lock_guard<std::mutex> lk(classMutex); mitigation_skill2_ = value; }

+ 3 - 3
EQ2/source/WorldServer/Housing/HousingDB.cpp

@@ -31,10 +31,10 @@ void WorldDatabase::SetHouseUpkeepDue(int32 char_id, int32 house_id, int32 insta
 }
 
 
-void WorldDatabase::UpdateHouseEscrow(int32 house_id, int32 instance_id, int64 amount) {
+void WorldDatabase::UpdateHouseEscrow(int32 house_id, int32 instance_id, int64 amount_coins, int32 amount_status) {
 	Query query;
-	string update = string("UPDATE character_houses set escrow_coins = %I64u where house_id = %u and instance_id = %u");
-	query.RunQuery2(Q_UPDATE, update.c_str(), amount, house_id, instance_id);
+	string update = string("UPDATE character_houses set escrow_coins = %I64u, escrow_status = %u where house_id = %u and instance_id = %u");
+	query.RunQuery2(Q_UPDATE, update.c_str(), amount_coins, amount_status, house_id, instance_id);
 }
 
 

+ 2 - 2
EQ2/source/WorldServer/Housing/HousingPackets.cpp

@@ -7,14 +7,14 @@ extern ConfigReader configReader;
 extern World world;
 extern WorldDatabase database;
 
-void ClientPacketFunctions::SendHousePurchace(Client* client, HouseZone* hz, int32 spawnID) {
+void ClientPacketFunctions::SendHousePurchase(Client* client, HouseZone* hz, int32 spawnID) {
 	PacketStruct* packet = configReader.getStruct("WS_PlayerHousePurchase", client->GetVersion());
 	if (packet) {
 		packet->setDataByName("house_name", hz->name.c_str());
 		packet->setDataByName("house_id", hz->id);
 		packet->setDataByName("spawn_id", spawnID);
 		packet->setDataByName("purchase_coins", hz->cost_coin);
-		packet->setDataByName("purchace_status", hz->cost_status);
+		packet->setDataByName("purchase_status", hz->cost_status);
 		packet->setDataByName("upkeep_coins", hz->upkeep_coin);
 		packet->setDataByName("upkeep_status", hz->upkeep_status);
 		packet->setDataByName("vendor_vault_slots", hz->vault_slots);

+ 1 - 1
EQ2/source/WorldServer/Widget.cpp

@@ -415,7 +415,7 @@ void Widget::HandleUse(Client* client, string command, int8 overrideWidgetType){
 		}
 		else {
 			if (hz)
-				ClientPacketFunctions::SendHousePurchace(client, hz, 0);
+				ClientPacketFunctions::SendHousePurchase(client, hz, 0);
 		}
 	}
 	else if (client && strncasecmp("access", command.c_str(), 6) == 0 && GetZone()->GetInstanceType() > 0) {

+ 1 - 1
EQ2/source/WorldServer/WorldDatabase.h

@@ -510,7 +510,7 @@ public:
 	int64				AddPlayerHouse(int32 char_id, int32 house_id, int32 instance_id, int32 upkeep_due);
 	void				SetHouseUpkeepDue(int32 char_id, int32 house_id, int32 instance_id, int32 upkeep_due);
 	void				RemovePlayerHouse(int32 char_id, int32 house_id);
-	void				UpdateHouseEscrow(int32 house_id, int32 instance_id, int64 amount);
+	void				UpdateHouseEscrow(int32 house_id, int32 instance_id, int64 amount_coins, int32 amount_status);
 	void				LoadPlayerHouses();
 	void				LoadDeposits(PlayerHouse* house);
 	void				LoadHistory(PlayerHouse* house);

+ 42 - 7
EQ2/source/WorldServer/client.cpp

@@ -1949,9 +1949,14 @@ bool Client::HandlePacket(EQApplicationPacket* app) {
 					safe_delete(packet);
 					break;
 				}
-
-				if ((!hz->upkeep_coin && !hz->cost_coin) || player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)) // TODO: Need option to take from bank if player does not have enough coin on them
+				int32 status_req = hz->upkeep_status + hz->cost_status;
+				int32 available_status = player->GetInfoStruct()->get_status_points();
+				if (status_req <= available_status && 
+				((!hz->upkeep_coin && !hz->cost_coin) || 
+				( (hz->upkeep_coin || hz->cost_coin) && player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)))
+				) // TODO: Need option to take from bank if player does not have enough coin on them
 				{
+					player->GetInfoStruct()->subtract_status_points(status_req);
 					ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
 					int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
 					int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
@@ -2026,9 +2031,26 @@ bool Client::HandlePacket(EQApplicationPacket* app) {
 						break;
 					}
 				}
+				bool escrowChange = false;
+				int64 statusReq = hz->upkeep_status;
+				int64 tmpRecoverStatus = 0;
+				if(ph->escrow_status && statusReq >= ph->escrow_status )
+				{
+					escrowChange = true;
+					tmpRecoverStatus = ph->escrow_status;
+					statusReq -= ph->escrow_status;
+					ph->escrow_status = 0;
+				}
+				else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
+				{
+					escrowChange = true;
+					ph->escrow_status -= statusReq;
+					tmpRecoverStatus = statusReq;
+					statusReq = 0;
+				}
+
 				int64 coinReq = hz->upkeep_coin;
 				int64 tmpRecoverCoins = 0;
-				bool escrowChange = false;
 				if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
 				{
 					escrowChange = true;
@@ -2041,15 +2063,26 @@ bool Client::HandlePacket(EQApplicationPacket* app) {
 					escrowChange = true;
 					// more than enough in escrow, subtract and make our cost 0!
 					ph->escrow_coins -= coinReq;
+					tmpRecoverCoins = coinReq;
 					coinReq = 0;
 				}
-				// TODO: Need support for upkeep_status, but alas status_points are not implemented!
-				if (!coinReq || coinReq && player->RemoveCoins(coinReq)) // TODO: Need option to take from bank if player does not have enough coin on them
+
+				int32 available_status_points = player->GetInfoStruct()->get_status_points();
+				if(!statusReq || (statusReq && statusReq <= available_status_points))
+				{
+					if(coinReq && player->RemoveCoins(coinReq))
+						coinReq = 0;
+					
+					if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
+						statusReq = 0;
+				}
+				
+				if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
 				{
 					database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
 
 					if (escrowChange)
-						database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins);
+						database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
 
 					ph->upkeep_due = upkeep_due;
 					database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
@@ -2062,8 +2095,10 @@ bool Client::HandlePacket(EQApplicationPacket* app) {
 					// recover the escrow we were going to use but could not spend due to lack of funds
 					if (tmpRecoverCoins)
 						ph->escrow_coins += tmpRecoverCoins;
+					if(tmpRecoverStatus)
+						ph->escrow_status += tmpRecoverStatus;
 
-					SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to pay for upkeep.");
+					SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money  or status to pay for upkeep.");
 					PlaySound("buy_failed");
 				}
 			}