Exemple #1
0
        public void StartSequence(string sequenceName, HybrasylWorldObject associateOverride = null)
        {
            DialogSequence sequence;
            VisibleObject  associate;

            Logger.DebugFormat("{0} starting sequence {1}", User.Name, sequenceName);

            // If we're using a new associate, we will consult that to find our sequence
            associate = associateOverride == null ? User.DialogState.Associate as VisibleObject : associateOverride.Obj as VisibleObject;

            // Use the local catalog for sequences first, then consult the global catalog

            if (!associate.SequenceCatalog.TryGetValue(sequenceName, out sequence))
            {
                if (!User.World.GlobalSequencesCatalog.TryGetValue(sequenceName, out sequence))
                {
                    Logger.ErrorFormat("called from {0}: sequence name {1} cannot be found!",
                                       associate.Name, sequenceName);
                    // To be safe, end all dialogs and basically abort
                    User.DialogState.EndDialog();
                    return;
                }
            }

            // sequence should now be our target sequence, let's end the current state and start a new one

            User.DialogState.EndDialog();
            User.DialogState.StartDialog(associate, sequence);
            User.DialogState.ActiveDialog.ShowTo(User, associate);
        }
Exemple #2
0
 public void DropItem(HybrasylWorldObject obj, int x, int y)
 {
     if (obj.Obj is ItemObject)
     {
         Map.Insert(obj.Obj as ItemObject, (byte)x, (byte)y);
     }
 }
Exemple #3
0
 public void AssociateScriptWithObject(WorldObject obj)
 {
     Associate = new HybrasylWorldObject(obj);
     if (obj is VisibleObject)
     {
         var visibleObject = obj as VisibleObject;
         Compiled.Globals.Set("map", UserData.Create(new HybrasylMap(visibleObject.Map)));
     }
     Compiled.Globals.Set("associate", UserData.Create(Associate));
     obj.Script = this;
 }
Exemple #4
0
        public void StartDialogSequence(string sequenceName, HybrasylWorldObject associate)
        {
            DialogSequence newSequence;

            if (User.World.GlobalSequencesCatalog.TryGetValue(sequenceName, out newSequence))
            {
                newSequence.ShowTo(User, (VisibleObject)associate.Obj);
                // End previous sequence
                User.DialogState.EndDialog();
                User.DialogState.StartDialog(associate.Obj as VisibleObject, newSequence);
            }
        }
Exemple #5
0
 /// <summary>
 /// Calculate the Manhattan distance between the current world object and a target object. Assumes objects are on the same map, otherwise the calculation is meaningless.
 /// </summary>
 /// <param name="target">The target object</param>
 /// <returns></returns>
 public int Distance(HybrasylWorldObject target)
 {
     if (target is null)
     {
         GameLog.ScriptingError("Distance: target (first argument) was null, returning -1");
         return(-1);
     }
     if (target.Obj is VisibleObject v1 && Obj is VisibleObject v2)
     {
         if (v1.Map.Id == v2.Map.Id)
         {
             return(Obj.Distance(target.Obj));
         }
         else
         {
             GameLog.ScriptingError("Distance: target (first argument, {targetname}) not on same map as {thisname}, returning -1",
                                    v1.Name, v2.Name);
         }
     }
Exemple #6
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);
        }
Exemple #7
0
 /// <summary>
 /// Calculate the Manhattan distance between the current world object and a target object. Assumes objects are on the same map, otherwise the calculation is meaningless.
 /// </summary>
 /// <param name="target">The target object</param>
 /// <returns></returns>
 public int Distance(HybrasylWorldObject target) => Obj.Distance(target.Obj);
Exemple #8
0
 /// <summary>
 /// Attach a Scriptable to an in game NPC.
 /// </summary>
 /// <returns></returns>
 public bool AttachScriptable(WorldObject obj)
 {
     Associate = new HybrasylWorldObject(obj);
     return(true);
 }
Exemple #9
0
 public void AssociateScriptWithObject(WorldObject obj)
 {
     Associate          = new HybrasylWorldObject(obj);
     State["associate"] = Associate;
     obj.Script         = this;
 }
Exemple #10
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);
 }