////////////////

        public override void Action(CommandCaller caller, string input, string[] args)
        {
            if (Main.netMode == 2)
            {
                throw new HamstarException("No server.");
            }

            var mymod = (OnARailMod)this.mod;

            if (!mymod.Config.DebugModeEnableTrainRespawnCommand)
            {
                if (!UserHelpers.HasBasicServerPrivilege(caller.Player))
                {
                    caller.Reply("Train respawning disabled by config.", Color.Red);
                    return;
                }
                else
                {
                    Main.NewText("Priviledged player " + caller.Player.name + " respawns train.", Color.LightSteelBlue);
                }
            }

            int who = TrainEntity.FindMyTrain(caller.Player);

            if (who != -1)
            {
                CustomEntityManager.RemoveEntityByWho(who);
            }

            PacketProtocolRequestToServer.QuickRequest <TrainSpawnProtocol>();

            caller.Reply("Spawning train...", Color.LimeGreen);
        }
        public override bool PreAI(NPC npc)
        {
//DataStore.Add( DebugHelpers.GetCurrentContext()+"_"+npc.whoAmI+":"+npc.type+"_A", 1 );
            var mymod = (ModHelpersMod)this.mod;
            ISet <CustomEntity> ents = CustomEntityManager.GetEntitiesByComponent <HitRadiusNpcEntityComponent>();

            foreach (CustomEntity ent in ents)
            {
                var   hitRadComp = ent.GetComponentByType <HitRadiusNpcEntityComponent>();
                float radius     = hitRadComp.GetRadius(ent);

                if (Vector2.Distance(ent.Core.Center, npc.Center) <= radius)
                {
                    int dmg = npc.damage;

                    if (hitRadComp.PreHurt(ent, npc, ref dmg))
                    {
                        hitRadComp.PostHurt(ent, npc, dmg);
                    }
                }
            }

//DataStore.Add( DebugHelpers.GetCurrentContext()+"_"+npc.whoAmI+":"+npc.type+"_B", 1 );
            return(true);
        }
        private static void SaveAll(bool isJson)
        {
            var    mymod    = ModHelpersMod.Instance;
            string fileName = SaveableEntityComponent.GetFileNameBase();

            IList <SerializableCustomEntity> wrappedEnts = new List <SerializableCustomEntity>();

            foreach (var ent in CustomEntityManager.GetEntitiesByComponent <SaveableEntityComponent>())
            {
                if (ent.GetComponentByType <SaveableEntityComponent>().AsJson != isJson)
                {
                    continue;
                }

                wrappedEnts.Add(new SerializableCustomEntity(ent));
            }

            if (wrappedEnts.Count > 0)
            {
                if (isJson)
                {
                    DataFileHelpers.SaveAsJson(mymod, fileName, CustomEntityConverter.SerializerSettings, wrappedEnts);
                }
                else
                {
                    DataFileHelpers.SaveAsBinary(mymod, fileName + ".dat", false, CustomEntityConverter.SerializerSettings, wrappedEnts);
                }
            }
        }
Example #4
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 Initialize(CustomEntityManager customEntityManager)
 {
     _entityManager = customEntityManager;
     _pathToPositionComponentArray = _entityManager.GetComponentArray <PathToPositionComponent>();
     _positionComponentArray       = _entityManager.GetComponentArray <PositionComponent>();
     _combatStatsComponents        = _entityManager.GetComponentArray <CombatStatsComponent>();
 }
Example #6
0
        private void DrawFullMapForAll(SpriteBatch sb)
        {
            ISet <CustomEntity> ents = CustomEntityManager.GetEntitiesByComponent <DrawsOnMapEntityComponent>();

            foreach (var ent in ents)
            {
                var mapComp = ent.GetComponentByType <DrawsOnMapEntityComponent>();

                mapComp.DrawFullscreenMap(sb, ent);
            }
        }
Example #7
0
        ////

        protected override void InitializeServerSendData(int fromWho)
        {
            ISet <CustomEntity> ents = CustomEntityManager.GetEntitiesByComponent <PeriodicSyncEntityComponent>();

            this.Entities = ents.Where(ent => ent.SyncFromServer)
                            .SafeSelect(ent => new SerializableCustomEntity(ent))
                            .ToArray();

            /*if( ModHelpersMod.Instance.Config.DebugModeCustomEntityInfo ) {
             *      LogHelpers.Log( "ModHelpers.CustomEntityAllProtocol.SetServerDefaults - Sending " + string.Join(",\n   ", this.Entities.Select(e=>e.ToString())) );
             * }*/
        }
Example #8
0
        public static int FindMyTrain(Player player)
        {
            if (!SaveableEntityComponent.HaveAllEntitiesLoaded)
            {
                LogHelpers.LogOnce("!OnARail.TrainEntityHandler.FindMyTrain - Entities not loaded.");
                return(-1);
            }

            ISet <TrainEntity> ents = CustomEntityManager.GetEntitiesForPlayer <TrainEntity>(player);

            return(ents.FirstOrDefault()?.Core.WhoAmI ?? -1);
        }
 private void OnConnectHost()
 {
     //Promises.AddPostWorldLoadOncePromise( () => {
     Promises.AddValidatedPromise(SaveableEntityComponent.LoadAllValidator, () => {
         if (TrainEntity.FindMyTrain(this.player) == -1)
         {
             var ent = TrainEntity.CreateTrainEntity(this.player);
             CustomEntityManager.AddToWorld(ent);
         }
         return(false);
     });
 }
