📄 modnpc.vb.svn-base
字号:
Text = GetBetween(Code, "(", ")")
Params = Split(Text, ", ")
If Params.Length = 2 Then
Item = Params(0)
Item = Item.TrimStart(Chr(34))
Item = Item.TrimEnd(Chr(34))
Amount = Params(1)
Else
Amount = 1
Item = Text
Item = Item.TrimStart(Chr(34))
Item = Item.TrimEnd(Chr(34))
End If
GMCommands.MakeItem(Item, Amount, Player, "Npc-Give-Item")
'Take Item
Case Code.ToLower.StartsWith("take")
Dim Item, Text, Params() As String
Dim Amount As Integer
Text = GetBetween(Code, "(", ")")
Params = Split(Text, ", ")
If Params.Length = 2 Then
Item = Params(0)
Item = Item.TrimStart(Chr(34))
Item = Item.TrimEnd(Chr(34))
Amount = Params(1)
Else
Amount = 1
Item = Text
Item = Item.TrimStart(Chr(34))
Item = Item.TrimEnd(Chr(34))
End If
GMCommands.DeleteItem(Item, Amount, Player, "Npc-Take-Item")
'Npc Shout
Case Code.ToLower.StartsWith("shout")
Dim ShoutMsg As String
ShoutMsg = GetBetween(Code, "(" & Chr(34), Chr(34) & ")")
If Not ShoutMsg = "" Then
DoNpcShout(X, Y, Map, Name, ShoutMsg)
End If
'Npc World Shout
Case Code.ToLower.StartsWith("worldshout")
Dim ShoutMsg As String
ShoutMsg = GetBetween(Code, "(" & Chr(34), Chr(34) & ")")
If Not ShoutMsg = "" Then
GMCommands.GMShout(Name, ShoutMsg)
End If
End Select
End Sub
#End Region
#Region "FormatSay"
Private Function FormatSay(ByVal Say As String, ByVal Index As Integer) As String
If Say Is Nothing Then Return ""
Dim Player As clsPlayer = ObjectList(Index)
Say = Replace(Say, "<$USERNAME>", Player.Name)
Say = Replace(Say, "\", vbCrLf)
Return Say
End Function
#End Region
#End Region
End Class
#Region "LoadNpcs"
Public Sub LoadNpcs()
Dim ReadNpc As clsNpc
Dim Map As Map
Dim j, i As Integer
Dim OnMap As Boolean = False
Dim DR As System.Data.SqlClient.SqlDataReader
Dim StrSQL As String = "select * from TBL_Npc"
Dim SqlComm As New System.Data.SqlClient.SqlCommand(StrSQL, SqlConnDB)
DR = SqlComm.ExecuteReader
Do While DR.Read()
ReadNpc = New clsNpc
ReadNpc.Filename = DR.Item("Filename")
ReadNpc.Name = DR.Item("Name")
ReadNpc.Map = DR.Item("Map")
ReadNpc.X = DR.Item("X")
ReadNpc.Y = DR.Item("Y")
ReadNpc.NpcLook = DR.Item("Looks")
ReadNpc.Tax = Trim(DR.Item("Tax"))
ReadNpc.NpcId = NpcList.Count
If ObjectList.Contains(ReadNpc.NpcId) = False Then
ObjectList.Add(ReadNpc.NpcId, ReadNpc)
NpcList.Add(NpcList.Count, ReadNpc.NpcId)
End If
Dim CheckMap As Map = Maps.Item(ReadNpc.Map)
Dim Added As Boolean = False
While i < 10 And Added = False
If CheckMap.ObjectList.Contains(ReadNpc.X & "/" & ReadNpc.Y & "/" & i) = False Then
CheckMap.ObjectList.Add(ReadNpc.X & "/" & ReadNpc.Y & "/" & i, ReadNpc.NpcId)
Added = True
End If
i += 1
End While
LoadNpc(ReadNpc)
Loop
DR.Close()
SqlComm.Dispose()
DR = Nothing
SqlComm = Nothing
End Sub
#End Region
#Region "LoadNPC (Splits the Npc into different subs and adds in the #IF, #ACT, etc)"
Public Sub LoadNpc(ByVal Npc As clsNpc)
Dim DataStream, DataStream2 As System.IO.TextReader
Dim Data, Data2 As String
Dim SAY, ACT, IFStr, ElseAct, ElseSay As String
Dim i, SubNum As Integer
If IO.File.Exists(Config.NpcFolder & Npc.Filename & ".txt") = False Then
AddLog("LoadNpc", Npc.Filename & ".txt not found")
Exit Sub
End If
DataStream = System.IO.File.OpenText(Config.NpcFolder & Npc.Filename & ".txt")
DataStream2 = System.IO.File.OpenText(Config.NpcFolder & Npc.Filename & ".txt")
Data = DataStream.ReadLine()
Data2 = DataStream2.ReadLine()
Do Until Data2 Is Nothing
If Data2.StartsWith("[") = True Then
Npc.NpcCode.SubCount = Npc.NpcCode.SubCount + 1
End If
Data2 = DataStream2.ReadLine()
Loop
Do Until Data Is Nothing
Dim Line As String = Data
NextSub:
Select Case True
Case Line.StartsWith(";")
'Ignore all with this at start
Case Line.StartsWith("[@") And Line.EndsWith("]")
Dim NpcComm2 As clsNpc.clsNpcSub
Dim NpcComm As New clsNpc.clsNpcSub
SubNum = SubNum + 1
If SubNum <> 1 Then
Npc.NpcCode.NpcSub(SubNum - 1) = NpcComm2
End If
NpcComm.SubTitle = Line
Do Until Line Is Nothing
Line = DataStream.ReadLine()
ReSelectCase:
Select Case True
Case Line.StartsWith("[")
NpcComm2 = NpcComm
GoTo NextSub
'#SAY
Case Line.ToUpper = "#SAY"
SAY = ""
Line = DataStream.ReadLine()
On Error GoTo SayError
Do Until Line Is Nothing Or Line.StartsWith("[") Or Line.StartsWith("#")
If SAY Is Nothing Then
SAY = Line
Else
SAY = SAY & vbCrLf & Line
End If
Line = DataStream.ReadLine()
If Line.ToUpper = "#ACT" Or Line.ToUpper = "#ELSESAY" Or Line.ToUpper = "#IF" Or Line.ToUpper = "#ELSEACT" Or Line.StartsWith("[") Or Line Is Nothing Then
SAY = SAY.Replace("#SAY", "")
NpcComm.NpcSay = SAY
GoTo ReSelectCase
End If
Loop
GoTo ReSelectCase
SayError:
NpcComm.NpcSay = SAY
GoTo EndofFile
'#ACT
Case Line.ToUpper = "#ACT"
ACT = ""
Line = DataStream.ReadLine()
On Error GoTo ActError
Do Until Line Is Nothing
If ACT = "" Then
ACT = Line
Else
ACT = ACT & vbCrLf & Line
End If
Line = DataStream.ReadLine()
If Line.ToUpper = "#SAY" Or Line.ToUpper = "#ELSESAY" Or Line.ToUpper = "#IF" Or Line.ToUpper = "#ELSEACT" Or Line.StartsWith("[") Then
ACT = ACT.Replace("#ACT", "")
NpcComm.NpcAct = ACT
GoTo ReSelectCase
End If
Loop
GoTo ReSelectCase
ActError:
NpcComm.NpcAct = ACT
GoTo EndofFile
'#IF
Case Line.ToUpper = "#IF"
IFStr = ""
Line = DataStream.ReadLine()
On Error GoTo IFError
Do Until Line.StartsWith("[") Or Line Is Nothing Or Line.StartsWith("#")
If IFStr = "" Then
IFStr = Line
Else
IFStr = IFStr & vbCrLf & Line
End If
Line = DataStream.ReadLine()
If Line.ToUpper = "#SAY" Or Line.ToUpper = "#ELSESAY" Or Line.ToUpper = "#ELSEACT" Or Line.ToUpper = "#ACT" Or Line.StartsWith("[") Then
IFStr = IFStr.Replace("#IF", "")
NpcComm.NpcIF = IFStr
GoTo ReSelectCase
End If
Loop
GoTo ReSelectCase
IFError:
NpcComm.NpcIF = IFStr
GoTo EndOfFile
'#ELSESAY
Case Line.ToUpper = "#ELSESAY"
IFStr = ""
Line = DataStream.ReadLine()
On Error GoTo ElseSayError
Do Until Line.StartsWith("[") Or Line Is Nothing Or Line.StartsWith("#")
If ElseSay = "" Then
ElseSay = Line
Else
ElseSay = ElseSay & vbCrLf & Line
End If
Line = DataStream.ReadLine()
If Line.ToUpper = "#SAY" Or Line.ToUpper = "#IF" Or Line.ToUpper = "#ELSEACT" Or Line.ToUpper = "#ACT" Or Line.StartsWith("[") Then
ElseSay = ElseSay.Replace("#ELSESAY", "")
NpcComm.NPCElseSay = ElseSay
GoTo ReSelectCase
End If
Loop
GoTo ReSelectCase
ElseSayError:
NpcComm.NPCElseSay = ElseSay
GoTo EndOfFile
'#ELSEACT
Case Line.ToUpper = "#ELSEACT"
ElseAct = ""
Line = DataStream.ReadLine()
On Error GoTo ELSEACTError
Do Until Line.StartsWith("[") Or Line Is Nothing Or Line.StartsWith("#")
If ElseAct = "" Then
ElseAct = Line
Else
ElseAct = ElseAct & vbCrLf & Line
End If
Line = DataStream.ReadLine()
If Line.ToUpper = "#SAY" Or Line.ToUpper = "#ELSESAY" Or Line.ToUpper = "#IF" Or Line.ToUpper = "#ACT" Or Line.StartsWith("[") Then
ElseAct = ElseAct.Replace("#ELSEACT", "")
NpcComm.NpcElseAct = ElseAct
GoTo ReSelectCase
End If
Loop
GoTo ReSelectCase
ELSEACTError:
NpcComm.NpcElseAct = ElseAct
GoTo EndofFile
End Select
Loop
EndofFile:
Npc.NpcCode.NpcSub(SubNum) = NpcComm
'Next SubNum
End Select
Data = DataStream.ReadLine()
Loop
DataStream.Close()
DataStream2.Close()
End Sub
#End Region
End Module
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -