Procházet zdrojové kódy

Starting code for boats, will get cleaned up more soon

IsTransportSpawn(Spawn)
GetSpawnByRailID(railid)
GetSpawnListByRailID(railid)
Image před 3 roky
rodič
revize
f592c1aa90

+ 51 - 2
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -523,6 +523,26 @@ int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
 	return 0;
 }
 
+int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
+	if (!lua_interface)
+		return 0;
+	Spawn* spawn = lua_interface->GetSpawn(state);
+	sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
+	if (spawn) {
+		vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
+		if (spawns.size() > 0) {
+			vector<Spawn*>* spawnList = new vector<Spawn*>();
+			vector<Spawn*>::iterator itr;
+			for (itr = spawns.begin(); itr != spawns.end(); itr++) {
+				spawnList->push_back(*itr);
+			}
+			lua_interface->SetSpawnListValue(state, spawnList);
+			return 1;
+		}
+	}
+	return 0;
+}
+
 int EQ2Emu_lua_GetVariableValue(lua_State* state) {
 	if (!lua_interface)
 		return 0;
@@ -1166,14 +1186,15 @@ int EQ2Emu_lua_Shout(lua_State* state) {
 	Spawn* spawn = lua_interface->GetSpawn(state);
 	string message = lua_interface->GetStringValue(state, 2);
 	Spawn* player = lua_interface->GetSpawn(state, 3);
+	float dist = lua_interface->GetFloatValue(state, 4);
 	if (spawn && message.length() > 0) {
 		Client* client = 0;
 		if (player && player->IsPlayer())
 			client = spawn->GetZone()->GetClientBySpawn(player);
 		if (client)
-			spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
+			spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
 		else
-			spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
+			spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
 	}
 	lua_interface->ResetFunctionStack(state);
 	return 0;
@@ -7452,6 +7473,20 @@ int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
 	return 0;
 }
 
+int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
+	if (!lua_interface)
+		return 0;
+	Spawn* spawn = lua_interface->GetSpawn(state);
+
+	if (!spawn) {
+		lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
+		return 0;
+	}
+
+	lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
+	return 1;
+}
+
 int EQ2Emu_lua_GetSkillValue(lua_State* state) {
 	if (!lua_interface)
 		return 0;
@@ -12144,4 +12179,18 @@ int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
 		return 1;
 	}
 	return 0;
+}
+
+int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
+	ZoneServer* zone = lua_interface->GetZone(state);
+	sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
+
+	if (zone) {
+		Spawn* spawn = zone->GetTransportByRailID(rail_id);
+		if (spawn) {
+			lua_interface->SetSpawnValue(state, spawn);
+			return 1;
+		}
+	}
+	return 0;
 }

+ 4 - 0
EQ2/source/WorldServer/LuaFunctions.h

@@ -117,6 +117,7 @@ int EQ2Emu_lua_CreateSpawnList(lua_State* state);
 int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state);
 int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state);
 int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state); 
+int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state); 
 int EQ2Emu_lua_GetVariableValue(lua_State* state);
 int EQ2Emu_lua_GetCoinMessage(lua_State* state);
 int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state);
@@ -232,6 +233,7 @@ int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state);
 int EQ2Emu_lua_HasRecipeBook(lua_State* state);
 int EQ2Emu_lua_SpawnMove(lua_State* state);
 int EQ2Emu_lua_AddTransportSpawn(lua_State* state);
+int EQ2Emu_lua_IsTransportSpawn(lua_State* state);
 int	EQ2Emu_lua_PerformCameraShake(lua_State* state);
 
 //Quest Stuff
@@ -581,4 +583,6 @@ int EQ2Emu_lua_StopMovement(lua_State* state);
 
 int EQ2Emu_lua_GetArrowColor(lua_State* state);
 int EQ2Emu_lua_GetTSArrowColor(lua_State* state);
+
+int EQ2Emu_lua_GetSpawnByRailID(lua_State* state);
 #endif

+ 4 - 0
EQ2/source/WorldServer/LuaInterface.cpp

@@ -917,6 +917,7 @@ void LuaInterface::RegisterFunctions(lua_State* state) {
 	lua_register(state, "AddSpawnToSpawnList", EQ2Emu_lua_AddSpawnToSpawnList);
 	lua_register(state, "RemoveSpawnFromSpawnList", EQ2Emu_lua_RemoveSpawnFromSpawnList);
 	lua_register(state, "GetSpawnListBySpawnID", EQ2Emu_lua_GetSpawnListBySpawnID);
+	lua_register(state, "GetSpawnListByRailID", EQ2Emu_lua_GetSpawnListByRailID);
 	lua_register(state, "GetSpawnFromList", EQ2Emu_lua_GetSpawnFromList);
 	lua_register(state, "GetSpawnListSize", EQ2Emu_lua_GetSpawnListSize);	
 	lua_register(state, "SetFactionID", EQ2Emu_lua_SetFactionID);
@@ -1135,6 +1136,7 @@ void LuaInterface::RegisterFunctions(lua_State* state) {
 	lua_register(state, "SetQuestYellow", EQ2Emu_lua_SetQuestYellow);
 	lua_register(state, "CanReceiveQuest", EQ2Emu_lua_CanReceiveQuest);
 	lua_register(state, "AddTransportSpawn", EQ2Emu_lua_AddTransportSpawn);
+	lua_register(state, "IsTransportSpawn", EQ2Emu_lua_IsTransportSpawn);
 
 	// Option window
 	lua_register(state, "CreateOptionWindow", EQ2Emu_lua_CreateOptionWindow);
@@ -1412,6 +1414,8 @@ void LuaInterface::RegisterFunctions(lua_State* state) {
 	
 	lua_register(state, "GetArrowColor", EQ2Emu_lua_GetArrowColor);
 	lua_register(state, "GetTSArrowColor", EQ2Emu_lua_GetTSArrowColor);
+	
+	lua_register(state, "GetSpawnByRailID", EQ2Emu_lua_GetSpawnByRailID);
 }
 
 void LuaInterface::LogError(const char* error, ...)  {

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

@@ -3563,8 +3563,15 @@ void Player::PrepareIncomingMovementPacket(int32 len, uchar* data, int16 version
 		pos_packet_speed = speed;
 		grid_id = appearance.pos.grid_id;
 	}
-	else if (GetBoatSpawn() > 0)
+	else if (GetBoatSpawn() > 0 && !lift_cooldown.Enabled())
+	{
+		lift_cooldown.Start(100, true);
+	}
+	else if(lift_cooldown.Check())
+	{
+		printf("Disable boat\n");
 		SetBoatSpawn(0);
+	}
 
 	if (!IsResurrecting() && !GetBoatSpawn())
 	{

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

@@ -1123,6 +1123,7 @@ private:
 	map<Spawn*, int8>	player_removed_spawns;
 
 	bool all_spells_locked;
+	Timer lift_cooldown;
 };
 #pragma pack()
 #endif

+ 6 - 4
EQ2/source/WorldServer/Spawn.cpp

@@ -125,6 +125,8 @@ Spawn::Spawn(){
 	pause_timer.Disable();
 	m_SpawnMutex.SetName("Spawn::SpawnMutex");
 	appearance_equipment_list.SetAppearanceType(1);
+	is_transport_spawn = false;
+	rail_id = 0;
 }
 
 Spawn::~Spawn(){
@@ -2555,7 +2557,7 @@ void Spawn::InitializeInfoPacketData(Player* spawn, PacketStruct* packet) {
 
 		// if this is either a boat or lift let the client be manipulated by the object
 		// doesn't work for DoF client version 546
-		if (appearance.icon == 28 || appearance.icon == 12)
+		if (this->GetModelType() == 7941 || appearance.icon == 28 || appearance.icon == 12)
 		{
 			temp_activity_status += ACTIVITY_STATUS_ISTRANSPORT_1188;
 		}
@@ -2567,7 +2569,7 @@ void Spawn::InitializeInfoPacketData(Player* spawn, PacketStruct* packet) {
 			temp_activity_status = 0xFF;
 
 		// this only partially fixes lifts in classic 283 client if you move just as the lift starts to move
-		if (appearance.icon == 28 || appearance.icon == 12)
+		if (this->GetModelType() == 7941 || appearance.icon == 28 || appearance.icon == 12)
 			packet->setDataByName("is_transport", 1);
 
 		if (MeetsSpawnAccessRequirements(spawn))
@@ -2848,7 +2850,7 @@ void Spawn::ProcessMovement(bool isSpawnListLocked){
 					}
 					// delay at target location, only need to set 1 location
 					else
-						AddRunningLocation(data->x, data->y, data->z, data->speed);
+						AddRunningLocation(data->x, data->y, data->z, data->speed, 0, true, true, "", true);
 				}
 				movement_start_time = 0;
 				resume_movement = false;
@@ -2921,7 +2923,7 @@ void Spawn::ProcessMovement(bool isSpawnListLocked){
 						}
 						// there is a delay at the next location so we only need to set it
 						else
-							AddRunningLocation(data->x, data->y, data->z, data->speed);
+							AddRunningLocation(data->x, data->y, data->z, data->speed, 0, true, true, "", true);
 
 						// reset this timer to 0 now that we are moving again
 						movement_start_time = 0;

+ 8 - 0
EQ2/source/WorldServer/Spawn.h

@@ -1207,6 +1207,11 @@ public:
 	virtual void StopMovement();
 	virtual bool PauseMovement(int32 period_of_time_ms);
 	virtual bool IsPauseMovementTimerActive();
+	bool IsTransportSpawn() { return is_transport_spawn; }
+	void SetTransportSpawn(bool val) { is_transport_spawn = val; }
+	
+	sint64 GetRailID() { return rail_id; }
+	void SetRailID(sint64 val) { rail_id = val; }
 protected:
 
 	bool	has_quests_required;
@@ -1306,6 +1311,9 @@ private:
 
 	RegionMap* region_map;
 	Map* current_map;
+
+	bool is_transport_spawn;
+	sint64 rail_id;
 };
 
 #endif

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

@@ -7419,7 +7419,7 @@ void WorldDatabase::LoadCharacterSpellEffects(int32 char_id, Client* client, int
 		if(!spell)
 		{
 			LogWrite(LUA__ERROR, 0, "LUA", "WorldDatabase::LoadCharacterSpellEffects: GetSpell(%u, %u), spell could not be found!", spell_id, tier);
-			Spell* spell = master_spell_list.GetSpell(spell_id, 0);
+			spell = master_spell_list.GetSpell(spell_id, 0);
 			if(spell)
 				LogWrite(LUA__WARNING, 0, "LUA", "WorldDatabase::LoadCharacterSpellEffects: GetSpell(%u, %u), identified tier 0 as replacement since the GetSpell failed!", spell_id, tier);
 			else

+ 36 - 0
EQ2/source/WorldServer/zoneserver.cpp

@@ -6244,6 +6244,7 @@ void ZoneServer::AddTransportSpawn(Spawn* spawn){
 		return;
 	MTransportSpawns.writelock(__FUNCTION__, __LINE__);
 	transport_spawns.push_back(spawn->GetID());
+	spawn->SetTransportSpawn(true);
 	MTransportSpawns.releasewritelock(__FUNCTION__, __LINE__);
 }
 
@@ -6274,6 +6275,24 @@ Spawn* ZoneServer::GetClosestTransportSpawn(float x, float y, float z){
 	return closest_spawn;
 }
 
+Spawn* ZoneServer::GetTransportByRailID(sint64 rail_id){
+	Spawn* spawn = 0;
+	Spawn* closest_spawn = 0;
+	MTransportSpawns.readlock(__FUNCTION__, __LINE__);
+	vector<int32>::iterator itr = transport_spawns.begin();
+	while(itr != transport_spawns.end()){
+		spawn = GetSpawnByID(*itr);
+		if(spawn && spawn->GetRailID() == rail_id){
+			closest_spawn = spawn;
+			break;
+		}
+		itr++;
+	}
+	MTransportSpawns.releasereadlock(__FUNCTION__, __LINE__);
+
+	return closest_spawn;
+}
+
 void ZoneServer::SetRain(float val) {
 	rain = val;
 	vector<Client*>::iterator itr;
@@ -6513,6 +6532,23 @@ vector<Spawn*> ZoneServer::GetSpawnsByID(int32 id) {
 	return tmp_list;
 }
 
+
+vector<Spawn*> ZoneServer::GetSpawnsByRailID(sint64 rail_id) {
+	vector<Spawn*> tmp_list;
+	Spawn* spawn;
+
+	map<int32, Spawn*>::iterator itr;
+	MSpawnList.readlock(__FUNCTION__, __LINE__);
+	for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
+		spawn = itr->second;
+		if (spawn && (spawn->GetRailID() == rail_id))
+			tmp_list.push_back(spawn);
+	}
+	MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
+
+	return tmp_list;
+}
+
 vector<Spawn*> ZoneServer::GetAttackableSpawnsByDistance(Spawn* caster, float distance) {
 	vector<Spawn*> ret;
 	Spawn* spawn = 0;

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

@@ -417,6 +417,7 @@ public:
 	void	ProcessWeather();
 	
 	Spawn*  GetClosestTransportSpawn(float x, float y, float z);
+	Spawn*  GetTransportByRailID(sint64 rail_id);
 	
 	void    ResurrectSpawn(Spawn* spawn, Client* client);
 
@@ -461,6 +462,7 @@ public:
 	void			PlayAnimation(Spawn* spawn, int32 visual_state, Spawn* spawn2 = 0, int8 type = 1);
 	void			AddTransportSpawn(Spawn* spawn);
 	vector<Spawn*>	GetSpawnsByID(int32 id);
+	vector<Spawn*>	GetSpawnsByRailID(sint64 rail_id);
 	bool			IsDusk() { return isDusk; }										// never used, probably meant for lua though