Example #10
0
        ////////////////

        protected override void Receive()
        {
            CustomEntityManager.ClearAllEntities();

            foreach (SerializableCustomEntity ent in this.Entities)
            {
                /*if( ModHelpersMod.Instance.Config.DebugModeCustomEntityInfo ) {
                 *      LogHelpers.Log( "ModHelpers.CustomEntityAllProtocol.ReceiveWithClient - New entity " + ent.ToString() );
                 * }*/

                var realEnt = CustomEntityManager.AddToWorld(ent.Core.whoAmI, ent, true);
            }

            SaveableEntityComponent.PostLoadAll();
        }
        public void UnloadOuter()
        {
            this.ReflectionHelpers         = null;
            this.PacketProtocolMngr        = null;
            this.ExceptionMngr             = null;
            this.Timers                    = null;
            this.ConfigJson                = null;
            this.LogHelpers                = null;
            this.ModFeaturesHelpers        = null;
            this.BuffHelpers               = null;
            this.NetHelpers                = null;
            this.ItemIdentityHelpers       = null;
            this.NPCIdentityHelpers        = null;
            this.ProjectileIdentityHelpers = null;
            this.BuffIdentityHelpers       = null;
            this.NPCBannerHelpers          = null;
            this.RecipeIdentityHelpers     = null;
            this.RecipeGroupHelpers        = null;
            this.PlayerHooks               = null;
            this.LoadHelpers               = null;
            this.GetModInfo                = null;
            this.GetModTags                = null;
            this.WorldStateHelpers         = null;
            this.ModLock                   = null;
            this.EntityGroups              = null;
            this.AnimatedColors            = null;
            this.PlayerMessages            = null;
            this.Inbox                 = null;
            this.ControlPanel          = null;
            this.MenuItemMngr          = null;
            this.MenuContextMngr       = null;
            this.MusicHelpers          = null;
            this.PlayerIdentityHelpers = null;
            this.CustomEntMngr         = null;
            this.Promises              = null;
            this.DataStore             = null;
            this.CustomHotkeys         = null;
            this.XnaHelpers            = null;
            this.ServerInfo            = null;
            //this.PlayerDataMngr = null;
            this.SupportInfo    = null;
            this.RecipeHack     = null;
            this.ModListHelpers = null;

            this.ControlPanelHotkey = null;
            this.DataDumpHotkey     = null;
        }
        ////////////////

        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);
            }
        }
Example #13
0
        private void DrawMiniMapForAll(SpriteBatch sb)
        {
            ISet <CustomEntity> ents = CustomEntityManager.GetEntitiesByComponent <DrawsOnMapEntityComponent>();

            foreach (var ent in ents)
            {
                var mapComp = ent.GetComponentByType <DrawsOnMapEntityComponent>();

                if (Main.mapStyle == 1)
                {
                    mapComp.DrawMiniMap(sb, ent);
                }
                else
                {
                    mapComp.DrawOverlayMap(sb, ent);
                }
            }
        }
Example #14
0
        ////////////////

        protected override bool ReceiveRequestWithServer(int from_who)
        {
            Player player = Main.player[from_who];

            Promises.AddValidatedPromise(SaveableEntityComponent.LoadAllValidator, () => {
                if (TrainEntity.FindMyTrain(player) != -1)
                {
                    throw new HamstarException("Cannot spawn duplicate train for player " + player.name);
                }

                var ent = TrainEntity.CreateTrainEntity(player);
                CustomEntityManager.AddToWorld(ent);

                return(false);
            });

            return(true);
        }
        private void LoadOuter()
        {
            this.ReflectionHelpers = new ReflectionHelpers();
            this.DataStore         = new DataStore();
            this.Promises          = new Promises();
            this.LoadHelpers       = new LoadHelpers();

            this.Timers             = new Timers();
            this.LogHelpers         = new LogHelpers();
            this.ModFeaturesHelpers = new ModFeaturesHelpers();
            this.PacketProtocolMngr = new PacketProtocolManager();

            this.BuffHelpers               = new BuffHelpers();
            this.NetHelpers                = new NetHelpers();
            this.ItemIdentityHelpers       = new ItemIdentityHelpers();
            this.NPCIdentityHelpers        = new NPCIdentityHelpers();
            this.ProjectileIdentityHelpers = new ProjectileIdentityHelpers();
            this.BuffIdentityHelpers       = new BuffIdentityHelpers();
            this.NPCBannerHelpers          = new NPCBannerHelpers();
            this.RecipeIdentityHelpers     = new RecipeIdentityHelpers();
            this.RecipeGroupHelpers        = new RecipeGroupHelpers();
            this.PlayerHooks               = new ExtendedPlayerHooks();
            this.WorldStateHelpers         = new WorldStateHelpers();
            this.ControlPanel              = new UIControlPanel();
            this.ModLock               = new ModLockService();
            this.EntityGroups          = new EntityGroups();
            this.PlayerMessages        = new PlayerMessages();
            this.Inbox                 = new InboxControl();
            this.GetModInfo            = new GetModInfo();
            this.GetModTags            = new GetModTags();
            this.MenuItemMngr          = new MenuItemManager();
            this.MenuContextMngr       = new MenuContextServiceManager();
            this.MusicHelpers          = new MusicHelpers();
            this.PlayerIdentityHelpers = new PlayerIdentityHelpers();
            this.CustomEntMngr         = new CustomEntityManager();
            this.CustomHotkeys         = new CustomHotkeys();
            this.XnaHelpers            = new XnaHelpers();
            this.ServerInfo            = new ServerInfo();
            //this.PlayerDataMngr = new PlayerDataManager();
            this.SupportInfo    = new SupportInfoDisplay();
            this.RecipeHack     = new RecipeHack();
            this.ModListHelpers = new ModListHelpers();
        }
