예제 #1
0
        /// <summary>
        /// </summary>
        /// <param name="imExecuteFunction">
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public void ExecuteFunction(IMExecuteFunction imExecuteFunction)
        {
            var          user = (ITargetingEntity)this.FindNamedEntityByIdentity(imExecuteFunction.User);
            INamedEntity target;

            // TODO: Go over the targets, they can return item templates, inventory entries etc too
            switch (imExecuteFunction.Function.Target)
            {
            case 1:
                target = (INamedEntity)user;
                break;

            case 2:
                throw new NotImplementedException("Target Wearer not implemented yet");

            case 3:
                target = this.FindNamedEntityByIdentity(user.SelectedTarget);
                break;

            case 14:
                target = this.FindNamedEntityByIdentity(user.FightingTarget);
                break;

            case 19:     // Perhaps (if issued from a item) its the item itself
                target = (INamedEntity)user;
                break;

            case 23:
                target = this.FindNamedEntityByIdentity(user.SelectedTarget);
                break;

            case 26:
                target = (INamedEntity)user;
                break;

            case 100:
                target = (INamedEntity)user;
                break;

            default:
                throw new NotImplementedException(
                          "Unknown target encountered: Target#:" + imExecuteFunction.Function.Target);
            }

            if (target == null)
            {
                var temp = user as Character;
                if (temp != null)
                {
                    if (temp.Controller.Client != null)
                    {
                        temp.Controller.Client.SendCompressed(
                            new ChatTextMessage {
                            Identity = temp.Identity, Text = "No valid target found"
                        });
                    }
                    return;
                }
            }

            FunctionCollection.Instance.CallFunction(
                imExecuteFunction.Function.FunctionType,
                (INamedEntity)user,
                (INamedEntity)user,
                target,
                imExecuteFunction.Function.Arguments.Values.ToArray());
        }
예제 #2
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="target">
        /// </param>
        /// <param name="args">
        /// </param>
        public override void ExecuteCommand(Client client, Identity target, string[] args)
        {
            // Fallback to self if no target is selected
            bool fallback = false;

            if (target.Instance == 0)
            {
                target   = client.Character.Identity;
                fallback = true;
            }

            int statId = 0;

            try
            {
                statId = StatNamesDefaults.GetStatNumber(args[1]);
            }
            catch (Exception)
            {
                client.SendChatText("Unknown Stat name " + args[1]);
                return;
            }

            uint statNewValue = 1234567890;

            try
            {
                statNewValue = uint.Parse(args[2]);
            }
            catch
            {
                try
                {
                    // For values >= 2^31
                    statNewValue = uint.Parse(args[2]);
                }
                catch (FormatException)
                {
                }
                catch (OverflowException)
                {
                }
            }

            IStats tempch = client.Playfield.FindByIdentity(target);

            if (tempch == null)
            {
                client.SendChatText("Target vanished? This should NOT be reached");
            }

            uint statOldValue;

            try
            {
                statOldValue = tempch.Stats[statId].BaseValue;
                var IM =
                    new IMExecuteFunction(
                        new Functions
                {
                    Target       = Constants.ItemtargetSelectedtarget,
                    FunctionType = Constants.FunctiontypeSet,
                    Requirements = new List <Requirements>(),
                    Arguments    =
                        new FunctionArguments
                    {
                        Values =
                            new List <object> {
                            statId, (int)statNewValue
                        }
                    },
                    TickCount    = 1,
                    TickInterval = 1,
                    dolocalstats = true
                },
                        ((INamedEntity)tempch).Identity);
                if (fallback)
                {
                    IM.Function.Target = Constants.ItemtargetSelf;
                }

                if (tempch.CheckRequirements(IM.Function, true))
                {
                    ((IInstancedEntity)tempch).Playfield.Publish(IM);
                }
            }
            catch
            {
                client.SendChatText("Unknown StatId " + statId);
                return;
            }

            INamedEntity namedEntity = tempch as INamedEntity;
            string       response;

            if (namedEntity != null)
            {
                response = "Character " + namedEntity.Name + " (" + target.Instance + "): Stat "
                           + StatNamesDefaults.GetStatName(statId) + " (" + statId + ") =";
            }
            else
            {
                response = "Dynel (" + ((IInstancedEntity)tempch).Identity.Instance + "): Stat "
                           + StatNamesDefaults.GetStatName(statId) + " (" + statId + ") =";
            }

            response += " Old: " + statOldValue;
            response += " New: " + statNewValue;
            client.SendChatText(response);
        }