示例#1
0
        ////////////////

        protected override void OnMouseHover(CustomEntity ent)
        {
            Player player = Main.LocalPlayer;

            this.IsMouseHovering = player.Distance(ent.Core.Center) <= TrainMouseInteractionEntityComponent.BoardingDistance;

            if (this.IsMouseHovering)
            {
                if (Main.mouseRight)
                {
                    var draw_comp = ent.GetComponentByType <TrainDrawInGameEntityComponent>();

                    if (!player.dead && !draw_comp.IsMinecartIconHovering)
                    {
                        var myplayer = player.GetModPlayer <OnARailPlayer>();

                        if (!myplayer.IsInInitLockdown)
                        {
                            if (ent.MyOwnerPlayerWho == player.whoAmI)
                            {
                                int train_buff_id = OnARailMod.Instance.BuffType <TrainMountBuff>();

                                if (player.FindBuffIndex(train_buff_id) == -1)
                                {
                                    player.AddBuff(train_buff_id, 30);                                          // Board train
                                }
                            }
                        }
                    }
                }
            }
        }
        ////////////////

        private void UpdateMe(CustomEntity ent)
        {
            var     core = ent.Core;
            bool    respectsGravity = ent.GetComponentByType <RespectsGravityEntityComponent>() != null;
            Vector2 wetVelocity = core.velocity * 0.5f;
            bool    lavaWet, honeyWet;

            if (!respectsGravity)
            {
                this.ApplyZeroGravityMovement(ent);
            }
            this.RefreshLiquidContactStates(ent, out lavaWet, out honeyWet);
            this.ApplyLiquidMovement(ent, lavaWet, honeyWet);
            this.ApplyCollisionMovement(ent, ref wetVelocity);
            this.ApplySlopeDodgeAndConveyorMovement(ent);

            if (core.wet)
            {
                core.position += wetVelocity;
            }
            else
            {
                core.position += core.velocity;
            }
        }
        public override void PostDraw(SpriteBatch sb, CustomEntity ent)
        {
            var train_comp = ent.GetComponentByType <TrainBehaviorEntityComponent>();
            var mouse_comp = ent.GetComponentByType <TrainMouseInteractionEntityComponent>();

            if (this.IsMinecartIconHovering)
            {
                return;
            }
            if (!mouse_comp.IsMouseHovering)
            {
                return;
            }
            if (train_comp.IsMountedBy != -1)
            {
                return;
            }
            if (ent.MyOwnerPlayerWho != Main.myPlayer)
            {
                return;
            }

            var text_pos = new Vector2(
                Main.mouseX + 16,
                Main.mouseY + 16
                );
            var pos = new Vector2(
                Main.mouseX - this.TrainIcon.Width,
                Main.mouseY - this.TrainIcon.Height
                );
            float         scale = 1.5f + ((this.PulseScaleAnimation > 0 ? this.PulseScaleAnimation : -this.PulseScaleAnimation) / 240f);
            SpriteEffects dir   = DrawsInGameEntityComponent.GetOrientation(ent.Core);

            if (this.PulseScaleAnimation >= 26)
            {
                this.PulseScaleAnimation = -this.PulseScaleAnimation;
            }
            else
            {
                this.PulseScaleAnimation++;
            }

            sb.Draw(this.TrainIcon, pos, null, Color.White, 0f, default(Vector2), scale, dir, 1f);

            HudHelpers.DrawGlowingString(ent.Core.DisplayName, text_pos, 1f);
        }
示例#4
0
        public override void UpdateServer(CustomEntity ent)
        {
            var train_comp = ent.GetComponentByType <TrainBehaviorEntityComponent>();

            if (train_comp.IsMountedBy == -1)
            {
                base.UpdateServer(ent);
            }
        }
        ////////////////

        private void OnLoad(CustomEntity ent)
        {
            var behav_comp = ent.GetComponentByType <TrainBehaviorEntityComponent>();

            if (behav_comp == null)
            {
                throw new HamstarException("Train entity " + ent.ToString() + " is missing TrainBehaviorEntityComponent.");
            }
        }
        ////////////////

        public override void Draw(SpriteBatch sb, CustomEntity ent)
        {
            var    train_comp = ent.GetComponentByType <TrainBehaviorEntityComponent>();
            Player plr        = Main.LocalPlayer;

            this.IsMinecartIconHovering = plr.showItemIcon && plr.showItemIcon2 == ItemID.Minecart;

            if (train_comp.IsMountedBy == -1)
            {
                base.Draw(sb, ent);
            }
        }
        ////////////////

        public override void Update()
        {
            if (Main.netMode == 1)
            {
                throw new HamstarException("Never run on client.");
            }

            int exit_id = this.Find(this.ExitTileX, this.ExitTileY);

            // Clear unmatched tunnel entities
            if (exit_id == -1)
            {
                if (this.IsInitialized)
                {
                    WorldGen.KillTile(this.Position.X, this.Position.Y);
                    this.Kill(this.Position.X, this.Position.Y);
                }
                return;
            }

            var exit_ent = (TrainTunnelTileEntity)ModTileEntity.ByID[exit_id];

            for (int i = 0; i < Main.player.Length; i++)
            {
                Player plr = Main.player[i];
                if (plr == null || !plr.active)
                {
                    continue;
                }

                var myplayer = plr.GetModPlayer <OnARailPlayer>();
                if (myplayer.MyTrainWho == -1)
                {
                    continue;
                }

                CustomEntity train_ent = CustomEntityManager.GetEntityByWho(myplayer.MyTrainWho);
                if (train_ent == null)
                {
                    continue;
                }

                var behav_comp = train_ent.GetComponentByType <TrainBehaviorEntityComponent>();
                behav_comp.CheckTunnel(train_ent, this, exit_ent);
            }
        }
示例#8
0
        ////////////////

        private bool ApplyHits(CustomEntity ent, Projectile projectile)
        {
            int dmg     = projectile.damage;
            var hitComp = ent.GetComponentByType <HitRadiusProjectileEntityComponent>();

            if (!hitComp.PreHurt(ent, projectile, ref dmg))
            {
                return(true);
            }

            hitComp.PostHurt(ent, projectile, dmg);

            if (projectile.numHits > 1)
            {
                projectile.numHits--;
                return(true);
            }
            return(false);
        }
示例#9
0
        private void HandleRecall()
        {
            CustomEntity ent        = CustomEntityManager.GetEntityByWho(this.MyTrainWho);
            var          train_comp = ent.GetComponentByType <TrainBehaviorEntityComponent>();

            if (train_comp.IsMountedBy != -1)
            {
                PlayerHelpers.Teleport(this.player, this.PrevPosition);                         // return to train's last position
            }
            else
            {
                if (((OnARailMod)this.mod).Config.DebugModeInfo)
                {
                    Main.NewText("Warping to train...");
                }

                TrainEntity.WarpPlayerToTrain(player);                          // return to train
            }
        }
        ////////////////

        public override void UpdateClient(CustomEntity ent)
        {
            var train_comp = ent.GetComponentByType <TrainBehaviorEntityComponent>();

            base.UpdateMe(ent);
        }