public bool IsCastingSpell(ChampionTypes champ, PlayerActionType action) { SpellTypes spell = ChampionTypesHelper.GetSpellFromAction(champ, action); return(TimeOfLastSpellUse(spell).TotalSeconds + SpellsHelper.Info(spell).CastingTime.TotalSeconds >= Server.Instance.GetTime().TotalSeconds); }
void HandleAction(ServerClient client, PlayerAction action) { if (ActionTypeHelper.IsSpell(action.Type)) { var spell = ChampionTypesHelper.GetSpellFromAction(client.Champion.Type, action.Type); if (client.ChampStats.Alive && !client.ChampStats.IsOnCooldown(spell)) // we're not dead and the spell is not on cooldown { CastChampionSpell(client.Champion, action); client.ChampStats.UsedSpell(spell); } } else if (action.Type != PlayerActionType.Idle) { ILogger.Log("Unknown player action type: " + action.Type); } }
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); } }