void UpdateSpells(double dt) { var toRemove = new List <LinearSpell>(); ActiveSpells.ForEach(s => { Vec2 before = (Vec2)s.Position.Clone(); Match.CurrentState.ApplyPhysicsUpdate(s.ID, (float)dt); Vec2 pass = (s.Position - before) / PhysicsEngine.PHYSICS_PASSES; s.Position = before; for (int i = 0; i < PhysicsEngine.PHYSICS_PASSES; ++i) { // Check for entities collisions var rect = s.CreateCollisionRectangle(); var enemyTeam = TeamsHelper.Opposite(s.Team); // Check to hit players bool remove = CheckForSpellPlayerCollisions(s, rect, enemyTeam); // Check to hit structures if (!remove) { remove = CheckForSpellStructuresCollisions(s, rect, enemyTeam == Teams.Left ? Match.LeftStructures : Match.RightStructures); } // Check to remove spells if (!remove && // don't check if we know it already has to be removed Match.CurrentState.SpellShouldDisappear(s)) { remove = true; } // The spell has to be removed if (remove) { toRemove.Add(s); break; } s.Position += pass; } }); toRemove.ForEach(s => { ActiveSpells.Remove(s); RemarkableEvents.Add(Utilities.MakePair <ServerCommand, Action <NetBuffer> >( ServerCommand.SpellDisappear, (msg) => { ulong id = s.ID; msg.Write(id); })); }); }
void OnStateUpdate(object sender, CommandEventArgs args) { StateUpdateEventArgs e = args as StateUpdateEventArgs; Debug.Assert(e != null); OurChampion.Champion.SetLastAcknowledgedActionID(e.LastAcknowledgedActionID); LastStateUpdateData = new List <StateUpdateData>(e.EntitiesUpdatedState.ToArray()); RemarkableEvents.AddRange(e.RemarkableEvents); TimeOfLastStateUpdate = Client.GetTime().TotalSeconds; }
/// <summary> /// Sends the state deltas to the clients. /// </summary> void SendStateChanges(double dt) { if (TimeSinceLastCorrection >= GameMatch.STATE_UPDATE_INTERVAL.TotalSeconds) { foreach (NetConnection connection in Clients.Keys) { SendCommand( connection, ServerCommand.StateUpdate, RemarkableEvents.Count == 0 ? NetDeliveryMethod.UnreliableSequenced : NetDeliveryMethod.ReliableUnordered, (msg) => FillStateUpdateMessage(msg, connection)); } RemarkableEvents.Clear(); TimeSinceLastCorrection = 0.0; } TimeSinceLastCorrection += dt; }
void ApplyRemarkableEvents() { RemarkableEvents.ForEach(r => { switch (r.Command) { case ServerCommand.SpellCast: OnCastSpell((SpellCastEventData)r); break; case ServerCommand.SpellDisappear: OnRemoveSpell((SpellDisappearEventData)r); break; case ServerCommand.StatsChanged: OnChangeStats((StatsChangedEventData)r); break; case ServerCommand.ChampionDied: OnChampionDied((ChampionDiedEventData)r); break; case ServerCommand.StructureStatsChanged: OnStructureStatsChanged((StructureStatsChangedEventData)r); break; case ServerCommand.StructureDestroyed: OnStructureDestroyed((StructureDestroyedEventData)r); break; case ServerCommand.EndOfGame: OnEndOfGame((EndOfGameEventData)r); break; case ServerCommand.TowerPreparingToShoot: OnTowerPreparingToShoot((TowerPreparingToShootEventData)r); break; default: Debug.Fail("Unknown server command (unknown remarkable event)."); break; } }); RemarkableEvents.Clear(); }
void AddRemarkableEvent(ServerCommand command, Action <NetBuffer> action) { RemarkableEvents.Add(Utilities.MakePair(command, action)); }