Exemplo n.º 1
0
        /// <summary>
        /// Gets the walk speed multiplier.
        /// </summary>
        /// <param name="groundDragFactor">The amount of drag provided by the current ground. (Default: 0.3)</param>
        public override double GetWalkSpeedMultiplier(double groundDragFactor = 0.3)
        {
            Block belowBlock  = World.BlockAccessor.GetBlock((int)LocalPos.X, (int)(LocalPos.Y - 0.05f), (int)LocalPos.Z);
            Block insideblock = World.BlockAccessor.GetBlock((int)LocalPos.X, (int)(LocalPos.Y + 0.01f), (int)LocalPos.Z);

            double multiplier = (servercontrols.Sneak ? GlobalConstants.SneakSpeedMultiplier : 1.0) * (servercontrols.Sprint ? GlobalConstants.SprintSpeedMultiplier : 1.0);

            if (FeetInLiquid)
            {
                multiplier /= 2.5;
            }

            double mul1 = belowBlock.Code.Path.Contains("metalspike") ? 1 : belowBlock.WalkSpeedMultiplier;
            double mul2 = insideblock.Code.Path.Contains("metalspike") ? 1 : insideblock.WalkSpeedMultiplier;

            multiplier *= mul1 * mul2;

            // Apply walk speed modifiers.
            var attribute = WatchedAttributes.GetTreeAttribute("walkSpeedModifiers");

            if (attribute?.Count > 0)
            {
                // Enumerate over all values in this attribute as tree attributes, then
                // multiply their "Value" properties together with the current multiplier.
                multiplier *= attribute.Values.Cast <ITreeAttribute>()
                              .Aggregate(1.0F, (current, modifier) => current * modifier.GetFloat("Value"));
            }

            return(multiplier);
        }
Exemplo n.º 2
0
        public override void Initialize(EntityProperties properties, ICoreAPI api, long chunkindex3d)
        {
            base.Initialize(properties, api, chunkindex3d);

            inv.LateInitialize("gearinv-" + EntityId, api);

            Name = WatchedAttributes.GetTreeAttribute("nametag")?.GetString("name");
        }
Exemplo n.º 3
0
        public override void FromBytes(BinaryReader reader, bool forClient)
        {
            base.FromBytes(reader, forClient);

            if (!forClient)
            {
                ITreeAttribute ctree = WatchedAttributes.GetTreeAttribute("commandQueue");
                if (ctree == null)
                {
                    return;
                }

                ITreeAttribute commands = ctree.GetTreeAttribute("commands");
                if (commands == null)
                {
                    return;
                }

                foreach (var val in commands)
                {
                    ITreeAttribute attr = val.Value as ITreeAttribute;
                    string         type = attr.GetString("type");

                    INpcCommand command = null;

                    switch (type)
                    {
                    case "tp":
                        command = new NpcTeleportCommand(this, null);
                        break;

                    case "goto":
                        command = new NpcGotoCommand(this, null, null, 0);
                        break;

                    case "anim":
                        command = new NpcPlayAnimationCommand(this, null, 1f);
                        break;
                    }

                    command.FromAttribute(attr);
                    Commands.Add(command);
                }
            }
        }