Exemplo n.º 1
0
 public ScriptInvocation(dynamic function = null, WorldObject associate = null, WorldObject invoker = null, Script script = null)
 {
     Function = function;
     Associate = associate;
     Invoker = invoker;
     Script = null;
 }
Exemplo n.º 2
0
 public HybrasylWorldObject(WorldObject obj)
 {
     Obj = obj;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Execute the script in the passed scope.
        /// </summary>
        /// <param name="scope">The ScriptScope the script will execute in.</param>
        public void ExecuteScript(WorldObject caller = null)
        {
            dynamic resolvedCaller;

            if (caller != null)
            {
                if (caller is User)
                    resolvedCaller = new HybrasylUser(caller as User);
                else
                    resolvedCaller = new HybrasylWorldObject(caller);
                Scope.SetVariable("npc", resolvedCaller);
            }

            Scope.SetVariable("world", Processor.World);
            Compiled.Execute(Scope);
        }
Exemplo n.º 4
0
 public dynamic GetObjectWrapper(WorldObject obj)
 {
     if (obj is User)
         return new HybrasylUser(obj as User);
     return new HybrasylWorldObject(obj);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Attach a Scriptable to an in game NPC.
 /// </summary>
 /// <returns></returns>
 public bool AttachScriptable(WorldObject obj)
 {
     Associate = new HybrasylWorldObject(obj);
     Logger.InfoFormat("Scriptable name: {0}", Instance.name);
     return true;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Associate a dialog with an object in the world.
 /// </summary>
 /// <param name="obj"></param>
 public void AssociateSequence(WorldObject obj)
 {
     Associate = obj;
 }
Exemplo n.º 7
0
 public void AssociateScriptWithObject(WorldObject obj)
 {
     Associate = new HybrasylWorldObject(obj);
     obj.Script = this;
 }
Exemplo n.º 8
0
 public void HandleResponse(WorldObject invoker, String response, WorldObject associateOverride = null)
 {
     Logger.DebugFormat("Response {0} from player {1}", response, invoker.Name);
     if (Handler != null)
     {
         // Either we must have an associate already known to us, one must be passed, or we must have a script defined
         if (Sequence.Associate == null && associateOverride == null && Sequence.Script == null)
         {
             Logger.ErrorFormat("InputDialog has no known associate or script...?");
             // Need better error handling here
             return;
         }
         var invocation = new ScriptInvocation();
         invocation.Function = Handler;
         invocation.Associate = associateOverride == null ? Sequence.Associate : associateOverride;
         invocation.Invoker = invoker;
         invocation.Execute(response);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Update the WorldObject associated with this dialog state to obj.
 /// </summary>
 /// <param name="obj">The world object which will now be associated with the dialog state.</param>
 internal void UpdateAssociate(WorldObject obj)
 {
     Associate = obj;
 }
Exemplo n.º 10
0
 public void Remove(WorldObject obj)
 {
     if (obj is User)
     {
         DeleteUser(obj.Name);
     }
     Objects.Remove(obj.Id);
     obj.World = null;
     obj.Id = 0;
 }
Exemplo n.º 11
0
            public void HandleResponse(WorldObject invoker, int optionSelected, WorldObject associateOverride = null)
            {
                var invocation = new ScriptInvocation();
                invocation.Invoker = invoker;

                if (Sequence.Associate != null)
                    invocation.Associate = Sequence.Associate;
                else
                    invocation.Associate = associateOverride;

                // If the individual options don't have callbacks, use the dialog callback instead.
                if (Handler != null && Options[optionSelected - 1].CallbackFunction == null)
                {
                    invocation.Function = Handler;
                }
                else if (Options[optionSelected - 1].CallbackFunction != null)
                {
                    invocation.Function = Options[optionSelected - 1].CallbackFunction;
                }
                invocation.Execute(optionSelected);
            }
Exemplo n.º 12
0
        public void Insert(WorldObject obj)
        {
            if (obj is User)
            {
                AddUser((User) obj);
            }

            ++worldObjectID;
            obj.Id = worldObjectID;
            obj.World = this;
            obj.SendId();

            if (obj is Item)
            {
                var itemscript = Game.World.ScriptProcessor.GetScript(obj.Name);
                if (itemscript != null)
                {
                    var clone = itemscript.Clone();
                    itemscript.AssociateScriptWithObject(obj);
                }
            }

            Objects.Add(worldObjectID, obj);
        }
Exemplo n.º 13
0
        private void PacketHandler_0x43_PointClick(Object obj, ClientPacket packet)
        {
            var user = (User) obj;
            var clickType = packet.ReadByte();
            Rectangle commonViewport = user.GetViewport();
            // User has clicked an X,Y point
            if (clickType == 3)
            {
                var x = (byte) packet.ReadUInt16();
                var y = (byte) packet.ReadUInt16();
                var coords = new Tuple<byte, byte>(x, y);
                Logger.DebugFormat("coordinates were {0}, {1}", x, y);

                if (user.Map.Doors.ContainsKey(coords))
                {
                    if (user.Map.Doors[coords].Closed)
                        user.SendMessage("It's open.", 0x1);
                    else
                        user.SendMessage("It's closed.", 0x1);

                    user.Map.ToggleDoors(x, y);
                }
                else if (user.Map.Signposts.ContainsKey(coords))
                {
                    user.Map.Signposts[coords].OnClick(user);
                }
                else
                {
                    Logger.DebugFormat("User clicked {0}@{1},{2} but no door/signpost is present",
                        user.Map.Name, x, y);
                }
            }

                // User has clicked on another entity
            else if (clickType == 1)
            {
                var entityId = packet.ReadUInt32();
                Logger.DebugFormat("User {0} clicked ID {1}: ", user.Name, entityId);

                WorldObject clickTarget = new WorldObject();

                if (user.World.Objects.TryGetValue(entityId, out clickTarget))
                {
                    if (clickTarget is User || clickTarget is Merchant)
                    {
                        Type type = clickTarget.GetType();
                        MethodInfo methodInfo = type.GetMethod("OnClick");
                        methodInfo.Invoke(clickTarget, new[] {user});
                    }
                }
            }
            else
            {
                Logger.DebugFormat("Unsupported clickType {0}", clickType);
                Logger.DebugFormat("Packet follows:");
                packet.DumpPacket();

            }

        }
Exemplo n.º 14
0
 public void OnLeave(WorldObject obj)
 {
     if (Ready)
         Script.ExecuteScriptableFunction("OnLeave", Script.GetObjectWrapper(obj));
 }
Exemplo n.º 15
0
 public void OnDrop(WorldObject obj, WorldObject dropped)
 {
     if (Ready)
         Script.ExecuteScriptableFunction("OnDrop", Script.GetObjectWrapper(obj),
             Script.GetObjectWrapper(dropped));
 }
Exemplo n.º 16
0
 public void AoiEntry(WorldObject obj)
 {
     if (Ready)
         Script.ExecuteScriptableFunction("OnAoiEntry", Script.GetObjectWrapper(obj));
 }