Exemplo n.º 1
0
        public static void WarpPlayerToTrain(Player player)
        {
            if (!SaveableEntityComponent.HaveAllEntitiesLoaded)
            {
                throw new HamstarException("OnARail.TrainEntityHandler.WarpPlayerToTrain - Entities not loaded.");
            }

            var myplayer = player.GetModPlayer <OnARailPlayer>();

            if (myplayer.MyTrainWho == -1)
            {
                throw new HamstarException("OnARail.TrainEntityHandler.WarpPlayerToTrain - Player " + player.name + " (" + player.whoAmI + ") has no train.");
            }

            CustomEntity train_ent = CustomEntityManager.GetEntityByWho(myplayer.MyTrainWho);

            if (train_ent == null)
            {
                throw new HamstarException("OnARail.TrainEntityHandler.WarpPlayerToTrain - Player " + player.name + " (" + player.whoAmI + ") has no train entity.");
            }

            PlayerHelpers.Teleport(player, train_ent.Core.Center - new Vector2(player.width / 2, (player.height / 2) + 16));

            int train_buff_id = OnARailMod.Instance.BuffType <TrainMountBuff>();

            player.AddBuff(train_buff_id, 30);
        }
        ////////////////

        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);
            }
        }
Exemplo n.º 3
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
            }
        }