Example #16
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
            }
        }
Example #17
0
        ////////////////

        public override void PreUpdate()
        {
//DataStore.Add( DebugHelpers.GetCurrentContext()+"_"+this.player.name+":"+this.player.whoAmI+"_A", 1 );
            var mymod = (ModHelpersMod)this.mod;
            ISet <CustomEntity> ents = CustomEntityManager.GetEntitiesByComponent <HitRadiusPlayerEntityComponent>();

            mymod.ControlPanel.UpdateGlobal();

            foreach (CustomEntity ent in ents)
            {
                var   hitRadComp = ent.GetComponentByType <HitRadiusPlayerEntityComponent>();
                float radius     = hitRadComp.GetRadius(ent);

                if (Vector2.Distance(ent.Core.Center, this.player.Center) <= radius)
                {
                    int dmg = 0;
                    if (hitRadComp.PreHurt(ent, this.player, ref dmg))
                    {
                        hitRadComp.PostHurt(ent, this.player, dmg);
                    }
                }
            }

            if (Main.netMode == 2)
            {
                this.Logic.PreUpdateServer(this.player);
            }
            else if (Main.netMode == 1)
            {
                this.Logic.PreUpdateClient(this.player);
            }
            else
            {
                this.Logic.PreUpdateSingle();
            }
//DataStore.Add( DebugHelpers.GetCurrentContext()+"_"+this.player.name+":"+this.player.whoAmI+"_B", 1 );
        }
        private static bool LoadAll(bool isJson)
        {
            var    mymod    = ModHelpersMod.Instance;
            string fileName = SaveableEntityComponent.GetFileNameBase();
            bool   success  = false;
            IList <SerializableCustomEntity> wrappedEnts = null;

            try {
                if (isJson)
                {
                    wrappedEnts = DataFileHelpers.LoadJson <List <SerializableCustomEntity> >(mymod, fileName, CustomEntityConverter.SerializerSettings, out success);
                }
                else
                {
                    wrappedEnts = DataFileHelpers.LoadBinary <List <SerializableCustomEntity> >(mymod, fileName + ".dat", false, CustomEntityConverter.SerializerSettings);
                    success     = wrappedEnts != null;
                }

                if (success)
                {
                    foreach (SerializableCustomEntity ent in wrappedEnts)
                    {
                        if (ent == null)
                        {
                            continue;
                        }
                        CustomEntity realEnt = ent.Convert();
                        CustomEntityManager.AddToWorld(realEnt);
                    }
                }
            } catch (Exception e) {
                LogHelpers.Log("!ModHelpers.SaveableEntityComponent.LoadAll - " + e.ToString());
            }

            return(success);
        }
Example #19
0
        public override bool PreAI(Projectile projectile)
        {
//DataStore.Add( DebugHelpers.GetCurrentContext()+"_"+ projectile.whoAmI+":"+ projectile.type+"_A", 1 );
            var mymod = (ModHelpersMod)this.mod;
            ISet <CustomEntity> ents = CustomEntityManager.GetEntitiesByComponent <HitRadiusProjectileEntityComponent>();

            foreach (CustomEntity ent in ents)
            {
                var   hitComp = ent.GetComponentByType <HitRadiusProjectileEntityComponent>();
                float radius  = hitComp.GetRadius(ent);

                if (Vector2.Distance(ent.Core.Center, projectile.Center) <= radius)
                {
                    if (!this.ApplyHits(ent, projectile))
                    {
                        projectile.Kill();
                        return(false);
                    }
                }
            }

//DataStore.Add( DebugHelpers.GetCurrentContext()+"_"+ projectile.whoAmI+":"+ projectile.type+"_B", 1 );
            return(true);
        }
Example #20
0
 public override void Initialize(CustomEntityManager customEntityManager)
 {
     _entityManager        = customEntityManager;
     _teamComponentArray   = _entityManager.GetComponentArray <TeamComponent>();
     _targetComponentArray = _entityManager.GetComponentArray <TargetComponent>();
 }
Example #21
0
 public virtual void Initialize(CustomEntityManager customEntityManager)
 {
 }