Browse Source

Fix #422 - switching from bow attack to melee when in range and use combat ability, fixed consuming food after drink not working

Emagi 1 year ago
parent
commit
751ee63d47

+ 8 - 1
EQ2/source/WorldServer/Combat.cpp

@@ -458,8 +458,15 @@ bool Entity::SpellAttack(Spawn* victim, float distance, LuaSpell* luaspell, int8
 		{
 			if (victim->IsNPC())
 				((NPC*)victim)->AddHate(this, 5);
-			else
+			else {
+				Client* client = 0;
+				if(IsPlayer())
+					client = GetZone()->GetClientBySpawn(this);
+				if(client) {
+					client->GetPlayer()->InCombat(true, client->GetPlayer()->GetRangeAttack());
+				}
 				InCombat(true);
+			}
 		}
 	}
 

+ 21 - 16
EQ2/source/WorldServer/Commands/Commands.cpp

@@ -3128,6 +3128,11 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 
 			break;
 		}
+		case COMMAND_GROUP: {
+			if(sep && sep->arg[0])
+				printf("Group: %s\n",sep->argplus[0]);
+			break;
+		}
 		case COMMAND_GROUPSAY:{
 			GroupMemberInfo* gmi = client->GetPlayer()->GetGroupMemberInfo();
 			if(sep && sep->arg[0] && gmi)
@@ -4061,6 +4066,7 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 		case COMMAND_ATTACK:
 		case COMMAND_AUTO_ATTACK:{
 			int8 type = 1;
+			bool update = false;
 			Player* player = client->GetPlayer();
 			if(!player)
 				break;
@@ -4075,6 +4081,7 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 				if(incombat)
 					client->SimpleMessage(CHANNEL_GENERAL_COMBAT, "You stop fighting.");
 					player->StopCombat(type);
+					update = true;
 			}
 			else {
 				if(type == 2){
@@ -4082,24 +4089,31 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 					if(incombat && player->GetRangeAttack()){
 						player->StopCombat(type);
 						client->SimpleMessage(CHANNEL_GENERAL_COMBAT, "You stop fighting.");
+						update = true;
 					}
 					else{
 						player->SetRangeAttack(true);
 						player->InCombat(true, true);
 						client->SimpleMessage(CHANNEL_GENERAL_COMBAT, "You start fighting.");
+						update = true;
 					}
 				}
 				else {
 					player->InCombat(false, true);
 					player->SetRangeAttack(false);
 					player->InCombat(true);
-					if(!incombat)
+					if(!incombat) {
 						client->SimpleMessage(CHANNEL_GENERAL_COMBAT, "You start fighting.");
+						update = true;
+					}
 				}
 				/*else
 					client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You cannot attack that!");*/
 			}
-			player->SetCharSheetChanged(true);
+			
+			if(update) {
+				player->SetCharSheetChanged(true);
+			}
 			break;
 								}
 		case COMMAND_DEPOP:{
@@ -9124,11 +9138,9 @@ void Commands::Command_Toggle_AutoConsume(Client* client, Seperator* sep)
 			}
 		}
 
-
-		if(slot == 22 && player->GetSpellEffectBySpellType(SPELL_TYPE_FOOD))
-			return;
-		else if (player->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
+		if(!client->CheckConsumptionAllowed(slot, false))
 			return;
+		
 		Item* item = player->GetEquipmentList()->GetItem(slot);
 		if(item)
 			client->ConsumeFoodDrink(item, slot);
@@ -11181,17 +11193,10 @@ void Commands::Command_ConsumeFood(Client* client, Seperator* sep) {
 		Player* player = client->GetPlayer();
 		int8 slot = atoi(sep->arg[0]);
 		Item* item = player->GetEquipmentList()->GetItem(slot);
-		if(slot == 22 && player->GetSpellEffectBySpellType(SPELL_TYPE_FOOD))
-		{
-			client->Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
-			return;
-		}
-		else if (player->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
-		{
-			client->Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
-			return;
+
+		if(client->CheckConsumptionAllowed(slot)) {
+			client->ConsumeFoodDrink(item, slot);
 		}
-		client->ConsumeFoodDrink(item, slot);
 	}
 }
 

+ 2 - 2
EQ2/source/WorldServer/Entity.h

@@ -223,8 +223,8 @@ struct InfoStruct{
 		alignment_ = 0;
 		pet_id_ = 0;
 		pet_name_ = std::string("");
-		pet_health_pct_ = 0;
-		pet_power_pct_ = 0;
+		pet_health_pct_ = 0.0f;
+		pet_power_pct_ = 0.0f;
 		pet_movement_ = 0;
 		pet_behavior_ = 0;
 		vision_ = 0;

+ 17 - 2
EQ2/source/WorldServer/SpellProcess.cpp

@@ -667,8 +667,23 @@ void SpellProcess::SendFinishedCast(LuaSpell* spell, Client* client){
 			TakeSavagery(spell);
 			AddDissonance(spell);
 			AddConcentration(spell);
-			if (client && spell->spell && !spell->spell->GetSpellData()->friendly_spell)
-				client->GetPlayer()->InCombat(true);
+			if (client && spell->spell && !spell->spell->GetSpellData()->friendly_spell) {
+				if(!client->GetPlayer()->EngagedInCombat()) {
+					client->GetPlayer()->InCombat(true, false);
+					client->GetPlayer()->SetRangeAttack(false);
+				}
+				else if(client->GetPlayer()->EngagedInCombat() && 
+						client->GetPlayer()->GetRangeAttack() && spell->spell->GetSpellData()->type == SPELL_BOOK_TYPE_COMBAT_ART) {
+					Spawn* target = client->GetPlayer()->GetZone()->GetSpawnByID(spell->initial_target);
+					if(target) {
+						float distance = client->GetPlayer()->GetDistance(target);
+						if(distance <= rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat()) {
+							client->GetPlayer()->InCombat(true, false);
+							client->GetPlayer()->SetRangeAttack(false);
+						}
+					}
+				}
+			}
 			if(client && spell->caster)
 				client->CheckPlayerQuestsSpellUpdate(spell->spell);
 		}

+ 30 - 0
EQ2/source/WorldServer/client.cpp

@@ -11647,5 +11647,35 @@ bool Client::SetPetName(const char* petName) {
 	}
 
 	GetPlayer()->GetInfoStruct()->set_pet_name(petName);
+	return true;
+}
+
+bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
+	switch(slot) {
+		case EQ2_FOOD_SLOT: {
+			if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
+				if(send_message) {
+					Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
+				}
+				return false;
+			}
+			break;
+		}
+		case EQ2_DRINK_SLOT: {
+			if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
+			{
+				if(send_message) {
+					Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
+				}
+				return false;
+			}
+			break;
+		}
+		default: {
+			return false;
+			break;
+		}
+	}
+	
 	return true;
 }

+ 2 - 0
EQ2/source/WorldServer/client.h

@@ -578,6 +578,8 @@ public:
 	
 	void	HandleDialogSelectMsg(int32 conversation_id, int32 response_index);
 	bool	SetPetName(const char* name);
+	
+	bool	CheckConsumptionAllowed(int16 slot, bool send_message = true);
 private:
 	void    SavePlayerImages();
 	void	SkillChanged(Skill* skill, int16 previous_value, int16 new_value);