public void Update() { SpawnForcedEntities(); if (_updatesUntilNextAttempt > 0) { _updatesUntilNextAttempt -= Main.dayRate; return; } ResetSpawnTime(); IEnumerable <SkyEntityType> source = from pair in _spawnConditions where pair.Value() select pair.Key; if (source.Count((SkyEntityType type) => true) == 0) { return; } FindPlayerThatCanSeeBackgroundAmbience(out Player player); if (player != null) { IEnumerable <SkyEntityType> source2 = source.Where((SkyEntityType type) => IsPlayerAtRightHeightForType(type, player) && _secondarySpawnConditionsPerPlayer.ContainsKey(type) && _secondarySpawnConditionsPerPlayer[type](player)); int num = source2.Count((SkyEntityType type) => true); if (num == 0 || Main.rand.Next(5) < 3) { source2 = source.Where((SkyEntityType type) => IsPlayerAtRightHeightForType(type, player) && (!_secondarySpawnConditionsPerPlayer.ContainsKey(type) || _secondarySpawnConditionsPerPlayer[type](player))); num = source2.Count((SkyEntityType type) => true); } if (num != 0) { SkyEntityType type2 = source2.ElementAt(Main.rand.Next(num)); SpawnForPlayer(player, type2); } } }
private bool IsPlayerAtRightHeightForType(SkyEntityType type, Player plr) { if (type == SkyEntityType.Hellbats) { return(IsPlayerInAPlaceWhereTheyCanSeeAmbienceHell(plr)); } return(IsPlayerInAPlaceWhereTheyCanSeeAmbienceSky(plr)); }
public override bool Deserialize(BinaryReader reader, int userId) { byte playerId = reader.ReadByte(); int seed = reader.ReadInt32(); SkyEntityType type = (SkyEntityType)reader.ReadByte(); Main.QueueMainThreadAction((Action)(() => ((AmbientSky)SkyManager.Instance["Ambience"]).Spawn(Main.player[(int)playerId], type, seed))); return(true); }
public static NetPacket SerializeSkyEntitySpawn(Player player, SkyEntityType type) { int num = Main.rand.Next(); NetPacket packet = NetModule.CreatePacket <NetAmbienceModule>(6); packet.Writer.Write((byte)player.whoAmI); packet.Writer.Write(num); packet.Writer.Write((byte)type); return(packet); }
public static NetPacket SerializeSkyEntitySpawn(Player player, SkyEntityType type) { int value = Main.rand.Next(); NetPacket result = NetModule.CreatePacket <NetAmbienceModule>(6); result.Writer.Write((byte)player.whoAmI); result.Writer.Write(value); result.Writer.Write((byte)type); return(result); }
public void Update() { this.SpawnForcedEntities(); if (this._updatesUntilNextAttempt > 0) { this._updatesUntilNextAttempt -= Main.dayRate; } else { this.ResetSpawnTime(); IEnumerable <SkyEntityType> source1 = this._spawnConditions.Where <KeyValuePair <SkyEntityType, Func <bool> > >((Func <KeyValuePair <SkyEntityType, Func <bool> >, bool>)(pair => pair.Value())).Select <KeyValuePair <SkyEntityType, Func <bool> >, SkyEntityType>((Func <KeyValuePair <SkyEntityType, Func <bool> >, SkyEntityType>)(pair => pair.Key)); if (source1.Count <SkyEntityType>((Func <SkyEntityType, bool>)(type => true)) == 0) { return; } Player player; AmbienceServer.FindPlayerThatCanSeeBackgroundAmbience(out player); if (player == null) { return; } IEnumerable <SkyEntityType> source2 = source1.Where <SkyEntityType>((Func <SkyEntityType, bool>)(type => this.IsPlayerAtRightHeightForType(type, player) && this._secondarySpawnConditionsPerPlayer.ContainsKey(type) && this._secondarySpawnConditionsPerPlayer[type](player))); int maxValue = source2.Count <SkyEntityType>((Func <SkyEntityType, bool>)(type => true)); if (maxValue == 0 || Main.rand.Next(5) < 3) { source2 = source1.Where <SkyEntityType>((Func <SkyEntityType, bool>)(type => { if (!this.IsPlayerAtRightHeightForType(type, player)) { return(false); } return(!this._secondarySpawnConditionsPerPlayer.ContainsKey(type) || this._secondarySpawnConditionsPerPlayer[type](player)); })); maxValue = source2.Count <SkyEntityType>((Func <SkyEntityType, bool>)(type => true)); } if (maxValue == 0) { return; } SkyEntityType type1 = source2.ElementAt <SkyEntityType>(Main.rand.Next(maxValue)); this.SpawnForPlayer(player, type1); } }
private void SpawnForPlayer(Player player, SkyEntityType type) { NetManager.Instance.BroadcastOrLoopback(NetAmbienceModule.SerializeSkyEntitySpawn(player, type)); }