static void FillChampionInfo(NetBuffer msg, ICharacter champion, ChampionStats stats) { ulong id = champion.ID; float x = champion.Position.X; float y = champion.Position.Y; byte type = (byte)champion.Type; bool team = champion.Team == Teams.Left; float maxhp = stats.MaxHealth; float hp = stats.Health; msg.Write(id); msg.Write(x); msg.Write(y); msg.Write(type); msg.Write(team); msg.Write(maxhp); msg.Write(hp); }
static void DoAction(MatchState match, ICharacter champion, PlayerAction action) { switch (action.Type) { case PlayerActionType.MoveLeft: match.Move(champion.ID, HorizontalDirection.Left); champion.FacingLeft = true; break; case PlayerActionType.MoveRight: match.Move(champion.ID, HorizontalDirection.Right); champion.FacingLeft = false; break; case PlayerActionType.Jump: match.Jump(champion.ID); break; // Ignore the actions that are not related to movement case PlayerActionType.Idle: case PlayerActionType.Spell1: case PlayerActionType.Spell2: case PlayerActionType.Spell3: case PlayerActionType.Spell4: break; default: Debug.Fail("Invalid player action."); ILogger.Log("Invalid player action passed in a package: " + action.Type.ToString(), LogPriority.Warning); break; } }
const double RADIANS_BETWEEN_PROJECTILES = Math.PI / 36.0; // ~5 degrees void CastChampionSpell(ICharacter champ, PlayerAction action) { Debug.Assert(action.Target != null); // aim in the direction of the spell champ.FacingLeft = action.Target.X < champ.Position.X + champ.CollisionWidth / 2f; SpellTypes type = ChampionTypesHelper.GetSpellFromAction(champ.Type, action.Type); int projectiles = SpellsHelper.Info(type).Projectiles; Vec2 spawn = champ.GetHandsPosition(); double angle = 0.0; if (action.Target != null) { Vec2 dir = action.Target - spawn; angle = Math.Atan2(dir.Y, dir.X); // current angle double completeArc = RADIANS_BETWEEN_PROJECTILES * (projectiles - 1); // complete arc that we'll cover angle -= completeArc / 2f; // start from the lowest angle } for (int i = 0; i < projectiles; ++i) { Vec2 dir = Vec2.Zero; if (action.Target != null) { double current = angle + i * RADIANS_BETWEEN_PROJECTILES; dir = new Vec2((float)Math.Cos(current), (float)Math.Sin(current)); } LinearSpell spell = new LinearSpell( IDGenerator.GenerateID(), champ.Team, spawn, spawn + dir, type, champ); CastSpell(spell, action.Target); } }
public override object Clone() { ICharacter c = new ICharacter(ID, Position, Type, Team); c.Clone(this); return c; }
public void Jump(ICharacter character) { Debug.Assert(character != null && character.Velocity != null); // We may only jump when we're on the ground if (IsOnGround(character)) { character.Velocity.Y = -character.JumpForce; } }
/// <summary> /// Actually applies a physics update to an entity with a fixed timestep. /// </summary> void UpdateCharacter(ICharacter character) { Debug.Assert(character != null && character.Position != null && character.Velocity != null); // Apply gravity character.Velocity += GRAVITY * DELTA_S; RestrictSpeed(character); ApplyMovement(character, () => Collisions.UndoCollisions(character)); // Make the movement fade out over time character.Velocity.X *= (float)Math.Pow(character.HorizontalAcceleration, DELTA_S); }