0 people like it.
Like the snippet!
questflow prototype
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
|
open System
open System.Collections.Generic
// event handler
type Handler = (unit->unit)
// imitates dialog system
let Dialogs = new Dictionary<string*string, Handler>()
// imitates killing events
let Kills = new Dictionary<string, Handler>()
type Player() =
member x.GiveXP n =
printfn "Gained %d experience points" n
member x.StartQuest(quest) =
printfn "Starting quest '%s'" quest
// simulating players actions
member x.TalkTo(npc, node) =
Dialogs.[npc, node]()
member x.Kill(npc) =
Kills.[npc]()
type Event =
| Talk of Player * string * string // player talks with npc using given node
| Kill of Player * string // player kills npc
type Quest =
| Phase of Event * Handler
| Nothing
type QuestBuilder() =
member x.Bind(v : Event, f) =
match v with
| Talk(player, npc, node) ->
printfn "Player needs to talk with %s using node %s" npc node
Dialogs.[(npc, node)] <- f // assign handler to dialog
Talk(player, npc, node), f // or we could use that return type to do that?
| Kill(player, npc) ->
printfn "Player needs to kill %s" npc
Kills.[npc] <- f
Kill(player, npc), f
|> ignore
member x.Zero() =
printfn "Zero"
()
let talk player npc node = Talk(player, npc, node)
let kill player npc = Kill(player, npc)
let quest = new QuestBuilder()
let beast = quest {
let player = new Player()
do! talk player "Rudolf" "KillBeast" // this is the beginning, we require player to talk with an npc using specified dialog node
player.StartQuest("Beast") // and then, the rest will be called when player does this
do! kill player "Beast" // so, when he talks to that npc, this piece is executed, and it attaches the rest, as the handler for kill event
player.GiveXP(100) // and then, when monster is killed, this is executed
}
// let's simulate player
let player = new Player()
player.TalkTo("Rudolf", "KillBeast")
player.Kill("Beast")
|
namespace System
namespace System.Collections
namespace System.Collections.Generic
Multiple items
type Handler = unit -> unit
Full name: Script.Handler
--------------------
type Handler<'T> =
delegate of obj * 'T -> unit
Full name: Microsoft.FSharp.Control.Handler<_>
type unit = Unit
Full name: Microsoft.FSharp.Core.unit
val Dialogs : Dictionary<(string * string),Handler>
Full name: Script.Dialogs
Multiple items
type Dictionary<'TKey,'TValue> =
new : unit -> Dictionary<'TKey, 'TValue> + 5 overloads
member Add : key:'TKey * value:'TValue -> unit
member Clear : unit -> unit
member Comparer : IEqualityComparer<'TKey>
member ContainsKey : key:'TKey -> bool
member ContainsValue : value:'TValue -> bool
member Count : int
member GetEnumerator : unit -> Enumerator<'TKey, 'TValue>
member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
member Item : 'TKey -> 'TValue with get, set
...
nested type Enumerator
nested type KeyCollection
nested type ValueCollection
Full name: System.Collections.Generic.Dictionary<_,_>
--------------------
Dictionary() : unit
Dictionary(capacity: int) : unit
Dictionary(comparer: IEqualityComparer<'TKey>) : unit
Dictionary(dictionary: IDictionary<'TKey,'TValue>) : unit
Dictionary(capacity: int, comparer: IEqualityComparer<'TKey>) : unit
Dictionary(dictionary: IDictionary<'TKey,'TValue>, comparer: IEqualityComparer<'TKey>) : unit
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
val Kills : Dictionary<string,Handler>
Full name: Script.Kills
Multiple items
type Player =
new : unit -> Player
member GiveXP : n:int -> unit
member Kill : npc:string -> unit
member StartQuest : quest:string -> unit
member TalkTo : npc:string * node:string -> unit
Full name: Script.Player
--------------------
new : unit -> Player
val x : Player
member Player.GiveXP : n:int -> unit
Full name: Script.Player.GiveXP
val n : int
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
member Player.StartQuest : quest:string -> unit
Full name: Script.Player.StartQuest
val quest : string
member Player.TalkTo : npc:string * node:string -> unit
Full name: Script.Player.TalkTo
val npc : string
val node : string
member Player.Kill : npc:string -> unit
Full name: Script.Player.Kill
Multiple items
module Event
from Microsoft.FSharp.Control
--------------------
type Event =
| Talk of Player * string * string
| Kill of Player * string
Full name: Script.Event
--------------------
type Event<'T> =
new : unit -> Event<'T>
member Trigger : arg:'T -> unit
member Publish : IEvent<'T>
Full name: Microsoft.FSharp.Control.Event<_>
--------------------
type Event<'Delegate,'Args (requires delegate and 'Delegate :> Delegate)> =
new : unit -> Event<'Delegate,'Args>
member Trigger : sender:obj * args:'Args -> unit
member Publish : IEvent<'Delegate,'Args>
Full name: Microsoft.FSharp.Control.Event<_,_>
--------------------
new : unit -> Event<'T>
--------------------
new : unit -> Event<'Delegate,'Args>
union case Event.Talk: Player * string * string -> Event
union case Event.Kill: Player * string -> Event
type Quest =
| Phase of Event * Handler
| Nothing
Full name: Script.Quest
union case Quest.Phase: Event * Handler -> Quest
union case Quest.Nothing: Quest
Multiple items
type QuestBuilder =
new : unit -> QuestBuilder
member Bind : v:Event * f:Handler -> unit
member Zero : unit -> unit
Full name: Script.QuestBuilder
--------------------
new : unit -> QuestBuilder
val x : QuestBuilder
member QuestBuilder.Bind : v:Event * f:Handler -> unit
Full name: Script.QuestBuilder.Bind
val v : Event
val f : Handler
val player : Player
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
member QuestBuilder.Zero : unit -> unit
Full name: Script.QuestBuilder.Zero
val talk : player:Player -> npc:string -> node:string -> Event
Full name: Script.talk
val kill : player:Player -> npc:string -> Event
Full name: Script.kill
val quest : QuestBuilder
Full name: Script.quest
val beast : unit
Full name: Script.beast
member Player.StartQuest : quest:string -> unit
member Player.GiveXP : n:int -> unit
val player : Player
Full name: Script.player
member Player.TalkTo : npc:string * node:string -> unit
member Player.Kill : npc:string -> unit
More information