Beispiel #1
0
        public override bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            if (byEntity.World.Side == EnumAppSide.Client)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ModelTransform       tf    = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Rotation.X = Math.Min(60, secondsPassed * 360);
                if (secondsPassed > 0.3)
                {
                    tf.Translation.Z -= Math.Min(1.5f, 36f * (secondsPassed - 0.3f));
                    tf.Rotation.X    -= Math.Max(-40, secondsPassed * 500);
                }


                byEntity.Controls.UsingHeldItemTransformAfter = tf;

                if (secondsPassed > 0.43f && byEntity.Attributes.GetInt("didattack") == 0)
                {
                    world.TryAttackEntity(entitySel);
                    byEntity.Attributes.SetInt("didattack", 1);
                    world.AddCameraShake(0.25f);
                }
            }

            return(secondsPassed < 0.9f);
        }
Beispiel #2
0
        public override bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            secondsPassed *= 1.25f;

            float backwards = -Math.Min(0.35f, 2 * secondsPassed);
            float stab      = Math.Min(1.2f, 20 * Math.Max(0, secondsPassed - 0.35f));

            if (byEntity.World.Side == EnumAppSide.Client)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ModelTransform       tf    = new ModelTransform();
                tf.EnsureDefaultValues();

                float sum     = stab + backwards;
                float easeout = Math.Max(0, 2 * (secondsPassed - 1));

                if (secondsPassed > 0.4f)
                {
                    sum = Math.Max(0, sum - easeout);
                }

                tf.Translation.Set(-1.4f * sum, 0, -sum * 0.8f * 2.6f);
                tf.Rotation.Set(-sum * 90, 0, sum * 10);

                byEntity.Controls.UsingHeldItemTransformAfter = tf;


                if (stab > 1.15f && byEntity.Attributes.GetInt("didattack") == 0)
                {
                    world.TryAttackEntity(entitySel);
                    byEntity.Attributes.SetInt("didattack", 1);
                    world.AddCameraShake(0.25f);
                }
            }



            return(secondsPassed < 1.2f);
        }
Beispiel #3
0
        public override bool OnHeldAttackStep(float secondsPassed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            float backwards = -Math.Min(0.35f, 2 * secondsPassed);
            float stab      = Math.Min(1.2f, 20 * Math.Max(0, secondsPassed - 0.35f)); // + Math.Max(0, 5*(secondsPassed - 0.5f));

            if (byEntity.World.Side == EnumAppSide.Client)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ModelTransform       tf    = new ModelTransform();
                tf.EnsureDefaultValues();

                float sum          = stab + backwards;
                float ztranslation = Math.Min(0.2f, 1.5f * secondsPassed);
                float easeout      = Math.Max(0, 10 * (secondsPassed - 1));

                if (secondsPassed > 0.4f)
                {
                    sum = Math.Max(0, sum - easeout);
                }
                ztranslation = Math.Max(0, ztranslation - easeout);

                tf.Translation.Set(sum * 0.8f, 2.5f * sum / 3, -ztranslation);
                tf.Rotation.Set(sum * 10, sum * 2, sum * 25);

                byEntity.Controls.UsingHeldItemTransformBefore = tf;

                if (stab > 1.15f && byEntity.Attributes.GetInt("didattack") == 0)
                {
                    world.TryAttackEntity(entitySel);
                    byEntity.Attributes.SetInt("didattack", 1);
                    world.ShakeCamera(0.125f);
                }
            }



            return(secondsPassed < 1.2f);
        }
Beispiel #4
0
        public override bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            float backwards = -Math.Min(0.8f, 3 * secondsPassed);
            float stab      = Math.Min(1.2f, 20 * Math.Max(0, secondsPassed - 0.25f));

            if (byEntity.World.Side == EnumAppSide.Client)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ModelTransform       tf    = new ModelTransform();
                tf.EnsureDefaultValues();


                float sum          = stab + backwards;
                float ztranslation = Math.Min(0.2f, 1.5f * secondsPassed);
                float easeout      = Math.Max(0, 2 * (secondsPassed - 1));

                if (secondsPassed > 0.4f)
                {
                    sum = Math.Max(0, sum - easeout);
                }
                ztranslation = Math.Max(0, ztranslation - easeout);

                tf.Translation.Set(-1f * sum, ztranslation * 0.4f, -sum * 0.8f * 2.6f);
                tf.Rotation.Set(-sum * 9, sum * 30, -sum * 30);

                byEntity.Controls.UsingHeldItemTransformAfter = tf;


                if (stab > 1.15f && byEntity.Attributes.GetInt("didattack") == 0)
                {
                    world.TryAttackEntity(entitySel);
                    byEntity.Attributes.SetInt("didattack", 1);
                    world.AddCameraShake(0.25f);
                }
            }
            else
            {
                if (stab > 1.15f && byEntity.Attributes.GetInt("didattack") == 0 && entitySel != null)
                {
                    byEntity.Attributes.SetInt("didattack", 1);

                    bool canhackEntity =
                        entitySel.Entity.Properties.Attributes?["hackedEntity"].Exists == true &&
                        slot.Itemstack.ItemAttributes.IsTrue("hacking") == true && api.ModLoader.GetModSystem <CharacterSystem>().HasTrait((byEntity as EntityPlayer).Player, "technical")
                    ;
                    ICoreServerAPI sapi = api as ICoreServerAPI;

                    if (canhackEntity)
                    {
                        sapi.World.PlaySoundAt(new AssetLocation("sounds/player/hackingspearhit.ogg"), entitySel.Entity, null);
                    }

                    if (api.World.Rand.NextDouble() < 0.15 && canhackEntity)
                    {
                        SpawnEntityInPlaceOf(entitySel.Entity, entitySel.Entity.Properties.Attributes["hackedEntity"].AsString(), byEntity);
                        sapi.World.DespawnEntity(entitySel.Entity, new EntityDespawnReason()
                        {
                            reason = EnumDespawnReason.Removed
                        });
                    }
                }
            }

            return(secondsPassed < 1.2f);
        }