SQL ve XML Gibi DataSource Tipleri

MySQL’de SP cinayeti

MySQL tabanlı bir oyunun basit bir mücadelesine ait kodlarpaylaşıyorum. Kullanılmadıkça unutulan yollar için kendime not ediyorum.
[code lang=”sql”]CREATE PROCEDURE FIGHT (IN UA INT(11), IN UD INT(11), IN UAW INT(3), IN UDW INT(3))
BEGIN
DECLARE UA_ATAK INT;
DECLARE UA_POWER INT;

DECLARE UD_DEF INT;
DECLARE UD_POWER INT;
DECLARE UD_LVL INT;

SELECT atack INTO UA_ATAK FROM usr WHERE id=UA;
SELECT deffence INTO UD_DEF FROM usr WHERE id=UD;
SELECT energy INTO UA_POWER FROM usr WHERE id=UA;
SELECT energy INTO UD_POWER FROM usr WHERE id=UD;
SELECT level INTO UD_LVL FROM usr WHERE id=UD;
INSERT INTO not (nuser, nnot, ndate) values (owner ,CONCAT(‘Someone attacked to you with’,UA_ATAK,’ attack power.’),now());

CASE UAW
WHEN UAW =1 AND UDW =3 OR UAW =2 AND UDW =1 OR UAW =3 AND UDW =1 THEN
BEGIN
UPDATE usr SET umaster=UA WHERE id=UD;
CASE UA_POWER WHEN UA_POWER >=5
THEN CASE UA_ATAK WHEN UA_ATAK >= UD_DEF THEN
BEGIN
UPDATE usr SET energy=energy-5, atack=atack-UD_DEF WHERE id=UA;
CASE UD_POWER WHEN UD_POWER >=5 THEN
UPDATE usr SET energy=energy-5 WHERE id=UD;
ELSE UPDATE usr SET energy=95, level=level-1 WHERE id=UD;
END CASE;
CASE UD_DEF WHEN UD_DEF >= UA_ATAK THEN
UPDATE usr SET deffence=deffence-UA_ATAK WHERE id=UD;
ELSE UPDATE usr SET deffence=0 WHERE id=UD;
END CASE;
END;
END CASE;
WHEN UA_POWER>=10 THEN CASE UD_DEF WHEN UD_DEF > UA_ATAK THEN
BEGIN
UPDATE usr SET energy=energy-10, atack=0 WHERE id=UA;
CASE UD_POWER WHEN UD_POWER >=5 THEN
UPDATE usr SET energy=energy-5 WHERE id=UD;
ELSE UPDATE usr SET energy=95, level=level-1 WHERE id=UD;
END CASE;
CASE UD_DEF WHEN UD_DEF >= UA_ATAK THEN
UPDATE usr SET deffence=deffence-UA_ATAK WHERE id=UD;
ELSE UPDATE usr SET deffence=0 WHERE id=UD;
END CASE;
END;
END CASE;
END CASE;
END;
ELSE UPDATE usr SET energy=energy-5, atack=0 WHERE id=UA;
END CASE;
END[/code]

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir