View Single Post
Old 04.07.2007, 13:07   #1
madar
Архивный участник
 
Join Date: Dec 2005
Posts: 156
Default [SHARE] Hero Skill acquire

didnt tested yet because our server is still run in test phrase so dont have enough ppl to test it, if it works ill write a script that will delete those skills from players that are not heroes (after competition)

Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE dbo.lin_NominateHeroes
(
@now_season INT,
@new_step INT,
@new_season_start_time INT
)
AS
SET NOCOUNT ON

UPDATE user_nobless
SET hero_type = 0

CREATE TABLE #hero_candidate (char_id INT, main_class INT, match_count INT, olympiad_point INT)
INSERT INTO #hero_candidate 
	SELECT un.char_id, ud.subjob0_class, un.match_count, un.olympiad_point 
	FROM user_nobless un, user_data ud 
	WHERE un.char_id = ud.char_id AND un.match_count >= 5 AND un.olympiad_win_count >= 1

CREATE TABLE #highest_score (main_class INT, olympiad_point INT, match_count INT)

DECLARE @hero_candidate_class INT
DECLARE hero_candidate_cursor CURSOR FOR
SELECT DISTINCT main_class FROM #hero_candidate

OPEN hero_candidate_cursor

FETCH NEXT FROM hero_candidate_cursor INTO @hero_candidate_class

WHILE @@FETCH_STATUS = 0
BEGIN

INSERT INTO #highest_score
	SELECT TOP 1 main_class, olympiad_point, match_count 
	FROM #hero_candidate 
	WHERE main_class = @hero_candidate_class
	ORDER BY olympiad_point DESC, match_count DESC

	FETCH NEXT FROM hero_candidate_cursor INTO @hero_candidate_class
END

CLOSE hero_candidate_cursor
DEALLOCATE hero_candidate_cursor

CREATE TABLE #highest_score_nobless (char_id INT, main_class INT)
INSERT INTO #highest_score_nobless
	SELECT c.char_id, c.main_class FROM #hero_candidate c, #highest_score s
		WHERE c.main_class = s.main_class AND c.olympiad_point = s.olympiad_point AND c.match_count = s.match_count

CREATE TABLE #hero (char_id INT, main_class INT)
INSERT INTO #hero
	SELECT char_id, main_class  FROM #highest_score_nobless WHERE main_class IN (SELECT main_class FROM #highest_score_nobless GROUP BY main_class HAVING COUNT(main_class) = 1)

UPDATE user_nobless
SET hero_type = 1, win_count = win_count+1
WHERE char_id IN (SELECT char_id FROM #hero)

UPDATE user_nobless
SET previous_point = olympiad_point

UPDATE user_nobless
SET olympiad_point = 0, match_count = 0, olympiad_win_count = 0, olympiad_lose_count = 0

INSERT INTO olympiad_result
	SELECT @now_season, main_class, char_id, olympiad_point, match_count FROM #hero_candidate

INSERT INTO olympiad
	(step, season_start_time) VALUES (@new_step, @new_season_start_time)

INSERT INTO user_skill (char_id, skill_id, skill_lev, to_end_time)
	SELECT char_id, "395", "1", "0"
	FROM user_nobless
	WHERE hero_type = 1

INSERT INTO user_skill (char_id, skill_id, skill_lev, to_end_time)
	SELECT char_id, "396", "1", "0"
	FROM user_nobless
	WHERE hero_type = 1

INSERT INTO user_skill (char_id, skill_id, skill_lev, to_end_time)
	SELECT char_id, "1374", "1", "0"
	FROM user_nobless
	WHERE hero_type = 1

INSERT INTO user_skill (char_id, skill_id, skill_lev, to_end_time)
	SELECT char_id, "1375", "1", "0"
	FROM user_nobless
	WHERE hero_type = 1

INSERT INTO user_skill (char_id, skill_id, skill_lev, to_end_time)
	SELECT char_id, "1376", "1", "0"
	FROM user_nobless
	WHERE hero_type = 1

SELECT @@IDENTITY
madar is offline