 DROP TABLE TblCastleInfo
GO

CREATE TABLE [TblCastleInfo] (
	[nCastleID] [int] IDENTITY (1, 1) NOT NULL ,
	[tnNation] [tinyint] NULL ,
	[tnZone] [tinyint] NULL ,
	[tnChannel] [tinyint] NULL ,
	[tnName] [tinyint] NULL ,
	[tnSiegeCount] [tinyint] NULL ,
	[tnInvincibleCount] [tinyint] NULL ,
	[snTotalSiegeCount] [smallint] NULL ,
	[nTotalTaxMoney] [int] NULL ,
	[bRight] [varbinary] (10) NULL ,
	[fPosInX] [real] NULL ,
	[fPosInY] [real] NULL ,
	[fPosInZ] [real] NULL ,
	[fPosOutX] [real] NULL ,
	[fPosOutY] [real] NULL ,
	[fPosOutZ] [real] NULL ,
	[snItemID] [smallint] NULL ,
	[tnItemNum] [tinyint] NULL 
) ON [PRIMARY]
GO


INSERT INTO TblCastleInfo(tnNation, tnZone, tnChannel, tnName, tnSiegeCount, tnInvincibleCount, snTotalSiegeCount, nTotalTaxMoney, bRight, fPosInX, fPosInY, fPosInZ, fPosOutX, fPosOutY, fPosOutZ, snItemID, tnItemNum)
VALUES (0, 16, 0, 1, 0, 0, 0, 0, 0x03030303030303030303, 0.0, 100.0, 0.0, 0.0, 100.0, 0.0, 0, 0)
GO
INSERT INTO TblCastleInfo(tnNation, tnZone, tnChannel, tnName, tnSiegeCount, tnInvincibleCount, snTotalSiegeCount, nTotalTaxMoney, bRight, fPosInX, fPosInY, fPosInZ, fPosOutX, fPosOutY, fPosOutZ, snItemID, tnItemNum)
VALUES (0, 16, 1, 1, 0, 0, 0, 0, 0x03030303030303030303, 0.0, 100.0, 0.0, 0.0, 100.0, 0.0, 0, 0)
GO


DROP TABLE TblCastleCreatureInfo
GO

CREATE TABLE [TblCastleCreatureInfo] (
	[nCreatureID] [int] IDENTITY (1, 1) NOT NULL ,
	[nCastleID] [int] NULL ,
	[nOwnerID] [int] NULL,
	[nHP] [int] NULL ,
	[snObjectType] [smallint] NULL ,
	[fDirection] [real] NULL ,
	[tnState] [tinyint] NULL ,
	[tnSubState] [tinyint] NULL ,
	[tnUpgradeStep] [tinyint] NULL ,
	[tnUpgradeType] [tinyint] NULL ,
	[RemainTime] [smalldatetime] NULL ,
	[LastUseTime] [smalldatetime] NULL,
	[fPosX] [real] NULL ,
	[fPosY] [real] NULL ,
	[fPosZ] [real] NULL ,
	 PRIMARY KEY  CLUSTERED 
	(
		[nCreatureID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (1, 0, 59973, 5000, 3.1670001, 0, 1, 1, 0, getdate(), getdate(), 2034.0, 138.133, 3004.5)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (1, 0, 100, 5324, 3.1340001, 0, 2, 0, 0, getdate(), getdate(), 2034.5, 100.0, 2956.0)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (1, 0, 100, 5433, 0.76999998, 0, 0, 0, 0, getdate(), getdate(), 1987.5, 118.1, 2952.0)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (1, 0, 100, 5433, 0.0, 0, 0, 0, 0, getdate(), getdate(), 2018.0, 118.1, 2951.5)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (1, 0, 100, 5433, 5.48, 0, 0, 0, 0, getdate(), getdate(), 2080.0, 118.1, 2952.0)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (1, 0, 100, 5433, 0.0, 0, 0, 0, 0, getdate(), getdate(), 2050.0, 118.1, 2952.0)

GO

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (2, 0, 59973, 5000, 3.1670001, 0, 1, 1, 0, getdate(), getdate(), 2034.0, 138.133, 3004.0)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (2, 0, 100, 5324, 3.1340001, 0, 2, 0, 0, getdate(), getdate(), 2034.0, 100.0, 2956.0)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (2, 0, 100, 5433, 0.76999998, 0, 0, 0, 0, getdate(), getdate(), 1987.5, 118.1, 2952.0)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (2, 0, 100, 5433, 0.0, 0, 0, 0, 0, getdate(), getdate(), 2018.0, 118.1, 2951.5)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (2, 0, 100, 5433, 5.48, 0, 0, 0, 0, getdate(), getdate(), 2080.0, 118.1, 2952.0)

INSERT INTO TblCastleCreatureInfo(nCastleID, nOwnerID, nHP, snObjectType, fDirection, tnState, tnSubState, tnUpgradeStep, tnUpgradeType, RemainTime, LastUseTime, fPosX, fPosY, fPosZ)
VALUES (2, 0, 100, 5433, 0.0, 0, 0, 0, 0, getdate(), getdate(), 2050.0, 118.1, 2952.0)


GO


SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



ALTER PROC USPCastleUpdate @nCastleID INT,@tnNation TINYINT,@tnSiegeCount TINYINT,
	@tnInvincibleCount TINYINT,@snTotalSiegeCount SMALLINT,@nTotalTaxMoney INT,
	@snItemID SMALLINT,@tnItemNum TINYINT
AS
	SET NOCOUNT ON

	DECLARE @RETURN INT

	UPDATE TblCastleInfo
	SET tnNation = @tnNation,tnSiegeCount = @tnSiegeCount,tnInvincibleCount = @tnInvincibleCount,
		snTotalSiegeCount = @snTotalSiegeCount,nTotalTaxMoney = @nTotalTaxMoney,
		snItemID = @snItemID,tnItemNum = @tnItemNum
	WHERE nCastleID = @nCastleID
	
	SET @RETURN = @@ROWCOUNT

	SELECT @RETURN




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO