Loading...   


	// #2: figure out things that affect the player dying and mark them dead
	//

	InterruptSpell();
	SetPet(0);
	SetHorseId(0);
	dead = true;
	dead_timer.Start(5000, true);
	float pvp_points = 6.0;

	if (other != NULL)
	{
		int linkBuffSlot = other->GetBuffSlotFromType(SE_DamageRedirect);
		if(linkBuffSlot > 0 && linkBuffSlot < 26) {
			other->DropDelayTarget(linkBuffSlot);
		}
		if (other->IsNPC())
			parse->Event(EVENT_SLAY, other->GetNPCTypeID(), 0, other->CastToNPC(), this);
		//Lieka Edit:  PvP death message	
		if(other->IsPet() && other->GetOwner()->IsClient())   //Null: display message if pet killed player
			other = other->GetOwner();
		if(other->IsClient()) {
			char errbuf[MYSQL_ERRMSG_SIZE];
			char *query = 0;
			if(killerName != NULL) {
				database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO wiretaps(_from, _to, message, from_ip) VALUES ('%s', '%s', 'PvP: %s <%s> killed by %s in %s!', '%s');", killerName, this->GetName(), this->GetName(),guild_mgr.GetGuildName(this->GuildID()),killerName, zone->GetShortName(), long2ip(other->CastToClient()->GetIP()).c_str()), errbuf);
				worldserver.SendEmoteMessage(0,0,0,15,"PvP News: %s <%s> has been slain by %s in %s!",this->GetName(),guild_mgr.GetGuildName(this->GuildID()),killerName, zone->GetLongName());
			}else{
				database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO wiretaps(_from, _to, message, from_ip) VALUES ('%s', '%s', 'PvP: %s <%s> killed by %s <%s> in %s!', '%s');", other->GetName(), this->GetName(), this->GetName(),guild_mgr.GetGuildName(this->GuildID()),other->GetName(),guild_mgr.GetGuildName((other->CastToClient())->GuildID()), zone->GetShortName(), long2ip(other->CastToClient()->GetIP()).c_str()), errbuf);
				worldserver.SendEmoteMessage(0,0,0,15,"PvP News: %s <%s> has been slain by %s <%s> in %s!",this->GetName(),guild_mgr.GetGuildName(this->GuildID()),other->GetName(),guild_mgr.GetGuildName((other->CastToClient())->GuildID()), zone->GetLongName());
			}
			//Null: PvP Leaderboard updates
			//Message(0, "1");
			if(this->GetLevel() >= 50 && other->GetLevel() >= 50 && !zone->IsCity(zone->GetZoneID() )) {
				/*MYSQL_RES *result;
				MYSQL_ROW row;
				Message(0, "2");
				database.RunQuery(query, MakeAnyLenString(&query, "SELECT pvp_points FROM character_ where id = %i;", this->GuildID()), errbuf, &result);
				row = mysql_fetch_row(result);
				Message(0, "%s", row[0]);
				if(atof(row[0]) < 6) {
					Message(0, "4");
					pvp_points = 1;
				}
				Message(0, "5");*/

				if (this->GetName() == other->GetName()) {
					database.RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET pvp_points = (pvp_points - 6) WHERE id = %i;", this->CharacterID()), errbuf);
				}else{
					if(other->IsGrouped() && pvp_points != 1) {
						Group* pvp_group = entity_list.GetGroupByClient(other->CastToClient());
						if(pvp_group != 0) {
						pvp_points = pvp_points / pvp_group->GroupCount();
						for(int i=0;i<6;i++) { // Doesnt work right, needs work
							if(pvp_group->members[i] != NULL) {
								database.RunQuery(query, MakeAnyLenString(&query, "UPDATE guilds SET pvp_points = (pvp_points + %f) WHERE id = %i;", pvp_points, pvp_group->members[i]->CastToClient()->GuildID()), errbuf);
								database.RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET pvp_points = (pvp_points + %f) WHERE id = %i;", pvp_points, pvp_group->members[i]->CastToClient()->CharacterID()), errbuf);
							}
						}
						
						database.RunQuery(query, MakeAnyLenString(&query, "UPDATE guilds SET pvp_points = (pvp_points - 6) WHERE id = %i;", this->GuildID()), errbuf);
						database.RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET pvp_points = (pvp_points - 6) WHERE id = %i;", this->CharacterID()), errbuf);
						}
					}else{
							database.RunQuery(query, MakeAnyLenString(&query, "UPDATE guilds SET pvp_points = (pvp_points + %f) WHERE id = %i;", pvp_points, other->CastToClient()->GuildID()), errbuf);
							database.RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET pvp_points = (pvp_points + %f) WHERE id = %i;",pvp_points, other->CastToClient()->CharacterID()), errbuf);
							database.RunQuery(query, MakeAnyLenString(&query, "UPDATE guilds SET pvp_points = (pvp_points - %f) WHERE id = %i;",pvp_points, this->GuildID()), errbuf);
							database.RunQuery(query, MakeAnyLenString(&query, "UPDATE character_ SET pvp_points = (pvp_points - %f) WHERE id = %i;",pvp_points, this->CharacterID()), errbuf);
						
					}
				}
			}
			safe_delete_array(query);
		//End Lieka Edit
		if(other->IsClient() && (IsDueling() || other->CastToClient()->IsDueling())) {
			SetDueling(false);
			SetDuelTarget(0);
			if (other->IsClient() && other->CastToClient()->IsDueling() && other->CastToClient()->GetDuelTarget() == GetID())
			{
				//if duel opponent killed us...
				other->CastToClient()->SetDueling(false);
				other->CastToClient()->SetDuelTarget(0);
				entity_list.DuelMessage(other,this,false);
			} else {
				//otherwise, we just died, end the duel.
				Mob* who = entity_list.GetMob(GetDuelTarget());
				if(who && who->IsClient()) {
					who->CastToClient()->SetDueling(false);
					who->CastToClient()->SetDuelTarget(0);
				}
			}
		}
		}
	}

	entity_list.RemoveFromTargets(this);
	hate_list.RemoveEnt(this);
	
	if(isgrouped) {
		Group *g = GetGroup();
		if(g)
			g->MemberZoned(this);
	}
	

Raw Paste Data