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); }); }
//////////////// 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(); }
//////////////// 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 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); }